Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Target/ARM/ARMBranchTargets.cpp
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
/// to find a PAC instruction and replace it with PACBTI. Otherwise just insert | /// to find a PAC instruction and replace it with PACBTI. Otherwise just insert | ||||
/// a BTI instruction. | /// a BTI instruction. | ||||
/// The point of insertion is in the beginning of the BB, immediately after meta | /// The point of insertion is in the beginning of the BB, immediately after meta | ||||
/// instructions (such labels in exception handling landing pads). | /// instructions (such labels in exception handling landing pads). | ||||
void ARMBranchTargets::addBTI(const ARMInstrInfo &TII, MachineBasicBlock &MBB, | void ARMBranchTargets::addBTI(const ARMInstrInfo &TII, MachineBasicBlock &MBB, | ||||
bool IsFirstBB) { | bool IsFirstBB) { | ||||
// Which instruction to insert: BTI or PACBTI | // Which instruction to insert: BTI or PACBTI | ||||
unsigned OpCode = ARM::t2BTI; | unsigned OpCode = ARM::t2BTI; | ||||
unsigned MIFlags = 0; | |||||
// Skip meta instructions, including EH labels | // Skip meta instructions, including EH labels | ||||
auto MBBI = llvm::find_if_not(MBB.instrs(), [](const MachineInstr &MI) { | auto MBBI = llvm::find_if_not(MBB.instrs(), [](const MachineInstr &MI) { | ||||
return MI.isMetaInstruction(); | return MI.isMetaInstruction(); | ||||
}); | }); | ||||
// If this is the first BB in a function, check if it starts with a PAC | // If this is the first BB in a function, check if it starts with a PAC | ||||
// instruction and in that case remove the PAC instruction. | // instruction and in that case remove the PAC instruction. | ||||
if (IsFirstBB) { | if (IsFirstBB) { | ||||
if (MBBI != MBB.instr_end() && MBBI->getOpcode() == ARM::t2PAC) { | if (MBBI != MBB.instr_end() && MBBI->getOpcode() == ARM::t2PAC) { | ||||
LLVM_DEBUG(dbgs() << "Removing a 'PAC' instr from BB '" << MBB.getName() | LLVM_DEBUG(dbgs() << "Removing a 'PAC' instr from BB '" << MBB.getName() | ||||
<< "' to replace with PACBTI\n"); | << "' to replace with PACBTI\n"); | ||||
OpCode = ARM::t2PACBTI; | OpCode = ARM::t2PACBTI; | ||||
MIFlags = MachineInstr::FrameSetup; | |||||
auto NextMBBI = std::next(MBBI); | auto NextMBBI = std::next(MBBI); | ||||
MBBI->eraseFromParent(); | MBBI->eraseFromParent(); | ||||
MBBI = NextMBBI; | MBBI = NextMBBI; | ||||
} | } | ||||
} | } | ||||
LLVM_DEBUG(dbgs() << "Inserting a '" | LLVM_DEBUG(dbgs() << "Inserting a '" | ||||
<< (OpCode == ARM::t2BTI ? "BTI" : "PACBTI") | << (OpCode == ARM::t2BTI ? "BTI" : "PACBTI") | ||||
<< "' instr into BB '" << MBB.getName() << "'\n"); | << "' instr into BB '" << MBB.getName() << "'\n"); | ||||
// Finally, insert a new instruction (either PAC or PACBTI) | // Finally, insert a new instruction (either PAC or PACBTI) | ||||
BuildMI(MBB, MBBI, MBB.findDebugLoc(MBBI), TII.get(OpCode)); | BuildMI(MBB, MBBI, MBB.findDebugLoc(MBBI), TII.get(OpCode)) | ||||
.setMIFlags(MIFlags); | |||||
} | } |