1 //===- llvm/CodeGen/MachineFunction.h ---------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Collect native machine code for a function. This class contains a list of 10 // MachineBasicBlock instances that make up the current compiled function. 11 // 12 // This class also contains pointers to various classes which hold 13 // target-specific information about the generated code. 14 // 15 //===----------------------------------------------------------------------===// 16 17 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H 18 #define LLVM_CODEGEN_MACHINEFUNCTION_H 19 20 #include "llvm/ADT/ArrayRef.h" 21 #include "llvm/ADT/BitVector.h" 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/GraphTraits.h" 24 #include "llvm/ADT/SmallVector.h" 25 #include "llvm/ADT/ilist.h" 26 #include "llvm/ADT/iterator.h" 27 #include "llvm/Analysis/EHPersonalities.h" 28 #include "llvm/CodeGen/MachineBasicBlock.h" 29 #include "llvm/CodeGen/MachineInstr.h" 30 #include "llvm/CodeGen/MachineMemOperand.h" 31 #include "llvm/Support/Allocator.h" 32 #include "llvm/Support/ArrayRecycler.h" 33 #include "llvm/Support/AtomicOrdering.h" 34 #include "llvm/Support/Compiler.h" 35 #include "llvm/Support/Recycler.h" 36 #include "llvm/Target/TargetOptions.h" 37 #include <cassert> 38 #include <cstdint> 39 #include <memory> 40 #include <utility> 41 #include <vector> 42 43 namespace llvm { 44 45 class BasicBlock; 46 class BlockAddress; 47 class DataLayout; 48 class DebugLoc; 49 struct DenormalMode; 50 class DIExpression; 51 class DILocalVariable; 52 class DILocation; 53 class Function; 54 class GISelChangeObserver; 55 class GlobalValue; 56 class LLVMTargetMachine; 57 class MachineConstantPool; 58 class MachineFrameInfo; 59 class MachineFunction; 60 class MachineJumpTableInfo; 61 class MachineModuleInfo; 62 class MachineRegisterInfo; 63 class MCContext; 64 class MCInstrDesc; 65 class MCSymbol; 66 class MCSection; 67 class Pass; 68 class PseudoSourceValueManager; 69 class raw_ostream; 70 class SlotIndexes; 71 class StringRef; 72 class TargetRegisterClass; 73 class TargetSubtargetInfo; 74 struct WasmEHFuncInfo; 75 struct WinEHFuncInfo; 76 77 template <> struct ilist_alloc_traits<MachineBasicBlock> { 78 void deleteNode(MachineBasicBlock *MBB); 79 }; 80 81 template <> struct ilist_callback_traits<MachineBasicBlock> { 82 void addNodeToList(MachineBasicBlock* N); 83 void removeNodeFromList(MachineBasicBlock* N); 84 85 template <class Iterator> 86 void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator) { 87 assert(this == &OldList && "never transfer MBBs between functions"); 88 } 89 }; 90 91 /// MachineFunctionInfo - This class can be derived from and used by targets to 92 /// hold private target-specific information for each MachineFunction. Objects 93 /// of type are accessed/created with MF::getInfo and destroyed when the 94 /// MachineFunction is destroyed. 95 struct MachineFunctionInfo { 96 virtual ~MachineFunctionInfo(); 97 98 /// Factory function: default behavior is to call new using the 99 /// supplied allocator. 100 /// 101 /// This function can be overridden in a derive class. 102 template<typename Ty> 103 static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { 104 return new (Allocator.Allocate<Ty>()) Ty(MF); 105 } 106 }; 107 108 /// Properties which a MachineFunction may have at a given point in time. 109 /// Each of these has checking code in the MachineVerifier, and passes can 110 /// require that a property be set. 111 class MachineFunctionProperties { 112 // Possible TODO: Allow targets to extend this (perhaps by allowing the 113 // constructor to specify the size of the bit vector) 114 // Possible TODO: Allow requiring the negative (e.g. VRegsAllocated could be 115 // stated as the negative of "has vregs" 116 117 public: 118 // The properties are stated in "positive" form; i.e. a pass could require 119 // that the property hold, but not that it does not hold. 120 121 // Property descriptions: 122 // IsSSA: True when the machine function is in SSA form and virtual registers 123 // have a single def. 124 // NoPHIs: The machine function does not contain any PHI instruction. 125 // TracksLiveness: True when tracking register liveness accurately. 126 // While this property is set, register liveness information in basic block 127 // live-in lists and machine instruction operands (e.g. implicit defs) is 128 // accurate, kill flags are conservatively accurate (kill flag correctly 129 // indicates the last use of a register, an operand without kill flag may or 130 // may not be the last use of a register). This means it can be used to 131 // change the code in ways that affect the values in registers, for example 132 // by the register scavenger. 133 // When this property is cleared at a very late time, liveness is no longer 134 // reliable. 135 // NoVRegs: The machine function does not use any virtual registers. 136 // Legalized: In GlobalISel: the MachineLegalizer ran and all pre-isel generic 137 // instructions have been legalized; i.e., all instructions are now one of: 138 // - generic and always legal (e.g., COPY) 139 // - target-specific 140 // - legal pre-isel generic instructions. 141 // RegBankSelected: In GlobalISel: the RegBankSelect pass ran and all generic 142 // virtual registers have been assigned to a register bank. 143 // Selected: In GlobalISel: the InstructionSelect pass ran and all pre-isel 144 // generic instructions have been eliminated; i.e., all instructions are now 145 // target-specific or non-pre-isel generic instructions (e.g., COPY). 146 // Since only pre-isel generic instructions can have generic virtual register 147 // operands, this also means that all generic virtual registers have been 148 // constrained to virtual registers (assigned to register classes) and that 149 // all sizes attached to them have been eliminated. 150 // TiedOpsRewritten: The twoaddressinstruction pass will set this flag, it 151 // means that tied-def have been rewritten to meet the RegConstraint. 152 enum class Property : unsigned { 153 IsSSA, 154 NoPHIs, 155 TracksLiveness, 156 NoVRegs, 157 FailedISel, 158 Legalized, 159 RegBankSelected, 160 Selected, 161 TiedOpsRewritten, 162 LastProperty = TiedOpsRewritten, 163 }; 164 165 bool hasProperty(Property P) const { 166 return Properties[static_cast<unsigned>(P)]; 167 } 168 169 MachineFunctionProperties &set(Property P) { 170 Properties.set(static_cast<unsigned>(P)); 171 return *this; 172 } 173 174 MachineFunctionProperties &reset(Property P) { 175 Properties.reset(static_cast<unsigned>(P)); 176 return *this; 177 } 178 179 /// Reset all the properties. 180 MachineFunctionProperties &reset() { 181 Properties.reset(); 182 return *this; 183 } 184 185 MachineFunctionProperties &set(const MachineFunctionProperties &MFP) { 186 Properties |= MFP.Properties; 187 return *this; 188 } 189 190 MachineFunctionProperties &reset(const MachineFunctionProperties &MFP) { 191 Properties.reset(MFP.Properties); 192 return *this; 193 } 194 195 // Returns true if all properties set in V (i.e. required by a pass) are set 196 // in this. 197 bool verifyRequiredProperties(const MachineFunctionProperties &V) const { 198 return !V.Properties.test(Properties); 199 } 200 201 /// Print the MachineFunctionProperties in human-readable form. 202 void print(raw_ostream &OS) const; 203 204 private: 205 BitVector Properties = 206 BitVector(static_cast<unsigned>(Property::LastProperty)+1); 207 }; 208 209 struct SEHHandler { 210 /// Filter or finally function. Null indicates a catch-all. 211 const Function *FilterOrFinally; 212 213 /// Address of block to recover at. Null for a finally handler. 214 const BlockAddress *RecoverBA; 215 }; 216 217 /// This structure is used to retain landing pad info for the current function. 218 struct LandingPadInfo { 219 MachineBasicBlock *LandingPadBlock; // Landing pad block. 220 SmallVector<MCSymbol *, 1> BeginLabels; // Labels prior to invoke. 221 SmallVector<MCSymbol *, 1> EndLabels; // Labels after invoke. 222 SmallVector<SEHHandler, 1> SEHHandlers; // SEH handlers active at this lpad. 223 MCSymbol *LandingPadLabel = nullptr; // Label at beginning of landing pad. 224 std::vector<int> TypeIds; // List of type ids (filters negative). 225 226 explicit LandingPadInfo(MachineBasicBlock *MBB) 227 : LandingPadBlock(MBB) {} 228 }; 229 230 class LLVM_EXTERNAL_VISIBILITY MachineFunction { 231 Function &F; 232 const LLVMTargetMachine &Target; 233 const TargetSubtargetInfo *STI; 234 MCContext &Ctx; 235 MachineModuleInfo &MMI; 236 237 // RegInfo - Information about each register in use in the function. 238 MachineRegisterInfo *RegInfo; 239 240 // Used to keep track of target-specific per-machine function information for 241 // the target implementation. 242 MachineFunctionInfo *MFInfo; 243 244 // Keep track of objects allocated on the stack. 245 MachineFrameInfo *FrameInfo; 246 247 // Keep track of constants which are spilled to memory 248 MachineConstantPool *ConstantPool; 249 250 // Keep track of jump tables for switch instructions 251 MachineJumpTableInfo *JumpTableInfo; 252 253 // Keep track of the function section. 254 MCSection *Section = nullptr; 255 256 // Keeps track of Wasm exception handling related data. This will be null for 257 // functions that aren't using a wasm EH personality. 258 WasmEHFuncInfo *WasmEHInfo = nullptr; 259 260 // Keeps track of Windows exception handling related data. This will be null 261 // for functions that aren't using a funclet-based EH personality. 262 WinEHFuncInfo *WinEHInfo = nullptr; 263 264 // Function-level unique numbering for MachineBasicBlocks. When a 265 // MachineBasicBlock is inserted into a MachineFunction is it automatically 266 // numbered and this vector keeps track of the mapping from ID's to MBB's. 267 std::vector<MachineBasicBlock*> MBBNumbering; 268 269 // Unary encoding of basic block symbols is used to reduce size of ".strtab". 270 // Basic block number 'i' gets a prefix of length 'i'. The ith character also 271 // denotes the type of basic block number 'i'. Return blocks are marked with 272 // 'r', landing pads with 'l' and regular blocks with 'a'. 273 std::vector<char> BBSectionsSymbolPrefix; 274 275 // Pool-allocate MachineFunction-lifetime and IR objects. 276 BumpPtrAllocator Allocator; 277 278 // Allocation management for instructions in function. 279 Recycler<MachineInstr> InstructionRecycler; 280 281 // Allocation management for operand arrays on instructions. 282 ArrayRecycler<MachineOperand> OperandRecycler; 283 284 // Allocation management for basic blocks in function. 285 Recycler<MachineBasicBlock> BasicBlockRecycler; 286 287 // List of machine basic blocks in function 288 using BasicBlockListType = ilist<MachineBasicBlock>; 289 BasicBlockListType BasicBlocks; 290 291 /// FunctionNumber - This provides a unique ID for each function emitted in 292 /// this translation unit. 293 /// 294 unsigned FunctionNumber; 295 296 /// Alignment - The alignment of the function. 297 Align Alignment; 298 299 /// ExposesReturnsTwice - True if the function calls setjmp or related 300 /// functions with attribute "returns twice", but doesn't have 301 /// the attribute itself. 302 /// This is used to limit optimizations which cannot reason 303 /// about the control flow of such functions. 304 bool ExposesReturnsTwice = false; 305 306 /// True if the function includes any inline assembly. 307 bool HasInlineAsm = false; 308 309 /// True if any WinCFI instruction have been emitted in this function. 310 bool HasWinCFI = false; 311 312 /// Current high-level properties of the IR of the function (e.g. is in SSA 313 /// form or whether registers have been allocated) 314 MachineFunctionProperties Properties; 315 316 // Allocation management for pseudo source values. 317 std::unique_ptr<PseudoSourceValueManager> PSVManager; 318 319 /// List of moves done by a function's prolog. Used to construct frame maps 320 /// by debug and exception handling consumers. 321 std::vector<MCCFIInstruction> FrameInstructions; 322 323 /// List of basic blocks immediately following calls to _setjmp. Used to 324 /// construct a table of valid longjmp targets for Windows Control Flow Guard. 325 std::vector<MCSymbol *> LongjmpTargets; 326 327 /// List of basic blocks that are the target of catchrets. Used to construct 328 /// a table of valid targets for Windows EHCont Guard. 329 std::vector<MCSymbol *> CatchretTargets; 330 331 /// \name Exception Handling 332 /// \{ 333 334 /// List of LandingPadInfo describing the landing pad information. 335 std::vector<LandingPadInfo> LandingPads; 336 337 /// Map a landing pad's EH symbol to the call site indexes. 338 DenseMap<MCSymbol*, SmallVector<unsigned, 4>> LPadToCallSiteMap; 339 340 /// Map a landing pad to its index. 341 DenseMap<const MachineBasicBlock *, unsigned> WasmLPadToIndexMap; 342 343 /// Map of invoke call site index values to associated begin EH_LABEL. 344 DenseMap<MCSymbol*, unsigned> CallSiteMap; 345 346 /// CodeView label annotations. 347 std::vector<std::pair<MCSymbol *, MDNode *>> CodeViewAnnotations; 348 349 bool CallsEHReturn = false; 350 bool CallsUnwindInit = false; 351 bool HasEHCatchret = false; 352 bool HasEHScopes = false; 353 bool HasEHFunclets = false; 354 355 /// Section Type for basic blocks, only relevant with basic block sections. 356 BasicBlockSection BBSectionsType = BasicBlockSection::None; 357 358 /// List of C++ TypeInfo used. 359 std::vector<const GlobalValue *> TypeInfos; 360 361 /// List of typeids encoding filters used. 362 std::vector<unsigned> FilterIds; 363 364 /// List of the indices in FilterIds corresponding to filter terminators. 365 std::vector<unsigned> FilterEnds; 366 367 EHPersonality PersonalityTypeCache = EHPersonality::Unknown; 368 369 /// \} 370 371 /// Clear all the members of this MachineFunction, but the ones used 372 /// to initialize again the MachineFunction. 373 /// More specifically, this deallocates all the dynamically allocated 374 /// objects and get rid of all the XXXInfo data structure, but keep 375 /// unchanged the references to Fn, Target, MMI, and FunctionNumber. 376 void clear(); 377 /// Allocate and initialize the different members. 378 /// In particular, the XXXInfo data structure. 379 /// \pre Fn, Target, MMI, and FunctionNumber are properly set. 380 void init(); 381 382 public: 383 struct VariableDbgInfo { 384 const DILocalVariable *Var; 385 const DIExpression *Expr; 386 // The Slot can be negative for fixed stack objects. 387 int Slot; 388 const DILocation *Loc; 389 390 VariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, 391 int Slot, const DILocation *Loc) 392 : Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {} 393 }; 394 395 class Delegate { 396 virtual void anchor(); 397 398 public: 399 virtual ~Delegate() = default; 400 /// Callback after an insertion. This should not modify the MI directly. 401 virtual void MF_HandleInsertion(MachineInstr &MI) = 0; 402 /// Callback before a removal. This should not modify the MI directly. 403 virtual void MF_HandleRemoval(MachineInstr &MI) = 0; 404 }; 405 406 /// Structure used to represent pair of argument number after call lowering 407 /// and register used to transfer that argument. 408 /// For now we support only cases when argument is transferred through one 409 /// register. 410 struct ArgRegPair { 411 Register Reg; 412 uint16_t ArgNo; 413 ArgRegPair(Register R, unsigned Arg) : Reg(R), ArgNo(Arg) { 414 assert(Arg < (1 << 16) && "Arg out of range"); 415 } 416 }; 417 /// Vector of call argument and its forwarding register. 418 using CallSiteInfo = SmallVector<ArgRegPair, 1>; 419 using CallSiteInfoImpl = SmallVectorImpl<ArgRegPair>; 420 421 private: 422 Delegate *TheDelegate = nullptr; 423 GISelChangeObserver *Observer = nullptr; 424 425 using CallSiteInfoMap = DenseMap<const MachineInstr *, CallSiteInfo>; 426 /// Map a call instruction to call site arguments forwarding info. 427 CallSiteInfoMap CallSitesInfo; 428 429 /// A helper function that returns call site info for a give call 430 /// instruction if debug entry value support is enabled. 431 CallSiteInfoMap::iterator getCallSiteInfo(const MachineInstr *MI); 432 433 // Callbacks for insertion and removal. 434 void handleInsertion(MachineInstr &MI); 435 void handleRemoval(MachineInstr &MI); 436 friend struct ilist_traits<MachineInstr>; 437 438 public: 439 using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>; 440 VariableDbgInfoMapTy VariableDbgInfos; 441 442 /// A count of how many instructions in the function have had numbers 443 /// assigned to them. Used for debug value tracking, to determine the 444 /// next instruction number. 445 unsigned DebugInstrNumberingCount = 0; 446 447 /// Set value of DebugInstrNumberingCount field. Avoid using this unless 448 /// you're deserializing this data. 449 void setDebugInstrNumberingCount(unsigned Num); 450 451 /// Pair of instruction number and operand number. 452 using DebugInstrOperandPair = std::pair<unsigned, unsigned>; 453 454 /// Replacement definition for a debug instruction reference. Made up of a 455 /// source instruction / operand pair, destination pair, and a qualifying 456 /// subregister indicating what bits in the operand make up the substitution. 457 // For example, a debug user 458 /// of %1: 459 /// %0:gr32 = someinst, debug-instr-number 1 460 /// %1:gr16 = %0.some_16_bit_subreg, debug-instr-number 2 461 /// Would receive the substitution {{2, 0}, {1, 0}, $subreg}, where $subreg is 462 /// the subregister number for some_16_bit_subreg. 463 class DebugSubstitution { 464 public: 465 DebugInstrOperandPair Src; ///< Source instruction / operand pair. 466 DebugInstrOperandPair Dest; ///< Replacement instruction / operand pair. 467 unsigned Subreg; ///< Qualifier for which part of Dest is read. 468 469 DebugSubstitution(const DebugInstrOperandPair &Src, 470 const DebugInstrOperandPair &Dest, unsigned Subreg) 471 : Src(Src), Dest(Dest), Subreg(Subreg) {} 472 473 /// Order only by source instruction / operand pair: there should never 474 /// be duplicate entries for the same source in any collection. 475 bool operator<(const DebugSubstitution &Other) const { 476 return Src < Other.Src; 477 } 478 }; 479 480 /// Debug value substitutions: a collection of DebugSubstitution objects, 481 /// recording changes in where a value is defined. For example, when one 482 /// instruction is substituted for another. Keeping a record allows recovery 483 /// of variable locations after compilation finishes. 484 SmallVector<DebugSubstitution, 8> DebugValueSubstitutions; 485 486 /// Location of a PHI instruction that is also a debug-info variable value, 487 /// for the duration of register allocation. Loaded by the PHI-elimination 488 /// pass, and emitted as DBG_PHI instructions during VirtRegRewriter, with 489 /// maintenance applied by intermediate passes that edit registers (such as 490 /// coalescing and the allocator passes). 491 class DebugPHIRegallocPos { 492 public: 493 MachineBasicBlock *MBB; ///< Block where this PHI was originally located. 494 Register Reg; ///< VReg where the control-flow-merge happens. 495 unsigned SubReg; ///< Optional subreg qualifier within Reg. 496 DebugPHIRegallocPos(MachineBasicBlock *MBB, Register Reg, unsigned SubReg) 497 : MBB(MBB), Reg(Reg), SubReg(SubReg) {} 498 }; 499 500 /// Map of debug instruction numbers to the position of their PHI instructions 501 /// during register allocation. See DebugPHIRegallocPos. 502 DenseMap<unsigned, DebugPHIRegallocPos> DebugPHIPositions; 503 504 /// Create a substitution between one <instr,operand> value to a different, 505 /// new value. 506 void makeDebugValueSubstitution(DebugInstrOperandPair, DebugInstrOperandPair, 507 unsigned SubReg = 0); 508 509 /// Create substitutions for any tracked values in \p Old, to point at 510 /// \p New. Needed when we re-create an instruction during optimization, 511 /// which has the same signature (i.e., def operands in the same place) but 512 /// a modified instruction type, flags, or otherwise. An example: X86 moves 513 /// are sometimes transformed into equivalent LEAs. 514 /// If the two instructions are not the same opcode, limit which operands to 515 /// examine for substitutions to the first N operands by setting 516 /// \p MaxOperand. 517 void substituteDebugValuesForInst(const MachineInstr &Old, MachineInstr &New, 518 unsigned MaxOperand = UINT_MAX); 519 520 /// Find the underlying defining instruction / operand for a COPY instruction 521 /// while in SSA form. Copies do not actually define values -- they move them 522 /// between registers. Labelling a COPY-like instruction with an instruction 523 /// number is to be avoided as it makes value numbers non-unique later in 524 /// compilation. This method follows the definition chain for any sequence of 525 /// COPY-like instructions to find whatever non-COPY-like instruction defines 526 /// the copied value; or for parameters, creates a DBG_PHI on entry. 527 /// May insert instructions into the entry block! 528 /// \p MI The copy-like instruction to salvage. 529 /// \returns An instruction/operand pair identifying the defining value. 530 DebugInstrOperandPair salvageCopySSA(MachineInstr &MI); 531 532 /// Finalise any partially emitted debug instructions. These are DBG_INSTR_REF 533 /// instructions where we only knew the vreg of the value they use, not the 534 /// instruction that defines that vreg. Once isel finishes, we should have 535 /// enough information for every DBG_INSTR_REF to point at an instruction 536 /// (or DBG_PHI). 537 void finalizeDebugInstrRefs(); 538 539 MachineFunction(Function &F, const LLVMTargetMachine &Target, 540 const TargetSubtargetInfo &STI, unsigned FunctionNum, 541 MachineModuleInfo &MMI); 542 MachineFunction(const MachineFunction &) = delete; 543 MachineFunction &operator=(const MachineFunction &) = delete; 544 ~MachineFunction(); 545 546 /// Reset the instance as if it was just created. 547 void reset() { 548 clear(); 549 init(); 550 } 551 552 /// Reset the currently registered delegate - otherwise assert. 553 void resetDelegate(Delegate *delegate) { 554 assert(TheDelegate == delegate && 555 "Only the current delegate can perform reset!"); 556 TheDelegate = nullptr; 557 } 558 559 /// Set the delegate. resetDelegate must be called before attempting 560 /// to set. 561 void setDelegate(Delegate *delegate) { 562 assert(delegate && !TheDelegate && 563 "Attempted to set delegate to null, or to change it without " 564 "first resetting it!"); 565 566 TheDelegate = delegate; 567 } 568 569 void setObserver(GISelChangeObserver *O) { Observer = O; } 570 571 GISelChangeObserver *getObserver() const { return Observer; } 572 573 MachineModuleInfo &getMMI() const { return MMI; } 574 MCContext &getContext() const { return Ctx; } 575 576 /// Returns the Section this function belongs to. 577 MCSection *getSection() const { return Section; } 578 579 /// Indicates the Section this function belongs to. 580 void setSection(MCSection *S) { Section = S; } 581 582 PseudoSourceValueManager &getPSVManager() const { return *PSVManager; } 583 584 /// Return the DataLayout attached to the Module associated to this MF. 585 const DataLayout &getDataLayout() const; 586 587 /// Return the LLVM function that this machine code represents 588 Function &getFunction() { return F; } 589 590 /// Return the LLVM function that this machine code represents 591 const Function &getFunction() const { return F; } 592 593 /// getName - Return the name of the corresponding LLVM function. 594 StringRef getName() const; 595 596 /// getFunctionNumber - Return a unique ID for the current function. 597 unsigned getFunctionNumber() const { return FunctionNumber; } 598 599 /// Returns true if this function has basic block sections enabled. 600 bool hasBBSections() const { 601 return (BBSectionsType == BasicBlockSection::All || 602 BBSectionsType == BasicBlockSection::List || 603 BBSectionsType == BasicBlockSection::Preset); 604 } 605 606 /// Returns true if basic block labels are to be generated for this function. 607 bool hasBBLabels() const { 608 return BBSectionsType == BasicBlockSection::Labels; 609 } 610 611 void setBBSectionsType(BasicBlockSection V) { BBSectionsType = V; } 612 613 /// Assign IsBeginSection IsEndSection fields for basic blocks in this 614 /// function. 615 void assignBeginEndSections(); 616 617 /// getTarget - Return the target machine this machine code is compiled with 618 const LLVMTargetMachine &getTarget() const { return Target; } 619 620 /// getSubtarget - Return the subtarget for which this machine code is being 621 /// compiled. 622 const TargetSubtargetInfo &getSubtarget() const { return *STI; } 623 624 /// getSubtarget - This method returns a pointer to the specified type of 625 /// TargetSubtargetInfo. In debug builds, it verifies that the object being 626 /// returned is of the correct type. 627 template<typename STC> const STC &getSubtarget() const { 628 return *static_cast<const STC *>(STI); 629 } 630 631 /// getRegInfo - Return information about the registers currently in use. 632 MachineRegisterInfo &getRegInfo() { return *RegInfo; } 633 const MachineRegisterInfo &getRegInfo() const { return *RegInfo; } 634 635 /// getFrameInfo - Return the frame info object for the current function. 636 /// This object contains information about objects allocated on the stack 637 /// frame of the current function in an abstract way. 638 MachineFrameInfo &getFrameInfo() { return *FrameInfo; } 639 const MachineFrameInfo &getFrameInfo() const { return *FrameInfo; } 640 641 /// getJumpTableInfo - Return the jump table info object for the current 642 /// function. This object contains information about jump tables in the 643 /// current function. If the current function has no jump tables, this will 644 /// return null. 645 const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; } 646 MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; } 647 648 /// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it 649 /// does already exist, allocate one. 650 MachineJumpTableInfo *getOrCreateJumpTableInfo(unsigned JTEntryKind); 651 652 /// getConstantPool - Return the constant pool object for the current 653 /// function. 654 MachineConstantPool *getConstantPool() { return ConstantPool; } 655 const MachineConstantPool *getConstantPool() const { return ConstantPool; } 656 657 /// getWasmEHFuncInfo - Return information about how the current function uses 658 /// Wasm exception handling. Returns null for functions that don't use wasm 659 /// exception handling. 660 const WasmEHFuncInfo *getWasmEHFuncInfo() const { return WasmEHInfo; } 661 WasmEHFuncInfo *getWasmEHFuncInfo() { return WasmEHInfo; } 662 663 /// getWinEHFuncInfo - Return information about how the current function uses 664 /// Windows exception handling. Returns null for functions that don't use 665 /// funclets for exception handling. 666 const WinEHFuncInfo *getWinEHFuncInfo() const { return WinEHInfo; } 667 WinEHFuncInfo *getWinEHFuncInfo() { return WinEHInfo; } 668 669 /// getAlignment - Return the alignment of the function. 670 Align getAlignment() const { return Alignment; } 671 672 /// setAlignment - Set the alignment of the function. 673 void setAlignment(Align A) { Alignment = A; } 674 675 /// ensureAlignment - Make sure the function is at least A bytes aligned. 676 void ensureAlignment(Align A) { 677 if (Alignment < A) 678 Alignment = A; 679 } 680 681 /// exposesReturnsTwice - Returns true if the function calls setjmp or 682 /// any other similar functions with attribute "returns twice" without 683 /// having the attribute itself. 684 bool exposesReturnsTwice() const { 685 return ExposesReturnsTwice; 686 } 687 688 /// setCallsSetJmp - Set a flag that indicates if there's a call to 689 /// a "returns twice" function. 690 void setExposesReturnsTwice(bool B) { 691 ExposesReturnsTwice = B; 692 } 693 694 /// Returns true if the function contains any inline assembly. 695 bool hasInlineAsm() const { 696 return HasInlineAsm; 697 } 698 699 /// Set a flag that indicates that the function contains inline assembly. 700 void setHasInlineAsm(bool B) { 701 HasInlineAsm = B; 702 } 703 704 bool hasWinCFI() const { 705 return HasWinCFI; 706 } 707 void setHasWinCFI(bool v) { HasWinCFI = v; } 708 709 /// True if this function needs frame moves for debug or exceptions. 710 bool needsFrameMoves() const; 711 712 /// Get the function properties 713 const MachineFunctionProperties &getProperties() const { return Properties; } 714 MachineFunctionProperties &getProperties() { return Properties; } 715 716 /// getInfo - Keep track of various per-function pieces of information for 717 /// backends that would like to do so. 718 /// 719 template<typename Ty> 720 Ty *getInfo() { 721 if (!MFInfo) 722 MFInfo = Ty::template create<Ty>(Allocator, *this); 723 return static_cast<Ty*>(MFInfo); 724 } 725 726 template<typename Ty> 727 const Ty *getInfo() const { 728 return const_cast<MachineFunction*>(this)->getInfo<Ty>(); 729 } 730 731 /// Returns the denormal handling type for the default rounding mode of the 732 /// function. 733 DenormalMode getDenormalMode(const fltSemantics &FPType) const; 734 735 /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they 736 /// are inserted into the machine function. The block number for a machine 737 /// basic block can be found by using the MBB::getNumber method, this method 738 /// provides the inverse mapping. 739 MachineBasicBlock *getBlockNumbered(unsigned N) const { 740 assert(N < MBBNumbering.size() && "Illegal block number"); 741 assert(MBBNumbering[N] && "Block was removed from the machine function!"); 742 return MBBNumbering[N]; 743 } 744 745 /// Should we be emitting segmented stack stuff for the function 746 bool shouldSplitStack() const; 747 748 /// getNumBlockIDs - Return the number of MBB ID's allocated. 749 unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); } 750 751 /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and 752 /// recomputes them. This guarantees that the MBB numbers are sequential, 753 /// dense, and match the ordering of the blocks within the function. If a 754 /// specific MachineBasicBlock is specified, only that block and those after 755 /// it are renumbered. 756 void RenumberBlocks(MachineBasicBlock *MBBFrom = nullptr); 757 758 /// print - Print out the MachineFunction in a format suitable for debugging 759 /// to the specified stream. 760 void print(raw_ostream &OS, const SlotIndexes* = nullptr) const; 761 762 /// viewCFG - This function is meant for use from the debugger. You can just 763 /// say 'call F->viewCFG()' and a ghostview window should pop up from the 764 /// program, displaying the CFG of the current function with the code for each 765 /// basic block inside. This depends on there being a 'dot' and 'gv' program 766 /// in your path. 767 void viewCFG() const; 768 769 /// viewCFGOnly - This function is meant for use from the debugger. It works 770 /// just like viewCFG, but it does not include the contents of basic blocks 771 /// into the nodes, just the label. If you are only interested in the CFG 772 /// this can make the graph smaller. 773 /// 774 void viewCFGOnly() const; 775 776 /// dump - Print the current MachineFunction to cerr, useful for debugger use. 777 void dump() const; 778 779 /// Run the current MachineFunction through the machine code verifier, useful 780 /// for debugger use. 781 /// \returns true if no problems were found. 782 bool verify(Pass *p = nullptr, const char *Banner = nullptr, 783 bool AbortOnError = true) const; 784 785 // Provide accessors for the MachineBasicBlock list... 786 using iterator = BasicBlockListType::iterator; 787 using const_iterator = BasicBlockListType::const_iterator; 788 using const_reverse_iterator = BasicBlockListType::const_reverse_iterator; 789 using reverse_iterator = BasicBlockListType::reverse_iterator; 790 791 /// Support for MachineBasicBlock::getNextNode(). 792 static BasicBlockListType MachineFunction::* 793 getSublistAccess(MachineBasicBlock *) { 794 return &MachineFunction::BasicBlocks; 795 } 796 797 /// addLiveIn - Add the specified physical register as a live-in value and 798 /// create a corresponding virtual register for it. 799 Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC); 800 801 //===--------------------------------------------------------------------===// 802 // BasicBlock accessor functions. 803 // 804 iterator begin() { return BasicBlocks.begin(); } 805 const_iterator begin() const { return BasicBlocks.begin(); } 806 iterator end () { return BasicBlocks.end(); } 807 const_iterator end () const { return BasicBlocks.end(); } 808 809 reverse_iterator rbegin() { return BasicBlocks.rbegin(); } 810 const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); } 811 reverse_iterator rend () { return BasicBlocks.rend(); } 812 const_reverse_iterator rend () const { return BasicBlocks.rend(); } 813 814 unsigned size() const { return (unsigned)BasicBlocks.size();} 815 bool empty() const { return BasicBlocks.empty(); } 816 const MachineBasicBlock &front() const { return BasicBlocks.front(); } 817 MachineBasicBlock &front() { return BasicBlocks.front(); } 818 const MachineBasicBlock & back() const { return BasicBlocks.back(); } 819 MachineBasicBlock & back() { return BasicBlocks.back(); } 820 821 void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); } 822 void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); } 823 void insert(iterator MBBI, MachineBasicBlock *MBB) { 824 BasicBlocks.insert(MBBI, MBB); 825 } 826 void splice(iterator InsertPt, iterator MBBI) { 827 BasicBlocks.splice(InsertPt, BasicBlocks, MBBI); 828 } 829 void splice(iterator InsertPt, MachineBasicBlock *MBB) { 830 BasicBlocks.splice(InsertPt, BasicBlocks, MBB); 831 } 832 void splice(iterator InsertPt, iterator MBBI, iterator MBBE) { 833 BasicBlocks.splice(InsertPt, BasicBlocks, MBBI, MBBE); 834 } 835 836 void remove(iterator MBBI) { BasicBlocks.remove(MBBI); } 837 void remove(MachineBasicBlock *MBBI) { BasicBlocks.remove(MBBI); } 838 void erase(iterator MBBI) { BasicBlocks.erase(MBBI); } 839 void erase(MachineBasicBlock *MBBI) { BasicBlocks.erase(MBBI); } 840 841 template <typename Comp> 842 void sort(Comp comp) { 843 BasicBlocks.sort(comp); 844 } 845 846 /// Return the number of \p MachineInstrs in this \p MachineFunction. 847 unsigned getInstructionCount() const { 848 unsigned InstrCount = 0; 849 for (const MachineBasicBlock &MBB : BasicBlocks) 850 InstrCount += MBB.size(); 851 return InstrCount; 852 } 853 854 //===--------------------------------------------------------------------===// 855 // Internal functions used to automatically number MachineBasicBlocks 856 857 /// Adds the MBB to the internal numbering. Returns the unique number 858 /// assigned to the MBB. 859 unsigned addToMBBNumbering(MachineBasicBlock *MBB) { 860 MBBNumbering.push_back(MBB); 861 return (unsigned)MBBNumbering.size()-1; 862 } 863 864 /// removeFromMBBNumbering - Remove the specific machine basic block from our 865 /// tracker, this is only really to be used by the MachineBasicBlock 866 /// implementation. 867 void removeFromMBBNumbering(unsigned N) { 868 assert(N < MBBNumbering.size() && "Illegal basic block #"); 869 MBBNumbering[N] = nullptr; 870 } 871 872 /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead 873 /// of `new MachineInstr'. 874 MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL, 875 bool NoImplicit = false); 876 877 /// Create a new MachineInstr which is a copy of \p Orig, identical in all 878 /// ways except the instruction has no parent, prev, or next. Bundling flags 879 /// are reset. 880 /// 881 /// Note: Clones a single instruction, not whole instruction bundles. 882 /// Does not perform target specific adjustments; consider using 883 /// TargetInstrInfo::duplicate() instead. 884 MachineInstr *CloneMachineInstr(const MachineInstr *Orig); 885 886 /// Clones instruction or the whole instruction bundle \p Orig and insert 887 /// into \p MBB before \p InsertBefore. 888 /// 889 /// Note: Does not perform target specific adjustments; consider using 890 /// TargetInstrInfo::duplicate() intead. 891 MachineInstr &CloneMachineInstrBundle(MachineBasicBlock &MBB, 892 MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig); 893 894 /// DeleteMachineInstr - Delete the given MachineInstr. 895 void DeleteMachineInstr(MachineInstr *MI); 896 897 /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this 898 /// instead of `new MachineBasicBlock'. 899 MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = nullptr); 900 901 /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock. 902 void DeleteMachineBasicBlock(MachineBasicBlock *MBB); 903 904 /// getMachineMemOperand - Allocate a new MachineMemOperand. 905 /// MachineMemOperands are owned by the MachineFunction and need not be 906 /// explicitly deallocated. 907 MachineMemOperand *getMachineMemOperand( 908 MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, 909 Align base_alignment, const AAMDNodes &AAInfo = AAMDNodes(), 910 const MDNode *Ranges = nullptr, SyncScope::ID SSID = SyncScope::System, 911 AtomicOrdering Ordering = AtomicOrdering::NotAtomic, 912 AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic); 913 914 MachineMemOperand *getMachineMemOperand( 915 MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, 916 Align base_alignment, const AAMDNodes &AAInfo = AAMDNodes(), 917 const MDNode *Ranges = nullptr, SyncScope::ID SSID = SyncScope::System, 918 AtomicOrdering Ordering = AtomicOrdering::NotAtomic, 919 AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic); 920 921 /// getMachineMemOperand - Allocate a new MachineMemOperand by copying 922 /// an existing one, adjusting by an offset and using the given size. 923 /// MachineMemOperands are owned by the MachineFunction and need not be 924 /// explicitly deallocated. 925 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO, 926 int64_t Offset, LLT Ty); 927 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO, 928 int64_t Offset, uint64_t Size) { 929 return getMachineMemOperand(MMO, Offset, LLT::scalar(8 * Size)); 930 } 931 932 /// getMachineMemOperand - Allocate a new MachineMemOperand by copying 933 /// an existing one, replacing only the MachinePointerInfo and size. 934 /// MachineMemOperands are owned by the MachineFunction and need not be 935 /// explicitly deallocated. 936 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO, 937 const MachinePointerInfo &PtrInfo, 938 uint64_t Size); 939 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO, 940 const MachinePointerInfo &PtrInfo, 941 LLT Ty); 942 943 /// Allocate a new MachineMemOperand by copying an existing one, 944 /// replacing only AliasAnalysis information. MachineMemOperands are owned 945 /// by the MachineFunction and need not be explicitly deallocated. 946 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO, 947 const AAMDNodes &AAInfo); 948 949 /// Allocate a new MachineMemOperand by copying an existing one, 950 /// replacing the flags. MachineMemOperands are owned 951 /// by the MachineFunction and need not be explicitly deallocated. 952 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO, 953 MachineMemOperand::Flags Flags); 954 955 using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity; 956 957 /// Allocate an array of MachineOperands. This is only intended for use by 958 /// internal MachineInstr functions. 959 MachineOperand *allocateOperandArray(OperandCapacity Cap) { 960 return OperandRecycler.allocate(Cap, Allocator); 961 } 962 963 /// Dellocate an array of MachineOperands and recycle the memory. This is 964 /// only intended for use by internal MachineInstr functions. 965 /// Cap must be the same capacity that was used to allocate the array. 966 void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array) { 967 OperandRecycler.deallocate(Cap, Array); 968 } 969 970 /// Allocate and initialize a register mask with @p NumRegister bits. 971 uint32_t *allocateRegMask(); 972 973 ArrayRef<int> allocateShuffleMask(ArrayRef<int> Mask); 974 975 /// Allocate and construct an extra info structure for a `MachineInstr`. 976 /// 977 /// This is allocated on the function's allocator and so lives the life of 978 /// the function. 979 MachineInstr::ExtraInfo *createMIExtraInfo( 980 ArrayRef<MachineMemOperand *> MMOs, MCSymbol *PreInstrSymbol = nullptr, 981 MCSymbol *PostInstrSymbol = nullptr, MDNode *HeapAllocMarker = nullptr); 982 983 /// Allocate a string and populate it with the given external symbol name. 984 const char *createExternalSymbolName(StringRef Name); 985 986 //===--------------------------------------------------------------------===// 987 // Label Manipulation. 988 989 /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table. 990 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a 991 /// normal 'L' label is returned. 992 MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx, 993 bool isLinkerPrivate = false) const; 994 995 /// getPICBaseSymbol - Return a function-local symbol to represent the PIC 996 /// base. 997 MCSymbol *getPICBaseSymbol() const; 998 999 /// Returns a reference to a list of cfi instructions in the function's 1000 /// prologue. Used to construct frame maps for debug and exception handling 1001 /// comsumers. 1002 const std::vector<MCCFIInstruction> &getFrameInstructions() const { 1003 return FrameInstructions; 1004 } 1005 1006 LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst); 1007 1008 /// Returns a reference to a list of symbols immediately following calls to 1009 /// _setjmp in the function. Used to construct the longjmp target table used 1010 /// by Windows Control Flow Guard. 1011 const std::vector<MCSymbol *> &getLongjmpTargets() const { 1012 return LongjmpTargets; 1013 } 1014 1015 /// Add the specified symbol to the list of valid longjmp targets for Windows 1016 /// Control Flow Guard. 1017 void addLongjmpTarget(MCSymbol *Target) { LongjmpTargets.push_back(Target); } 1018 1019 /// Returns a reference to a list of symbols that we have catchrets. 1020 /// Used to construct the catchret target table used by Windows EHCont Guard. 1021 const std::vector<MCSymbol *> &getCatchretTargets() const { 1022 return CatchretTargets; 1023 } 1024 1025 /// Add the specified symbol to the list of valid catchret targets for Windows 1026 /// EHCont Guard. 1027 void addCatchretTarget(MCSymbol *Target) { 1028 CatchretTargets.push_back(Target); 1029 } 1030 1031 /// \name Exception Handling 1032 /// \{ 1033 1034 bool callsEHReturn() const { return CallsEHReturn; } 1035 void setCallsEHReturn(bool b) { CallsEHReturn = b; } 1036 1037 bool callsUnwindInit() const { return CallsUnwindInit; } 1038 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; } 1039 1040 bool hasEHCatchret() const { return HasEHCatchret; } 1041 void setHasEHCatchret(bool V) { HasEHCatchret = V; } 1042 1043 bool hasEHScopes() const { return HasEHScopes; } 1044 void setHasEHScopes(bool V) { HasEHScopes = V; } 1045 1046 bool hasEHFunclets() const { return HasEHFunclets; } 1047 void setHasEHFunclets(bool V) { HasEHFunclets = V; } 1048 1049 /// Find or create an LandingPadInfo for the specified MachineBasicBlock. 1050 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad); 1051 1052 /// Remap landing pad labels and remove any deleted landing pads. 1053 void tidyLandingPads(DenseMap<MCSymbol *, uintptr_t> *LPMap = nullptr, 1054 bool TidyIfNoBeginLabels = true); 1055 1056 /// Return a reference to the landing pad info for the current function. 1057 const std::vector<LandingPadInfo> &getLandingPads() const { 1058 return LandingPads; 1059 } 1060 1061 /// Provide the begin and end labels of an invoke style call and associate it 1062 /// with a try landing pad block. 1063 void addInvoke(MachineBasicBlock *LandingPad, 1064 MCSymbol *BeginLabel, MCSymbol *EndLabel); 1065 1066 /// Add a new panding pad, and extract the exception handling information from 1067 /// the landingpad instruction. Returns the label ID for the landing pad 1068 /// entry. 1069 MCSymbol *addLandingPad(MachineBasicBlock *LandingPad); 1070 1071 /// Provide the catch typeinfo for a landing pad. 1072 void addCatchTypeInfo(MachineBasicBlock *LandingPad, 1073 ArrayRef<const GlobalValue *> TyInfo); 1074 1075 /// Provide the filter typeinfo for a landing pad. 1076 void addFilterTypeInfo(MachineBasicBlock *LandingPad, 1077 ArrayRef<const GlobalValue *> TyInfo); 1078 1079 /// Add a cleanup action for a landing pad. 1080 void addCleanup(MachineBasicBlock *LandingPad); 1081 1082 void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter, 1083 const BlockAddress *RecoverBA); 1084 1085 void addSEHCleanupHandler(MachineBasicBlock *LandingPad, 1086 const Function *Cleanup); 1087 1088 /// Return the type id for the specified typeinfo. This is function wide. 1089 unsigned getTypeIDFor(const GlobalValue *TI); 1090 1091 /// Return the id of the filter encoded by TyIds. This is function wide. 1092 int getFilterIDFor(std::vector<unsigned> &TyIds); 1093 1094 /// Map the landing pad's EH symbol to the call site indexes. 1095 void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef<unsigned> Sites); 1096 1097 /// Map the landing pad to its index. Used for Wasm exception handling. 1098 void setWasmLandingPadIndex(const MachineBasicBlock *LPad, unsigned Index) { 1099 WasmLPadToIndexMap[LPad] = Index; 1100 } 1101 1102 /// Returns true if the landing pad has an associate index in wasm EH. 1103 bool hasWasmLandingPadIndex(const MachineBasicBlock *LPad) const { 1104 return WasmLPadToIndexMap.count(LPad); 1105 } 1106 1107 /// Get the index in wasm EH for a given landing pad. 1108 unsigned getWasmLandingPadIndex(const MachineBasicBlock *LPad) const { 1109 assert(hasWasmLandingPadIndex(LPad)); 1110 return WasmLPadToIndexMap.lookup(LPad); 1111 } 1112 1113 /// Get the call site indexes for a landing pad EH symbol. 1114 SmallVectorImpl<unsigned> &getCallSiteLandingPad(MCSymbol *Sym) { 1115 assert(hasCallSiteLandingPad(Sym) && 1116 "missing call site number for landing pad!"); 1117 return LPadToCallSiteMap[Sym]; 1118 } 1119 1120 /// Return true if the landing pad Eh symbol has an associated call site. 1121 bool hasCallSiteLandingPad(MCSymbol *Sym) { 1122 return !LPadToCallSiteMap[Sym].empty(); 1123 } 1124 1125 /// Map the begin label for a call site. 1126 void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) { 1127 CallSiteMap[BeginLabel] = Site; 1128 } 1129 1130 /// Get the call site number for a begin label. 1131 unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) const { 1132 assert(hasCallSiteBeginLabel(BeginLabel) && 1133 "Missing call site number for EH_LABEL!"); 1134 return CallSiteMap.lookup(BeginLabel); 1135 } 1136 1137 /// Return true if the begin label has a call site number associated with it. 1138 bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) const { 1139 return CallSiteMap.count(BeginLabel); 1140 } 1141 1142 /// Record annotations associated with a particular label. 1143 void addCodeViewAnnotation(MCSymbol *Label, MDNode *MD) { 1144 CodeViewAnnotations.push_back({Label, MD}); 1145 } 1146 1147 ArrayRef<std::pair<MCSymbol *, MDNode *>> getCodeViewAnnotations() const { 1148 return CodeViewAnnotations; 1149 } 1150 1151 /// Return a reference to the C++ typeinfo for the current function. 1152 const std::vector<const GlobalValue *> &getTypeInfos() const { 1153 return TypeInfos; 1154 } 1155 1156 /// Return a reference to the typeids encoding filters used in the current 1157 /// function. 1158 const std::vector<unsigned> &getFilterIds() const { 1159 return FilterIds; 1160 } 1161 1162 /// \} 1163 1164 /// Collect information used to emit debugging information of a variable. 1165 void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, 1166 int Slot, const DILocation *Loc) { 1167 VariableDbgInfos.emplace_back(Var, Expr, Slot, Loc); 1168 } 1169 1170 VariableDbgInfoMapTy &getVariableDbgInfo() { return VariableDbgInfos; } 1171 const VariableDbgInfoMapTy &getVariableDbgInfo() const { 1172 return VariableDbgInfos; 1173 } 1174 1175 /// Start tracking the arguments passed to the call \p CallI. 1176 void addCallArgsForwardingRegs(const MachineInstr *CallI, 1177 CallSiteInfoImpl &&CallInfo) { 1178 assert(CallI->isCandidateForCallSiteEntry()); 1179 bool Inserted = 1180 CallSitesInfo.try_emplace(CallI, std::move(CallInfo)).second; 1181 (void)Inserted; 1182 assert(Inserted && "Call site info not unique"); 1183 } 1184 1185 const CallSiteInfoMap &getCallSitesInfo() const { 1186 return CallSitesInfo; 1187 } 1188 1189 /// Following functions update call site info. They should be called before 1190 /// removing, replacing or copying call instruction. 1191 1192 /// Erase the call site info for \p MI. It is used to remove a call 1193 /// instruction from the instruction stream. 1194 void eraseCallSiteInfo(const MachineInstr *MI); 1195 /// Copy the call site info from \p Old to \ New. Its usage is when we are 1196 /// making a copy of the instruction that will be inserted at different point 1197 /// of the instruction stream. 1198 void copyCallSiteInfo(const MachineInstr *Old, 1199 const MachineInstr *New); 1200 1201 const std::vector<char> &getBBSectionsSymbolPrefix() const { 1202 return BBSectionsSymbolPrefix; 1203 } 1204 1205 /// Move the call site info from \p Old to \New call site info. This function 1206 /// is used when we are replacing one call instruction with another one to 1207 /// the same callee. 1208 void moveCallSiteInfo(const MachineInstr *Old, 1209 const MachineInstr *New); 1210 1211 unsigned getNewDebugInstrNum() { 1212 return ++DebugInstrNumberingCount; 1213 } 1214 }; 1215 1216 //===--------------------------------------------------------------------===// 1217 // GraphTraits specializations for function basic block graphs (CFGs) 1218 //===--------------------------------------------------------------------===// 1219 1220 // Provide specializations of GraphTraits to be able to treat a 1221 // machine function as a graph of machine basic blocks... these are 1222 // the same as the machine basic block iterators, except that the root 1223 // node is implicitly the first node of the function. 1224 // 1225 template <> struct GraphTraits<MachineFunction*> : 1226 public GraphTraits<MachineBasicBlock*> { 1227 static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); } 1228 1229 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph 1230 using nodes_iterator = pointer_iterator<MachineFunction::iterator>; 1231 1232 static nodes_iterator nodes_begin(MachineFunction *F) { 1233 return nodes_iterator(F->begin()); 1234 } 1235 1236 static nodes_iterator nodes_end(MachineFunction *F) { 1237 return nodes_iterator(F->end()); 1238 } 1239 1240 static unsigned size (MachineFunction *F) { return F->size(); } 1241 }; 1242 template <> struct GraphTraits<const MachineFunction*> : 1243 public GraphTraits<const MachineBasicBlock*> { 1244 static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); } 1245 1246 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph 1247 using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>; 1248 1249 static nodes_iterator nodes_begin(const MachineFunction *F) { 1250 return nodes_iterator(F->begin()); 1251 } 1252 1253 static nodes_iterator nodes_end (const MachineFunction *F) { 1254 return nodes_iterator(F->end()); 1255 } 1256 1257 static unsigned size (const MachineFunction *F) { 1258 return F->size(); 1259 } 1260 }; 1261 1262 // Provide specializations of GraphTraits to be able to treat a function as a 1263 // graph of basic blocks... and to walk it in inverse order. Inverse order for 1264 // a function is considered to be when traversing the predecessor edges of a BB 1265 // instead of the successor edges. 1266 // 1267 template <> struct GraphTraits<Inverse<MachineFunction*>> : 1268 public GraphTraits<Inverse<MachineBasicBlock*>> { 1269 static NodeRef getEntryNode(Inverse<MachineFunction *> G) { 1270 return &G.Graph->front(); 1271 } 1272 }; 1273 template <> struct GraphTraits<Inverse<const MachineFunction*>> : 1274 public GraphTraits<Inverse<const MachineBasicBlock*>> { 1275 static NodeRef getEntryNode(Inverse<const MachineFunction *> G) { 1276 return &G.Graph->front(); 1277 } 1278 }; 1279 1280 class MachineFunctionAnalysisManager; 1281 void verifyMachineFunction(MachineFunctionAnalysisManager *, 1282 const std::string &Banner, 1283 const MachineFunction &MF); 1284 1285 } // end namespace llvm 1286 1287 #endif // LLVM_CODEGEN_MACHINEFUNCTION_H 1288