1 //===- llvm/CodeGen/MachineInstr.h - MachineInstr class ---------*- 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 // This file contains the declaration of the MachineInstr class, which is the 10 // basic representation for all target dependent machine instructions used by 11 // the back end. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CODEGEN_MACHINEINSTR_H 16 #define LLVM_CODEGEN_MACHINEINSTR_H 17 18 #include "llvm/ADT/DenseMapInfo.h" 19 #include "llvm/ADT/PointerSumType.h" 20 #include "llvm/ADT/ilist.h" 21 #include "llvm/ADT/ilist_node.h" 22 #include "llvm/ADT/iterator_range.h" 23 #include "llvm/CodeGen/MachineMemOperand.h" 24 #include "llvm/CodeGen/MachineOperand.h" 25 #include "llvm/CodeGen/TargetOpcodes.h" 26 #include "llvm/IR/DebugLoc.h" 27 #include "llvm/IR/InlineAsm.h" 28 #include "llvm/MC/MCInstrDesc.h" 29 #include "llvm/MC/MCSymbol.h" 30 #include "llvm/Support/ArrayRecycler.h" 31 #include "llvm/Support/TrailingObjects.h" 32 #include <algorithm> 33 #include <cassert> 34 #include <cstdint> 35 #include <utility> 36 37 namespace llvm { 38 39 class AAResults; 40 template <typename T> class ArrayRef; 41 class DIExpression; 42 class DILocalVariable; 43 class MachineBasicBlock; 44 class MachineFunction; 45 class MachineMemOperand; 46 class MachineRegisterInfo; 47 class ModuleSlotTracker; 48 class raw_ostream; 49 template <typename T> class SmallVectorImpl; 50 class SmallBitVector; 51 class StringRef; 52 class TargetInstrInfo; 53 class TargetRegisterClass; 54 class TargetRegisterInfo; 55 56 //===----------------------------------------------------------------------===// 57 /// Representation of each machine instruction. 58 /// 59 /// This class isn't a POD type, but it must have a trivial destructor. When a 60 /// MachineFunction is deleted, all the contained MachineInstrs are deallocated 61 /// without having their destructor called. 62 /// 63 class MachineInstr 64 : public ilist_node_with_parent<MachineInstr, MachineBasicBlock, 65 ilist_sentinel_tracking<true>> { 66 public: 67 using mmo_iterator = ArrayRef<MachineMemOperand *>::iterator; 68 69 /// Flags to specify different kinds of comments to output in 70 /// assembly code. These flags carry semantic information not 71 /// otherwise easily derivable from the IR text. 72 /// 73 enum CommentFlag { 74 ReloadReuse = 0x1, // higher bits are reserved for target dep comments. 75 NoSchedComment = 0x2, 76 TAsmComments = 0x4 // Target Asm comments should start from this value. 77 }; 78 79 enum MIFlag { 80 NoFlags = 0, 81 FrameSetup = 1 << 0, // Instruction is used as a part of 82 // function frame setup code. 83 FrameDestroy = 1 << 1, // Instruction is used as a part of 84 // function frame destruction code. 85 BundledPred = 1 << 2, // Instruction has bundled predecessors. 86 BundledSucc = 1 << 3, // Instruction has bundled successors. 87 FmNoNans = 1 << 4, // Instruction does not support Fast 88 // math nan values. 89 FmNoInfs = 1 << 5, // Instruction does not support Fast 90 // math infinity values. 91 FmNsz = 1 << 6, // Instruction is not required to retain 92 // signed zero values. 93 FmArcp = 1 << 7, // Instruction supports Fast math 94 // reciprocal approximations. 95 FmContract = 1 << 8, // Instruction supports Fast math 96 // contraction operations like fma. 97 FmAfn = 1 << 9, // Instruction may map to Fast math 98 // instrinsic approximation. 99 FmReassoc = 1 << 10, // Instruction supports Fast math 100 // reassociation of operand order. 101 NoUWrap = 1 << 11, // Instruction supports binary operator 102 // no unsigned wrap. 103 NoSWrap = 1 << 12, // Instruction supports binary operator 104 // no signed wrap. 105 IsExact = 1 << 13, // Instruction supports division is 106 // known to be exact. 107 NoFPExcept = 1 << 14, // Instruction does not raise 108 // floatint-point exceptions. 109 }; 110 111 private: 112 const MCInstrDesc *MCID; // Instruction descriptor. 113 MachineBasicBlock *Parent = nullptr; // Pointer to the owning basic block. 114 115 // Operands are allocated by an ArrayRecycler. 116 MachineOperand *Operands = nullptr; // Pointer to the first operand. 117 unsigned NumOperands = 0; // Number of operands on instruction. 118 119 uint16_t Flags = 0; // Various bits of additional 120 // information about machine 121 // instruction. 122 123 uint8_t AsmPrinterFlags = 0; // Various bits of information used by 124 // the AsmPrinter to emit helpful 125 // comments. This is *not* semantic 126 // information. Do not use this for 127 // anything other than to convey comment 128 // information to AsmPrinter. 129 130 // OperandCapacity has uint8_t size, so it should be next to AsmPrinterFlags 131 // to properly pack. 132 using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity; 133 OperandCapacity CapOperands; // Capacity of the Operands array. 134 135 /// Internal implementation detail class that provides out-of-line storage for 136 /// extra info used by the machine instruction when this info cannot be stored 137 /// in-line within the instruction itself. 138 /// 139 /// This has to be defined eagerly due to the implementation constraints of 140 /// `PointerSumType` where it is used. 141 class ExtraInfo final 142 : TrailingObjects<ExtraInfo, MachineMemOperand *, MCSymbol *, MDNode *> { 143 public: 144 static ExtraInfo *create(BumpPtrAllocator &Allocator, 145 ArrayRef<MachineMemOperand *> MMOs, 146 MCSymbol *PreInstrSymbol = nullptr, 147 MCSymbol *PostInstrSymbol = nullptr, 148 MDNode *HeapAllocMarker = nullptr) { 149 bool HasPreInstrSymbol = PreInstrSymbol != nullptr; 150 bool HasPostInstrSymbol = PostInstrSymbol != nullptr; 151 bool HasHeapAllocMarker = HeapAllocMarker != nullptr; 152 auto *Result = new (Allocator.Allocate( 153 totalSizeToAlloc<MachineMemOperand *, MCSymbol *, MDNode *>( 154 MMOs.size(), HasPreInstrSymbol + HasPostInstrSymbol, 155 HasHeapAllocMarker), 156 alignof(ExtraInfo))) 157 ExtraInfo(MMOs.size(), HasPreInstrSymbol, HasPostInstrSymbol, 158 HasHeapAllocMarker); 159 160 // Copy the actual data into the trailing objects. 161 std::copy(MMOs.begin(), MMOs.end(), 162 Result->getTrailingObjects<MachineMemOperand *>()); 163 164 if (HasPreInstrSymbol) 165 Result->getTrailingObjects<MCSymbol *>()[0] = PreInstrSymbol; 166 if (HasPostInstrSymbol) 167 Result->getTrailingObjects<MCSymbol *>()[HasPreInstrSymbol] = 168 PostInstrSymbol; 169 if (HasHeapAllocMarker) 170 Result->getTrailingObjects<MDNode *>()[0] = HeapAllocMarker; 171 172 return Result; 173 } 174 175 ArrayRef<MachineMemOperand *> getMMOs() const { 176 return makeArrayRef(getTrailingObjects<MachineMemOperand *>(), NumMMOs); 177 } 178 179 MCSymbol *getPreInstrSymbol() const { 180 return HasPreInstrSymbol ? getTrailingObjects<MCSymbol *>()[0] : nullptr; 181 } 182 183 MCSymbol *getPostInstrSymbol() const { 184 return HasPostInstrSymbol 185 ? getTrailingObjects<MCSymbol *>()[HasPreInstrSymbol] 186 : nullptr; 187 } 188 189 MDNode *getHeapAllocMarker() const { 190 return HasHeapAllocMarker ? getTrailingObjects<MDNode *>()[0] : nullptr; 191 } 192 193 private: 194 friend TrailingObjects; 195 196 // Description of the extra info, used to interpret the actual optional 197 // data appended. 198 // 199 // Note that this is not terribly space optimized. This leaves a great deal 200 // of flexibility to fit more in here later. 201 const int NumMMOs; 202 const bool HasPreInstrSymbol; 203 const bool HasPostInstrSymbol; 204 const bool HasHeapAllocMarker; 205 206 // Implement the `TrailingObjects` internal API. 207 size_t numTrailingObjects(OverloadToken<MachineMemOperand *>) const { 208 return NumMMOs; 209 } 210 size_t numTrailingObjects(OverloadToken<MCSymbol *>) const { 211 return HasPreInstrSymbol + HasPostInstrSymbol; 212 } 213 size_t numTrailingObjects(OverloadToken<MDNode *>) const { 214 return HasHeapAllocMarker; 215 } 216 217 // Just a boring constructor to allow us to initialize the sizes. Always use 218 // the `create` routine above. 219 ExtraInfo(int NumMMOs, bool HasPreInstrSymbol, bool HasPostInstrSymbol, 220 bool HasHeapAllocMarker) 221 : NumMMOs(NumMMOs), HasPreInstrSymbol(HasPreInstrSymbol), 222 HasPostInstrSymbol(HasPostInstrSymbol), 223 HasHeapAllocMarker(HasHeapAllocMarker) {} 224 }; 225 226 /// Enumeration of the kinds of inline extra info available. It is important 227 /// that the `MachineMemOperand` inline kind has a tag value of zero to make 228 /// it accessible as an `ArrayRef`. 229 enum ExtraInfoInlineKinds { 230 EIIK_MMO = 0, 231 EIIK_PreInstrSymbol, 232 EIIK_PostInstrSymbol, 233 EIIK_OutOfLine 234 }; 235 236 // We store extra information about the instruction here. The common case is 237 // expected to be nothing or a single pointer (typically a MMO or a symbol). 238 // We work to optimize this common case by storing it inline here rather than 239 // requiring a separate allocation, but we fall back to an allocation when 240 // multiple pointers are needed. 241 PointerSumType<ExtraInfoInlineKinds, 242 PointerSumTypeMember<EIIK_MMO, MachineMemOperand *>, 243 PointerSumTypeMember<EIIK_PreInstrSymbol, MCSymbol *>, 244 PointerSumTypeMember<EIIK_PostInstrSymbol, MCSymbol *>, 245 PointerSumTypeMember<EIIK_OutOfLine, ExtraInfo *>> 246 Info; 247 248 DebugLoc debugLoc; // Source line information. 249 250 // Intrusive list support 251 friend struct ilist_traits<MachineInstr>; 252 friend struct ilist_callback_traits<MachineBasicBlock>; 253 void setParent(MachineBasicBlock *P) { Parent = P; } 254 255 /// This constructor creates a copy of the given 256 /// MachineInstr in the given MachineFunction. 257 MachineInstr(MachineFunction &, const MachineInstr &); 258 259 /// This constructor create a MachineInstr and add the implicit operands. 260 /// It reserves space for number of operands specified by 261 /// MCInstrDesc. An explicit DebugLoc is supplied. 262 MachineInstr(MachineFunction &, const MCInstrDesc &tid, DebugLoc dl, 263 bool NoImp = false); 264 265 // MachineInstrs are pool-allocated and owned by MachineFunction. 266 friend class MachineFunction; 267 268 void 269 dumprImpl(const MachineRegisterInfo &MRI, unsigned Depth, unsigned MaxDepth, 270 SmallPtrSetImpl<const MachineInstr *> &AlreadySeenInstrs) const; 271 272 public: 273 MachineInstr(const MachineInstr &) = delete; 274 MachineInstr &operator=(const MachineInstr &) = delete; 275 // Use MachineFunction::DeleteMachineInstr() instead. 276 ~MachineInstr() = delete; 277 278 const MachineBasicBlock* getParent() const { return Parent; } 279 MachineBasicBlock* getParent() { return Parent; } 280 281 /// Return the function that contains the basic block that this instruction 282 /// belongs to. 283 /// 284 /// Note: this is undefined behaviour if the instruction does not have a 285 /// parent. 286 const MachineFunction *getMF() const; 287 MachineFunction *getMF() { 288 return const_cast<MachineFunction *>( 289 static_cast<const MachineInstr *>(this)->getMF()); 290 } 291 292 /// Return the asm printer flags bitvector. 293 uint8_t getAsmPrinterFlags() const { return AsmPrinterFlags; } 294 295 /// Clear the AsmPrinter bitvector. 296 void clearAsmPrinterFlags() { AsmPrinterFlags = 0; } 297 298 /// Return whether an AsmPrinter flag is set. 299 bool getAsmPrinterFlag(CommentFlag Flag) const { 300 return AsmPrinterFlags & Flag; 301 } 302 303 /// Set a flag for the AsmPrinter. 304 void setAsmPrinterFlag(uint8_t Flag) { 305 AsmPrinterFlags |= Flag; 306 } 307 308 /// Clear specific AsmPrinter flags. 309 void clearAsmPrinterFlag(CommentFlag Flag) { 310 AsmPrinterFlags &= ~Flag; 311 } 312 313 /// Return the MI flags bitvector. 314 uint16_t getFlags() const { 315 return Flags; 316 } 317 318 /// Return whether an MI flag is set. 319 bool getFlag(MIFlag Flag) const { 320 return Flags & Flag; 321 } 322 323 /// Set a MI flag. 324 void setFlag(MIFlag Flag) { 325 Flags |= (uint16_t)Flag; 326 } 327 328 void setFlags(unsigned flags) { 329 // Filter out the automatically maintained flags. 330 unsigned Mask = BundledPred | BundledSucc; 331 Flags = (Flags & Mask) | (flags & ~Mask); 332 } 333 334 /// clearFlag - Clear a MI flag. 335 void clearFlag(MIFlag Flag) { 336 Flags &= ~((uint16_t)Flag); 337 } 338 339 /// Return true if MI is in a bundle (but not the first MI in a bundle). 340 /// 341 /// A bundle looks like this before it's finalized: 342 /// ---------------- 343 /// | MI | 344 /// ---------------- 345 /// | 346 /// ---------------- 347 /// | MI * | 348 /// ---------------- 349 /// | 350 /// ---------------- 351 /// | MI * | 352 /// ---------------- 353 /// In this case, the first MI starts a bundle but is not inside a bundle, the 354 /// next 2 MIs are considered "inside" the bundle. 355 /// 356 /// After a bundle is finalized, it looks like this: 357 /// ---------------- 358 /// | Bundle | 359 /// ---------------- 360 /// | 361 /// ---------------- 362 /// | MI * | 363 /// ---------------- 364 /// | 365 /// ---------------- 366 /// | MI * | 367 /// ---------------- 368 /// | 369 /// ---------------- 370 /// | MI * | 371 /// ---------------- 372 /// The first instruction has the special opcode "BUNDLE". It's not "inside" 373 /// a bundle, but the next three MIs are. 374 bool isInsideBundle() const { 375 return getFlag(BundledPred); 376 } 377 378 /// Return true if this instruction part of a bundle. This is true 379 /// if either itself or its following instruction is marked "InsideBundle". 380 bool isBundled() const { 381 return isBundledWithPred() || isBundledWithSucc(); 382 } 383 384 /// Return true if this instruction is part of a bundle, and it is not the 385 /// first instruction in the bundle. 386 bool isBundledWithPred() const { return getFlag(BundledPred); } 387 388 /// Return true if this instruction is part of a bundle, and it is not the 389 /// last instruction in the bundle. 390 bool isBundledWithSucc() const { return getFlag(BundledSucc); } 391 392 /// Bundle this instruction with its predecessor. This can be an unbundled 393 /// instruction, or it can be the first instruction in a bundle. 394 void bundleWithPred(); 395 396 /// Bundle this instruction with its successor. This can be an unbundled 397 /// instruction, or it can be the last instruction in a bundle. 398 void bundleWithSucc(); 399 400 /// Break bundle above this instruction. 401 void unbundleFromPred(); 402 403 /// Break bundle below this instruction. 404 void unbundleFromSucc(); 405 406 /// Returns the debug location id of this MachineInstr. 407 const DebugLoc &getDebugLoc() const { return debugLoc; } 408 409 /// Return the debug variable referenced by 410 /// this DBG_VALUE instruction. 411 const DILocalVariable *getDebugVariable() const; 412 413 /// Return the complex address expression referenced by 414 /// this DBG_VALUE instruction. 415 const DIExpression *getDebugExpression() const; 416 417 /// Return the debug label referenced by 418 /// this DBG_LABEL instruction. 419 const DILabel *getDebugLabel() const; 420 421 /// Emit an error referring to the source location of this instruction. 422 /// This should only be used for inline assembly that is somehow 423 /// impossible to compile. Other errors should have been handled much 424 /// earlier. 425 /// 426 /// If this method returns, the caller should try to recover from the error. 427 void emitError(StringRef Msg) const; 428 429 /// Returns the target instruction descriptor of this MachineInstr. 430 const MCInstrDesc &getDesc() const { return *MCID; } 431 432 /// Returns the opcode of this MachineInstr. 433 unsigned getOpcode() const { return MCID->Opcode; } 434 435 /// Retuns the total number of operands. 436 unsigned getNumOperands() const { return NumOperands; } 437 438 const MachineOperand& getOperand(unsigned i) const { 439 assert(i < getNumOperands() && "getOperand() out of range!"); 440 return Operands[i]; 441 } 442 MachineOperand& getOperand(unsigned i) { 443 assert(i < getNumOperands() && "getOperand() out of range!"); 444 return Operands[i]; 445 } 446 447 /// Returns the total number of definitions. 448 unsigned getNumDefs() const { 449 return getNumExplicitDefs() + MCID->getNumImplicitDefs(); 450 } 451 452 /// Returns true if the instruction has implicit definition. 453 bool hasImplicitDef() const { 454 for (unsigned I = getNumExplicitOperands(), E = getNumOperands(); 455 I != E; ++I) { 456 const MachineOperand &MO = getOperand(I); 457 if (MO.isDef() && MO.isImplicit()) 458 return true; 459 } 460 return false; 461 } 462 463 /// Returns the implicit operands number. 464 unsigned getNumImplicitOperands() const { 465 return getNumOperands() - getNumExplicitOperands(); 466 } 467 468 /// Return true if operand \p OpIdx is a subregister index. 469 bool isOperandSubregIdx(unsigned OpIdx) const { 470 assert(getOperand(OpIdx).getType() == MachineOperand::MO_Immediate && 471 "Expected MO_Immediate operand type."); 472 if (isExtractSubreg() && OpIdx == 2) 473 return true; 474 if (isInsertSubreg() && OpIdx == 3) 475 return true; 476 if (isRegSequence() && OpIdx > 1 && (OpIdx % 2) == 0) 477 return true; 478 if (isSubregToReg() && OpIdx == 3) 479 return true; 480 return false; 481 } 482 483 /// Returns the number of non-implicit operands. 484 unsigned getNumExplicitOperands() const; 485 486 /// Returns the number of non-implicit definitions. 487 unsigned getNumExplicitDefs() const; 488 489 /// iterator/begin/end - Iterate over all operands of a machine instruction. 490 using mop_iterator = MachineOperand *; 491 using const_mop_iterator = const MachineOperand *; 492 493 mop_iterator operands_begin() { return Operands; } 494 mop_iterator operands_end() { return Operands + NumOperands; } 495 496 const_mop_iterator operands_begin() const { return Operands; } 497 const_mop_iterator operands_end() const { return Operands + NumOperands; } 498 499 iterator_range<mop_iterator> operands() { 500 return make_range(operands_begin(), operands_end()); 501 } 502 iterator_range<const_mop_iterator> operands() const { 503 return make_range(operands_begin(), operands_end()); 504 } 505 iterator_range<mop_iterator> explicit_operands() { 506 return make_range(operands_begin(), 507 operands_begin() + getNumExplicitOperands()); 508 } 509 iterator_range<const_mop_iterator> explicit_operands() const { 510 return make_range(operands_begin(), 511 operands_begin() + getNumExplicitOperands()); 512 } 513 iterator_range<mop_iterator> implicit_operands() { 514 return make_range(explicit_operands().end(), operands_end()); 515 } 516 iterator_range<const_mop_iterator> implicit_operands() const { 517 return make_range(explicit_operands().end(), operands_end()); 518 } 519 /// Returns a range over all explicit operands that are register definitions. 520 /// Implicit definition are not included! 521 iterator_range<mop_iterator> defs() { 522 return make_range(operands_begin(), 523 operands_begin() + getNumExplicitDefs()); 524 } 525 /// \copydoc defs() 526 iterator_range<const_mop_iterator> defs() const { 527 return make_range(operands_begin(), 528 operands_begin() + getNumExplicitDefs()); 529 } 530 /// Returns a range that includes all operands that are register uses. 531 /// This may include unrelated operands which are not register uses. 532 iterator_range<mop_iterator> uses() { 533 return make_range(operands_begin() + getNumExplicitDefs(), operands_end()); 534 } 535 /// \copydoc uses() 536 iterator_range<const_mop_iterator> uses() const { 537 return make_range(operands_begin() + getNumExplicitDefs(), operands_end()); 538 } 539 iterator_range<mop_iterator> explicit_uses() { 540 return make_range(operands_begin() + getNumExplicitDefs(), 541 operands_begin() + getNumExplicitOperands()); 542 } 543 iterator_range<const_mop_iterator> explicit_uses() const { 544 return make_range(operands_begin() + getNumExplicitDefs(), 545 operands_begin() + getNumExplicitOperands()); 546 } 547 548 /// Returns the number of the operand iterator \p I points to. 549 unsigned getOperandNo(const_mop_iterator I) const { 550 return I - operands_begin(); 551 } 552 553 /// Access to memory operands of the instruction. If there are none, that does 554 /// not imply anything about whether the function accesses memory. Instead, 555 /// the caller must behave conservatively. 556 ArrayRef<MachineMemOperand *> memoperands() const { 557 if (!Info) 558 return {}; 559 560 if (Info.is<EIIK_MMO>()) 561 return makeArrayRef(Info.getAddrOfZeroTagPointer(), 1); 562 563 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>()) 564 return EI->getMMOs(); 565 566 return {}; 567 } 568 569 /// Access to memory operands of the instruction. 570 /// 571 /// If `memoperands_begin() == memoperands_end()`, that does not imply 572 /// anything about whether the function accesses memory. Instead, the caller 573 /// must behave conservatively. 574 mmo_iterator memoperands_begin() const { return memoperands().begin(); } 575 576 /// Access to memory operands of the instruction. 577 /// 578 /// If `memoperands_begin() == memoperands_end()`, that does not imply 579 /// anything about whether the function accesses memory. Instead, the caller 580 /// must behave conservatively. 581 mmo_iterator memoperands_end() const { return memoperands().end(); } 582 583 /// Return true if we don't have any memory operands which described the 584 /// memory access done by this instruction. If this is true, calling code 585 /// must be conservative. 586 bool memoperands_empty() const { return memoperands().empty(); } 587 588 /// Return true if this instruction has exactly one MachineMemOperand. 589 bool hasOneMemOperand() const { return memoperands().size() == 1; } 590 591 /// Return the number of memory operands. 592 unsigned getNumMemOperands() const { return memoperands().size(); } 593 594 /// Helper to extract a pre-instruction symbol if one has been added. 595 MCSymbol *getPreInstrSymbol() const { 596 if (!Info) 597 return nullptr; 598 if (MCSymbol *S = Info.get<EIIK_PreInstrSymbol>()) 599 return S; 600 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>()) 601 return EI->getPreInstrSymbol(); 602 603 return nullptr; 604 } 605 606 /// Helper to extract a post-instruction symbol if one has been added. 607 MCSymbol *getPostInstrSymbol() const { 608 if (!Info) 609 return nullptr; 610 if (MCSymbol *S = Info.get<EIIK_PostInstrSymbol>()) 611 return S; 612 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>()) 613 return EI->getPostInstrSymbol(); 614 615 return nullptr; 616 } 617 618 /// Helper to extract a heap alloc marker if one has been added. 619 MDNode *getHeapAllocMarker() const { 620 if (!Info) 621 return nullptr; 622 if (ExtraInfo *EI = Info.get<EIIK_OutOfLine>()) 623 return EI->getHeapAllocMarker(); 624 625 return nullptr; 626 } 627 628 /// API for querying MachineInstr properties. They are the same as MCInstrDesc 629 /// queries but they are bundle aware. 630 631 enum QueryType { 632 IgnoreBundle, // Ignore bundles 633 AnyInBundle, // Return true if any instruction in bundle has property 634 AllInBundle // Return true if all instructions in bundle have property 635 }; 636 637 /// Return true if the instruction (or in the case of a bundle, 638 /// the instructions inside the bundle) has the specified property. 639 /// The first argument is the property being queried. 640 /// The second argument indicates whether the query should look inside 641 /// instruction bundles. 642 bool hasProperty(unsigned MCFlag, QueryType Type = AnyInBundle) const { 643 assert(MCFlag < 64 && 644 "MCFlag out of range for bit mask in getFlags/hasPropertyInBundle."); 645 // Inline the fast path for unbundled or bundle-internal instructions. 646 if (Type == IgnoreBundle || !isBundled() || isBundledWithPred()) 647 return getDesc().getFlags() & (1ULL << MCFlag); 648 649 // If this is the first instruction in a bundle, take the slow path. 650 return hasPropertyInBundle(1ULL << MCFlag, Type); 651 } 652 653 /// Return true if this is an instruction that should go through the usual 654 /// legalization steps. 655 bool isPreISelOpcode(QueryType Type = IgnoreBundle) const { 656 return hasProperty(MCID::PreISelOpcode, Type); 657 } 658 659 /// Return true if this instruction can have a variable number of operands. 660 /// In this case, the variable operands will be after the normal 661 /// operands but before the implicit definitions and uses (if any are 662 /// present). 663 bool isVariadic(QueryType Type = IgnoreBundle) const { 664 return hasProperty(MCID::Variadic, Type); 665 } 666 667 /// Set if this instruction has an optional definition, e.g. 668 /// ARM instructions which can set condition code if 's' bit is set. 669 bool hasOptionalDef(QueryType Type = IgnoreBundle) const { 670 return hasProperty(MCID::HasOptionalDef, Type); 671 } 672 673 /// Return true if this is a pseudo instruction that doesn't 674 /// correspond to a real machine instruction. 675 bool isPseudo(QueryType Type = IgnoreBundle) const { 676 return hasProperty(MCID::Pseudo, Type); 677 } 678 679 bool isReturn(QueryType Type = AnyInBundle) const { 680 return hasProperty(MCID::Return, Type); 681 } 682 683 /// Return true if this is an instruction that marks the end of an EH scope, 684 /// i.e., a catchpad or a cleanuppad instruction. 685 bool isEHScopeReturn(QueryType Type = AnyInBundle) const { 686 return hasProperty(MCID::EHScopeReturn, Type); 687 } 688 689 bool isCall(QueryType Type = AnyInBundle) const { 690 return hasProperty(MCID::Call, Type); 691 } 692 693 /// Return true if this is a call instruction that may have an associated 694 /// call site entry in the debug info. 695 bool isCandidateForCallSiteEntry(QueryType Type = IgnoreBundle) const; 696 /// Return true if copying, moving, or erasing this instruction requires 697 /// updating Call Site Info (see \ref copyCallSiteInfo, \ref moveCallSiteInfo, 698 /// \ref eraseCallSiteInfo). 699 bool shouldUpdateCallSiteInfo() const; 700 701 /// Returns true if the specified instruction stops control flow 702 /// from executing the instruction immediately following it. Examples include 703 /// unconditional branches and return instructions. 704 bool isBarrier(QueryType Type = AnyInBundle) const { 705 return hasProperty(MCID::Barrier, Type); 706 } 707 708 /// Returns true if this instruction part of the terminator for a basic block. 709 /// Typically this is things like return and branch instructions. 710 /// 711 /// Various passes use this to insert code into the bottom of a basic block, 712 /// but before control flow occurs. 713 bool isTerminator(QueryType Type = AnyInBundle) const { 714 return hasProperty(MCID::Terminator, Type); 715 } 716 717 /// Returns true if this is a conditional, unconditional, or indirect branch. 718 /// Predicates below can be used to discriminate between 719 /// these cases, and the TargetInstrInfo::analyzeBranch method can be used to 720 /// get more information. 721 bool isBranch(QueryType Type = AnyInBundle) const { 722 return hasProperty(MCID::Branch, Type); 723 } 724 725 /// Return true if this is an indirect branch, such as a 726 /// branch through a register. 727 bool isIndirectBranch(QueryType Type = AnyInBundle) const { 728 return hasProperty(MCID::IndirectBranch, Type); 729 } 730 731 /// Return true if this is a branch which may fall 732 /// through to the next instruction or may transfer control flow to some other 733 /// block. The TargetInstrInfo::analyzeBranch method can be used to get more 734 /// information about this branch. 735 bool isConditionalBranch(QueryType Type = AnyInBundle) const { 736 return isBranch(Type) && !isBarrier(Type) && !isIndirectBranch(Type); 737 } 738 739 /// Return true if this is a branch which always 740 /// transfers control flow to some other block. The 741 /// TargetInstrInfo::analyzeBranch method can be used to get more information 742 /// about this branch. 743 bool isUnconditionalBranch(QueryType Type = AnyInBundle) const { 744 return isBranch(Type) && isBarrier(Type) && !isIndirectBranch(Type); 745 } 746 747 /// Return true if this instruction has a predicate operand that 748 /// controls execution. It may be set to 'always', or may be set to other 749 /// values. There are various methods in TargetInstrInfo that can be used to 750 /// control and modify the predicate in this instruction. 751 bool isPredicable(QueryType Type = AllInBundle) const { 752 // If it's a bundle than all bundled instructions must be predicable for this 753 // to return true. 754 return hasProperty(MCID::Predicable, Type); 755 } 756 757 /// Return true if this instruction is a comparison. 758 bool isCompare(QueryType Type = IgnoreBundle) const { 759 return hasProperty(MCID::Compare, Type); 760 } 761 762 /// Return true if this instruction is a move immediate 763 /// (including conditional moves) instruction. 764 bool isMoveImmediate(QueryType Type = IgnoreBundle) const { 765 return hasProperty(MCID::MoveImm, Type); 766 } 767 768 /// Return true if this instruction is a register move. 769 /// (including moving values from subreg to reg) 770 bool isMoveReg(QueryType Type = IgnoreBundle) const { 771 return hasProperty(MCID::MoveReg, Type); 772 } 773 774 /// Return true if this instruction is a bitcast instruction. 775 bool isBitcast(QueryType Type = IgnoreBundle) const { 776 return hasProperty(MCID::Bitcast, Type); 777 } 778 779 /// Return true if this instruction is a select instruction. 780 bool isSelect(QueryType Type = IgnoreBundle) const { 781 return hasProperty(MCID::Select, Type); 782 } 783 784 /// Return true if this instruction cannot be safely duplicated. 785 /// For example, if the instruction has a unique labels attached 786 /// to it, duplicating it would cause multiple definition errors. 787 bool isNotDuplicable(QueryType Type = AnyInBundle) const { 788 return hasProperty(MCID::NotDuplicable, Type); 789 } 790 791 /// Return true if this instruction is convergent. 792 /// Convergent instructions can not be made control-dependent on any 793 /// additional values. 794 bool isConvergent(QueryType Type = AnyInBundle) const { 795 if (isInlineAsm()) { 796 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm(); 797 if (ExtraInfo & InlineAsm::Extra_IsConvergent) 798 return true; 799 } 800 return hasProperty(MCID::Convergent, Type); 801 } 802 803 /// Returns true if the specified instruction has a delay slot 804 /// which must be filled by the code generator. 805 bool hasDelaySlot(QueryType Type = AnyInBundle) const { 806 return hasProperty(MCID::DelaySlot, Type); 807 } 808 809 /// Return true for instructions that can be folded as 810 /// memory operands in other instructions. The most common use for this 811 /// is instructions that are simple loads from memory that don't modify 812 /// the loaded value in any way, but it can also be used for instructions 813 /// that can be expressed as constant-pool loads, such as V_SETALLONES 814 /// on x86, to allow them to be folded when it is beneficial. 815 /// This should only be set on instructions that return a value in their 816 /// only virtual register definition. 817 bool canFoldAsLoad(QueryType Type = IgnoreBundle) const { 818 return hasProperty(MCID::FoldableAsLoad, Type); 819 } 820 821 /// Return true if this instruction behaves 822 /// the same way as the generic REG_SEQUENCE instructions. 823 /// E.g., on ARM, 824 /// dX VMOVDRR rY, rZ 825 /// is equivalent to 826 /// dX = REG_SEQUENCE rY, ssub_0, rZ, ssub_1. 827 /// 828 /// Note that for the optimizers to be able to take advantage of 829 /// this property, TargetInstrInfo::getRegSequenceLikeInputs has to be 830 /// override accordingly. 831 bool isRegSequenceLike(QueryType Type = IgnoreBundle) const { 832 return hasProperty(MCID::RegSequence, Type); 833 } 834 835 /// Return true if this instruction behaves 836 /// the same way as the generic EXTRACT_SUBREG instructions. 837 /// E.g., on ARM, 838 /// rX, rY VMOVRRD dZ 839 /// is equivalent to two EXTRACT_SUBREG: 840 /// rX = EXTRACT_SUBREG dZ, ssub_0 841 /// rY = EXTRACT_SUBREG dZ, ssub_1 842 /// 843 /// Note that for the optimizers to be able to take advantage of 844 /// this property, TargetInstrInfo::getExtractSubregLikeInputs has to be 845 /// override accordingly. 846 bool isExtractSubregLike(QueryType Type = IgnoreBundle) const { 847 return hasProperty(MCID::ExtractSubreg, Type); 848 } 849 850 /// Return true if this instruction behaves 851 /// the same way as the generic INSERT_SUBREG instructions. 852 /// E.g., on ARM, 853 /// dX = VSETLNi32 dY, rZ, Imm 854 /// is equivalent to a INSERT_SUBREG: 855 /// dX = INSERT_SUBREG dY, rZ, translateImmToSubIdx(Imm) 856 /// 857 /// Note that for the optimizers to be able to take advantage of 858 /// this property, TargetInstrInfo::getInsertSubregLikeInputs has to be 859 /// override accordingly. 860 bool isInsertSubregLike(QueryType Type = IgnoreBundle) const { 861 return hasProperty(MCID::InsertSubreg, Type); 862 } 863 864 //===--------------------------------------------------------------------===// 865 // Side Effect Analysis 866 //===--------------------------------------------------------------------===// 867 868 /// Return true if this instruction could possibly read memory. 869 /// Instructions with this flag set are not necessarily simple load 870 /// instructions, they may load a value and modify it, for example. 871 bool mayLoad(QueryType Type = AnyInBundle) const { 872 if (isInlineAsm()) { 873 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm(); 874 if (ExtraInfo & InlineAsm::Extra_MayLoad) 875 return true; 876 } 877 return hasProperty(MCID::MayLoad, Type); 878 } 879 880 /// Return true if this instruction could possibly modify memory. 881 /// Instructions with this flag set are not necessarily simple store 882 /// instructions, they may store a modified value based on their operands, or 883 /// may not actually modify anything, for example. 884 bool mayStore(QueryType Type = AnyInBundle) const { 885 if (isInlineAsm()) { 886 unsigned ExtraInfo = getOperand(InlineAsm::MIOp_ExtraInfo).getImm(); 887 if (ExtraInfo & InlineAsm::Extra_MayStore) 888 return true; 889 } 890 return hasProperty(MCID::MayStore, Type); 891 } 892 893 /// Return true if this instruction could possibly read or modify memory. 894 bool mayLoadOrStore(QueryType Type = AnyInBundle) const { 895 return mayLoad(Type) || mayStore(Type); 896 } 897 898 /// Return true if this instruction could possibly raise a floating-point 899 /// exception. This is the case if the instruction is a floating-point 900 /// instruction that can in principle raise an exception, as indicated 901 /// by the MCID::MayRaiseFPException property, *and* at the same time, 902 /// the instruction is used in a context where we expect floating-point 903 /// exceptions are not disabled, as indicated by the NoFPExcept MI flag. 904 bool mayRaiseFPException() const { 905 return hasProperty(MCID::MayRaiseFPException) && 906 !getFlag(MachineInstr::MIFlag::NoFPExcept); 907 } 908 909 //===--------------------------------------------------------------------===// 910 // Flags that indicate whether an instruction can be modified by a method. 911 //===--------------------------------------------------------------------===// 912 913 /// Return true if this may be a 2- or 3-address 914 /// instruction (of the form "X = op Y, Z, ..."), which produces the same 915 /// result if Y and Z are exchanged. If this flag is set, then the 916 /// TargetInstrInfo::commuteInstruction method may be used to hack on the 917 /// instruction. 918 /// 919 /// Note that this flag may be set on instructions that are only commutable 920 /// sometimes. In these cases, the call to commuteInstruction will fail. 921 /// Also note that some instructions require non-trivial modification to 922 /// commute them. 923 bool isCommutable(QueryType Type = IgnoreBundle) const { 924 return hasProperty(MCID::Commutable, Type); 925 } 926 927 /// Return true if this is a 2-address instruction 928 /// which can be changed into a 3-address instruction if needed. Doing this 929 /// transformation can be profitable in the register allocator, because it 930 /// means that the instruction can use a 2-address form if possible, but 931 /// degrade into a less efficient form if the source and dest register cannot 932 /// be assigned to the same register. For example, this allows the x86 933 /// backend to turn a "shl reg, 3" instruction into an LEA instruction, which 934 /// is the same speed as the shift but has bigger code size. 935 /// 936 /// If this returns true, then the target must implement the 937 /// TargetInstrInfo::convertToThreeAddress method for this instruction, which 938 /// is allowed to fail if the transformation isn't valid for this specific 939 /// instruction (e.g. shl reg, 4 on x86). 940 /// 941 bool isConvertibleTo3Addr(QueryType Type = IgnoreBundle) const { 942 return hasProperty(MCID::ConvertibleTo3Addr, Type); 943 } 944 945 /// Return true if this instruction requires 946 /// custom insertion support when the DAG scheduler is inserting it into a 947 /// machine basic block. If this is true for the instruction, it basically 948 /// means that it is a pseudo instruction used at SelectionDAG time that is 949 /// expanded out into magic code by the target when MachineInstrs are formed. 950 /// 951 /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method 952 /// is used to insert this into the MachineBasicBlock. 953 bool usesCustomInsertionHook(QueryType Type = IgnoreBundle) const { 954 return hasProperty(MCID::UsesCustomInserter, Type); 955 } 956 957 /// Return true if this instruction requires *adjustment* 958 /// after instruction selection by calling a target hook. For example, this 959 /// can be used to fill in ARM 's' optional operand depending on whether 960 /// the conditional flag register is used. 961 bool hasPostISelHook(QueryType Type = IgnoreBundle) const { 962 return hasProperty(MCID::HasPostISelHook, Type); 963 } 964 965 /// Returns true if this instruction is a candidate for remat. 966 /// This flag is deprecated, please don't use it anymore. If this 967 /// flag is set, the isReallyTriviallyReMaterializable() method is called to 968 /// verify the instruction is really rematable. 969 bool isRematerializable(QueryType Type = AllInBundle) const { 970 // It's only possible to re-mat a bundle if all bundled instructions are 971 // re-materializable. 972 return hasProperty(MCID::Rematerializable, Type); 973 } 974 975 /// Returns true if this instruction has the same cost (or less) than a move 976 /// instruction. This is useful during certain types of optimizations 977 /// (e.g., remat during two-address conversion or machine licm) 978 /// where we would like to remat or hoist the instruction, but not if it costs 979 /// more than moving the instruction into the appropriate register. Note, we 980 /// are not marking copies from and to the same register class with this flag. 981 bool isAsCheapAsAMove(QueryType Type = AllInBundle) const { 982 // Only returns true for a bundle if all bundled instructions are cheap. 983 return hasProperty(MCID::CheapAsAMove, Type); 984 } 985 986 /// Returns true if this instruction source operands 987 /// have special register allocation requirements that are not captured by the 988 /// operand register classes. e.g. ARM::STRD's two source registers must be an 989 /// even / odd pair, ARM::STM registers have to be in ascending order. 990 /// Post-register allocation passes should not attempt to change allocations 991 /// for sources of instructions with this flag. 992 bool hasExtraSrcRegAllocReq(QueryType Type = AnyInBundle) const { 993 return hasProperty(MCID::ExtraSrcRegAllocReq, Type); 994 } 995 996 /// Returns true if this instruction def operands 997 /// have special register allocation requirements that are not captured by the 998 /// operand register classes. e.g. ARM::LDRD's two def registers must be an 999 /// even / odd pair, ARM::LDM registers have to be in ascending order. 1000 /// Post-register allocation passes should not attempt to change allocations 1001 /// for definitions of instructions with this flag. 1002 bool hasExtraDefRegAllocReq(QueryType Type = AnyInBundle) const { 1003 return hasProperty(MCID::ExtraDefRegAllocReq, Type); 1004 } 1005 1006 enum MICheckType { 1007 CheckDefs, // Check all operands for equality 1008 CheckKillDead, // Check all operands including kill / dead markers 1009 IgnoreDefs, // Ignore all definitions 1010 IgnoreVRegDefs // Ignore virtual register definitions 1011 }; 1012 1013 /// Return true if this instruction is identical to \p Other. 1014 /// Two instructions are identical if they have the same opcode and all their 1015 /// operands are identical (with respect to MachineOperand::isIdenticalTo()). 1016 /// Note that this means liveness related flags (dead, undef, kill) do not 1017 /// affect the notion of identical. 1018 bool isIdenticalTo(const MachineInstr &Other, 1019 MICheckType Check = CheckDefs) const; 1020 1021 /// Unlink 'this' from the containing basic block, and return it without 1022 /// deleting it. 1023 /// 1024 /// This function can not be used on bundled instructions, use 1025 /// removeFromBundle() to remove individual instructions from a bundle. 1026 MachineInstr *removeFromParent(); 1027 1028 /// Unlink this instruction from its basic block and return it without 1029 /// deleting it. 1030 /// 1031 /// If the instruction is part of a bundle, the other instructions in the 1032 /// bundle remain bundled. 1033 MachineInstr *removeFromBundle(); 1034 1035 /// Unlink 'this' from the containing basic block and delete it. 1036 /// 1037 /// If this instruction is the header of a bundle, the whole bundle is erased. 1038 /// This function can not be used for instructions inside a bundle, use 1039 /// eraseFromBundle() to erase individual bundled instructions. 1040 void eraseFromParent(); 1041 1042 /// Unlink 'this' from the containing basic block and delete it. 1043 /// 1044 /// For all definitions mark their uses in DBG_VALUE nodes 1045 /// as undefined. Otherwise like eraseFromParent(). 1046 void eraseFromParentAndMarkDBGValuesForRemoval(); 1047 1048 /// Unlink 'this' form its basic block and delete it. 1049 /// 1050 /// If the instruction is part of a bundle, the other instructions in the 1051 /// bundle remain bundled. 1052 void eraseFromBundle(); 1053 1054 bool isEHLabel() const { return getOpcode() == TargetOpcode::EH_LABEL; } 1055 bool isGCLabel() const { return getOpcode() == TargetOpcode::GC_LABEL; } 1056 bool isAnnotationLabel() const { 1057 return getOpcode() == TargetOpcode::ANNOTATION_LABEL; 1058 } 1059 1060 /// Returns true if the MachineInstr represents a label. 1061 bool isLabel() const { 1062 return isEHLabel() || isGCLabel() || isAnnotationLabel(); 1063 } 1064 1065 bool isCFIInstruction() const { 1066 return getOpcode() == TargetOpcode::CFI_INSTRUCTION; 1067 } 1068 1069 // True if the instruction represents a position in the function. 1070 bool isPosition() const { return isLabel() || isCFIInstruction(); } 1071 1072 bool isDebugValue() const { return getOpcode() == TargetOpcode::DBG_VALUE; } 1073 bool isDebugLabel() const { return getOpcode() == TargetOpcode::DBG_LABEL; } 1074 bool isDebugInstr() const { return isDebugValue() || isDebugLabel(); } 1075 1076 /// A DBG_VALUE is indirect iff the first operand is a register and 1077 /// the second operand is an immediate. 1078 bool isIndirectDebugValue() const { 1079 return isDebugValue() 1080 && getOperand(0).isReg() 1081 && getOperand(1).isImm(); 1082 } 1083 1084 /// A DBG_VALUE is an entry value iff its debug expression contains the 1085 /// DW_OP_LLVM_entry_value operation. 1086 bool isDebugEntryValue() const; 1087 1088 /// Return true if the instruction is a debug value which describes a part of 1089 /// a variable as unavailable. 1090 bool isUndefDebugValue() const { 1091 return isDebugValue() && getOperand(0).isReg() && !getOperand(0).getReg().isValid(); 1092 } 1093 1094 bool isPHI() const { 1095 return getOpcode() == TargetOpcode::PHI || 1096 getOpcode() == TargetOpcode::G_PHI; 1097 } 1098 bool isKill() const { return getOpcode() == TargetOpcode::KILL; } 1099 bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; } 1100 bool isInlineAsm() const { 1101 return getOpcode() == TargetOpcode::INLINEASM || 1102 getOpcode() == TargetOpcode::INLINEASM_BR; 1103 } 1104 1105 /// FIXME: Seems like a layering violation that the AsmDialect, which is X86 1106 /// specific, be attached to a generic MachineInstr. 1107 bool isMSInlineAsm() const { 1108 return isInlineAsm() && getInlineAsmDialect() == InlineAsm::AD_Intel; 1109 } 1110 1111 bool isStackAligningInlineAsm() const; 1112 InlineAsm::AsmDialect getInlineAsmDialect() const; 1113 1114 bool isInsertSubreg() const { 1115 return getOpcode() == TargetOpcode::INSERT_SUBREG; 1116 } 1117 1118 bool isSubregToReg() const { 1119 return getOpcode() == TargetOpcode::SUBREG_TO_REG; 1120 } 1121 1122 bool isRegSequence() const { 1123 return getOpcode() == TargetOpcode::REG_SEQUENCE; 1124 } 1125 1126 bool isBundle() const { 1127 return getOpcode() == TargetOpcode::BUNDLE; 1128 } 1129 1130 bool isCopy() const { 1131 return getOpcode() == TargetOpcode::COPY; 1132 } 1133 1134 bool isFullCopy() const { 1135 return isCopy() && !getOperand(0).getSubReg() && !getOperand(1).getSubReg(); 1136 } 1137 1138 bool isExtractSubreg() const { 1139 return getOpcode() == TargetOpcode::EXTRACT_SUBREG; 1140 } 1141 1142 /// Return true if the instruction behaves like a copy. 1143 /// This does not include native copy instructions. 1144 bool isCopyLike() const { 1145 return isCopy() || isSubregToReg(); 1146 } 1147 1148 /// Return true is the instruction is an identity copy. 1149 bool isIdentityCopy() const { 1150 return isCopy() && getOperand(0).getReg() == getOperand(1).getReg() && 1151 getOperand(0).getSubReg() == getOperand(1).getSubReg(); 1152 } 1153 1154 /// Return true if this instruction doesn't produce any output in the form of 1155 /// executable instructions. 1156 bool isMetaInstruction() const { 1157 switch (getOpcode()) { 1158 default: 1159 return false; 1160 case TargetOpcode::IMPLICIT_DEF: 1161 case TargetOpcode::KILL: 1162 case TargetOpcode::CFI_INSTRUCTION: 1163 case TargetOpcode::EH_LABEL: 1164 case TargetOpcode::GC_LABEL: 1165 case TargetOpcode::DBG_VALUE: 1166 case TargetOpcode::DBG_LABEL: 1167 case TargetOpcode::LIFETIME_START: 1168 case TargetOpcode::LIFETIME_END: 1169 return true; 1170 } 1171 } 1172 1173 /// Return true if this is a transient instruction that is either very likely 1174 /// to be eliminated during register allocation (such as copy-like 1175 /// instructions), or if this instruction doesn't have an execution-time cost. 1176 bool isTransient() const { 1177 switch (getOpcode()) { 1178 default: 1179 return isMetaInstruction(); 1180 // Copy-like instructions are usually eliminated during register allocation. 1181 case TargetOpcode::PHI: 1182 case TargetOpcode::G_PHI: 1183 case TargetOpcode::COPY: 1184 case TargetOpcode::INSERT_SUBREG: 1185 case TargetOpcode::SUBREG_TO_REG: 1186 case TargetOpcode::REG_SEQUENCE: 1187 return true; 1188 } 1189 } 1190 1191 /// Return the number of instructions inside the MI bundle, excluding the 1192 /// bundle header. 1193 /// 1194 /// This is the number of instructions that MachineBasicBlock::iterator 1195 /// skips, 0 for unbundled instructions. 1196 unsigned getBundleSize() const; 1197 1198 /// Return true if the MachineInstr reads the specified register. 1199 /// If TargetRegisterInfo is passed, then it also checks if there 1200 /// is a read of a super-register. 1201 /// This does not count partial redefines of virtual registers as reads: 1202 /// %reg1024:6 = OP. 1203 bool readsRegister(Register Reg, 1204 const TargetRegisterInfo *TRI = nullptr) const { 1205 return findRegisterUseOperandIdx(Reg, false, TRI) != -1; 1206 } 1207 1208 /// Return true if the MachineInstr reads the specified virtual register. 1209 /// Take into account that a partial define is a 1210 /// read-modify-write operation. 1211 bool readsVirtualRegister(Register Reg) const { 1212 return readsWritesVirtualRegister(Reg).first; 1213 } 1214 1215 /// Return a pair of bools (reads, writes) indicating if this instruction 1216 /// reads or writes Reg. This also considers partial defines. 1217 /// If Ops is not null, all operand indices for Reg are added. 1218 std::pair<bool,bool> readsWritesVirtualRegister(Register Reg, 1219 SmallVectorImpl<unsigned> *Ops = nullptr) const; 1220 1221 /// Return true if the MachineInstr kills the specified register. 1222 /// If TargetRegisterInfo is passed, then it also checks if there is 1223 /// a kill of a super-register. 1224 bool killsRegister(Register Reg, 1225 const TargetRegisterInfo *TRI = nullptr) const { 1226 return findRegisterUseOperandIdx(Reg, true, TRI) != -1; 1227 } 1228 1229 /// Return true if the MachineInstr fully defines the specified register. 1230 /// If TargetRegisterInfo is passed, then it also checks 1231 /// if there is a def of a super-register. 1232 /// NOTE: It's ignoring subreg indices on virtual registers. 1233 bool definesRegister(Register Reg, 1234 const TargetRegisterInfo *TRI = nullptr) const { 1235 return findRegisterDefOperandIdx(Reg, false, false, TRI) != -1; 1236 } 1237 1238 /// Return true if the MachineInstr modifies (fully define or partially 1239 /// define) the specified register. 1240 /// NOTE: It's ignoring subreg indices on virtual registers. 1241 bool modifiesRegister(Register Reg, const TargetRegisterInfo *TRI) const { 1242 return findRegisterDefOperandIdx(Reg, false, true, TRI) != -1; 1243 } 1244 1245 /// Returns true if the register is dead in this machine instruction. 1246 /// If TargetRegisterInfo is passed, then it also checks 1247 /// if there is a dead def of a super-register. 1248 bool registerDefIsDead(Register Reg, 1249 const TargetRegisterInfo *TRI = nullptr) const { 1250 return findRegisterDefOperandIdx(Reg, true, false, TRI) != -1; 1251 } 1252 1253 /// Returns true if the MachineInstr has an implicit-use operand of exactly 1254 /// the given register (not considering sub/super-registers). 1255 bool hasRegisterImplicitUseOperand(Register Reg) const; 1256 1257 /// Returns the operand index that is a use of the specific register or -1 1258 /// if it is not found. It further tightens the search criteria to a use 1259 /// that kills the register if isKill is true. 1260 int findRegisterUseOperandIdx(Register Reg, bool isKill = false, 1261 const TargetRegisterInfo *TRI = nullptr) const; 1262 1263 /// Wrapper for findRegisterUseOperandIdx, it returns 1264 /// a pointer to the MachineOperand rather than an index. 1265 MachineOperand *findRegisterUseOperand(Register Reg, bool isKill = false, 1266 const TargetRegisterInfo *TRI = nullptr) { 1267 int Idx = findRegisterUseOperandIdx(Reg, isKill, TRI); 1268 return (Idx == -1) ? nullptr : &getOperand(Idx); 1269 } 1270 1271 const MachineOperand *findRegisterUseOperand( 1272 Register Reg, bool isKill = false, 1273 const TargetRegisterInfo *TRI = nullptr) const { 1274 return const_cast<MachineInstr *>(this)-> 1275 findRegisterUseOperand(Reg, isKill, TRI); 1276 } 1277 1278 /// Returns the operand index that is a def of the specified register or 1279 /// -1 if it is not found. If isDead is true, defs that are not dead are 1280 /// skipped. If Overlap is true, then it also looks for defs that merely 1281 /// overlap the specified register. If TargetRegisterInfo is non-null, 1282 /// then it also checks if there is a def of a super-register. 1283 /// This may also return a register mask operand when Overlap is true. 1284 int findRegisterDefOperandIdx(Register Reg, 1285 bool isDead = false, bool Overlap = false, 1286 const TargetRegisterInfo *TRI = nullptr) const; 1287 1288 /// Wrapper for findRegisterDefOperandIdx, it returns 1289 /// a pointer to the MachineOperand rather than an index. 1290 MachineOperand * 1291 findRegisterDefOperand(Register Reg, bool isDead = false, 1292 bool Overlap = false, 1293 const TargetRegisterInfo *TRI = nullptr) { 1294 int Idx = findRegisterDefOperandIdx(Reg, isDead, Overlap, TRI); 1295 return (Idx == -1) ? nullptr : &getOperand(Idx); 1296 } 1297 1298 const MachineOperand * 1299 findRegisterDefOperand(Register Reg, bool isDead = false, 1300 bool Overlap = false, 1301 const TargetRegisterInfo *TRI = nullptr) const { 1302 return const_cast<MachineInstr *>(this)->findRegisterDefOperand( 1303 Reg, isDead, Overlap, TRI); 1304 } 1305 1306 /// Find the index of the first operand in the 1307 /// operand list that is used to represent the predicate. It returns -1 if 1308 /// none is found. 1309 int findFirstPredOperandIdx() const; 1310 1311 /// Find the index of the flag word operand that 1312 /// corresponds to operand OpIdx on an inline asm instruction. Returns -1 if 1313 /// getOperand(OpIdx) does not belong to an inline asm operand group. 1314 /// 1315 /// If GroupNo is not NULL, it will receive the number of the operand group 1316 /// containing OpIdx. 1317 /// 1318 /// The flag operand is an immediate that can be decoded with methods like 1319 /// InlineAsm::hasRegClassConstraint(). 1320 int findInlineAsmFlagIdx(unsigned OpIdx, unsigned *GroupNo = nullptr) const; 1321 1322 /// Compute the static register class constraint for operand OpIdx. 1323 /// For normal instructions, this is derived from the MCInstrDesc. 1324 /// For inline assembly it is derived from the flag words. 1325 /// 1326 /// Returns NULL if the static register class constraint cannot be 1327 /// determined. 1328 const TargetRegisterClass* 1329 getRegClassConstraint(unsigned OpIdx, 1330 const TargetInstrInfo *TII, 1331 const TargetRegisterInfo *TRI) const; 1332 1333 /// Applies the constraints (def/use) implied by this MI on \p Reg to 1334 /// the given \p CurRC. 1335 /// If \p ExploreBundle is set and MI is part of a bundle, all the 1336 /// instructions inside the bundle will be taken into account. In other words, 1337 /// this method accumulates all the constraints of the operand of this MI and 1338 /// the related bundle if MI is a bundle or inside a bundle. 1339 /// 1340 /// Returns the register class that satisfies both \p CurRC and the 1341 /// constraints set by MI. Returns NULL if such a register class does not 1342 /// exist. 1343 /// 1344 /// \pre CurRC must not be NULL. 1345 const TargetRegisterClass *getRegClassConstraintEffectForVReg( 1346 Register Reg, const TargetRegisterClass *CurRC, 1347 const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, 1348 bool ExploreBundle = false) const; 1349 1350 /// Applies the constraints (def/use) implied by the \p OpIdx operand 1351 /// to the given \p CurRC. 1352 /// 1353 /// Returns the register class that satisfies both \p CurRC and the 1354 /// constraints set by \p OpIdx MI. Returns NULL if such a register class 1355 /// does not exist. 1356 /// 1357 /// \pre CurRC must not be NULL. 1358 /// \pre The operand at \p OpIdx must be a register. 1359 const TargetRegisterClass * 1360 getRegClassConstraintEffect(unsigned OpIdx, const TargetRegisterClass *CurRC, 1361 const TargetInstrInfo *TII, 1362 const TargetRegisterInfo *TRI) const; 1363 1364 /// Add a tie between the register operands at DefIdx and UseIdx. 1365 /// The tie will cause the register allocator to ensure that the two 1366 /// operands are assigned the same physical register. 1367 /// 1368 /// Tied operands are managed automatically for explicit operands in the 1369 /// MCInstrDesc. This method is for exceptional cases like inline asm. 1370 void tieOperands(unsigned DefIdx, unsigned UseIdx); 1371 1372 /// Given the index of a tied register operand, find the 1373 /// operand it is tied to. Defs are tied to uses and vice versa. Returns the 1374 /// index of the tied operand which must exist. 1375 unsigned findTiedOperandIdx(unsigned OpIdx) const; 1376 1377 /// Given the index of a register def operand, 1378 /// check if the register def is tied to a source operand, due to either 1379 /// two-address elimination or inline assembly constraints. Returns the 1380 /// first tied use operand index by reference if UseOpIdx is not null. 1381 bool isRegTiedToUseOperand(unsigned DefOpIdx, 1382 unsigned *UseOpIdx = nullptr) const { 1383 const MachineOperand &MO = getOperand(DefOpIdx); 1384 if (!MO.isReg() || !MO.isDef() || !MO.isTied()) 1385 return false; 1386 if (UseOpIdx) 1387 *UseOpIdx = findTiedOperandIdx(DefOpIdx); 1388 return true; 1389 } 1390 1391 /// Return true if the use operand of the specified index is tied to a def 1392 /// operand. It also returns the def operand index by reference if DefOpIdx 1393 /// is not null. 1394 bool isRegTiedToDefOperand(unsigned UseOpIdx, 1395 unsigned *DefOpIdx = nullptr) const { 1396 const MachineOperand &MO = getOperand(UseOpIdx); 1397 if (!MO.isReg() || !MO.isUse() || !MO.isTied()) 1398 return false; 1399 if (DefOpIdx) 1400 *DefOpIdx = findTiedOperandIdx(UseOpIdx); 1401 return true; 1402 } 1403 1404 /// Clears kill flags on all operands. 1405 void clearKillInfo(); 1406 1407 /// Replace all occurrences of FromReg with ToReg:SubIdx, 1408 /// properly composing subreg indices where necessary. 1409 void substituteRegister(Register FromReg, Register ToReg, unsigned SubIdx, 1410 const TargetRegisterInfo &RegInfo); 1411 1412 /// We have determined MI kills a register. Look for the 1413 /// operand that uses it and mark it as IsKill. If AddIfNotFound is true, 1414 /// add a implicit operand if it's not found. Returns true if the operand 1415 /// exists / is added. 1416 bool addRegisterKilled(Register IncomingReg, 1417 const TargetRegisterInfo *RegInfo, 1418 bool AddIfNotFound = false); 1419 1420 /// Clear all kill flags affecting Reg. If RegInfo is provided, this includes 1421 /// all aliasing registers. 1422 void clearRegisterKills(Register Reg, const TargetRegisterInfo *RegInfo); 1423 1424 /// We have determined MI defined a register without a use. 1425 /// Look for the operand that defines it and mark it as IsDead. If 1426 /// AddIfNotFound is true, add a implicit operand if it's not found. Returns 1427 /// true if the operand exists / is added. 1428 bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, 1429 bool AddIfNotFound = false); 1430 1431 /// Clear all dead flags on operands defining register @p Reg. 1432 void clearRegisterDeads(Register Reg); 1433 1434 /// Mark all subregister defs of register @p Reg with the undef flag. 1435 /// This function is used when we determined to have a subregister def in an 1436 /// otherwise undefined super register. 1437 void setRegisterDefReadUndef(Register Reg, bool IsUndef = true); 1438 1439 /// We have determined MI defines a register. Make sure there is an operand 1440 /// defining Reg. 1441 void addRegisterDefined(Register Reg, 1442 const TargetRegisterInfo *RegInfo = nullptr); 1443 1444 /// Mark every physreg used by this instruction as 1445 /// dead except those in the UsedRegs list. 1446 /// 1447 /// On instructions with register mask operands, also add implicit-def 1448 /// operands for all registers in UsedRegs. 1449 void setPhysRegsDeadExcept(ArrayRef<Register> UsedRegs, 1450 const TargetRegisterInfo &TRI); 1451 1452 /// Return true if it is safe to move this instruction. If 1453 /// SawStore is set to true, it means that there is a store (or call) between 1454 /// the instruction's location and its intended destination. 1455 bool isSafeToMove(AAResults *AA, bool &SawStore) const; 1456 1457 /// Returns true if this instruction's memory access aliases the memory 1458 /// access of Other. 1459 // 1460 /// Assumes any physical registers used to compute addresses 1461 /// have the same value for both instructions. Returns false if neither 1462 /// instruction writes to memory. 1463 /// 1464 /// @param AA Optional alias analysis, used to compare memory operands. 1465 /// @param Other MachineInstr to check aliasing against. 1466 /// @param UseTBAA Whether to pass TBAA information to alias analysis. 1467 bool mayAlias(AAResults *AA, const MachineInstr &Other, bool UseTBAA) const; 1468 1469 /// Return true if this instruction may have an ordered 1470 /// or volatile memory reference, or if the information describing the memory 1471 /// reference is not available. Return false if it is known to have no 1472 /// ordered or volatile memory references. 1473 bool hasOrderedMemoryRef() const; 1474 1475 /// Return true if this load instruction never traps and points to a memory 1476 /// location whose value doesn't change during the execution of this function. 1477 /// 1478 /// Examples include loading a value from the constant pool or from the 1479 /// argument area of a function (if it does not change). If the instruction 1480 /// does multiple loads, this returns true only if all of the loads are 1481 /// dereferenceable and invariant. 1482 bool isDereferenceableInvariantLoad(AAResults *AA) const; 1483 1484 /// If the specified instruction is a PHI that always merges together the 1485 /// same virtual register, return the register, otherwise return 0. 1486 unsigned isConstantValuePHI() const; 1487 1488 /// Return true if this instruction has side effects that are not modeled 1489 /// by mayLoad / mayStore, etc. 1490 /// For all instructions, the property is encoded in MCInstrDesc::Flags 1491 /// (see MCInstrDesc::hasUnmodeledSideEffects(). The only exception is 1492 /// INLINEASM instruction, in which case the side effect property is encoded 1493 /// in one of its operands (see InlineAsm::Extra_HasSideEffect). 1494 /// 1495 bool hasUnmodeledSideEffects() const; 1496 1497 /// Returns true if it is illegal to fold a load across this instruction. 1498 bool isLoadFoldBarrier() const; 1499 1500 /// Return true if all the defs of this instruction are dead. 1501 bool allDefsAreDead() const; 1502 1503 /// Return a valid size if the instruction is a spill instruction. 1504 Optional<unsigned> getSpillSize(const TargetInstrInfo *TII) const; 1505 1506 /// Return a valid size if the instruction is a folded spill instruction. 1507 Optional<unsigned> getFoldedSpillSize(const TargetInstrInfo *TII) const; 1508 1509 /// Return a valid size if the instruction is a restore instruction. 1510 Optional<unsigned> getRestoreSize(const TargetInstrInfo *TII) const; 1511 1512 /// Return a valid size if the instruction is a folded restore instruction. 1513 Optional<unsigned> 1514 getFoldedRestoreSize(const TargetInstrInfo *TII) const; 1515 1516 /// Copy implicit register operands from specified 1517 /// instruction to this instruction. 1518 void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI); 1519 1520 /// Debugging support 1521 /// @{ 1522 /// Determine the generic type to be printed (if needed) on uses and defs. 1523 LLT getTypeToPrint(unsigned OpIdx, SmallBitVector &PrintedTypes, 1524 const MachineRegisterInfo &MRI) const; 1525 1526 /// Return true when an instruction has tied register that can't be determined 1527 /// by the instruction's descriptor. This is useful for MIR printing, to 1528 /// determine whether we need to print the ties or not. 1529 bool hasComplexRegisterTies() const; 1530 1531 /// Print this MI to \p OS. 1532 /// Don't print information that can be inferred from other instructions if 1533 /// \p IsStandalone is false. It is usually true when only a fragment of the 1534 /// function is printed. 1535 /// Only print the defs and the opcode if \p SkipOpers is true. 1536 /// Otherwise, also print operands if \p SkipDebugLoc is true. 1537 /// Otherwise, also print the debug loc, with a terminating newline. 1538 /// \p TII is used to print the opcode name. If it's not present, but the 1539 /// MI is in a function, the opcode will be printed using the function's TII. 1540 void print(raw_ostream &OS, bool IsStandalone = true, bool SkipOpers = false, 1541 bool SkipDebugLoc = false, bool AddNewLine = true, 1542 const TargetInstrInfo *TII = nullptr) const; 1543 void print(raw_ostream &OS, ModuleSlotTracker &MST, bool IsStandalone = true, 1544 bool SkipOpers = false, bool SkipDebugLoc = false, 1545 bool AddNewLine = true, 1546 const TargetInstrInfo *TII = nullptr) const; 1547 void dump() const; 1548 /// Print on dbgs() the current instruction and the instructions defining its 1549 /// operands and so on until we reach \p MaxDepth. 1550 void dumpr(const MachineRegisterInfo &MRI, 1551 unsigned MaxDepth = UINT_MAX) const; 1552 /// @} 1553 1554 //===--------------------------------------------------------------------===// 1555 // Accessors used to build up machine instructions. 1556 1557 /// Add the specified operand to the instruction. If it is an implicit 1558 /// operand, it is added to the end of the operand list. If it is an 1559 /// explicit operand it is added at the end of the explicit operand list 1560 /// (before the first implicit operand). 1561 /// 1562 /// MF must be the machine function that was used to allocate this 1563 /// instruction. 1564 /// 1565 /// MachineInstrBuilder provides a more convenient interface for creating 1566 /// instructions and adding operands. 1567 void addOperand(MachineFunction &MF, const MachineOperand &Op); 1568 1569 /// Add an operand without providing an MF reference. This only works for 1570 /// instructions that are inserted in a basic block. 1571 /// 1572 /// MachineInstrBuilder and the two-argument addOperand(MF, MO) should be 1573 /// preferred. 1574 void addOperand(const MachineOperand &Op); 1575 1576 /// Replace the instruction descriptor (thus opcode) of 1577 /// the current instruction with a new one. 1578 void setDesc(const MCInstrDesc &tid) { MCID = &tid; } 1579 1580 /// Replace current source information with new such. 1581 /// Avoid using this, the constructor argument is preferable. 1582 void setDebugLoc(DebugLoc dl) { 1583 debugLoc = std::move(dl); 1584 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor"); 1585 } 1586 1587 /// Erase an operand from an instruction, leaving it with one 1588 /// fewer operand than it started with. 1589 void RemoveOperand(unsigned OpNo); 1590 1591 /// Clear this MachineInstr's memory reference descriptor list. This resets 1592 /// the memrefs to their most conservative state. This should be used only 1593 /// as a last resort since it greatly pessimizes our knowledge of the memory 1594 /// access performed by the instruction. 1595 void dropMemRefs(MachineFunction &MF); 1596 1597 /// Assign this MachineInstr's memory reference descriptor list. 1598 /// 1599 /// Unlike other methods, this *will* allocate them into a new array 1600 /// associated with the provided `MachineFunction`. 1601 void setMemRefs(MachineFunction &MF, ArrayRef<MachineMemOperand *> MemRefs); 1602 1603 /// Add a MachineMemOperand to the machine instruction. 1604 /// This function should be used only occasionally. The setMemRefs function 1605 /// is the primary method for setting up a MachineInstr's MemRefs list. 1606 void addMemOperand(MachineFunction &MF, MachineMemOperand *MO); 1607 1608 /// Clone another MachineInstr's memory reference descriptor list and replace 1609 /// ours with it. 1610 /// 1611 /// Note that `*this` may be the incoming MI! 1612 /// 1613 /// Prefer this API whenever possible as it can avoid allocations in common 1614 /// cases. 1615 void cloneMemRefs(MachineFunction &MF, const MachineInstr &MI); 1616 1617 /// Clone the merge of multiple MachineInstrs' memory reference descriptors 1618 /// list and replace ours with it. 1619 /// 1620 /// Note that `*this` may be one of the incoming MIs! 1621 /// 1622 /// Prefer this API whenever possible as it can avoid allocations in common 1623 /// cases. 1624 void cloneMergedMemRefs(MachineFunction &MF, 1625 ArrayRef<const MachineInstr *> MIs); 1626 1627 /// Set a symbol that will be emitted just prior to the instruction itself. 1628 /// 1629 /// Setting this to a null pointer will remove any such symbol. 1630 /// 1631 /// FIXME: This is not fully implemented yet. 1632 void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol); 1633 1634 /// Set a symbol that will be emitted just after the instruction itself. 1635 /// 1636 /// Setting this to a null pointer will remove any such symbol. 1637 /// 1638 /// FIXME: This is not fully implemented yet. 1639 void setPostInstrSymbol(MachineFunction &MF, MCSymbol *Symbol); 1640 1641 /// Clone another MachineInstr's pre- and post- instruction symbols and 1642 /// replace ours with it. 1643 void cloneInstrSymbols(MachineFunction &MF, const MachineInstr &MI); 1644 1645 /// Set a marker on instructions that denotes where we should create and emit 1646 /// heap alloc site labels. This waits until after instruction selection and 1647 /// optimizations to create the label, so it should still work if the 1648 /// instruction is removed or duplicated. 1649 void setHeapAllocMarker(MachineFunction &MF, MDNode *MD); 1650 1651 /// Return the MIFlags which represent both MachineInstrs. This 1652 /// should be used when merging two MachineInstrs into one. This routine does 1653 /// not modify the MIFlags of this MachineInstr. 1654 uint16_t mergeFlagsWith(const MachineInstr& Other) const; 1655 1656 static uint16_t copyFlagsFromInstruction(const Instruction &I); 1657 1658 /// Copy all flags to MachineInst MIFlags 1659 void copyIRFlags(const Instruction &I); 1660 1661 /// Break any tie involving OpIdx. 1662 void untieRegOperand(unsigned OpIdx) { 1663 MachineOperand &MO = getOperand(OpIdx); 1664 if (MO.isReg() && MO.isTied()) { 1665 getOperand(findTiedOperandIdx(OpIdx)).TiedTo = 0; 1666 MO.TiedTo = 0; 1667 } 1668 } 1669 1670 /// Add all implicit def and use operands to this instruction. 1671 void addImplicitDefUseOperands(MachineFunction &MF); 1672 1673 /// Scan instructions immediately following MI and collect any matching 1674 /// DBG_VALUEs. 1675 void collectDebugValues(SmallVectorImpl<MachineInstr *> &DbgValues); 1676 1677 /// Find all DBG_VALUEs that point to the register def in this instruction 1678 /// and point them to \p Reg instead. 1679 void changeDebugValuesDefReg(Register Reg); 1680 1681 /// Returns the Intrinsic::ID for this instruction. 1682 /// \pre Must have an intrinsic ID operand. 1683 unsigned getIntrinsicID() const { 1684 return getOperand(getNumExplicitDefs()).getIntrinsicID(); 1685 } 1686 1687 private: 1688 /// If this instruction is embedded into a MachineFunction, return the 1689 /// MachineRegisterInfo object for the current function, otherwise 1690 /// return null. 1691 MachineRegisterInfo *getRegInfo(); 1692 1693 /// Unlink all of the register operands in this instruction from their 1694 /// respective use lists. This requires that the operands already be on their 1695 /// use lists. 1696 void RemoveRegOperandsFromUseLists(MachineRegisterInfo&); 1697 1698 /// Add all of the register operands in this instruction from their 1699 /// respective use lists. This requires that the operands not be on their 1700 /// use lists yet. 1701 void AddRegOperandsToUseLists(MachineRegisterInfo&); 1702 1703 /// Slow path for hasProperty when we're dealing with a bundle. 1704 bool hasPropertyInBundle(uint64_t Mask, QueryType Type) const; 1705 1706 /// Implements the logic of getRegClassConstraintEffectForVReg for the 1707 /// this MI and the given operand index \p OpIdx. 1708 /// If the related operand does not constrained Reg, this returns CurRC. 1709 const TargetRegisterClass *getRegClassConstraintEffectForVRegImpl( 1710 unsigned OpIdx, Register Reg, const TargetRegisterClass *CurRC, 1711 const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const; 1712 1713 /// Stores extra instruction information inline or allocates as ExtraInfo 1714 /// based on the number of pointers. 1715 void setExtraInfo(MachineFunction &MF, ArrayRef<MachineMemOperand *> MMOs, 1716 MCSymbol *PreInstrSymbol, MCSymbol *PostInstrSymbol, 1717 MDNode *HeapAllocMarker); 1718 }; 1719 1720 /// Special DenseMapInfo traits to compare MachineInstr* by *value* of the 1721 /// instruction rather than by pointer value. 1722 /// The hashing and equality testing functions ignore definitions so this is 1723 /// useful for CSE, etc. 1724 struct MachineInstrExpressionTrait : DenseMapInfo<MachineInstr*> { 1725 static inline MachineInstr *getEmptyKey() { 1726 return nullptr; 1727 } 1728 1729 static inline MachineInstr *getTombstoneKey() { 1730 return reinterpret_cast<MachineInstr*>(-1); 1731 } 1732 1733 static unsigned getHashValue(const MachineInstr* const &MI); 1734 1735 static bool isEqual(const MachineInstr* const &LHS, 1736 const MachineInstr* const &RHS) { 1737 if (RHS == getEmptyKey() || RHS == getTombstoneKey() || 1738 LHS == getEmptyKey() || LHS == getTombstoneKey()) 1739 return LHS == RHS; 1740 return LHS->isIdenticalTo(*RHS, MachineInstr::IgnoreVRegDefs); 1741 } 1742 }; 1743 1744 //===----------------------------------------------------------------------===// 1745 // Debugging Support 1746 1747 inline raw_ostream& operator<<(raw_ostream &OS, const MachineInstr &MI) { 1748 MI.print(OS); 1749 return OS; 1750 } 1751 1752 } // end namespace llvm 1753 1754 #endif // LLVM_CODEGEN_MACHINEINSTR_H 1755