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 
312  return static_cast<BinaryOps>(Instruction::getOpcode());
313  }
314 
315  /// Exchange the two operands to this instruction.
316  /// This instruction is safe to use on any binary instruction and
317  /// does not modify the semantics of the instruction. If the instruction
318  /// cannot be reversed (ie, it's a Div), then return true.
319  ///
320  bool swapOperands();
321 
322  // Methods for support type inquiry through isa, cast, and dyn_cast:
323  static bool classof(const Instruction *I) {
324  return I->isBinaryOp();
325  }
326  static bool classof(const Value *V) {
327  return isa<Instruction>(V) && classof(cast<Instruction>(V));
328  }
329 };
330 
331 template <>
333  public FixedNumOperandTraits<BinaryOperator, 2> {
334 };
335 
337 
338 //===----------------------------------------------------------------------===//
339 // CastInst Class
340 //===----------------------------------------------------------------------===//
341 
342 /// This is the base class for all instructions that perform data
343 /// casts. It is simply provided so that instruction category testing
344 /// can be performed with code like:
345 ///
346 /// if (isa<CastInst>(Instr)) { ... }
347 /// Base class of casting instructions.
348 class CastInst : public UnaryInstruction {
349 protected:
350  /// Constructor with insert-before-instruction semantics for subclasses
351  CastInst(Type *Ty, unsigned iType, Value *S,
352  const Twine &NameStr = "", Instruction *InsertBefore = nullptr)
353  : UnaryInstruction(Ty, iType, S, InsertBefore) {
354  setName(NameStr);
355  }
356  /// Constructor with insert-at-end-of-block semantics for subclasses
357  CastInst(Type *Ty, unsigned iType, Value *S,
358  const Twine &NameStr, BasicBlock *InsertAtEnd)
359  : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
360  setName(NameStr);
361  }
362 
363 public:
364  /// Provides a way to construct any of the CastInst subclasses using an
365  /// opcode instead of the subclass's constructor. The opcode must be in the
366  /// CastOps category (Instruction::isCast(opcode) returns true). This
367  /// constructor has insert-before-instruction semantics to automatically
368  /// insert the new CastInst before InsertBefore (if it is non-null).
369  /// Construct any of the CastInst subclasses
370  static CastInst *Create(
371  Instruction::CastOps, ///< The opcode of the cast instruction
372  Value *S, ///< The value to be casted (operand 0)
373  Type *Ty, ///< The type to which cast should be made
374  const Twine &Name = "", ///< Name for the instruction
375  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
376  );
377  /// Provides a way to construct any of the CastInst subclasses using an
378  /// opcode instead of the subclass's constructor. The opcode must be in the
379  /// CastOps category. This constructor has insert-at-end-of-block semantics
380  /// to automatically insert the new CastInst at the end of InsertAtEnd (if
381  /// its non-null).
382  /// Construct any of the CastInst subclasses
383  static CastInst *Create(
384  Instruction::CastOps, ///< The opcode for the cast instruction
385  Value *S, ///< The value to be casted (operand 0)
386  Type *Ty, ///< The type to which operand is casted
387  const Twine &Name, ///< The name for the instruction
388  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
389  );
390 
391  /// Create a ZExt or BitCast cast instruction
392  static CastInst *CreateZExtOrBitCast(
393  Value *S, ///< The value to be casted (operand 0)
394  Type *Ty, ///< The type to which cast should be made
395  const Twine &Name = "", ///< Name for the instruction
396  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
397  );
398 
399  /// Create a ZExt or BitCast cast instruction
400  static CastInst *CreateZExtOrBitCast(
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 SExt or BitCast cast instruction
408  static CastInst *CreateSExtOrBitCast(
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 SExt or BitCast cast instruction
416  static CastInst *CreateSExtOrBitCast(
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 BitCast AddrSpaceCast, or a PtrToInt cast instruction.
424  static CastInst *CreatePointerCast(
425  Value *S, ///< The pointer value to be casted (operand 0)
426  Type *Ty, ///< The type to which operand is casted
427  const Twine &Name, ///< The name for the instruction
428  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
429  );
430 
431  /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
432  static CastInst *CreatePointerCast(
433  Value *S, ///< The pointer value to be casted (operand 0)
434  Type *Ty, ///< The type to which cast should be made
435  const Twine &Name = "", ///< Name for the instruction
436  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
437  );
438 
439  /// Create a BitCast or an AddrSpaceCast cast instruction.
440  static CastInst *CreatePointerBitCastOrAddrSpaceCast(
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 or an AddrSpaceCast cast instruction.
448  static CastInst *CreatePointerBitCastOrAddrSpaceCast(
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, a PtrToInt, or an IntToPTr cast instruction.
456  ///
457  /// If the value is a pointer type and the destination an integer type,
458  /// creates a PtrToInt cast. If the value is an integer type and the
459  /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
460  /// a bitcast.
461  static CastInst *CreateBitOrPointerCast(
462  Value *S, ///< The pointer value to be casted (operand 0)
463  Type *Ty, ///< The type to which cast should be made
464  const Twine &Name = "", ///< Name for the instruction
465  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
466  );
467 
468  /// Create a ZExt, BitCast, or Trunc for int -> int casts.
469  static CastInst *CreateIntegerCast(
470  Value *S, ///< The pointer value to be casted (operand 0)
471  Type *Ty, ///< The type to which cast should be made
472  bool isSigned, ///< Whether to regard S as signed or not
473  const Twine &Name = "", ///< Name for the instruction
474  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
475  );
476 
477  /// Create a ZExt, BitCast, or Trunc for int -> int casts.
478  static CastInst *CreateIntegerCast(
479  Value *S, ///< The integer value to be casted (operand 0)
480  Type *Ty, ///< The integer type to which operand is casted
481  bool isSigned, ///< Whether to regard S as signed or not
482  const Twine &Name, ///< The name for the instruction
483  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
484  );
485 
486  /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
487  static CastInst *CreateFPCast(
488  Value *S, ///< The floating point value to be casted
489  Type *Ty, ///< The floating point type to cast to
490  const Twine &Name = "", ///< Name for the instruction
491  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
492  );
493 
494  /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
495  static CastInst *CreateFPCast(
496  Value *S, ///< The floating point value to be casted
497  Type *Ty, ///< The floating point type to cast to
498  const Twine &Name, ///< The name for the instruction
499  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
500  );
501 
502  /// Create a Trunc or BitCast cast instruction
503  static CastInst *CreateTruncOrBitCast(
504  Value *S, ///< The value to be casted (operand 0)
505  Type *Ty, ///< The type to which cast should be made
506  const Twine &Name = "", ///< Name for the instruction
507  Instruction *InsertBefore = nullptr ///< Place to insert the instruction
508  );
509 
510  /// Create a Trunc or BitCast cast instruction
511  static CastInst *CreateTruncOrBitCast(
512  Value *S, ///< The value to be casted (operand 0)
513  Type *Ty, ///< The type to which operand is casted
514  const Twine &Name, ///< The name for the instruction
515  BasicBlock *InsertAtEnd ///< The block to insert the instruction into
516  );
517 
518  /// Check whether it is valid to call getCastOpcode for these types.
519  static bool isCastable(
520  Type *SrcTy, ///< The Type from which the value should be cast.
521  Type *DestTy ///< The Type to which the value should be cast.
522  );
523 
524  /// Check whether a bitcast between these types is valid
525  static bool isBitCastable(
526  Type *SrcTy, ///< The Type from which the value should be cast.
527  Type *DestTy ///< The Type to which the value should be cast.
528  );
529 
530  /// Check whether a bitcast, inttoptr, or ptrtoint cast between these
531  /// types is valid and a no-op.
532  ///
533  /// This ensures that any pointer<->integer cast has enough bits in the
534  /// integer and any other cast is a bitcast.
535  static bool isBitOrNoopPointerCastable(
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  const DataLayout &DL);
539 
540  /// Returns the opcode necessary to cast Val into Ty using usual casting
541  /// rules.
542  /// Infer the opcode for cast operand and type
543  static Instruction::CastOps getCastOpcode(
544  const Value *Val, ///< The value to cast
545  bool SrcIsSigned, ///< Whether to treat the source as signed
546  Type *Ty, ///< The Type to which the value should be casted
547  bool DstIsSigned ///< Whether to treate the dest. as signed
548  );
549 
550  /// There are several places where we need to know if a cast instruction
551  /// only deals with integer source and destination types. To simplify that
552  /// logic, this method is provided.
553  /// @returns true iff the cast has only integral typed operand and dest type.
554  /// Determine if this is an integer-only cast.
555  bool isIntegerCast() const;
556 
557  /// A lossless cast is one that does not alter the basic value. It implies
558  /// a no-op cast but is more stringent, preventing things like int->float,
559  /// long->double, or int->ptr.
560  /// @returns true iff the cast is lossless.
561  /// Determine if this is a lossless cast.
562  bool isLosslessCast() const;
563 
564  /// A no-op cast is one that can be effected without changing any bits.
565  /// It implies that the source and destination types are the same size. The
566  /// DataLayout argument is to determine the pointer size when examining casts
567  /// involving Integer and Pointer types. They are no-op casts if the integer
568  /// is the same size as the pointer. However, pointer size varies with
569  /// platform.
570  /// Determine if the described cast is a no-op cast.
571  static bool isNoopCast(
572  Instruction::CastOps Opcode, ///< Opcode of cast
573  Type *SrcTy, ///< SrcTy of cast
574  Type *DstTy, ///< DstTy of cast
575  const DataLayout &DL ///< DataLayout to get the Int Ptr type from.
576  );
577 
578  /// Determine if this cast is a no-op cast.
579  ///
580  /// \param DL is the DataLayout to determine pointer size.
581  bool isNoopCast(const DataLayout &DL) const;
582 
583  /// Determine how a pair of casts can be eliminated, if they can be at all.
584  /// This is a helper function for both CastInst and ConstantExpr.
585  /// @returns 0 if the CastInst pair can't be eliminated, otherwise
586  /// returns Instruction::CastOps value for a cast that can replace
587  /// the pair, casting SrcTy to DstTy.
588  /// Determine if a cast pair is eliminable
589  static unsigned isEliminableCastPair(
590  Instruction::CastOps firstOpcode, ///< Opcode of first cast
591  Instruction::CastOps secondOpcode, ///< Opcode of second cast
592  Type *SrcTy, ///< SrcTy of 1st cast
593  Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
594  Type *DstTy, ///< DstTy of 2nd cast
595  Type *SrcIntPtrTy, ///< Integer type corresponding to Ptr SrcTy, or null
596  Type *MidIntPtrTy, ///< Integer type corresponding to Ptr MidTy, or null
597  Type *DstIntPtrTy ///< Integer type corresponding to Ptr DstTy, or null
598  );
599 
600  /// Return the opcode of this CastInst
603  }
604 
605  /// Return the source type, as a convenience
606  Type* getSrcTy() const { return getOperand(0)->getType(); }
607  /// Return the destination type, as a convenience
608  Type* getDestTy() const { return getType(); }
609 
610  /// This method can be used to determine if a cast from S to DstTy using
611  /// Opcode op is valid or not.
612  /// @returns true iff the proposed cast is valid.
613  /// Determine if a cast is valid without creating one.
614  static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy);
615 
616  /// Methods for support type inquiry through isa, cast, and dyn_cast:
617  static bool classof(const Instruction *I) {
618  return I->isCast();
619  }
620  static bool classof(const Value *V) {
621  return isa<Instruction>(V) && classof(cast<Instruction>(V));
622  }
623 };
624 
625 //===----------------------------------------------------------------------===//
626 // CmpInst Class
627 //===----------------------------------------------------------------------===//
628 
629 /// This class is the base class for the comparison instructions.
630 /// Abstract base class of comparison instructions.
631 class CmpInst : public Instruction {
632 public:
633  /// This enumeration lists the possible predicates for CmpInst subclasses.
634  /// Values in the range 0-31 are reserved for FCmpInst, while values in the
635  /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
636  /// predicate values are not overlapping between the classes.
637  ///
638  /// Some passes (e.g. InstCombine) depend on the bit-wise characteristics of
639  /// FCMP_* values. Changing the bit patterns requires a potential change to
640  /// those passes.
641  enum Predicate {
642  // Opcode U L G E Intuitive operation
643  FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
644  FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
645  FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
646  FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
647  FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
648  FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
649  FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
650  FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
651  FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
652  FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
653  FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than
654  FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal
655  FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than
656  FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal
657  FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal
658  FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded)
659  FIRST_FCMP_PREDICATE = FCMP_FALSE,
660  LAST_FCMP_PREDICATE = FCMP_TRUE,
661  BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
662  ICMP_EQ = 32, ///< equal
663  ICMP_NE = 33, ///< not equal
664  ICMP_UGT = 34, ///< unsigned greater than
665  ICMP_UGE = 35, ///< unsigned greater or equal
666  ICMP_ULT = 36, ///< unsigned less than
667  ICMP_ULE = 37, ///< unsigned less or equal
668  ICMP_SGT = 38, ///< signed greater than
669  ICMP_SGE = 39, ///< signed greater or equal
670  ICMP_SLT = 40, ///< signed less than
671  ICMP_SLE = 41, ///< signed less or equal
672  FIRST_ICMP_PREDICATE = ICMP_EQ,
673  LAST_ICMP_PREDICATE = ICMP_SLE,
674  BAD_ICMP_PREDICATE = ICMP_SLE + 1
675  };
676 
677 protected:
679  Value *LHS, Value *RHS, const Twine &Name = "",
680  Instruction *InsertBefore = nullptr,
681  Instruction *FlagsSource = nullptr);
682 
684  Value *LHS, Value *RHS, const Twine &Name,
685  BasicBlock *InsertAtEnd);
686 
687 public:
688  // allocate space for exactly two operands
689  void *operator new(size_t s) {
690  return User::operator new(s, 2);
691  }
692 
693  /// Construct a compare instruction, given the opcode, the predicate and
694  /// the two operands. Optionally (if InstBefore is specified) insert the
695  /// instruction into a BasicBlock right before the specified instruction.
696  /// The specified Instruction is allowed to be a dereferenced end iterator.
697  /// Create a CmpInst
698  static CmpInst *Create(OtherOps Op,
699  Predicate predicate, Value *S1,
700  Value *S2, const Twine &Name = "",
701  Instruction *InsertBefore = nullptr);
702 
703  /// Construct a compare instruction, given the opcode, the predicate and the
704  /// two operands. Also automatically insert this instruction to the end of
705  /// the BasicBlock specified.
706  /// Create a CmpInst
707  static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1,
708  Value *S2, const Twine &Name, BasicBlock *InsertAtEnd);
709 
710  /// Get the opcode casted to the right type
711  OtherOps getOpcode() const {
712  return static_cast<OtherOps>(Instruction::getOpcode());
713  }
714 
715  /// Return the predicate for this instruction.
718  }
719 
720  /// Set the predicate for this instruction to the specified value.
722 
723  static bool isFPPredicate(Predicate P) {
724  return P >= FIRST_FCMP_PREDICATE && P <= LAST_FCMP_PREDICATE;
725  }
726 
727  static bool isIntPredicate(Predicate P) {
728  return P >= FIRST_ICMP_PREDICATE && P <= LAST_ICMP_PREDICATE;
729  }
730 
731  static StringRef getPredicateName(Predicate P);
732 
733  bool isFPPredicate() const { return isFPPredicate(getPredicate()); }
734  bool isIntPredicate() const { return isIntPredicate(getPredicate()); }
735 
736  /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
737  /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
738  /// @returns the inverse predicate for the instruction's current predicate.
739  /// Return the inverse of the instruction's predicate.
741  return getInversePredicate(getPredicate());
742  }
743 
744  /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE,
745  /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
746  /// @returns the inverse predicate for predicate provided in \p pred.
747  /// Return the inverse of a given predicate
748  static Predicate getInversePredicate(Predicate pred);
749 
750  /// For example, EQ->EQ, SLE->SGE, ULT->UGT,
751  /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
752  /// @returns the predicate that would be the result of exchanging the two
753  /// operands of the CmpInst instruction without changing the result
754  /// produced.
755  /// Return the predicate as if the operands were swapped
758  }
759 
760  /// This is a static version that you can use without an instruction
761  /// available.
762  /// Return the predicate as if the operands were swapped.
764 
765  /// For predicate of kind "is X or equal to 0" returns the predicate "is X".
766  /// For predicate of kind "is X" returns the predicate "is X or equal to 0".
767  /// does not support other kind of predicates.
768  /// @returns the predicate that does not contains is equal to zero if
769  /// it had and vice versa.
770  /// Return the flipped strictness of predicate
772  return getFlippedStrictnessPredicate(getPredicate());
773  }
774 
775  /// This is a static version that you can use without an instruction
776  /// available.
777  /// Return the flipped strictness of predicate
778  static Predicate getFlippedStrictnessPredicate(Predicate pred);
779 
780  /// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
781  /// Returns the non-strict version of strict comparisons.
783  return getNonStrictPredicate(getPredicate());
784  }
785 
786  /// This is a static version that you can use without an instruction
787  /// available.
788  /// @returns the non-strict version of comparison provided in \p pred.
789  /// If \p pred is not a strict comparison predicate, returns \p pred.
790  /// Returns the non-strict version of strict comparisons.
791  static Predicate getNonStrictPredicate(Predicate pred);
792 
793  /// Provide more efficient getOperand methods.
795 
796  /// This is just a convenience that dispatches to the subclasses.
797  /// Swap the operands and adjust predicate accordingly to retain
798  /// the same comparison.
799  void swapOperands();
800 
801  /// This is just a convenience that dispatches to the subclasses.
802  /// Determine if this CmpInst is commutative.
803  bool isCommutative() const;
804 
805  /// This is just a convenience that dispatches to the subclasses.
806  /// Determine if this is an equals/not equals predicate.
807  bool isEquality() const;
808 
809  /// @returns true if the comparison is signed, false otherwise.
810  /// Determine if this instruction is using a signed comparison.
811  bool isSigned() const {
812  return isSigned(getPredicate());
813  }
814 
815  /// @returns true if the comparison is unsigned, false otherwise.
816  /// Determine if this instruction is using an unsigned comparison.
817  bool isUnsigned() const {
818  return isUnsigned(getPredicate());
819  }
820 
821  /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
822  /// @returns the signed version of the unsigned predicate pred.
823  /// return the signed version of a predicate
824  static Predicate getSignedPredicate(Predicate pred);
825 
826  /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
827  /// @returns the signed version of the predicate for this instruction (which
828  /// has to be an unsigned predicate).
829  /// return the signed version of a predicate
831  return getSignedPredicate(getPredicate());
832  }
833 
834  /// This is just a convenience.
835  /// Determine if this is true when both operands are the same.
836  bool isTrueWhenEqual() const {
837  return isTrueWhenEqual(getPredicate());
838  }
839 
840  /// This is just a convenience.
841  /// Determine if this is false when both operands are the same.
842  bool isFalseWhenEqual() const {
843  return isFalseWhenEqual(getPredicate());
844  }
845 
846  /// @returns true if the predicate is unsigned, false otherwise.
847  /// Determine if the predicate is an unsigned operation.
848  static bool isUnsigned(Predicate predicate);
849 
850  /// @returns true if the predicate is signed, false otherwise.
851  /// Determine if the predicate is an signed operation.
852  static bool isSigned(Predicate predicate);
853 
854  /// Determine if the predicate is an ordered operation.
855  static bool isOrdered(Predicate predicate);
856 
857  /// Determine if the predicate is an unordered operation.
858  static bool isUnordered(Predicate predicate);
859 
860  /// Determine if the predicate is true when comparing a value with itself.
861  static bool isTrueWhenEqual(Predicate predicate);
862 
863  /// Determine if the predicate is false when comparing a value with itself.
864  static bool isFalseWhenEqual(Predicate predicate);
865 
866  /// Determine if Pred1 implies Pred2 is true when two compares have matching
867  /// operands.
868  static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2);
869 
870  /// Determine if Pred1 implies Pred2 is false when two compares have matching
871  /// operands.
872  static bool isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2);
873 
874  /// Methods for support type inquiry through isa, cast, and dyn_cast:
875  static bool classof(const Instruction *I) {
876  return I->getOpcode() == Instruction::ICmp ||
877  I->getOpcode() == Instruction::FCmp;
878  }
879  static bool classof(const Value *V) {
880  return isa<Instruction>(V) && classof(cast<Instruction>(V));
881  }
882 
883  /// Create a result type for fcmp/icmp
884  static Type* makeCmpResultType(Type* opnd_type) {
885  if (VectorType* vt = dyn_cast<VectorType>(opnd_type)) {
886  return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
887  vt->getNumElements());
888  }
889  return Type::getInt1Ty(opnd_type->getContext());
890  }
891 
892 private:
893  // Shadow Value::setValueSubclassData with a private forwarding method so that
894  // subclasses cannot accidentally use it.
895  void setValueSubclassData(unsigned short D) {
897  }
898 };
899 
900 // FIXME: these are redundant if CmpInst < BinaryOperator
901 template <>
902 struct OperandTraits<CmpInst> : public FixedNumOperandTraits<CmpInst, 2> {
903 };
904 
906 
907 //===----------------------------------------------------------------------===//
908 // FuncletPadInst Class
909 //===----------------------------------------------------------------------===//
910 class FuncletPadInst : public Instruction {
911 private:
912  FuncletPadInst(const FuncletPadInst &CPI);
913 
914  explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
915  ArrayRef<Value *> Args, unsigned Values,
916  const Twine &NameStr, Instruction *InsertBefore);
917  explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
918  ArrayRef<Value *> Args, unsigned Values,
919  const Twine &NameStr, BasicBlock *InsertAtEnd);
920 
921  void init(Value *ParentPad, ArrayRef<Value *> Args, const Twine &NameStr);
922 
923 protected:
924  // Note: Instruction needs to be a friend here to call cloneImpl.
925  friend class Instruction;
926  friend class CatchPadInst;
927  friend class CleanupPadInst;
928 
929  FuncletPadInst *cloneImpl() const;
930 
931 public:
932  /// Provide fast operand accessors
934 
935  /// getNumArgOperands - Return the number of funcletpad arguments.
936  ///
937  unsigned getNumArgOperands() const { return getNumOperands() - 1; }
938 
939  /// Convenience accessors
940 
941  /// Return the outer EH-pad this funclet is nested within.
942  ///
943  /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
944  /// is a CatchPadInst.
945  Value *getParentPad() const { return Op<-1>(); }
946  void setParentPad(Value *ParentPad) {
947  assert(ParentPad);
948  Op<-1>() = ParentPad;
949  }
950 
951  /// getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
952  ///
953  Value *getArgOperand(unsigned i) const { return getOperand(i); }
954  void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
955 
956  /// arg_operands - iteration adapter for range-for loops.
957  op_range arg_operands() { return op_range(op_begin(), op_end() - 1); }
958 
959  /// arg_operands - iteration adapter for range-for loops.
961  return const_op_range(op_begin(), op_end() - 1);
962  }
963 
964  // Methods for support type inquiry through isa, cast, and dyn_cast:
965  static bool classof(const Instruction *I) { return I->isFuncletPad(); }
966  static bool classof(const Value *V) {
967  return isa<Instruction>(V) && classof(cast<Instruction>(V));
968  }
969 };
970 
971 template <>
973  : public VariadicOperandTraits<FuncletPadInst, /*MINARITY=*/1> {};
974 
976 
977 /// A lightweight accessor for an operand bundle meant to be passed
978 /// around by value.
981 
982  OperandBundleUse() = default;
984  : Inputs(Inputs), Tag(Tag) {}
985 
986  /// Return true if the operand at index \p Idx in this operand bundle
987  /// has the attribute A.
988  bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const {
989  if (isDeoptOperandBundle())
990  if (A == Attribute::ReadOnly || A == Attribute::NoCapture)
991  return Inputs[Idx]->getType()->isPointerTy();
992 
993  // Conservative answer: no operands have any attributes.
994  return false;
995  }
996 
997  /// Return the tag of this operand bundle as a string.
999  return Tag->getKey();
1000  }
1001 
1002  /// Return the tag of this operand bundle as an integer.
1003  ///
1004  /// Operand bundle tags are interned by LLVMContextImpl::getOrInsertBundleTag,
1005  /// and this function returns the unique integer getOrInsertBundleTag
1006  /// associated the tag of this operand bundle to.
1007  uint32_t getTagID() const {
1008  return Tag->getValue();
1009  }
1010 
1011  /// Return true if this is a "deopt" operand bundle.
1012  bool isDeoptOperandBundle() const {
1013  return getTagID() == LLVMContext::OB_deopt;
1014  }
1015 
1016  /// Return true if this is a "funclet" operand bundle.
1017  bool isFuncletOperandBundle() const {
1018  return getTagID() == LLVMContext::OB_funclet;
1019  }
1020 
1021 private:
1022  /// Pointer to an entry in LLVMContextImpl::getOrInsertBundleTag.
1024 };
1025 
1026 /// A container for an operand bundle being viewed as a set of values
1027 /// rather than a set of uses.
1028 ///
1029 /// Unlike OperandBundleUse, OperandBundleDefT owns the memory it carries, and
1030 /// so it is possible to create and pass around "self-contained" instances of
1031 /// OperandBundleDef and ConstOperandBundleDef.
1032 template <typename InputTy> class OperandBundleDefT {
1033  std::string Tag;
1034  std::vector<InputTy> Inputs;
1035 
1036 public:
1037  explicit OperandBundleDefT(std::string Tag, std::vector<InputTy> Inputs)
1038  : Tag(std::move(Tag)), Inputs(std::move(Inputs)) {}
1039  explicit OperandBundleDefT(std::string Tag, ArrayRef<InputTy> Inputs)
1040  : Tag(std::move(Tag)), Inputs(Inputs) {}
1041 
1042  explicit OperandBundleDefT(const OperandBundleUse &OBU) {
1043  Tag = OBU.getTagName();
1044  Inputs.insert(Inputs.end(), OBU.Inputs.begin(), OBU.Inputs.end());
1045  }
1046 
1047  ArrayRef<InputTy> inputs() const { return Inputs; }
1048 
1049  using input_iterator = typename std::vector<InputTy>::const_iterator;
1050 
1051  size_t input_size() const { return Inputs.size(); }
1052  input_iterator input_begin() const { return Inputs.begin(); }
1053  input_iterator input_end() const { return Inputs.end(); }
1054 
1055  StringRef getTag() const { return Tag; }
1056 };
1057 
1060 
1061 /// A mixin to add operand bundle functionality to llvm instruction
1062 /// classes.
1063 ///
1064 /// OperandBundleUser uses the descriptor area co-allocated with the host User
1065 /// to store some meta information about which operands are "normal" operands,
1066 /// and which ones belong to some operand bundle.
1067 ///
1068 /// The layout of an operand bundle user is
1069 ///
1070 /// +-----------uint32_t End-------------------------------------+
1071 /// | |
1072 /// | +--------uint32_t Begin--------------------+ |
1073 /// | | | |
1074 /// ^ ^ v v
1075 /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
1076 /// | BOI0 | BOI1 | .. | DU | U0 | U1 | .. | BOI0_U0 | .. | BOI1_U0 | .. | Un
1077 /// |------|------|----|----|----|----|----|---------|----|---------|----|-----
1078 /// v v ^ ^
1079 /// | | | |
1080 /// | +--------uint32_t Begin------------+ |
1081 /// | |
1082 /// +-----------uint32_t End-----------------------------+
1083 ///
1084 ///
1085 /// BOI0, BOI1 ... are descriptions of operand bundles in this User's use list.
1086 /// These descriptions are installed and managed by this class, and they're all
1087 /// instances of OperandBundleUser<T>::BundleOpInfo.
1088 ///
1089 /// DU is an additional descriptor installed by User's 'operator new' to keep
1090 /// track of the 'BOI0 ... BOIN' co-allocation. OperandBundleUser does not
1091 /// access or modify DU in any way, it's an implementation detail private to
1092 /// User.
1093 ///
1094 /// The regular Use& vector for the User starts at U0. The operand bundle uses
1095 /// are part of the Use& vector, just like normal uses. In the diagram above,
1096 /// the operand bundle uses start at BOI0_U0. Each instance of BundleOpInfo has
1097 /// information about a contiguous set of uses constituting an operand bundle,
1098 /// and the total set of operand bundle uses themselves form a contiguous set of
1099 /// uses (i.e. there are no gaps between uses corresponding to individual
1100 /// operand bundles).
1101 ///
1102 /// This class does not know the location of the set of operand bundle uses
1103 /// within the use list -- that is decided by the User using this class via the
1104 /// BeginIdx argument in populateBundleOperandInfos.
1105 ///
1106 /// Currently operand bundle users with hung-off operands are not supported.
1107 template <typename InstrTy, typename OpIteratorTy> class OperandBundleUser {
1108 public:
1109  /// Return the number of operand bundles associated with this User.
1110  unsigned getNumOperandBundles() const {
1111  return std::distance(bundle_op_info_begin(), bundle_op_info_end());
1112  }
1113 
1114  /// Return true if this User has any operand bundles.
1115  bool hasOperandBundles() const { return getNumOperandBundles() != 0; }
1116 
1117  /// Return the index of the first bundle operand in the Use array.
1118  unsigned getBundleOperandsStartIndex() const {
1119  assert(hasOperandBundles() && "Don't call otherwise!");
1120  return bundle_op_info_begin()->Begin;
1121  }
1122 
1123  /// Return the index of the last bundle operand in the Use array.
1124  unsigned getBundleOperandsEndIndex() const {
1125  assert(hasOperandBundles() && "Don't call otherwise!");
1126  return bundle_op_info_end()[-1].End;
1127  }
1128 
1129  /// Return true if the operand at index \p Idx is a bundle operand.
1130  bool isBundleOperand(unsigned Idx) const {
1131  return hasOperandBundles() && Idx >= getBundleOperandsStartIndex() &&
1132  Idx < getBundleOperandsEndIndex();
1133  }
1134 
1135  /// Return the total number operands (not operand bundles) used by
1136  /// every operand bundle in this OperandBundleUser.
1137  unsigned getNumTotalBundleOperands() const {
1138  if (!hasOperandBundles())
1139  return 0;
1140 
1141  unsigned Begin = getBundleOperandsStartIndex();
1142  unsigned End = getBundleOperandsEndIndex();
1143 
1144  assert(Begin <= End && "Should be!");
1145  return End - Begin;
1146  }
1147 
1148  /// Return the operand bundle at a specific index.
1150  assert(Index < getNumOperandBundles() && "Index out of bounds!");
1151  return operandBundleFromBundleOpInfo(*(bundle_op_info_begin() + Index));
1152  }
1153 
1154  /// Return the number of operand bundles with the tag Name attached to
1155  /// this instruction.
1157  unsigned Count = 0;
1158  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1159  if (getOperandBundleAt(i).getTagName() == Name)
1160  Count++;
1161 
1162  return Count;
1163  }
1164 
1165  /// Return the number of operand bundles with the tag ID attached to
1166  /// this instruction.
1168  unsigned Count = 0;
1169  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1170  if (getOperandBundleAt(i).getTagID() == ID)
1171  Count++;
1172 
1173  return Count;
1174  }
1175 
1176  /// Return an operand bundle by name, if present.
1177  ///
1178  /// It is an error to call this for operand bundle types that may have
1179  /// multiple instances of them on the same instruction.
1181  assert(countOperandBundlesOfType(Name) < 2 && "Precondition violated!");
1182 
1183  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1184  OperandBundleUse U = getOperandBundleAt(i);
1185  if (U.getTagName() == Name)
1186  return U;
1187  }
1188 
1189  return None;
1190  }
1191 
1192  /// Return an operand bundle by tag ID, if present.
1193  ///
1194  /// It is an error to call this for operand bundle types that may have
1195  /// multiple instances of them on the same instruction.
1197  assert(countOperandBundlesOfType(ID) < 2 && "Precondition violated!");
1198 
1199  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1200  OperandBundleUse U = getOperandBundleAt(i);
1201  if (U.getTagID() == ID)
1202  return U;
1203  }
1204 
1205  return None;
1206  }
1207 
1208  /// Return the list of operand bundles attached to this instruction as
1209  /// a vector of OperandBundleDefs.
1210  ///
1211  /// This function copies the OperandBundeUse instances associated with this
1212  /// OperandBundleUser to a vector of OperandBundleDefs. Note:
1213  /// OperandBundeUses and OperandBundleDefs are non-trivially *different*
1214  /// representations of operand bundles (see documentation above).
1216  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
1217  Defs.emplace_back(getOperandBundleAt(i));
1218  }
1219 
1220  /// Return the operand bundle for the operand at index OpIdx.
1221  ///
1222  /// It is an error to call this with an OpIdx that does not correspond to an
1223  /// bundle operand.
1225  return operandBundleFromBundleOpInfo(getBundleOpInfoForOperand(OpIdx));
1226  }
1227 
1228  /// Return true if this operand bundle user has operand bundles that
1229  /// may read from the heap.
1231  // Implementation note: this is a conservative implementation of operand
1232  // bundle semantics, where *any* operand bundle forces a callsite to be at
1233  // least readonly.
1234  return hasOperandBundles();
1235  }
1236 
1237  /// Return true if this operand bundle user has operand bundles that
1238  /// may write to the heap.
1240  for (auto &BOI : bundle_op_infos()) {
1241  if (BOI.Tag->second == LLVMContext::OB_deopt ||
1242  BOI.Tag->second == LLVMContext::OB_funclet)
1243  continue;
1244 
1245  // This instruction has an operand bundle that is not known to us.
1246  // Assume the worst.
1247  return true;
1248  }
1249 
1250  return false;
1251  }
1252 
1253  /// Return true if the bundle operand at index \p OpIdx has the
1254  /// attribute \p A.
1255  bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const {
1256  auto &BOI = getBundleOpInfoForOperand(OpIdx);
1257  auto OBU = operandBundleFromBundleOpInfo(BOI);
1258  return OBU.operandHasAttr(OpIdx - BOI.Begin, A);
1259  }
1260 
1261  /// Return true if \p Other has the same sequence of operand bundle
1262  /// tags with the same number of operands on each one of them as this
1263  /// OperandBundleUser.
1265  const OperandBundleUser<InstrTy, OpIteratorTy> &Other) const {
1266  if (getNumOperandBundles() != Other.getNumOperandBundles())
1267  return false;
1268 
1269  return std::equal(bundle_op_info_begin(), bundle_op_info_end(),
1270  Other.bundle_op_info_begin());
1271  }
1272 
1273  /// Return true if this operand bundle user contains operand bundles
1274  /// with tags other than those specified in \p IDs.
1276  for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
1277  uint32_t ID = getOperandBundleAt(i).getTagID();
1278  if (!is_contained(IDs, ID))
1279  return true;
1280  }
1281  return false;
1282  }
1283 
1284 protected:
1285  /// Is the function attribute S disallowed by some operand bundle on
1286  /// this operand bundle user?
1288  // Operand bundles only possibly disallow readnone, readonly and argmenonly
1289  // attributes. All String attributes are fine.
1290  return false;
1291  }
1292 
1293  /// Is the function attribute A disallowed by some operand bundle on
1294  /// this operand bundle user?
1296  switch (A) {
1297  default:
1298  return false;
1299 
1300  case Attribute::InaccessibleMemOrArgMemOnly:
1301  return hasReadingOperandBundles();
1302 
1303  case Attribute::InaccessibleMemOnly:
1304  return hasReadingOperandBundles();
1305 
1306  case Attribute::ArgMemOnly:
1307  return hasReadingOperandBundles();
1308 
1309  case Attribute::ReadNone:
1310  return hasReadingOperandBundles();
1311 
1312  case Attribute::ReadOnly:
1313  return hasClobberingOperandBundles();
1314  }
1315 
1316  llvm_unreachable("switch has a default case!");
1317  }
1318 
1319  /// Used to keep track of an operand bundle. See the main comment on
1320  /// OperandBundleUser above.
1321  struct BundleOpInfo {
1322  /// The operand bundle tag, interned by
1323  /// LLVMContextImpl::getOrInsertBundleTag.
1325 
1326  /// The index in the Use& vector where operands for this operand
1327  /// bundle starts.
1329 
1330  /// The index in the Use& vector where operands for this operand
1331  /// bundle ends.
1333 
1334  bool operator==(const BundleOpInfo &Other) const {
1335  return Tag == Other.Tag && Begin == Other.Begin && End == Other.End;
1336  }
1337  };
1338 
1339  /// Simple helper function to map a BundleOpInfo to an
1340  /// OperandBundleUse.
1342  operandBundleFromBundleOpInfo(const BundleOpInfo &BOI) const {
1343  auto op_begin = static_cast<const InstrTy *>(this)->op_begin();
1344  ArrayRef<Use> Inputs(op_begin + BOI.Begin, op_begin + BOI.End);
1345  return OperandBundleUse(BOI.Tag, Inputs);
1346  }
1347 
1348  using bundle_op_iterator = BundleOpInfo *;
1349  using const_bundle_op_iterator = const BundleOpInfo *;
1350 
1351  /// Return the start of the list of BundleOpInfo instances associated
1352  /// with this OperandBundleUser.
1354  if (!static_cast<InstrTy *>(this)->hasDescriptor())
1355  return nullptr;
1356 
1357  uint8_t *BytesBegin = static_cast<InstrTy *>(this)->getDescriptor().begin();
1358  return reinterpret_cast<bundle_op_iterator>(BytesBegin);
1359  }
1360 
1361  /// Return the start of the list of BundleOpInfo instances associated
1362  /// with this OperandBundleUser.
1364  auto *NonConstThis =
1365  const_cast<OperandBundleUser<InstrTy, OpIteratorTy> *>(this);
1366  return NonConstThis->bundle_op_info_begin();
1367  }
1368 
1369  /// Return the end of the list of BundleOpInfo instances associated
1370  /// with this OperandBundleUser.
1372  if (!static_cast<InstrTy *>(this)->hasDescriptor())
1373  return nullptr;
1374 
1375  uint8_t *BytesEnd = static_cast<InstrTy *>(this)->getDescriptor().end();
1376  return reinterpret_cast<bundle_op_iterator>(BytesEnd);
1377  }
1378 
1379  /// Return the end of the list of BundleOpInfo instances associated
1380  /// with this OperandBundleUser.
1382  auto *NonConstThis =
1383  const_cast<OperandBundleUser<InstrTy, OpIteratorTy> *>(this);
1384  return NonConstThis->bundle_op_info_end();
1385  }
1386 
1387  /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
1389  return make_range(bundle_op_info_begin(), bundle_op_info_end());
1390  }
1391 
1392  /// Return the range [\p bundle_op_info_begin, \p bundle_op_info_end).
1394  return make_range(bundle_op_info_begin(), bundle_op_info_end());
1395  }
1396 
1397  /// Populate the BundleOpInfo instances and the Use& vector from \p
1398  /// Bundles. Return the op_iterator pointing to the Use& one past the last
1399  /// last bundle operand use.
1400  ///
1401  /// Each \p OperandBundleDef instance is tracked by a OperandBundleInfo
1402  /// instance allocated in this User's descriptor.
1404  const unsigned BeginIndex) {
1405  auto It = static_cast<InstrTy *>(this)->op_begin() + BeginIndex;
1406  for (auto &B : Bundles)
1407  It = std::copy(B.input_begin(), B.input_end(), It);
1408 
1409  auto *ContextImpl = static_cast<InstrTy *>(this)->getContext().pImpl;
1410  auto BI = Bundles.begin();
1411  unsigned CurrentIndex = BeginIndex;
1412 
1413  for (auto &BOI : bundle_op_infos()) {
1414  assert(BI != Bundles.end() && "Incorrect allocation?");
1415 
1416  BOI.Tag = ContextImpl->getOrInsertBundleTag(BI->getTag());
1417  BOI.Begin = CurrentIndex;
1418  BOI.End = CurrentIndex + BI->input_size();
1419  CurrentIndex = BOI.End;
1420  BI++;
1421  }
1422 
1423  assert(BI == Bundles.end() && "Incorrect allocation?");
1424 
1425  return It;
1426  }
1427 
1428  /// Return the BundleOpInfo for the operand at index OpIdx.
1429  ///
1430  /// It is an error to call this with an OpIdx that does not correspond to an
1431  /// bundle operand.
1432  const BundleOpInfo &getBundleOpInfoForOperand(unsigned OpIdx) const {
1433  for (auto &BOI : bundle_op_infos())
1434  if (BOI.Begin <= OpIdx && OpIdx < BOI.End)
1435  return BOI;
1436 
1437  llvm_unreachable("Did not find operand bundle for operand!");
1438  }
1439 
1440  /// Return the total number of values used in \p Bundles.
1442  unsigned Total = 0;
1443  for (auto &B : Bundles)
1444  Total += B.input_size();
1445  return Total;
1446  }
1447 };
1448 
1449 } // end namespace llvm
1450 
1451 #endif // LLVM_IR_INSTRTYPES_H
bool isFPPredicate() const
Definition: InstrTypes.h:733
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:954
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:1115
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition: InstrTypes.h:782
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:631
Type * getSrcTy() const
Return the source type, as a convenience.
Definition: InstrTypes.h:606
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:173
OperandBundleDefT(std::string Tag, ArrayRef< InputTy > Inputs)
Definition: InstrTypes.h:1039
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition: InstrTypes.h:884
bool isFuncletPad() const
Definition: Instruction.h:135
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:311
unsigned getSubclassDataFromInstruction() const
Definition: Instruction.h:741
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
Definition: InstrTypes.h:1156
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:1441
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
Definition: InstrTypes.h:1110
uint32_t Begin
The index in the Use& vector where operands for this operand bundle starts.
Definition: InstrTypes.h:1328
bool operator==(const BundleOpInfo &Other) const
Definition: InstrTypes.h:1334
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
Definition: InstrTypes.h:1137
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:1149
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:705
static bool classof(const Value *V)
Definition: InstrTypes.h:620
typename std::vector< InputTy >::const_iterator input_iterator
Definition: InstrTypes.h:1049
#define op(i)
ArrayRef< InputTy > inputs() const
Definition: InstrTypes.h:1047
bool isTrueWhenEqual(CondCode Cond)
Return true if the specified condition returns true if the two operands to the condition are equal...
Definition: ISDOpcodes.h:994
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:1275
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:830
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:811
size_t input_size() const
Definition: InstrTypes.h:1051
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
Definition: InstrTypes.h:740
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:348
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:357
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:1007
bool isUnsigned() const
Definition: InstrTypes.h:817
bool hasClobberingOperandBundles() const
Return true if this operand bundle user has operand bundles that may write to the heap...
Definition: InstrTypes.h:1239
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:1353
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:286
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:711
#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:601
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:1017
void setParentPad(Value *ParentPad)
Definition: InstrTypes.h:946
const_op_range arg_operands() const
arg_operands - iteration adapter for range-for loops.
Definition: InstrTypes.h:960
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:1321
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:736
OperandBundleUse(StringMapEntry< uint32_t > *Tag, ArrayRef< Use > Inputs)
Definition: InstrTypes.h:983
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:875
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:419
bool isFnAttrDisallowedByOpBundle(Attribute::AttrKind A) const
Is the function attribute A disallowed by some operand bundle on this operand bundle user...
Definition: InstrTypes.h:1295
static bool isIntPredicate(Predicate P)
Definition: InstrTypes.h:727
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:1118
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:980
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:1196
iterator_range< const_bundle_op_iterator > bundle_op_infos() const
Return the range [bundle_op_info_begin, bundle_op_info_end).
Definition: InstrTypes.h:1393
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
ArrayRef< const uint8_t > getDescriptor() const
Returns the descriptor co-allocated with this User instance.
Definition: User.cpp:93
bool isBinaryOp() const
Definition: Instruction.h:131
static bool classof(const Value *V)
Definition: InstrTypes.h:326
bool isDeoptOperandBundle() const
Return true if this is a "deopt" operand bundle.
Definition: InstrTypes.h:1012
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:134
unsigned countOperandBundlesOfType(uint32_t ID) const
Return the number of operand bundles with the tag ID attached to this instruction.
Definition: InstrTypes.h:1167
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:1264
#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:1403
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:1130
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Value * getParentPad() const
Convenience accessors.
Definition: InstrTypes.h:945
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:988
bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const
Return true if the bundle operand at index OpIdx has the attribute A.
Definition: InstrTypes.h:1255
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:1037
const BundleOpInfo & getBundleOpInfoForOperand(unsigned OpIdx) const
Return the BundleOpInfo for the operand at index OpIdx.
Definition: InstrTypes.h:1432
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics for subclasses.
Definition: InstrTypes.h:351
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:1287
bundle_op_iterator bundle_op_info_end()
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1371
#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:1342
Type * getDestTy() const
Return the destination type, as a convenience.
Definition: InstrTypes.h:608
unsigned getNumArgOperands() const
getNumArgOperands - Return the number of funcletpad arguments.
Definition: InstrTypes.h:937
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:478
void setValueSubclassData(unsigned short D)
Definition: Value.h:656
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition: InstrTypes.h:721
Predicate getFlippedStrictnessPredicate() const
For predicate of kind "is X or equal to 0" returns the predicate "is X".
Definition: InstrTypes.h:771
void setOperand(unsigned i, Value *Val)
Definition: User.h:175
bool isIntPredicate() const
Definition: InstrTypes.h:734
bool isTrueWhenEqual() const
This is just a convenience.
Definition: InstrTypes.h:836
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:842
static bool isFPPredicate(Predicate P)
Definition: InstrTypes.h:723
StringRef getTag() const
Definition: InstrTypes.h:1055
A lightweight accessor for an operand bundle meant to be passed around by value.
Definition: InstrTypes.h:979
unsigned getBundleOperandsEndIndex() const
Return the index of the last bundle operand in the Use array.
Definition: InstrTypes.h:1124
uint32_t End
The index in the Use& vector where operands for this operand bundle ends.
Definition: InstrTypes.h:1332
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:1324
OperandBundleDefT(const OperandBundleUse &OBU)
Definition: InstrTypes.h:1042
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:716
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:1180
input_iterator input_begin() const
Definition: InstrTypes.h:1052
input_iterator input_end() const
Definition: InstrTypes.h:1053
#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:998
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:1363
OperandBundleUse getOperandBundleForOperand(unsigned OpIdx) const
Return the operand bundle for the operand at index OpIdx.
Definition: InstrTypes.h:1224
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Definition: InstrTypes.h:1215
static bool classof(const Value *V)
Definition: InstrTypes.h:879
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:957
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:1381
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:606
A container for an operand bundle being viewed as a set of values rather than a set of uses...
Definition: InstrTypes.h:1032
iterator_range< bundle_op_iterator > bundle_op_infos()
Return the range [bundle_op_info_begin, bundle_op_info_end).
Definition: InstrTypes.h:1388
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:756
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:953
Use & Op()
Definition: User.h:134
static bool classof(const Instruction *I)
Definition: InstrTypes.h:323
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:1100
static bool classof(const Instruction *I)
Definition: InstrTypes.h:965
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: InstrTypes.h:617
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:1230
static bool classof(const Value *V)
Definition: InstrTypes.h:966
A mixin to add operand bundle functionality to llvm instruction classes.
Definition: InstrTypes.h:1107
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:1107
Predicate getSwappedPredicate(Predicate Opcode)
Assume the condition register is set by MI(a,b), return the predicate if we modify the instructions s...