LLVM 23.0.0git
InstrTypes.h
Go to the documentation of this file.
1//===- llvm/InstrTypes.h - Important Instruction subclasses -----*- 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 various meta classes of instructions that exist in the VM
10// representation. Specific concrete subclasses of these may be found in the
11// i*.h files...
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_INSTRTYPES_H
16#define LLVM_IR_INSTRTYPES_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/Sequence.h"
21#include "llvm/ADT/StringMap.h"
22#include "llvm/ADT/Twine.h"
24#include "llvm/IR/Attributes.h"
25#include "llvm/IR/CallingConv.h"
27#include "llvm/IR/FMF.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/Instruction.h"
30#include "llvm/IR/LLVMContext.h"
32#include "llvm/IR/User.h"
34#include <algorithm>
35#include <cassert>
36#include <cstddef>
37#include <cstdint>
38#include <iterator>
39#include <optional>
40#include <string>
41#include <vector>
42
43namespace llvm {
44
45class StringRef;
46class Type;
47class Value;
48class ConstantRange;
49
50namespace Intrinsic {
51typedef unsigned ID;
52}
53
54//===----------------------------------------------------------------------===//
55// UnaryInstruction Class
56//===----------------------------------------------------------------------===//
57
59 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
60
61protected:
62 UnaryInstruction(Type *Ty, unsigned iType, Value *V,
63 InsertPosition InsertBefore = nullptr)
64 : Instruction(Ty, iType, AllocMarker, InsertBefore) {
65 Op<0>() = V;
66 }
67
68public:
69 // allocate space for exactly one operand
70 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
71 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
72
73 /// Transparently provide more efficient getOperand methods.
75
76 // Methods for support type inquiry through isa, cast, and dyn_cast:
77 static bool classof(const Instruction *I) {
78 return I->isUnaryOp() || I->getOpcode() == Instruction::Alloca ||
79 I->getOpcode() == Instruction::Load ||
80 I->getOpcode() == Instruction::VAArg ||
81 I->getOpcode() == Instruction::ExtractValue ||
82 I->getOpcode() == Instruction::Freeze ||
83 (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
84 }
85 static bool classof(const Value *V) {
87 }
88};
89
90template <>
92 public FixedNumOperandTraits<UnaryInstruction, 1> {
93};
94
96
97//===----------------------------------------------------------------------===//
98// UnaryOperator Class
99//===----------------------------------------------------------------------===//
100
102 void AssertOK();
103
104protected:
105 LLVM_ABI UnaryOperator(UnaryOps iType, Value *S, Type *Ty, const Twine &Name,
106 InsertPosition InsertBefore);
107
108 // Note: Instruction needs to be a friend here to call cloneImpl.
109 friend class Instruction;
110
112
113public:
114 /// Construct a unary instruction, given the opcode and an operand.
115 /// Optionally (if InstBefore is specified) insert the instruction
116 /// into a BasicBlock right before the specified instruction. The specified
117 /// Instruction is allowed to be a dereferenced end iterator.
118 ///
120 const Twine &Name = Twine(),
121 InsertPosition InsertBefore = nullptr);
122
123 /// These methods just forward to Create, and are useful when you
124 /// statically know what type of instruction you're going to create. These
125 /// helpers just save some typing.
126#define HANDLE_UNARY_INST(N, OPC, CLASS) \
127 static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") { \
128 return Create(Instruction::OPC, V, Name); \
129 }
130#include "llvm/IR/Instruction.def"
131#define HANDLE_UNARY_INST(N, OPC, CLASS) \
132 static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
133 InsertPosition InsertBefore = nullptr) { \
134 return Create(Instruction::OPC, V, Name, InsertBefore); \
135 }
136#include "llvm/IR/Instruction.def"
137
138 static UnaryOperator *
140 const Twine &Name = "",
141 InsertPosition InsertBefore = nullptr) {
142 UnaryOperator *UO = Create(Opc, V, Name, InsertBefore);
143 UO->copyIRFlags(CopyO);
144 return UO;
145 }
146
148 const Twine &Name = "",
149 InsertPosition InsertBefore = nullptr) {
150 return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name,
151 InsertBefore);
152 }
153
155 return static_cast<UnaryOps>(Instruction::getOpcode());
156 }
157
158 // Methods for support type inquiry through isa, cast, and dyn_cast:
159 static bool classof(const Instruction *I) {
160 return I->isUnaryOp();
161 }
162 static bool classof(const Value *V) {
164 }
165};
166
167//===----------------------------------------------------------------------===//
168// BinaryOperator Class
169//===----------------------------------------------------------------------===//
170
172 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
173
174 void AssertOK();
175
176protected:
178 const Twine &Name, InsertPosition InsertBefore);
179
180 // Note: Instruction needs to be a friend here to call cloneImpl.
181 friend class Instruction;
182
184
185public:
186 // allocate space for exactly two operands
187 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
188 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
189
190 /// Transparently provide more efficient getOperand methods.
192
193 /// Construct a binary instruction, given the opcode and the two
194 /// operands. Optionally (if InstBefore is specified) insert the instruction
195 /// into a BasicBlock right before the specified instruction. The specified
196 /// Instruction is allowed to be a dereferenced end iterator.
197 ///
199 const Twine &Name = Twine(),
200 InsertPosition InsertBefore = nullptr);
201
202 /// These methods just forward to Create, and are useful when you
203 /// statically know what type of instruction you're going to create. These
204 /// helpers just save some typing.
205#define HANDLE_BINARY_INST(N, OPC, CLASS) \
206 static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
207 const Twine &Name = "") { \
208 return Create(Instruction::OPC, V1, V2, Name); \
209 }
210#include "llvm/IR/Instruction.def"
211#define HANDLE_BINARY_INST(N, OPC, CLASS) \
212 static BinaryOperator *Create##OPC(Value *V1, Value *V2, const Twine &Name, \
213 InsertPosition InsertBefore) { \
214 return Create(Instruction::OPC, V1, V2, Name, InsertBefore); \
215 }
216#include "llvm/IR/Instruction.def"
217
218 static BinaryOperator *
220 const Twine &Name = "",
221 InsertPosition InsertBefore = nullptr) {
222 BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
223 BO->copyIRFlags(CopyO);
224 return BO;
225 }
226
228 FastMathFlags FMF,
229 const Twine &Name = "",
230 InsertPosition InsertBefore = nullptr) {
231 BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
232 BO->setFastMathFlags(FMF);
233 return BO;
234 }
235
237 const Twine &Name = "") {
238 return CreateWithFMF(Instruction::FAdd, V1, V2, FMF, Name);
239 }
241 const Twine &Name = "") {
242 return CreateWithFMF(Instruction::FSub, V1, V2, FMF, Name);
243 }
245 const Twine &Name = "") {
246 return CreateWithFMF(Instruction::FMul, V1, V2, FMF, Name);
247 }
249 const Twine &Name = "") {
250 return CreateWithFMF(Instruction::FDiv, V1, V2, FMF, Name);
251 }
252
255 const Twine &Name = "") {
256 return CreateWithCopiedFlags(Instruction::FAdd, V1, V2, FMFSource, Name);
257 }
260 const Twine &Name = "") {
261 return CreateWithCopiedFlags(Instruction::FSub, V1, V2, FMFSource, Name);
262 }
265 const Twine &Name = "") {
266 return CreateWithCopiedFlags(Instruction::FMul, V1, V2, FMFSource, Name);
267 }
270 const Twine &Name = "") {
271 return CreateWithCopiedFlags(Instruction::FDiv, V1, V2, FMFSource, Name);
272 }
275 const Twine &Name = "") {
276 return CreateWithCopiedFlags(Instruction::FRem, V1, V2, FMFSource, Name);
277 }
278
280 const Twine &Name = "") {
281 BinaryOperator *BO = Create(Opc, V1, V2, Name);
282 BO->setHasNoSignedWrap(true);
283 return BO;
284 }
285
287 const Twine &Name,
288 InsertPosition InsertBefore) {
289 BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
290 BO->setHasNoSignedWrap(true);
291 return BO;
292 }
293
295 const Twine &Name = "") {
296 BinaryOperator *BO = Create(Opc, V1, V2, Name);
297 BO->setHasNoUnsignedWrap(true);
298 return BO;
299 }
300
302 const Twine &Name,
303 InsertPosition InsertBefore) {
304 BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
305 BO->setHasNoUnsignedWrap(true);
306 return BO;
307 }
308
310 const Twine &Name = "") {
311 BinaryOperator *BO = Create(Opc, V1, V2, Name);
312 BO->setIsExact(true);
313 return BO;
314 }
315
317 const Twine &Name,
318 InsertPosition InsertBefore) {
319 BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
320 BO->setIsExact(true);
321 return BO;
322 }
323
324 static inline BinaryOperator *
325 CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = "");
326 static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
327 Value *V2, const Twine &Name,
328 InsertPosition InsertBefore);
329
330#define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
331 static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \
332 const Twine &Name = "") { \
333 return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
334 } \
335 static BinaryOperator *Create##NUWNSWEXACT##OPC( \
336 Value *V1, Value *V2, const Twine &Name, \
337 InsertPosition InsertBefore = nullptr) { \
338 return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, InsertBefore); \
339 }
340
341 DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
342 DEFINE_HELPERS(Add, NUW) // CreateNUWAdd
343 DEFINE_HELPERS(Sub, NSW) // CreateNSWSub
344 DEFINE_HELPERS(Sub, NUW) // CreateNUWSub
345 DEFINE_HELPERS(Mul, NSW) // CreateNSWMul
346 DEFINE_HELPERS(Mul, NUW) // CreateNUWMul
347 DEFINE_HELPERS(Shl, NSW) // CreateNSWShl
348 DEFINE_HELPERS(Shl, NUW) // CreateNUWShl
349
350 DEFINE_HELPERS(SDiv, Exact) // CreateExactSDiv
351 DEFINE_HELPERS(UDiv, Exact) // CreateExactUDiv
352 DEFINE_HELPERS(AShr, Exact) // CreateExactAShr
353 DEFINE_HELPERS(LShr, Exact) // CreateExactLShr
354
355 DEFINE_HELPERS(Or, Disjoint) // CreateDisjointOr
356
357#undef DEFINE_HELPERS
358
359 /// Helper functions to construct and inspect unary operations (NEG and NOT)
360 /// via binary operators SUB and XOR:
361 ///
362 /// Create the NEG and NOT instructions out of SUB and XOR instructions.
363 ///
364 LLVM_ABI static BinaryOperator *
365 CreateNeg(Value *Op, const Twine &Name = "",
366 InsertPosition InsertBefore = nullptr);
367 LLVM_ABI static BinaryOperator *
368 CreateNSWNeg(Value *Op, const Twine &Name = "",
369 InsertPosition InsertBefore = nullptr);
370 LLVM_ABI static BinaryOperator *
371 CreateNot(Value *Op, const Twine &Name = "",
372 InsertPosition InsertBefore = nullptr);
373
375 return static_cast<BinaryOps>(Instruction::getOpcode());
376 }
377
378 /// Exchange the two operands to this instruction.
379 /// This instruction is safe to use on any binary instruction and
380 /// does not modify the semantics of the instruction. If the instruction
381 /// cannot be reversed (ie, it's a Div), then return true.
382 ///
383 LLVM_ABI bool swapOperands();
384
385 // Methods for support type inquiry through isa, cast, and dyn_cast:
386 static bool classof(const Instruction *I) {
387 return I->isBinaryOp();
388 }
389 static bool classof(const Value *V) {
391 }
392};
393
394template <>
396 public FixedNumOperandTraits<BinaryOperator, 2> {
397};
398
400
401/// An or instruction, which can be marked as "disjoint", indicating that the
402/// inputs don't have a 1 in the same bit position. Meaning this instruction
403/// can also be treated as an add.
405public:
406 enum { IsDisjoint = (1 << 0) };
407
412
413 bool isDisjoint() const { return SubclassOptionalData & IsDisjoint; }
414
415 static bool classof(const Instruction *I) {
416 return I->getOpcode() == Instruction::Or;
417 }
418
419 static bool classof(const Value *V) {
421 }
422};
423
425 Value *V2, const Twine &Name) {
426 BinaryOperator *BO = Create(Opc, V1, V2, Name);
427 cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
428 return BO;
429}
431 Value *V2, const Twine &Name,
432 InsertPosition InsertBefore) {
433 BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
434 cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
435 return BO;
436}
437
438//===----------------------------------------------------------------------===//
439// CastInst Class
440//===----------------------------------------------------------------------===//
441
442/// This is the base class for all instructions that perform data
443/// casts. It is simply provided so that instruction category testing
444/// can be performed with code like:
445///
446/// if (isa<CastInst>(Instr)) { ... }
447/// Base class of casting instructions.
449protected:
450 /// Constructor with insert-before-instruction semantics for subclasses
451 CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr = "",
452 InsertPosition InsertBefore = nullptr)
453 : UnaryInstruction(Ty, iType, S, InsertBefore) {
454 setName(NameStr);
455 }
456
457public:
458 /// Provides a way to construct any of the CastInst subclasses using an
459 /// opcode instead of the subclass's constructor. The opcode must be in the
460 /// CastOps category (Instruction::isCast(opcode) returns true). This
461 /// constructor has insert-before-instruction semantics to automatically
462 /// insert the new CastInst before InsertBefore (if it is non-null).
463 /// Construct any of the CastInst subclasses
464 LLVM_ABI static CastInst *Create(
465 Instruction::CastOps, ///< The opcode of the cast instruction
466 Value *S, ///< The value to be casted (operand 0)
467 Type *Ty, ///< The type to which cast should be made
468 const Twine &Name = "", ///< Name for the instruction
469 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
470 );
471
472 /// Create a ZExt or BitCast cast instruction
474 Value *S, ///< The value to be casted (operand 0)
475 Type *Ty, ///< The type to which cast should be made
476 const Twine &Name = "", ///< Name for the instruction
477 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
478 );
479
480 /// Create a SExt or BitCast cast instruction
482 Value *S, ///< The value to be casted (operand 0)
483 Type *Ty, ///< The type to which cast should be made
484 const Twine &Name = "", ///< Name for the instruction
485 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
486 );
487
488 /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
490 Value *S, ///< The pointer value to be casted (operand 0)
491 Type *Ty, ///< The type to which cast should be made
492 const Twine &Name = "", ///< Name for the instruction
493 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
494 );
495
496 /// Create a BitCast or an AddrSpaceCast cast instruction.
498 Value *S, ///< The pointer value to be casted (operand 0)
499 Type *Ty, ///< The type to which cast should be made
500 const Twine &Name = "", ///< Name for the instruction
501 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
502 );
503
504 /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
505 ///
506 /// If the value is a pointer type and the destination an integer type,
507 /// creates a PtrToInt cast. If the value is an integer type and the
508 /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
509 /// a bitcast.
511 Value *S, ///< The pointer value to be casted (operand 0)
512 Type *Ty, ///< The type to which cast should be made
513 const Twine &Name = "", ///< Name for the instruction
514 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
515 );
516
517 /// Create a ZExt, BitCast, or Trunc for int -> int casts.
519 Value *S, ///< The pointer value to be casted (operand 0)
520 Type *Ty, ///< The type to which cast should be made
521 bool isSigned, ///< Whether to regard S as signed or not
522 const Twine &Name = "", ///< Name for the instruction
523 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
524 );
525
526 /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
528 Value *S, ///< The floating point value to be casted
529 Type *Ty, ///< The floating point type to cast to
530 const Twine &Name = "", ///< Name for the instruction
531 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
532 );
533
534 /// Create a Trunc or BitCast cast instruction
536 Value *S, ///< The value to be casted (operand 0)
537 Type *Ty, ///< The type to which cast should be made
538 const Twine &Name = "", ///< Name for the instruction
539 InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
540 );
541
542 /// Check whether a bitcast between these types is valid
543 LLVM_ABI static bool
544 isBitCastable(Type *SrcTy, ///< The Type from which the value should be cast.
545 Type *DestTy ///< The Type to which the value should be cast.
546 );
547
548 /// Check whether a bitcast, inttoptr, or ptrtoint cast between these
549 /// types is valid and a no-op.
550 ///
551 /// This ensures that any pointer<->integer cast has enough bits in the
552 /// integer and any other cast is a bitcast.
554 Type *SrcTy, ///< The Type from which the value should be cast.
555 Type *DestTy, ///< The Type to which the value should be cast.
556 const DataLayout &DL);
557
558 /// Returns the opcode necessary to cast Val into Ty using usual casting
559 /// rules.
560 /// Infer the opcode for cast operand and type
562 getCastOpcode(const Value *Val, ///< The value to cast
563 bool SrcIsSigned, ///< Whether to treat the source as signed
564 Type *Ty, ///< The Type to which the value should be casted
565 bool DstIsSigned ///< Whether to treate the dest. as signed
566 );
567
568 /// There are several places where we need to know if a cast instruction
569 /// only deals with integer source and destination types. To simplify that
570 /// logic, this method is provided.
571 /// @returns true iff the cast has only integral typed operand and dest type.
572 /// Determine if this is an integer-only cast.
573 LLVM_ABI bool isIntegerCast() const;
574
575 /// A no-op cast is one that can be effected without changing any bits.
576 /// It implies that the source and destination types are the same size. The
577 /// DataLayout argument is to determine the pointer size when examining casts
578 /// involving Integer and Pointer types. They are no-op casts if the integer
579 /// is the same size as the pointer. However, pointer size varies with
580 /// platform. Note that a precondition of this method is that the cast is
581 /// legal - i.e. the instruction formed with these operands would verify.
582 LLVM_ABI static bool
583 isNoopCast(Instruction::CastOps Opcode, ///< Opcode of cast
584 Type *SrcTy, ///< SrcTy of cast
585 Type *DstTy, ///< DstTy of cast
586 const DataLayout &DL ///< DataLayout to get the Int Ptr type from.
587 );
588
589 /// Determine if this cast is a no-op cast.
590 ///
591 /// \param DL is the DataLayout to determine pointer size.
592 LLVM_ABI bool isNoopCast(const DataLayout &DL) const;
593
594 /// Determine how a pair of casts can be eliminated, if they can be at all.
595 /// This is a helper function for both CastInst and ConstantExpr.
596 /// @returns 0 if the CastInst pair can't be eliminated, otherwise
597 /// returns Instruction::CastOps value for a cast that can replace
598 /// the pair, casting SrcTy to DstTy.
599 /// Determine if a cast pair is eliminable
600 LLVM_ABI static unsigned isEliminableCastPair(
601 Instruction::CastOps firstOpcode, ///< Opcode of first cast
602 Instruction::CastOps secondOpcode, ///< Opcode of second cast
603 Type *SrcTy, ///< SrcTy of 1st cast
604 Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
605 Type *DstTy, ///< DstTy of 2nd cast
606 const DataLayout *DL ///< Optional data layout
607 );
608
609 /// Return the opcode of this CastInst
613
614 /// Return the source type, as a convenience
615 Type* getSrcTy() const { return getOperand(0)->getType(); }
616 /// Return the destination type, as a convenience
617 Type* getDestTy() const { return getType(); }
618
619 /// This method can be used to determine if a cast from SrcTy to DstTy using
620 /// Opcode op is valid or not.
621 /// @returns true iff the proposed cast is valid.
622 /// Determine if a cast is valid without creating one.
623 LLVM_ABI static bool castIsValid(Instruction::CastOps op, Type *SrcTy,
624 Type *DstTy);
625 static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy) {
626 return castIsValid(op, S->getType(), DstTy);
627 }
628
629 /// Methods for support type inquiry through isa, cast, and dyn_cast:
630 static bool classof(const Instruction *I) {
631 return I->isCast();
632 }
633 static bool classof(const Value *V) {
635 }
636};
637
638/// Instruction that can have a nneg flag (zext/uitofp).
640public:
641 enum { NonNeg = (1 << 0) };
642
643 static bool classof(const Instruction *I) {
644 switch (I->getOpcode()) {
645 case Instruction::ZExt:
646 case Instruction::UIToFP:
647 return true;
648 default:
649 return false;
650 }
651 }
652
653 static bool classof(const Value *V) {
655 }
656};
657
658//===----------------------------------------------------------------------===//
659// CmpInst Class
660//===----------------------------------------------------------------------===//
661
662/// This class is the base class for the comparison instructions.
663/// Abstract base class of comparison instructions.
664class CmpInst : public Instruction {
665 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
666
667public:
668 /// This enumeration lists the possible predicates for CmpInst subclasses.
669 /// Values in the range 0-31 are reserved for FCmpInst, while values in the
670 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
671 /// predicate values are not overlapping between the classes.
672 ///
673 /// Some passes (e.g. InstCombine) depend on the bit-wise characteristics of
674 /// FCMP_* values. Changing the bit patterns requires a potential change to
675 /// those passes.
676 enum Predicate : unsigned {
677 // Opcode U L G E Intuitive operation
678 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
679 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
680 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
681 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
682 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
683 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
684 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
685 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
686 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
687 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
688 FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than
689 FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal
690 FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than
691 FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal
692 FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal
693 FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded)
697 ICMP_EQ = 32, ///< equal
698 ICMP_NE = 33, ///< not equal
699 ICMP_UGT = 34, ///< unsigned greater than
700 ICMP_UGE = 35, ///< unsigned greater or equal
701 ICMP_ULT = 36, ///< unsigned less than
702 ICMP_ULE = 37, ///< unsigned less or equal
703 ICMP_SGT = 38, ///< signed greater than
704 ICMP_SGE = 39, ///< signed greater or equal
705 ICMP_SLT = 40, ///< signed less than
706 ICMP_SLE = 41, ///< signed less or equal
710 };
713
714 /// Returns the sequence of all FCmp predicates.
720
721 /// Returns the sequence of all ICmp predicates.
727
728protected:
730 Value *LHS, Value *RHS, const Twine &Name = "",
731 InsertPosition InsertBefore = nullptr,
732 Instruction *FlagsSource = nullptr);
733
734public:
735 // allocate space for exactly two operands
736 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
737 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
738
739 /// Construct a compare instruction, given the opcode, the predicate and
740 /// the two operands. Optionally (if InstBefore is specified) insert the
741 /// instruction into a BasicBlock right before the specified instruction.
742 /// The specified Instruction is allowed to be a dereferenced end iterator.
743 /// Create a CmpInst
745 Value *S2, const Twine &Name = "",
746 InsertPosition InsertBefore = nullptr);
747
748 /// Construct a compare instruction, given the opcode, the predicate,
749 /// the two operands and the instruction to copy the flags from. Optionally
750 /// (if InstBefore is specified) insert the instruction into a BasicBlock
751 /// right before the specified instruction. The specified Instruction is
752 /// allowed to be a dereferenced end iterator.
753 /// Create a CmpInst
754 LLVM_ABI static CmpInst *
756 const Instruction *FlagsSource, const Twine &Name = "",
757 InsertPosition InsertBefore = nullptr);
758
759 /// Get the opcode casted to the right type
761 return static_cast<OtherOps>(Instruction::getOpcode());
762 }
763
764 /// Return the predicate for this instruction.
766
767 /// Set the predicate for this instruction to the specified value.
769
770 static bool isFPPredicate(Predicate P) {
771 static_assert(FIRST_FCMP_PREDICATE == 0,
772 "FIRST_FCMP_PREDICATE is required to be 0");
773 return P <= LAST_FCMP_PREDICATE;
774 }
775
778 }
779
781
782 bool isFPPredicate() const { return isFPPredicate(getPredicate()); }
783 bool isIntPredicate() const { return isIntPredicate(getPredicate()); }
784
785 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
786 /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
787 /// @returns the inverse predicate for the instruction's current predicate.
788 /// Return the inverse of the instruction's predicate.
792
793 /// Returns the ordered variant of a floating point compare.
794 ///
795 /// For example, UEQ -> OEQ, ULT -> OLT, OEQ -> OEQ
797 return static_cast<Predicate>(Pred & FCMP_ORD);
798 }
799
803
804 /// Returns the unordered variant of a floating point compare.
805 ///
806 /// For example, OEQ -> UEQ, OLT -> ULT, OEQ -> UEQ
808 return static_cast<Predicate>(Pred | FCMP_UNO);
809 }
810
814
815 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
816 /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
817 /// @returns the inverse predicate for predicate provided in \p pred.
818 /// Return the inverse of a given predicate
820
821 /// For example, EQ->EQ, SLE->SGE, ULT->UGT,
822 /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
823 /// @returns the predicate that would be the result of exchanging the two
824 /// operands of the CmpInst instruction without changing the result
825 /// produced.
826 /// Return the predicate as if the operands were swapped
830
831 /// This is a static version that you can use without an instruction
832 /// available.
833 /// Return the predicate as if the operands were swapped.
835
836 /// This is a static version that you can use without an instruction
837 /// available.
838 /// @returns true if the comparison predicate is strict, false otherwise.
839 LLVM_ABI static bool isStrictPredicate(Predicate predicate);
840
841 /// @returns true if the comparison predicate is strict, false otherwise.
842 /// Determine if this instruction is using an strict comparison predicate.
844
845 /// This is a static version that you can use without an instruction
846 /// available.
847 /// @returns true if the comparison predicate is non-strict, false otherwise.
848 LLVM_ABI static bool isNonStrictPredicate(Predicate predicate);
849
850 /// @returns true if the comparison predicate is non-strict, false otherwise.
851 /// Determine if this instruction is using an non-strict comparison predicate.
852 bool isNonStrictPredicate() const {
854 }
855
856 /// For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.
857 /// Returns the strict version of non-strict comparisons.
861
862 /// This is a static version that you can use without an instruction
863 /// available.
864 /// @returns the strict version of comparison provided in \p pred.
865 /// If \p pred is not a strict comparison predicate, returns \p pred.
866 /// Returns the strict version of non-strict comparisons.
868
869 /// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
870 /// Returns the non-strict version of strict comparisons.
874
875 /// This is a static version that you can use without an instruction
876 /// available.
877 /// @returns the non-strict version of comparison provided in \p pred.
878 /// If \p pred is not a strict comparison predicate, returns \p pred.
879 /// Returns the non-strict version of strict comparisons.
881
882 /// This is a static version that you can use without an instruction
883 /// available.
884 /// Return the flipped strictness of predicate
886
887 /// For predicate of kind "is X or equal to 0" returns the predicate "is X".
888 /// For predicate of kind "is X" returns the predicate "is X or equal to 0".
889 /// does not support other kind of predicates.
890 /// @returns the predicate that does not contains is equal to zero if
891 /// it had and vice versa.
892 /// Return the flipped strictness of predicate
896
897 /// Provide more efficient getOperand methods.
899
900 /// This is just a convenience that dispatches to the subclasses.
901 /// Swap the operands and adjust predicate accordingly to retain
902 /// the same comparison.
903 LLVM_ABI void swapOperands();
904
905 /// This is just a convenience that dispatches to the subclasses.
906 /// Determine if this CmpInst is commutative.
907 LLVM_ABI bool isCommutative() const;
908
909 /// Determine if this is an equals/not equals predicate.
910 /// This is a static version that you can use without an instruction
911 /// available.
912 LLVM_ABI static bool isEquality(Predicate pred);
913
914 /// Determine if this is an equals/not equals predicate.
915 bool isEquality() const { return isEquality(getPredicate()); }
916
917 /// Determine if one operand of this compare can always be replaced by the
918 /// other operand, ignoring provenance considerations. If \p Invert, check for
919 /// equivalence with the inverse predicate.
920 LLVM_ABI bool isEquivalence(bool Invert = false) const;
921
922 /// Return true if the predicate is relational (not EQ or NE).
923 static bool isRelational(Predicate P) { return !isEquality(P); }
924
925 /// Return true if the predicate is relational (not EQ or NE).
926 bool isRelational() const { return !isEquality(); }
927
928 /// @returns true if the comparison is signed, false otherwise.
929 /// Determine if this instruction is using a signed comparison.
930 bool isSigned() const {
931 return isSigned(getPredicate());
932 }
933
934 /// @returns true if the comparison is unsigned, false otherwise.
935 /// Determine if this instruction is using an unsigned comparison.
936 bool isUnsigned() const {
937 return isUnsigned(getPredicate());
938 }
939
940 /// This is just a convenience.
941 /// Determine if this is true when both operands are the same.
942 bool isTrueWhenEqual() const {
944 }
945
946 /// This is just a convenience.
947 /// Determine if this is false when both operands are the same.
948 bool isFalseWhenEqual() const {
950 }
951
952 /// @returns true if the predicate is unsigned, false otherwise.
953 /// Determine if the predicate is an unsigned operation.
954 static bool isUnsigned(Predicate Pred) {
955 return Pred >= ICMP_UGT && Pred <= ICMP_ULE;
956 }
957
958 /// @returns true if the predicate is signed, false otherwise.
959 /// Determine if the predicate is an signed operation.
960 static bool isSigned(Predicate Pred) {
961 return Pred >= ICMP_SGT && Pred <= ICMP_SLE;
962 }
963
964 /// Determine if the predicate is an ordered operation.
965 LLVM_ABI static bool isOrdered(Predicate predicate);
966
967 /// Determine if the predicate is an unordered operation.
968 LLVM_ABI static bool isUnordered(Predicate predicate);
969
970 /// Determine if the predicate is true when comparing a value with itself.
971 LLVM_ABI static bool isTrueWhenEqual(Predicate predicate);
972
973 /// Determine if the predicate is false when comparing a value with itself.
974 LLVM_ABI static bool isFalseWhenEqual(Predicate predicate);
975
976 /// Methods for support type inquiry through isa, cast, and dyn_cast:
977 static bool classof(const Instruction *I) {
978 return I->getOpcode() == Instruction::ICmp ||
979 I->getOpcode() == Instruction::FCmp;
980 }
981 static bool classof(const Value *V) {
983 }
984
985 /// Create a result type for fcmp/icmp
986 static Type* makeCmpResultType(Type* opnd_type) {
987 if (VectorType* vt = dyn_cast<VectorType>(opnd_type)) {
988 return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
989 vt->getElementCount());
990 }
991 return Type::getInt1Ty(opnd_type->getContext());
992 }
993
994private:
995 // Shadow Value::setValueSubclassData with a private forwarding method so that
996 // subclasses cannot accidentally use it.
997 void setValueSubclassData(unsigned short D) {
999 }
1000};
1001
1002// FIXME: these are redundant if CmpInst < BinaryOperator
1003template <>
1004struct OperandTraits<CmpInst> : public FixedNumOperandTraits<CmpInst, 2> {
1005};
1006
1008
1010
1011/// A lightweight accessor for an operand bundle meant to be passed
1012/// around by value.
1015
1016 OperandBundleUse() = default;
1019
1020 /// Return true if the operand at index \p Idx in this operand bundle
1021 /// has the attribute A.
1022 bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const {
1024 if (A == Attribute::ReadOnly)
1025 return Inputs[Idx]->getType()->isPointerTy();
1026
1027 // Conservative answer: no operands have any attributes.
1028 return false;
1029 }
1030
1031 /// Return the tag of this operand bundle as a string.
1033 return Tag->getKey();
1034 }
1035
1036 /// Return the tag of this operand bundle as an integer.
1037 ///
1038 /// Operand bundle tags are interned by LLVMContextImpl::getOrInsertBundleTag,
1039 /// and this function returns the unique integer getOrInsertBundleTag
1040 /// associated the tag of this operand bundle to.
1042 return Tag->getValue();
1043 }
1044
1045 /// Return true if this is a "deopt" operand bundle.
1047 return getTagID() == LLVMContext::OB_deopt;
1048 }
1049
1050 /// Return true if this is a "funclet" operand bundle.
1053 }
1054
1055 /// Return true if this is a "cfguardtarget" operand bundle.
1059
1060private:
1061 /// Pointer to an entry in LLVMContextImpl::getOrInsertBundleTag.
1063};
1064
1065/// A container for an operand bundle being viewed as a set of values
1066/// rather than a set of uses.
1067///
1068/// Unlike OperandBundleUse, OperandBundleDefT owns the memory it carries, and
1069/// so it is possible to create and pass around "self-contained" instances of
1070/// OperandBundleDef and ConstOperandBundleDef.
1071template <typename InputTy> class OperandBundleDefT {
1072 std::string Tag;
1073 std::vector<InputTy> Inputs;
1074
1075public:
1076 explicit OperandBundleDefT(std::string Tag, std::vector<InputTy> Inputs)
1077 : Tag(std::move(Tag)), Inputs(std::move(Inputs)) {}
1078 explicit OperandBundleDefT(std::string Tag, ArrayRef<InputTy> Inputs)
1079 : Tag(std::move(Tag)), Inputs(Inputs) {}
1080
1082 Tag = std::string(OBU.getTagName());
1083 llvm::append_range(Inputs, OBU.Inputs);
1084 }
1085
1086 ArrayRef<InputTy> inputs() const { return Inputs; }
1087
1088 using input_iterator = typename std::vector<InputTy>::const_iterator;
1089
1090 size_t input_size() const { return Inputs.size(); }
1091 input_iterator input_begin() const { return Inputs.begin(); }
1092 input_iterator input_end() const { return Inputs.end(); }
1093
1094 StringRef getTag() const { return Tag; }
1095};
1096
1097using OperandBundleDef = OperandBundleDefT<Value *>;
1099
1100//===----------------------------------------------------------------------===//
1101// CallBase Class
1102//===----------------------------------------------------------------------===//
1103
1104/// Base class for all callable instructions (InvokeInst and CallInst)
1105/// Holds everything related to calling a function.
1106///
1107/// All call-like instructions are required to use a common operand layout:
1108/// - Zero or more arguments to the call,
1109/// - Zero or more operand bundles with zero or more operand inputs each
1110/// bundle,
1111/// - Zero or more subclass controlled operands
1112/// - The called function.
1113///
1114/// This allows this base class to easily access the called function and the
1115/// start of the arguments without knowing how many other operands a particular
1116/// subclass requires. Note that accessing the end of the argument list isn't
1117/// as cheap as most other operations on the base class.
1118class CallBase : public Instruction {
1119protected:
1120 // The first two bits are reserved by CallInst for fast retrieval,
1125 static_assert(
1127 "Bitfields must be contiguous");
1128
1129 /// The last operand is the called operand.
1130 static constexpr int CalledOperandOpEndIdx = -1;
1131
1132 AttributeList Attrs; ///< parameter attributes for callable
1134
1135 template <class... ArgsTy>
1136 CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
1137 : Instruction(std::forward<ArgsTy>(Args)...), Attrs(A), FTy(FT) {}
1138
1140
1141 bool hasDescriptor() const { return Value::HasDescriptor; }
1142
1144 switch (getOpcode()) {
1145 case Instruction::Call:
1146 return 0;
1147 case Instruction::Invoke:
1148 return 2;
1149 case Instruction::CallBr:
1151 }
1152 llvm_unreachable("Invalid opcode!");
1153 }
1154
1155 /// Get the number of extra operands for instructions that don't have a fixed
1156 /// number of extra operands.
1158
1159public:
1161
1162 /// Create a clone of \p CB with a different set of operand bundles and
1163 /// insert it before \p InsertPt.
1164 ///
1165 /// The returned call instruction is identical \p CB in every way except that
1166 /// the operand bundles for the new instruction are set to the operand bundles
1167 /// in \p Bundles.
1168 LLVM_ABI static CallBase *Create(CallBase *CB,
1170 InsertPosition InsertPt = nullptr);
1171
1172 /// Create a clone of \p CB with the operand bundle with the tag matching
1173 /// \p Bundle's tag replaced with Bundle, and insert it before \p InsertPt.
1174 ///
1175 /// The returned call instruction is identical \p CI in every way except that
1176 /// the specified operand bundle has been replaced.
1177 LLVM_ABI static CallBase *Create(CallBase *CB, OperandBundleDef Bundle,
1178 InsertPosition InsertPt = nullptr);
1179
1180 /// Create a clone of \p CB with operand bundle \p OB added.
1183 InsertPosition InsertPt = nullptr);
1184
1185 /// Create a clone of \p CB with operand bundle \p ID removed.
1186 LLVM_ABI static CallBase *
1188 InsertPosition InsertPt = nullptr);
1189
1190 /// Return the convergence control token for this call, if it exists.
1193 return Bundle->Inputs[0].get();
1194 }
1195 return nullptr;
1196 }
1197
1198 static bool classof(const Instruction *I) {
1199 return I->getOpcode() == Instruction::Call ||
1200 I->getOpcode() == Instruction::Invoke ||
1201 I->getOpcode() == Instruction::CallBr;
1202 }
1203 static bool classof(const Value *V) {
1205 }
1206
1207 FunctionType *getFunctionType() const { return FTy; }
1208
1210 Value::mutateType(FTy->getReturnType());
1211 this->FTy = FTy;
1212 }
1213
1215
1216 /// data_operands_begin/data_operands_end - Return iterators iterating over
1217 /// the call / invoke argument list and bundle operands. For invokes, this is
1218 /// the set of instruction operands except the invoke target and the two
1219 /// successor blocks; and for calls this is the set of instruction operands
1220 /// except the call target.
1223 return const_cast<CallBase *>(this)->data_operands_begin();
1224 }
1226 // Walk from the end of the operands over the called operand and any
1227 // subclass operands.
1228 return op_end() - getNumSubclassExtraOperands() - 1;
1229 }
1231 return const_cast<CallBase *>(this)->data_operands_end();
1232 }
1239 bool data_operands_empty() const {
1241 }
1242 unsigned data_operands_size() const {
1243 return std::distance(data_operands_begin(), data_operands_end());
1244 }
1245
1246 bool isDataOperand(const Use *U) const {
1247 assert(this == U->getUser() &&
1248 "Only valid to query with a use of this instruction!");
1249 return data_operands_begin() <= U && U < data_operands_end();
1250 }
1252 return isDataOperand(&UI.getUse());
1253 }
1254
1255 /// Given a value use iterator, return the data operand corresponding to it.
1256 /// Iterator must actually correspond to a data operand.
1258 return getDataOperandNo(&UI.getUse());
1259 }
1260
1261 /// Given a use for a data operand, get the data operand number that
1262 /// corresponds to it.
1263 unsigned getDataOperandNo(const Use *U) const {
1264 assert(isDataOperand(U) && "Data operand # out of range!");
1265 return U - data_operands_begin();
1266 }
1267
1268 /// Return the iterator pointing to the beginning of the argument list.
1271 return const_cast<CallBase *>(this)->arg_begin();
1272 }
1273
1274 /// Return the iterator pointing to the end of the argument list.
1276 // From the end of the data operands, walk backwards past the bundle
1277 // operands.
1279 }
1281 return const_cast<CallBase *>(this)->arg_end();
1282 }
1283
1284 /// Iteration adapter for range-for loops.
1291 bool arg_empty() const { return arg_end() == arg_begin(); }
1292 unsigned arg_size() const { return arg_end() - arg_begin(); }
1293
1294 Value *getArgOperand(unsigned i) const {
1295 assert(i < arg_size() && "Out of bounds!");
1296 return getOperand(i);
1297 }
1298
1299 void setArgOperand(unsigned i, Value *v) {
1300 assert(i < arg_size() && "Out of bounds!");
1301 setOperand(i, v);
1302 }
1303
1304 /// Wrappers for getting the \c Use of a call argument.
1305 const Use &getArgOperandUse(unsigned i) const {
1306 assert(i < arg_size() && "Out of bounds!");
1307 return User::getOperandUse(i);
1308 }
1309 Use &getArgOperandUse(unsigned i) {
1310 assert(i < arg_size() && "Out of bounds!");
1311 return User::getOperandUse(i);
1312 }
1313
1314 bool isArgOperand(const Use *U) const {
1315 assert(this == U->getUser() &&
1316 "Only valid to query with a use of this instruction!");
1317 return arg_begin() <= U && U < arg_end();
1318 }
1320 return isArgOperand(&UI.getUse());
1321 }
1322
1323 /// Given a use for a arg operand, get the arg operand number that
1324 /// corresponds to it.
1325 unsigned getArgOperandNo(const Use *U) const {
1326 assert(isArgOperand(U) && "Arg operand # out of range!");
1327 return U - arg_begin();
1328 }
1329
1330 /// Given a value use iterator, return the arg operand number corresponding to
1331 /// it. Iterator must actually correspond to a data operand.
1333 return getArgOperandNo(&UI.getUse());
1334 }
1335
1336 /// Returns true if this CallSite passes the given Value* as an argument to
1337 /// the called function.
1338 bool hasArgument(const Value *V) const {
1339 return llvm::is_contained(args(), V);
1340 }
1341
1343
1346
1347 /// Returns the function called, or null if this is an indirect function
1348 /// invocation or the function signature does not match the call signature, or
1349 /// the call target is an alias.
1352 if (F->getFunctionType() == getFunctionType())
1353 return F;
1354 return nullptr;
1355 }
1356
1357 /// Return true if the callsite is an indirect call.
1358 LLVM_ABI bool isIndirectCall() const;
1359
1360 /// Determine whether the passed iterator points to the callee operand's Use.
1362 return isCallee(&UI.getUse());
1363 }
1364
1365 /// Determine whether this Use is the callee operand's Use.
1366 bool isCallee(const Use *U) const { return &getCalledOperandUse() == U; }
1367
1368 /// Helper to get the caller (the parent function).
1370 const Function *getCaller() const {
1371 return const_cast<CallBase *>(this)->getCaller();
1372 }
1373
1374 /// Tests if this call site must be tail call optimized. Only a CallInst can
1375 /// be tail call optimized.
1376 LLVM_ABI bool isMustTailCall() const;
1377
1378 /// Tests if this call site is marked as a tail call.
1379 LLVM_ABI bool isTailCall() const;
1380
1381 /// Returns the intrinsic ID of the intrinsic called or
1382 /// Intrinsic::not_intrinsic if the called function is not an intrinsic, or if
1383 /// this is an indirect call.
1385
1387
1388 /// Sets the function called, including updating the function type.
1392
1393 /// Sets the function called, including updating the function type.
1397
1398 /// Sets the function called, including updating to the specified function
1399 /// type.
1401 this->FTy = FTy;
1402 // This function doesn't mutate the return type, only the function
1403 // type. Seems broken, but I'm just gonna stick an assert in for now.
1404 assert(getType() == FTy->getReturnType());
1405 setCalledOperand(Fn);
1406 }
1407
1411
1415
1416 /// Check if this call is an inline asm statement.
1417 bool isInlineAsm() const { return isa<InlineAsm>(getCalledOperand()); }
1418
1419 /// \name Attribute API
1420 ///
1421 /// These methods access and modify attributes on this call (including
1422 /// looking through to the attributes on the called function when necessary).
1423 ///@{
1424
1425 /// Return the attributes for this call.
1426 AttributeList getAttributes() const { return Attrs; }
1427
1428 /// Set the attributes for this call.
1429 void setAttributes(AttributeList A) { Attrs = A; }
1430
1431 /// Return the return attributes for this call.
1433 return getAttributes().getRetAttrs();
1434 }
1435
1436 /// Return the param attributes for this call.
1437 AttributeSet getParamAttributes(unsigned ArgNo) const {
1438 return getAttributes().getParamAttrs(ArgNo);
1439 }
1440
1441 /// Try to intersect the attributes from 'this' CallBase and the
1442 /// 'Other' CallBase. Sets the intersected attributes to 'this' and
1443 /// return true if successful. Doesn't modify 'this' and returns
1444 /// false if unsuccessful.
1446 if (this == Other)
1447 return true;
1448 AttributeList AL = getAttributes();
1449 AttributeList ALOther = Other->getAttributes();
1450 auto Intersected = AL.intersectWith(getContext(), ALOther);
1451 if (!Intersected)
1452 return false;
1453 setAttributes(*Intersected);
1454 return true;
1455 }
1456
1457 /// Determine whether this call has the given attribute. If it does not
1458 /// then determine if the called function has the attribute, but only if
1459 /// the attribute is allowed for the call.
1461 assert(Kind != Attribute::NoBuiltin &&
1462 "Use CallBase::isNoBuiltin() to check for Attribute::NoBuiltin");
1463 return hasFnAttrImpl(Kind);
1464 }
1465
1466 /// Determine whether this call has the given attribute. If it does not
1467 /// then determine if the called function has the attribute, but only if
1468 /// the attribute is allowed for the call.
1469 bool hasFnAttr(StringRef Kind) const { return hasFnAttrImpl(Kind); }
1470
1471 // TODO: remove non-AtIndex versions of these methods.
1472 /// adds the attribute to the list of attributes.
1474 Attrs = Attrs.addAttributeAtIndex(getContext(), i, Kind);
1475 }
1476
1477 /// adds the attribute to the list of attributes.
1478 void addAttributeAtIndex(unsigned i, Attribute Attr) {
1479 Attrs = Attrs.addAttributeAtIndex(getContext(), i, Attr);
1480 }
1481
1482 /// Adds the attribute to the function.
1484 Attrs = Attrs.addFnAttribute(getContext(), Kind);
1485 }
1486
1487 /// Adds the attribute to the function.
1489 Attrs = Attrs.addFnAttribute(getContext(), Attr);
1490 }
1491
1492 /// Adds the attribute to the return value.
1494 Attrs = Attrs.addRetAttribute(getContext(), Kind);
1495 }
1496
1497 /// Adds the attribute to the return value.
1499 Attrs = Attrs.addRetAttribute(getContext(), Attr);
1500 }
1501
1502 /// Adds attributes to the return value.
1503 void addRetAttrs(const AttrBuilder &B) {
1504 Attrs = Attrs.addRetAttributes(getContext(), B);
1505 }
1506
1507 /// Adds the attribute to the indicated argument
1508 void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
1509 assert(ArgNo < arg_size() && "Out of bounds");
1510 Attrs = Attrs.addParamAttribute(getContext(), ArgNo, Kind);
1511 }
1512
1513 /// Adds the attribute to the indicated argument
1514 void addParamAttr(unsigned ArgNo, Attribute Attr) {
1515 assert(ArgNo < arg_size() && "Out of bounds");
1516 Attrs = Attrs.addParamAttribute(getContext(), ArgNo, Attr);
1517 }
1518
1519 /// Adds attributes to the indicated argument
1520 void addParamAttrs(unsigned ArgNo, const AttrBuilder &B) {
1521 assert(ArgNo < arg_size() && "Out of bounds");
1522 Attrs = Attrs.addParamAttributes(getContext(), ArgNo, B);
1523 }
1524
1525 /// removes the attribute from the list of attributes.
1527 Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind);
1528 }
1529
1530 /// removes the attribute from the list of attributes.
1531 void removeAttributeAtIndex(unsigned i, StringRef Kind) {
1532 Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind);
1533 }
1534
1535 /// Removes the attributes from the function
1536 void removeFnAttrs(const AttributeMask &AttrsToRemove) {
1537 Attrs = Attrs.removeFnAttributes(getContext(), AttrsToRemove);
1538 }
1539
1540 /// Removes the attribute from the function
1542 Attrs = Attrs.removeFnAttribute(getContext(), Kind);
1543 }
1544
1545 /// Removes the attribute from the function
1547 Attrs = Attrs.removeFnAttribute(getContext(), Kind);
1548 }
1549
1550 /// Removes the attribute from the return value
1552 Attrs = Attrs.removeRetAttribute(getContext(), Kind);
1553 }
1554
1555 /// Removes the attributes from the return value
1556 void removeRetAttrs(const AttributeMask &AttrsToRemove) {
1557 Attrs = Attrs.removeRetAttributes(getContext(), AttrsToRemove);
1558 }
1559
1560 /// Removes the attribute from the given argument
1561 void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
1562 assert(ArgNo < arg_size() && "Out of bounds");
1563 Attrs = Attrs.removeParamAttribute(getContext(), ArgNo, Kind);
1564 }
1565
1566 /// Removes the attribute from the given argument
1567 void removeParamAttr(unsigned ArgNo, StringRef Kind) {
1568 assert(ArgNo < arg_size() && "Out of bounds");
1569 Attrs = Attrs.removeParamAttribute(getContext(), ArgNo, Kind);
1570 }
1571
1572 /// Removes the attributes from the given argument
1573 void removeParamAttrs(unsigned ArgNo, const AttributeMask &AttrsToRemove) {
1574 Attrs = Attrs.removeParamAttributes(getContext(), ArgNo, AttrsToRemove);
1575 }
1576
1577 /// adds the dereferenceable attribute to the list of attributes.
1578 void addDereferenceableParamAttr(unsigned i, uint64_t Bytes) {
1579 Attrs = Attrs.addDereferenceableParamAttr(getContext(), i, Bytes);
1580 }
1581
1582 /// adds the dereferenceable attribute to the list of attributes.
1584 Attrs = Attrs.addDereferenceableRetAttr(getContext(), Bytes);
1585 }
1586
1587 /// adds the range attribute to the list of attributes.
1589 Attrs = Attrs.addRangeRetAttr(getContext(), CR);
1590 }
1591
1592 /// Determine whether the return value has the given attribute.
1594 return hasRetAttrImpl(Kind);
1595 }
1596 /// Determine whether the return value has the given attribute.
1597 bool hasRetAttr(StringRef Kind) const { return hasRetAttrImpl(Kind); }
1598
1599 /// Return the attribute for the given attribute kind for the return value.
1601 Attribute RetAttr = Attrs.getRetAttr(Kind);
1602 if (RetAttr.isValid())
1603 return RetAttr;
1604
1605 // Look at the callee, if available.
1606 if (const Function *F = getCalledFunction())
1607 return F->getRetAttribute(Kind);
1608 return Attribute();
1609 }
1610
1611 /// Determine whether the argument or parameter has the given attribute.
1612 LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const;
1613
1614 /// Return true if this argument has the nonnull attribute on either the
1615 /// CallBase instruction or the called function. Also returns true if at least
1616 /// one byte is known to be dereferenceable and the pointer is in
1617 /// addrspace(0). If \p AllowUndefOrPoison is true, respect the semantics of
1618 /// nonnull attribute and return true even if the argument can be undef or
1619 /// poison.
1620 LLVM_ABI bool paramHasNonNullAttr(unsigned ArgNo,
1621 bool AllowUndefOrPoison) const;
1622
1623 /// Get the attribute of a given kind at a position.
1625 return getAttributes().getAttributeAtIndex(i, Kind);
1626 }
1627
1628 /// Get the attribute of a given kind at a position.
1629 Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const {
1630 return getAttributes().getAttributeAtIndex(i, Kind);
1631 }
1632
1633 /// Get the attribute of a given kind for the function.
1635 Attribute Attr = getAttributes().getFnAttr(Kind);
1636 if (Attr.isValid())
1637 return Attr;
1638 return getFnAttrOnCalledFunction(Kind);
1639 }
1640
1641 /// Get the attribute of a given kind for the function.
1643 Attribute A = getAttributes().getFnAttr(Kind);
1644 if (A.isValid())
1645 return A;
1646 return getFnAttrOnCalledFunction(Kind);
1647 }
1648
1649 /// Get the attribute of a given kind from a given arg
1650 Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
1651 assert(ArgNo < arg_size() && "Out of bounds");
1652 Attribute A = getAttributes().getParamAttr(ArgNo, Kind);
1653 if (A.isValid())
1654 return A;
1655 return getParamAttrOnCalledFunction(ArgNo, Kind);
1656 }
1657
1658 /// Get the attribute of a given kind from a given arg
1659 Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const {
1660 assert(ArgNo < arg_size() && "Out of bounds");
1661 Attribute A = getAttributes().getParamAttr(ArgNo, Kind);
1662 if (A.isValid())
1663 return A;
1664 return getParamAttrOnCalledFunction(ArgNo, Kind);
1665 }
1666
1667 /// Return true if the data operand at index \p i has the attribute \p
1668 /// A.
1669 ///
1670 /// Data operands include call arguments and values used in operand bundles,
1671 /// but does not include the callee operand.
1672 ///
1673 /// The index \p i is interpreted as
1674 ///
1675 /// \p i in [0, arg_size) -> argument number (\p i)
1676 /// \p i in [arg_size, data_operand_size) -> bundle operand at index
1677 /// (\p i) in the operand list.
1678 bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const {
1679 // Note that we have to add one because `i` isn't zero-indexed.
1681 "Data operand index out of bounds!");
1682
1683 // The attribute A can either be directly specified, if the operand in
1684 // question is a call argument; or be indirectly implied by the kind of its
1685 // containing operand bundle, if the operand is a bundle operand.
1686
1687 if (i < arg_size())
1688 return paramHasAttr(i, Kind);
1689
1691 "Must be either a call argument or an operand bundle!");
1692 return bundleOperandHasAttr(i, Kind);
1693 }
1694
1695 /// Return which pointer components this operand may capture.
1696 LLVM_ABI CaptureInfo getCaptureInfo(unsigned OpNo) const;
1697
1698 /// Determine whether this data operand is not captured.
1699 // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
1700 // better indicate that this may return a conservative answer.
1701 bool doesNotCapture(unsigned OpNo) const {
1702 return capturesNothing(getCaptureInfo(OpNo));
1703 }
1704
1705 /// Returns whether the call has an argument that has an attribute like
1706 /// captures(ret: address, provenance), where the return capture components
1707 /// are not a subset of the other capture components.
1709
1710 /// Determine whether this argument is passed by value.
1711 bool isByValArgument(unsigned ArgNo) const {
1712 return paramHasAttr(ArgNo, Attribute::ByVal);
1713 }
1714
1715 /// Determine whether this argument is passed in an alloca.
1716 bool isInAllocaArgument(unsigned ArgNo) const {
1717 return paramHasAttr(ArgNo, Attribute::InAlloca);
1718 }
1719
1720 /// Determine whether this argument is passed by value, in an alloca, or is
1721 /// preallocated.
1722 bool isPassPointeeByValueArgument(unsigned ArgNo) const {
1723 return paramHasAttr(ArgNo, Attribute::ByVal) ||
1724 paramHasAttr(ArgNo, Attribute::InAlloca) ||
1725 paramHasAttr(ArgNo, Attribute::Preallocated);
1726 }
1727
1728 /// Determine whether passing undef to this argument is undefined behavior.
1729 /// If passing undef to this argument is UB, passing poison is UB as well
1730 /// because poison is more undefined than undef.
1731 bool isPassingUndefUB(unsigned ArgNo) const {
1732 return paramHasAttr(ArgNo, Attribute::NoUndef) ||
1733 // dereferenceable implies noundef.
1734 paramHasAttr(ArgNo, Attribute::Dereferenceable) ||
1735 // dereferenceable implies noundef, and null is a well-defined value.
1736 paramHasAttr(ArgNo, Attribute::DereferenceableOrNull);
1737 }
1738
1739 /// Determine if there are is an inalloca argument. Only the last argument can
1740 /// have the inalloca attribute.
1741 bool hasInAllocaArgument() const {
1742 return !arg_empty() && paramHasAttr(arg_size() - 1, Attribute::InAlloca);
1743 }
1744
1745 // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
1746 // better indicate that this may return a conservative answer.
1747 bool doesNotAccessMemory(unsigned OpNo) const {
1748 return dataOperandHasImpliedAttr(OpNo, Attribute::ReadNone);
1749 }
1750
1751 // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
1752 // better indicate that this may return a conservative answer.
1753 bool onlyReadsMemory(unsigned OpNo) const {
1754 // If the argument is passed byval, the callee does not have access to the
1755 // original pointer and thus cannot write to it.
1756 if (OpNo < arg_size() && isByValArgument(OpNo))
1757 return true;
1758
1759 return dataOperandHasImpliedAttr(OpNo, Attribute::ReadOnly) ||
1760 dataOperandHasImpliedAttr(OpNo, Attribute::ReadNone);
1761 }
1762
1763 // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
1764 // better indicate that this may return a conservative answer.
1765 bool onlyWritesMemory(unsigned OpNo) const {
1766 return dataOperandHasImpliedAttr(OpNo, Attribute::WriteOnly) ||
1767 dataOperandHasImpliedAttr(OpNo, Attribute::ReadNone);
1768 }
1769
1770 /// Extract the alignment of the return value.
1772 if (auto Align = Attrs.getRetAlignment())
1773 return Align;
1774 if (const Function *F = getCalledFunction())
1775 return F->getAttributes().getRetAlignment();
1776 return std::nullopt;
1777 }
1778
1779 /// Extract the alignment for a call or parameter (0=unknown).
1780 MaybeAlign getParamAlign(unsigned ArgNo) const {
1781 return Attrs.getParamAlignment(ArgNo);
1782 }
1783
1784 MaybeAlign getParamStackAlign(unsigned ArgNo) const {
1785 return Attrs.getParamStackAlignment(ArgNo);
1786 }
1787
1788 /// Extract the byref type for a call or parameter.
1789 Type *getParamByRefType(unsigned ArgNo) const {
1790 if (auto *Ty = Attrs.getParamByRefType(ArgNo))
1791 return Ty;
1792 if (const Function *F = getCalledFunction())
1793 return F->getAttributes().getParamByRefType(ArgNo);
1794 return nullptr;
1795 }
1796
1797 /// Extract the byval type for a call or parameter.
1798 Type *getParamByValType(unsigned ArgNo) const {
1799 if (auto *Ty = Attrs.getParamByValType(ArgNo))
1800 return Ty;
1801 if (const Function *F = getCalledFunction())
1802 return F->getAttributes().getParamByValType(ArgNo);
1803 return nullptr;
1804 }
1805
1806 /// Extract the preallocated type for a call or parameter.
1807 Type *getParamPreallocatedType(unsigned ArgNo) const {
1808 if (auto *Ty = Attrs.getParamPreallocatedType(ArgNo))
1809 return Ty;
1810 if (const Function *F = getCalledFunction())
1811 return F->getAttributes().getParamPreallocatedType(ArgNo);
1812 return nullptr;
1813 }
1814
1815 /// Extract the inalloca type for a call or parameter.
1816 Type *getParamInAllocaType(unsigned ArgNo) const {
1817 if (auto *Ty = Attrs.getParamInAllocaType(ArgNo))
1818 return Ty;
1819 if (const Function *F = getCalledFunction())
1820 return F->getAttributes().getParamInAllocaType(ArgNo);
1821 return nullptr;
1822 }
1823
1824 /// Extract the sret type for a call or parameter.
1825 Type *getParamStructRetType(unsigned ArgNo) const {
1826 if (auto *Ty = Attrs.getParamStructRetType(ArgNo))
1827 return Ty;
1828 if (const Function *F = getCalledFunction())
1829 return F->getAttributes().getParamStructRetType(ArgNo);
1830 return nullptr;
1831 }
1832
1833 /// Extract the elementtype type for a parameter.
1834 /// Note that elementtype() can only be applied to call arguments, not
1835 /// function declaration parameters.
1836 Type *getParamElementType(unsigned ArgNo) const {
1837 return Attrs.getParamElementType(ArgNo);
1838 }
1839
1840 /// Extract the number of dereferenceable bytes for a call or
1841 /// parameter (0=unknown).
1843 uint64_t Bytes = Attrs.getRetDereferenceableBytes();
1844 if (const Function *F = getCalledFunction())
1845 Bytes = std::max(Bytes, F->getAttributes().getRetDereferenceableBytes());
1846 return Bytes;
1847 }
1848
1849 /// Extract the number of dereferenceable bytes for a call or
1850 /// parameter (0=unknown).
1852 return Attrs.getParamDereferenceableBytes(i);
1853 }
1854
1855 /// Extract the number of dereferenceable_or_null bytes for a call
1856 /// (0=unknown).
1858 uint64_t Bytes = Attrs.getRetDereferenceableOrNullBytes();
1859 if (const Function *F = getCalledFunction()) {
1860 Bytes = std::max(Bytes,
1861 F->getAttributes().getRetDereferenceableOrNullBytes());
1862 }
1863
1864 return Bytes;
1865 }
1866
1867 /// Extract the number of dereferenceable_or_null bytes for a
1868 /// parameter (0=unknown).
1870 return Attrs.getParamDereferenceableOrNullBytes(i);
1871 }
1872
1873 /// Extract a test mask for disallowed floating-point value classes for the
1874 /// return value.
1876
1877 /// Extract a test mask for disallowed floating-point value classes for the
1878 /// parameter.
1879 LLVM_ABI FPClassTest getParamNoFPClass(unsigned i) const;
1880
1881 /// If this return value has a range attribute, return the value range of the
1882 /// argument. Otherwise, std::nullopt is returned.
1883 LLVM_ABI std::optional<ConstantRange> getRange() const;
1884
1885 /// Return true if the return value is known to be not null.
1886 /// This may be because it has the nonnull attribute, or because at least
1887 /// one byte is dereferenceable and the pointer is in addrspace(0).
1888 LLVM_ABI bool isReturnNonNull() const;
1889
1890 /// Determine if the return value is marked with NoAlias attribute.
1891 bool returnDoesNotAlias() const {
1892 return Attrs.hasRetAttr(Attribute::NoAlias);
1893 }
1894
1895 /// If one of the arguments has the 'returned' attribute, returns its
1896 /// operand value. Otherwise, return nullptr.
1898 return getArgOperandWithAttribute(Attribute::Returned);
1899 }
1900
1901 /// If one of the arguments has the specified attribute, returns its
1902 /// operand value. Otherwise, return nullptr.
1904
1905 /// Return true if the call should not be treated as a call to a
1906 /// builtin.
1907 bool isNoBuiltin() const {
1908 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1909 !hasFnAttrImpl(Attribute::Builtin);
1910 }
1911
1912 /// Determine if the call requires strict floating point semantics.
1913 bool isStrictFP() const { return hasFnAttr(Attribute::StrictFP); }
1914
1915 /// Return true if the call should not be inlined.
1916 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1917 void setIsNoInline() { addFnAttr(Attribute::NoInline); }
1918
1921
1922 /// Determine if the call does not access memory.
1923 LLVM_ABI bool doesNotAccessMemory() const;
1925
1926 /// Determine if the call does not access or only reads memory.
1927 LLVM_ABI bool onlyReadsMemory() const;
1929
1930 /// Determine if the call does not access or only writes memory.
1931 LLVM_ABI bool onlyWritesMemory() const;
1933
1934 /// Determine if the call can access memmory only using pointers based
1935 /// on its arguments.
1936 LLVM_ABI bool onlyAccessesArgMemory() const;
1938
1939 /// Determine if the function may only access memory that is
1940 /// inaccessible from the IR.
1943
1944 /// Determine if the function may only access memory that is
1945 /// either inaccessible from the IR or pointed to by its arguments.
1948
1949 /// Determine if the call cannot return.
1950 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1951 void setDoesNotReturn() { addFnAttr(Attribute::NoReturn); }
1952
1953 /// Determine if the call should not perform indirect branch tracking.
1954 bool doesNoCfCheck() const { return hasFnAttr(Attribute::NoCfCheck); }
1955
1956 /// Determine if the call cannot unwind.
1957 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1958 void setDoesNotThrow() { addFnAttr(Attribute::NoUnwind); }
1959
1960 /// Determine if the invoke cannot be duplicated.
1961 bool cannotDuplicate() const { return hasFnAttr(Attribute::NoDuplicate); }
1962 void setCannotDuplicate() { addFnAttr(Attribute::NoDuplicate); }
1963
1964 /// Determine if the call cannot be tail merged.
1965 bool cannotMerge() const { return hasFnAttr(Attribute::NoMerge); }
1966 void setCannotMerge() { addFnAttr(Attribute::NoMerge); }
1967
1968 /// Determine if the invoke is convergent
1969 bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
1970 void setConvergent() { addFnAttr(Attribute::Convergent); }
1971 void setNotConvergent() { removeFnAttr(Attribute::Convergent); }
1972
1973 /// Determine if the call returns a structure through first
1974 /// pointer argument.
1975 bool hasStructRetAttr() const {
1976 if (arg_empty())
1977 return false;
1978
1979 // Be friendly and also check the callee.
1980 return paramHasAttr(0, Attribute::StructRet);
1981 }
1982
1983 /// Determine if any call argument is an aggregate passed by value.
1984 bool hasByValArgument() const {
1985 return Attrs.hasAttrSomewhere(Attribute::ByVal);
1986 }
1987
1988 ///@}
1989 // End of attribute API.
1990
1991 /// \name Operand Bundle API
1992 ///
1993 /// This group of methods provides the API to access and manipulate operand
1994 /// bundles on this call.
1995 /// @{
1996
1997 /// Return the number of operand bundles associated with this User.
1998 unsigned getNumOperandBundles() const {
1999 return std::distance(bundle_op_info_begin(), bundle_op_info_end());
2000 }
2001
2002 /// Return true if this User has any operand bundles.
2003 bool hasOperandBundles() const { return getNumOperandBundles() != 0; }
2004
2005 /// Return the index of the first bundle operand in the Use array.
2007 assert(hasOperandBundles() && "Don't call otherwise!");
2008 return bundle_op_info_begin()->Begin;
2009 }
2010
2011 /// Return the index of the last bundle operand in the Use array.
2012 unsigned getBundleOperandsEndIndex() const {
2013 assert(hasOperandBundles() && "Don't call otherwise!");
2014 return bundle_op_info_end()[-1].End;
2015 }
2016
2017 /// Return true if the operand at index \p Idx is a bundle operand.
2018 bool isBundleOperand(unsigned Idx) const {
2019 return hasOperandBundles() && Idx >= getBundleOperandsStartIndex() &&
2021 }
2022
2023 /// Return true if the operand at index \p Idx is a bundle operand that has
2024 /// tag ID \p ID.
2025 bool isOperandBundleOfType(uint32_t ID, unsigned Idx) const {
2026 return isBundleOperand(Idx) &&
2028 }
2029
2030 /// Returns true if the use is a bundle operand.
2031 bool isBundleOperand(const Use *U) const {
2032 assert(this == U->getUser() &&
2033 "Only valid to query with a use of this instruction!");
2034 return hasOperandBundles() && isBundleOperand(U - op_begin());
2035 }
2037 return isBundleOperand(&UI.getUse());
2038 }
2039
2040 /// Return the total number operands (not operand bundles) used by
2041 /// every operand bundle in this OperandBundleUser.
2042 unsigned getNumTotalBundleOperands() const {
2043 if (!hasOperandBundles())
2044 return 0;
2045
2046 unsigned Begin = getBundleOperandsStartIndex();
2047 unsigned End = getBundleOperandsEndIndex();
2048
2049 assert(Begin <= End && "Should be!");
2050 return End - Begin;
2051 }
2052
2053 /// Return the operand bundle at a specific index.
2054 OperandBundleUse getOperandBundleAt(unsigned Index) const {
2055 assert(Index < getNumOperandBundles() && "Index out of bounds!");
2057 }
2058
2059 /// Return the number of operand bundles with the tag Name attached to
2060 /// this instruction.
2062 unsigned Count = 0;
2063 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
2064 if (getOperandBundleAt(i).getTagName() == Name)
2065 Count++;
2066
2067 return Count;
2068 }
2069
2070 /// Return the number of operand bundles with the tag ID attached to
2071 /// this instruction.
2073 unsigned Count = 0;
2074 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
2075 if (getOperandBundleAt(i).getTagID() == ID)
2076 Count++;
2077
2078 return Count;
2079 }
2080
2081 /// Return an operand bundle by name, if present.
2082 ///
2083 /// It is an error to call this for operand bundle types that may have
2084 /// multiple instances of them on the same instruction.
2085 std::optional<OperandBundleUse> getOperandBundle(StringRef Name) const {
2086 assert(countOperandBundlesOfType(Name) < 2 && "Precondition violated!");
2087
2088 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
2090 if (U.getTagName() == Name)
2091 return U;
2092 }
2093
2094 return std::nullopt;
2095 }
2096
2097 /// Return an operand bundle by tag ID, if present.
2098 ///
2099 /// It is an error to call this for operand bundle types that may have
2100 /// multiple instances of them on the same instruction.
2101 std::optional<OperandBundleUse> getOperandBundle(uint32_t ID) const {
2102 assert(countOperandBundlesOfType(ID) < 2 && "Precondition violated!");
2103
2104 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
2106 if (U.getTagID() == ID)
2107 return U;
2108 }
2109
2110 return std::nullopt;
2111 }
2112
2113 /// Return the list of operand bundles attached to this instruction as
2114 /// a vector of OperandBundleDefs.
2115 ///
2116 /// This function copies the OperandBundeUse instances associated with this
2117 /// OperandBundleUser to a vector of OperandBundleDefs. Note:
2118 /// OperandBundeUses and OperandBundleDefs are non-trivially *different*
2119 /// representations of operand bundles (see documentation above).
2120 LLVM_ABI void
2122
2123 /// Return the operand bundle for the operand at index OpIdx.
2124 ///
2125 /// It is an error to call this with an OpIdx that does not correspond to an
2126 /// bundle operand.
2130
2131 /// Return true if this operand bundle user has operand bundles that
2132 /// may read from the heap.
2134
2135 /// Return true if this operand bundle user has operand bundles that
2136 /// may write to the heap.
2138
2139 /// Return true if the bundle operand at index \p OpIdx has the
2140 /// attribute \p A.
2142 auto &BOI = getBundleOpInfoForOperand(OpIdx);
2143 auto OBU = operandBundleFromBundleOpInfo(BOI);
2144 return OBU.operandHasAttr(OpIdx - BOI.Begin, A);
2145 }
2146
2147 /// Return true if \p Other has the same sequence of operand bundle
2148 /// tags with the same number of operands on each one of them as this
2149 /// OperandBundleUser.
2151 if (getNumOperandBundles() != Other.getNumOperandBundles())
2152 return false;
2153
2154 return std::equal(bundle_op_info_begin(), bundle_op_info_end(),
2155 Other.bundle_op_info_begin());
2156 }
2157
2158 /// Return true if this operand bundle user contains operand bundles
2159 /// with tags other than those specified in \p IDs.
2161 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
2163 if (!is_contained(IDs, ID))
2164 return true;
2165 }
2166 return false;
2167 }
2168
2169 /// Used to keep track of an operand bundle. See the main comment on
2170 /// OperandBundleUser above.
2172 /// The operand bundle tag, interned by
2173 /// LLVMContextImpl::getOrInsertBundleTag.
2175
2176 /// The index in the Use& vector where operands for this operand
2177 /// bundle starts.
2179
2180 /// The index in the Use& vector where operands for this operand
2181 /// bundle ends.
2183
2184 bool operator==(const BundleOpInfo &Other) const {
2185 return Tag == Other.Tag && Begin == Other.Begin && End == Other.End;
2186 }
2187 };
2188
2189 /// Simple helper function to map a BundleOpInfo to an
2190 /// OperandBundleUse.
2193 const auto *begin = op_begin();
2194 ArrayRef<Use> Inputs(begin + BOI.Begin, begin + BOI.End);
2195 return OperandBundleUse(BOI.Tag, Inputs);
2196 }
2197
2200
2201 /// Return the start of the list of BundleOpInfo instances associated
2202 /// with this OperandBundleUser.
2203 ///
2204 /// OperandBundleUser uses the descriptor area co-allocated with the host User
2205 /// to store some meta information about which operands are "normal" operands,
2206 /// and which ones belong to some operand bundle.
2207 ///
2208 /// The layout of an operand bundle user is
2209 ///
2210 /// +-----------uint32_t End-------------------------------------+
2211 /// | |
2212 /// | +--------uint32_t Begin--------------------+ |
2213 /// | | | |
2214 /// ^ ^ v v
2215 /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
2216 /// | BOI0 | BOI1 | .. | DU | U0 | U1 | .. | BOI0_U0 | .. | BOI1_U0 | .. | Un
2217 /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
2218 /// v v ^ ^
2219 /// | | | |
2220 /// | +--------uint32_t Begin------------+ |
2221 /// | |
2222 /// +-----------uint32_t End-----------------------------+
2223 ///
2224 ///
2225 /// BOI0, BOI1 ... are descriptions of operand bundles in this User's use
2226 /// list. These descriptions are installed and managed by this class, and
2227 /// they're all instances of OperandBundleUser<T>::BundleOpInfo.
2228 ///
2229 /// DU is an additional descriptor installed by User's 'operator new' to keep
2230 /// track of the 'BOI0 ... BOIN' co-allocation. OperandBundleUser does not
2231 /// access or modify DU in any way, it's an implementation detail private to
2232 /// User.
2233 ///
2234 /// The regular Use& vector for the User starts at U0. The operand bundle
2235 /// uses are part of the Use& vector, just like normal uses. In the diagram
2236 /// above, the operand bundle uses start at BOI0_U0. Each instance of
2237 /// BundleOpInfo has information about a contiguous set of uses constituting
2238 /// an operand bundle, and the total set of operand bundle uses themselves
2239 /// form a contiguous set of uses (i.e. there are no gaps between uses
2240 /// corresponding to individual operand bundles).
2241 ///
2242 /// This class does not know the location of the set of operand bundle uses
2243 /// within the use list -- that is decided by the User using this class via
2244 /// the BeginIdx argument in populateBundleOperandInfos.
2245 ///
2246 /// Currently operand bundle users with hung-off operands are not supported.
2248 if (!hasDescriptor())
2249 return nullptr;
2250
2251 uint8_t *BytesBegin = getDescriptor().begin();
2252 return reinterpret_cast<bundle_op_iterator>(BytesBegin);
2253 }
2254
2255 /// Return the start of the list of BundleOpInfo instances associated
2256 /// with this OperandBundleUser.
2258 auto *NonConstThis = const_cast<CallBase *>(this);
2259 return NonConstThis->bundle_op_info_begin();
2260 }
2261
2262 /// Return the end of the list of BundleOpInfo instances associated
2263 /// with this OperandBundleUser.
2265 if (!hasDescriptor())
2266 return nullptr;
2267
2268 uint8_t *BytesEnd = getDescriptor().end();
2269 return reinterpret_cast<bundle_op_iterator>(BytesEnd);
2270 }
2271
2272 /// Return the end of the list of BundleOpInfo instances associated
2273 /// with this OperandBundleUser.
2275 auto *NonConstThis = const_cast<CallBase *>(this);
2276 return NonConstThis->bundle_op_info_end();
2277 }
2278
2279 /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
2283
2284 /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
2288
2289 /// Populate the BundleOpInfo instances and the Use& vector from \p
2290 /// Bundles. Return the op_iterator pointing to the Use& one past the last
2291 /// last bundle operand use.
2292 ///
2293 /// Each \p OperandBundleDef instance is tracked by a OperandBundleInfo
2294 /// instance allocated in this User's descriptor.
2296 ArrayRef<OperandBundleDef> Bundles, const unsigned BeginIndex);
2297
2298 /// Return true if the call has deopt state bundle.
2299 bool hasDeoptState() const {
2300 return getOperandBundle(LLVMContext::OB_deopt).has_value();
2301 }
2302
2303public:
2304 /// Return the BundleOpInfo for the operand at index OpIdx.
2305 ///
2306 /// It is an error to call this with an OpIdx that does not correspond to an
2307 /// bundle operand.
2308 LLVM_ABI BundleOpInfo &getBundleOpInfoForOperand(unsigned OpIdx);
2310 return const_cast<CallBase *>(this)->getBundleOpInfoForOperand(OpIdx);
2311 }
2312
2313protected:
2314 /// Return the total number of values used in \p Bundles.
2316 unsigned Total = 0;
2317 for (const auto &B : Bundles)
2318 Total += B.input_size();
2319 return Total;
2320 }
2321
2322 /// @}
2323 // End of operand bundle API.
2324
2325private:
2326 LLVM_ABI bool hasFnAttrOnCalledFunction(Attribute::AttrKind Kind) const;
2327 LLVM_ABI bool hasFnAttrOnCalledFunction(StringRef Kind) const;
2328
2329 template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const {
2330 if (Attrs.hasFnAttr(Kind))
2331 return true;
2332
2333 return hasFnAttrOnCalledFunction(Kind);
2334 }
2335 template <typename AK> Attribute getFnAttrOnCalledFunction(AK Kind) const;
2336 template <typename AK>
2337 Attribute getParamAttrOnCalledFunction(unsigned ArgNo, AK Kind) const;
2338
2339 /// Determine whether the return value has the given attribute. Supports
2340 /// Attribute::AttrKind and StringRef as \p AttrKind types.
2341 template <typename AttrKind> bool hasRetAttrImpl(AttrKind Kind) const {
2342 if (Attrs.hasRetAttr(Kind))
2343 return true;
2344
2345 // Look at the callee, if available.
2346 if (const Function *F = getCalledFunction())
2347 return F->getAttributes().hasRetAttr(Kind);
2348 return false;
2349 }
2350};
2351
2352template <>
2353struct OperandTraits<CallBase> : public VariadicOperandTraits<CallBase> {};
2354
2356
2357//===----------------------------------------------------------------------===//
2358// FuncletPadInst Class
2359//===----------------------------------------------------------------------===//
2360class FuncletPadInst : public Instruction {
2361private:
2362 FuncletPadInst(const FuncletPadInst &CPI, AllocInfo AllocInfo);
2363
2364 LLVM_ABI explicit FuncletPadInst(Instruction::FuncletPadOps Op,
2365 Value *ParentPad, ArrayRef<Value *> Args,
2366 AllocInfo AllocInfo, const Twine &NameStr,
2367 InsertPosition InsertBefore);
2368
2369 void init(Value *ParentPad, ArrayRef<Value *> Args, const Twine &NameStr);
2370
2371protected:
2372 // Note: Instruction needs to be a friend here to call cloneImpl.
2373 friend class Instruction;
2374 friend class CatchPadInst;
2375 friend class CleanupPadInst;
2376
2377 LLVM_ABI FuncletPadInst *cloneImpl() const;
2378
2379public:
2380 /// Provide fast operand accessors
2382
2383 /// arg_size - Return the number of funcletpad arguments.
2384 ///
2385 unsigned arg_size() const { return getNumOperands() - 1; }
2386
2387 /// Convenience accessors
2388
2389 /// Return the outer EH-pad this funclet is nested within.
2390 ///
2391 /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
2392 /// is a CatchPadInst.
2393 Value *getParentPad() const { return Op<-1>(); }
2394 void setParentPad(Value *ParentPad) {
2395 assert(ParentPad);
2396 Op<-1>() = ParentPad;
2397 }
2398
2399 /// getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
2400 ///
2401 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2402 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2403
2404 /// arg_operands - iteration adapter for range-for loops.
2406
2407 /// arg_operands - iteration adapter for range-for loops.
2409 return const_op_range(op_begin(), op_end() - 1);
2410 }
2411
2412 // Methods for support type inquiry through isa, cast, and dyn_cast:
2413 static bool classof(const Instruction *I) { return I->isFuncletPad(); }
2414 static bool classof(const Value *V) {
2416 }
2417};
2418
2419template <>
2421 : public VariadicOperandTraits<FuncletPadInst> {};
2422
2424
2425} // end namespace llvm
2426
2427#endif // LLVM_IR_INSTRTYPES_H
OperandBundleDefT< Value * > OperandBundleDef
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
constexpr LLT S1
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
@ RetAttr
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
#define op(i)
#define DEFINE_HELPERS(OPC, NUWNSWEXACT)
Definition InstrTypes.h:330
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
MachineInstr unsigned OpIdx
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
#define P(N)
This file contains some templates that are useful if you are working with the STL at all.
Provides some synthesis utilities to produce sequences of values.
Value * RHS
Value * LHS
BinaryOperator * Mul
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:407
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:124
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:261
static BinaryOperator * CreateFAddFMF(Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="")
Definition InstrTypes.h:236
static LLVM_ABI BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition InstrTypes.h:268
BinaryOps getOpcode() const
Definition InstrTypes.h:374
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition InstrTypes.h:279
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const Value *V)
Definition InstrTypes.h:389
static BinaryOperator * CreateFRemFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition InstrTypes.h:273
static BinaryOperator * CreateWithFMF(BinaryOps Opc, Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Definition InstrTypes.h:227
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition InstrTypes.h:309
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition InstrTypes.h:263
LLVM_ABI bool swapOperands()
Exchange the two operands to this instruction.
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, InsertPosition InsertBefore)
Definition InstrTypes.h:316
static LLVM_ABI BinaryOperator * CreateNot(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition InstrTypes.h:181
static BinaryOperator * CreateFSubFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition InstrTypes.h:258
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition InstrTypes.h:294
static BinaryOperator * CreateFAddFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Definition InstrTypes.h:253
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="")
Definition InstrTypes.h:244
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="")
Definition InstrTypes.h:248
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, InsertPosition InsertBefore)
Definition InstrTypes.h:301
static BinaryOperator * CreateFSubFMF(Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="")
Definition InstrTypes.h:240
static BinaryOperator * CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition InstrTypes.h:424
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Value *CopyO, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Definition InstrTypes.h:219
LLVM_ABI BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty, const Twine &Name, InsertPosition InsertBefore)
static LLVM_ABI BinaryOperator * CreateNSWNeg(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
LLVM_ABI BinaryOperator * cloneImpl() const
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, InsertPosition InsertBefore)
Definition InstrTypes.h:286
static bool classof(const Instruction *I)
Definition InstrTypes.h:386
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
MaybeAlign getParamStackAlign(unsigned ArgNo) const
void setCalledFunction(FunctionType *FTy, Value *Fn)
Sets the function called, including updating to the specified function type.
LLVM_ABI FPClassTest getParamNoFPClass(unsigned i) const
Extract a test mask for disallowed floating-point value classes for the parameter.
bool isInlineAsm() const
Check if this call is an inline asm statement.
void addFnAttr(Attribute Attr)
Adds the attribute to the function.
bool hasDescriptor() const
LLVM_ABI BundleOpInfo & getBundleOpInfoForOperand(unsigned OpIdx)
Return the BundleOpInfo for the operand at index OpIdx.
Attribute getRetAttr(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind for the return value.
void setCallingConv(CallingConv::ID CC)
void setDoesNotReturn()
LLVM_ABI FPClassTest getRetNoFPClass() const
Extract a test mask for disallowed floating-point value classes for the return value.
bool cannotMerge() const
Determine if the call cannot be tail merged.
unsigned getBundleOperandsEndIndex() const
Return the index of the last bundle operand in the Use array.
bundle_op_iterator bundle_op_info_begin()
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
LLVM_ABI bool paramHasNonNullAttr(unsigned ArgNo, bool AllowUndefOrPoison) const
Return true if this argument has the nonnull attribute on either the CallBase instruction or the call...
LLVM_ABI MemoryEffects getMemoryEffects() const
void setDoesNotThrow()
void addRangeRetAttr(const ConstantRange &CR)
adds the range attribute to the list of attributes.
bool arg_empty() const
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
void removeParamAttrs(unsigned ArgNo, const AttributeMask &AttrsToRemove)
Removes the attributes from the given argument.
bool hasByValArgument() const
Determine if any call argument is an aggregate passed by value.
LLVM_ABI bool doesNotAccessMemory() const
Determine if the call does not access memory.
MaybeAlign getRetAlign() const
Extract the alignment of the return value.
LLVM_ABI void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Type * getParamByRefType(unsigned ArgNo) const
Extract the byref type for a call or parameter.
LLVM_ABI void setOnlyAccessesArgMemory()
iterator_range< const_bundle_op_iterator > bundle_op_infos() const
Return the range [bundle_op_info_begin, bundle_op_info_end).
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
OperandBundleUse operandBundleFromBundleOpInfo(const BundleOpInfo &BOI) const
Simple helper function to map a BundleOpInfo to an OperandBundleUse.
bool isPassingUndefUB(unsigned ArgNo) const
Determine whether passing undef to this argument is undefined behavior.
bool hasArgument(const Value *V) const
Returns true if this CallSite passes the given Value* as an argument to the called function.
Type * getParamPreallocatedType(unsigned ArgNo) const
Extract the preallocated type for a call or parameter.
LLVM_ABI void setOnlyAccessesInaccessibleMemOrArgMem()
bool data_operands_empty() const
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
bool isOperandBundleOfType(uint32_t ID, unsigned Idx) const
Return true if the operand at index Idx is a bundle operand that has tag ID ID.
void addAttributeAtIndex(unsigned i, Attribute Attr)
adds the attribute to the list of attributes.
Bitfield::Element< CallingConv::ID, CallInstReservedField::NextBit, 10, CallingConv::MaxID > CallingConvField
unsigned getDataOperandNo(const Use *U) const
Given a use for a data operand, get the data operand number that corresponds to it.
Bitfield::Element< unsigned, 0, 2 > CallInstReservedField
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
Type * getParamStructRetType(unsigned ArgNo) const
Extract the sret type for a call or parameter.
Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const
Get the attribute of a given kind from a given arg.
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Type * getParamInAllocaType(unsigned ArgNo) const
Extract the inalloca type for a call or parameter.
bool doesNotAccessMemory(unsigned OpNo) const
void removeRetAttrs(const AttributeMask &AttrsToRemove)
Removes the attributes from the return value.
LLVM_ABI void setDoesNotAccessMemory()
bool isInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed in an alloca.
Use & getArgOperandUse(unsigned i)
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
bool isStrictFP() const
Determine if the call requires strict floating point semantics.
User::op_iterator data_operands_begin()
data_operands_begin/data_operands_end - Return iterators iterating over the call / invoke argument li...
bool cannotDuplicate() const
Determine if the invoke cannot be duplicated.
AttributeSet getParamAttributes(unsigned ArgNo) const
Return the param attributes for this call.
bool hasRetAttr(Attribute::AttrKind Kind) const
Determine whether the return value has the given attribute.
User::const_op_iterator data_operands_end() const
LLVM_ABI bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
uint64_t getParamDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
void removeAttributeAtIndex(unsigned i, StringRef Kind)
removes the attribute from the list of attributes.
unsigned getDataOperandNo(Value::const_user_iterator UI) const
Given a value use iterator, return the data operand corresponding to it.
CallingConv::ID getCallingConv() const
bundle_op_iterator bundle_op_info_end()
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
LLVM_ABI unsigned getNumSubclassExtraOperandsDynamic() const
Get the number of extra operands for instructions that don't have a fixed number of extra operands.
void addParamAttr(unsigned ArgNo, Attribute Attr)
Adds the attribute to the indicated argument.
BundleOpInfo * bundle_op_iterator
unsigned getNumSubclassExtraOperands() const
bool doesNoCfCheck() const
Determine if the call should not perform indirect branch tracking.
bool hasFnAttr(StringRef Kind) const
Determine whether this call has the given attribute.
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
bool hasIdenticalOperandBundleSchema(const CallBase &Other) const
Return true if Other has the same sequence of operand bundle tags with the same number of operands on...
User::const_op_iterator arg_begin() const
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Get the attribute of a given kind from a given arg.
bool hasRetAttr(StringRef Kind) const
Determine whether the return value has the given attribute.
static bool classof(const Instruction *I)
bool isDataOperand(Value::const_user_iterator UI) const
Use & getCalledOperandUse()
LLVM_ABI bool isIndirectCall() const
Return true if the callsite is an indirect call.
bool isNoInline() const
Return true if the call should not be inlined.
bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const
Return true if the data operand at index i has the attribute A.
static constexpr int CalledOperandOpEndIdx
The last operand is the called operand.
LLVM_ABI bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
bool isBundleOperand(const Use *U) const
Returns true if the use is a bundle operand.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
iterator_range< bundle_op_iterator > bundle_op_infos()
Return the range [bundle_op_info_begin, bundle_op_info_end).
bool onlyWritesMemory(unsigned OpNo) const
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
LLVM_ABI void setOnlyReadsMemory()
void removeFnAttrs(const AttributeMask &AttrsToRemove)
Removes the attributes from the function.
iterator_range< User::op_iterator > data_ops()
const_bundle_op_iterator bundle_op_info_begin() const
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
void setCannotMerge()
static LLVM_ABI CallBase * addOperandBundle(CallBase *CB, uint32_t ID, OperandBundleDef OB, InsertPosition InsertPt=nullptr)
Create a clone of CB with operand bundle OB added.
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand's Use.
iterator_range< User::const_op_iterator > args() const
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
unsigned getBundleOperandsStartIndex() const
Return the index of the first bundle operand in the Use array.
LLVM_ABI bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
LLVM_ABI CaptureInfo getCaptureInfo(unsigned OpNo) const
Return which pointer components this operand may capture.
AttributeSet getRetAttributes() const
Return the return attributes for this call.
Attribute getFnAttr(Attribute::AttrKind Kind) const
Get the attribute of a given kind for the function.
User::op_iterator data_operands_end()
bool onlyReadsMemory(unsigned OpNo) const
void setNotConvergent()
LLVM_ABI bool hasArgumentWithAdditionalReturnCaptureComponents() const
Returns whether the call has an argument that has an attribute like captures(ret: address,...
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter.
bool isCallee(const Use *U) const
Determine whether this Use is the callee operand's Use.
CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
const BundleOpInfo & getBundleOpInfoForOperand(unsigned OpIdx) const
Value * getCalledOperand() const
void setCalledFunction(FunctionCallee Fn)
Sets the function called, including updating the function type.
const Use & getCalledOperandUse() const
bool isArgOperand(Value::const_user_iterator UI) const
LLVM_ABI void setOnlyWritesMemory()
LLVM_ABI op_iterator populateBundleOperandInfos(ArrayRef< OperandBundleDef > Bundles, const unsigned BeginIndex)
Populate the BundleOpInfo instances and the Use& vector from Bundles.
void removeRetAttr(Attribute::AttrKind Kind)
Removes the attribute from the return value.
AttributeList Attrs
parameter attributes for callable
void addDereferenceableRetAttr(uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
unsigned getArgOperandNo(Value::const_user_iterator UI) const
Given a value use iterator, return the arg operand number corresponding to it.
void setAttributes(AttributeList A)
Set the attributes for this call.
Attribute getFnAttr(StringRef Kind) const
Get the attribute of a given kind for the function.
void addAttributeAtIndex(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
unsigned countOperandBundlesOfType(uint32_t ID) const
Return the number of operand bundles with the tag ID attached to this instruction.
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
bool hasOperandBundlesOtherThan(ArrayRef< uint32_t > IDs) const
Return true if this operand bundle user contains operand bundles with tags other than those specified...
bool returnDoesNotAlias() const
Determine if the return value is marked with NoAlias attribute.
OperandBundleUse getOperandBundleForOperand(unsigned OpIdx) const
Return the operand bundle for the operand at index OpIdx.
LLVM_ABI std::optional< ConstantRange > getRange() const
If this return value has a range attribute, return the value range of the argument.
bool doesNotThrow() const
Determine if the call cannot unwind.
void addRetAttr(Attribute::AttrKind Kind)
Adds the attribute to the return value.
Type * getParamElementType(unsigned ArgNo) const
Extract the elementtype type for a parameter.
LLVM_ABI bool isReturnNonNull() const
Return true if the return value is known to be not null.
Value * getArgOperand(unsigned i) const
FunctionType * FTy
bool hasStructRetAttr() const
Determine if the call returns a structure through first pointer argument.
uint64_t getRetDereferenceableBytes() const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
void setCannotDuplicate()
User::const_op_iterator data_operands_begin() const
void mutateFunctionType(FunctionType *FTy)
void addRetAttrs(const AttrBuilder &B)
Adds attributes to the return value.
uint64_t getParamDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a parameter (0=unknown).
void setArgOperand(unsigned i, Value *v)
Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const
Get the attribute of a given kind at a position.
bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const
Return true if the bundle operand at index OpIdx has the attribute A.
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
bool isBundleOperand(unsigned Idx) const
Return true if the operand at index Idx is a bundle operand.
bool isConvergent() const
Determine if the invoke is convergent.
FunctionType * getFunctionType() const
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
void setIsNoInline()
static unsigned CountBundleInputs(ArrayRef< OperandBundleDef > Bundles)
Return the total number of values used in Bundles.
LLVM_ABI Value * getArgOperandWithAttribute(Attribute::AttrKind Kind) const
If one of the arguments has the specified attribute, returns its operand value.
Value * getReturnedArgOperand() const
If one of the arguments has the 'returned' attribute, returns its operand value.
LLVM_ABI void setOnlyAccessesInaccessibleMemory()
static LLVM_ABI CallBase * Create(CallBase *CB, ArrayRef< OperandBundleDef > Bundles, InsertPosition InsertPt=nullptr)
Create a clone of CB with a different set of operand bundles and insert it before InsertPt.
LLVM_ABI bool onlyWritesMemory() const
Determine if the call does not access or only writes memory.
unsigned data_operands_size() const
void removeFnAttr(Attribute::AttrKind Kind)
Removes the attribute from the function.
uint64_t getRetDereferenceableOrNullBytes() const
Extract the number of dereferenceable_or_null bytes for a call (0=unknown).
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned getArgOperandNo(const Use *U) const
Given a use for a arg operand, get the arg operand number that corresponds to it.
bool isBundleOperand(Value::const_user_iterator UI) const
LLVM_ABI bool hasClobberingOperandBundles() const
Return true if this operand bundle user has operand bundles that may write to the heap.
static bool classof(const Value *V)
Value * getConvergenceControlToken() const
Return the convergence control token for this call, if it exists.
void setCalledOperand(Value *V)
void addParamAttrs(unsigned ArgNo, const AttrBuilder &B)
Adds attributes to the indicated argument.
static LLVM_ABI CallBase * removeOperandBundle(CallBase *CB, uint32_t ID, InsertPosition InsertPt=nullptr)
Create a clone of CB with operand bundle ID removed.
bool doesNotReturn() const
Determine if the call cannot return.
LLVM_ABI bool hasReadingOperandBundles() const
Return true if this operand bundle user has operand bundles that may read from the heap.
void removeFnAttr(StringRef Kind)
Removes the attribute from the function.
void setConvergent()
LLVM_ABI bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
unsigned arg_size() const
void addDereferenceableParamAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
AttributeList getAttributes() const
Return the attributes for this call.
std::optional< OperandBundleUse > getOperandBundle(uint32_t ID) const
Return an operand bundle by tag ID, if present.
void addRetAttr(Attribute Attr)
Adds the attribute to the return value.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
iterator_range< User::const_op_iterator > data_ops() const
Instruction(const Instruction &)=delete
bool isArgOperand(const Use *U) const
bool isDataOperand(const Use *U) const
bool hasDeoptState() const
Return true if the call has deopt state bundle.
LLVM_ABI void setMemoryEffects(MemoryEffects ME)
bool hasOperandBundles() const
Return true if this User has any operand bundles.
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
const_bundle_op_iterator bundle_op_info_end() const
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
bool isPassPointeeByValueArgument(unsigned ArgNo) const
Determine whether this argument is passed by value, in an alloca, or is preallocated.
LLVM_ABI bool isTailCall() const
Tests if this call site is marked as a tail call.
const Function * getCaller() const
void removeParamAttr(unsigned ArgNo, StringRef Kind)
Removes the attribute from the given argument.
User::const_op_iterator arg_end() const
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
bool tryIntersectAttributes(const CallBase *Other)
Try to intersect the attributes from 'this' CallBase and the 'Other' CallBase.
const BundleOpInfo * const_bundle_op_iterator
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const
Get the attribute of a given kind at a position.
Represents which components of the pointer may be captured in which location.
Definition ModRef.h:414
This is the base class for all instructions that perform data casts.
Definition InstrTypes.h:448
Type * getSrcTy() const
Return the source type, as a convenience.
Definition InstrTypes.h:615
static LLVM_ABI Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
static LLVM_ABI CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast or an AddrSpaceCast cast instruction.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition InstrTypes.h:610
static LLVM_ABI unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, const DataLayout *DL)
Determine how a pair of casts can be eliminated, if they can be at all.
static bool classof(const Value *V)
Definition InstrTypes.h:633
static LLVM_ABI CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static LLVM_ABI CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics for subclasses.
Definition InstrTypes.h:451
static LLVM_ABI bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op.
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
Definition InstrTypes.h:625
static LLVM_ABI bool isBitCastable(Type *SrcTy, Type *DestTy)
Check whether a bitcast between these types is valid.
static LLVM_ABI CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
static LLVM_ABI CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
static LLVM_ABI CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
static LLVM_ABI bool isNoopCast(Instruction::CastOps Opcode, Type *SrcTy, Type *DstTy, const DataLayout &DL)
A no-op cast is one that can be effected without changing any bits.
static LLVM_ABI CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
LLVM_ABI bool isIntegerCast() const
There are several places where we need to know if a cast instruction only deals with integer source a...
Type * getDestTy() const
Return the destination type, as a convenience.
Definition InstrTypes.h:617
static LLVM_ABI CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a SExt or BitCast cast instruction.
static LLVM_ABI bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition InstrTypes.h:630
This class is the base class for the comparison instructions.
Definition InstrTypes.h:664
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition InstrTypes.h:986
Predicate getStrictPredicate() const
For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.
Definition InstrTypes.h:858
bool isEquality() const
Determine if this is an equals/not equals predicate.
Definition InstrTypes.h:915
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition InstrTypes.h:768
bool isFalseWhenEqual() const
This is just a convenience.
Definition InstrTypes.h:948
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition InstrTypes.h:977
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:679
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:693
@ ICMP_SLT
signed less than
Definition InstrTypes.h:705
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:706
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:682
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:691
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:680
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:681
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:700
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:699
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:703
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:690
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:684
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:687
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:701
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:688
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:683
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:685
@ ICMP_NE
not equal
Definition InstrTypes.h:698
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:704
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:692
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:702
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:689
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:678
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:686
static auto ICmpPredicates()
Returns the sequence of all ICmp predicates.
Definition InstrTypes.h:722
LLVM_ABI bool isEquivalence(bool Invert=false) const
Determine if one operand of this compare can always be replaced by the other operand,...
bool isSigned() const
Definition InstrTypes.h:930
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition InstrTypes.h:827
static auto FCmpPredicates()
Returns the sequence of all FCmp predicates.
Definition InstrTypes.h:715
Bitfield::Element< Predicate, 0, 6, LAST_ICMP_PREDICATE > PredicateField
Definition InstrTypes.h:711
bool isTrueWhenEqual() const
This is just a convenience.
Definition InstrTypes.h:942
static LLVM_ABI CmpInst * Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
Predicate getOrderedPredicate() const
Definition InstrTypes.h:800
static bool isFPPredicate(Predicate P)
Definition InstrTypes.h:770
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition InstrTypes.h:871
static LLVM_ABI CmpInst * CreateWithCopiedFlags(OtherOps Op, Predicate Pred, Value *S1, Value *S2, const Instruction *FlagsSource, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate, the two operands and the instructio...
bool isNonStrictPredicate() const
Definition InstrTypes.h:852
bool isFPPredicate() const
Definition InstrTypes.h:782
LLVM_ABI void swapOperands()
This is just a convenience that dispatches to the subclasses.
static bool isRelational(Predicate P)
Return true if the predicate is relational (not EQ or NE).
Definition InstrTypes.h:923
static bool isUnsigned(Predicate Pred)
Definition InstrTypes.h:954
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Definition InstrTypes.h:789
static LLVM_ABI StringRef getPredicateName(Predicate P)
Predicate getPredicate() const
Return the predicate for this instruction.
Definition InstrTypes.h:765
bool isStrictPredicate() const
Definition InstrTypes.h:843
static LLVM_ABI bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
Predicate getFlippedStrictnessPredicate() const
For predicate of kind "is X or equal to 0" returns the predicate "is X".
Definition InstrTypes.h:893
static Predicate getOrderedPredicate(Predicate Pred)
Returns the ordered variant of a floating point compare.
Definition InstrTypes.h:796
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide more efficient getOperand methods.
static bool isSigned(Predicate Pred)
Definition InstrTypes.h:960
bool isIntPredicate() const
Definition InstrTypes.h:783
static bool isIntPredicate(Predicate P)
Definition InstrTypes.h:776
Predicate getUnorderedPredicate() const
Definition InstrTypes.h:811
static LLVM_ABI bool isOrdered(Predicate predicate)
Determine if the predicate is an ordered operation.
LLVM_ABI CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, Value *RHS, const Twine &Name="", InsertPosition InsertBefore=nullptr, Instruction *FlagsSource=nullptr)
static bool classof(const Value *V)
Definition InstrTypes.h:981
bool isUnsigned() const
Definition InstrTypes.h:936
static Predicate getUnorderedPredicate(Predicate Pred)
Returns the unordered variant of a floating point compare.
Definition InstrTypes.h:807
OtherOps getOpcode() const
Get the opcode casted to the right type.
Definition InstrTypes.h:760
LLVM_ABI bool isCommutative() const
This is just a convenience that dispatches to the subclasses.
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
Definition InstrTypes.h:926
This class represents a range of values.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
This provides a helper for copying FMF from an instruction or setting specified flags.
Definition IRBuilder.h:93
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
static bool classof(const Instruction *I)
op_range arg_operands()
arg_operands - iteration adapter for range-for loops.
void setArgOperand(unsigned i, Value *v)
unsigned arg_size() const
arg_size - Return the number of funcletpad arguments.
static bool classof(const Value *V)
void setParentPad(Value *ParentPad)
friend class CatchPadInst
friend class Instruction
Iterator for Instructions in a `BasicBlock.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
Value * getParentPad() const
Convenience accessors.
LLVM_ABI FuncletPadInst * cloneImpl() const
friend class CleanupPadInst
const_op_range arg_operands() const
arg_operands - iteration adapter for range-for loops.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
FunctionType * getFunctionType()
Class to represent function types.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition Function.h:211
BitfieldElement::Type getSubclassData() const
LLVM_ABI void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
LLVM_ABI void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Instruction(const Instruction &)=delete
void setSubclassData(typename BitfieldElement::Type Value)
A container for an operand bundle being viewed as a set of values rather than a set of uses.
size_t input_size() const
input_iterator input_end() const
OperandBundleDefT(const OperandBundleUse &OBU)
ArrayRef< InputTy > inputs() const
typename std::vector< Value * >::const_iterator input_iterator
OperandBundleDefT(std::string Tag, std::vector< InputTy > Inputs)
input_iterator input_begin() const
StringRef getTag() const
OperandBundleDefT(std::string Tag, ArrayRef< InputTy > Inputs)
An or instruction, which can be marked as "disjoint", indicating that the inputs don't have a 1 in th...
Definition InstrTypes.h:404
static bool classof(const Value *V)
Definition InstrTypes.h:419
static bool classof(const Instruction *I)
Definition InstrTypes.h:415
Instruction that can have a nneg flag (zext/uitofp).
Definition InstrTypes.h:639
static bool classof(const Instruction *I)
Definition InstrTypes.h:643
static bool classof(const Value *V)
Definition InstrTypes.h:653
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:310
static bool classof(const Instruction *I)
Definition InstrTypes.h:77
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const Value *V)
Definition InstrTypes.h:85
UnaryInstruction(Type *Ty, unsigned iType, Value *V, InsertPosition InsertBefore=nullptr)
Definition InstrTypes.h:62
static LLVM_ABI UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
LLVM_ABI UnaryOperator(UnaryOps iType, Value *S, Type *Ty, const Twine &Name, InsertPosition InsertBefore)
LLVM_ABI UnaryOperator * cloneImpl() const
static UnaryOperator * CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Definition InstrTypes.h:139
UnaryOps getOpcode() const
Definition InstrTypes.h:154
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition InstrTypes.h:109
static UnaryOperator * CreateFNegFMF(Value *Op, Instruction *FMFSource, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Definition InstrTypes.h:147
static bool classof(const Value *V)
Definition InstrTypes.h:162
static bool classof(const Instruction *I)
Definition InstrTypes.h:159
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
iterator_range< const_op_iterator > const_op_range
Definition User.h:257
Use * op_iterator
Definition User.h:254
op_iterator op_begin()
Definition User.h:259
const Use & getOperandUse(unsigned i) const
Definition User.h:220
LLVM_ABI ArrayRef< const uint8_t > getDescriptor() const
Returns the descriptor co-allocated with this User instance.
Definition User.cpp:103
void setOperand(unsigned i, Value *Val)
Definition User.h:212
const Use * const_op_iterator
Definition User.h:255
iterator_range< op_iterator > op_range
Definition User.h:256
Value * getOperand(unsigned i) const
Definition User.h:207
unsigned getNumOperands() const
Definition User.h:229
op_iterator op_end()
Definition User.h:261
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
user_iterator_impl< const User > const_user_iterator
Definition Value.h:393
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition Value.h:85
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition Value.cpp:397
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:259
void setValueSubclassData(unsigned short D)
Definition Value.h:892
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
Definition Value.h:840
unsigned HasDescriptor
Definition Value.h:116
Base class of all SIMD vector types.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ MaxID
The highest possible ID. Must be some 2^k - 1.
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
auto enum_seq_inclusive(EnumT Begin, EnumT End)
Iterate over an enum type from Begin to End inclusive.
Definition Sequence.h:364
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2208
constexpr force_iteration_on_noniterable_enum_t force_iteration_on_noniterable_enum
Definition Sequence.h:109
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ Other
Any other memory.
Definition ModRef.h:68
OperandBundleDefT< Value * > OperandBundleDef
Definition AutoUpgrade.h:34
@ Or
Bitwise or logical OR of integers.
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
bool capturesNothing(CaptureComponents CC)
Definition ModRef.h:375
OperandBundleDefT< const Value * > ConstOperandBundleDef
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Describes an element of a Bitfield.
Definition Bitfields.h:176
static constexpr unsigned NextBit
Definition Bitfields.h:184
static constexpr bool areContiguous()
Definition Bitfields.h:233
Used to keep track of an operand bundle.
bool operator==(const BundleOpInfo &Other) const
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
uint32_t End
The index in the Use& vector where operands for this operand bundle ends.
uint32_t Begin
The index in the Use& vector where operands for this operand bundle starts.
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
A lightweight accessor for an operand bundle meant to be passed around by value.
bool isFuncletOperandBundle() const
Return true if this is a "funclet" operand bundle.
StringRef getTagName() const
Return the tag of this operand bundle as a string.
bool isDeoptOperandBundle() const
Return true if this is a "deopt" operand bundle.
OperandBundleUse(StringMapEntry< uint32_t > *Tag, ArrayRef< Use > Inputs)
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
ArrayRef< Use > Inputs
bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const
Return true if the operand at index Idx in this operand bundle has the attribute A.
bool isCFGuardTargetOperandBundle() const
Return true if this is a "cfguardtarget" operand bundle.
Compile-time customization of User operands.
Definition User.h:42
Information about how a User object was allocated, to be passed into the User constructor.
Definition User.h:79
Indicates this User has operands co-allocated.
Definition User.h:60
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...