Skip to content

Commit 82acb59

Browse files
authored
[NFC] Split UniqueBBID definition to a separate file. (#148043)
1 parent f0befb0 commit 82acb59

File tree

6 files changed

+56
-30
lines changed

6 files changed

+56
-30
lines changed

llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
#include "llvm/ADT/SmallVector.h"
2020
#include "llvm/ADT/StringMap.h"
2121
#include "llvm/ADT/StringRef.h"
22-
#include "llvm/CodeGen/MachineBasicBlock.h"
2322
#include "llvm/IR/Module.h"
2423
#include "llvm/IR/PassManager.h"
2524
#include "llvm/InitializePasses.h"
2625
#include "llvm/Pass.h"
2726
#include "llvm/Support/Error.h"
2827
#include "llvm/Support/LineIterator.h"
2928
#include "llvm/Support/MemoryBuffer.h"
29+
#include "llvm/Support/UniqueBBID.h"
3030
#include "llvm/Target/TargetMachine.h"
3131

3232
namespace llvm {
3333

3434
// This struct represents the cluster information for a machine basic block,
35-
// which is specifed by a unique ID (`MachineBasicBlock::BBID`).
35+
// which is specifed by a unique basic block ID.
3636
struct BBClusterInfo {
3737
// Basic block ID.
3838
UniqueBBID BBID;
@@ -52,27 +52,6 @@ struct FunctionPathAndClusterInfo {
5252
SmallVector<SmallVector<unsigned>> ClonePaths;
5353
};
5454

55-
// Provides DenseMapInfo for UniqueBBID.
56-
template <> struct DenseMapInfo<UniqueBBID> {
57-
static inline UniqueBBID getEmptyKey() {
58-
unsigned EmptyKey = DenseMapInfo<unsigned>::getEmptyKey();
59-
return UniqueBBID{EmptyKey, EmptyKey};
60-
}
61-
static inline UniqueBBID getTombstoneKey() {
62-
unsigned TombstoneKey = DenseMapInfo<unsigned>::getTombstoneKey();
63-
return UniqueBBID{TombstoneKey, TombstoneKey};
64-
}
65-
static unsigned getHashValue(const UniqueBBID &Val) {
66-
std::pair<unsigned, unsigned> PairVal =
67-
std::make_pair(Val.BaseID, Val.CloneID);
68-
return DenseMapInfo<std::pair<unsigned, unsigned>>::getHashValue(PairVal);
69-
}
70-
static bool isEqual(const UniqueBBID &LHS, const UniqueBBID &RHS) {
71-
return DenseMapInfo<unsigned>::isEqual(LHS.BaseID, RHS.BaseID) &&
72-
DenseMapInfo<unsigned>::isEqual(LHS.CloneID, RHS.CloneID);
73-
}
74-
};
75-
7655
class BasicBlockSectionsProfileReader {
7756
public:
7857
friend class BasicBlockSectionsProfileReaderWrapperPass;

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/MC/LaneBitmask.h"
2626
#include "llvm/Support/BranchProbability.h"
2727
#include "llvm/Support/Compiler.h"
28+
#include "llvm/Support/UniqueBBID.h"
2829
#include <cassert>
2930
#include <cstdint>
3031
#include <iterator>
@@ -99,13 +100,6 @@ template <> struct DenseMapInfo<MBBSectionID> {
99100
}
100101
};
101102

102-
// This structure represents the information for a basic block pertaining to
103-
// the basic block sections profile.
104-
struct UniqueBBID {
105-
unsigned BaseID;
106-
unsigned CloneID;
107-
};
108-
109103
template <> struct ilist_traits<MachineInstr> {
110104
private:
111105
friend class MachineBasicBlock; // Set by the owning MachineBasicBlock.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//===- llvm/Support/UniqueBBID.h --------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Unique fixed ID assigned to basic blocks upon their creation.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_SUPPORT_UNIQUEBBID_H
14+
#define LLVM_SUPPORT_UNIQUEBBID_H
15+
16+
#include "llvm/ADT/DenseMapInfo.h"
17+
18+
namespace llvm {
19+
20+
// This structure represents the information for a basic block pertaining to
21+
// the basic block sections profile.
22+
struct UniqueBBID {
23+
unsigned BaseID;
24+
unsigned CloneID;
25+
};
26+
27+
// Provides DenseMapInfo for UniqueBBID.
28+
template <> struct DenseMapInfo<UniqueBBID> {
29+
static inline UniqueBBID getEmptyKey() {
30+
unsigned EmptyKey = DenseMapInfo<unsigned>::getEmptyKey();
31+
return UniqueBBID{EmptyKey, EmptyKey};
32+
}
33+
static inline UniqueBBID getTombstoneKey() {
34+
unsigned TombstoneKey = DenseMapInfo<unsigned>::getTombstoneKey();
35+
return UniqueBBID{TombstoneKey, TombstoneKey};
36+
}
37+
static unsigned getHashValue(const UniqueBBID &Val) {
38+
std::pair<unsigned, unsigned> PairVal =
39+
std::make_pair(Val.BaseID, Val.CloneID);
40+
return DenseMapInfo<std::pair<unsigned, unsigned>>::getHashValue(PairVal);
41+
}
42+
static bool isEqual(const UniqueBBID &LHS, const UniqueBBID &RHS) {
43+
return DenseMapInfo<unsigned>::isEqual(LHS.BaseID, RHS.BaseID) &&
44+
DenseMapInfo<unsigned>::isEqual(LHS.CloneID, RHS.CloneID);
45+
}
46+
};
47+
48+
} // end namespace llvm
49+
50+
#endif // LLVM_SUPPORT_UNIQUEBBID_H

llvm/lib/CodeGen/BasicBlockPathCloning.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "llvm/CodeGen/Passes.h"
4242
#include "llvm/CodeGen/TargetInstrInfo.h"
4343
#include "llvm/InitializePasses.h"
44+
#include "llvm/Support/UniqueBBID.h"
4445
#include "llvm/Support/WithColor.h"
4546
#include "llvm/Target/TargetMachine.h"
4647

llvm/lib/CodeGen/BasicBlockSections.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
#include "llvm/CodeGen/Passes.h"
8080
#include "llvm/CodeGen/TargetInstrInfo.h"
8181
#include "llvm/InitializePasses.h"
82+
#include "llvm/Support/UniqueBBID.h"
8283
#include "llvm/Target/TargetMachine.h"
8384
#include <optional>
8485

llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/Support/LineIterator.h"
2727
#include "llvm/Support/MemoryBuffer.h"
2828
#include "llvm/Support/Path.h"
29+
#include "llvm/Support/UniqueBBID.h"
2930
#include <llvm/ADT/STLExtras.h>
3031

3132
using namespace llvm;

0 commit comments

Comments
 (0)