Skip to content

Commit ce10610

Browse files
committed
[BOLT][NFC] Simplify MCPlusBuilder::getRegSize
Pre-calculate the register size table in MCPlusBuilder constructor, similar to `AliasMap`/`SmallerAliasMap` in `initAliases`. Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D145828
1 parent ef45c12 commit ce10610

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class MCPlusBuilder {
310310
MaxAllocatorId++;
311311
// Build alias map
312312
initAliases();
313+
initSizeMap();
313314
}
314315

315316
/// Create and return target-specific MC symbolizer for the \p Function.
@@ -1176,7 +1177,10 @@ class MCPlusBuilder {
11761177
bool OnlySmaller = false) const;
11771178

11781179
/// Initialize aliases tables.
1179-
virtual void initAliases();
1180+
void initAliases();
1181+
1182+
/// Initialize register size table.
1183+
void initSizeMap();
11801184

11811185
/// Change \p Regs setting all registers used to pass parameters according
11821186
/// to the host abi. Do nothing if not implemented.
@@ -1219,7 +1223,7 @@ class MCPlusBuilder {
12191223
}
12201224

12211225
/// Return the register width in bytes (1, 2, 4 or 8)
1222-
virtual uint8_t getRegSize(MCPhysReg Reg) const;
1226+
uint8_t getRegSize(MCPhysReg Reg) const { return SizeMap[Reg]; }
12231227

12241228
/// For aliased registers, return an alias of \p Reg that has the width of
12251229
/// \p Size bytes
@@ -1969,6 +1973,8 @@ class MCPlusBuilder {
19691973
// alias (are sub or superregs of itself, including itself).
19701974
std::vector<BitVector> AliasMap;
19711975
std::vector<BitVector> SmallerAliasMap;
1976+
// SizeMap caches a mapping of registers to their sizes.
1977+
std::vector<uint8_t> SizeMap;
19721978
};
19731979

19741980
MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *,

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,22 +483,12 @@ void MCPlusBuilder::initAliases() {
483483
});
484484
}
485485

486-
uint8_t MCPlusBuilder::getRegSize(MCPhysReg Reg) const {
487-
// SizeMap caches a mapping of registers to their sizes
488-
static std::vector<uint8_t> SizeMap;
489-
490-
if (SizeMap.size() > 0) {
491-
return SizeMap[Reg];
492-
}
493-
SizeMap = std::vector<uint8_t>(RegInfo->getNumRegs());
486+
void MCPlusBuilder::initSizeMap() {
487+
SizeMap.resize(RegInfo->getNumRegs());
494488
// Build size map
495-
for (auto I = RegInfo->regclass_begin(), E = RegInfo->regclass_end(); I != E;
496-
++I) {
497-
for (MCPhysReg Reg : *I)
498-
SizeMap[Reg] = I->getSizeInBits() / 8;
499-
}
500-
501-
return SizeMap[Reg];
489+
for (auto RC : RegInfo->regclasses())
490+
for (MCPhysReg Reg : RC)
491+
SizeMap[Reg] = RC.getSizeInBits() / 8;
502492
}
503493

504494
bool MCPlusBuilder::setOperandToSymbolRef(MCInst &Inst, int OpNum,

0 commit comments

Comments
 (0)