27#define DEBUG_TYPE "aarch64-win-cfi"
47 return "AArch64 Windows unwind range insertion";
52char AArch64WinCFILegacy::ID = 0;
55 "AArch64 Windows unwind range insertion",
false,
false)
63 if (
End->getPrevNode() &&
End->getPrevNode()->isTerminator())
64 End->bundleWithPred();
70 assert(ST.isTargetWindows() &&
71 "Windows CFI range insertion requires a Windows target");
96 if (
MI.getOpcode() == AArch64::SEH_StartProc)
98 "AArch64 Windows unwind range insertion cannot be run twice");
99 if (
MI.getOpcode() == AArch64::SEH_PrologEnd) {
102 "AArch64 Windows unwind range insertion does "
103 "not support multiple prologues");
104 PrologueBlock = &
MBB;
106 if (
MI.getOpcode() == AArch64::SEH_EpilogEnd)
112 if (!PrologueBlock || PrologueBlock == &MF.
front())
120 auto PrologueStart = PrologueBlock->
end();
122 if (
MI.getOpcode() == AArch64::SEH_PrologEnd)
126 if (PrologueStart == PrologueBlock->
end())
127 PrologueStart =
MI.getIterator();
128 if (AArch64InstrInfo::isSEHInstruction(
MI))
132 if (PrologueStart == PrologueBlock->
end())
139 while (!PendingBlocks.
empty()) {
155 if (FrameOnExit == FrameOnEntry)
159 if (ReachableBlocks.
empty())
163 "inconsistent Windows ARM64 frame state at CFG join");
171 bool RangeStarted =
false;
174 bool IsPhysicalPrologue = &
MBB == PrologueBlock;
178 (
MBB.isBeginSection() || !IsFramed || IsPhysicalPrologue)) {
179 endWinCFIRange(*PreviousLayoutBlock,
TII, PreviousLayoutBlock->
end());
180 RangeStarted =
false;
183 if (IsFramed && !RangeStarted) {
184 if (IsPhysicalPrologue) {
186 TII.get(AArch64::SEH_StartProc));
204 if (RangeStarted && EpilogueBlocks.
contains(&
MBB)) {
206 return MI.getOpcode() == AArch64::SEH_EpilogEnd;
210 return !
MI.isMetaInstruction() &&
211 !AArch64InstrInfo::isSEHInstruction(
MI);
213 auto FirstInstrAfterEpilog =
llvm::find_if(Suffix, IsRealInstruction);
216 if (FirstInstrAfterEpilog !=
MBB.end() &&
217 (!FirstInstrAfterEpilog->isTerminator() ||
218 TII.getInstSizeInBytes(*FirstInstrAfterEpilog) != 4 ||
220 IsRealInstruction))) {
221 endWinCFIRange(
MBB,
TII, Suffix.begin());
222 RangeStarted =
false;
228 if (RangeStarted && (
MBB.isEndSection() || &
MBB == &MF.
back())) {
230 RangeStarted =
false;
232 PreviousLayoutBlock = &
MBB;
252 return new AArch64WinCFILegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool insertWinCFIRanges(MachineFunction &MF)
const AArch64InstrInfo MachineBasicBlock::iterator InsertPt
const AArch64InstrInfo & TII
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
bool hasPersonalityFn() const
Check whether this function has a personality function.
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.
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & back() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
bool hasEHFunclets() const
Representation of each machine instruction.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
void insert_range(Range &&R)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
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.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
FunctionPass * createAArch64WinCFIPass()
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
iterator_range< df_iterator< T > > depth_first(const T &G)
@ End
Run the machine verifier once, at the end of the pipeline.