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/Constants.h"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/Instruction.h"
31 #include "llvm/IR/LLVMContext.h"
32 #include "llvm/IR/OperandTraits.h"
33 #include "llvm/IR/Type.h"
34 #include "llvm/IR/User.h"
35 #include "llvm/IR/Value.h"
36 #include "llvm/Support/Casting.h"
38 #include <algorithm>
39 #include <cassert>
40 #include <cstddef>
41 #include <cstdint>
42 #include <iterator>
43 #include <string>
44 #include <vector>
45 
46 namespace llvm {
47 
48 //===----------------------------------------------------------------------===//
49 // UnaryInstruction Class
50 //===----------------------------------------------------------------------===//
51 
52 class UnaryInstruction : public Instruction {
53 protected:
54  UnaryInstruction(Type *Ty, unsigned iType, Value *V,
55  Instruction *IB = nullptr)
56  : Instruction(Ty, iType, &Op<0>(), 1, IB) {
57  Op<0>() = V;
58  }
59  UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
60  : Instruction(Ty, iType, &Op<0>(), 1, IAE) {
61  Op<0>() = V;
62  }
63 
64 public:
65  // allocate space for exactly one operand
66  void *operator new(size_t s) {
67  return User::operator new(s, 1);
68  }
69 
70  /// Transparently provide more efficient getOperand methods.
72 
73  // Methods for support type inquiry through isa, cast, and dyn_cast:
74  static bool classof(const Instruction *I) {
75  return I->getOpcode() == Instruction::Alloca ||
76  I->getOpcode() == Instruction::Load ||
77  I->getOpcode() == Instruction::VAArg ||
78  I->getOpcode() == Instruction::ExtractValue ||
79  (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
80  }
81  static bool classof(const Value *V) {
82  return isa<Instruction>(V) && classof(cast<Instruction>(V));
83  }
84 };
85 
86 template <>
88  public FixedNumOperandTraits<UnaryInstruction, 1> {
89 };
90 
92 
93 //===----------------------------------------------------------------------===//
94 // BinaryOperator Class
95 //===----------------------------------------------------------------------===//
96 
97 class BinaryOperator : public Instruction {
98  void AssertOK();
99 
100 protected:
101  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
102  const Twine &Name, Instruction *InsertBefore);
103  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
104  const Twine &Name, BasicBlock *InsertAtEnd);
105 
106  // Note: Instruction needs to be a friend here to call cloneImpl.
107  friend class Instruction;
108 
109  BinaryOperator *cloneImpl() const;
110 
111 public:
112  // allocate space for exactly two operands
113  void *operator new(size_t s) {
114  return User::operator new(s, 2);
115  }
116 
117  /// Transparently provide more efficient getOperand methods.
119 
120  /// Construct a binary instruction, given the opcode and the two
121  /// operands. Optionally (if InstBefore is specified) insert the instruction
122  /// into a BasicBlock right before the specified instruction. The specified
123  /// Instruction is allowed to be a dereferenced end iterator.
124  ///
125  static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
126  const Twine &Name = Twine(),
127  Instruction *InsertBefore = nullptr);
128 
129  /// Construct a binary instruction, given the opcode and the two
130  /// operands. Also automatically insert this instruction to the end of the
131  /// BasicBlock specified.
132  ///
133  static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
134  const Twine &Name, BasicBlock *InsertAtEnd);
135 
136  /// These methods just forward to Create, and are useful when you
137  /// statically know what type of instruction you're going to create. These
138  /// helpers just save some typing.
139 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
140  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
141  const Twine &Name = "") {\
142  return Create(Instruction::OPC, V1, V2, Name);\
143  }
144 #include "llvm/IR/Instruction.def"
145 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
146  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
147  const Twine &Name, BasicBlock *BB) {\
148  return Create(Instruction::OPC, V1, V2, Name, BB);\
149  }
150 #include "llvm/IR/Instruction.def"
151 #define HANDLE_BINARY_INST(N, OPC, CLASS) \
152  static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
153  const Twine &Name, Instruction *I) {\
154  return Create(Instruction::OPC, V1, V2, Name, I);\
155  }
156 #include "llvm/IR/Instruction.def"
157 
159  Value *V1, Value *V2,
160  BinaryOperator *CopyBO,
161  const Twine &Name = "") {
162  BinaryOperator *BO = Create(Opc, V1, V2, Name);
163  BO->copyIRFlags(CopyBO);
164  return BO;
165  }
166 
168  BinaryOperator *FMFSource,
169  const Twine &Name = "") {
170  return CreateWithCopiedFlags(Instruction::FAdd, V1, V2, FMFSource, Name);
171  }
173  BinaryOperator *FMFSource,
174  const Twine &Name = "") {
175  return CreateWithCopiedFlags(Instruction::FSub, V1, V2, FMFSource, Name);
176  }
178  BinaryOperator *FMFSource,
179  const Twine &Name = "") {
180  return CreateWithCopiedFlags(Instruction::FMul, V1, V2, FMFSource, Name);
181  }
183  BinaryOperator *FMFSource,
184  const Twine &Name = "") {
185  return CreateWithCopiedFlags(Instruction::FDiv, V1, V2, FMFSource, Name);
186  }
188  BinaryOperator *FMFSource,
189  const Twine &Name = "") {
190  return CreateWithCopiedFlags(Instruction::FRem, V1, V2, FMFSource, Name);
191  }
193  const Twine &Name = "") {
195  return CreateWithCopiedFlags(Instruction::FSub, Zero, Op, FMFSource);
196  }
197 
199  const Twine &Name = "") {
200  BinaryOperator *BO = Create(Opc, V1, V2, Name);
201  BO->setHasNoSignedWrap(true);
202  return BO;
203  }
205  const Twine &Name, BasicBlock *BB) {
206  BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
207  BO->setHasNoSignedWrap(true);
208  return BO;
209  }
211  const Twine &Name, Instruction *I) {
212  BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
213  BO->setHasNoSignedWrap(true);
214  return BO;
215  }
216 
218  const Twine &Name = "") {
219  BinaryOperator *BO = Create(Opc, V1, V2, Name);
220  BO->setHasNoUnsignedWrap(true);
221  return BO;
222  }
224  const Twine &Name, BasicBlock *BB) {
225  BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
226  BO->setHasNoUnsignedWrap(true);
227  return BO;
228  }
230  const Twine &Name, Instruction *I) {
231  BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
232  BO->setHasNoUnsignedWrap(true);
233  return BO;
234  }
235 
237  const Twine &Name = "") {
238  BinaryOperator *BO = Create(Opc, V1, V2, Name);
239  BO->setIsExact(true);
240  return BO;
241  }
243  const Twine &Name, BasicBlock *BB) {
244  BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
245  BO->setIsExact(true);
246  return BO;
247  }
249  const Twine &Name, Instruction *I) {
250  BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
251  BO->setIsExact(true);
252  return BO;
253  }
254 
255 #define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
256  static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \
257  const Twine &Name = "") { \
258  return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
259  } \
260  static BinaryOperator *Create##NUWNSWEXACT##OPC( \
261  Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \
262  return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \
263  } \
264  static BinaryOperator *Create##NUWNSWEXACT##OPC( \
265  Value *V1, Value *V2, const Twine &Name, Instruction *I) { \
266  return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, I); \
267  }
268 
269  DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
270  DEFINE_HELPERS(Add, NUW) // CreateNUWAdd
271  DEFINE_HELPERS(Sub, NSW) // CreateNSWSub
272  DEFINE_HELPERS(Sub, NUW) // CreateNUWSub
273  DEFINE_HELPERS(Mul, NSW) // CreateNSWMul
274  DEFINE_HELPERS(Mul, NUW) // CreateNUWMul
275  DEFINE_HELPERS(Shl, NSW) // CreateNSWShl
276  DEFINE_HELPERS(Shl, NUW) // CreateNUWShl
277 
278  DEFINE_HELPERS(SDiv, Exact) // CreateExactSDiv
279  DEFINE_HELPERS(UDiv, Exact) // CreateExactUDiv
280  DEFINE_HELPERS(AShr, Exact) // CreateExactAShr
281  DEFINE_HELPERS(LShr, Exact) // CreateExactLShr
282 
283 #undef DEFINE_HELPERS
284 
285  /// Helper functions to construct and inspect unary operations (NEG and NOT)
286  /// via binary operators SUB and XOR:
287  ///
288  /// Create the NEG and NOT instructions out of SUB and XOR instructions.
289  ///
290  static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
291  Instruction *InsertBefore = nullptr);
292  static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
293  BasicBlock *InsertAtEnd);
294  static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name = "",
295  Instruction *InsertBefore = nullptr);
296  static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
297  BasicBlock *InsertAtEnd);
298  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name = "",
299  Instruction *InsertBefore = nullptr);
300  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
301  BasicBlock *InsertAtEnd);
302  static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name = "",
303  Instruction *InsertBefore = nullptr);
304  static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name,
305  BasicBlock *InsertAtEnd);
306  static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
307  Instruction *InsertBefore = nullptr);
308  static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
309  BasicBlock *InsertAtEnd);
310 
311  /// Check if the given Value is a NEG, FNeg, or NOT instruction.
312  ///
313  static bool isNeg(const Value *V);
314  static bool isFNeg(const Value *V, bool IgnoreZeroSign=false);
315  static bool isNot(const Value *V);
316 
317  /// Helper functions to extract the unary argument of a NEG, FNEG or NOT
318  /// operation implemented via Sub, FSub, or Xor.
319  ///
320  static const Value *getNegArgument(const Value *BinOp);
321  static Value *getNegArgument( Value *BinOp);
322  static const Value *getFNegArgument(const Value *BinOp);
323  static Value *getFNegArgument( Value *BinOp);
324  static const Value *getNotArgument(const Value *BinOp);
325  static Value *getNotArgument( Value *BinOp);
326 
328  return static_cast<BinaryOps>(Instruction::getOpcode());
329  }
330 
331  /// Exchange the two operands to this instruction.
332  /// This instruction is safe to use on any binary instruction and
333  /// does not modify the semantics of the instruction. If the instruction
334  /// cannot be reversed (ie, it's a Div), then return true.
335  ///
336  bool swapOperands();
337 
338  // Methods for support type inquiry through isa, cast, and dyn_cast:
339  static bool classof(const Instruction *I) {
340  return I->isBinaryOp();
341  }
342  static bool classof(const Value *V) {
343  return isa<Instruction>(V) && classof(cast<Instruction>(V));
344  }
345 };
346 
347 template <>
349  public FixedNumOperandTraits<BinaryOperator, 2> {
350 };
351 
353 
354 //===----------------------------------------------------------------------===//
355 // CastInst Class
356 //===----------------------------------------------------------------------===//
357 
358 /// This is the base class for all instructions that perform data
359 /// casts. It is simply provided so that instruction category testing
360 /// can be performed with code like:
361 ///
362 /// if (isa<CastInst>(Instr)) { ... }
363 /// Base class of casting instructions.
364 class CastInst : public UnaryInstruction {
365 protected:
366  /// Constructor with insert-before-instruction semantics for subclasses
367  CastInst(Type *Ty, unsigned iType, Value *S,
368  const Twine &NameStr = "", Instruction *InsertBefore = nullptr)
369  : UnaryInstruction(Ty, iType, S, InsertBefore) {
370  setName(NameStr);
371  }
372  /// Constructor with insert-at-end-of-block semantics for subclasses
373  CastInst(Type *Ty, unsigned iType, Value *S,
374  const Twine &NameStr, BasicBlock *InsertAtEnd)
375  : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
376  setName(NameStr);
377  }
378 
379 public:
380  /// Provides a way to construct any of the CastInst subclasses using an
381  /// opcode instead of the subclass's constructor. The opcode must be in the
382  /// CastOps category (Instruction::isCast(opcode) returns true). This
383  /// constructor has insert-before-instruction semantics to automatically
384  /// insert the new CastInst before InsertBefore (if it is non-null).
385  /// Construct any of the CastInst subclasses
386  static CastInst *Create(
387  Instruction::CastOps, ///< The opcode of the cast instruction
388  Value *S, ///< The value to be casted (operand 0)
389  Type *Ty, ///< The type to which cast should be made
390  const Twine &Name = "", ///< Name for the instruction
391  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
392  );
393  /// Provides a way to construct any of the CastInst subclasses using an
394  /// opcode instead of the subclass's constructor. The opcode must be in the
395  /// CastOps category. This constructor has insert-at-end-of-block semantics
396  /// to automatically insert the new CastInst at the end of InsertAtEnd (if
397  /// its non-null).
398  /// Construct any of the CastInst subclasses
399  static CastInst *Create(
400  Instruction::CastOps, ///< The opcode for the cast instruction
401  Value *S, ///< The value to be casted (operand 0)
402  Type *Ty, ///< The type to which operand is casted
403  const Twine &Name, ///< The name for the instruction
404  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
405  );
406 
407  /// Create a ZExt or BitCast cast instruction
408  static CastInst *CreateZExtOrBitCast(
409  Value *S, ///< The value to be casted (operand 0)
410  Type *Ty, ///< The type to which cast should be made
411  const Twine &Name = "", ///< Name for the instruction
412  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
413  );
414 
415  /// Create a ZExt or BitCast cast instruction
416  static CastInst *CreateZExtOrBitCast(
417  Value *S, ///< The value to be casted (operand 0)
418  Type *Ty, ///< The type to which operand is casted
419  const Twine &Name, ///< The name for the instruction
420  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
421  );
422 
423  /// Create a SExt or BitCast cast instruction
424  static CastInst *CreateSExtOrBitCast(
425  Value *S, ///< The value to be casted (operand 0)
426  Type *Ty, ///< The type to which cast should be made
427  const Twine &Name = "", ///< Name for the instruction
428  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
429  );
430 
431  /// Create a SExt or BitCast cast instruction
432  static CastInst *CreateSExtOrBitCast(
433  Value *S, ///< The value to be casted (operand 0)
434  Type *Ty, ///< The type to which operand is casted
435  const Twine &Name, ///< The name for the instruction
436  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
437  );
438 
439  /// Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
440  static CastInst *CreatePointerCast(
441  Value *S, ///< The pointer value to be casted (operand 0)
442  Type *Ty, ///< The type to which operand is casted
443  const Twine &Name, ///< The name for the instruction
444  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
445  );
446 
447  /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
448  static CastInst *CreatePointerCast(
449  Value *S, ///< The pointer value to be casted (operand 0)
450  Type *Ty, ///< The type to which cast should be made
451  const Twine &Name = "", ///< Name for the instruction
452  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
453  );
454 
455  /// Create a BitCast or an AddrSpaceCast cast instruction.
456  static CastInst *CreatePointerBitCastOrAddrSpaceCast(
457  Value *S, ///< The pointer value to be casted (operand 0)
458  Type *Ty, ///< The type to which operand is casted
459  const Twine &Name, ///< The name for the instruction
460  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
461  );
462 
463  /// Create a BitCast or an AddrSpaceCast cast instruction.
464  static CastInst *CreatePointerBitCastOrAddrSpaceCast(
465  Value *S, ///< The pointer value to be casted (operand 0)
466  Type *Ty, ///< The type to which cast should be made
467  const Twine &Name = "", ///< Name for the instruction
468  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
469  );
470 
471  /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
472  ///
473  /// If the value is a pointer type and the destination an integer type,
474  /// creates a PtrToInt cast. If the value is an integer type and the
475  /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
476  /// a bitcast.
477  static CastInst *CreateBitOrPointerCast(
478  Value *S, ///< The pointer value to be casted (operand 0)
479  Type *Ty, ///< The type to which cast should be made
480  const Twine &Name = "", ///< Name for the instruction
481  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
482  );
483 
484  /// Create a ZExt, BitCast, or Trunc for int -> int casts.
485  static CastInst *CreateIntegerCast(
486  Value *S, ///< The pointer value to be casted (operand 0)
487  Type *Ty, ///< The type to which cast should be made
488  bool isSigned, ///< Whether to regard S as signed or not
489  const Twine &Name = "", ///< Name for the instruction
490  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
491  );
492 
493  /// Create a ZExt, BitCast, or Trunc for int -> int casts.
494  static CastInst *CreateIntegerCast(
495  Value *S, ///< The integer value to be casted (operand 0)
496  Type *Ty, ///< The integer type to which operand is casted
497  bool isSigned, ///< Whether to regard S as signed or not
498  const Twine &Name, ///< The name for the instruction
499  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
500  );
501 
502  /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
503  static CastInst *CreateFPCast(
504  Value *S, ///< The floating point value to be casted
505  Type *Ty, ///< The floating point type to cast to
506  const Twine &Name = "", ///< Name for the instruction
507  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
508  );
509 
510  /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
511  static CastInst *CreateFPCast(
512  Value *S, ///< The floating point value to be casted
513  Type *Ty, ///< The floating point type to cast to
514  const Twine &Name, ///< The name for the instruction
515  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
516  );
517 
518  /// Create a Trunc or BitCast cast instruction
519  static CastInst *CreateTruncOrBitCast(
520  Value *S, ///< The value to be casted (operand 0)
521  Type *Ty, ///< The type to which cast should be made
522  const Twine &Name = "", ///< Name for the instruction
523  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
524  );
525 
526  /// Create a Trunc or BitCast cast instruction
527  static CastInst *CreateTruncOrBitCast(
528  Value *S, ///< The value to be casted (operand 0)
529  Type *Ty, ///< The type to which operand is casted
530  const Twine &Name, ///< The name for the instruction
531  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
532  );
533 
534  /// Check whether it is valid to call getCastOpcode for these types.
535  static bool isCastable(
536  Type *SrcTy, ///< The Type from which the value should be cast.
537  Type *DestTy ///< The Type to which the value should be cast.
538  );
539 
540  /// Check whether a bitcast between these types is valid
541  static bool isBitCastable(
542  Type *SrcTy, ///< The Type from which the value should be cast.
543  Type *DestTy ///< The Type to which the value should be cast.
544  );
545 
546  /// Check whether a bitcast, inttoptr, or ptrtoint cast between these
547  /// types is valid and a no-op.
548  ///
549  /// This ensures that any pointer<->integer cast has enough bits in the
550  /// integer and any other cast is a bitcast.
551  static bool isBitOrNoopPointerCastable(
552  Type *SrcTy, ///< The Type from which the value should be cast.
553  Type *DestTy, ///< The Type to which the value should be cast.
554  const DataLayout &DL);
555 
556  /// Returns the opcode necessary to cast Val into Ty using usual casting
557  /// rules.
558  /// Infer the opcode for cast operand and type
559  static Instruction::CastOps getCastOpcode(
560  const Value *Val, ///< The value to cast
561  bool SrcIsSigned, ///< Whether to treat the source as signed
562  Type *Ty, ///< The Type to which the value should be casted
563  bool DstIsSigned ///< Whether to treate the dest. as signed
564  );
565 
566  /// There are several places where we need to know if a cast instruction
567  /// only deals with integer source and destination types. To simplify that
568  /// logic, this method is provided.
569  /// @returns true iff the cast has only integral typed operand and dest type.
570  /// Determine if this is an integer-only cast.
571  bool isIntegerCast() const;
572 
573  /// A lossless cast is one that does not alter the basic value. It implies
574  /// a no-op cast but is more stringent, preventing things like int->float,
575  /// long->double, or int->ptr.
576  /// @returns true iff the cast is lossless.
577  /// Determine if this is a lossless cast.
578  bool isLosslessCast() const;
579 
580  /// A no-op cast is one that can be effected without changing any bits.
581  /// It implies that the source and destination types are the same size. The
582  /// DataLayout argument is to determine the pointer size when examining casts
583  /// involving Integer and Pointer types. They are no-op casts if the integer
584  /// is the same size as the pointer. However, pointer size varies with
585  /// platform.
586  /// Determine if the described cast is a no-op cast.
587  static bool isNoopCast(
588  Instruction::CastOps Opcode, ///< Opcode of cast
589  Type *SrcTy, ///< SrcTy of cast
590  Type *DstTy, ///< DstTy of cast
591  const DataLayout &DL ///< DataLayout to get the Int Ptr type from.
592  );
593 
594  /// Determine if this cast is a no-op cast.
595  ///
596  /// \param DL is the DataLayout to determine pointer size.
597  bool isNoopCast(const DataLayout &DL) const;
598 
599  /// Determine how a pair of casts can be eliminated, if they can be at all.
600  /// This is a helper function for both CastInst and ConstantExpr.
601  /// @returns 0 if the CastInst pair can't be eliminated, otherwise
602  /// returns Instruction::CastOps value for a cast that can replace
603  /// the pair, casting SrcTy to DstTy.
604  /// Determine if a cast pair is eliminable
605  static unsigned isEliminableCastPair(
606  Instruction::CastOps firstOpcode, ///< Opcode of first cast
607  Instruction::CastOps secondOpcode, ///< Opcode of second cast
608  Type *SrcTy, ///< SrcTy of 1st cast
609  Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
610  Type *DstTy, ///< DstTy of 2nd cast
611  Type *SrcIntPtrTy, ///< Integer type corresponding to Ptr SrcTy, or null
612  Type *MidIntPtrTy, ///< Integer type corresponding to Ptr MidTy, or null
613  Type *DstIntPtrTy ///< Integer type corresponding to Ptr DstTy, or null
614  );
615 
616  /// Return the opcode of this CastInst
619  }
620 
621  /// Return the source type, as a convenience
622  Type* getSrcTy() const { return getOperand(0)->getType(); }
623  /// Return the destination type, as a convenience
624  Type* getDestTy() const { return getType(); }
625 
626  /// This method can be used to determine if a cast from S to DstTy using
627  /// Opcode op is valid or not.
628  /// @returns true iff the proposed cast is valid.
629  /// Determine if a cast is valid without creating one.
630  static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy);
631 
632  /// Methods for support type inquiry through isa, cast, and dyn_cast:
633  static bool classof(const Instruction *I) {
634  return I->isCast();
635  }
636  static bool classof(const Value *V) {
637  return isa<Instruction>(V) && classof(cast<Instruction>(V));
638  }
639 };
640 
641 //===----------------------------------------------------------------------===//
642 // CmpInst Class
643 //===----------------------------------------------------------------------===//
644 
645 /// This class is the base class for the comparison instructions.
646 /// Abstract base class of comparison instructions.
647 class CmpInst : public Instruction {
648 public:
649  /// This enumeration lists the possible predicates for CmpInst subclasses.
650  /// Values in the range 0-31 are reserved for FCmpInst, while values in the
651  /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
652  /// predicate values are not overlapping between the classes.
653  ///
654  /// Some passes (e.g. InstCombine) depend on the bit-wise characteristics of
655  /// FCMP_* values. Changing the bit patterns requires a potential change to
656  /// those passes.
657  enum Predicate {
658  // Opcode U L G E Intuitive operation
659  FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
660  FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
661  FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
662  FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
663  FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
664  FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
665  FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
666  FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
667  FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
668  FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
669  FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than
670  FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal
671  FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than
672  FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal
673  FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal
674  FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded)
675  FIRST_FCMP_PREDICATE = FCMP_FALSE,
676  LAST_FCMP_PREDICATE = FCMP_TRUE,
677  BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
678  ICMP_EQ = 32, ///< equal
679  ICMP_NE = 33, ///< not equal
680  ICMP_UGT = 34, ///< unsigned greater than
681  ICMP_UGE = 35, ///< unsigned greater or equal
682  ICMP_ULT = 36, ///< unsigned less than
683  ICMP_ULE = 37, ///< unsigned less or equal
684  ICMP_SGT = 38, ///< signed greater than
685  ICMP_SGE = 39, ///< signed greater or equal
686  ICMP_SLT = 40, ///< signed less than
687  ICMP_SLE = 41, ///< signed less or equal
688  FIRST_ICMP_PREDICATE = ICMP_EQ,
689  LAST_ICMP_PREDICATE = ICMP_SLE,
690  BAD_ICMP_PREDICATE = ICMP_SLE + 1
691  };
692 
693 protected:
695  Value *LHS, Value *RHS, const Twine &Name = "",
696  Instruction *InsertBefore = nullptr);
697 
699  Value *LHS, Value *RHS, const Twine &Name,
700  BasicBlock *InsertAtEnd);
701 
702 public:
703  // allocate space for exactly two operands
704  void *operator new(size_t s) {
705  return User::operator new(s, 2);
706  }
707 
708  /// Construct a compare instruction, given the opcode, the predicate and
709  /// the two operands. Optionally (if InstBefore is specified) insert the
710  /// instruction into a BasicBlock right before the specified instruction.
711  /// The specified Instruction is allowed to be a dereferenced end iterator.
712  /// Create a CmpInst
713  static CmpInst *Create(OtherOps Op,
714  Predicate predicate, Value *S1,
715  Value *S2, const Twine &Name = "",
716  Instruction *InsertBefore = nullptr);
717 
718  /// Construct a compare instruction, given the opcode, the predicate and the
719  /// two operands. Also automatically insert this instruction to the end of
720  /// the BasicBlock specified.
721  /// Create a CmpInst
722  static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1,
723  Value *S2, const Twine &Name, BasicBlock *InsertAtEnd);
724 
725  /// Get the opcode casted to the right type
726  OtherOps getOpcode() const {
727  return static_cast<OtherOps>(Instruction::getOpcode());
728  }
729 
730  /// Return the predicate for this instruction.
733  }
734 
735  /// Set the predicate for this instruction to the specified value.
737 
738  static bool isFPPredicate(Predicate P) {
739  return P >= FIRST_FCMP_PREDICATE && P <= LAST_FCMP_PREDICATE;
740  }
741 
742  static bool isIntPredicate(Predicate P) {
743  return P >= FIRST_ICMP_PREDICATE && P <= LAST_ICMP_PREDICATE;
744  }
745 
746  static StringRef getPredicateName(Predicate P);
747 
748  bool isFPPredicate() const { return isFPPredicate(getPredicate()); }
749  bool isIntPredicate() const { return isIntPredicate(getPredicate()); }
750 
751  /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
752  /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
753  /// @returns the inverse predicate for the instruction's current predicate.
754  /// Return the inverse of the instruction's predicate.
756  return getInversePredicate(getPredicate());
757  }
758 
759  /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
760  /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
761  /// @returns the inverse predicate for predicate provided in \p pred.
762  /// Return the inverse of a given predicate
763  static Predicate getInversePredicate(Predicate pred);
764 
765  /// For example, EQ->EQ, SLE->SGE, ULT->UGT,
766  /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
767  /// @returns the predicate that would be the result of exchanging the two
768  /// operands of the CmpInst instruction without changing the result
769  /// produced.
770  /// Return the predicate as if the operands were swapped
773  }
774 
775  /// This is a static version that you can use without an instruction
776  /// available.
777  /// Return the predicate as if the operands were swapped.
779 
780  /// For predicate of kind "is X or equal to 0" returns the predicate "is X".
781  /// For predicate of kind "is X" returns the predicate "is X or equal to 0".
782  /// does not support other kind of predicates.
783  /// @returns the predicate that does not contains is equal to zero if
784  /// it had and vice versa.
785  /// Return the flipped strictness of predicate
787  return getFlippedStrictnessPredicate(getPredicate());
788  }
789 
790  /// This is a static version that you can use without an instruction
791  /// available.
792  /// Return the flipped strictness of predicate
793  static Predicate getFlippedStrictnessPredicate(Predicate pred);
794 
795  /// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
796  /// Returns the non-strict version of strict comparisons.
798  return getNonStrictPredicate(getPredicate());
799  }
800 
801  /// This is a static version that you can use without an instruction
802  /// available.
803  /// @returns the non-strict version of comparison provided in \p pred.
804  /// If \p pred is not a strict comparison predicate, returns \p pred.
805  /// Returns the non-strict version of strict comparisons.
806  static Predicate getNonStrictPredicate(Predicate pred);
807 
808  /// Provide more efficient getOperand methods.
810 
811  /// This is just a convenience that dispatches to the subclasses.
812  /// Swap the operands and adjust predicate accordingly to retain
813  /// the same comparison.
814  void swapOperands();
815 
816  /// This is just a convenience that dispatches to the subclasses.
817  /// Determine if this CmpInst is commutative.
818  bool isCommutative() const;
819 
820  /// This is just a convenience that dispatches to the subclasses.
821  /// Determine if this is an equals/not equals predicate.
822  bool isEquality() const;
823 
824  /// @returns true if the comparison is signed, false otherwise.
825  /// Determine if this instruction is using a signed comparison.
826  bool isSigned() const {
827  return isSigned(getPredicate());
828  }
829 
830  /// @returns true if the comparison is unsigned, false otherwise.
831  /// Determine if this instruction is using an unsigned comparison.
832  bool isUnsigned() const {
833  return isUnsigned(getPredicate());
834  }
835 
836  /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
837  /// @returns the signed version of the unsigned predicate pred.
838  /// return the signed version of a predicate
839  static Predicate getSignedPredicate(Predicate pred);
840 
841  /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
842  /// @returns the signed version of the predicate for this instruction (which
843  /// has to be an unsigned predicate).
844  /// return the signed version of a predicate
846  return getSignedPredicate(getPredicate());
847  }
848 
849  /// This is just a convenience.
850  /// Determine if this is true when both operands are the same.
851  bool isTrueWhenEqual() const {
852  return isTrueWhenEqual(getPredicate());
853  }
854 
855  /// This is just a convenience.
856  /// Determine if this is false when both operands are the same.
857  bool isFalseWhenEqual() const {
858  return isFalseWhenEqual(getPredicate());
859  }
860 
861  /// @returns true if the predicate is unsigned, false otherwise.
862  /// Determine if the predicate is an unsigned operation.
863  static bool isUnsigned(Predicate predicate);
864 
865  /// @returns true if the predicate is signed, false otherwise.
866  /// Determine if the predicate is an signed operation.
867  static bool isSigned(Predicate predicate);
868 
869  /// Determine if the predicate is an ordered operation.
870  static bool isOrdered(Predicate predicate);
871 
872  /// Determine if the predicate is an unordered operation.
873  static bool isUnordered(Predicate predicate);
874 
875  /// Determine if the predicate is true when comparing a value with itself.
876  static bool isTrueWhenEqual(Predicate predicate);
877 
878  /// Determine if the predicate is false when comparing a value with itself.
879  static bool isFalseWhenEqual(Predicate predicate);
880 
881  /// Determine if Pred1 implies Pred2 is true when two compares have matching
882  /// operands.
883  static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2);
884 
885  /// Determine if Pred1 implies Pred2 is false when two compares have matching
886  /// operands.
887  static bool isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2);
888 
889  /// Methods for support type inquiry through isa, cast, and dyn_cast:
890  static bool classof(const Instruction *I) {
891  return I->getOpcode() == Instruction::ICmp ||
892  I->getOpcode() == Instruction::FCmp;
893  }
894  static bool classof(const Value *V) {
895  return isa<Instruction>(V) && classof(cast<Instruction>(V));
896  }
897 
898  /// Create a result type for fcmp/icmp
899  static Type* makeCmpResultType(Type* opnd_type) {
900  if (VectorType* vt = dyn_cast<VectorType>(opnd_type)) {
901  return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
902  vt->getNumElements());
903  }
904  return Type::getInt1Ty(opnd_type->getContext());
905  }
906 
907 private:
908  // Shadow Value::setValueSubclassData with a private forwarding method so that
909  // subclasses cannot accidentally use it.
910  void setValueSubclassData(unsigned short D) {
912  }
913 };
914 
915 // FIXME: these are redundant if CmpInst < BinaryOperator
916 template <>
917 struct OperandTraits<CmpInst> : public FixedNumOperandTraits<CmpInst, 2> {
918 };
919 
921 
922 //===----------------------------------------------------------------------===//
923 // FuncletPadInst Class
924 //===----------------------------------------------------------------------===//
925 class FuncletPadInst : public Instruction {
926 private:
927  FuncletPadInst(const FuncletPadInst &CPI);
928 
929  explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
930  ArrayRef<Value *> Args, unsigned Values,
931  const Twine &NameStr, Instruction *InsertBefore);
932  explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
933  ArrayRef<Value *> Args, unsigned Values,
934  const Twine &NameStr, BasicBlock *InsertAtEnd);
935 
936  void init(Value *ParentPad, ArrayRef<Value *> Args, const Twine &NameStr);
937 
938 protected:
939  // Note: Instruction needs to be a friend here to call cloneImpl.
940  friend class Instruction;
941  friend class CatchPadInst;
942  friend class CleanupPadInst;
943 
944  FuncletPadInst *cloneImpl() const;
945 
946 public:
947  /// Provide fast operand accessors
949 
950  /// getNumArgOperands - Return the number of funcletpad arguments.
951  ///
952  unsigned getNumArgOperands() const { return getNumOperands() - 1; }
953 
954  /// Convenience accessors
955 
956  /// Return the outer EH-pad this funclet is nested within.
957  ///
958  /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
959  /// is a CatchPadInst.
960  Value *getParentPad() const { return Op<-1>(); }
961  void setParentPad(Value *ParentPad) {
962  assert(ParentPad);
963  Op<-1>() = ParentPad;
964  }
965 
966  /// getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
967  ///
968  Value *getArgOperand(unsigned i) const { return getOperand(i); }
969  void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
970 
971  /// arg_operands - iteration adapter for range-for loops.
972  op_range arg_operands() { return op_range(op_begin(), op_end() - 1); }
973 
974  /// arg_operands - iteration adapter for range-for loops.
976  return const_op_range(op_begin(), op_end() - 1);
977  }
978 
979  // Methods for support type inquiry through isa, cast, and dyn_cast:
980  static bool classof(const Instruction *I) { return I->isFuncletPad(); }
981  static bool classof(const Value *V) {
982  return isa<Instruction>(V) && classof(cast<Instruction>(V));
983  }
984 };
985 
986 template <>
988  : public VariadicOperandTraits<FuncletPadInst, /*MINARITY=*/1> {};
989 
991 
992 /// A lightweight accessor for an operand bundle meant to be passed
993 /// around by value.
996 
997  OperandBundleUse() = default;
999  : Inputs(Inputs), Tag(Tag) {}
1000 
1001  /// Return true if the operand at index \p Idx in this operand bundle
1002  /// has the attribute A.
1003  bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const {
1004  if (isDeoptOperandBundle())
1005  if (A == Attribute::ReadOnly || A == Attribute::NoCapture)
1006  return Inputs[Idx]->getType()->isPointerTy();
1007 
1008  // Conservative answer: no operands have any attributes.
1009  return false;
1010  }
1011 
1012  /// Return the tag of this operand bundle as a string.
1014  return Tag->getKey();
1015  }
1016 
1017  /// Return the tag of this operand bundle as an integer.
1018  ///
1019  /// Operand bundle tags are interned by LLVMContextImpl::getOrInsertBundleTag,
1020  /// and this function returns the unique integer getOrInsertBundleTag
1021  /// associated the tag of this operand bundle to.
1022  uint32_t getTagID() const {
1023  return Tag->getValue();
1024  }
1025 
1026  /// Return true if this is a "deopt" operand bundle.
1027  bool isDeoptOperandBundle() const {
1028  return getTagID() == LLVMContext::OB_deopt;
1029  }
1030 
1031  /// Return true if this is a "funclet" operand bundle.
1032  bool isFuncletOperandBundle() const {
1033  return getTagID() == LLVMContext::OB_funclet;
1034  }
1035 
1036 private:
1037  /// Pointer to an entry in LLVMContextImpl::getOrInsertBundleTag.
1039 };
1040 
1041 /// A container for an operand bundle being viewed as a set of values
1042 /// rather than a set of uses.
1043 ///
1044 /// Unlike OperandBundleUse, OperandBundleDefT owns the memory it carries, and
1045 /// so it is possible to create and pass around "self-contained" instances of
1046 /// OperandBundleDef and ConstOperandBundleDef.
1047 template <typename InputTy> class OperandBundleDefT {
1048  std::string Tag;
1049  std::vector<InputTy> Inputs;
1050 
1051 public:
1052  explicit OperandBundleDefT(std::string Tag, std::vector<InputTy> Inputs)
1053  : Tag(std::move(Tag)), Inputs(std::move(Inputs)) {}
1054  explicit OperandBundleDefT(std::string Tag, ArrayRef<InputTy> Inputs)
1055  : Tag(std::move(Tag)), Inputs(Inputs) {}
1056 
1057  explicit OperandBundleDefT(const OperandBundleUse &OBU) {
1058  Tag = OBU.getTagName();
1059  Inputs.insert(Inputs.end(), OBU.Inputs.begin(), OBU.Inputs.end());
1060  }
1061 
1062  ArrayRef<InputTy> inputs() const { return Inputs; }
1063 
1064  using input_iterator = typename std::vector<InputTy>::const_iterator;
1065 
1066  size_t input_size() const { return Inputs.size(); }
1067  input_iterator input_begin() const { return Inputs.begin(); }
1068  input_iterator input_end() const { return Inputs.end(); }
1069 
1070  StringRef getTag() const { return Tag; }
1071 };
1072 
1075 
1076 /// A mixin to add operand bundle functionality to llvm instruction
1077 /// classes.
1078 ///
1079 /// OperandBundleUser uses the descriptor area co-allocated with the host User
1080 /// to store some meta information about which operands are "normal" operands,
1081 /// and which ones belong to some operand bundle.
1082 ///
1083 /// The layout of an operand bundle user is
1084 ///
1085 /// +-----------uint32_t End-------------------------------------+
1086 /// | |
1087 /// | +--------uint32_t Begin--------------------+ |
1088 /// | | | |
1089 /// ^ ^ v v
1090 /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
1091 /// | BOI0 | BOI1 | .. | DU | U0 | U1 | .. | BOI0_U0 | .. | BOI1_U0 | .. | Un
1092 /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
1093 /// v v ^ ^
1094 /// | | | |
1095 /// | +--------uint32_t Begin------------+ |
1096 /// | |
1097 /// +-----------uint32_t End-----------------------------+
1098 ///
1099 ///
1100 /// BOI0, BOI1 ... are descriptions of operand bundles in this User's use list.
1101 /// These descriptions are installed and managed by this class, and they're all
1102 /// instances of OperandBundleUser<T>::BundleOpInfo.
1103 ///
1104 /// DU is an additional descriptor installed by User's 'operator new' to keep
1105 /// track of the 'BOI0 ... BOIN' co-allocation. OperandBundleUser does not
1106 /// access or modify DU in any way, it's an implementation detail private to
1107 /// User.
1108 ///
1109 /// The regular Use& vector for the User starts at U0. The operand bundle uses
1110 /// are part of the Use& vector, just like normal uses. In the diagram above,
1111 /// the operand bundle uses start at BOI0_U0. Each instance of BundleOpInfo has
1112 /// information about a contiguous set of uses constituting an operand bundle,
1113 /// and the total set of operand bundle uses themselves form a contiguous set of
1114 /// uses (i.e. there are no gaps between uses corresponding to individual
1115 /// operand bundles).
1116 ///
1117 /// This class does not know the location of the set of operand bundle uses
1118 /// within the use list -- that is decided by the User using this class via the
1119 /// BeginIdx argument in populateBundleOperandInfos.
1120 ///
1121 /// Currently operand bundle users with hung-off operands are not supported.
1122 template <typename InstrTy, typename OpIteratorTy> class OperandBundleUser {
1123 public:
1124  /// Return the number of operand bundles associated with this User.
1125  unsigned getNumOperandBundles() const {
1126  return std::distance(bundle_op_info_begin(), bundle_op_info_end());
1127  }
1128 
1129  /// Return true if this User has any operand bundles.
1130  bool hasOperandBundles() const { return getNumOperandBundles() != 0; }
1131 
1132  /// Return the index of the first bundle operand in the Use array.
1133  unsigned getBundleOperandsStartIndex() const {
1134  assert(hasOperandBundles() && "Don't call otherwise!");
1135  return bundle_op_info_begin()->Begin;
1136  }
1137 
1138  /// Return the index of the last bundle operand in the Use array.
1139  unsigned getBundleOperandsEndIndex() const {
1140  assert(hasOperandBundles() && "Don't call otherwise!");
1141  return bundle_op_info_end()[-1].End;
1142  }
1143 
1144  /// Return true if the operand at index \p Idx is a bundle operand.
1145  bool isBundleOperand(unsigned Idx) const {
1146  return hasOperandBundles() && Idx >= getBundleOperandsStartIndex() &&
1147  Idx < getBundleOperandsEndIndex();
1148  }
1149 
1150  /// Return the total number operands (not operand bundles) used by
1151  /// every operand bundle in this OperandBundleUser.
1152  unsigned getNumTotalBundleOperands() const {
1153  if (!hasOperandBundles())
1154  return 0;
1155 
1156  unsigned Begin = getBundleOperandsStartIndex();
1157  unsigned End = getBundleOperandsEndIndex();
1158 
1159  assert(Begin <= End && "Should be!");
1160  return End - Begin;
1161  }
1162 
1163  /// Return the operand bundle at a specific index.
1165  assert(Index < getNumOperandBundles() && "Index out of bounds!");
1166  return operandBundleFromBundleOpInfo(*(bundle_op_info_begin() + Index));
1167  }
1168 
1169  /// Return the number of operand bundles with the tag Name attached to
1170  /// this instruction.
1172  unsigned Count = 0;
1173  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1174  if (getOperandBundleAt(i).getTagName() == Name)
1175  Count++;
1176 
1177  return Count;
1178  }
1179 
1180  /// Return the number of operand bundles with the tag ID attached to
1181  /// this instruction.
1183  unsigned Count = 0;
1184  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1185  if (getOperandBundleAt(i).getTagID() == ID)
1186  Count++;
1187 
1188  return Count;
1189  }
1190 
1191  /// Return an operand bundle by name, if present.
1192  ///
1193  /// It is an error to call this for operand bundle types that may have
1194  /// multiple instances of them on the same instruction.
1196  assert(countOperandBundlesOfType(Name) < 2 && "Precondition violated!");
1197 
1198  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1199  OperandBundleUse U = getOperandBundleAt(i);
1200  if (U.getTagName() == Name)
1201  return U;
1202  }
1203 
1204  return None;
1205  }
1206 
1207  /// Return an operand bundle by tag ID, if present.
1208  ///
1209  /// It is an error to call this for operand bundle types that may have
1210  /// multiple instances of them on the same instruction.
1212  assert(countOperandBundlesOfType(ID) < 2 && "Precondition violated!");
1213 
1214  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1215  OperandBundleUse U = getOperandBundleAt(i);
1216  if (U.getTagID() == ID)
1217  return U;
1218  }
1219 
1220  return None;
1221  }
1222 
1223  /// Return the list of operand bundles attached to this instruction as
1224  /// a vector of OperandBundleDefs.
1225  ///
1226  /// This function copies the OperandBundeUse instances associated with this
1227  /// OperandBundleUser to a vector of OperandBundleDefs. Note:
1228  /// OperandBundeUses and OperandBundleDefs are non-trivially *different*
1229  /// representations of operand bundles (see documentation above).
1231  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1232  Defs.emplace_back(getOperandBundleAt(i));
1233  }
1234 
1235  /// Return the operand bundle for the operand at index OpIdx.
1236  ///
1237  /// It is an error to call this with an OpIdx that does not correspond to an
1238  /// bundle operand.
1240  return operandBundleFromBundleOpInfo(getBundleOpInfoForOperand(OpIdx));
1241  }
1242 
1243  /// Return true if this operand bundle user has operand bundles that
1244  /// may read from the heap.
1246  // Implementation note: this is a conservative implementation of operand
1247  // bundle semantics, where *any* operand bundle forces a callsite to be at
1248  // least readonly.
1249  return hasOperandBundles();
1250  }
1251 
1252  /// Return true if this operand bundle user has operand bundles that
1253  /// may write to the heap.
1255  for (auto &BOI : bundle_op_infos()) {
1256  if (BOI.Tag->second == LLVMContext::OB_deopt ||
1257  BOI.Tag->second == LLVMContext::OB_funclet)
1258  continue;
1259 
1260  // This instruction has an operand bundle that is not known to us.
1261  // Assume the worst.
1262  return true;
1263  }
1264 
1265  return false;
1266  }
1267 
1268  /// Return true if the bundle operand at index \p OpIdx has the
1269  /// attribute \p A.
1270  bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const {
1271  auto &BOI = getBundleOpInfoForOperand(OpIdx);
1272  auto OBU = operandBundleFromBundleOpInfo(BOI);
1273  return OBU.operandHasAttr(OpIdx - BOI.Begin, A);
1274  }
1275 
1276  /// Return true if \p Other has the same sequence of operand bundle
1277  /// tags with the same number of operands on each one of them as this
1278  /// OperandBundleUser.
1280  const OperandBundleUser<InstrTy, OpIteratorTy> &Other) const {
1281  if (getNumOperandBundles() != Other.getNumOperandBundles())
1282  return false;
1283 
1284  return std::equal(bundle_op_info_begin(), bundle_op_info_end(),
1285  Other.bundle_op_info_begin());
1286  }
1287 
1288  /// Return true if this operand bundle user contains operand bundles
1289  /// with tags other than those specified in \p IDs.
1291  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1292  uint32_t ID = getOperandBundleAt(i).getTagID();
1293  if (!is_contained(IDs, ID))
1294  return true;
1295  }
1296  return false;
1297  }
1298 
1299 protected:
1300  /// Is the function attribute S disallowed by some operand bundle on
1301  /// this operand bundle user?
1303  // Operand bundles only possibly disallow readnone, readonly and argmenonly
1304  // attributes. All String attributes are fine.
1305  return false;
1306  }
1307 
1308  /// Is the function attribute A disallowed by some operand bundle on
1309  /// this operand bundle user?
1311  switch (A) {
1312  default:
1313  return false;
1314 
1315  case Attribute::InaccessibleMemOrArgMemOnly:
1316  return hasReadingOperandBundles();
1317 
1318  case Attribute::InaccessibleMemOnly:
1319  return hasReadingOperandBundles();
1320 
1321  case Attribute::ArgMemOnly:
1322  return hasReadingOperandBundles();
1323 
1324  case Attribute::ReadNone:
1325  return hasReadingOperandBundles();
1326 
1327  case Attribute::ReadOnly:
1328  return hasClobberingOperandBundles();
1329  }
1330 
1331  llvm_unreachable("switch has a default case!");
1332  }
1333 
1334  /// Used to keep track of an operand bundle. See the main comment on
1335  /// OperandBundleUser above.
1336  struct BundleOpInfo {
1337  /// The operand bundle tag, interned by
1338  /// LLVMContextImpl::getOrInsertBundleTag.
1340 
1341  /// The index in the Use& vector where operands for this operand
1342  /// bundle starts.
1344 
1345  /// The index in the Use& vector where operands for this operand
1346  /// bundle ends.
1348 
1349  bool operator==(const BundleOpInfo &Other) const {
1350  return Tag == Other.Tag && Begin == Other.Begin && End == Other.End;
1351  }
1352  };
1353 
1354  /// Simple helper function to map a BundleOpInfo to an
1355  /// OperandBundleUse.
1357  operandBundleFromBundleOpInfo(const BundleOpInfo &BOI) const {
1358  auto op_begin = static_cast<const InstrTy *>(this)->op_begin();
1359  ArrayRef<Use> Inputs(op_begin + BOI.Begin, op_begin + BOI.End);
1360  return OperandBundleUse(BOI.Tag, Inputs);
1361  }
1362 
1363  using bundle_op_iterator = BundleOpInfo *;
1364  using const_bundle_op_iterator = const BundleOpInfo *;
1365 
1366  /// Return the start of the list of BundleOpInfo instances associated
1367  /// with this OperandBundleUser.
1369  if (!static_cast<InstrTy *>(this)->hasDescriptor())
1370  return nullptr;
1371 
1372  uint8_t *BytesBegin = static_cast<InstrTy *>(this)->getDescriptor().begin();
1373  return reinterpret_cast<bundle_op_iterator>(BytesBegin);
1374  }
1375 
1376  /// Return the start of the list of BundleOpInfo instances associated
1377  /// with this OperandBundleUser.
1379  auto *NonConstThis =
1380  const_cast<OperandBundleUser<InstrTy, OpIteratorTy> *>(this);
1381  return NonConstThis->bundle_op_info_begin();
1382  }
1383 
1384  /// Return the end of the list of BundleOpInfo instances associated
1385  /// with this OperandBundleUser.
1387  if (!static_cast<InstrTy *>(this)->hasDescriptor())
1388  return nullptr;
1389 
1390  uint8_t *BytesEnd = static_cast<InstrTy *>(this)->getDescriptor().end();
1391  return reinterpret_cast<bundle_op_iterator>(BytesEnd);
1392  }
1393 
1394  /// Return the end of the list of BundleOpInfo instances associated
1395  /// with this OperandBundleUser.
1397  auto *NonConstThis =
1398  const_cast<OperandBundleUser<InstrTy, OpIteratorTy> *>(this);
1399  return NonConstThis->bundle_op_info_end();
1400  }
1401 
1402  /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
1404  return make_range(bundle_op_info_begin(), bundle_op_info_end());
1405  }
1406 
1407  /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
1409  return make_range(bundle_op_info_begin(), bundle_op_info_end());
1410  }
1411 
1412  /// Populate the BundleOpInfo instances and the Use& vector from \p
1413  /// Bundles. Return the op_iterator pointing to the Use& one past the last
1414  /// last bundle operand use.
1415  ///
1416  /// Each \p OperandBundleDef instance is tracked by a OperandBundleInfo
1417  /// instance allocated in this User's descriptor.
1419  const unsigned BeginIndex) {
1420  auto It = static_cast<InstrTy *>(this)->op_begin() + BeginIndex;
1421  for (auto &B : Bundles)
1422  It = std::copy(B.input_begin(), B.input_end(), It);
1423 
1424  auto *ContextImpl = static_cast<InstrTy *>(this)->getContext().pImpl;
1425  auto BI = Bundles.begin();
1426  unsigned CurrentIndex = BeginIndex;
1427 
1428  for (auto &BOI : bundle_op_infos()) {
1429  assert(BI != Bundles.end() && "Incorrect allocation?");
1430 
1431  BOI.Tag = ContextImpl->getOrInsertBundleTag(BI->getTag());
1432  BOI.Begin = CurrentIndex;
1433  BOI.End = CurrentIndex + BI->input_size();
1434  CurrentIndex = BOI.End;
1435  BI++;
1436  }
1437 
1438  assert(BI == Bundles.end() && "Incorrect allocation?");
1439 
1440  return It;
1441  }
1442 
1443  /// Return the BundleOpInfo for the operand at index OpIdx.
1444  ///
1445  /// It is an error to call this with an OpIdx that does not correspond to an
1446  /// bundle operand.
1447  const BundleOpInfo &getBundleOpInfoForOperand(unsigned OpIdx) const {
1448  for (auto &BOI : bundle_op_infos())
1449  if (BOI.Begin <= OpIdx && OpIdx < BOI.End)
1450  return BOI;
1451 
1452  llvm_unreachable("Did not find operand bundle for operand!");
1453  }
1454 
1455  /// Return the total number of values used in \p Bundles.
1457  unsigned Total = 0;
1458  for (auto &B : Bundles)
1459  Total += B.input_size();
1460  return Total;
1461  }
1462 };
1463 
1464 } // end namespace llvm
1465 
1466 #endif // LLVM_IR_INSTRTYPES_H
bool isFPPredicate() const
Definition: InstrTypes.h:748
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:969
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:177
bool hasOperandBundles() const
Return true if this User has any operand bundles.
Definition: InstrTypes.h:1130
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition: InstrTypes.h:797
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:647
Type * getSrcTy() const
Return the source type, as a convenience.
Definition: InstrTypes.h:622
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:173
OperandBundleDefT(std::string Tag, ArrayRef< InputTy > Inputs)
Definition: InstrTypes.h:1054
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition: InstrTypes.h:899
bool isFuncletPad() const
Definition: Instruction.h:134
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:229
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
BinaryOps getOpcode() const
Definition: InstrTypes.h:327
unsigned getSubclassDataFromInstruction() const
Definition: Instruction.h:722
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
Definition: InstrTypes.h:1171
Various leaf nodes.
Definition: ISDOpcodes.h:60
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:236
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Definition: InstrTypes.h:204
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
Definition: InstrTypes.h:59
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
static unsigned CountBundleInputs(ArrayRef< OperandBundleDef > Bundles)
Return the total number of values used in Bundles.
Definition: InstrTypes.h:1456
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
Definition: InstrTypes.h:1125
uint32_t Begin
The index in the Use& vector where operands for this operand bundle starts.
Definition: InstrTypes.h:1343
bool operator==(const BundleOpInfo &Other) const
Definition: InstrTypes.h:1349
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
Definition: InstrTypes.h:1152
iterator_range< op_iterator > op_range
Definition: User.h:227
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
Definition: InstrTypes.h:1164
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:714
static bool classof(const Value *V)
Definition: InstrTypes.h:636
typename std::vector< InputTy >::const_iterator input_iterator
Definition: InstrTypes.h:1064
#define op(i)
ArrayRef< InputTy > inputs() const
Definition: InstrTypes.h:1062
bool isTrueWhenEqual(CondCode Cond)
Return true if the specified condition returns true if the two operands to the condition are equal...
Definition: ISDOpcodes.h:974
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:1290
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
UnaryInstruction(Type *Ty, unsigned iType, Value *V, Instruction *IB=nullptr)
Definition: InstrTypes.h:54
static BinaryOperator * CreateFSubFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:172
op_iterator op_begin()
Definition: User.h:230
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:210
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:845
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:198
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Definition: BitVector.h:938
bool isSigned() const
Definition: InstrTypes.h:826
size_t input_size() const
Definition: InstrTypes.h:1066
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
Definition: InstrTypes.h:755
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:364
static Constant * getNegativeZero(Type *Ty)
Definition: Constants.cpp:736
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:373
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:1022
bool isUnsigned() const
Definition: InstrTypes.h:832
bool hasClobberingOperandBundles() const
Return true if this operand bundle user has operand bundles that may write to the heap...
Definition: InstrTypes.h:1254
This file contains the simple types necessary to represent the attributes associated with functions a...
bundle_op_iterator bundle_op_info_begin()
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1368
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:295
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:187
OtherOps getOpcode() const
Get the opcode casted to the right type.
Definition: InstrTypes.h:726
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
static BinaryOperator * CreateFAddFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:167
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:617
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
bool isFuncletOperandBundle() const
Return true if this is a "funclet" operand bundle.
Definition: InstrTypes.h:1032
void setParentPad(Value *ParentPad)
Definition: InstrTypes.h:961
const_op_range arg_operands() const
arg_operands - iteration adapter for range-for loops.
Definition: InstrTypes.h:975
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Used to keep track of an operand bundle.
Definition: InstrTypes.h:1336
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:126
void setInstructionSubclassData(unsigned short D)
Definition: Instruction.h:717
OperandBundleUse(StringMapEntry< uint32_t > *Tag, ArrayRef< Use > Inputs)
Definition: InstrTypes.h:998
Value * getOperand(unsigned i) const
Definition: User.h:170
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: InstrTypes.h:890
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:410
bool isFnAttrDisallowedByOpBundle(Attribute::AttrKind A) const
Is the function attribute A disallowed by some operand bundle on this operand bundle user...
Definition: InstrTypes.h:1310
static bool isIntPredicate(Predicate P)
Definition: InstrTypes.h:742
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned getBundleOperandsStartIndex() const
Return the index of the first bundle operand in the Use array.
Definition: InstrTypes.h:1133
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
ArrayRef< Use > Inputs
Definition: InstrTypes.h:995
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
Definition: InstrTypes.h:217
Optional< OperandBundleUse > getOperandBundle(uint32_t ID) const
Return an operand bundle by tag ID, if present.
Definition: InstrTypes.h:1211
iterator_range< const_bundle_op_iterator > bundle_op_infos() const
Return the range [bundle_op_info_begin, bundle_op_info_end).
Definition: InstrTypes.h:1408
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, BasicBlock *BB)
Definition: InstrTypes.h:223
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:242
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:657
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:130
static bool classof(const Value *V)
Definition: InstrTypes.h:342
bool isDeoptOperandBundle() const
Return true if this is a "deopt" operand bundle.
Definition: InstrTypes.h:1027
static bool classof(const Instruction *I)
Definition: InstrTypes.h:74
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:54
bool isCast() const
Definition: Instruction.h:133
unsigned countOperandBundlesOfType(uint32_t ID) const
Return the number of operand bundles with the tag ID attached to this instruction.
Definition: InstrTypes.h:1182
bool hasIdenticalOperandBundleSchema(const OperandBundleUser< InstrTy, OpIteratorTy > &Other) const
Return true if Other has the same sequence of operand bundle tags with the same number of operands on...
Definition: InstrTypes.h:1279
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
OpIteratorTy populateBundleOperandInfos(ArrayRef< OperandBundleDef > Bundles, const unsigned BeginIndex)
Populate the BundleOpInfo instances and the Use& vector from Bundles.
Definition: InstrTypes.h:1418
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:71
bool isBundleOperand(unsigned Idx) const
Return true if the operand at index Idx is a bundle operand.
Definition: InstrTypes.h:1145
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Value * getParentPad() const
Convenience accessors.
Definition: InstrTypes.h:960
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:1003
bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const
Return true if the bundle operand at index OpIdx has the attribute A.
Definition: InstrTypes.h:1270
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
Definition: PPCPredicates.h:88
unsigned getNumOperands() const
Definition: User.h:192
OperandBundleDefT(std::string Tag, std::vector< InputTy > Inputs)
Definition: InstrTypes.h:1052
const BundleOpInfo & getBundleOpInfoForOperand(unsigned OpIdx) const
Return the BundleOpInfo for the operand at index OpIdx.
Definition: InstrTypes.h:1447
Predicate getSwappedPredicate(Predicate Opcode)
Assume the condition register is set by MI(a,b), return the predicate if we modify the instructions s...
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics for subclasses.
Definition: InstrTypes.h:367
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Definition: PPCPredicates.h:27
bool isFnAttrDisallowedByOpBundle(StringRef S) const
Is the function attribute S disallowed by some operand bundle on this operand bundle user...
Definition: InstrTypes.h:1302
bundle_op_iterator bundle_op_info_end()
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1386
#define DEFINE_HELPERS(OPC, NUWNSWEXACT)
Definition: InstrTypes.h:255
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
OperandBundleUse operandBundleFromBundleOpInfo(const BundleOpInfo &BOI) const
Simple helper function to map a BundleOpInfo to an OperandBundleUse.
Definition: InstrTypes.h:1357
Type * getDestTy() const
Return the destination type, as a convenience.
Definition: InstrTypes.h:624
unsigned getNumArgOperands() const
getNumArgOperands - Return the number of funcletpad arguments.
Definition: InstrTypes.h:952
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:182
bool isCommutative() const
Return true if the instruction is commutative:
Definition: Instruction.h:474
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:736
Predicate getFlippedStrictnessPredicate() const
For predicate of kind "is X or equal to 0" returns the predicate "is X".
Definition: InstrTypes.h:786
void setOperand(unsigned i, Value *Val)
Definition: User.h:175
bool isIntPredicate() const
Definition: InstrTypes.h:749
bool isTrueWhenEqual() const
This is just a convenience.
Definition: InstrTypes.h:851
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:857
static bool isFPPredicate(Predicate P)
Definition: InstrTypes.h:738
StringRef getTag() const
Definition: InstrTypes.h:1070
A lightweight accessor for an operand bundle meant to be passed around by value.
Definition: InstrTypes.h:994
unsigned getBundleOperandsEndIndex() const
Return the index of the last bundle operand in the Use array.
Definition: InstrTypes.h:1139
uint32_t End
The index in the Use& vector where operands for this operand bundle ends.
Definition: InstrTypes.h:1347
static BinaryOperator * CreateExact(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name, Instruction *I)
Definition: InstrTypes.h:248
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
Definition: InstrTypes.h:1339
OperandBundleDefT(const OperandBundleUse &OBU)
Definition: InstrTypes.h:1057
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:731
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, BinaryOperator *CopyBO, const Twine &Name="")
Definition: InstrTypes.h:158
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:652
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Definition: InstrTypes.h:1195
input_iterator input_begin() const
Definition: InstrTypes.h:1067
input_iterator input_end() const
Definition: InstrTypes.h:1068
#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:1013
Compile-time customization of User operands.
Definition: User.h:43
static BinaryOperator * CreateFNegFMF(Value *Op, BinaryOperator *FMFSource, const Twine &Name="")
Definition: InstrTypes.h:192
static BinaryOperator * CreateNeg(Value *S1, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
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:1378
OperandBundleUse getOperandBundleForOperand(unsigned OpIdx) const
Return the operand bundle for the operand at index OpIdx.
Definition: InstrTypes.h:1239
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Definition: InstrTypes.h:1230
static bool classof(const Value *V)
Definition: InstrTypes.h:894
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:972
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:1396
LLVM Value Representation.
Definition: Value.h:73
static bool classof(const Value *V)
Definition: InstrTypes.h:81
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:593
A container for an operand bundle being viewed as a set of values rather than a set of uses...
Definition: InstrTypes.h:1047
iterator_range< bundle_op_iterator > bundle_op_infos()
Return the range [bundle_op_info_begin, bundle_op_info_end).
Definition: InstrTypes.h:1403
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:771
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:968
Use & Op()
Definition: User.h:134
static bool classof(const Instruction *I)
Definition: InstrTypes.h:339
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:69
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1094
static bool classof(const Instruction *I)
Definition: InstrTypes.h:980
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: InstrTypes.h:633
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool hasReadingOperandBundles() const
Return true if this operand bundle user has operand bundles that may read from the heap...
Definition: InstrTypes.h:1245
static bool classof(const Value *V)
Definition: InstrTypes.h:981
A mixin to add operand bundle functionality to llvm instruction classes.
Definition: InstrTypes.h:1122
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:1101