Skip to content

Commit 8b3ff18

Browse files
committed
[BOLT][BTI] Add MCPlusBuilder::updateBTIVariant
Checks if an instruction is BTI, and updates the immediate value to the newly requested variant.
1 parent f1cc15e commit 8b3ff18

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,12 @@ class MCPlusBuilder {
18841884
llvm_unreachable("not implemented");
18851885
}
18861886

1887+
/// Update operand of BTI instruction.
1888+
virtual void updateBTIVariant(MCInst &Inst, bool CouldCall,
1889+
bool CouldJump) const {
1890+
llvm_unreachable("not implemented");
1891+
}
1892+
18871893
/// Store \p Target absolute address to \p RegName
18881894
virtual InstructionListType materializeAddress(const MCSymbol *Target,
18891895
MCContext *Ctx,

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,14 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
27302730
Inst.addOperand(MCOperand::createImm(HintNum));
27312731
}
27322732

2733+
void updateBTIVariant(MCInst &Inst, bool CouldCall,
2734+
bool CouldJump) const override {
2735+
assert(Inst.getOpcode() == AArch64::HINT && "Not a BTI instruction.");
2736+
unsigned HintNum = getBTIHintNum(CouldCall, CouldJump);
2737+
Inst.clear();
2738+
Inst.addOperand(MCOperand::createImm(HintNum));
2739+
}
2740+
27332741
InstructionListType materializeAddress(const MCSymbol *Target, MCContext *Ctx,
27342742
MCPhysReg RegName,
27352743
int64_t Addend = 0) const override {

bolt/unittests/Core/MCPlusBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,26 @@ TEST_P(MCPlusBuilderTester, AArch64_BTI) {
156156
ASSERT_EQ(II->getOpcode(), AArch64::HINT);
157157
ASSERT_EQ(II->getOperand(0).getImm(), 38);
158158
ASSERT_TRUE(BC->MIB->isBTILandingPad(*II, true, true));
159+
BC->MIB->updateBTIVariant(*II, true, false);
160+
ASSERT_TRUE(BC->MIB->isBTILandingPad(*II, true, false));
159161

160162
MCInst BTIj;
161163
BC->MIB->createBTI(BTIj, false, true);
162164
II = BB->addInstruction(BTIj);
163165
ASSERT_EQ(II->getOpcode(), AArch64::HINT);
164166
ASSERT_EQ(II->getOperand(0).getImm(), 36);
165167
ASSERT_TRUE(BC->MIB->isBTILandingPad(*II, false, true));
168+
BC->MIB->updateBTIVariant(*II, true, true);
169+
ASSERT_TRUE(BC->MIB->isBTILandingPad(*II, true, true));
166170

167171
MCInst BTIc;
168172
BC->MIB->createBTI(BTIc, true, false);
169173
II = BB->addInstruction(BTIc);
170174
ASSERT_EQ(II->getOpcode(), AArch64::HINT);
171175
ASSERT_EQ(II->getOperand(0).getImm(), 34);
172176
ASSERT_TRUE(BC->MIB->isBTILandingPad(*II, true, false));
177+
BC->MIB->updateBTIVariant(*II, false, true);
178+
ASSERT_TRUE(BC->MIB->isBTILandingPad(*II, false, true));
173179

174180
MCInst BTIinvalid;
175181
ASSERT_DEATH(BC->MIB->createBTI(BTIinvalid, false, false),

0 commit comments

Comments
 (0)