diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h --- a/bolt/include/bolt/Core/MCPlusBuilder.h +++ b/bolt/include/bolt/Core/MCPlusBuilder.h @@ -310,6 +310,7 @@ MaxAllocatorId++; // Build alias map initAliases(); + initSizeMap(); } /// Create and return target-specific MC symbolizer for the \p Function. @@ -1193,7 +1194,10 @@ bool OnlySmaller = false) const; /// Initialize aliases tables. - virtual void initAliases(); + void initAliases(); + + /// Initialize register size table. + void initSizeMap(); /// Change \p Regs setting all registers used to pass parameters according /// to the host abi. Do nothing if not implemented. @@ -1236,7 +1240,7 @@ } /// Return the register width in bytes (1, 2, 4 or 8) - virtual uint8_t getRegSize(MCPhysReg Reg) const; + uint8_t getRegSize(MCPhysReg Reg) const { return SizeMap[Reg]; } /// For aliased registers, return an alias of \p Reg that has the width of /// \p Size bytes @@ -1986,6 +1990,8 @@ // alias (are sub or superregs of itself, including itself). std::vector AliasMap; std::vector SmallerAliasMap; + // SizeMap caches a mapping of registers to their sizes. + std::vector SizeMap; }; MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *, diff --git a/bolt/lib/Core/MCPlusBuilder.cpp b/bolt/lib/Core/MCPlusBuilder.cpp --- a/bolt/lib/Core/MCPlusBuilder.cpp +++ b/bolt/lib/Core/MCPlusBuilder.cpp @@ -483,22 +483,12 @@ }); } -uint8_t MCPlusBuilder::getRegSize(MCPhysReg Reg) const { - // SizeMap caches a mapping of registers to their sizes - static std::vector SizeMap; - - if (SizeMap.size() > 0) { - return SizeMap[Reg]; - } - SizeMap = std::vector(RegInfo->getNumRegs()); +void MCPlusBuilder::initSizeMap() { + SizeMap.resize(RegInfo->getNumRegs()); // Build size map - for (auto I = RegInfo->regclass_begin(), E = RegInfo->regclass_end(); I != E; - ++I) { - for (MCPhysReg Reg : *I) - SizeMap[Reg] = I->getSizeInBits() / 8; - } - - return SizeMap[Reg]; + for (auto RC : RegInfo->regclasses()) + for (MCPhysReg Reg : RC) + SizeMap[Reg] = RC.getSizeInBits() / 8; } bool MCPlusBuilder::setOperandToSymbolRef(MCInst &Inst, int OpNum,