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