003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/CodeGen
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
CodeGen
/
📁
..
📄
AggressiveAntiDepBreaker.cpp
(37.23 KB)
📄
AggressiveAntiDepBreaker.h
(6.8 KB)
📄
AllocationOrder.cpp
(1.96 KB)
📄
AllocationOrder.h
(2.96 KB)
📄
Analysis.cpp
(32.62 KB)
📁
AsmPrinter
📄
AtomicExpandPass.cpp
(71.86 KB)
📄
BBSectionsPrepare.cpp
(18.8 KB)
📄
BasicTargetTransformInfo.cpp
(1.53 KB)
📄
BranchFolding.cpp
(77.92 KB)
📄
BranchFolding.h
(7.36 KB)
📄
BranchRelaxation.cpp
(19.45 KB)
📄
BreakFalseDeps.cpp
(9.79 KB)
📄
BuiltinGCs.cpp
(4.88 KB)
📄
CFGuardLongjmp.cpp
(3.73 KB)
📄
CFIInstrInserter.cpp
(17.53 KB)
📄
CalcSpillWeights.cpp
(10.22 KB)
📄
CallingConvLower.cpp
(10.4 KB)
📄
CodeGen.cpp
(5.28 KB)
📄
CodeGenPrepare.cpp
(295.01 KB)
📄
CommandFlags.cpp
(24.89 KB)
📄
CriticalAntiDepBreaker.cpp
(27.91 KB)
📄
CriticalAntiDepBreaker.h
(4.22 KB)
📄
DFAPacketizer.cpp
(10.91 KB)
📄
DeadMachineInstructionElim.cpp
(6.52 KB)
📄
DetectDeadLanes.cpp
(20.74 KB)
📄
DwarfEHPrepare.cpp
(9.01 KB)
📄
EarlyIfConversion.cpp
(37.51 KB)
📄
EdgeBundles.cpp
(3.21 KB)
📄
ExecutionDomainFix.cpp
(14.67 KB)
📄
ExpandMemCmp.cpp
(33.66 KB)
📄
ExpandPostRAPseudos.cpp
(7.28 KB)
📄
ExpandReductions.cpp
(7.23 KB)
📄
FEntryInserter.cpp
(1.81 KB)
📄
FaultMaps.cpp
(4.99 KB)
📄
FinalizeISel.cpp
(2.65 KB)
📄
FixupStatepointCallerSaved.cpp
(11.06 KB)
📄
FuncletLayout.cpp
(2.21 KB)
📄
GCMetadata.cpp
(5.1 KB)
📄
GCMetadataPrinter.cpp
(748 B)
📄
GCRootLowering.cpp
(11.46 KB)
📄
GCStrategy.cpp
(708 B)
📁
GlobalISel
📄
GlobalMerge.cpp
(24.52 KB)
📄
HardwareLoops.cpp
(18.44 KB)
📄
IfConversion.cpp
(89.43 KB)
📄
ImplicitNullChecks.cpp
(25.14 KB)
📄
IndirectBrExpandPass.cpp
(7.79 KB)
📄
InlineSpiller.cpp
(58.24 KB)
📄
InterferenceCache.cpp
(8.83 KB)
📄
InterferenceCache.h
(7.22 KB)
📄
InterleavedAccessPass.cpp
(16.59 KB)
📄
InterleavedLoadCombinePass.cpp
(42.35 KB)
📄
IntrinsicLowering.cpp
(17.08 KB)
📄
LLVMTargetMachine.cpp
(10.25 KB)
📄
LatencyPriorityQueue.cpp
(5.64 KB)
📄
LazyMachineBlockFrequencyInfo.cpp
(3.36 KB)
📄
LexicalScopes.cpp
(12.16 KB)
📄
LiveDebugValues.cpp
(78.98 KB)
📄
LiveDebugVariables.cpp
(51.79 KB)
📄
LiveDebugVariables.h
(2.15 KB)
📄
LiveInterval.cpp
(46.67 KB)
📄
LiveIntervalCalc.cpp
(7.62 KB)
📄
LiveIntervalUnion.cpp
(6.36 KB)
📄
LiveIntervals.cpp
(64.59 KB)
📄
LivePhysRegs.cpp
(11.08 KB)
📄
LiveRangeCalc.cpp
(15.72 KB)
📄
LiveRangeEdit.cpp
(17.03 KB)
📄
LiveRangeShrink.cpp
(8.69 KB)
📄
LiveRangeUtils.h
(2.12 KB)
📄
LiveRegMatrix.cpp
(7.47 KB)
📄
LiveRegUnits.cpp
(4.72 KB)
📄
LiveStacks.cpp
(2.95 KB)
📄
LiveVariables.cpp
(30.26 KB)
📄
LocalStackSlotAllocation.cpp
(17.26 KB)
📄
LoopTraversal.cpp
(2.89 KB)
📄
LowLevelType.cpp
(1.93 KB)
📄
LowerEmuTLS.cpp
(5.66 KB)
📄
MBFIWrapper.cpp
(1.57 KB)
📄
MIRCanonicalizerPass.cpp
(12.46 KB)
📄
MIRNamerPass.cpp
(2.16 KB)
📁
MIRParser
📄
MIRPrinter.cpp
(32.67 KB)
📄
MIRPrintingPass.cpp
(1.99 KB)
📄
MIRVRegNamerUtils.cpp
(6.04 KB)
📄
MIRVRegNamerUtils.h
(3.25 KB)
📄
MachineBasicBlock.cpp
(50.47 KB)
📄
MachineBlockFrequencyInfo.cpp
(10.13 KB)
📄
MachineBlockPlacement.cpp
(137.61 KB)
📄
MachineBranchProbabilityInfo.cpp
(3.5 KB)
📄
MachineCSE.cpp
(31.82 KB)
📄
MachineCombiner.cpp
(28.13 KB)
📄
MachineCopyPropagation.cpp
(29.21 KB)
📄
MachineDebugify.cpp
(6.47 KB)
📄
MachineDominanceFrontier.cpp
(1.83 KB)
📄
MachineDominators.cpp
(4.86 KB)
📄
MachineFrameInfo.cpp
(9.77 KB)
📄
MachineFunction.cpp
(42.97 KB)
📄
MachineFunctionPass.cpp
(4.78 KB)
📄
MachineFunctionPrinterPass.cpp
(2.3 KB)
📄
MachineInstr.cpp
(76.39 KB)
📄
MachineInstrBundle.cpp
(11.49 KB)
📄
MachineLICM.cpp
(57.05 KB)
📄
MachineLoopInfo.cpp
(4.98 KB)
📄
MachineLoopUtils.cpp
(5.16 KB)
📄
MachineModuleInfo.cpp
(9.9 KB)
📄
MachineModuleInfoImpls.cpp
(1.5 KB)
📄
MachineOperand.cpp
(39.6 KB)
📄
MachineOptimizationRemarkEmitter.cpp
(3.29 KB)
📄
MachineOutliner.cpp
(42.13 KB)
📄
MachinePipeliner.cpp
(111.33 KB)
📄
MachinePostDominators.cpp
(2.42 KB)
📄
MachineRegionInfo.cpp
(4.75 KB)
📄
MachineRegisterInfo.cpp
(22.97 KB)
📄
MachineSSAUpdater.cpp
(12.99 KB)
📄
MachineScheduler.cpp
(136.89 KB)
📄
MachineSink.cpp
(51.94 KB)
📄
MachineSizeOpts.cpp
(8.76 KB)
📄
MachineStripDebug.cpp
(3.76 KB)
📄
MachineTraceMetrics.cpp
(49.58 KB)
📄
MachineVerifier.cpp
(107.98 KB)
📄
MacroFusion.cpp
(7.55 KB)
📄
ModuloSchedule.cpp
(85.09 KB)
📄
NonRelocatableStringpool.cpp
(1.65 KB)
📄
OptimizePHIs.cpp
(6.7 KB)
📄
PHIElimination.cpp
(27.73 KB)
📄
PHIEliminationUtils.cpp
(2.56 KB)
📄
PHIEliminationUtils.h
(972 B)
📄
ParallelCG.cpp
(3.71 KB)
📄
PatchableFunction.cpp
(3.44 KB)
📄
PeepholeOptimizer.cpp
(78.41 KB)
📄
PostRAHazardRecognizer.cpp
(3.5 KB)
📄
PostRASchedulerList.cpp
(24.31 KB)
📄
PreISelIntrinsicLowering.cpp
(7.91 KB)
📄
ProcessImplicitDefs.cpp
(5.4 KB)
📄
PrologEpilogInserter.cpp
(50.45 KB)
📄
PseudoSourceValue.cpp
(4.71 KB)
📄
RDFGraph.cpp
(58.39 KB)
📄
RDFLiveness.cpp
(40.7 KB)
📄
RDFRegisters.cpp
(11.29 KB)
📄
ReachingDefAnalysis.cpp
(21.74 KB)
📄
RegAllocBase.cpp
(6.31 KB)
📄
RegAllocBase.h
(4.63 KB)
📄
RegAllocBasic.cpp
(11.33 KB)
📄
RegAllocFast.cpp
(45.78 KB)
📄
RegAllocGreedy.cpp
(123.32 KB)
📄
RegAllocPBQP.cpp
(33.14 KB)
📄
RegUsageInfoCollector.cpp
(7.39 KB)
📄
RegUsageInfoPropagate.cpp
(5.07 KB)
📄
RegisterClassInfo.cpp
(6.62 KB)
📄
RegisterCoalescer.cpp
(151.71 KB)
📄
RegisterCoalescer.h
(4.04 KB)
📄
RegisterPressure.cpp
(48.86 KB)
📄
RegisterScavenging.cpp
(27.48 KB)
📄
RegisterUsageInfo.cpp
(3.18 KB)
📄
RenameIndependentSubregs.cpp
(14.79 KB)
📄
ResetMachineFunctionPass.cpp
(3.48 KB)
📄
SafeStack.cpp
(34.12 KB)
📄
SafeStackLayout.cpp
(5.3 KB)
📄
SafeStackLayout.h
(2.41 KB)
📄
ScalarizeMaskedMemIntrin.cpp
(31.46 KB)
📄
ScheduleDAG.cpp
(21.34 KB)
📄
ScheduleDAGInstrs.cpp
(54.59 KB)
📄
ScheduleDAGPrinter.cpp
(3.21 KB)
📄
ScoreboardHazardRecognizer.cpp
(7.96 KB)
📁
SelectionDAG
📄
ShadowStackGCLowering.cpp
(14.16 KB)
📄
ShrinkWrap.cpp
(23.03 KB)
📄
SjLjEHPrepare.cpp
(18.93 KB)
📄
SlotIndexes.cpp
(9.35 KB)
📄
SpillPlacement.cpp
(12.58 KB)
📄
SpillPlacement.h
(6.67 KB)
📄
SplitKit.cpp
(66.39 KB)
📄
SplitKit.h
(23.7 KB)
📄
StackColoring.cpp
(49.03 KB)
📄
StackMapLivenessAnalysis.cpp
(6.16 KB)
📄
StackMaps.cpp
(19.74 KB)
📄
StackProtector.cpp
(22.94 KB)
📄
StackSlotColoring.cpp
(17.12 KB)
📄
SwiftErrorValueTracking.cpp
(11.37 KB)
📄
SwitchLoweringUtils.cpp
(18.33 KB)
📄
TailDuplication.cpp
(3.32 KB)
📄
TailDuplicator.cpp
(38.29 KB)
📄
TargetFrameLoweringImpl.cpp
(6.24 KB)
📄
TargetInstrInfo.cpp
(51.1 KB)
📄
TargetLoweringBase.cpp
(82.53 KB)
📄
TargetLoweringObjectFileImpl.cpp
(80.52 KB)
📄
TargetOptionsImpl.cpp
(2 KB)
📄
TargetPassConfig.cpp
(48.89 KB)
📄
TargetRegisterInfo.cpp
(19.15 KB)
📄
TargetSchedule.cpp
(13.16 KB)
📄
TargetSubtargetInfo.cpp
(1.89 KB)
📄
TwoAddressInstructionPass.cpp
(62.08 KB)
📄
TypePromotion.cpp
(32.46 KB)
📄
UnreachableBlockElim.cpp
(7.48 KB)
📄
ValueTypes.cpp
(19.87 KB)
📄
VirtRegMap.cpp
(21.4 KB)
📄
WasmEHPrepare.cpp
(17.48 KB)
📄
WinEHPrepare.cpp
(51.16 KB)
📄
XRayInstrumentation.cpp
(9.66 KB)
Editing: CFIInstrInserter.cpp
//===------ CFIInstrInserter.cpp - Insert additional CFI instructions -----===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // /// \file This pass verifies incoming and outgoing CFA information of basic /// blocks. CFA information is information about offset and register set by CFI /// directives, valid at the start and end of a basic block. This pass checks /// that outgoing information of predecessors matches incoming information of /// their successors. Then it checks if blocks have correct CFA calculation rule /// set and inserts additional CFI instruction at their beginnings if they /// don't. CFI instructions are inserted if basic blocks have incorrect offset /// or register set by previous blocks, as a result of a non-linear layout of /// blocks in a function. //===----------------------------------------------------------------------===// #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SetOperations.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetFrameLowering.h" #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/InitializePasses.h" #include "llvm/Target/TargetMachine.h" using namespace llvm; static cl::opt<bool> VerifyCFI("verify-cfiinstrs", cl::desc("Verify Call Frame Information instructions"), cl::init(false), cl::Hidden); namespace { class CFIInstrInserter : public MachineFunctionPass { public: static char ID; CFIInstrInserter() : MachineFunctionPass(ID) { initializeCFIInstrInserterPass(*PassRegistry::getPassRegistry()); } void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesAll(); MachineFunctionPass::getAnalysisUsage(AU); } bool runOnMachineFunction(MachineFunction &MF) override { if (!MF.needsFrameMoves()) return false; MBBVector.resize(MF.getNumBlockIDs()); calculateCFAInfo(MF); if (VerifyCFI) { if (unsigned ErrorNum = verify(MF)) report_fatal_error("Found " + Twine(ErrorNum) + " in/out CFI information errors."); } bool insertedCFI = insertCFIInstrs(MF); MBBVector.clear(); return insertedCFI; } private: struct MBBCFAInfo { MachineBasicBlock *MBB; /// Value of cfa offset valid at basic block entry. int IncomingCFAOffset = -1; /// Value of cfa offset valid at basic block exit. int OutgoingCFAOffset = -1; /// Value of cfa register valid at basic block entry. unsigned IncomingCFARegister = 0; /// Value of cfa register valid at basic block exit. unsigned OutgoingCFARegister = 0; /// Set of callee saved registers saved at basic block entry. BitVector IncomingCSRSaved; /// Set of callee saved registers saved at basic block exit. BitVector OutgoingCSRSaved; /// If in/out cfa offset and register values for this block have already /// been set or not. bool Processed = false; }; #define INVALID_REG UINT_MAX #define INVALID_OFFSET INT_MAX /// contains the location where CSR register is saved. struct CSRSavedLocation { CSRSavedLocation(Optional<unsigned> R, Optional<int> O) : Reg(R), Offset(O) {} Optional<unsigned> Reg; Optional<int> Offset; }; /// Contains cfa offset and register values valid at entry and exit of basic /// blocks. std::vector<MBBCFAInfo> MBBVector; /// Map the callee save registers to the locations where they are saved. SmallDenseMap<unsigned, CSRSavedLocation, 16> CSRLocMap; /// Calculate cfa offset and register values valid at entry and exit for all /// basic blocks in a function. void calculateCFAInfo(MachineFunction &MF); /// Calculate cfa offset and register values valid at basic block exit by /// checking the block for CFI instructions. Block's incoming CFA info remains /// the same. void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo); /// Update in/out cfa offset and register values for successors of the basic /// block. void updateSuccCFAInfo(MBBCFAInfo &MBBInfo); /// Check if incoming CFA information of a basic block matches outgoing CFA /// information of the previous block. If it doesn't, insert CFI instruction /// at the beginning of the block that corrects the CFA calculation rule for /// that block. bool insertCFIInstrs(MachineFunction &MF); /// Return the cfa offset value that should be set at the beginning of a MBB /// if needed. The negated value is needed when creating CFI instructions that /// set absolute offset. int getCorrectCFAOffset(MachineBasicBlock *MBB) { return MBBVector[MBB->getNumber()].IncomingCFAOffset; } void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ); void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ); /// Go through each MBB in a function and check that outgoing offset and /// register of its predecessors match incoming offset and register of that /// MBB, as well as that incoming offset and register of its successors match /// outgoing offset and register of the MBB. unsigned verify(MachineFunction &MF); }; } // namespace char CFIInstrInserter::ID = 0; INITIALIZE_PASS(CFIInstrInserter, "cfi-instr-inserter", "Check CFA info and insert CFI instructions if needed", false, false) FunctionPass *llvm::createCFIInstrInserter() { return new CFIInstrInserter(); } void CFIInstrInserter::calculateCFAInfo(MachineFunction &MF) { // Initial CFA offset value i.e. the one valid at the beginning of the // function. int InitialOffset = MF.getSubtarget().getFrameLowering()->getInitialCFAOffset(MF); // Initial CFA register value i.e. the one valid at the beginning of the // function. unsigned InitialRegister = MF.getSubtarget().getFrameLowering()->getInitialCFARegister(MF); const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); unsigned NumRegs = TRI.getNumRegs(); // Initialize MBBMap. for (MachineBasicBlock &MBB : MF) { MBBCFAInfo MBBInfo; MBBInfo.MBB = &MBB; MBBInfo.IncomingCFAOffset = InitialOffset; MBBInfo.OutgoingCFAOffset = InitialOffset; MBBInfo.IncomingCFARegister = InitialRegister; MBBInfo.OutgoingCFARegister = InitialRegister; MBBInfo.IncomingCSRSaved.resize(NumRegs); MBBInfo.OutgoingCSRSaved.resize(NumRegs); MBBVector[MBB.getNumber()] = MBBInfo; } CSRLocMap.clear(); // Set in/out cfa info for all blocks in the function. This traversal is based // on the assumption that the first block in the function is the entry block // i.e. that it has initial cfa offset and register values as incoming CFA // information. updateSuccCFAInfo(MBBVector[MF.front().getNumber()]); } void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) { // Outgoing cfa offset set by the block. int SetOffset = MBBInfo.IncomingCFAOffset; // Outgoing cfa register set by the block. unsigned SetRegister = MBBInfo.IncomingCFARegister; MachineFunction *MF = MBBInfo.MBB->getParent(); const std::vector<MCCFIInstruction> &Instrs = MF->getFrameInstructions(); const TargetRegisterInfo &TRI = *MF->getSubtarget().getRegisterInfo(); unsigned NumRegs = TRI.getNumRegs(); BitVector CSRSaved(NumRegs), CSRRestored(NumRegs); // Determine cfa offset and register set by the block. for (MachineInstr &MI : *MBBInfo.MBB) { if (MI.isCFIInstruction()) { Optional<unsigned> CSRReg; Optional<int> CSROffset; unsigned CFIIndex = MI.getOperand(0).getCFIIndex(); const MCCFIInstruction &CFI = Instrs[CFIIndex]; switch (CFI.getOperation()) { case MCCFIInstruction::OpDefCfaRegister: SetRegister = CFI.getRegister(); break; case MCCFIInstruction::OpDefCfaOffset: SetOffset = CFI.getOffset(); break; case MCCFIInstruction::OpAdjustCfaOffset: SetOffset += CFI.getOffset(); break; case MCCFIInstruction::OpDefCfa: SetRegister = CFI.getRegister(); SetOffset = CFI.getOffset(); break; case MCCFIInstruction::OpOffset: CSROffset = CFI.getOffset(); break; case MCCFIInstruction::OpRegister: CSRReg = CFI.getRegister2(); break; case MCCFIInstruction::OpRelOffset: CSROffset = CFI.getOffset() - SetOffset; break; case MCCFIInstruction::OpRestore: CSRRestored.set(CFI.getRegister()); break; case MCCFIInstruction::OpRememberState: // TODO: Add support for handling cfi_remember_state. #ifndef NDEBUG report_fatal_error( "Support for cfi_remember_state not implemented! Value of CFA " "may be incorrect!\n"); #endif break; case MCCFIInstruction::OpRestoreState: // TODO: Add support for handling cfi_restore_state. #ifndef NDEBUG report_fatal_error( "Support for cfi_restore_state not implemented! Value of CFA may " "be incorrect!\n"); #endif break; // Other CFI directives do not affect CFA value. case MCCFIInstruction::OpUndefined: case MCCFIInstruction::OpSameValue: case MCCFIInstruction::OpEscape: case MCCFIInstruction::OpWindowSave: case MCCFIInstruction::OpNegateRAState: case MCCFIInstruction::OpGnuArgsSize: break; } if (CSRReg || CSROffset) { auto It = CSRLocMap.find(CFI.getRegister()); if (It == CSRLocMap.end()) { CSRLocMap.insert( {CFI.getRegister(), CSRSavedLocation(CSRReg, CSROffset)}); } else if (It->second.Reg != CSRReg || It->second.Offset != CSROffset) { llvm_unreachable("Different saved locations for the same CSR"); } CSRSaved.set(CFI.getRegister()); } } } MBBInfo.Processed = true; // Update outgoing CFA info. MBBInfo.OutgoingCFAOffset = SetOffset; MBBInfo.OutgoingCFARegister = SetRegister; // Update outgoing CSR info. MBBInfo.OutgoingCSRSaved = MBBInfo.IncomingCSRSaved; MBBInfo.OutgoingCSRSaved |= CSRSaved; MBBInfo.OutgoingCSRSaved.reset(CSRRestored); } void CFIInstrInserter::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) { SmallVector<MachineBasicBlock *, 4> Stack; Stack.push_back(MBBInfo.MBB); do { MachineBasicBlock *Current = Stack.pop_back_val(); MBBCFAInfo &CurrentInfo = MBBVector[Current->getNumber()]; calculateOutgoingCFAInfo(CurrentInfo); for (auto *Succ : CurrentInfo.MBB->successors()) { MBBCFAInfo &SuccInfo = MBBVector[Succ->getNumber()]; if (!SuccInfo.Processed) { SuccInfo.IncomingCFAOffset = CurrentInfo.OutgoingCFAOffset; SuccInfo.IncomingCFARegister = CurrentInfo.OutgoingCFARegister; SuccInfo.IncomingCSRSaved = CurrentInfo.OutgoingCSRSaved; Stack.push_back(Succ); } } } while (!Stack.empty()); } bool CFIInstrInserter::insertCFIInstrs(MachineFunction &MF) { const MBBCFAInfo *PrevMBBInfo = &MBBVector[MF.front().getNumber()]; const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo(); bool InsertedCFIInstr = false; for (MachineBasicBlock &MBB : MF) { // Skip the first MBB in a function if (MBB.getNumber() == MF.front().getNumber()) continue; const MBBCFAInfo &MBBInfo = MBBVector[MBB.getNumber()]; auto MBBI = MBBInfo.MBB->begin(); DebugLoc DL = MBBInfo.MBB->findDebugLoc(MBBI); // If the current MBB will be placed in a unique section, a full DefCfa // must be emitted. const bool ForceFullCFA = MBB.isBeginSection(); if ((PrevMBBInfo->OutgoingCFAOffset != MBBInfo.IncomingCFAOffset && PrevMBBInfo->OutgoingCFARegister != MBBInfo.IncomingCFARegister) || ForceFullCFA) { // If both outgoing offset and register of a previous block don't match // incoming offset and register of this block, or if this block begins a // section, add a def_cfa instruction with the correct offset and // register for this block. unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa( nullptr, MBBInfo.IncomingCFARegister, getCorrectCFAOffset(&MBB))); BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION)) .addCFIIndex(CFIIndex); InsertedCFIInstr = true; } else if (PrevMBBInfo->OutgoingCFAOffset != MBBInfo.IncomingCFAOffset) { // If outgoing offset of a previous block doesn't match incoming offset // of this block, add a def_cfa_offset instruction with the correct // offset for this block. unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset( nullptr, getCorrectCFAOffset(&MBB))); BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION)) .addCFIIndex(CFIIndex); InsertedCFIInstr = true; } else if (PrevMBBInfo->OutgoingCFARegister != MBBInfo.IncomingCFARegister) { unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createDefCfaRegister( nullptr, MBBInfo.IncomingCFARegister)); BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION)) .addCFIIndex(CFIIndex); InsertedCFIInstr = true; } if (ForceFullCFA) { MF.getSubtarget().getFrameLowering()->emitCalleeSavedFrameMoves( *MBBInfo.MBB, MBBI); InsertedCFIInstr = true; PrevMBBInfo = &MBBInfo; continue; } BitVector SetDifference = PrevMBBInfo->OutgoingCSRSaved; SetDifference.reset(MBBInfo.IncomingCSRSaved); for (int Reg : SetDifference.set_bits()) { unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, Reg)); BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION)) .addCFIIndex(CFIIndex); InsertedCFIInstr = true; } SetDifference = MBBInfo.IncomingCSRSaved; SetDifference.reset(PrevMBBInfo->OutgoingCSRSaved); for (int Reg : SetDifference.set_bits()) { auto it = CSRLocMap.find(Reg); assert(it != CSRLocMap.end() && "Reg should have an entry in CSRLocMap"); unsigned CFIIndex; CSRSavedLocation RO = it->second; if (!RO.Reg && RO.Offset) { CFIIndex = MF.addFrameInst( MCCFIInstruction::createOffset(nullptr, Reg, *RO.Offset)); } else if (RO.Reg && !RO.Offset) { CFIIndex = MF.addFrameInst( MCCFIInstruction::createRegister(nullptr, Reg, *RO.Reg)); } else { llvm_unreachable("RO.Reg and RO.Offset cannot both be valid/invalid"); } BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION)) .addCFIIndex(CFIIndex); InsertedCFIInstr = true; } PrevMBBInfo = &MBBInfo; } return InsertedCFIInstr; } void CFIInstrInserter::reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ) { errs() << "*** Inconsistent CFA register and/or offset between pred and succ " "***\n"; errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber() << " in " << Pred.MBB->getParent()->getName() << " outgoing CFA Reg:" << Pred.OutgoingCFARegister << "\n"; errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber() << " in " << Pred.MBB->getParent()->getName() << " outgoing CFA Offset:" << Pred.OutgoingCFAOffset << "\n"; errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber() << " incoming CFA Reg:" << Succ.IncomingCFARegister << "\n"; errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber() << " incoming CFA Offset:" << Succ.IncomingCFAOffset << "\n"; } void CFIInstrInserter::reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ) { errs() << "*** Inconsistent CSR Saved between pred and succ in function " << Pred.MBB->getParent()->getName() << " ***\n"; errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber() << " outgoing CSR Saved: "; for (int Reg : Pred.OutgoingCSRSaved.set_bits()) errs() << Reg << " "; errs() << "\n"; errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber() << " incoming CSR Saved: "; for (int Reg : Succ.IncomingCSRSaved.set_bits()) errs() << Reg << " "; errs() << "\n"; } unsigned CFIInstrInserter::verify(MachineFunction &MF) { unsigned ErrorNum = 0; for (auto *CurrMBB : depth_first(&MF)) { const MBBCFAInfo &CurrMBBInfo = MBBVector[CurrMBB->getNumber()]; for (MachineBasicBlock *Succ : CurrMBB->successors()) { const MBBCFAInfo &SuccMBBInfo = MBBVector[Succ->getNumber()]; // Check that incoming offset and register values of successors match the // outgoing offset and register values of CurrMBB if (SuccMBBInfo.IncomingCFAOffset != CurrMBBInfo.OutgoingCFAOffset || SuccMBBInfo.IncomingCFARegister != CurrMBBInfo.OutgoingCFARegister) { // Inconsistent offsets/registers are ok for 'noreturn' blocks because // we don't generate epilogues inside such blocks. if (SuccMBBInfo.MBB->succ_empty() && !SuccMBBInfo.MBB->isReturnBlock()) continue; reportCFAError(CurrMBBInfo, SuccMBBInfo); ErrorNum++; } // Check that IncomingCSRSaved of every successor matches the // OutgoingCSRSaved of CurrMBB if (SuccMBBInfo.IncomingCSRSaved != CurrMBBInfo.OutgoingCSRSaved) { reportCSRError(CurrMBBInfo, SuccMBBInfo); ErrorNum++; } } } return ErrorNum; }
Upload File
Create Folder