LLVM: lib/Target/X86/X86AvoidTrailingCall.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
42
43#define AVOIDCALL_DESC "X86 avoid trailing call pass"
44#define AVOIDCALL_NAME "x86-avoid-trailing-call"
45
46#define DEBUG_TYPE AVOIDCALL_NAME
47
48using namespace llvm;
49
50namespace {
52public:
54
56
57 static char ID;
58
59private:
61};
62}
63
64char X86AvoidTrailingCallLegacyPass::ID = 0;
65
67 return new X86AvoidTrailingCallLegacyPass();
68}
69
71 false, false)
72
73
74
75
76static bool isCallOrRealInstruction(MachineInstr &MI) {
77 return MI.isCall() || (.isPseudo() &&
.isMetaInstruction());
78}
79
80
82 return MI.isCall() && .isReturn();
83}
84
89
90
91
93 return false;
94
95
96
97
100
101
104 continue;
105
106
108
109
110
111
112
113 bool IsEmpty = LastRealInstr == MBB.rend();
115 if (IsEmpty || IsCall) {
117 if (IsCall) {
118 dbgs() << "inserting int3 after trailing call instruction:\n";
119 LastRealInstr->dump();
120 dbgs() << '\n';
121 } else {
122 dbgs() << "inserting int3 in trailing empty MBB:\n";
123 MBB.dump();
124 }
125 });
126
129 if (IsCall) {
130 MBBI = std::next(LastRealInstr.getReverse());
131 DL = LastRealInstr->getDebugLoc();
132 }
135 }
136 }
137
139}
140
141bool X86AvoidTrailingCallLegacyPass::runOnMachineFunction(MachineFunction &MF) {
143}
144
145PreservedAnalyses
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const TargetInstrInfo & TII
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
bool UpdatedOnX86AvoidTrailingCallPass(MachineFunction &MF)
Definition X86AvoidTrailingCall.cpp:85
#define AVOIDCALL_NAME
Definition X86AvoidTrailingCall.cpp:44
static bool isCallInstruction(const MachineInstr &MI)
Definition X86AvoidTrailingCall.cpp:81
#define AVOIDCALL_DESC
Definition X86AvoidTrailingCall.cpp:43
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
StringRef - Represent a constant reference to a string, i.e.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition X86AvoidTrailingCall.cpp:146
bool isTargetWin64() const
const X86InstrInfo * getInstrInfo() const override
Pass manager infrastructure for declaring and invalidating analyses.
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
FunctionPass * createX86AvoidTrailingCallLegacyPass()
Definition X86AvoidTrailingCall.cpp:66