Skip to content

Commit b332cb0

Browse files
authored
[NFC][CodeGen] Add MachineBlockHashInfoResult for use in NewPM (#193059)
This patch extracts the hash computation logic into a separate `MachineBlockHashInfoResult` class. This allows the data to be managed independently of the legacy pass manager and prepares the infrastructure for the New Pass Manager. Preparation for #192911.
1 parent 07f29a3 commit b332cb0

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

llvm/include/llvm/CodeGen/MachineBlockHashInfo.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_CODEGEN_MACHINEBLOCKHASHINFO_H
1414
#define LLVM_CODEGEN_MACHINEBLOCKHASHINFO_H
1515

16+
#include "llvm/ADT/DenseMap.h"
1617
#include "llvm/CodeGen/MachineFunctionPass.h"
1718

1819
namespace llvm {
@@ -95,9 +96,19 @@ struct BlendedBlockHash {
9596
uint16_t NeighborHash{0};
9697
};
9798

98-
class MachineBlockHashInfo : public MachineFunctionPass {
99+
/// Result object for MachineBlockHashInfo.
100+
class MachineBlockHashInfoResult {
99101
DenseMap<const MachineBasicBlock *, uint64_t> MBBHashInfo;
100102

103+
public:
104+
MachineBlockHashInfoResult();
105+
explicit MachineBlockHashInfoResult(const MachineFunction &MBB);
106+
uint64_t getMBBHash(const MachineBasicBlock &MBB) const;
107+
};
108+
109+
class MachineBlockHashInfo : public MachineFunctionPass {
110+
MachineBlockHashInfoResult Result;
111+
101112
public:
102113
static char ID;
103114
MachineBlockHashInfo();
@@ -108,7 +119,7 @@ class MachineBlockHashInfo : public MachineFunctionPass {
108119

109120
bool runOnMachineFunction(MachineFunction &F) override;
110121

111-
uint64_t getMBBHash(const MachineBasicBlock &MBB);
122+
uint64_t getMBBHash(const MachineBasicBlock &MBB) const;
112123
};
113124

114125
} // end namespace llvm

llvm/lib/CodeGen/MachineBlockHashInfo.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ struct CollectHashInfo {
6363
uint64_t NeighborHash;
6464
};
6565

66-
bool MachineBlockHashInfo::runOnMachineFunction(MachineFunction &F) {
66+
MachineBlockHashInfoResult::MachineBlockHashInfoResult() = default;
67+
68+
MachineBlockHashInfoResult::MachineBlockHashInfoResult(
69+
const MachineFunction &F) {
6770
DenseMap<const MachineBasicBlock *, CollectHashInfo> HashInfos;
6871
uint16_t Offset = 0;
6972
// Initialize hash components
@@ -103,12 +106,21 @@ bool MachineBlockHashInfo::runOnMachineFunction(MachineFunction &F) {
103106
fold_64_to_16(HashInfo.NeighborHash));
104107
MBBHashInfo[&MBB] = BlendedHash.combine();
105108
}
109+
}
106110

111+
uint64_t
112+
MachineBlockHashInfoResult::getMBBHash(const MachineBasicBlock &MBB) const {
113+
auto it = MBBHashInfo.find(&MBB);
114+
return it == MBBHashInfo.end() ? 0 : it->second;
115+
}
116+
117+
bool MachineBlockHashInfo::runOnMachineFunction(MachineFunction &F) {
118+
Result = MachineBlockHashInfoResult{F};
107119
return false;
108120
}
109121

110-
uint64_t MachineBlockHashInfo::getMBBHash(const MachineBasicBlock &MBB) {
111-
return MBBHashInfo[&MBB];
122+
uint64_t MachineBlockHashInfo::getMBBHash(const MachineBasicBlock &MBB) const {
123+
return Result.getMBBHash(MBB);
112124
}
113125

114126
MachineFunctionPass *llvm::createMachineBlockHashInfoPass() {

0 commit comments

Comments
 (0)