Skip to content

Commit 68c7299

Browse files
committed
[BOLT][NFC] Fix MCPlusBuilder::getAliases caching behavior
Caching behavior of `getAliases` causes a failure in unit tests where two MCPlusBuilder objects are created corresponding to AArch64 and X86: the alias cache is created for AArch64 but then used for X86. https://lab.llvm.org/staging/#/builders/211/builds/126 The issue only affects unit tests as we only construct one MCPlusBuilder for ELF binary. Resolve the issue by moving alias bitvectors to MCPlusBuilder object. Reviewed By: yota9 Differential Revision: https://reviews.llvm.org/D124942
1 parent 2966f0f commit 68c7299

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ class MCPlusBuilder {
282282
// Initialize the default annotation allocator with id 0
283283
AnnotationAllocators.emplace(0, AnnotationAllocator());
284284
MaxAllocatorId++;
285+
// Build alias map
286+
initAliases();
285287
}
286288

287289
/// Initialize a new annotation allocator and return its id
@@ -1135,6 +1137,9 @@ class MCPlusBuilder {
11351137
virtual const BitVector &getAliases(MCPhysReg Reg,
11361138
bool OnlySmaller = false) const;
11371139

1140+
/// Initialize aliases tables.
1141+
virtual void initAliases();
1142+
11381143
/// Change \p Regs setting all registers used to pass parameters according
11391144
/// to the host abi. Do nothing if not implemented.
11401145
virtual BitVector getRegsUsedAsParams() const {
@@ -1904,6 +1909,11 @@ class MCPlusBuilder {
19041909
llvm_unreachable("not implemented");
19051910
return BlocksVectorTy();
19061911
}
1912+
1913+
// AliasMap caches a mapping of registers to the set of registers that
1914+
// alias (are sub or superregs of itself, including itself).
1915+
std::vector<BitVector> AliasMap;
1916+
std::vector<BitVector> SmallerAliasMap;
19071917
};
19081918

19091919
MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *,

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,13 @@ bool MCPlusBuilder::hasUseOfPhysReg(const MCInst &MI, unsigned Reg) const {
441441

442442
const BitVector &MCPlusBuilder::getAliases(MCPhysReg Reg,
443443
bool OnlySmaller) const {
444-
// AliasMap caches a mapping of registers to the set of registers that
445-
// alias (are sub or superregs of itself, including itself).
446-
static std::vector<BitVector> AliasMap;
447-
static std::vector<BitVector> SmallerAliasMap;
448-
449-
if (AliasMap.size() > 0) {
450-
if (OnlySmaller)
451-
return SmallerAliasMap[Reg];
452-
return AliasMap[Reg];
453-
}
444+
if (OnlySmaller)
445+
return SmallerAliasMap[Reg];
446+
return AliasMap[Reg];
447+
}
454448

449+
void MCPlusBuilder::initAliases() {
450+
assert(AliasMap.size() == 0 && SmallerAliasMap.size() == 0);
455451
// Build alias map
456452
for (MCPhysReg I = 0, E = RegInfo->getNumRegs(); I != E; ++I) {
457453
BitVector BV(RegInfo->getNumRegs(), false);
@@ -492,10 +488,6 @@ const BitVector &MCPlusBuilder::getAliases(MCPhysReg Reg,
492488
dbgs() << "\n";
493489
}
494490
});
495-
496-
if (OnlySmaller)
497-
return SmallerAliasMap[Reg];
498-
return AliasMap[Reg];
499491
}
500492

501493
uint8_t MCPlusBuilder::getRegSize(MCPhysReg Reg) const {

0 commit comments

Comments
 (0)