1 //===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- 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 defines classes that make it really easy to deal with intrinsic 10 // functions with the isa/dyncast family of functions. In particular, this 11 // allows you to do things like: 12 // 13 // if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst)) 14 // ... MCI->getDest() ... MCI->getSource() ... 15 // 16 // All intrinsic function calls are instances of the call instruction, so these 17 // are all subclasses of the CallInst class. Note that none of these classes 18 // has state or virtual methods, which is an important part of this gross/neat 19 // hack working. 20 // 21 //===----------------------------------------------------------------------===// 22 23 #ifndef LLVM_IR_INTRINSICINST_H 24 #define LLVM_IR_INTRINSICINST_H 25 26 #include "llvm/IR/Constants.h" 27 #include "llvm/IR/DebugInfoMetadata.h" 28 #include "llvm/IR/DerivedTypes.h" 29 #include "llvm/IR/FPEnv.h" 30 #include "llvm/IR/Function.h" 31 #include "llvm/IR/GlobalVariable.h" 32 #include "llvm/IR/Instructions.h" 33 #include "llvm/IR/Intrinsics.h" 34 #include "llvm/IR/Metadata.h" 35 #include "llvm/IR/Value.h" 36 #include "llvm/Support/Casting.h" 37 #include <cassert> 38 #include <cstdint> 39 40 namespace llvm { 41 42 /// A wrapper class for inspecting calls to intrinsic functions. 43 /// This allows the standard isa/dyncast/cast functionality to work with calls 44 /// to intrinsic functions. 45 class IntrinsicInst : public CallInst { 46 public: 47 IntrinsicInst() = delete; 48 IntrinsicInst(const IntrinsicInst &) = delete; 49 IntrinsicInst &operator=(const IntrinsicInst &) = delete; 50 51 /// Return the intrinsic ID of this intrinsic. 52 Intrinsic::ID getIntrinsicID() const { 53 return getCalledFunction()->getIntrinsicID(); 54 } 55 56 /// Return true if swapping the first two arguments to the intrinsic produces 57 /// the same result. 58 bool isCommutative() const { 59 switch (getIntrinsicID()) { 60 case Intrinsic::maxnum: 61 case Intrinsic::minnum: 62 case Intrinsic::maximum: 63 case Intrinsic::minimum: 64 case Intrinsic::smax: 65 case Intrinsic::smin: 66 case Intrinsic::umax: 67 case Intrinsic::umin: 68 case Intrinsic::sadd_sat: 69 case Intrinsic::uadd_sat: 70 case Intrinsic::sadd_with_overflow: 71 case Intrinsic::uadd_with_overflow: 72 case Intrinsic::smul_with_overflow: 73 case Intrinsic::umul_with_overflow: 74 case Intrinsic::smul_fix: 75 case Intrinsic::umul_fix: 76 case Intrinsic::smul_fix_sat: 77 case Intrinsic::umul_fix_sat: 78 case Intrinsic::fma: 79 case Intrinsic::fmuladd: 80 return true; 81 default: 82 return false; 83 } 84 } 85 86 // Checks if the intrinsic is an annotation. 87 bool isAssumeLikeIntrinsic() const { 88 switch (getIntrinsicID()) { 89 default: break; 90 case Intrinsic::assume: 91 case Intrinsic::sideeffect: 92 case Intrinsic::pseudoprobe: 93 case Intrinsic::dbg_declare: 94 case Intrinsic::dbg_value: 95 case Intrinsic::dbg_label: 96 case Intrinsic::invariant_start: 97 case Intrinsic::invariant_end: 98 case Intrinsic::lifetime_start: 99 case Intrinsic::lifetime_end: 100 case Intrinsic::experimental_noalias_scope_decl: 101 case Intrinsic::objectsize: 102 case Intrinsic::ptr_annotation: 103 case Intrinsic::var_annotation: 104 return true; 105 } 106 return false; 107 } 108 109 // Methods for support type inquiry through isa, cast, and dyn_cast: 110 static bool classof(const CallInst *I) { 111 if (const Function *CF = I->getCalledFunction()) 112 return CF->isIntrinsic(); 113 return false; 114 } 115 static bool classof(const Value *V) { 116 return isa<CallInst>(V) && classof(cast<CallInst>(V)); 117 } 118 }; 119 120 /// Check if \p ID corresponds to a debug info intrinsic. 121 static inline bool isDbgInfoIntrinsic(Intrinsic::ID ID) { 122 switch (ID) { 123 case Intrinsic::dbg_declare: 124 case Intrinsic::dbg_value: 125 case Intrinsic::dbg_addr: 126 case Intrinsic::dbg_label: 127 return true; 128 default: 129 return false; 130 } 131 } 132 133 /// This is the common base class for debug info intrinsics. 134 class DbgInfoIntrinsic : public IntrinsicInst { 135 public: 136 /// \name Casting methods 137 /// @{ 138 static bool classof(const IntrinsicInst *I) { 139 return isDbgInfoIntrinsic(I->getIntrinsicID()); 140 } 141 static bool classof(const Value *V) { 142 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 143 } 144 /// @} 145 }; 146 147 /// This is the common base class for debug info intrinsics for variables. 148 class DbgVariableIntrinsic : public DbgInfoIntrinsic { 149 public: 150 // Iterator for ValueAsMetadata that internally uses direct pointer iteration 151 // over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the 152 // ValueAsMetadata . 153 class location_op_iterator 154 : public iterator_facade_base<location_op_iterator, 155 std::bidirectional_iterator_tag, Value *> { 156 PointerUnion<ValueAsMetadata *, ValueAsMetadata **> I; 157 158 public: 159 location_op_iterator(ValueAsMetadata *SingleIter) : I(SingleIter) {} 160 location_op_iterator(ValueAsMetadata **MultiIter) : I(MultiIter) {} 161 162 location_op_iterator(const location_op_iterator &R) : I(R.I) {} 163 location_op_iterator &operator=(const location_op_iterator &R) { 164 I = R.I; 165 return *this; 166 } 167 bool operator==(const location_op_iterator &RHS) const { 168 return I == RHS.I; 169 } 170 const Value *operator*() const { 171 ValueAsMetadata *VAM = I.is<ValueAsMetadata *>() 172 ? I.get<ValueAsMetadata *>() 173 : *I.get<ValueAsMetadata **>(); 174 return VAM->getValue(); 175 }; 176 Value *operator*() { 177 ValueAsMetadata *VAM = I.is<ValueAsMetadata *>() 178 ? I.get<ValueAsMetadata *>() 179 : *I.get<ValueAsMetadata **>(); 180 return VAM->getValue(); 181 } 182 location_op_iterator &operator++() { 183 if (I.is<ValueAsMetadata *>()) 184 I = I.get<ValueAsMetadata *>() + 1; 185 else 186 I = I.get<ValueAsMetadata **>() + 1; 187 return *this; 188 } 189 location_op_iterator &operator--() { 190 if (I.is<ValueAsMetadata *>()) 191 I = I.get<ValueAsMetadata *>() - 1; 192 else 193 I = I.get<ValueAsMetadata **>() - 1; 194 return *this; 195 } 196 }; 197 198 /// Get the locations corresponding to the variable referenced by the debug 199 /// info intrinsic. Depending on the intrinsic, this could be the 200 /// variable's value or its address. 201 iterator_range<location_op_iterator> location_ops() const; 202 203 Value *getVariableLocationOp(unsigned OpIdx) const; 204 205 void replaceVariableLocationOp(Value *OldValue, Value *NewValue); 206 void replaceVariableLocationOp(unsigned OpIdx, Value *NewValue); 207 /// Adding a new location operand will always result in this intrinsic using 208 /// an ArgList, and must always be accompanied by a new expression that uses 209 /// the new operand. 210 void addVariableLocationOps(ArrayRef<Value *> NewValues, 211 DIExpression *NewExpr); 212 213 void setVariable(DILocalVariable *NewVar) { 214 setArgOperand(1, MetadataAsValue::get(NewVar->getContext(), NewVar)); 215 } 216 217 void setExpression(DIExpression *NewExpr) { 218 setArgOperand(2, MetadataAsValue::get(NewExpr->getContext(), NewExpr)); 219 } 220 221 unsigned getNumVariableLocationOps() const { 222 if (hasArgList()) 223 return cast<DIArgList>(getRawLocation())->getArgs().size(); 224 return 1; 225 } 226 227 bool hasArgList() const { return isa<DIArgList>(getRawLocation()); } 228 229 /// Does this describe the address of a local variable. True for dbg.addr 230 /// and dbg.declare, but not dbg.value, which describes its value. 231 bool isAddressOfVariable() const { 232 return getIntrinsicID() != Intrinsic::dbg_value; 233 } 234 235 void setUndef() { 236 // TODO: When/if we remove duplicate values from DIArgLists, we don't need 237 // this set anymore. 238 SmallPtrSet<Value *, 4> RemovedValues; 239 for (Value *OldValue : location_ops()) { 240 if (!RemovedValues.insert(OldValue).second) 241 continue; 242 Value *Undef = UndefValue::get(OldValue->getType()); 243 replaceVariableLocationOp(OldValue, Undef); 244 } 245 } 246 247 bool isUndef() const { 248 return (getNumVariableLocationOps() == 0 && 249 !getExpression()->isComplex()) || 250 any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); }); 251 } 252 253 DILocalVariable *getVariable() const { 254 return cast<DILocalVariable>(getRawVariable()); 255 } 256 257 DIExpression *getExpression() const { 258 return cast<DIExpression>(getRawExpression()); 259 } 260 261 Metadata *getRawLocation() const { 262 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata(); 263 } 264 265 Metadata *getRawVariable() const { 266 return cast<MetadataAsValue>(getArgOperand(1))->getMetadata(); 267 } 268 269 Metadata *getRawExpression() const { 270 return cast<MetadataAsValue>(getArgOperand(2))->getMetadata(); 271 } 272 273 /// Use of this should generally be avoided; instead, 274 /// replaceVariableLocationOp and addVariableLocationOps should be used where 275 /// possible to avoid creating invalid state. 276 void setRawLocation(Metadata *Location) { 277 return setArgOperand(0, MetadataAsValue::get(getContext(), Location)); 278 } 279 280 /// Get the size (in bits) of the variable, or fragment of the variable that 281 /// is described. 282 Optional<uint64_t> getFragmentSizeInBits() const; 283 284 /// \name Casting methods 285 /// @{ 286 static bool classof(const IntrinsicInst *I) { 287 switch (I->getIntrinsicID()) { 288 case Intrinsic::dbg_declare: 289 case Intrinsic::dbg_value: 290 case Intrinsic::dbg_addr: 291 return true; 292 default: 293 return false; 294 } 295 } 296 static bool classof(const Value *V) { 297 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 298 } 299 /// @} 300 private: 301 void setArgOperand(unsigned i, Value *v) { 302 DbgInfoIntrinsic::setArgOperand(i, v); 303 } 304 void setOperand(unsigned i, Value *v) { DbgInfoIntrinsic::setOperand(i, v); } 305 }; 306 307 /// This represents the llvm.dbg.declare instruction. 308 class DbgDeclareInst : public DbgVariableIntrinsic { 309 public: 310 Value *getAddress() const { 311 assert(getNumVariableLocationOps() == 1 && 312 "dbg.declare must have exactly 1 location operand."); 313 return getVariableLocationOp(0); 314 } 315 316 /// \name Casting methods 317 /// @{ 318 static bool classof(const IntrinsicInst *I) { 319 return I->getIntrinsicID() == Intrinsic::dbg_declare; 320 } 321 static bool classof(const Value *V) { 322 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 323 } 324 /// @} 325 }; 326 327 /// This represents the llvm.dbg.addr instruction. 328 class DbgAddrIntrinsic : public DbgVariableIntrinsic { 329 public: 330 Value *getAddress() const { 331 assert(getNumVariableLocationOps() == 1 && 332 "dbg.addr must have exactly 1 location operand."); 333 return getVariableLocationOp(0); 334 } 335 336 /// \name Casting methods 337 /// @{ 338 static bool classof(const IntrinsicInst *I) { 339 return I->getIntrinsicID() == Intrinsic::dbg_addr; 340 } 341 static bool classof(const Value *V) { 342 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 343 } 344 }; 345 346 /// This represents the llvm.dbg.value instruction. 347 class DbgValueInst : public DbgVariableIntrinsic { 348 public: 349 // The default argument should only be used in ISel, and the default option 350 // should be removed once ISel support for multiple location ops is complete. 351 Value *getValue(unsigned OpIdx = 0) const { 352 return getVariableLocationOp(OpIdx); 353 } 354 iterator_range<location_op_iterator> getValues() const { 355 return location_ops(); 356 } 357 358 /// \name Casting methods 359 /// @{ 360 static bool classof(const IntrinsicInst *I) { 361 return I->getIntrinsicID() == Intrinsic::dbg_value; 362 } 363 static bool classof(const Value *V) { 364 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 365 } 366 /// @} 367 }; 368 369 /// This represents the llvm.dbg.label instruction. 370 class DbgLabelInst : public DbgInfoIntrinsic { 371 public: 372 DILabel *getLabel() const { return cast<DILabel>(getRawLabel()); } 373 374 Metadata *getRawLabel() const { 375 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata(); 376 } 377 378 /// Methods for support type inquiry through isa, cast, and dyn_cast: 379 /// @{ 380 static bool classof(const IntrinsicInst *I) { 381 return I->getIntrinsicID() == Intrinsic::dbg_label; 382 } 383 static bool classof(const Value *V) { 384 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 385 } 386 /// @} 387 }; 388 389 /// This is the common base class for vector predication intrinsics. 390 class VPIntrinsic : public IntrinsicInst { 391 public: 392 /// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters 393 /// \p Params. Additionally, the load and gather intrinsics require 394 /// \p ReturnType to be specified. 395 static Function *getDeclarationForParams(Module *M, Intrinsic::ID, 396 Type *ReturnType, 397 ArrayRef<Value *> Params); 398 399 static Optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID); 400 static Optional<unsigned> getVectorLengthParamPos(Intrinsic::ID IntrinsicID); 401 402 /// The llvm.vp.* intrinsics for this instruction Opcode 403 static Intrinsic::ID getForOpcode(unsigned OC); 404 405 // Whether \p ID is a VP intrinsic ID. 406 static bool isVPIntrinsic(Intrinsic::ID); 407 408 /// \return The mask parameter or nullptr. 409 Value *getMaskParam() const; 410 void setMaskParam(Value *); 411 412 /// \return The vector length parameter or nullptr. 413 Value *getVectorLengthParam() const; 414 void setVectorLengthParam(Value *); 415 416 /// \return Whether the vector length param can be ignored. 417 bool canIgnoreVectorLengthParam() const; 418 419 /// \return The static element count (vector number of elements) the vector 420 /// length parameter applies to. 421 ElementCount getStaticVectorLength() const; 422 423 /// \return The alignment of the pointer used by this load/store/gather or 424 /// scatter. 425 MaybeAlign getPointerAlignment() const; 426 // MaybeAlign setPointerAlignment(Align NewAlign); // TODO 427 428 /// \return The pointer operand of this load,store, gather or scatter. 429 Value *getMemoryPointerParam() const; 430 static Optional<unsigned> getMemoryPointerParamPos(Intrinsic::ID); 431 432 /// \return The data (payload) operand of this store or scatter. 433 Value *getMemoryDataParam() const; 434 static Optional<unsigned> getMemoryDataParamPos(Intrinsic::ID); 435 436 // Methods for support type inquiry through isa, cast, and dyn_cast: 437 static bool classof(const IntrinsicInst *I) { 438 return isVPIntrinsic(I->getIntrinsicID()); 439 } 440 static bool classof(const Value *V) { 441 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 442 } 443 444 // Equivalent non-predicated opcode 445 Optional<unsigned> getFunctionalOpcode() const { 446 return getFunctionalOpcodeForVP(getIntrinsicID()); 447 } 448 449 // Equivalent non-predicated opcode 450 static Optional<unsigned> getFunctionalOpcodeForVP(Intrinsic::ID ID); 451 }; 452 453 /// This represents vector predication reduction intrinsics. 454 class VPReductionIntrinsic : public VPIntrinsic { 455 public: 456 static bool isVPReduction(Intrinsic::ID ID); 457 458 unsigned getStartParamPos() const; 459 unsigned getVectorParamPos() const; 460 461 static Optional<unsigned> getStartParamPos(Intrinsic::ID ID); 462 static Optional<unsigned> getVectorParamPos(Intrinsic::ID ID); 463 464 /// Methods for support type inquiry through isa, cast, and dyn_cast: 465 /// @{ 466 static bool classof(const IntrinsicInst *I) { 467 return VPReductionIntrinsic::isVPReduction(I->getIntrinsicID()); 468 } 469 static bool classof(const Value *V) { 470 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 471 } 472 /// @} 473 }; 474 475 /// This is the common base class for constrained floating point intrinsics. 476 class ConstrainedFPIntrinsic : public IntrinsicInst { 477 public: 478 bool isUnaryOp() const; 479 bool isTernaryOp() const; 480 Optional<RoundingMode> getRoundingMode() const; 481 Optional<fp::ExceptionBehavior> getExceptionBehavior() const; 482 bool isDefaultFPEnvironment() const; 483 484 // Methods for support type inquiry through isa, cast, and dyn_cast: 485 static bool classof(const IntrinsicInst *I); 486 static bool classof(const Value *V) { 487 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 488 } 489 }; 490 491 /// Constrained floating point compare intrinsics. 492 class ConstrainedFPCmpIntrinsic : public ConstrainedFPIntrinsic { 493 public: 494 FCmpInst::Predicate getPredicate() const; 495 496 // Methods for support type inquiry through isa, cast, and dyn_cast: 497 static bool classof(const IntrinsicInst *I) { 498 switch (I->getIntrinsicID()) { 499 case Intrinsic::experimental_constrained_fcmp: 500 case Intrinsic::experimental_constrained_fcmps: 501 return true; 502 default: 503 return false; 504 } 505 } 506 static bool classof(const Value *V) { 507 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 508 } 509 }; 510 511 /// This class represents min/max intrinsics. 512 class MinMaxIntrinsic : public IntrinsicInst { 513 public: 514 static bool classof(const IntrinsicInst *I) { 515 switch (I->getIntrinsicID()) { 516 case Intrinsic::umin: 517 case Intrinsic::umax: 518 case Intrinsic::smin: 519 case Intrinsic::smax: 520 return true; 521 default: 522 return false; 523 } 524 } 525 static bool classof(const Value *V) { 526 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 527 } 528 529 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); } 530 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); } 531 532 /// Returns the comparison predicate underlying the intrinsic. 533 ICmpInst::Predicate getPredicate() const { 534 switch (getIntrinsicID()) { 535 case Intrinsic::umin: 536 return ICmpInst::Predicate::ICMP_ULT; 537 case Intrinsic::umax: 538 return ICmpInst::Predicate::ICMP_UGT; 539 case Intrinsic::smin: 540 return ICmpInst::Predicate::ICMP_SLT; 541 case Intrinsic::smax: 542 return ICmpInst::Predicate::ICMP_SGT; 543 default: 544 llvm_unreachable("Invalid intrinsic"); 545 } 546 } 547 548 /// Whether the intrinsic is signed or unsigned. 549 bool isSigned() const { return ICmpInst::isSigned(getPredicate()); }; 550 }; 551 552 /// This class represents an intrinsic that is based on a binary operation. 553 /// This includes op.with.overflow and saturating add/sub intrinsics. 554 class BinaryOpIntrinsic : public IntrinsicInst { 555 public: 556 static bool classof(const IntrinsicInst *I) { 557 switch (I->getIntrinsicID()) { 558 case Intrinsic::uadd_with_overflow: 559 case Intrinsic::sadd_with_overflow: 560 case Intrinsic::usub_with_overflow: 561 case Intrinsic::ssub_with_overflow: 562 case Intrinsic::umul_with_overflow: 563 case Intrinsic::smul_with_overflow: 564 case Intrinsic::uadd_sat: 565 case Intrinsic::sadd_sat: 566 case Intrinsic::usub_sat: 567 case Intrinsic::ssub_sat: 568 return true; 569 default: 570 return false; 571 } 572 } 573 static bool classof(const Value *V) { 574 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 575 } 576 577 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); } 578 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); } 579 580 /// Returns the binary operation underlying the intrinsic. 581 Instruction::BinaryOps getBinaryOp() const; 582 583 /// Whether the intrinsic is signed or unsigned. 584 bool isSigned() const; 585 586 /// Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap. 587 unsigned getNoWrapKind() const; 588 }; 589 590 /// Represents an op.with.overflow intrinsic. 591 class WithOverflowInst : public BinaryOpIntrinsic { 592 public: 593 static bool classof(const IntrinsicInst *I) { 594 switch (I->getIntrinsicID()) { 595 case Intrinsic::uadd_with_overflow: 596 case Intrinsic::sadd_with_overflow: 597 case Intrinsic::usub_with_overflow: 598 case Intrinsic::ssub_with_overflow: 599 case Intrinsic::umul_with_overflow: 600 case Intrinsic::smul_with_overflow: 601 return true; 602 default: 603 return false; 604 } 605 } 606 static bool classof(const Value *V) { 607 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 608 } 609 }; 610 611 /// Represents a saturating add/sub intrinsic. 612 class SaturatingInst : public BinaryOpIntrinsic { 613 public: 614 static bool classof(const IntrinsicInst *I) { 615 switch (I->getIntrinsicID()) { 616 case Intrinsic::uadd_sat: 617 case Intrinsic::sadd_sat: 618 case Intrinsic::usub_sat: 619 case Intrinsic::ssub_sat: 620 return true; 621 default: 622 return false; 623 } 624 } 625 static bool classof(const Value *V) { 626 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 627 } 628 }; 629 630 /// Common base class for all memory intrinsics. Simply provides 631 /// common methods. 632 /// Written as CRTP to avoid a common base class amongst the 633 /// three atomicity hierarchies. 634 template <typename Derived> class MemIntrinsicBase : public IntrinsicInst { 635 private: 636 enum { ARG_DEST = 0, ARG_LENGTH = 2 }; 637 638 public: 639 Value *getRawDest() const { 640 return const_cast<Value *>(getArgOperand(ARG_DEST)); 641 } 642 const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); } 643 Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); } 644 645 Value *getLength() const { 646 return const_cast<Value *>(getArgOperand(ARG_LENGTH)); 647 } 648 const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); } 649 Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); } 650 651 /// This is just like getRawDest, but it strips off any cast 652 /// instructions (including addrspacecast) that feed it, giving the 653 /// original input. The returned value is guaranteed to be a pointer. 654 Value *getDest() const { return getRawDest()->stripPointerCasts(); } 655 656 unsigned getDestAddressSpace() const { 657 return cast<PointerType>(getRawDest()->getType())->getAddressSpace(); 658 } 659 660 /// FIXME: Remove this function once transition to Align is over. 661 /// Use getDestAlign() instead. 662 unsigned getDestAlignment() const { 663 if (auto MA = getParamAlign(ARG_DEST)) 664 return MA->value(); 665 return 0; 666 } 667 MaybeAlign getDestAlign() const { return getParamAlign(ARG_DEST); } 668 669 /// Set the specified arguments of the instruction. 670 void setDest(Value *Ptr) { 671 assert(getRawDest()->getType() == Ptr->getType() && 672 "setDest called with pointer of wrong type!"); 673 setArgOperand(ARG_DEST, Ptr); 674 } 675 676 /// FIXME: Remove this function once transition to Align is over. 677 /// Use the version that takes MaybeAlign instead of this one. 678 void setDestAlignment(unsigned Alignment) { 679 setDestAlignment(MaybeAlign(Alignment)); 680 } 681 void setDestAlignment(MaybeAlign Alignment) { 682 removeParamAttr(ARG_DEST, Attribute::Alignment); 683 if (Alignment) 684 addParamAttr(ARG_DEST, 685 Attribute::getWithAlignment(getContext(), *Alignment)); 686 } 687 void setDestAlignment(Align Alignment) { 688 removeParamAttr(ARG_DEST, Attribute::Alignment); 689 addParamAttr(ARG_DEST, 690 Attribute::getWithAlignment(getContext(), Alignment)); 691 } 692 693 void setLength(Value *L) { 694 assert(getLength()->getType() == L->getType() && 695 "setLength called with value of wrong type!"); 696 setArgOperand(ARG_LENGTH, L); 697 } 698 }; 699 700 /// Common base class for all memory transfer intrinsics. Simply provides 701 /// common methods. 702 template <class BaseCL> class MemTransferBase : public BaseCL { 703 private: 704 enum { ARG_SOURCE = 1 }; 705 706 public: 707 /// Return the arguments to the instruction. 708 Value *getRawSource() const { 709 return const_cast<Value *>(BaseCL::getArgOperand(ARG_SOURCE)); 710 } 711 const Use &getRawSourceUse() const { 712 return BaseCL::getArgOperandUse(ARG_SOURCE); 713 } 714 Use &getRawSourceUse() { return BaseCL::getArgOperandUse(ARG_SOURCE); } 715 716 /// This is just like getRawSource, but it strips off any cast 717 /// instructions that feed it, giving the original input. The returned 718 /// value is guaranteed to be a pointer. 719 Value *getSource() const { return getRawSource()->stripPointerCasts(); } 720 721 unsigned getSourceAddressSpace() const { 722 return cast<PointerType>(getRawSource()->getType())->getAddressSpace(); 723 } 724 725 /// FIXME: Remove this function once transition to Align is over. 726 /// Use getSourceAlign() instead. 727 unsigned getSourceAlignment() const { 728 if (auto MA = BaseCL::getParamAlign(ARG_SOURCE)) 729 return MA->value(); 730 return 0; 731 } 732 733 MaybeAlign getSourceAlign() const { 734 return BaseCL::getParamAlign(ARG_SOURCE); 735 } 736 737 void setSource(Value *Ptr) { 738 assert(getRawSource()->getType() == Ptr->getType() && 739 "setSource called with pointer of wrong type!"); 740 BaseCL::setArgOperand(ARG_SOURCE, Ptr); 741 } 742 743 /// FIXME: Remove this function once transition to Align is over. 744 /// Use the version that takes MaybeAlign instead of this one. 745 void setSourceAlignment(unsigned Alignment) { 746 setSourceAlignment(MaybeAlign(Alignment)); 747 } 748 void setSourceAlignment(MaybeAlign Alignment) { 749 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment); 750 if (Alignment) 751 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment( 752 BaseCL::getContext(), *Alignment)); 753 } 754 void setSourceAlignment(Align Alignment) { 755 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment); 756 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment( 757 BaseCL::getContext(), Alignment)); 758 } 759 }; 760 761 /// Common base class for all memset intrinsics. Simply provides 762 /// common methods. 763 template <class BaseCL> class MemSetBase : public BaseCL { 764 private: 765 enum { ARG_VALUE = 1 }; 766 767 public: 768 Value *getValue() const { 769 return const_cast<Value *>(BaseCL::getArgOperand(ARG_VALUE)); 770 } 771 const Use &getValueUse() const { return BaseCL::getArgOperandUse(ARG_VALUE); } 772 Use &getValueUse() { return BaseCL::getArgOperandUse(ARG_VALUE); } 773 774 void setValue(Value *Val) { 775 assert(getValue()->getType() == Val->getType() && 776 "setValue called with value of wrong type!"); 777 BaseCL::setArgOperand(ARG_VALUE, Val); 778 } 779 }; 780 781 // The common base class for the atomic memset/memmove/memcpy intrinsics 782 // i.e. llvm.element.unordered.atomic.memset/memcpy/memmove 783 class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> { 784 private: 785 enum { ARG_ELEMENTSIZE = 3 }; 786 787 public: 788 Value *getRawElementSizeInBytes() const { 789 return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE)); 790 } 791 792 ConstantInt *getElementSizeInBytesCst() const { 793 return cast<ConstantInt>(getRawElementSizeInBytes()); 794 } 795 796 uint32_t getElementSizeInBytes() const { 797 return getElementSizeInBytesCst()->getZExtValue(); 798 } 799 800 void setElementSizeInBytes(Constant *V) { 801 assert(V->getType() == Type::getInt8Ty(getContext()) && 802 "setElementSizeInBytes called with value of wrong type!"); 803 setArgOperand(ARG_ELEMENTSIZE, V); 804 } 805 806 static bool classof(const IntrinsicInst *I) { 807 switch (I->getIntrinsicID()) { 808 case Intrinsic::memcpy_element_unordered_atomic: 809 case Intrinsic::memmove_element_unordered_atomic: 810 case Intrinsic::memset_element_unordered_atomic: 811 return true; 812 default: 813 return false; 814 } 815 } 816 static bool classof(const Value *V) { 817 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 818 } 819 }; 820 821 /// This class represents atomic memset intrinsic 822 // i.e. llvm.element.unordered.atomic.memset 823 class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> { 824 public: 825 static bool classof(const IntrinsicInst *I) { 826 return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic; 827 } 828 static bool classof(const Value *V) { 829 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 830 } 831 }; 832 833 // This class wraps the atomic memcpy/memmove intrinsics 834 // i.e. llvm.element.unordered.atomic.memcpy/memmove 835 class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> { 836 public: 837 static bool classof(const IntrinsicInst *I) { 838 switch (I->getIntrinsicID()) { 839 case Intrinsic::memcpy_element_unordered_atomic: 840 case Intrinsic::memmove_element_unordered_atomic: 841 return true; 842 default: 843 return false; 844 } 845 } 846 static bool classof(const Value *V) { 847 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 848 } 849 }; 850 851 /// This class represents the atomic memcpy intrinsic 852 /// i.e. llvm.element.unordered.atomic.memcpy 853 class AtomicMemCpyInst : public AtomicMemTransferInst { 854 public: 855 static bool classof(const IntrinsicInst *I) { 856 return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic; 857 } 858 static bool classof(const Value *V) { 859 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 860 } 861 }; 862 863 /// This class represents the atomic memmove intrinsic 864 /// i.e. llvm.element.unordered.atomic.memmove 865 class AtomicMemMoveInst : public AtomicMemTransferInst { 866 public: 867 static bool classof(const IntrinsicInst *I) { 868 return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic; 869 } 870 static bool classof(const Value *V) { 871 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 872 } 873 }; 874 875 /// This is the common base class for memset/memcpy/memmove. 876 class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> { 877 private: 878 enum { ARG_VOLATILE = 3 }; 879 880 public: 881 ConstantInt *getVolatileCst() const { 882 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE))); 883 } 884 885 bool isVolatile() const { return !getVolatileCst()->isZero(); } 886 887 void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); } 888 889 // Methods for support type inquiry through isa, cast, and dyn_cast: 890 static bool classof(const IntrinsicInst *I) { 891 switch (I->getIntrinsicID()) { 892 case Intrinsic::memcpy: 893 case Intrinsic::memmove: 894 case Intrinsic::memset: 895 case Intrinsic::memcpy_inline: 896 return true; 897 default: 898 return false; 899 } 900 } 901 static bool classof(const Value *V) { 902 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 903 } 904 }; 905 906 /// This class wraps the llvm.memset intrinsic. 907 class MemSetInst : public MemSetBase<MemIntrinsic> { 908 public: 909 // Methods for support type inquiry through isa, cast, and dyn_cast: 910 static bool classof(const IntrinsicInst *I) { 911 return I->getIntrinsicID() == Intrinsic::memset; 912 } 913 static bool classof(const Value *V) { 914 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 915 } 916 }; 917 918 /// This class wraps the llvm.memcpy/memmove intrinsics. 919 class MemTransferInst : public MemTransferBase<MemIntrinsic> { 920 public: 921 // Methods for support type inquiry through isa, cast, and dyn_cast: 922 static bool classof(const IntrinsicInst *I) { 923 switch (I->getIntrinsicID()) { 924 case Intrinsic::memcpy: 925 case Intrinsic::memmove: 926 case Intrinsic::memcpy_inline: 927 return true; 928 default: 929 return false; 930 } 931 } 932 static bool classof(const Value *V) { 933 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 934 } 935 }; 936 937 /// This class wraps the llvm.memcpy intrinsic. 938 class MemCpyInst : public MemTransferInst { 939 public: 940 // Methods for support type inquiry through isa, cast, and dyn_cast: 941 static bool classof(const IntrinsicInst *I) { 942 return I->getIntrinsicID() == Intrinsic::memcpy || 943 I->getIntrinsicID() == Intrinsic::memcpy_inline; 944 } 945 static bool classof(const Value *V) { 946 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 947 } 948 }; 949 950 /// This class wraps the llvm.memmove intrinsic. 951 class MemMoveInst : public MemTransferInst { 952 public: 953 // Methods for support type inquiry through isa, cast, and dyn_cast: 954 static bool classof(const IntrinsicInst *I) { 955 return I->getIntrinsicID() == Intrinsic::memmove; 956 } 957 static bool classof(const Value *V) { 958 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 959 } 960 }; 961 962 /// This class wraps the llvm.memcpy.inline intrinsic. 963 class MemCpyInlineInst : public MemCpyInst { 964 public: 965 ConstantInt *getLength() const { 966 return cast<ConstantInt>(MemCpyInst::getLength()); 967 } 968 // Methods for support type inquiry through isa, cast, and dyn_cast: 969 static bool classof(const IntrinsicInst *I) { 970 return I->getIntrinsicID() == Intrinsic::memcpy_inline; 971 } 972 static bool classof(const Value *V) { 973 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 974 } 975 }; 976 977 // The common base class for any memset/memmove/memcpy intrinsics; 978 // whether they be atomic or non-atomic. 979 // i.e. llvm.element.unordered.atomic.memset/memcpy/memmove 980 // and llvm.memset/memcpy/memmove 981 class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> { 982 public: 983 bool isVolatile() const { 984 // Only the non-atomic intrinsics can be volatile 985 if (auto *MI = dyn_cast<MemIntrinsic>(this)) 986 return MI->isVolatile(); 987 return false; 988 } 989 990 static bool classof(const IntrinsicInst *I) { 991 switch (I->getIntrinsicID()) { 992 case Intrinsic::memcpy: 993 case Intrinsic::memcpy_inline: 994 case Intrinsic::memmove: 995 case Intrinsic::memset: 996 case Intrinsic::memcpy_element_unordered_atomic: 997 case Intrinsic::memmove_element_unordered_atomic: 998 case Intrinsic::memset_element_unordered_atomic: 999 return true; 1000 default: 1001 return false; 1002 } 1003 } 1004 static bool classof(const Value *V) { 1005 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1006 } 1007 }; 1008 1009 /// This class represents any memset intrinsic 1010 // i.e. llvm.element.unordered.atomic.memset 1011 // and llvm.memset 1012 class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> { 1013 public: 1014 static bool classof(const IntrinsicInst *I) { 1015 switch (I->getIntrinsicID()) { 1016 case Intrinsic::memset: 1017 case Intrinsic::memset_element_unordered_atomic: 1018 return true; 1019 default: 1020 return false; 1021 } 1022 } 1023 static bool classof(const Value *V) { 1024 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1025 } 1026 }; 1027 1028 // This class wraps any memcpy/memmove intrinsics 1029 // i.e. llvm.element.unordered.atomic.memcpy/memmove 1030 // and llvm.memcpy/memmove 1031 class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> { 1032 public: 1033 static bool classof(const IntrinsicInst *I) { 1034 switch (I->getIntrinsicID()) { 1035 case Intrinsic::memcpy: 1036 case Intrinsic::memcpy_inline: 1037 case Intrinsic::memmove: 1038 case Intrinsic::memcpy_element_unordered_atomic: 1039 case Intrinsic::memmove_element_unordered_atomic: 1040 return true; 1041 default: 1042 return false; 1043 } 1044 } 1045 static bool classof(const Value *V) { 1046 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1047 } 1048 }; 1049 1050 /// This class represents any memcpy intrinsic 1051 /// i.e. llvm.element.unordered.atomic.memcpy 1052 /// and llvm.memcpy 1053 class AnyMemCpyInst : public AnyMemTransferInst { 1054 public: 1055 static bool classof(const IntrinsicInst *I) { 1056 switch (I->getIntrinsicID()) { 1057 case Intrinsic::memcpy: 1058 case Intrinsic::memcpy_inline: 1059 case Intrinsic::memcpy_element_unordered_atomic: 1060 return true; 1061 default: 1062 return false; 1063 } 1064 } 1065 static bool classof(const Value *V) { 1066 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1067 } 1068 }; 1069 1070 /// This class represents any memmove intrinsic 1071 /// i.e. llvm.element.unordered.atomic.memmove 1072 /// and llvm.memmove 1073 class AnyMemMoveInst : public AnyMemTransferInst { 1074 public: 1075 static bool classof(const IntrinsicInst *I) { 1076 switch (I->getIntrinsicID()) { 1077 case Intrinsic::memmove: 1078 case Intrinsic::memmove_element_unordered_atomic: 1079 return true; 1080 default: 1081 return false; 1082 } 1083 } 1084 static bool classof(const Value *V) { 1085 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1086 } 1087 }; 1088 1089 /// This represents the llvm.va_start intrinsic. 1090 class VAStartInst : public IntrinsicInst { 1091 public: 1092 static bool classof(const IntrinsicInst *I) { 1093 return I->getIntrinsicID() == Intrinsic::vastart; 1094 } 1095 static bool classof(const Value *V) { 1096 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1097 } 1098 1099 Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); } 1100 }; 1101 1102 /// This represents the llvm.va_end intrinsic. 1103 class VAEndInst : public IntrinsicInst { 1104 public: 1105 static bool classof(const IntrinsicInst *I) { 1106 return I->getIntrinsicID() == Intrinsic::vaend; 1107 } 1108 static bool classof(const Value *V) { 1109 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1110 } 1111 1112 Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); } 1113 }; 1114 1115 /// This represents the llvm.va_copy intrinsic. 1116 class VACopyInst : public IntrinsicInst { 1117 public: 1118 static bool classof(const IntrinsicInst *I) { 1119 return I->getIntrinsicID() == Intrinsic::vacopy; 1120 } 1121 static bool classof(const Value *V) { 1122 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1123 } 1124 1125 Value *getDest() const { return const_cast<Value *>(getArgOperand(0)); } 1126 Value *getSrc() const { return const_cast<Value *>(getArgOperand(1)); } 1127 }; 1128 1129 /// This represents the llvm.instrprof_increment intrinsic. 1130 class InstrProfIncrementInst : public IntrinsicInst { 1131 public: 1132 static bool classof(const IntrinsicInst *I) { 1133 return I->getIntrinsicID() == Intrinsic::instrprof_increment; 1134 } 1135 static bool classof(const Value *V) { 1136 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1137 } 1138 1139 GlobalVariable *getName() const { 1140 return cast<GlobalVariable>( 1141 const_cast<Value *>(getArgOperand(0))->stripPointerCasts()); 1142 } 1143 1144 ConstantInt *getHash() const { 1145 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1))); 1146 } 1147 1148 ConstantInt *getNumCounters() const { 1149 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2))); 1150 } 1151 1152 ConstantInt *getIndex() const { 1153 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3))); 1154 } 1155 1156 Value *getStep() const; 1157 }; 1158 1159 class InstrProfIncrementInstStep : public InstrProfIncrementInst { 1160 public: 1161 static bool classof(const IntrinsicInst *I) { 1162 return I->getIntrinsicID() == Intrinsic::instrprof_increment_step; 1163 } 1164 static bool classof(const Value *V) { 1165 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1166 } 1167 }; 1168 1169 /// This represents the llvm.instrprof_value_profile intrinsic. 1170 class InstrProfValueProfileInst : public IntrinsicInst { 1171 public: 1172 static bool classof(const IntrinsicInst *I) { 1173 return I->getIntrinsicID() == Intrinsic::instrprof_value_profile; 1174 } 1175 static bool classof(const Value *V) { 1176 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1177 } 1178 1179 GlobalVariable *getName() const { 1180 return cast<GlobalVariable>( 1181 const_cast<Value *>(getArgOperand(0))->stripPointerCasts()); 1182 } 1183 1184 ConstantInt *getHash() const { 1185 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1))); 1186 } 1187 1188 Value *getTargetValue() const { 1189 return cast<Value>(const_cast<Value *>(getArgOperand(2))); 1190 } 1191 1192 ConstantInt *getValueKind() const { 1193 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3))); 1194 } 1195 1196 // Returns the value site index. 1197 ConstantInt *getIndex() const { 1198 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4))); 1199 } 1200 }; 1201 1202 class PseudoProbeInst : public IntrinsicInst { 1203 public: 1204 static bool classof(const IntrinsicInst *I) { 1205 return I->getIntrinsicID() == Intrinsic::pseudoprobe; 1206 } 1207 1208 static bool classof(const Value *V) { 1209 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1210 } 1211 1212 ConstantInt *getFuncGuid() const { 1213 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(0))); 1214 } 1215 1216 ConstantInt *getIndex() const { 1217 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1))); 1218 } 1219 1220 ConstantInt *getAttributes() const { 1221 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2))); 1222 } 1223 1224 ConstantInt *getFactor() const { 1225 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3))); 1226 } 1227 }; 1228 1229 class NoAliasScopeDeclInst : public IntrinsicInst { 1230 public: 1231 static bool classof(const IntrinsicInst *I) { 1232 return I->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl; 1233 } 1234 1235 static bool classof(const Value *V) { 1236 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1237 } 1238 1239 MDNode *getScopeList() const { 1240 auto *MV = 1241 cast<MetadataAsValue>(getOperand(Intrinsic::NoAliasScopeDeclScopeArg)); 1242 return cast<MDNode>(MV->getMetadata()); 1243 } 1244 1245 void setScopeList(MDNode *ScopeList) { 1246 setOperand(Intrinsic::NoAliasScopeDeclScopeArg, 1247 MetadataAsValue::get(getContext(), ScopeList)); 1248 } 1249 }; 1250 1251 // Defined in Statepoint.h -- NOT a subclass of IntrinsicInst 1252 class GCStatepointInst; 1253 1254 /// Common base class for representing values projected from a statepoint. 1255 /// Currently, the only projections available are gc.result and gc.relocate. 1256 class GCProjectionInst : public IntrinsicInst { 1257 public: 1258 static bool classof(const IntrinsicInst *I) { 1259 return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate || 1260 I->getIntrinsicID() == Intrinsic::experimental_gc_result; 1261 } 1262 1263 static bool classof(const Value *V) { 1264 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1265 } 1266 1267 /// Return true if this relocate is tied to the invoke statepoint. 1268 /// This includes relocates which are on the unwinding path. 1269 bool isTiedToInvoke() const { 1270 const Value *Token = getArgOperand(0); 1271 1272 return isa<LandingPadInst>(Token) || isa<InvokeInst>(Token); 1273 } 1274 1275 /// The statepoint with which this gc.relocate is associated. 1276 const GCStatepointInst *getStatepoint() const; 1277 }; 1278 1279 /// Represents calls to the gc.relocate intrinsic. 1280 class GCRelocateInst : public GCProjectionInst { 1281 public: 1282 static bool classof(const IntrinsicInst *I) { 1283 return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate; 1284 } 1285 1286 static bool classof(const Value *V) { 1287 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1288 } 1289 1290 /// The index into the associate statepoint's argument list 1291 /// which contains the base pointer of the pointer whose 1292 /// relocation this gc.relocate describes. 1293 unsigned getBasePtrIndex() const { 1294 return cast<ConstantInt>(getArgOperand(1))->getZExtValue(); 1295 } 1296 1297 /// The index into the associate statepoint's argument list which 1298 /// contains the pointer whose relocation this gc.relocate describes. 1299 unsigned getDerivedPtrIndex() const { 1300 return cast<ConstantInt>(getArgOperand(2))->getZExtValue(); 1301 } 1302 1303 Value *getBasePtr() const; 1304 Value *getDerivedPtr() const; 1305 }; 1306 1307 /// Represents calls to the gc.result intrinsic. 1308 class GCResultInst : public GCProjectionInst { 1309 public: 1310 static bool classof(const IntrinsicInst *I) { 1311 return I->getIntrinsicID() == Intrinsic::experimental_gc_result; 1312 } 1313 1314 static bool classof(const Value *V) { 1315 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1316 } 1317 }; 1318 1319 1320 /// This represents the llvm.assume intrinsic. 1321 class AssumeInst : public IntrinsicInst { 1322 public: 1323 static bool classof(const IntrinsicInst *I) { 1324 return I->getIntrinsicID() == Intrinsic::assume; 1325 } 1326 static bool classof(const Value *V) { 1327 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 1328 } 1329 }; 1330 1331 } // end namespace llvm 1332 1333 #endif // LLVM_IR_INTRINSICINST_H 1334