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