LLVM: lib/Target/ARM/ARMBranchTargets.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
25
26using namespace llvm;
27
28#define DEBUG_TYPE "arm-branch-targets"
29#define ARM_BRANCH_TARGETS_NAME "ARM Branch Targets"
30
31namespace {
33public:
34 static char ID;
36 void getAnalysisUsage(AnalysisUsage &AU) const override;
39
40private:
42};
43}
44
45char ARMBranchTargets::ID = 0;
46
48 false, false)
49
50void ARMBranchTargets::getAnalysisUsage(AnalysisUsage &AU) const {
51 AU.setPreservesCFG();
53}
54
56 return new ARMBranchTargets();
57}
58
59bool ARMBranchTargets::runOnMachineFunction(MachineFunction &MF) {
60 if (!MF.getInfo()->branchTargetEnforcement())
61 return false;
62
63 LLVM_DEBUG(dbgs() << "********** ARM Branch Targets **********\n"
64 << "********** Function: " << MF.getName() << '\n');
65 const ARMInstrInfo &TII =
66 *static_cast<const ARMInstrInfo *>(MF.getSubtarget().getInstrInfo());
67
68 bool MadeChange = false;
69 for (MachineBasicBlock &MBB : MF) {
70 bool IsFirstBB = &MBB == &MF.front();
71
72
73
74
75
76
77
78
79
82 addBTI(TII, MBB, IsFirstBB);
83 MadeChange = true;
84 }
85 }
86
87 return MadeChange;
88}
89
90
91
92
93
94
95
96void ARMBranchTargets::addBTI(const ARMInstrInfo &TII, MachineBasicBlock &MBB,
97 bool IsFirstBB) {
98
99 unsigned OpCode = ARM::t2BTI;
100 unsigned MIFlags = 0;
101
102
104 return MI.isMetaInstruction();
105 });
106
107
108
109 if (IsFirstBB) {
112 << "' to replace with PACBTI\n");
113 OpCode = ARM::t2PACBTI;
115 auto NextMBBI = std::next(MBBI);
117 MBBI = NextMBBI;
118 }
119 }
120
122 << (OpCode == ARM::t2BTI ? "BTI" : "PACBTI")
123 << "' instr into BB '" << MBB.getName() << "'\n");
124
127}
const TargetInstrInfo & TII
#define ARM_BRANCH_TARGETS_NAME
Definition ARMBranchTargets.cpp:29
MachineBasicBlock MachineBasicBlock::iterator MBBI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
bool isEHPad() const
Returns true if the block is a landing pad.
bool isIRBlockAddressTaken() const
Test whether this block is the target of an IR BlockAddress.
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
instr_iterator instr_end()
bool isMachineBlockAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
StringRef - Represent a constant reference to a string, i.e.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createARMBranchTargetsPass()
auto find_if_not(R &&Range, UnaryPredicate P)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.