LLVM  8.0.0svn
InstrTypes.h
Go to the documentation of this file.
1 //===- llvm/InstrTypes.h - Important Instruction subclasses -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines various meta classes of instructions that exist in the VM
11 // representation. Specific concrete subclasses of these may be found in the
12 // i*.h files...
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_INSTRTYPES_H
17 #define LLVM_IR_INSTRTYPES_H
18 
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/None.h"
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/STLExtras.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/ADT/Twine.h"
27 #include "llvm/IR/Attributes.h"
28 #include "llvm/IR/CallingConv.h"
29 #include "llvm/IR/Constants.h"
30 #include "llvm/IR/DerivedTypes.h"
31 #include "llvm/IR/Instruction.h"
32 #include "llvm/IR/LLVMContext.h"
33 #include "llvm/IR/OperandTraits.h"
34 #include "llvm/IR/Type.h"
35 #include "llvm/IR/User.h"
36 #include "llvm/IR/Value.h"
37 #include "llvm/Support/Casting.h"
39 #include <algorithm>
40 #include <cassert>
41 #include <cstddef>
42 #include <cstdint>
43 #include <iterator>
44 #include <string>
45 #include <vector>
46 
47 namespace llvm {
48 
49 //===----------------------------------------------------------------------===//
50 // UnaryInstruction Class
51 //===----------------------------------------------------------------------===//
52 
53 class UnaryInstruction : public Instruction {
54 protected:
55  UnaryInstruction(Type *Ty, unsigned iType, Value *V,
56  Instruction *IB = nullptr)
57  : Instruction(Ty, iType, &Op<0>(), 1, IB) {
58  Op<0>() = V;
59  }
60  UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
61  : Instruction(Ty, iType, &Op<0>(), 1, IAE) {
62  Op<0>() = V;
63  }
64 
65 public:
66  // allocate space for exactly one operand
67  void *operator new(size_t s) {
68  return User::operator new(s, 1);
69  }
70 
71  /// Transparently provide more efficient getOperand methods.
73 
74  // Methods for support type inquiry through isa, cast, and dyn_cast:
75  static bool classof(const Instruction *I) {
76  return I->getOpcode() == Instruction::Alloca ||
77  I->getOpcode() == Instruction::Load ||
78  I->getOpcode() == Instruction::VAArg ||
79  I->getOpcode() == Instruction::ExtractValue ||
80  (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
81  }
82  static bool classof(const Value *V) {
83  return isa<Instruction>(V) && classof(cast<Instruction>(V));
84  }
85 };
86 
87 template <>
89  public FixedNumOperandTraits<UnaryInstruction, 1> {
90 };
91 
93 
94 //===----------------------------------------------------------------------===//
95 // BinaryOperator Class
96 //===----------------------------------------------------------------------===//
97 
98 class BinaryOperator : public Instruction {
99  void AssertOK();
100 
101 protected:
102  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
103  const Twine &Name, Instruction *InsertBefore);
104  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
105  const Twine &Name, BasicBlock *InsertAtEnd);
106 
107  // Note: Instruction needs to be a friend here to call cloneImpl.
108  friend class Instruction;
109 
110  BinaryOperator *cloneImpl() const;
111 
112 public:
113  // allocate space for exactly two operands
114  void *operator new(size_t s) {
115  return User::operator new(s, 2);
116  }
117 
118  /// Transparently provide more efficient getOperand methods.
120 
121  /// Construct a binary instruction, given the opcode and the two
122  /// operands. Optionally (if InstBefore is specified) insert the instruction
123  /// into a BasicBlock right before the specified instruction. The specified
124  /// Instruction is allowed to be a dereferenced end iterator.
125  ///
126  static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
127  const Twine &Name = Twine(),
128  Instruction *InsertBefore = nullptr);
129 
130  /// Construct a binary instruction, given the opcode and the two
131  /// operands. Also automatically insert this instruction to the end of the
132  /// BasicBlock specified.
133  ///
134  static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
135  const Twine &Name, BasicBlock *InsertAtEnd);
136 
137  /// These methods just forward to Create, and are useful when you
138  /// statically know what type of instruction you're going to create. These
139  /// helpers just save some typing.
140 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
141  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
142  const Twine &Name = "") {\
143  return Create(Instruction::OPC, V1, V2, Name);\
144  }
145 #include "llvm/IR/Instruction.def"
146 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
147  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
148  const Twine &Name, BasicBlock *BB) {\
149  return Create(Instruction::OPC, V1, V2, Name, BB);\
150  }
151 #include "llvm/IR/Instruction.def"
152 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
153  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
154  const Twine &Name, Instruction *I) {\
155  return Create(Instruction::OPC, V1, V2, Name, I);\
156  }
157 #include "llvm/IR/Instruction.def"
158 
160  Value *V1, Value *V2,
161  BinaryOperator *CopyBO,
162  const Twine &Name = "") {
163  BinaryOperator *BO = Create(Opc, V1, V2, Name);
164  BO->copyIRFlags(CopyBO);
165  return BO;
166  }
167 
169  BinaryOperator *FMFSource,
170  const Twine &Name = "") {
171  return CreateWithCopiedFlags(Instruction::FAdd, V1, V2, FMFSource, Name);
172  }
174  BinaryOperator *FMFSource,
175  const Twine &Name = "") {
176  return CreateWithCopiedFlags(Instruction::FSub, V1, V2, FMFSource, Name);
177  }
179  BinaryOperator *FMFSource,
180  const Twine &Name = "") {
181  return CreateWithCopiedFlags(Instruction::FMul, V1, V2, FMFSource, Name);
182  }
184  BinaryOperator *FMFSource,
185  const Twine &Name = "") {
186  return CreateWithCopiedFlags(Instruction::FDiv, V1, V2, FMFSource, Name);
187  }
189  BinaryOperator *FMFSource,
190  const Twine &Name = "") {
191  return CreateWithCopiedFlags(Instruction::FRem, V1, V2, FMFSource, Name);
192  }
194  const Twine &Name = "") {
196  return CreateWithCopiedFlags(Instruction::FSub, Zero, Op, FMFSource);
197  }
198 
200  const Twine &Name = "") {
201  BinaryOperator *BO = Create(Opc, V1, V2, Name);
202  BO->setHasNoSignedWrap(true);
203  return BO;
204  }
206  const Twine &Name, BasicBlock *BB) {
207  BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
208  BO->setHasNoSignedWrap(true);
209  return BO;
210  }
212  const Twine &Name, Instruction *I) {
213  BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
214  BO->setHasNoSignedWrap(true);
215  return BO;
216  }
217 
219  const Twine &Name = "") {
220  BinaryOperator *BO = Create(Opc, V1, V2, Name);
221  BO->setHasNoUnsignedWrap(true);
222  return BO;
223  }
225  const Twine &Name, BasicBlock *BB) {
226  BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
227  BO->setHasNoUnsignedWrap(true);
228  return BO;
229  }
231  const Twine &Name, Instruction *I) {
232  BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
233  BO->setHasNoUnsignedWrap(true);
234  return BO;
235  }
236 
238  const Twine &Name = "") {
239  BinaryOperator *BO = Create(Opc, V1, V2, Name);
240  BO->setIsExact(true);
241  return BO;
242  }
244  const Twine &Name, BasicBlock *BB) {
245  BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
246  BO->setIsExact(true);
247  return BO;
248  }
250  const Twine &Name, Instruction *I) {
251  BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
252  BO->setIsExact(true);
253  return BO;
254  }
255 
256 #define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
257  static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \
258  const Twine &Name = "") { \
259  return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
260  } \
261  static BinaryOperator *Create##NUWNSWEXACT##OPC( \
262  Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \
263  return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \
264  } \
265  static BinaryOperator *Create##NUWNSWEXACT##OPC( \
266  Value *V1, Value *V2, const Twine &Name, Instruction *I) { \
267  return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, I); \
268  }
269 
270  DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
271  DEFINE_HELPERS(Add, NUW) // CreateNUWAdd
272  DEFINE_HELPERS(Sub, NSW) // CreateNSWSub
273  DEFINE_HELPERS(Sub, NUW) // CreateNUWSub
274  DEFINE_HELPERS(Mul, NSW) // CreateNSWMul
275  DEFINE_HELPERS(Mul, NUW) // CreateNUWMul
276  DEFINE_HELPERS(Shl, NSW) // CreateNSWShl
277  DEFINE_HELPERS(Shl, NUW) // CreateNUWShl
278 
279  DEFINE_HELPERS(SDiv, Exact) // CreateExactSDiv
280  DEFINE_HELPERS(UDiv, Exact) // CreateExactUDiv
281  DEFINE_HELPERS(AShr, Exact) // CreateExactAShr
282  DEFINE_HELPERS(LShr, Exact) // CreateExactLShr
283 
284 #undef DEFINE_HELPERS
285 
286  /// Helper functions to construct and inspect unary operations (NEG and NOT)
287  /// via binary operators SUB and XOR:
288  ///
289  /// Create the NEG and NOT instructions out of SUB and XOR instructions.
290  ///
291  static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
292  Instruction *InsertBefore = nullptr);
293  static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
294  BasicBlock *InsertAtEnd);
295  static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name = "",
296  Instruction *InsertBefore = nullptr);
297  static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
298  BasicBlock *InsertAtEnd);
299  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name = "",
300  Instruction *InsertBefore = nullptr);
301  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
302  BasicBlock *InsertAtEnd);
303  static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name = "",
304  Instruction *InsertBefore = nullptr);
305  static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name,
306  BasicBlock *InsertAtEnd);
307  static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
308  Instruction *InsertBefore = nullptr);
309  static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
310  BasicBlock *InsertAtEnd);
311 
313  return static_cast<BinaryOps>(Instruction::getOpcode());
314  }
315 
316  /// Exchange the two operands to this instruction.
317  /// This instruction is safe to use on any binary instruction and
318  /// does not modify the semantics of the instruction. If the instruction
319  /// cannot be reversed (ie, it's a Div), then return true.
320  ///
321  bool swapOperands();
322 
323  // Methods for support type inquiry through isa, cast, and dyn_cast:
324  static bool classof(const Instruction *I) {
325  return I->isBinaryOp();
326  }
327  static bool classof(const Value *V) {
328  return isa<Instruction>(V) && classof(cast<Instruction>(V));
329  }
330 };
331 
332 template <>
334  public FixedNumOperandTraits<BinaryOperator, 2> {
335 };
336 
338 
339 //===----------------------------------------------------------------------===//
340 // CastInst Class
341 //===----------------------------------------------------------------------===//
342 
343 /// This is the base class for all instructions that perform data
344 /// casts. It is simply provided so that instruction category testing
345 /// can be performed with code like:
346 ///
347 /// if (isa<CastInst>(Instr)) { ... }
348 /// Base class of casting instructions.
349 class CastInst : public UnaryInstruction {
350 protected:
351  /// Constructor with insert-before-instruction semantics for subclasses
352  CastInst(Type *Ty, unsigned iType, Value *S,
353  const Twine &NameStr = "", Instruction *InsertBefore = nullptr)
354  : UnaryInstruction(Ty, iType, S, InsertBefore) {
355  setName(NameStr);
356  }
357  /// Constructor with insert-at-end-of-block semantics for subclasses
358  CastInst(Type *Ty, unsigned iType, Value *S,
359  const Twine &NameStr, BasicBlock *InsertAtEnd)
360  : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
361  setName(NameStr);
362  }
363 
364 public:
365  /// Provides a way to construct any of the CastInst subclasses using an
366  /// opcode instead of the subclass's constructor. The opcode must be in the
367  /// CastOps category (Instruction::isCast(opcode) returns true). This
368  /// constructor has insert-before-instruction semantics to automatically
369  /// insert the new CastInst before InsertBefore (if it is non-null).
370  /// Construct any of the CastInst subclasses
371  static CastInst *Create(
372  Instruction::CastOps, ///< The opcode of the cast instruction
373  Value *S, ///< The value to be casted (operand 0)
374  Type *Ty, ///< The type to which cast should be made
375  const Twine &Name = "", ///< Name for the instruction
376  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
377  );
378  /// Provides a way to construct any of the CastInst subclasses using an
379  /// opcode instead of the subclass's constructor. The opcode must be in the
380  /// CastOps category. This constructor has insert-at-end-of-block semantics
381  /// to automatically insert the new CastInst at the end of InsertAtEnd (if
382  /// its non-null).
383  /// Construct any of the CastInst subclasses
384  static CastInst *Create(
385  Instruction::CastOps, ///< The opcode for the cast instruction
386  Value *S, ///< The value to be casted (operand 0)
387  Type *Ty, ///< The type to which operand is casted
388  const Twine &Name, ///< The name for the instruction
389  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
390  );
391 
392  /// Create a ZExt or BitCast cast instruction
393  static CastInst *CreateZExtOrBitCast(
394  Value *S, ///< The value to be casted (operand 0)
395  Type *Ty, ///< The type to which cast should be made
396  const Twine &Name = "", ///< Name for the instruction
397  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
398  );
399 
400  /// Create a ZExt or BitCast cast instruction
401  static CastInst *CreateZExtOrBitCast(
402  Value *S, ///< The value to be casted (operand 0)
403  Type *Ty, ///< The type to which operand is casted
404  const Twine &Name, ///< The name for the instruction
405  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
406  );
407 
408  /// Create a SExt or BitCast cast instruction
409  static CastInst *CreateSExtOrBitCast(
410  Value *S, ///< The value to be casted (operand 0)
411  Type *Ty, ///< The type to which cast should be made
412  const Twine &Name = "", ///< Name for the instruction
413  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
414  );
415 
416  /// Create a SExt or BitCast cast instruction
417  static CastInst *CreateSExtOrBitCast(
418  Value *S, ///< The value to be casted (operand 0)
419  Type *Ty, ///< The type to which operand is casted
420  const Twine &Name, ///< The name for the instruction
421  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
422  );
423 
424  /// Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
425  static CastInst *CreatePointerCast(
426  Value *S, ///< The pointer value to be casted (operand 0)
427  Type *Ty, ///< The type to which operand is casted
428  const Twine &Name, ///< The name for the instruction
429  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
430  );
431 
432  /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
433  static CastInst *CreatePointerCast(
434  Value *S, ///< The pointer value to be casted (operand 0)
435  Type *Ty, ///< The type to which cast should be made
436  const Twine &Name = "", ///< Name for the instruction
437  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
438  );
439 
440  /// Create a BitCast or an AddrSpaceCast cast instruction.
441  static CastInst *CreatePointerBitCastOrAddrSpaceCast(
442  Value *S, ///< The pointer value to be casted (operand 0)
443  Type *Ty, ///< The type to which operand is casted
444  const Twine &Name, ///< The name for the instruction
445  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
446  );
447 
448  /// Create a BitCast or an AddrSpaceCast cast instruction.
449  static CastInst *CreatePointerBitCastOrAddrSpaceCast(
450  Value *S, ///< The pointer value to be casted (operand 0)
451  Type *Ty, ///< The type to which cast should be made
452  const Twine &Name = "", ///< Name for the instruction
453  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
454  );
455 
456  /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
457  ///
458  /// If the value is a pointer type and the destination an integer type,
459  /// creates a PtrToInt cast. If the value is an integer type and the
460  /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
461  /// a bitcast.
462  static CastInst *CreateBitOrPointerCast(
463  Value *S, ///< The pointer value to be casted (operand 0)
464  Type *Ty, ///< The type to which cast should be made
465  const Twine &Name = "", ///< Name for the instruction
466  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
467  );
468 
469  /// Create a ZExt, BitCast, or Trunc for int -> int casts.
470  static CastInst *CreateIntegerCast(
471  Value *S, ///< The pointer value to be casted (operand 0)
472  Type *Ty, ///< The type to which cast should be made
473  bool isSigned, ///< Whether to regard S as signed or not
474  const Twine &Name = "", ///< Name for the instruction
475  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
476  );
477 
478  /// Create a ZExt, BitCast, or Trunc for int -> int casts.
479  static CastInst *CreateIntegerCast(
480  Value *S, ///< The integer value to be casted (operand 0)
481  Type *Ty, ///< The integer type to which operand is casted
482  bool isSigned, ///< Whether to regard S as signed or not
483  const Twine &Name, ///< The name for the instruction
484  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
485  );
486 
487  /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
488  static CastInst *CreateFPCast(
489  Value *S, ///< The floating point value to be casted
490  Type *Ty, ///< The floating point type to cast to
491  const Twine &Name = "", ///< Name for the instruction
492  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
493  );
494 
495  /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
496  static CastInst *CreateFPCast(
497  Value *S, ///< The floating point value to be casted
498  Type *Ty, ///< The floating point type to cast to
499  const Twine &Name, ///< The name for the instruction
500  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
501  );
502 
503  /// Create a Trunc or BitCast cast instruction
504  static CastInst *CreateTruncOrBitCast(
505  Value *S, ///< The value to be casted (operand 0)
506  Type *Ty, ///< The type to which cast should be made
507  const Twine &Name = "", ///< Name for the instruction
508  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
509  );
510 
511  /// Create a Trunc or BitCast cast instruction
512  static CastInst *CreateTruncOrBitCast(
513  Value *S, ///< The value to be casted (operand 0)
514  Type *Ty, ///< The type to which operand is casted
515  const Twine &Name, ///< The name for the instruction
516  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
517  );
518 
519  /// Check whether it is valid to call getCastOpcode for these types.
520  static bool isCastable(
521  Type *SrcTy, ///< The Type from which the value should be cast.
522  Type *DestTy ///< The Type to which the value should be cast.
523  );
524 
525  /// Check whether a bitcast between these types is valid
526  static bool isBitCastable(
527  Type *SrcTy, ///< The Type from which the value should be cast.
528  Type *DestTy ///< The Type to which the value should be cast.
529  );
530 
531  /// Check whether a bitcast, inttoptr, or ptrtoint cast between these
532  /// types is valid and a no-op.
533  ///
534  /// This ensures that any pointer<->integer cast has enough bits in the
535  /// integer and any other cast is a bitcast.
536  static bool isBitOrNoopPointerCastable(
537  Type *SrcTy, ///< The Type from which the value should be cast.
538  Type *DestTy, ///< The Type to which the value should be cast.
539  const DataLayout &DL);
540 
541  /// Returns the opcode necessary to cast Val into Ty using usual casting
542  /// rules.
543  /// Infer the opcode for cast operand and type
544  static Instruction::CastOps getCastOpcode(
545  const Value *Val, ///< The value to cast
546  bool SrcIsSigned, ///< Whether to treat the source as signed
547  Type *Ty, ///< The Type to which the value should be casted
548  bool DstIsSigned ///< Whether to treate the dest. as signed
549  );
550 
551  /// There are several places where we need to know if a cast instruction
552  /// only deals with integer source and destination types. To simplify that
553  /// logic, this method is provided.
554  /// @returns true iff the cast has only integral typed operand and dest type.
555  /// Determine if this is an integer-only cast.
556  bool isIntegerCast() const;
557 
558  /// A lossless cast is one that does not alter the basic value. It implies
559  /// a no-op cast but is more stringent, preventing things like int->float,
560  /// long->double, or int->ptr.
561  /// @returns true iff the cast is lossless.
562  /// Determine if this is a lossless cast.
563  bool isLosslessCast() const;
564 
565  /// A no-op cast is one that can be effected without changing any bits.
566  /// It implies that the source and destination types are the same size. The
567  /// DataLayout argument is to determine the pointer size when examining casts
568  /// involving Integer and Pointer types. They are no-op casts if the integer
569  /// is the same size as the pointer. However, pointer size varies with
570  /// platform.
571  /// Determine if the described cast is a no-op cast.
572  static bool isNoopCast(
573  Instruction::CastOps Opcode, ///< Opcode of cast
574  Type *SrcTy, ///< SrcTy of cast
575  Type *DstTy, ///< DstTy of cast
576  const DataLayout &DL ///< DataLayout to get the Int Ptr type from.
577  );
578 
579  /// Determine if this cast is a no-op cast.
580  ///
581  /// \param DL is the DataLayout to determine pointer size.
582  bool isNoopCast(const DataLayout &DL) const;
583 
584  /// Determine how a pair of casts can be eliminated, if they can be at all.
585  /// This is a helper function for both CastInst and ConstantExpr.
586  /// @returns 0 if the CastInst pair can't be eliminated, otherwise
587  /// returns Instruction::CastOps value for a cast that can replace
588  /// the pair, casting SrcTy to DstTy.
589  /// Determine if a cast pair is eliminable
590  static unsigned isEliminableCastPair(
591  Instruction::CastOps firstOpcode, ///< Opcode of first cast
592  Instruction::CastOps secondOpcode, ///< Opcode of second cast
593  Type *SrcTy, ///< SrcTy of 1st cast
594  Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
595  Type *DstTy, ///< DstTy of 2nd cast
596  Type *SrcIntPtrTy, ///< Integer type corresponding to Ptr SrcTy, or null
597  Type *MidIntPtrTy, ///< Integer type corresponding to Ptr MidTy, or null
598  Type *DstIntPtrTy ///< Integer type corresponding to Ptr DstTy, or null
599  );
600 
601  /// Return the opcode of this CastInst
604  }
605 
606  /// Return the source type, as a convenience
607  Type* getSrcTy() const { return getOperand(0)->getType(); }
608  /// Return the destination type, as a convenience
609  Type* getDestTy() const { return getType(); }
610 
611  /// This method can be used to determine if a cast from S to DstTy using
612  /// Opcode op is valid or not.
613  /// @returns true iff the proposed cast is valid.
614  /// Determine if a cast is valid without creating one.
615  static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy);
616 
617  /// Methods for support type inquiry through isa, cast, and dyn_cast:
618  static bool classof(const Instruction *I) {
619  return I->isCast();
620  }
621  static bool classof(const Value *V) {
622  return isa<Instruction>(V) && classof(cast<Instruction>(V));
623  }
624 };
625 
626 //===----------------------------------------------------------------------===//
627 // CmpInst Class
628 //===----------------------------------------------------------------------===//
629 
630 /// This class is the base class for the comparison instructions.
631 /// Abstract base class of comparison instructions.
632 class CmpInst : public Instruction {
633 public:
634  /// This enumeration lists the possible predicates for CmpInst subclasses.
635  /// Values in the range 0-31 are reserved for FCmpInst, while values in the
636  /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
637  /// predicate values are not overlapping between the classes.
638  ///
639  /// Some passes (e.g. InstCombine) depend on the bit-wise characteristics of
640  /// FCMP_* values. Changing the bit patterns requires a potential change to
641  /// those passes.
642  enum Predicate {
643  // Opcode U L G E Intuitive operation
644  FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
645  FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
646  FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
647  FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
648  FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
649  FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
650  FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
651  FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
652  FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
653  FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
654  FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than
655  FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal
656  FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than
657  FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal
658  FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal
659  FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded)
660  FIRST_FCMP_PREDICATE = FCMP_FALSE,
661  LAST_FCMP_PREDICATE = FCMP_TRUE,
662  BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
663  ICMP_EQ = 32, ///< equal
664  ICMP_NE = 33, ///< not equal
665  ICMP_UGT = 34, ///< unsigned greater than
666  ICMP_UGE = 35, ///< unsigned greater or equal
667  ICMP_ULT = 36, ///< unsigned less than
668  ICMP_ULE = 37, ///< unsigned less or equal
669  ICMP_SGT = 38, ///< signed greater than
670  ICMP_SGE = 39, ///< signed greater or equal
671  ICMP_SLT = 40, ///< signed less than
672  ICMP_SLE = 41, ///< signed less or equal
673  FIRST_ICMP_PREDICATE = ICMP_EQ,
674  LAST_ICMP_PREDICATE = ICMP_SLE,
675  BAD_ICMP_PREDICATE = ICMP_SLE + 1
676  };
677 
678 protected:
680  Value *LHS, Value *RHS, const Twine &Name = "",
681  Instruction *InsertBefore = nullptr,
682  Instruction *FlagsSource = nullptr);
683 
685  Value *LHS, Value *RHS, const Twine &Name,
686  BasicBlock *InsertAtEnd);
687 
688 public:
689  // allocate space for exactly two operands
690  void *operator new(size_t s) {
691  return User::operator new(s, 2);
692  }
693 
694  /// Construct a compare instruction, given the opcode, the predicate and
695  /// the two operands. Optionally (if InstBefore is specified) insert the
696  /// instruction into a BasicBlock right before the specified instruction.
697  /// The specified Instruction is allowed to be a dereferenced end iterator.
698  /// Create a CmpInst
699  static CmpInst *Create(OtherOps Op,
700  Predicate predicate, Value *S1,
701  Value *S2, const Twine &Name = "",
702  Instruction *InsertBefore = nullptr);
703 
704  /// Construct a compare instruction, given the opcode, the predicate and the
705  /// two operands. Also automatically insert this instruction to the end of
706  /// the BasicBlock specified.
707  /// Create a CmpInst
708  static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1,
709  Value *S2, const Twine &Name, BasicBlock *InsertAtEnd);
710 
711  /// Get the opcode casted to the right type
712  OtherOps getOpcode() const {
713  return static_cast<OtherOps>(Instruction::getOpcode());
714  }
715 
716  /// Return the predicate for this instruction.
719  }
720 
721  /// Set the predicate for this instruction to the specified value.
723 
724  static bool isFPPredicate(Predicate P) {
725  return P >= FIRST_FCMP_PREDICATE && P <= LAST_FCMP_PREDICATE;
726  }
727 
728  static bool isIntPredicate(Predicate P) {
729  return P >= FIRST_ICMP_PREDICATE && P <= LAST_ICMP_PREDICATE;
730  }
731 
732  static StringRef getPredicateName(Predicate P);
733 
734  bool isFPPredicate() const { return isFPPredicate(getPredicate()); }
735  bool isIntPredicate() const { return isIntPredicate(getPredicate()); }
736 
737  /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
738  /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
739  /// @returns the inverse predicate for the instruction's current predicate.
740  /// Return the inverse of the instruction's predicate.
742  return getInversePredicate(getPredicate());
743  }
744 
745  /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
746  /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
747  /// @returns the inverse predicate for predicate provided in \p pred.
748  /// Return the inverse of a given predicate
749  static Predicate getInversePredicate(Predicate pred);
750 
751  /// For example, EQ->EQ, SLE->SGE, ULT->UGT,
752  /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
753  /// @returns the predicate that would be the result of exchanging the two
754  /// operands of the CmpInst instruction without changing the result
755  /// produced.
756  /// Return the predicate as if the operands were swapped
759  }
760 
761  /// This is a static version that you can use without an instruction
762  /// available.
763  /// Return the predicate as if the operands were swapped.
765 
766  /// For predicate of kind "is X or equal to 0" returns the predicate "is X".
767  /// For predicate of kind "is X" returns the predicate "is X or equal to 0".
768  /// does not support other kind of predicates.
769  /// @returns the predicate that does not contains is equal to zero if
770  /// it had and vice versa.
771  /// Return the flipped strictness of predicate
773  return getFlippedStrictnessPredicate(getPredicate());
774  }
775 
776  /// This is a static version that you can use without an instruction
777  /// available.
778  /// Return the flipped strictness of predicate
779  static Predicate getFlippedStrictnessPredicate(Predicate pred);
780 
781  /// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
782  /// Returns the non-strict version of strict comparisons.
784  return getNonStrictPredicate(getPredicate());
785  }
786 
787  /// This is a static version that you can use without an instruction
788  /// available.
789  /// @returns the non-strict version of comparison provided in \p pred.
790  /// If \p pred is not a strict comparison predicate, returns \p pred.
791  /// Returns the non-strict version of strict comparisons.
792  static Predicate getNonStrictPredicate(Predicate pred);
793 
794  /// Provide more efficient getOperand methods.
796 
797  /// This is just a convenience that dispatches to the subclasses.
798  /// Swap the operands and adjust predicate accordingly to retain
799  /// the same comparison.
800  void swapOperands();
801 
802  /// This is just a convenience that dispatches to the subclasses.
803  /// Determine if this CmpInst is commutative.
804  bool isCommutative() const;
805 
806  /// This is just a convenience that dispatches to the subclasses.
807  /// Determine if this is an equals/not equals predicate.
808  bool isEquality() const;
809 
810  /// @returns true if the comparison is signed, false otherwise.
811  /// Determine if this instruction is using a signed comparison.
812  bool isSigned() const {
813  return isSigned(getPredicate());
814  }
815 
816  /// @returns true if the comparison is unsigned, false otherwise.
817  /// Determine if this instruction is using an unsigned comparison.
818  bool isUnsigned() const {
819  return isUnsigned(getPredicate());
820  }
821 
822  /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
823  /// @returns the signed version of the unsigned predicate pred.
824  /// return the signed version of a predicate
825  static Predicate getSignedPredicate(Predicate pred);
826 
827  /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
828  /// @returns the signed version of the predicate for this instruction (which
829  /// has to be an unsigned predicate).
830  /// return the signed version of a predicate
832  return getSignedPredicate(getPredicate());
833  }
834 
835  /// This is just a convenience.
836  /// Determine if this is true when both operands are the same.
837  bool isTrueWhenEqual() const {
838  return isTrueWhenEqual(getPredicate());
839  }
840 
841  /// This is just a convenience.
842  /// Determine if this is false when both operands are the same.
843  bool isFalseWhenEqual() const {
844  return isFalseWhenEqual(getPredicate());
845  }
846 
847  /// @returns true if the predicate is unsigned, false otherwise.
848  /// Determine if the predicate is an unsigned operation.
849  static bool isUnsigned(Predicate predicate);
850 
851  /// @returns true if the predicate is signed, false otherwise.
852  /// Determine if the predicate is an signed operation.
853  static bool isSigned(Predicate predicate);
854 
855  /// Determine if the predicate is an ordered operation.
856  static bool isOrdered(Predicate predicate);
857 
858  /// Determine if the predicate is an unordered operation.
859  static bool isUnordered(Predicate predicate);
860 
861  /// Determine if the predicate is true when comparing a value with itself.
862  static bool isTrueWhenEqual(Predicate predicate);
863 
864  /// Determine if the predicate is false when comparing a value with itself.
865  static bool isFalseWhenEqual(Predicate predicate);
866 
867  /// Determine if Pred1 implies Pred2 is true when two compares have matching
868  /// operands.
869  static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2);
870 
871  /// Determine if Pred1 implies Pred2 is false when two compares have matching
872  /// operands.
873  static bool isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2);
874 
875  /// Methods for support type inquiry through isa, cast, and dyn_cast:
876  static bool classof(const Instruction *I) {
877  return I->getOpcode() == Instruction::ICmp ||
878  I->getOpcode() == Instruction::FCmp;
879  }
880  static bool classof(const Value *V) {
881  return isa<Instruction>(V) && classof(cast<Instruction>(V));
882  }
883 
884  /// Create a result type for fcmp/icmp
885  static Type* makeCmpResultType(Type* opnd_type) {
886  if (VectorType* vt = dyn_cast<VectorType>(opnd_type)) {
887  return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
888  vt->getNumElements());
889  }
890  return Type::getInt1Ty(opnd_type->getContext());
891  }
892 
893 private:
894  // Shadow Value::setValueSubclassData with a private forwarding method so that
895  // subclasses cannot accidentally use it.
896  void setValueSubclassData(unsigned short D) {
898  }
899 };
900 
901 // FIXME: these are redundant if CmpInst < BinaryOperator
902 template <>
903 struct OperandTraits<CmpInst> : public FixedNumOperandTraits<CmpInst, 2> {
904 };
905 
907 
908 /// A lightweight accessor for an operand bundle meant to be passed
909 /// around by value.
912 
913  OperandBundleUse() = default;
915  : Inputs(Inputs), Tag(Tag) {}
916 
917  /// Return true if the operand at index \p Idx in this operand bundle
918  /// has the attribute A.
919  bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const {
920  if (isDeoptOperandBundle())
921  if (A == Attribute::ReadOnly || A == Attribute::NoCapture)
922  return Inputs[Idx]->getType()->isPointerTy();
923 
924  // Conservative answer: no operands have any attributes.
925  return false;
926  }
927 
928  /// Return the tag of this operand bundle as a string.
930  return Tag->getKey();
931  }
932 
933  /// Return the tag of this operand bundle as an integer.
934  ///
935  /// Operand bundle tags are interned by LLVMContextImpl::getOrInsertBundleTag,
936  /// and this function returns the unique integer getOrInsertBundleTag
937  /// associated the tag of this operand bundle to.
938  uint32_t getTagID() const {
939  return Tag->getValue();
940  }
941 
942  /// Return true if this is a "deopt" operand bundle.
943  bool isDeoptOperandBundle() const {
944  return getTagID() == LLVMContext::OB_deopt;
945  }
946 
947  /// Return true if this is a "funclet" operand bundle.
948  bool isFuncletOperandBundle() const {
949  return getTagID() == LLVMContext::OB_funclet;
950  }
951 
952 private:
953  /// Pointer to an entry in LLVMContextImpl::getOrInsertBundleTag.
955 };
956 
957 /// A container for an operand bundle being viewed as a set of values
958 /// rather than a set of uses.
959 ///
960 /// Unlike OperandBundleUse, OperandBundleDefT owns the memory it carries, and
961 /// so it is possible to create and pass around "self-contained" instances of
962 /// OperandBundleDef and ConstOperandBundleDef.
963 template <typename InputTy> class OperandBundleDefT {
964  std::string Tag;
965  std::vector<InputTy> Inputs;
966 
967 public:
968  explicit OperandBundleDefT(std::string Tag, std::vector<InputTy> Inputs)
969  : Tag(std::move(Tag)), Inputs(std::move(Inputs)) {}
970  explicit OperandBundleDefT(std::string Tag, ArrayRef<InputTy> Inputs)
971  : Tag(std::move(Tag)), Inputs(Inputs) {}
972 
973  explicit OperandBundleDefT(const OperandBundleUse &OBU) {
974  Tag = OBU.getTagName();
975  Inputs.insert(Inputs.end(), OBU.Inputs.begin(), OBU.Inputs.end());
976  }
977 
978  ArrayRef<InputTy> inputs() const { return Inputs; }
979 
980  using input_iterator = typename std::vector<InputTy>::const_iterator;
981 
982  size_t input_size() const { return Inputs.size(); }
983  input_iterator input_begin() const { return Inputs.begin(); }
984  input_iterator input_end() const { return Inputs.end(); }
985 
986  StringRef getTag() const { return Tag; }
987 };
988 
991 
992 //===----------------------------------------------------------------------===//
993 // CallBase Class
994 //===----------------------------------------------------------------------===//
995 
996 /// Base class for all callable instructions (InvokeInst and CallInst)
997 /// Holds everything related to calling a function.
998 ///
999 /// All call-like instructions are required to use a common operand layout:
1000 /// - Zero or more arguments to the call,
1001 /// - Zero or more operand bundles with zero or more operand inputs each
1002 /// bundle,
1003 /// - Zero or more subclass controlled operands
1004 /// - The called function.
1005 ///
1006 /// This allows this base class to easily access the called function and the
1007 /// start of the arguments without knowing how many other operands a particular
1008 /// subclass requires. Note that accessing the end of the argument list isn't
1009 /// as cheap as most other operations on the base class.
1010 class CallBase : public Instruction {
1011 protected:
1012  /// The last operand is the called operand.
1013  static constexpr int CalledOperandOpEndIdx = -1;
1014 
1015  AttributeList Attrs; ///< parameter attributes for callable
1017 
1018  template <class... ArgsTy>
1019  CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
1020  : Instruction(std::forward<ArgsTy>(Args)...), Attrs(A), FTy(FT) {}
1021 
1023 
1024  bool hasDescriptor() const { return Value::HasDescriptor; }
1025 
1026  unsigned getNumSubclassExtraOperands() const {
1027  switch (getOpcode()) {
1028  case Instruction::Call:
1029  return 0;
1030  case Instruction::Invoke:
1031  return 2;
1032  }
1033  llvm_unreachable("Invalid opcode!");
1034  }
1035 
1036 public:
1038 
1039  static bool classof(const Instruction *I) {
1040  return I->getOpcode() == Instruction::Call ||
1041  I->getOpcode() == Instruction::Invoke;
1042  }
1043 
1044  FunctionType *getFunctionType() const { return FTy; }
1045 
1048  this->FTy = FTy;
1049  }
1050 
1051  /// Return the iterator pointing to the beginning of the argument list.
1054  return const_cast<CallBase *>(this)->arg_begin();
1055  }
1056 
1057  /// Return the iterator pointing to the end of the argument list.
1059  // Walk from the end of the operands over the called operand, the subclass
1060  // operands, and any operands for bundles to find the end of the argument
1061  // operands.
1062  return op_end() - getNumTotalBundleOperands() -
1063  getNumSubclassExtraOperands() - 1;
1064  }
1066  return const_cast<CallBase *>(this)->arg_end();
1067  }
1068 
1069  /// Iteration adapter for range-for loops.
1071  return make_range(arg_begin(), arg_end());
1072  }
1074  return make_range(arg_begin(), arg_end());
1075  }
1076 
1077  unsigned getNumArgOperands() const { return arg_end() - arg_begin(); }
1078 
1079  Value *getArgOperand(unsigned i) const {
1080  assert(i < getNumArgOperands() && "Out of bounds!");
1081  return getOperand(i);
1082  }
1083 
1084  void setArgOperand(unsigned i, Value *v) {
1085  assert(i < getNumArgOperands() && "Out of bounds!");
1086  setOperand(i, v);
1087  }
1088 
1089  /// Wrappers for getting the \c Use of a call argument.
1090  const Use &getArgOperandUse(unsigned i) const {
1091  assert(i < getNumArgOperands() && "Out of bounds!");
1092  return User::getOperandUse(i);
1093  }
1094  Use &getArgOperandUse(unsigned i) {
1095  assert(i < getNumArgOperands() && "Out of bounds!");
1096  return User::getOperandUse(i);
1097  }
1098 
1100 
1101  Value *getCalledOperand() const { return Op<CalledOperandOpEndIdx>(); }
1102 
1103  // DEPRECATED: This routine will be removed in favor of `getCalledOperand` in
1104  // the near future.
1105  Value *getCalledValue() const { return getCalledOperand(); }
1106 
1107  const Use &getCalledOperandUse() const { return Op<CalledOperandOpEndIdx>(); }
1108  Use &getCalledOperandUse() { return Op<CalledOperandOpEndIdx>(); }
1109 
1110  /// Returns the function called, or null if this is an
1111  /// indirect function invocation.
1113  return dyn_cast_or_null<Function>(getCalledOperand());
1114  }
1115 
1116  void setCalledOperand(Value *V) { Op<CalledOperandOpEndIdx>() = V; }
1117 
1118  /// Sets the function called, including updating the function type.
1120  setCalledFunction(
1121  cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
1122  Fn);
1123  }
1124 
1125  /// Sets the function called, including updating to the specified function
1126  /// type.
1128  this->FTy = FTy;
1129  assert(FTy == cast<FunctionType>(
1130  cast<PointerType>(Fn->getType())->getElementType()));
1131  setCalledOperand(Fn);
1132  }
1133 
1135  return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1136  }
1137 
1139  auto ID = static_cast<unsigned>(CC);
1140  assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
1142  (ID << 2));
1143  }
1144 
1145  /// \name Attribute API
1146  ///
1147  /// These methods access and modify attributes on this call (including
1148  /// looking through to the attributes on the called function when necessary).
1149  ///@{
1150 
1151  /// Return the parameter attributes for this call.
1152  ///
1153  AttributeList getAttributes() const { return Attrs; }
1154 
1155  /// Set the parameter attributes for this call.
1156  ///
1157  void setAttributes(AttributeList A) { Attrs = A; }
1158 
1159  /// Determine whether this call has the given attribute.
1161  assert(Kind != Attribute::NoBuiltin &&
1162  "Use CallBase::isNoBuiltin() to check for Attribute::NoBuiltin");
1163  return hasFnAttrImpl(Kind);
1164  }
1165 
1166  /// Determine whether this call has the given attribute.
1167  bool hasFnAttr(StringRef Kind) const { return hasFnAttrImpl(Kind); }
1168 
1169  /// adds the attribute to the list of attributes.
1171  AttributeList PAL = getAttributes();
1172  PAL = PAL.addAttribute(getContext(), i, Kind);
1173  setAttributes(PAL);
1174  }
1175 
1176  /// adds the attribute to the list of attributes.
1177  void addAttribute(unsigned i, Attribute Attr) {
1178  AttributeList PAL = getAttributes();
1179  PAL = PAL.addAttribute(getContext(), i, Attr);
1180  setAttributes(PAL);
1181  }
1182 
1183  /// Adds the attribute to the indicated argument
1184  void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
1185  assert(ArgNo < getNumArgOperands() && "Out of bounds");
1186  AttributeList PAL = getAttributes();
1187  PAL = PAL.addParamAttribute(getContext(), ArgNo, Kind);
1188  setAttributes(PAL);
1189  }
1190 
1191  /// Adds the attribute to the indicated argument
1192  void addParamAttr(unsigned ArgNo, Attribute Attr) {
1193  assert(ArgNo < getNumArgOperands() && "Out of bounds");
1194  AttributeList PAL = getAttributes();
1195  PAL = PAL.addParamAttribute(getContext(), ArgNo, Attr);
1196  setAttributes(PAL);
1197  }
1198 
1199  /// removes the attribute from the list of attributes.
1201  AttributeList PAL = getAttributes();
1202  PAL = PAL.removeAttribute(getContext(), i, Kind);
1203  setAttributes(PAL);
1204  }
1205 
1206  /// removes the attribute from the list of attributes.
1207  void removeAttribute(unsigned i, StringRef Kind) {
1208  AttributeList PAL = getAttributes();
1209  PAL = PAL.removeAttribute(getContext(), i, Kind);
1210  setAttributes(PAL);
1211  }
1212 
1213  /// Removes the attribute from the given argument
1214  void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
1215  assert(ArgNo < getNumArgOperands() && "Out of bounds");
1216  AttributeList PAL = getAttributes();
1217  PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind);
1218  setAttributes(PAL);
1219  }
1220 
1221  /// Removes the attribute from the given argument
1222  void removeParamAttr(unsigned ArgNo, StringRef Kind) {
1223  assert(ArgNo < getNumArgOperands() && "Out of bounds");
1224  AttributeList PAL = getAttributes();
1225  PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind);
1226  setAttributes(PAL);
1227  }
1228 
1229  /// adds the dereferenceable attribute to the list of attributes.
1230  void addDereferenceableAttr(unsigned i, uint64_t Bytes) {
1231  AttributeList PAL = getAttributes();
1232  PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
1233  setAttributes(PAL);
1234  }
1235 
1236  /// adds the dereferenceable_or_null attribute to the list of
1237  /// attributes.
1238  void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) {
1239  AttributeList PAL = getAttributes();
1240  PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes);
1241  setAttributes(PAL);
1242  }
1243 
1244  /// Determine whether the return value has the given attribute.
1245  bool hasRetAttr(Attribute::AttrKind Kind) const;
1246 
1247  /// Determine whether the argument or parameter has the given attribute.
1248  bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const;
1249 
1250  /// Get the attribute of a given kind at a position.
1251  Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
1252  return getAttributes().getAttribute(i, Kind);
1253  }
1254 
1255  /// Get the attribute of a given kind at a position.
1256  Attribute getAttribute(unsigned i, StringRef Kind) const {
1257  return getAttributes().getAttribute(i, Kind);
1258  }
1259 
1260  /// Get the attribute of a given kind from a given arg
1261  Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
1262  assert(ArgNo < getNumArgOperands() && "Out of bounds");
1263  return getAttributes().getParamAttr(ArgNo, Kind);
1264  }
1265 
1266  /// Get the attribute of a given kind from a given arg
1267  Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const {
1268  assert(ArgNo < getNumArgOperands() && "Out of bounds");
1269  return getAttributes().getParamAttr(ArgNo, Kind);
1270  }
1271 
1272  /// Return true if the data operand at index \p i has the attribute \p
1273  /// A.
1274  ///
1275  /// Data operands include call arguments and values used in operand bundles,
1276  /// but does not include the callee operand. This routine dispatches to the
1277  /// underlying AttributeList or the OperandBundleUser as appropriate.
1278  ///
1279  /// The index \p i is interpreted as
1280  ///
1281  /// \p i == Attribute::ReturnIndex -> the return value
1282  /// \p i in [1, arg_size + 1) -> argument number (\p i - 1)
1283  /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
1284  /// (\p i - 1) in the operand list.
1285  bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const {
1286  // Note that we have to add one because `i` isn't zero-indexed.
1287  assert(i < (getNumArgOperands() + getNumTotalBundleOperands() + 1) &&
1288  "Data operand index out of bounds!");
1289 
1290  // The attribute A can either be directly specified, if the operand in
1291  // question is a call argument; or be indirectly implied by the kind of its
1292  // containing operand bundle, if the operand is a bundle operand.
1293 
1294  if (i == AttributeList::ReturnIndex)
1295  return hasRetAttr(Kind);
1296 
1297  // FIXME: Avoid these i - 1 calculations and update the API to use
1298  // zero-based indices.
1299  if (i < (getNumArgOperands() + 1))
1300  return paramHasAttr(i - 1, Kind);
1301 
1302  assert(hasOperandBundles() && i >= (getBundleOperandsStartIndex() + 1) &&
1303  "Must be either a call argument or an operand bundle!");
1304  return bundleOperandHasAttr(i - 1, Kind);
1305  }
1306 
1307  /// Extract the alignment of the return value.
1308  unsigned getRetAlignment() const { return Attrs.getRetAlignment(); }
1309 
1310  /// Extract the alignment for a call or parameter (0=unknown).
1311  unsigned getParamAlignment(unsigned ArgNo) const {
1312  return Attrs.getParamAlignment(ArgNo);
1313  }
1314 
1315  /// Extract the number of dereferenceable bytes for a call or
1316  /// parameter (0=unknown).
1317  uint64_t getDereferenceableBytes(unsigned i) const {
1318  return Attrs.getDereferenceableBytes(i);
1319  }
1320 
1321  /// Extract the number of dereferenceable_or_null bytes for a call or
1322  /// parameter (0=unknown).
1323  uint64_t getDereferenceableOrNullBytes(unsigned i) const {
1324  return Attrs.getDereferenceableOrNullBytes(i);
1325  }
1326 
1327  /// Determine if the return value is marked with NoAlias attribute.
1328  bool returnDoesNotAlias() const {
1330  }
1331 
1332  /// If one of the arguments has the 'returned' attribute, returns its
1333  /// operand value. Otherwise, return nullptr.
1334  Value *getReturnedArgOperand() const;
1335 
1336  /// Return true if the call should not be treated as a call to a
1337  /// builtin.
1338  bool isNoBuiltin() const {
1339  return hasFnAttrImpl(Attribute::NoBuiltin) &&
1340  !hasFnAttrImpl(Attribute::Builtin);
1341  }
1342 
1343  /// Determine if the call requires strict floating point semantics.
1344  bool isStrictFP() const { return hasFnAttr(Attribute::StrictFP); }
1345 
1346  /// Return true if the call should not be inlined.
1347  bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1348  void setIsNoInline() {
1349  addAttribute(AttributeList::FunctionIndex, Attribute::NoInline);
1350  }
1351  /// Determine if the call does not access memory.
1352  bool doesNotAccessMemory() const { return hasFnAttr(Attribute::ReadNone); }
1354  addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone);
1355  }
1356 
1357  /// Determine if the call does not access or only reads memory.
1358  bool onlyReadsMemory() const {
1359  return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1360  }
1362  addAttribute(AttributeList::FunctionIndex, Attribute::ReadOnly);
1363  }
1364 
1365  /// Determine if the call does not access or only writes memory.
1366  bool doesNotReadMemory() const {
1367  return doesNotAccessMemory() || hasFnAttr(Attribute::WriteOnly);
1368  }
1370  addAttribute(AttributeList::FunctionIndex, Attribute::WriteOnly);
1371  }
1372 
1373  /// Determine if the call can access memmory only using pointers based
1374  /// on its arguments.
1375  bool onlyAccessesArgMemory() const {
1376  return hasFnAttr(Attribute::ArgMemOnly);
1377  }
1379  addAttribute(AttributeList::FunctionIndex, Attribute::ArgMemOnly);
1380  }
1381 
1382  /// Determine if the function may only access memory that is
1383  /// inaccessible from the IR.
1385  return hasFnAttr(Attribute::InaccessibleMemOnly);
1386  }
1388  addAttribute(AttributeList::FunctionIndex, Attribute::InaccessibleMemOnly);
1389  }
1390 
1391  /// Determine if the function may only access memory that is
1392  /// either inaccessible from the IR or pointed to by its arguments.
1394  return hasFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
1395  }
1397  addAttribute(AttributeList::FunctionIndex,
1398  Attribute::InaccessibleMemOrArgMemOnly);
1399  }
1400  /// Determine if the call cannot return.
1401  bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1403  addAttribute(AttributeList::FunctionIndex, Attribute::NoReturn);
1404  }
1405 
1406  /// Determine if the call should not perform indirect branch tracking.
1407  bool doesNoCfCheck() const { return hasFnAttr(Attribute::NoCfCheck); }
1408 
1409  /// Determine if the call cannot unwind.
1410  bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1412  addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind);
1413  }
1414 
1415  /// Determine if the invoke cannot be duplicated.
1416  bool cannotDuplicate() const { return hasFnAttr(Attribute::NoDuplicate); }
1418  addAttribute(AttributeList::FunctionIndex, Attribute::NoDuplicate);
1419  }
1420 
1421  /// Determine if the invoke is convergent
1422  bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
1423  void setConvergent() {
1425  }
1428  }
1429 
1430  /// Determine if the call returns a structure through first
1431  /// pointer argument.
1432  bool hasStructRetAttr() const {
1433  if (getNumArgOperands() == 0)
1434  return false;
1435 
1436  // Be friendly and also check the callee.
1437  return paramHasAttr(0, Attribute::StructRet);
1438  }
1439 
1440  /// Determine if any call argument is an aggregate passed by value.
1441  bool hasByValArgument() const {
1442  return Attrs.hasAttrSomewhere(Attribute::ByVal);
1443  }
1444 
1445  ///@{
1446  // End of attribute API.
1447 
1448  /// \name Operand Bundle API
1449  ///
1450  /// This group of methods provides the API to access and manipulate operand
1451  /// bundles on this call.
1452  /// @{
1453 
1454  /// Return the number of operand bundles associated with this User.
1455  unsigned getNumOperandBundles() const {
1456  return std::distance(bundle_op_info_begin(), bundle_op_info_end());
1457  }
1458 
1459  /// Return true if this User has any operand bundles.
1460  bool hasOperandBundles() const { return getNumOperandBundles() != 0; }
1461 
1462  /// Return the index of the first bundle operand in the Use array.
1463  unsigned getBundleOperandsStartIndex() const {
1464  assert(hasOperandBundles() && "Don't call otherwise!");
1465  return bundle_op_info_begin()->Begin;
1466  }
1467 
1468  /// Return the index of the last bundle operand in the Use array.
1469  unsigned getBundleOperandsEndIndex() const {
1470  assert(hasOperandBundles() && "Don't call otherwise!");
1471  return bundle_op_info_end()[-1].End;
1472  }
1473 
1474  /// Return true if the operand at index \p Idx is a bundle operand.
1475  bool isBundleOperand(unsigned Idx) const {
1476  return hasOperandBundles() && Idx >= getBundleOperandsStartIndex() &&
1477  Idx < getBundleOperandsEndIndex();
1478  }
1479 
1480  /// Return the total number operands (not operand bundles) used by
1481  /// every operand bundle in this OperandBundleUser.
1482  unsigned getNumTotalBundleOperands() const {
1483  if (!hasOperandBundles())
1484  return 0;
1485 
1486  unsigned Begin = getBundleOperandsStartIndex();
1487  unsigned End = getBundleOperandsEndIndex();
1488 
1489  assert(Begin <= End && "Should be!");
1490  return End - Begin;
1491  }
1492 
1493  /// Return the operand bundle at a specific index.
1495  assert(Index < getNumOperandBundles() && "Index out of bounds!");
1496  return operandBundleFromBundleOpInfo(*(bundle_op_info_begin() + Index));
1497  }
1498 
1499  /// Return the number of operand bundles with the tag Name attached to
1500  /// this instruction.
1502  unsigned Count = 0;
1503  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1504  if (getOperandBundleAt(i).getTagName() == Name)
1505  Count++;
1506 
1507  return Count;
1508  }
1509 
1510  /// Return the number of operand bundles with the tag ID attached to
1511  /// this instruction.
1513  unsigned Count = 0;
1514  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1515  if (getOperandBundleAt(i).getTagID() == ID)
1516  Count++;
1517 
1518  return Count;
1519  }
1520 
1521  /// Return an operand bundle by name, if present.
1522  ///
1523  /// It is an error to call this for operand bundle types that may have
1524  /// multiple instances of them on the same instruction.
1526  assert(countOperandBundlesOfType(Name) < 2 && "Precondition violated!");
1527 
1528  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1529  OperandBundleUse U = getOperandBundleAt(i);
1530  if (U.getTagName() == Name)
1531  return U;
1532  }
1533 
1534  return None;
1535  }
1536 
1537  /// Return an operand bundle by tag ID, if present.
1538  ///
1539  /// It is an error to call this for operand bundle types that may have
1540  /// multiple instances of them on the same instruction.
1542  assert(countOperandBundlesOfType(ID) < 2 && "Precondition violated!");
1543 
1544  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1545  OperandBundleUse U = getOperandBundleAt(i);
1546  if (U.getTagID() == ID)
1547  return U;
1548  }
1549 
1550  return None;
1551  }
1552 
1553  /// Return the list of operand bundles attached to this instruction as
1554  /// a vector of OperandBundleDefs.
1555  ///
1556  /// This function copies the OperandBundeUse instances associated with this
1557  /// OperandBundleUser to a vector of OperandBundleDefs. Note:
1558  /// OperandBundeUses and OperandBundleDefs are non-trivially *different*
1559  /// representations of operand bundles (see documentation above).
1561  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1562  Defs.emplace_back(getOperandBundleAt(i));
1563  }
1564 
1565  /// Return the operand bundle for the operand at index OpIdx.
1566  ///
1567  /// It is an error to call this with an OpIdx that does not correspond to an
1568  /// bundle operand.
1570  return operandBundleFromBundleOpInfo(getBundleOpInfoForOperand(OpIdx));
1571  }
1572 
1573  /// Return true if this operand bundle user has operand bundles that
1574  /// may read from the heap.
1576  // Implementation note: this is a conservative implementation of operand
1577  // bundle semantics, where *any* operand bundle forces a callsite to be at
1578  // least readonly.
1579  return hasOperandBundles();
1580  }
1581 
1582  /// Return true if this operand bundle user has operand bundles that
1583  /// may write to the heap.
1585  for (auto &BOI : bundle_op_infos()) {
1586  if (BOI.Tag->second == LLVMContext::OB_deopt ||
1587  BOI.Tag->second == LLVMContext::OB_funclet)
1588  continue;
1589 
1590  // This instruction has an operand bundle that is not known to us.
1591  // Assume the worst.
1592  return true;
1593  }
1594 
1595  return false;
1596  }
1597 
1598  /// Return true if the bundle operand at index \p OpIdx has the
1599  /// attribute \p A.
1600  bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const {
1601  auto &BOI = getBundleOpInfoForOperand(OpIdx);
1602  auto OBU = operandBundleFromBundleOpInfo(BOI);
1603  return OBU.operandHasAttr(OpIdx - BOI.Begin, A);
1604  }
1605 
1606  /// Return true if \p Other has the same sequence of operand bundle
1607  /// tags with the same number of operands on each one of them as this
1608  /// OperandBundleUser.
1609  bool hasIdenticalOperandBundleSchema(const CallBase &Other) const {
1610  if (getNumOperandBundles() != Other.getNumOperandBundles())
1611  return false;
1612 
1613  return std::equal(bundle_op_info_begin(), bundle_op_info_end(),
1614  Other.bundle_op_info_begin());
1615  }
1616 
1617  /// Return true if this operand bundle user contains operand bundles
1618  /// with tags other than those specified in \p IDs.
1620  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1621  uint32_t ID = getOperandBundleAt(i).getTagID();
1622  if (!is_contained(IDs, ID))
1623  return true;
1624  }
1625  return false;
1626  }
1627 
1628  /// Is the function attribute S disallowed by some operand bundle on
1629  /// this operand bundle user?
1631  // Operand bundles only possibly disallow readnone, readonly and argmenonly
1632  // attributes. All String attributes are fine.
1633  return false;
1634  }
1635 
1636  /// Is the function attribute A disallowed by some operand bundle on
1637  /// this operand bundle user?
1639  switch (A) {
1640  default:
1641  return false;
1642 
1643  case Attribute::InaccessibleMemOrArgMemOnly:
1644  return hasReadingOperandBundles();
1645 
1646  case Attribute::InaccessibleMemOnly:
1647  return hasReadingOperandBundles();
1648 
1649  case Attribute::ArgMemOnly:
1650  return hasReadingOperandBundles();
1651 
1652  case Attribute::ReadNone:
1653  return hasReadingOperandBundles();
1654 
1655  case Attribute::ReadOnly:
1656  return hasClobberingOperandBundles();
1657  }
1658 
1659  llvm_unreachable("switch has a default case!");
1660  }
1661 
1662  /// Used to keep track of an operand bundle. See the main comment on
1663  /// OperandBundleUser above.
1664  struct BundleOpInfo {
1665  /// The operand bundle tag, interned by
1666  /// LLVMContextImpl::getOrInsertBundleTag.
1668 
1669  /// The index in the Use& vector where operands for this operand
1670  /// bundle starts.
1672 
1673  /// The index in the Use& vector where operands for this operand
1674  /// bundle ends.
1676 
1677  bool operator==(const BundleOpInfo &Other) const {
1678  return Tag == Other.Tag && Begin == Other.Begin && End == Other.End;
1679  }
1680  };
1681 
1682  /// Simple helper function to map a BundleOpInfo to an
1683  /// OperandBundleUse.
1686  auto begin = op_begin();
1687  ArrayRef<Use> Inputs(begin + BOI.Begin, begin + BOI.End);
1688  return OperandBundleUse(BOI.Tag, Inputs);
1689  }
1690 
1693 
1694  /// Return the start of the list of BundleOpInfo instances associated
1695  /// with this OperandBundleUser.
1696  ///
1697  /// OperandBundleUser uses the descriptor area co-allocated with the host User
1698  /// to store some meta information about which operands are "normal" operands,
1699  /// and which ones belong to some operand bundle.
1700  ///
1701  /// The layout of an operand bundle user is
1702  ///
1703  /// +-----------uint32_t End-------------------------------------+
1704  /// | |
1705  /// | +--------uint32_t Begin--------------------+ |
1706  /// | | | |
1707  /// ^ ^ v v
1708  /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
1709  /// | BOI0 | BOI1 | .. | DU | U0 | U1 | .. | BOI0_U0 | .. | BOI1_U0 | .. | Un
1710  /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
1711  /// v v ^ ^
1712  /// | | | |
1713  /// | +--------uint32_t Begin------------+ |
1714  /// | |
1715  /// +-----------uint32_t End-----------------------------+
1716  ///
1717  ///
1718  /// BOI0, BOI1 ... are descriptions of operand bundles in this User's use
1719  /// list. These descriptions are installed and managed by this class, and
1720  /// they're all instances of OperandBundleUser<T>::BundleOpInfo.
1721  ///
1722  /// DU is an additional descriptor installed by User's 'operator new' to keep
1723  /// track of the 'BOI0 ... BOIN' co-allocation. OperandBundleUser does not
1724  /// access or modify DU in any way, it's an implementation detail private to
1725  /// User.
1726  ///
1727  /// The regular Use& vector for the User starts at U0. The operand bundle
1728  /// uses are part of the Use& vector, just like normal uses. In the diagram
1729  /// above, the operand bundle uses start at BOI0_U0. Each instance of
1730  /// BundleOpInfo has information about a contiguous set of uses constituting
1731  /// an operand bundle, and the total set of operand bundle uses themselves
1732  /// form a contiguous set of uses (i.e. there are no gaps between uses
1733  /// corresponding to individual operand bundles).
1734  ///
1735  /// This class does not know the location of the set of operand bundle uses
1736  /// within the use list -- that is decided by the User using this class via
1737  /// the BeginIdx argument in populateBundleOperandInfos.
1738  ///
1739  /// Currently operand bundle users with hung-off operands are not supported.
1741  if (!hasDescriptor())
1742  return nullptr;
1743 
1744  uint8_t *BytesBegin = getDescriptor().begin();
1745  return reinterpret_cast<bundle_op_iterator>(BytesBegin);
1746  }
1747 
1748  /// Return the start of the list of BundleOpInfo instances associated
1749  /// with this OperandBundleUser.
1751  auto *NonConstThis = const_cast<CallBase *>(this);
1752  return NonConstThis->bundle_op_info_begin();
1753  }
1754 
1755  /// Return the end of the list of BundleOpInfo instances associated
1756  /// with this OperandBundleUser.
1758  if (!hasDescriptor())
1759  return nullptr;
1760 
1761  uint8_t *BytesEnd = getDescriptor().end();
1762  return reinterpret_cast<bundle_op_iterator>(BytesEnd);
1763  }
1764 
1765  /// Return the end of the list of BundleOpInfo instances associated
1766  /// with this OperandBundleUser.
1768  auto *NonConstThis = const_cast<CallBase *>(this);
1769  return NonConstThis->bundle_op_info_end();
1770  }
1771 
1772  /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
1774  return make_range(bundle_op_info_begin(), bundle_op_info_end());
1775  }
1776 
1777  /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
1779  return make_range(bundle_op_info_begin(), bundle_op_info_end());
1780  }
1781 
1782  /// Populate the BundleOpInfo instances and the Use& vector from \p
1783  /// Bundles. Return the op_iterator pointing to the Use& one past the last
1784  /// last bundle operand use.
1785  ///
1786  /// Each \p OperandBundleDef instance is tracked by a OperandBundleInfo
1787  /// instance allocated in this User's descriptor.
1788  op_iterator populateBundleOperandInfos(ArrayRef<OperandBundleDef> Bundles,
1789  const unsigned BeginIndex);
1790 
1791  /// Return the BundleOpInfo for the operand at index OpIdx.
1792  ///
1793  /// It is an error to call this with an OpIdx that does not correspond to an
1794  /// bundle operand.
1795  const BundleOpInfo &getBundleOpInfoForOperand(unsigned OpIdx) const {
1796  for (auto &BOI : bundle_op_infos())
1797  if (BOI.Begin <= OpIdx && OpIdx < BOI.End)
1798  return BOI;
1799 
1800  llvm_unreachable("Did not find operand bundle for operand!");
1801  }
1802 
1803 protected:
1804  /// Return the total number of values used in \p Bundles.
1806  unsigned Total = 0;
1807  for (auto &B : Bundles)
1808  Total += B.input_size();
1809  return Total;
1810  }
1811 
1812  /// @}
1813  // End of operand bundle API.
1814 
1815 private:
1816  bool hasFnAttrOnCalledFunction(Attribute::AttrKind Kind) const;
1817  bool hasFnAttrOnCalledFunction(StringRef Kind) const;
1818 
1819  template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const {
1820  if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind))
1821  return true;
1822 
1823  // Operand bundles override attributes on the called function, but don't
1824  // override attributes directly present on the call instruction.
1825  if (isFnAttrDisallowedByOpBundle(Kind))
1826  return false;
1827 
1828  return hasFnAttrOnCalledFunction(Kind);
1829  }
1830 };
1831 
1832 template <>
1833 struct OperandTraits<CallBase> : public VariadicOperandTraits<CallBase, 1> {};
1834 
1836 
1837 //===----------------------------------------------------------------------===//
1838 // FuncletPadInst Class
1839 //===----------------------------------------------------------------------===//
1840 class FuncletPadInst : public Instruction {
1841 private:
1842  FuncletPadInst(const FuncletPadInst &CPI);
1843 
1844  explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
1845  ArrayRef<Value *> Args, unsigned Values,
1846  const Twine &NameStr, Instruction *InsertBefore);
1847  explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
1848  ArrayRef<Value *> Args, unsigned Values,
1849  const Twine &NameStr, BasicBlock *InsertAtEnd);
1850 
1851  void init(Value *ParentPad, ArrayRef<Value *> Args, const Twine &NameStr);
1852 
1853 protected:
1854  // Note: Instruction needs to be a friend here to call cloneImpl.
1855  friend class Instruction;
1856  friend class CatchPadInst;
1857  friend class CleanupPadInst;
1858 
1859  FuncletPadInst *cloneImpl() const;
1860 
1861 public:
1862  /// Provide fast operand accessors
1864 
1865  /// getNumArgOperands - Return the number of funcletpad arguments.
1866  ///
1867  unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1868 
1869  /// Convenience accessors
1870 
1871  /// Return the outer EH-pad this funclet is nested within.
1872  ///
1873  /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
1874  /// is a CatchPadInst.
1875  Value *getParentPad() const { return Op<-1>(); }
1876  void setParentPad(Value *ParentPad) {
1877  assert(ParentPad);
1878  Op<-1>() = ParentPad;
1879  }
1880 
1881  /// getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
1882  ///
1883  Value *getArgOperand(unsigned i) const { return getOperand(i); }
1884  void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1885 
1886  /// arg_operands - iteration adapter for range-for loops.
1888 
1889  /// arg_operands - iteration adapter for range-for loops.
1891  return const_op_range(op_begin(), op_end() - 1);
1892  }
1893 
1894  // Methods for support type inquiry through isa, cast, and dyn_cast:
1895  static bool classof(const Instruction *I) { return I->isFuncletPad(); }
1896  static bool classof(const Value *V) {
1897  return isa<Instruction>(V) && classof(cast<Instruction>(V));
1898  }
1899 };
1900 
1901 template <>
1903  : public VariadicOperandTraits<FuncletPadInst, /*MINARITY=*/1> {};
1904 
1906 
1907 } // end namespace llvm
1908 
1909 #endif // LLVM_IR_INSTRTYPES_H
bool isFPPredicate() const
Definition: InstrTypes.h:734
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1884
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:178
bool hasOperandBundles() const
Return true if this User has any operand bundles.
Definition: InstrTypes.h:1460
bool hasReadingOperandBundles() const
Return true if this operand bundle user has operand bundles that may read from the heap...
Definition: InstrTypes.h:1575
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition: InstrTypes.h:783
bool hasClobberingOperandBundles() const
Return true if this operand bundle user has operand bundles that may write to the heap...
Definition: InstrTypes.h:1584
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return the attribute object that exists at the arg index.
Definition: Attributes.h:587
bool cannotDuplicate() const
Determine if the invoke cannot be duplicated.
Definition: InstrTypes.h:1416
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:632
unsigned HasDescriptor
Definition: Value.h:121
Type * getSrcTy() const
Return the source type, as a convenience.
Definition: InstrTypes.h:607
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:173
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:250
OperandBundleDefT(std::string Tag, ArrayRef< InputTy > Inputs)
Definition: InstrTypes.h:970
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition: InstrTypes.h:885
bool isFuncletPad() const
Definition: Instruction.h:135
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:230
This class represents lattice values for constants.
Definition: AllocatorList.h:24
BinaryOps getOpcode() const
Definition: InstrTypes.h:312
unsigned getSubclassDataFromInstruction() const
Definition: Instruction.h:741
Various leaf nodes.
Definition: ISDOpcodes.h:60
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:237
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Definition: InstrTypes.h:205
bool isConvergent() const
Determine if the invoke is convergent.
Definition: InstrTypes.h:1422
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
Definition: InstrTypes.h:60
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
unsigned getBundleOperandsStartIndex() const
Return the index of the first bundle operand in the Use array.
Definition: InstrTypes.h:1463
unsigned getNumSubclassExtraOperands() const
Definition: InstrTypes.h:1026
void setDoesNotAccessMemory()
Definition: InstrTypes.h:1353
The two locations do not alias at all.
Definition: AliasAnalysis.h:85
iterator_range< op_iterator > op_range
Definition: User.h:227
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:705
const Use & getOperandUse(unsigned i) const
Definition: User.h:183
void addParamAttr(unsigned ArgNo, Attribute Attr)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1192
static bool classof(const Value *V)
Definition: InstrTypes.h:621
bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const
Return true if the bundle operand at index OpIdx has the attribute A.
Definition: InstrTypes.h:1600
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1084
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1010
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
Definition: InstrTypes.h:1058
unsigned getRetAlignment() const
Return the alignment of the return value.
typename std::vector< InputTy >::const_iterator input_iterator
Definition: InstrTypes.h:980
Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const
Get the attribute of a given kind from a given arg.
Definition: InstrTypes.h:1267
#define op(i)
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
Definition: InstrTypes.h:1494
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: InstrTypes.h:1170
ArrayRef< InputTy > inputs() const
Definition: InstrTypes.h:978
bool isTrueWhenEqual(CondCode Cond)
Return true if the specified condition returns true if the two operands to the condition are equal...
Definition: ISDOpcodes.h:998
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
void setCalledFunction(FunctionType *FTy, Value *Fn)
Sets the function called, including updating to the specified function type.
Definition: InstrTypes.h:1127
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: InstrTypes.h:1311
UnaryInstruction(Type *Ty, unsigned iType, Value *V, Instruction *IB=nullptr)
Definition: InstrTypes.h:55
static BinaryOperator * CreateFSubFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:173
static bool classof(const Instruction *I)
Definition: InstrTypes.h:1039
void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable_or_null attribute to the list of attributes.
Definition: InstrTypes.h:1238
op_iterator op_begin()
Definition: User.h:230
CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
Definition: InstrTypes.h:1019
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:211
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:130
Predicate getSignedPredicate()
For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert.
Definition: InstrTypes.h:831
bool isBundleOperand(unsigned Idx) const
Return true if the operand at index Idx is a bundle operand.
Definition: InstrTypes.h:1475
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1079
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:199
iterator_range< User::const_op_iterator > arg_operands() const
Definition: InstrTypes.h:1073
void removeParamAttr(unsigned ArgNo, StringRef Kind)
Removes the attribute from the given argument.
Definition: InstrTypes.h:1222
The highest possible calling convention ID. Must be some 2^k - 1.
Definition: CallingConv.h:227
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Definition: BitVector.h:938
bool isSigned() const
Definition: InstrTypes.h:812
size_t input_size() const
Definition: InstrTypes.h:982
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
Definition: InstrTypes.h:1501
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
Definition: InstrTypes.h:1384
Used to keep track of an operand bundle.
Definition: InstrTypes.h:1664
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
Definition: InstrTypes.h:741
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Definition: InstrTypes.h:1375
uint64_t getDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown).
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:349
static Constant * getNegativeZero(Type *Ty)
Definition: Constants.cpp:755
bool doesNotReadMemory() const
Determine if the call does not access or only writes memory.
Definition: InstrTypes.h:1366
bundle_op_iterator bundle_op_info_end()
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1757
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr, BasicBlock *InsertAtEnd)
Constructor with insert-at-end-of-block semantics for subclasses.
Definition: InstrTypes.h:358
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
Definition: InstrTypes.h:938
bool isUnsigned() const
Definition: InstrTypes.h:818
void setCalledFunction(Value *Fn)
Sets the function called, including updating the function type.
Definition: InstrTypes.h:1119
This file contains the simple types necessary to represent the attributes associated with functions a...
void removeAttribute(unsigned i, StringRef Kind)
removes the attribute from the list of attributes.
Definition: InstrTypes.h:1207
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:286
bool operator==(const BundleOpInfo &Other) const
Definition: InstrTypes.h:1677
static bool isOrdered(const Instruction *I)
Definition: MemorySSA.cpp:1558
iterator_range< const_op_iterator > const_op_range
Definition: User.h:228
static BinaryOperator * CreateFRemFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:188
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
static unsigned CountBundleInputs(ArrayRef< OperandBundleDef > Bundles)
Return the total number of values used in Bundles.
Definition: InstrTypes.h:1805
OtherOps getOpcode() const
Get the opcode casted to the right type.
Definition: InstrTypes.h:712
bool doesNotThrow() const
Determine if the call cannot unwind.
Definition: InstrTypes.h:1410
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
Class to represent function types.
Definition: DerivedTypes.h:103
static BinaryOperator * CreateFAddFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:168
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition: InstrTypes.h:602
bool hasOperandBundlesOtherThan(ArrayRef< uint32_t > IDs) const
Return true if this operand bundle user contains operand bundles with tags other than those specified...
Definition: InstrTypes.h:1619
const BundleOpInfo & getBundleOpInfoForOperand(unsigned OpIdx) const
Return the BundleOpInfo for the operand at index OpIdx.
Definition: InstrTypes.h:1795
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
void setConvergent()
Definition: InstrTypes.h:1423
bool isFuncletOperandBundle() const
Return true if this is a "funclet" operand bundle.
Definition: InstrTypes.h:948
unsigned getRetAlignment() const
Extract the alignment of the return value.
Definition: InstrTypes.h:1308
void setOnlyReadsMemory()
Definition: InstrTypes.h:1361
Value * getCalledOperand() const
Definition: InstrTypes.h:1101
void setParentPad(Value *ParentPad)
Definition: InstrTypes.h:1876
const_op_range arg_operands() const
arg_operands - iteration adapter for range-for loops.
Definition: InstrTypes.h:1890
void setCalledOperand(Value *V)
Definition: InstrTypes.h:1116
uint64_t getDereferenceableOrNullBytes(unsigned Index) const
Get the number of dereferenceable_or_null bytes (or zero if unknown).
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
OperandBundleUse getOperandBundleForOperand(unsigned OpIdx) const
Return the operand bundle for the operand at index OpIdx.
Definition: InstrTypes.h:1569
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:126
iterator_range< User::op_iterator > arg_operands()
Iteration adapter for range-for loops.
Definition: InstrTypes.h:1070
void setInstructionSubclassData(unsigned short D)
Definition: Instruction.h:736
OperandBundleUse(StringMapEntry< uint32_t > *Tag, ArrayRef< Use > Inputs)
Definition: InstrTypes.h:914
bool doesNoCfCheck() const
Determine if the call should not perform indirect branch tracking.
Definition: InstrTypes.h:1407
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
Definition: InstrTypes.h:1455
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
uint32_t Begin
The index in the Use& vector where operands for this operand bundle starts.
Definition: InstrTypes.h:1671
void setOnlyAccessesInaccessibleMemOrArgMem()
Definition: InstrTypes.h:1396
Value * getOperand(unsigned i) const
Definition: User.h:170
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Definition: InstrTypes.h:1525
bool hasFnAttr(StringRef Kind) const
Determine whether this call has the given attribute.
Definition: InstrTypes.h:1167
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value...
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: InstrTypes.h:876
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:419
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
Definition: InstrTypes.h:1323
static bool isIntPredicate(Predicate P)
Definition: InstrTypes.h:728
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM_NODISCARD AttributeList addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given index.
bool isNoInline() const
Return true if the call should not be inlined.
Definition: InstrTypes.h:1347
Value * getCalledValue() const
Definition: InstrTypes.h:1105
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
void setCannotDuplicate()
Definition: InstrTypes.h:1417
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:403
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Definition: InstrTypes.h:1338
unsigned countOperandBundlesOfType(uint32_t ID) const
Return the number of operand bundles with the tag ID attached to this instruction.
Definition: InstrTypes.h:1512
ArrayRef< Use > Inputs
Definition: InstrTypes.h:911
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void setIsNoInline()
Definition: InstrTypes.h:1348
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:218
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1044
void mutateFunctionType(FunctionType *FTy)
Definition: InstrTypes.h:1046
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
Definition: InstrTypes.h:1482
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Definition: InstrTypes.h:224
op_iterator op_end()
Definition: User.h:232
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Definition: InstrTypes.h:243
ArrayRef< const uint8_t > getDescriptor() const
Returns the descriptor co-allocated with this User instance.
Definition: User.cpp:93
bool isBinaryOp() const
Definition: Instruction.h:131
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1138
static bool classof(const Value *V)
Definition: InstrTypes.h:327
bool isDeoptOperandBundle() const
Return true if this is a "deopt" operand bundle.
Definition: InstrTypes.h:943
unsigned getBundleOperandsEndIndex() const
Return the index of the last bundle operand in the Use array.
Definition: InstrTypes.h:1469
bool hasDescriptor() const
Definition: InstrTypes.h:1024
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
Definition: InstrTypes.h:1393
bool isFnAttrDisallowedByOpBundle(Attribute::AttrKind A) const
Is the function attribute A disallowed by some operand bundle on this operand bundle user...
Definition: InstrTypes.h:1638
static bool classof(const Instruction *I)
Definition: InstrTypes.h:75
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
Definition: InstrTypes.h:1317
const_bundle_op_iterator bundle_op_info_begin() const
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1750
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:54
bool isCast() const
Definition: Instruction.h:134
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
Definition: InstrTypes.h:1160
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Definition: InstrTypes.h:1358
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const_bundle_op_iterator bundle_op_info_end() const
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1767
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
User::const_op_iterator arg_begin() const
Definition: InstrTypes.h:1053
Value * getParentPad() const
Convenience accessors.
Definition: InstrTypes.h:1875
hexagon gen pred
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const
Return true if the operand at index Idx in this operand bundle has the attribute A.
Definition: InstrTypes.h:919
LLVM_NODISCARD AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:452
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1184
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
Definition: PPCPredicates.h:88
bool doesNotReturn() const
Determine if the call cannot return.
Definition: InstrTypes.h:1401
unsigned getNumOperands() const
Definition: User.h:192
bool returnDoesNotAlias() const
Determine if the return value is marked with NoAlias attribute.
Definition: InstrTypes.h:1328
OperandBundleUse operandBundleFromBundleOpInfo(const BundleOpInfo &BOI) const
Simple helper function to map a BundleOpInfo to an OperandBundleUse.
Definition: InstrTypes.h:1685
void setOnlyAccessesInaccessibleMemory()
Definition: InstrTypes.h:1387
OperandBundleDefT(std::string Tag, std::vector< InputTy > Inputs)
Definition: InstrTypes.h:968
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics for subclasses.
Definition: InstrTypes.h:352
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Definition: PPCPredicates.h:27
void setDoesNotReadMemory()
Definition: InstrTypes.h:1369
User::const_op_iterator arg_end() const
Definition: InstrTypes.h:1065
Type * getReturnType() const
Definition: DerivedTypes.h:124
#define DEFINE_HELPERS(OPC, NUWNSWEXACT)
Definition: InstrTypes.h:256
bool hasByValArgument() const
Determine if any call argument is an aggregate passed by value.
Definition: InstrTypes.h:1441
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Definition: InstrTypes.h:1560
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
Definition: InstrTypes.h:1667
Type * getDestTy() const
Return the destination type, as a convenience.
Definition: InstrTypes.h:609
Use & getArgOperandUse(unsigned i)
Definition: InstrTypes.h:1094
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1153
unsigned getNumArgOperands() const
getNumArgOperands - Return the number of funcletpad arguments.
Definition: InstrTypes.h:1867
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:183
bool isCommutative() const
Return true if the instruction is commutative:
Definition: Instruction.h:478
void setValueSubclassData(unsigned short D)
Definition: Value.h:656
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition: InstrTypes.h:722
Predicate getFlippedStrictnessPredicate() const
For predicate of kind "is X or equal to 0" returns the predicate "is X".
Definition: InstrTypes.h:772
void setOperand(unsigned i, Value *Val)
Definition: User.h:175
bool isIntPredicate() const
Definition: InstrTypes.h:735
bool isTrueWhenEqual() const
This is just a convenience.
Definition: InstrTypes.h:837
A range adaptor for a pair of iterators.
Class to represent vector types.
Definition: DerivedTypes.h:393
bool isFalseWhenEqual() const
This is just a convenience.
Definition: InstrTypes.h:843
void setNotConvergent()
Definition: InstrTypes.h:1426
static bool isFPPredicate(Predicate P)
Definition: InstrTypes.h:724
StringRef getTag() const
Definition: InstrTypes.h:986
A lightweight accessor for an operand bundle meant to be passed around by value.
Definition: InstrTypes.h:910
Attribute getAttribute(unsigned i, StringRef Kind) const
Get the attribute of a given kind at a position.
Definition: InstrTypes.h:1256
bool doesNotAccessMemory() const
Determine if the call does not access memory.
Definition: InstrTypes.h:1352
Use & getCalledOperandUse()
Definition: InstrTypes.h:1108
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:249
bool isFnAttrDisallowedByOpBundle(StringRef S) const
Is the function attribute S disallowed by some operand bundle on this operand bundle user...
Definition: InstrTypes.h:1630
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
Get the attribute of a given kind at a position.
Definition: InstrTypes.h:1251
bool hasStructRetAttr() const
Determine if the call returns a structure through first pointer argument.
Definition: InstrTypes.h:1432
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Definition: InstrTypes.h:1052
void addDereferenceableAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
Definition: InstrTypes.h:1230
OperandBundleDefT(const OperandBundleUse &OBU)
Definition: InstrTypes.h:973
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:717
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, BinaryOperator *CopyBO, const Twine &Name="")
Definition: InstrTypes.h:159
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
unsigned getNumArgOperands() const
Definition: InstrTypes.h:1077
Optional< OperandBundleUse > getOperandBundle(uint32_t ID) const
Return an operand bundle by tag ID, if present.
Definition: InstrTypes.h:1541
LLVM_NODISCARD AttributeList addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:652
AttributeList Attrs
parameter attributes for callable
Definition: InstrTypes.h:1015
iterator_range< const_bundle_op_iterator > bundle_op_infos() const
Return the range [bundle_op_info_begin, bundle_op_info_end).
Definition: InstrTypes.h:1778
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1134
input_iterator input_begin() const
Definition: InstrTypes.h:983
LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1112
input_iterator input_end() const
Definition: InstrTypes.h:984
#define I(x, y, z)
Definition: MD5.cpp:58
StringRef getTagName() const
Return the tag of this operand bundle as a string.
Definition: InstrTypes.h:929
uint32_t End
The index in the Use& vector where operands for this operand bundle ends.
Definition: InstrTypes.h:1675
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
Definition: InstrTypes.h:1090
Compile-time customization of User operands.
Definition: User.h:43
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1157
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Definition: InstrTypes.h:1214
static BinaryOperator * CreateFNegFMF(Value *Op, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:193
static BinaryOperator * CreateNeg(Value *S1, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
void setDoesNotReturn()
Definition: InstrTypes.h:1402
bool isStrictFP() const
Determine if the call requires strict floating point semantics.
Definition: InstrTypes.h:1344
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:604
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...
Definition: InstrTypes.h:1609
Instruction(const Instruction &)=delete
static bool classof(const Value *V)
Definition: InstrTypes.h:880
const unsigned Kind
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
op_range arg_operands()
arg_operands - iteration adapter for range-for loops.
Definition: InstrTypes.h:1887
LLVM Value Representation.
Definition: Value.h:73
void setOnlyAccessesArgMemory()
Definition: InstrTypes.h:1378
static bool classof(const Value *V)
Definition: InstrTypes.h:82
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:606
A container for an operand bundle being viewed as a set of values rather than a set of uses...
Definition: InstrTypes.h:963
bundle_op_iterator bundle_op_info_begin()
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1740
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition: InstrTypes.h:757
iterator_range< bundle_op_iterator > bundle_op_infos()
Return the range [bundle_op_info_begin, bundle_op_info_end).
Definition: InstrTypes.h:1773
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:31
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
Definition: InstrTypes.h:1883
Use & Op()
Definition: User.h:134
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Get the attribute of a given kind from a given arg.
Definition: InstrTypes.h:1261
static bool classof(const Instruction *I)
Definition: InstrTypes.h:324
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:69
const Use & getCalledOperandUse() const
Definition: InstrTypes.h:1107
static bool classof(const Instruction *I)
Definition: InstrTypes.h:1895
bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const
Return true if the data operand at index i has the attribute A.
Definition: InstrTypes.h:1285
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: InstrTypes.h:618
void setDoesNotThrow()
Definition: InstrTypes.h:1411
FunctionType * FTy
Definition: InstrTypes.h:1016
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static bool classof(const Value *V)
Definition: InstrTypes.h:1896
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: InstrTypes.h:1200
void addAttribute(unsigned i, Attribute Attr)
adds the attribute to the list of attributes.
Definition: InstrTypes.h:1177
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:70
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1239
Predicate getSwappedPredicate(Predicate Opcode)
Assume the condition register is set by MI(a,b), return the predicate if we modify the instructions s...