1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
19 #include "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/SmallVector.h"
34 //===----------------------------------------------------------------------===//
36 //===----------------------------------------------------------------------===//
38 /// AllocaInst - an instruction to allocate memory on the stack
40 class AllocaInst : public UnaryInstruction {
42 virtual AllocaInst *clone_impl() const;
44 explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
45 const Twine &Name = "", Instruction *InsertBefore = 0);
46 AllocaInst(Type *Ty, Value *ArraySize,
47 const Twine &Name, BasicBlock *InsertAtEnd);
49 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
50 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
52 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
53 const Twine &Name = "", Instruction *InsertBefore = 0);
54 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
55 const Twine &Name, BasicBlock *InsertAtEnd);
57 // Out of line virtual method, so the vtable, etc. has a home.
58 virtual ~AllocaInst();
60 /// isArrayAllocation - Return true if there is an allocation size parameter
61 /// to the allocation instruction that is not 1.
63 bool isArrayAllocation() const;
65 /// getArraySize - Get the number of elements allocated. For a simple
66 /// allocation of a single element, this will return a constant 1 value.
68 const Value *getArraySize() const { return getOperand(0); }
69 Value *getArraySize() { return getOperand(0); }
71 /// getType - Overload to return most specific pointer type
73 PointerType *getType() const {
74 return reinterpret_cast<PointerType*>(Instruction::getType());
77 /// getAllocatedType - Return the type that is being allocated by the
80 Type *getAllocatedType() const;
82 /// getAlignment - Return the alignment of the memory that is being allocated
83 /// by the instruction.
85 unsigned getAlignment() const {
86 return (1u << getSubclassDataFromInstruction()) >> 1;
88 void setAlignment(unsigned Align);
90 /// isStaticAlloca - Return true if this alloca is in the entry block of the
91 /// function and is a constant size. If so, the code generator will fold it
92 /// into the prolog/epilog code, so it is basically free.
93 bool isStaticAlloca() const;
95 // Methods for support type inquiry through isa, cast, and dyn_cast:
96 static inline bool classof(const AllocaInst *) { return true; }
97 static inline bool classof(const Instruction *I) {
98 return (I->getOpcode() == Instruction::Alloca);
100 static inline bool classof(const Value *V) {
101 return isa<Instruction>(V) && classof(cast<Instruction>(V));
104 // Shadow Instruction::setInstructionSubclassData with a private forwarding
105 // method so that subclasses cannot accidentally use it.
106 void setInstructionSubclassData(unsigned short D) {
107 Instruction::setInstructionSubclassData(D);
112 //===----------------------------------------------------------------------===//
114 //===----------------------------------------------------------------------===//
116 /// LoadInst - an instruction for reading from memory. This uses the
117 /// SubclassData field in Value to store whether or not the load is volatile.
119 class LoadInst : public UnaryInstruction {
122 virtual LoadInst *clone_impl() const;
124 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
125 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
126 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
127 Instruction *InsertBefore = 0);
128 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
129 unsigned Align, Instruction *InsertBefore = 0);
130 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
131 BasicBlock *InsertAtEnd);
132 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
133 unsigned Align, BasicBlock *InsertAtEnd);
135 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
136 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
137 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
138 bool isVolatile = false, Instruction *InsertBefore = 0);
139 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
140 BasicBlock *InsertAtEnd);
142 /// isVolatile - Return true if this is a load from a volatile memory
145 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
147 /// setVolatile - Specify whether this is a volatile load or not.
149 void setVolatile(bool V) {
150 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
154 /// getAlignment - Return the alignment of the access that is being performed
156 unsigned getAlignment() const {
157 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
160 void setAlignment(unsigned Align);
162 Value *getPointerOperand() { return getOperand(0); }
163 const Value *getPointerOperand() const { return getOperand(0); }
164 static unsigned getPointerOperandIndex() { return 0U; }
166 unsigned getPointerAddressSpace() const {
167 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
171 // Methods for support type inquiry through isa, cast, and dyn_cast:
172 static inline bool classof(const LoadInst *) { return true; }
173 static inline bool classof(const Instruction *I) {
174 return I->getOpcode() == Instruction::Load;
176 static inline bool classof(const Value *V) {
177 return isa<Instruction>(V) && classof(cast<Instruction>(V));
180 // Shadow Instruction::setInstructionSubclassData with a private forwarding
181 // method so that subclasses cannot accidentally use it.
182 void setInstructionSubclassData(unsigned short D) {
183 Instruction::setInstructionSubclassData(D);
188 //===----------------------------------------------------------------------===//
190 //===----------------------------------------------------------------------===//
192 /// StoreInst - an instruction for storing to memory
194 class StoreInst : public Instruction {
195 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
198 virtual StoreInst *clone_impl() const;
200 // allocate space for exactly two operands
201 void *operator new(size_t s) {
202 return User::operator new(s, 2);
204 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
205 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
206 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
207 Instruction *InsertBefore = 0);
208 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
209 unsigned Align, Instruction *InsertBefore = 0);
210 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
211 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
212 unsigned Align, BasicBlock *InsertAtEnd);
215 /// isVolatile - Return true if this is a load from a volatile memory
218 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
220 /// setVolatile - Specify whether this is a volatile load or not.
222 void setVolatile(bool V) {
223 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
227 /// Transparently provide more efficient getOperand methods.
228 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
230 /// getAlignment - Return the alignment of the access that is being performed
232 unsigned getAlignment() const {
233 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
236 void setAlignment(unsigned Align);
238 Value *getValueOperand() { return getOperand(0); }
239 const Value *getValueOperand() const { return getOperand(0); }
241 Value *getPointerOperand() { return getOperand(1); }
242 const Value *getPointerOperand() const { return getOperand(1); }
243 static unsigned getPointerOperandIndex() { return 1U; }
245 unsigned getPointerAddressSpace() const {
246 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
249 // Methods for support type inquiry through isa, cast, and dyn_cast:
250 static inline bool classof(const StoreInst *) { return true; }
251 static inline bool classof(const Instruction *I) {
252 return I->getOpcode() == Instruction::Store;
254 static inline bool classof(const Value *V) {
255 return isa<Instruction>(V) && classof(cast<Instruction>(V));
258 // Shadow Instruction::setInstructionSubclassData with a private forwarding
259 // method so that subclasses cannot accidentally use it.
260 void setInstructionSubclassData(unsigned short D) {
261 Instruction::setInstructionSubclassData(D);
266 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
269 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
271 //===----------------------------------------------------------------------===//
272 // GetElementPtrInst Class
273 //===----------------------------------------------------------------------===//
275 // checkGEPType - Simple wrapper function to give a better assertion failure
276 // message on bad indexes for a gep instruction.
278 static inline Type *checkGEPType(Type *Ty) {
279 assert(Ty && "Invalid GetElementPtrInst indices for type!");
283 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
284 /// access elements of arrays and structs
286 class GetElementPtrInst : public Instruction {
287 GetElementPtrInst(const GetElementPtrInst &GEPI);
288 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
290 /// Constructors - Create a getelementptr instruction with a base pointer an
291 /// list of indices. The first ctor can optionally insert before an existing
292 /// instruction, the second appends the new instruction to the specified
294 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
295 unsigned Values, const Twine &NameStr,
296 Instruction *InsertBefore);
297 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
298 unsigned Values, const Twine &NameStr,
299 BasicBlock *InsertAtEnd);
301 virtual GetElementPtrInst *clone_impl() const;
303 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
304 const Twine &NameStr = "",
305 Instruction *InsertBefore = 0) {
306 unsigned Values = 1 + unsigned(IdxList.size());
308 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
310 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
311 const Twine &NameStr,
312 BasicBlock *InsertAtEnd) {
313 unsigned Values = 1 + unsigned(IdxList.size());
315 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
318 /// Create an "inbounds" getelementptr. See the documentation for the
319 /// "inbounds" flag in LangRef.html for details.
320 static GetElementPtrInst *CreateInBounds(Value *Ptr,
321 ArrayRef<Value *> IdxList,
322 const Twine &NameStr = "",
323 Instruction *InsertBefore = 0) {
324 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
325 GEP->setIsInBounds(true);
328 static GetElementPtrInst *CreateInBounds(Value *Ptr,
329 ArrayRef<Value *> IdxList,
330 const Twine &NameStr,
331 BasicBlock *InsertAtEnd) {
332 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
333 GEP->setIsInBounds(true);
337 /// Transparently provide more efficient getOperand methods.
338 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
340 // getType - Overload to return most specific pointer type...
341 PointerType *getType() const {
342 return reinterpret_cast<PointerType*>(Instruction::getType());
345 /// getIndexedType - Returns the type of the element that would be loaded with
346 /// a load instruction with the specified parameters.
348 /// Null is returned if the indices are invalid for the specified
351 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
352 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
353 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
355 inline op_iterator idx_begin() { return op_begin()+1; }
356 inline const_op_iterator idx_begin() const { return op_begin()+1; }
357 inline op_iterator idx_end() { return op_end(); }
358 inline const_op_iterator idx_end() const { return op_end(); }
360 Value *getPointerOperand() {
361 return getOperand(0);
363 const Value *getPointerOperand() const {
364 return getOperand(0);
366 static unsigned getPointerOperandIndex() {
367 return 0U; // get index for modifying correct operand
370 unsigned getPointerAddressSpace() const {
371 return cast<PointerType>(getType())->getAddressSpace();
374 /// getPointerOperandType - Method to return the pointer operand as a
376 PointerType *getPointerOperandType() const {
377 return reinterpret_cast<PointerType*>(getPointerOperand()->getType());
381 unsigned getNumIndices() const { // Note: always non-negative
382 return getNumOperands() - 1;
385 bool hasIndices() const {
386 return getNumOperands() > 1;
389 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
390 /// zeros. If so, the result pointer and the first operand have the same
391 /// value, just potentially different types.
392 bool hasAllZeroIndices() const;
394 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
395 /// constant integers. If so, the result pointer and the first operand have
396 /// a constant offset between them.
397 bool hasAllConstantIndices() const;
399 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
400 /// See LangRef.html for the meaning of inbounds on a getelementptr.
401 void setIsInBounds(bool b = true);
403 /// isInBounds - Determine whether the GEP has the inbounds flag.
404 bool isInBounds() const;
406 // Methods for support type inquiry through isa, cast, and dyn_cast:
407 static inline bool classof(const GetElementPtrInst *) { return true; }
408 static inline bool classof(const Instruction *I) {
409 return (I->getOpcode() == Instruction::GetElementPtr);
411 static inline bool classof(const Value *V) {
412 return isa<Instruction>(V) && classof(cast<Instruction>(V));
417 struct OperandTraits<GetElementPtrInst> :
418 public VariadicOperandTraits<GetElementPtrInst, 1> {
421 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
422 ArrayRef<Value *> IdxList,
424 const Twine &NameStr,
425 Instruction *InsertBefore)
426 : Instruction(PointerType::get(checkGEPType(
427 getIndexedType(Ptr->getType(), IdxList)),
428 cast<PointerType>(Ptr->getType())
429 ->getAddressSpace()),
431 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
432 Values, InsertBefore) {
433 init(Ptr, IdxList, NameStr);
435 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
436 ArrayRef<Value *> IdxList,
438 const Twine &NameStr,
439 BasicBlock *InsertAtEnd)
440 : Instruction(PointerType::get(checkGEPType(
441 getIndexedType(Ptr->getType(), IdxList)),
442 cast<PointerType>(Ptr->getType())
443 ->getAddressSpace()),
445 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
446 Values, InsertAtEnd) {
447 init(Ptr, IdxList, NameStr);
451 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
454 //===----------------------------------------------------------------------===//
456 //===----------------------------------------------------------------------===//
458 /// This instruction compares its operands according to the predicate given
459 /// to the constructor. It only operates on integers or pointers. The operands
460 /// must be identical types.
461 /// @brief Represent an integer comparison operator.
462 class ICmpInst: public CmpInst {
464 /// @brief Clone an identical ICmpInst
465 virtual ICmpInst *clone_impl() const;
467 /// @brief Constructor with insert-before-instruction semantics.
469 Instruction *InsertBefore, ///< Where to insert
470 Predicate pred, ///< The predicate to use for the comparison
471 Value *LHS, ///< The left-hand-side of the expression
472 Value *RHS, ///< The right-hand-side of the expression
473 const Twine &NameStr = "" ///< Name of the instruction
474 ) : CmpInst(makeCmpResultType(LHS->getType()),
475 Instruction::ICmp, pred, LHS, RHS, NameStr,
477 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
478 pred <= CmpInst::LAST_ICMP_PREDICATE &&
479 "Invalid ICmp predicate value");
480 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
481 "Both operands to ICmp instruction are not of the same type!");
482 // Check that the operands are the right type
483 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
484 getOperand(0)->getType()->isPointerTy()) &&
485 "Invalid operand types for ICmp instruction");
488 /// @brief Constructor with insert-at-end semantics.
490 BasicBlock &InsertAtEnd, ///< Block to insert into.
491 Predicate pred, ///< The predicate to use for the comparison
492 Value *LHS, ///< The left-hand-side of the expression
493 Value *RHS, ///< The right-hand-side of the expression
494 const Twine &NameStr = "" ///< Name of the instruction
495 ) : CmpInst(makeCmpResultType(LHS->getType()),
496 Instruction::ICmp, pred, LHS, RHS, NameStr,
498 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
499 pred <= CmpInst::LAST_ICMP_PREDICATE &&
500 "Invalid ICmp predicate value");
501 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
502 "Both operands to ICmp instruction are not of the same type!");
503 // Check that the operands are the right type
504 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
505 getOperand(0)->getType()->isPointerTy()) &&
506 "Invalid operand types for ICmp instruction");
509 /// @brief Constructor with no-insertion semantics
511 Predicate pred, ///< The predicate to use for the comparison
512 Value *LHS, ///< The left-hand-side of the expression
513 Value *RHS, ///< The right-hand-side of the expression
514 const Twine &NameStr = "" ///< Name of the instruction
515 ) : CmpInst(makeCmpResultType(LHS->getType()),
516 Instruction::ICmp, pred, LHS, RHS, NameStr) {
517 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
518 pred <= CmpInst::LAST_ICMP_PREDICATE &&
519 "Invalid ICmp predicate value");
520 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
521 "Both operands to ICmp instruction are not of the same type!");
522 // Check that the operands are the right type
523 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
524 getOperand(0)->getType()->isPointerTy()) &&
525 "Invalid operand types for ICmp instruction");
528 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
529 /// @returns the predicate that would be the result if the operand were
530 /// regarded as signed.
531 /// @brief Return the signed version of the predicate
532 Predicate getSignedPredicate() const {
533 return getSignedPredicate(getPredicate());
536 /// This is a static version that you can use without an instruction.
537 /// @brief Return the signed version of the predicate.
538 static Predicate getSignedPredicate(Predicate pred);
540 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
541 /// @returns the predicate that would be the result if the operand were
542 /// regarded as unsigned.
543 /// @brief Return the unsigned version of the predicate
544 Predicate getUnsignedPredicate() const {
545 return getUnsignedPredicate(getPredicate());
548 /// This is a static version that you can use without an instruction.
549 /// @brief Return the unsigned version of the predicate.
550 static Predicate getUnsignedPredicate(Predicate pred);
552 /// isEquality - Return true if this predicate is either EQ or NE. This also
553 /// tests for commutativity.
554 static bool isEquality(Predicate P) {
555 return P == ICMP_EQ || P == ICMP_NE;
558 /// isEquality - Return true if this predicate is either EQ or NE. This also
559 /// tests for commutativity.
560 bool isEquality() const {
561 return isEquality(getPredicate());
564 /// @returns true if the predicate of this ICmpInst is commutative
565 /// @brief Determine if this relation is commutative.
566 bool isCommutative() const { return isEquality(); }
568 /// isRelational - Return true if the predicate is relational (not EQ or NE).
570 bool isRelational() const {
571 return !isEquality();
574 /// isRelational - Return true if the predicate is relational (not EQ or NE).
576 static bool isRelational(Predicate P) {
577 return !isEquality(P);
580 /// Initialize a set of values that all satisfy the predicate with C.
581 /// @brief Make a ConstantRange for a relation with a constant value.
582 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
584 /// Exchange the two operands to this instruction in such a way that it does
585 /// not modify the semantics of the instruction. The predicate value may be
586 /// changed to retain the same result if the predicate is order dependent
588 /// @brief Swap operands and adjust predicate.
589 void swapOperands() {
590 setPredicate(getSwappedPredicate());
591 Op<0>().swap(Op<1>());
594 // Methods for support type inquiry through isa, cast, and dyn_cast:
595 static inline bool classof(const ICmpInst *) { return true; }
596 static inline bool classof(const Instruction *I) {
597 return I->getOpcode() == Instruction::ICmp;
599 static inline bool classof(const Value *V) {
600 return isa<Instruction>(V) && classof(cast<Instruction>(V));
605 //===----------------------------------------------------------------------===//
607 //===----------------------------------------------------------------------===//
609 /// This instruction compares its operands according to the predicate given
610 /// to the constructor. It only operates on floating point values or packed
611 /// vectors of floating point values. The operands must be identical types.
612 /// @brief Represents a floating point comparison operator.
613 class FCmpInst: public CmpInst {
615 /// @brief Clone an identical FCmpInst
616 virtual FCmpInst *clone_impl() const;
618 /// @brief Constructor with insert-before-instruction semantics.
620 Instruction *InsertBefore, ///< Where to insert
621 Predicate pred, ///< The predicate to use for the comparison
622 Value *LHS, ///< The left-hand-side of the expression
623 Value *RHS, ///< The right-hand-side of the expression
624 const Twine &NameStr = "" ///< Name of the instruction
625 ) : CmpInst(makeCmpResultType(LHS->getType()),
626 Instruction::FCmp, pred, LHS, RHS, NameStr,
628 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
629 "Invalid FCmp predicate value");
630 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
631 "Both operands to FCmp instruction are not of the same type!");
632 // Check that the operands are the right type
633 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
634 "Invalid operand types for FCmp instruction");
637 /// @brief Constructor with insert-at-end semantics.
639 BasicBlock &InsertAtEnd, ///< Block to insert into.
640 Predicate pred, ///< The predicate to use for the comparison
641 Value *LHS, ///< The left-hand-side of the expression
642 Value *RHS, ///< The right-hand-side of the expression
643 const Twine &NameStr = "" ///< Name of the instruction
644 ) : CmpInst(makeCmpResultType(LHS->getType()),
645 Instruction::FCmp, pred, LHS, RHS, NameStr,
647 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
648 "Invalid FCmp predicate value");
649 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
650 "Both operands to FCmp instruction are not of the same type!");
651 // Check that the operands are the right type
652 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
653 "Invalid operand types for FCmp instruction");
656 /// @brief Constructor with no-insertion semantics
658 Predicate pred, ///< The predicate to use for the comparison
659 Value *LHS, ///< The left-hand-side of the expression
660 Value *RHS, ///< The right-hand-side of the expression
661 const Twine &NameStr = "" ///< Name of the instruction
662 ) : CmpInst(makeCmpResultType(LHS->getType()),
663 Instruction::FCmp, pred, LHS, RHS, NameStr) {
664 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
665 "Invalid FCmp predicate value");
666 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
667 "Both operands to FCmp instruction are not of the same type!");
668 // Check that the operands are the right type
669 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
670 "Invalid operand types for FCmp instruction");
673 /// @returns true if the predicate of this instruction is EQ or NE.
674 /// @brief Determine if this is an equality predicate.
675 bool isEquality() const {
676 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
677 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
680 /// @returns true if the predicate of this instruction is commutative.
681 /// @brief Determine if this is a commutative predicate.
682 bool isCommutative() const {
683 return isEquality() ||
684 getPredicate() == FCMP_FALSE ||
685 getPredicate() == FCMP_TRUE ||
686 getPredicate() == FCMP_ORD ||
687 getPredicate() == FCMP_UNO;
690 /// @returns true if the predicate is relational (not EQ or NE).
691 /// @brief Determine if this a relational predicate.
692 bool isRelational() const { return !isEquality(); }
694 /// Exchange the two operands to this instruction in such a way that it does
695 /// not modify the semantics of the instruction. The predicate value may be
696 /// changed to retain the same result if the predicate is order dependent
698 /// @brief Swap operands and adjust predicate.
699 void swapOperands() {
700 setPredicate(getSwappedPredicate());
701 Op<0>().swap(Op<1>());
704 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
705 static inline bool classof(const FCmpInst *) { return true; }
706 static inline bool classof(const Instruction *I) {
707 return I->getOpcode() == Instruction::FCmp;
709 static inline bool classof(const Value *V) {
710 return isa<Instruction>(V) && classof(cast<Instruction>(V));
714 //===----------------------------------------------------------------------===//
715 /// CallInst - This class represents a function call, abstracting a target
716 /// machine's calling convention. This class uses low bit of the SubClassData
717 /// field to indicate whether or not this is a tail call. The rest of the bits
718 /// hold the calling convention of the call.
720 class CallInst : public Instruction {
721 AttrListPtr AttributeList; ///< parameter attributes for call
722 CallInst(const CallInst &CI);
723 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
724 void init(Value *Func, const Twine &NameStr);
726 /// Construct a CallInst given a range of arguments.
727 /// @brief Construct a CallInst from a range of arguments
728 inline CallInst(Value *Func, ArrayRef<Value *> Args,
729 const Twine &NameStr, Instruction *InsertBefore);
731 /// Construct a CallInst given a range of arguments.
732 /// @brief Construct a CallInst from a range of arguments
733 inline CallInst(Value *Func, ArrayRef<Value *> Args,
734 const Twine &NameStr, BasicBlock *InsertAtEnd);
736 CallInst(Value *F, Value *Actual, const Twine &NameStr,
737 Instruction *InsertBefore);
738 CallInst(Value *F, Value *Actual, const Twine &NameStr,
739 BasicBlock *InsertAtEnd);
740 explicit CallInst(Value *F, const Twine &NameStr,
741 Instruction *InsertBefore);
742 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
744 virtual CallInst *clone_impl() const;
746 static CallInst *Create(Value *Func,
747 ArrayRef<Value *> Args,
748 const Twine &NameStr = "",
749 Instruction *InsertBefore = 0) {
750 return new(unsigned(Args.size() + 1))
751 CallInst(Func, Args, NameStr, InsertBefore);
753 static CallInst *Create(Value *Func,
754 ArrayRef<Value *> Args,
755 const Twine &NameStr, BasicBlock *InsertAtEnd) {
756 return new(unsigned(Args.size() + 1))
757 CallInst(Func, Args, NameStr, InsertAtEnd);
759 static CallInst *Create(Value *F, const Twine &NameStr = "",
760 Instruction *InsertBefore = 0) {
761 return new(1) CallInst(F, NameStr, InsertBefore);
763 static CallInst *Create(Value *F, const Twine &NameStr,
764 BasicBlock *InsertAtEnd) {
765 return new(1) CallInst(F, NameStr, InsertAtEnd);
767 /// CreateMalloc - Generate the IR for a call to malloc:
768 /// 1. Compute the malloc call's argument as the specified type's size,
769 /// possibly multiplied by the array size if the array size is not
771 /// 2. Call malloc with that argument.
772 /// 3. Bitcast the result of the malloc call to the specified type.
773 static Instruction *CreateMalloc(Instruction *InsertBefore,
774 Type *IntPtrTy, Type *AllocTy,
775 Value *AllocSize, Value *ArraySize = 0,
776 Function* MallocF = 0,
777 const Twine &Name = "");
778 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
779 Type *IntPtrTy, Type *AllocTy,
780 Value *AllocSize, Value *ArraySize = 0,
781 Function* MallocF = 0,
782 const Twine &Name = "");
783 /// CreateFree - Generate the IR for a call to the builtin free function.
784 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
785 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
789 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
790 void setTailCall(bool isTC = true) {
791 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
795 /// Provide fast operand accessors
796 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
798 /// getNumArgOperands - Return the number of call arguments.
800 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
802 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
804 Value *getArgOperand(unsigned i) const { return getOperand(i); }
805 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
807 /// getCallingConv/setCallingConv - Get or set the calling convention of this
809 CallingConv::ID getCallingConv() const {
810 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
812 void setCallingConv(CallingConv::ID CC) {
813 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
814 (static_cast<unsigned>(CC) << 1));
817 /// getAttributes - Return the parameter attributes for this call.
819 const AttrListPtr &getAttributes() const { return AttributeList; }
821 /// setAttributes - Set the parameter attributes for this call.
823 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
825 /// addAttribute - adds the attribute to the list of attributes.
826 void addAttribute(unsigned i, Attributes attr);
828 /// removeAttribute - removes the attribute from the list of attributes.
829 void removeAttribute(unsigned i, Attributes attr);
831 /// @brief Determine whether the call or the callee has the given attribute.
832 bool paramHasAttr(unsigned i, Attributes attr) const;
834 /// @brief Extract the alignment for a call or parameter (0=unknown).
835 unsigned getParamAlignment(unsigned i) const {
836 return AttributeList.getParamAlignment(i);
839 /// @brief Return true if the call should not be inlined.
840 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
841 void setIsNoInline(bool Value = true) {
842 if (Value) addAttribute(~0, Attribute::NoInline);
843 else removeAttribute(~0, Attribute::NoInline);
846 /// @brief Determine if the call does not access memory.
847 bool doesNotAccessMemory() const {
848 return paramHasAttr(~0, Attribute::ReadNone);
850 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
851 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
852 else removeAttribute(~0, Attribute::ReadNone);
855 /// @brief Determine if the call does not access or only reads memory.
856 bool onlyReadsMemory() const {
857 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
859 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
860 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
861 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
864 /// @brief Determine if the call cannot return.
865 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
866 void setDoesNotReturn(bool DoesNotReturn = true) {
867 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
868 else removeAttribute(~0, Attribute::NoReturn);
871 /// @brief Determine if the call cannot unwind.
872 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
873 void setDoesNotThrow(bool DoesNotThrow = true) {
874 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
875 else removeAttribute(~0, Attribute::NoUnwind);
878 /// @brief Determine if the call returns a structure through first
879 /// pointer argument.
880 bool hasStructRetAttr() const {
881 // Be friendly and also check the callee.
882 return paramHasAttr(1, Attribute::StructRet);
885 /// @brief Determine if any call argument is an aggregate passed by value.
886 bool hasByValArgument() const {
887 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
890 /// getCalledFunction - Return the function called, or null if this is an
891 /// indirect function invocation.
893 Function *getCalledFunction() const {
894 return dyn_cast<Function>(Op<-1>());
897 /// getCalledValue - Get a pointer to the function that is invoked by this
899 const Value *getCalledValue() const { return Op<-1>(); }
900 Value *getCalledValue() { return Op<-1>(); }
902 /// setCalledFunction - Set the function called.
903 void setCalledFunction(Value* Fn) {
907 /// isInlineAsm - Check if this call is an inline asm statement.
908 bool isInlineAsm() const {
909 return isa<InlineAsm>(Op<-1>());
912 // Methods for support type inquiry through isa, cast, and dyn_cast:
913 static inline bool classof(const CallInst *) { return true; }
914 static inline bool classof(const Instruction *I) {
915 return I->getOpcode() == Instruction::Call;
917 static inline bool classof(const Value *V) {
918 return isa<Instruction>(V) && classof(cast<Instruction>(V));
921 // Shadow Instruction::setInstructionSubclassData with a private forwarding
922 // method so that subclasses cannot accidentally use it.
923 void setInstructionSubclassData(unsigned short D) {
924 Instruction::setInstructionSubclassData(D);
929 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
932 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
933 const Twine &NameStr, BasicBlock *InsertAtEnd)
934 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
935 ->getElementType())->getReturnType(),
937 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
938 unsigned(Args.size() + 1), InsertAtEnd) {
939 init(Func, Args, NameStr);
942 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
943 const Twine &NameStr, Instruction *InsertBefore)
944 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
945 ->getElementType())->getReturnType(),
947 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
948 unsigned(Args.size() + 1), InsertBefore) {
949 init(Func, Args, NameStr);
953 // Note: if you get compile errors about private methods then
954 // please update your code to use the high-level operand
955 // interfaces. See line 943 above.
956 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
958 //===----------------------------------------------------------------------===//
960 //===----------------------------------------------------------------------===//
962 /// SelectInst - This class represents the LLVM 'select' instruction.
964 class SelectInst : public Instruction {
965 void init(Value *C, Value *S1, Value *S2) {
966 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
972 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
973 Instruction *InsertBefore)
974 : Instruction(S1->getType(), Instruction::Select,
975 &Op<0>(), 3, InsertBefore) {
979 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
980 BasicBlock *InsertAtEnd)
981 : Instruction(S1->getType(), Instruction::Select,
982 &Op<0>(), 3, InsertAtEnd) {
987 virtual SelectInst *clone_impl() const;
989 static SelectInst *Create(Value *C, Value *S1, Value *S2,
990 const Twine &NameStr = "",
991 Instruction *InsertBefore = 0) {
992 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
994 static SelectInst *Create(Value *C, Value *S1, Value *S2,
995 const Twine &NameStr,
996 BasicBlock *InsertAtEnd) {
997 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1000 const Value *getCondition() const { return Op<0>(); }
1001 const Value *getTrueValue() const { return Op<1>(); }
1002 const Value *getFalseValue() const { return Op<2>(); }
1003 Value *getCondition() { return Op<0>(); }
1004 Value *getTrueValue() { return Op<1>(); }
1005 Value *getFalseValue() { return Op<2>(); }
1007 /// areInvalidOperands - Return a string if the specified operands are invalid
1008 /// for a select operation, otherwise return null.
1009 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1011 /// Transparently provide more efficient getOperand methods.
1012 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1014 OtherOps getOpcode() const {
1015 return static_cast<OtherOps>(Instruction::getOpcode());
1018 // Methods for support type inquiry through isa, cast, and dyn_cast:
1019 static inline bool classof(const SelectInst *) { return true; }
1020 static inline bool classof(const Instruction *I) {
1021 return I->getOpcode() == Instruction::Select;
1023 static inline bool classof(const Value *V) {
1024 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1029 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1032 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1034 //===----------------------------------------------------------------------===//
1036 //===----------------------------------------------------------------------===//
1038 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1039 /// an argument of the specified type given a va_list and increments that list
1041 class VAArgInst : public UnaryInstruction {
1043 virtual VAArgInst *clone_impl() const;
1046 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1047 Instruction *InsertBefore = 0)
1048 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1051 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1052 BasicBlock *InsertAtEnd)
1053 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1057 Value *getPointerOperand() { return getOperand(0); }
1058 const Value *getPointerOperand() const { return getOperand(0); }
1059 static unsigned getPointerOperandIndex() { return 0U; }
1061 // Methods for support type inquiry through isa, cast, and dyn_cast:
1062 static inline bool classof(const VAArgInst *) { return true; }
1063 static inline bool classof(const Instruction *I) {
1064 return I->getOpcode() == VAArg;
1066 static inline bool classof(const Value *V) {
1067 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1071 //===----------------------------------------------------------------------===//
1072 // ExtractElementInst Class
1073 //===----------------------------------------------------------------------===//
1075 /// ExtractElementInst - This instruction extracts a single (scalar)
1076 /// element from a VectorType value
1078 class ExtractElementInst : public Instruction {
1079 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1080 Instruction *InsertBefore = 0);
1081 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1082 BasicBlock *InsertAtEnd);
1084 virtual ExtractElementInst *clone_impl() const;
1087 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1088 const Twine &NameStr = "",
1089 Instruction *InsertBefore = 0) {
1090 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1092 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1093 const Twine &NameStr,
1094 BasicBlock *InsertAtEnd) {
1095 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1098 /// isValidOperands - Return true if an extractelement instruction can be
1099 /// formed with the specified operands.
1100 static bool isValidOperands(const Value *Vec, const Value *Idx);
1102 Value *getVectorOperand() { return Op<0>(); }
1103 Value *getIndexOperand() { return Op<1>(); }
1104 const Value *getVectorOperand() const { return Op<0>(); }
1105 const Value *getIndexOperand() const { return Op<1>(); }
1107 VectorType *getVectorOperandType() const {
1108 return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
1112 /// Transparently provide more efficient getOperand methods.
1113 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1115 // Methods for support type inquiry through isa, cast, and dyn_cast:
1116 static inline bool classof(const ExtractElementInst *) { return true; }
1117 static inline bool classof(const Instruction *I) {
1118 return I->getOpcode() == Instruction::ExtractElement;
1120 static inline bool classof(const Value *V) {
1121 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1126 struct OperandTraits<ExtractElementInst> :
1127 public FixedNumOperandTraits<ExtractElementInst, 2> {
1130 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1132 //===----------------------------------------------------------------------===//
1133 // InsertElementInst Class
1134 //===----------------------------------------------------------------------===//
1136 /// InsertElementInst - This instruction inserts a single (scalar)
1137 /// element into a VectorType value
1139 class InsertElementInst : public Instruction {
1140 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1141 const Twine &NameStr = "",
1142 Instruction *InsertBefore = 0);
1143 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1144 const Twine &NameStr, BasicBlock *InsertAtEnd);
1146 virtual InsertElementInst *clone_impl() const;
1149 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1150 const Twine &NameStr = "",
1151 Instruction *InsertBefore = 0) {
1152 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1154 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1155 const Twine &NameStr,
1156 BasicBlock *InsertAtEnd) {
1157 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1160 /// isValidOperands - Return true if an insertelement instruction can be
1161 /// formed with the specified operands.
1162 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1165 /// getType - Overload to return most specific vector type.
1167 VectorType *getType() const {
1168 return reinterpret_cast<VectorType*>(Instruction::getType());
1171 /// Transparently provide more efficient getOperand methods.
1172 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1174 // Methods for support type inquiry through isa, cast, and dyn_cast:
1175 static inline bool classof(const InsertElementInst *) { return true; }
1176 static inline bool classof(const Instruction *I) {
1177 return I->getOpcode() == Instruction::InsertElement;
1179 static inline bool classof(const Value *V) {
1180 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1185 struct OperandTraits<InsertElementInst> :
1186 public FixedNumOperandTraits<InsertElementInst, 3> {
1189 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1191 //===----------------------------------------------------------------------===//
1192 // ShuffleVectorInst Class
1193 //===----------------------------------------------------------------------===//
1195 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1198 class ShuffleVectorInst : public Instruction {
1200 virtual ShuffleVectorInst *clone_impl() const;
1203 // allocate space for exactly three operands
1204 void *operator new(size_t s) {
1205 return User::operator new(s, 3);
1207 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1208 const Twine &NameStr = "",
1209 Instruction *InsertBefor = 0);
1210 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1211 const Twine &NameStr, BasicBlock *InsertAtEnd);
1213 /// isValidOperands - Return true if a shufflevector instruction can be
1214 /// formed with the specified operands.
1215 static bool isValidOperands(const Value *V1, const Value *V2,
1218 /// getType - Overload to return most specific vector type.
1220 VectorType *getType() const {
1221 return reinterpret_cast<VectorType*>(Instruction::getType());
1224 /// Transparently provide more efficient getOperand methods.
1225 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1227 /// getMaskValue - Return the index from the shuffle mask for the specified
1228 /// output result. This is either -1 if the element is undef or a number less
1229 /// than 2*numelements.
1230 int getMaskValue(unsigned i) const;
1232 // Methods for support type inquiry through isa, cast, and dyn_cast:
1233 static inline bool classof(const ShuffleVectorInst *) { return true; }
1234 static inline bool classof(const Instruction *I) {
1235 return I->getOpcode() == Instruction::ShuffleVector;
1237 static inline bool classof(const Value *V) {
1238 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1243 struct OperandTraits<ShuffleVectorInst> :
1244 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1247 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1249 //===----------------------------------------------------------------------===//
1250 // ExtractValueInst Class
1251 //===----------------------------------------------------------------------===//
1253 /// ExtractValueInst - This instruction extracts a struct member or array
1254 /// element value from an aggregate value.
1256 class ExtractValueInst : public UnaryInstruction {
1257 SmallVector<unsigned, 4> Indices;
1259 ExtractValueInst(const ExtractValueInst &EVI);
1260 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1262 /// Constructors - Create a extractvalue instruction with a base aggregate
1263 /// value and a list of indices. The first ctor can optionally insert before
1264 /// an existing instruction, the second appends the new instruction to the
1265 /// specified BasicBlock.
1266 inline ExtractValueInst(Value *Agg,
1267 ArrayRef<unsigned> Idxs,
1268 const Twine &NameStr,
1269 Instruction *InsertBefore);
1270 inline ExtractValueInst(Value *Agg,
1271 ArrayRef<unsigned> Idxs,
1272 const Twine &NameStr, BasicBlock *InsertAtEnd);
1274 // allocate space for exactly one operand
1275 void *operator new(size_t s) {
1276 return User::operator new(s, 1);
1279 virtual ExtractValueInst *clone_impl() const;
1282 static ExtractValueInst *Create(Value *Agg,
1283 ArrayRef<unsigned> Idxs,
1284 const Twine &NameStr = "",
1285 Instruction *InsertBefore = 0) {
1287 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1289 static ExtractValueInst *Create(Value *Agg,
1290 ArrayRef<unsigned> Idxs,
1291 const Twine &NameStr,
1292 BasicBlock *InsertAtEnd) {
1293 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1296 /// getIndexedType - Returns the type of the element that would be extracted
1297 /// with an extractvalue instruction with the specified parameters.
1299 /// Null is returned if the indices are invalid for the specified type.
1300 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1302 typedef const unsigned* idx_iterator;
1303 inline idx_iterator idx_begin() const { return Indices.begin(); }
1304 inline idx_iterator idx_end() const { return Indices.end(); }
1306 Value *getAggregateOperand() {
1307 return getOperand(0);
1309 const Value *getAggregateOperand() const {
1310 return getOperand(0);
1312 static unsigned getAggregateOperandIndex() {
1313 return 0U; // get index for modifying correct operand
1316 ArrayRef<unsigned> getIndices() const {
1320 unsigned getNumIndices() const {
1321 return (unsigned)Indices.size();
1324 bool hasIndices() const {
1328 // Methods for support type inquiry through isa, cast, and dyn_cast:
1329 static inline bool classof(const ExtractValueInst *) { return true; }
1330 static inline bool classof(const Instruction *I) {
1331 return I->getOpcode() == Instruction::ExtractValue;
1333 static inline bool classof(const Value *V) {
1334 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1338 ExtractValueInst::ExtractValueInst(Value *Agg,
1339 ArrayRef<unsigned> Idxs,
1340 const Twine &NameStr,
1341 Instruction *InsertBefore)
1342 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1343 ExtractValue, Agg, InsertBefore) {
1344 init(Idxs, NameStr);
1346 ExtractValueInst::ExtractValueInst(Value *Agg,
1347 ArrayRef<unsigned> Idxs,
1348 const Twine &NameStr,
1349 BasicBlock *InsertAtEnd)
1350 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1351 ExtractValue, Agg, InsertAtEnd) {
1352 init(Idxs, NameStr);
1356 //===----------------------------------------------------------------------===//
1357 // InsertValueInst Class
1358 //===----------------------------------------------------------------------===//
1360 /// InsertValueInst - This instruction inserts a struct field of array element
1361 /// value into an aggregate value.
1363 class InsertValueInst : public Instruction {
1364 SmallVector<unsigned, 4> Indices;
1366 void *operator new(size_t, unsigned); // Do not implement
1367 InsertValueInst(const InsertValueInst &IVI);
1368 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1369 const Twine &NameStr);
1371 /// Constructors - Create a insertvalue instruction with a base aggregate
1372 /// value, a value to insert, and a list of indices. The first ctor can
1373 /// optionally insert before an existing instruction, the second appends
1374 /// the new instruction to the specified BasicBlock.
1375 inline InsertValueInst(Value *Agg, Value *Val,
1376 ArrayRef<unsigned> Idxs,
1377 const Twine &NameStr,
1378 Instruction *InsertBefore);
1379 inline InsertValueInst(Value *Agg, Value *Val,
1380 ArrayRef<unsigned> Idxs,
1381 const Twine &NameStr, BasicBlock *InsertAtEnd);
1383 /// Constructors - These two constructors are convenience methods because one
1384 /// and two index insertvalue instructions are so common.
1385 InsertValueInst(Value *Agg, Value *Val,
1386 unsigned Idx, const Twine &NameStr = "",
1387 Instruction *InsertBefore = 0);
1388 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1389 const Twine &NameStr, BasicBlock *InsertAtEnd);
1391 virtual InsertValueInst *clone_impl() const;
1393 // allocate space for exactly two operands
1394 void *operator new(size_t s) {
1395 return User::operator new(s, 2);
1398 static InsertValueInst *Create(Value *Agg, Value *Val,
1399 ArrayRef<unsigned> Idxs,
1400 const Twine &NameStr = "",
1401 Instruction *InsertBefore = 0) {
1402 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1404 static InsertValueInst *Create(Value *Agg, Value *Val,
1405 ArrayRef<unsigned> Idxs,
1406 const Twine &NameStr,
1407 BasicBlock *InsertAtEnd) {
1408 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1411 /// Transparently provide more efficient getOperand methods.
1412 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1414 typedef const unsigned* idx_iterator;
1415 inline idx_iterator idx_begin() const { return Indices.begin(); }
1416 inline idx_iterator idx_end() const { return Indices.end(); }
1418 Value *getAggregateOperand() {
1419 return getOperand(0);
1421 const Value *getAggregateOperand() const {
1422 return getOperand(0);
1424 static unsigned getAggregateOperandIndex() {
1425 return 0U; // get index for modifying correct operand
1428 Value *getInsertedValueOperand() {
1429 return getOperand(1);
1431 const Value *getInsertedValueOperand() const {
1432 return getOperand(1);
1434 static unsigned getInsertedValueOperandIndex() {
1435 return 1U; // get index for modifying correct operand
1438 ArrayRef<unsigned> getIndices() const {
1442 unsigned getNumIndices() const {
1443 return (unsigned)Indices.size();
1446 bool hasIndices() const {
1450 // Methods for support type inquiry through isa, cast, and dyn_cast:
1451 static inline bool classof(const InsertValueInst *) { return true; }
1452 static inline bool classof(const Instruction *I) {
1453 return I->getOpcode() == Instruction::InsertValue;
1455 static inline bool classof(const Value *V) {
1456 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1461 struct OperandTraits<InsertValueInst> :
1462 public FixedNumOperandTraits<InsertValueInst, 2> {
1465 InsertValueInst::InsertValueInst(Value *Agg,
1467 ArrayRef<unsigned> Idxs,
1468 const Twine &NameStr,
1469 Instruction *InsertBefore)
1470 : Instruction(Agg->getType(), InsertValue,
1471 OperandTraits<InsertValueInst>::op_begin(this),
1473 init(Agg, Val, Idxs, NameStr);
1475 InsertValueInst::InsertValueInst(Value *Agg,
1477 ArrayRef<unsigned> Idxs,
1478 const Twine &NameStr,
1479 BasicBlock *InsertAtEnd)
1480 : Instruction(Agg->getType(), InsertValue,
1481 OperandTraits<InsertValueInst>::op_begin(this),
1483 init(Agg, Val, Idxs, NameStr);
1486 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1488 //===----------------------------------------------------------------------===//
1490 //===----------------------------------------------------------------------===//
1492 // PHINode - The PHINode class is used to represent the magical mystical PHI
1493 // node, that can not exist in nature, but can be synthesized in a computer
1494 // scientist's overactive imagination.
1496 class PHINode : public Instruction {
1497 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1498 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1499 /// the number actually in use.
1500 unsigned ReservedSpace;
1501 PHINode(const PHINode &PN);
1502 // allocate space for exactly zero operands
1503 void *operator new(size_t s) {
1504 return User::operator new(s, 0);
1506 explicit PHINode(Type *Ty, unsigned NumReservedValues,
1507 const Twine &NameStr = "", Instruction *InsertBefore = 0)
1508 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1509 ReservedSpace(NumReservedValues) {
1511 OperandList = allocHungoffUses(ReservedSpace);
1514 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1515 BasicBlock *InsertAtEnd)
1516 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1517 ReservedSpace(NumReservedValues) {
1519 OperandList = allocHungoffUses(ReservedSpace);
1522 // allocHungoffUses - this is more complicated than the generic
1523 // User::allocHungoffUses, because we have to allocate Uses for the incoming
1524 // values and pointers to the incoming blocks, all in one allocation.
1525 Use *allocHungoffUses(unsigned) const;
1527 virtual PHINode *clone_impl() const;
1529 /// Constructors - NumReservedValues is a hint for the number of incoming
1530 /// edges that this phi node will have (use 0 if you really have no idea).
1531 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1532 const Twine &NameStr = "",
1533 Instruction *InsertBefore = 0) {
1534 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1536 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1537 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1538 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
1542 /// Provide fast operand accessors
1543 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1545 // Block iterator interface. This provides access to the list of incoming
1546 // basic blocks, which parallels the list of incoming values.
1548 typedef BasicBlock **block_iterator;
1549 typedef BasicBlock * const *const_block_iterator;
1551 block_iterator block_begin() {
1553 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
1554 return reinterpret_cast<block_iterator>(ref + 1);
1557 const_block_iterator block_begin() const {
1558 const Use::UserRef *ref =
1559 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
1560 return reinterpret_cast<const_block_iterator>(ref + 1);
1563 block_iterator block_end() {
1564 return block_begin() + getNumOperands();
1567 const_block_iterator block_end() const {
1568 return block_begin() + getNumOperands();
1571 /// getNumIncomingValues - Return the number of incoming edges
1573 unsigned getNumIncomingValues() const { return getNumOperands(); }
1575 /// getIncomingValue - Return incoming value number x
1577 Value *getIncomingValue(unsigned i) const {
1578 return getOperand(i);
1580 void setIncomingValue(unsigned i, Value *V) {
1583 static unsigned getOperandNumForIncomingValue(unsigned i) {
1586 static unsigned getIncomingValueNumForOperand(unsigned i) {
1590 /// getIncomingBlock - Return incoming basic block number @p i.
1592 BasicBlock *getIncomingBlock(unsigned i) const {
1593 return block_begin()[i];
1596 /// getIncomingBlock - Return incoming basic block corresponding
1597 /// to an operand of the PHI.
1599 BasicBlock *getIncomingBlock(const Use &U) const {
1600 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1601 return getIncomingBlock(unsigned(&U - op_begin()));
1604 /// getIncomingBlock - Return incoming basic block corresponding
1605 /// to value use iterator.
1607 template <typename U>
1608 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1609 return getIncomingBlock(I.getUse());
1612 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1613 block_begin()[i] = BB;
1616 /// addIncoming - Add an incoming value to the end of the PHI list
1618 void addIncoming(Value *V, BasicBlock *BB) {
1619 assert(V && "PHI node got a null value!");
1620 assert(BB && "PHI node got a null basic block!");
1621 assert(getType() == V->getType() &&
1622 "All operands to PHI node must be the same type as the PHI node!");
1623 if (NumOperands == ReservedSpace)
1624 growOperands(); // Get more space!
1625 // Initialize some new operands.
1627 setIncomingValue(NumOperands - 1, V);
1628 setIncomingBlock(NumOperands - 1, BB);
1631 /// removeIncomingValue - Remove an incoming value. This is useful if a
1632 /// predecessor basic block is deleted. The value removed is returned.
1634 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1635 /// is true), the PHI node is destroyed and any uses of it are replaced with
1636 /// dummy values. The only time there should be zero incoming values to a PHI
1637 /// node is when the block is dead, so this strategy is sound.
1639 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1641 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1642 int Idx = getBasicBlockIndex(BB);
1643 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1644 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1647 /// getBasicBlockIndex - Return the first index of the specified basic
1648 /// block in the value list for this PHI. Returns -1 if no instance.
1650 int getBasicBlockIndex(const BasicBlock *BB) const {
1651 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
1652 if (block_begin()[i] == BB)
1657 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1658 int Idx = getBasicBlockIndex(BB);
1659 assert(Idx >= 0 && "Invalid basic block argument!");
1660 return getIncomingValue(Idx);
1663 /// hasConstantValue - If the specified PHI node always merges together the
1664 /// same value, return the value, otherwise return null.
1665 Value *hasConstantValue() const;
1667 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1668 static inline bool classof(const PHINode *) { return true; }
1669 static inline bool classof(const Instruction *I) {
1670 return I->getOpcode() == Instruction::PHI;
1672 static inline bool classof(const Value *V) {
1673 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1676 void growOperands();
1680 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1683 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1686 //===----------------------------------------------------------------------===//
1688 //===----------------------------------------------------------------------===//
1690 //===---------------------------------------------------------------------------
1691 /// ReturnInst - Return a value (possibly void), from a function. Execution
1692 /// does not continue in this function any longer.
1694 class ReturnInst : public TerminatorInst {
1695 ReturnInst(const ReturnInst &RI);
1698 // ReturnInst constructors:
1699 // ReturnInst() - 'ret void' instruction
1700 // ReturnInst( null) - 'ret void' instruction
1701 // ReturnInst(Value* X) - 'ret X' instruction
1702 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1703 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1704 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1705 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1707 // NOTE: If the Value* passed is of type void then the constructor behaves as
1708 // if it was passed NULL.
1709 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1710 Instruction *InsertBefore = 0);
1711 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1712 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1714 virtual ReturnInst *clone_impl() const;
1716 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1717 Instruction *InsertBefore = 0) {
1718 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1720 static ReturnInst* Create(LLVMContext &C, Value *retVal,
1721 BasicBlock *InsertAtEnd) {
1722 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
1724 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
1725 return new(0) ReturnInst(C, InsertAtEnd);
1727 virtual ~ReturnInst();
1729 /// Provide fast operand accessors
1730 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1732 /// Convenience accessor. Returns null if there is no return value.
1733 Value *getReturnValue() const {
1734 return getNumOperands() != 0 ? getOperand(0) : 0;
1737 unsigned getNumSuccessors() const { return 0; }
1739 // Methods for support type inquiry through isa, cast, and dyn_cast:
1740 static inline bool classof(const ReturnInst *) { return true; }
1741 static inline bool classof(const Instruction *I) {
1742 return (I->getOpcode() == Instruction::Ret);
1744 static inline bool classof(const Value *V) {
1745 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1748 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1749 virtual unsigned getNumSuccessorsV() const;
1750 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1754 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
1757 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1759 //===----------------------------------------------------------------------===//
1761 //===----------------------------------------------------------------------===//
1763 //===---------------------------------------------------------------------------
1764 /// BranchInst - Conditional or Unconditional Branch instruction.
1766 class BranchInst : public TerminatorInst {
1767 /// Ops list - Branches are strange. The operands are ordered:
1768 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
1769 /// they don't have to check for cond/uncond branchness. These are mostly
1770 /// accessed relative from op_end().
1771 BranchInst(const BranchInst &BI);
1773 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1774 // BranchInst(BB *B) - 'br B'
1775 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1776 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1777 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1778 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1779 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1780 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1781 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1782 Instruction *InsertBefore = 0);
1783 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1784 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1785 BasicBlock *InsertAtEnd);
1787 virtual BranchInst *clone_impl() const;
1789 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1790 return new(1) BranchInst(IfTrue, InsertBefore);
1792 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1793 Value *Cond, Instruction *InsertBefore = 0) {
1794 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1796 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1797 return new(1) BranchInst(IfTrue, InsertAtEnd);
1799 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1800 Value *Cond, BasicBlock *InsertAtEnd) {
1801 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1804 /// Transparently provide more efficient getOperand methods.
1805 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1807 bool isUnconditional() const { return getNumOperands() == 1; }
1808 bool isConditional() const { return getNumOperands() == 3; }
1810 Value *getCondition() const {
1811 assert(isConditional() && "Cannot get condition of an uncond branch!");
1815 void setCondition(Value *V) {
1816 assert(isConditional() && "Cannot set condition of unconditional branch!");
1820 unsigned getNumSuccessors() const { return 1+isConditional(); }
1822 BasicBlock *getSuccessor(unsigned i) const {
1823 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1824 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
1827 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1828 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1829 *(&Op<-1>() - idx) = (Value*)NewSucc;
1832 // Methods for support type inquiry through isa, cast, and dyn_cast:
1833 static inline bool classof(const BranchInst *) { return true; }
1834 static inline bool classof(const Instruction *I) {
1835 return (I->getOpcode() == Instruction::Br);
1837 static inline bool classof(const Value *V) {
1838 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1841 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1842 virtual unsigned getNumSuccessorsV() const;
1843 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1847 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
1850 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
1852 //===----------------------------------------------------------------------===//
1854 //===----------------------------------------------------------------------===//
1856 //===---------------------------------------------------------------------------
1857 /// SwitchInst - Multiway switch
1859 class SwitchInst : public TerminatorInst {
1860 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1861 unsigned ReservedSpace;
1862 // Operand[0] = Value to switch on
1863 // Operand[1] = Default basic block destination
1864 // Operand[2n ] = Value to match
1865 // Operand[2n+1] = BasicBlock to go to on match
1866 SwitchInst(const SwitchInst &SI);
1867 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
1868 void growOperands();
1869 // allocate space for exactly zero operands
1870 void *operator new(size_t s) {
1871 return User::operator new(s, 0);
1873 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1874 /// switch on and a default destination. The number of additional cases can
1875 /// be specified here to make memory allocation more efficient. This
1876 /// constructor can also autoinsert before another instruction.
1877 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1878 Instruction *InsertBefore);
1880 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1881 /// switch on and a default destination. The number of additional cases can
1882 /// be specified here to make memory allocation more efficient. This
1883 /// constructor also autoinserts at the end of the specified BasicBlock.
1884 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1885 BasicBlock *InsertAtEnd);
1887 virtual SwitchInst *clone_impl() const;
1889 static SwitchInst *Create(Value *Value, BasicBlock *Default,
1890 unsigned NumCases, Instruction *InsertBefore = 0) {
1891 return new SwitchInst(Value, Default, NumCases, InsertBefore);
1893 static SwitchInst *Create(Value *Value, BasicBlock *Default,
1894 unsigned NumCases, BasicBlock *InsertAtEnd) {
1895 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
1899 /// Provide fast operand accessors
1900 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1902 // Accessor Methods for Switch stmt
1903 Value *getCondition() const { return getOperand(0); }
1904 void setCondition(Value *V) { setOperand(0, V); }
1906 BasicBlock *getDefaultDest() const {
1907 return cast<BasicBlock>(getOperand(1));
1910 /// getNumCases - return the number of 'cases' in this switch instruction.
1911 /// Note that case #0 is always the default case.
1912 unsigned getNumCases() const {
1913 return getNumOperands()/2;
1916 /// getCaseValue - Return the specified case value. Note that case #0, the
1917 /// default destination, does not have a case value.
1918 ConstantInt *getCaseValue(unsigned i) {
1919 assert(i && i < getNumCases() && "Illegal case value to get!");
1920 return getSuccessorValue(i);
1923 /// getCaseValue - Return the specified case value. Note that case #0, the
1924 /// default destination, does not have a case value.
1925 const ConstantInt *getCaseValue(unsigned i) const {
1926 assert(i && i < getNumCases() && "Illegal case value to get!");
1927 return getSuccessorValue(i);
1930 /// findCaseValue - Search all of the case values for the specified constant.
1931 /// If it is explicitly handled, return the case number of it, otherwise
1932 /// return 0 to indicate that it is handled by the default handler.
1933 unsigned findCaseValue(const ConstantInt *C) const {
1934 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1935 if (getCaseValue(i) == C)
1940 /// findCaseDest - Finds the unique case value for a given successor. Returns
1941 /// null if the successor is not found, not unique, or is the default case.
1942 ConstantInt *findCaseDest(BasicBlock *BB) {
1943 if (BB == getDefaultDest()) return NULL;
1945 ConstantInt *CI = NULL;
1946 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1947 if (getSuccessor(i) == BB) {
1948 if (CI) return NULL; // Multiple cases lead to BB.
1949 else CI = getCaseValue(i);
1955 /// addCase - Add an entry to the switch instruction...
1957 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1959 /// removeCase - This method removes the specified successor from the switch
1960 /// instruction. Note that this cannot be used to remove the default
1961 /// destination (successor #0). Also note that this operation may reorder the
1962 /// remaining cases at index idx and above.
1964 void removeCase(unsigned idx);
1966 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1967 BasicBlock *getSuccessor(unsigned idx) const {
1968 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1969 return cast<BasicBlock>(getOperand(idx*2+1));
1971 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1972 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1973 setOperand(idx*2+1, (Value*)NewSucc);
1976 // getSuccessorValue - Return the value associated with the specified
1978 ConstantInt *getSuccessorValue(unsigned idx) const {
1979 assert(idx < getNumSuccessors() && "Successor # out of range!");
1980 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1983 // Methods for support type inquiry through isa, cast, and dyn_cast:
1984 static inline bool classof(const SwitchInst *) { return true; }
1985 static inline bool classof(const Instruction *I) {
1986 return I->getOpcode() == Instruction::Switch;
1988 static inline bool classof(const Value *V) {
1989 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1992 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1993 virtual unsigned getNumSuccessorsV() const;
1994 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1998 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2001 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2004 //===----------------------------------------------------------------------===//
2005 // IndirectBrInst Class
2006 //===----------------------------------------------------------------------===//
2008 //===---------------------------------------------------------------------------
2009 /// IndirectBrInst - Indirect Branch Instruction.
2011 class IndirectBrInst : public TerminatorInst {
2012 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2013 unsigned ReservedSpace;
2014 // Operand[0] = Value to switch on
2015 // Operand[1] = Default basic block destination
2016 // Operand[2n ] = Value to match
2017 // Operand[2n+1] = BasicBlock to go to on match
2018 IndirectBrInst(const IndirectBrInst &IBI);
2019 void init(Value *Address, unsigned NumDests);
2020 void growOperands();
2021 // allocate space for exactly zero operands
2022 void *operator new(size_t s) {
2023 return User::operator new(s, 0);
2025 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2026 /// Address to jump to. The number of expected destinations can be specified
2027 /// here to make memory allocation more efficient. This constructor can also
2028 /// autoinsert before another instruction.
2029 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2031 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2032 /// Address to jump to. The number of expected destinations can be specified
2033 /// here to make memory allocation more efficient. This constructor also
2034 /// autoinserts at the end of the specified BasicBlock.
2035 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2037 virtual IndirectBrInst *clone_impl() const;
2039 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2040 Instruction *InsertBefore = 0) {
2041 return new IndirectBrInst(Address, NumDests, InsertBefore);
2043 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2044 BasicBlock *InsertAtEnd) {
2045 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2049 /// Provide fast operand accessors.
2050 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2052 // Accessor Methods for IndirectBrInst instruction.
2053 Value *getAddress() { return getOperand(0); }
2054 const Value *getAddress() const { return getOperand(0); }
2055 void setAddress(Value *V) { setOperand(0, V); }
2058 /// getNumDestinations - return the number of possible destinations in this
2059 /// indirectbr instruction.
2060 unsigned getNumDestinations() const { return getNumOperands()-1; }
2062 /// getDestination - Return the specified destination.
2063 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2064 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2066 /// addDestination - Add a destination.
2068 void addDestination(BasicBlock *Dest);
2070 /// removeDestination - This method removes the specified successor from the
2071 /// indirectbr instruction.
2072 void removeDestination(unsigned i);
2074 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2075 BasicBlock *getSuccessor(unsigned i) const {
2076 return cast<BasicBlock>(getOperand(i+1));
2078 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2079 setOperand(i+1, (Value*)NewSucc);
2082 // Methods for support type inquiry through isa, cast, and dyn_cast:
2083 static inline bool classof(const IndirectBrInst *) { return true; }
2084 static inline bool classof(const Instruction *I) {
2085 return I->getOpcode() == Instruction::IndirectBr;
2087 static inline bool classof(const Value *V) {
2088 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2091 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2092 virtual unsigned getNumSuccessorsV() const;
2093 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2097 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2100 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2103 //===----------------------------------------------------------------------===//
2105 //===----------------------------------------------------------------------===//
2107 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2108 /// calling convention of the call.
2110 class InvokeInst : public TerminatorInst {
2111 AttrListPtr AttributeList;
2112 InvokeInst(const InvokeInst &BI);
2113 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2114 ArrayRef<Value *> Args, const Twine &NameStr);
2116 /// Construct an InvokeInst given a range of arguments.
2118 /// @brief Construct an InvokeInst from a range of arguments
2119 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2120 ArrayRef<Value *> Args, unsigned Values,
2121 const Twine &NameStr, Instruction *InsertBefore);
2123 /// Construct an InvokeInst given a range of arguments.
2125 /// @brief Construct an InvokeInst from a range of arguments
2126 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2127 ArrayRef<Value *> Args, unsigned Values,
2128 const Twine &NameStr, BasicBlock *InsertAtEnd);
2130 virtual InvokeInst *clone_impl() const;
2132 static InvokeInst *Create(Value *Func,
2133 BasicBlock *IfNormal, BasicBlock *IfException,
2134 ArrayRef<Value *> Args, const Twine &NameStr = "",
2135 Instruction *InsertBefore = 0) {
2136 unsigned Values = unsigned(Args.size()) + 3;
2137 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2138 Values, NameStr, InsertBefore);
2140 static InvokeInst *Create(Value *Func,
2141 BasicBlock *IfNormal, BasicBlock *IfException,
2142 ArrayRef<Value *> Args, const Twine &NameStr,
2143 BasicBlock *InsertAtEnd) {
2144 unsigned Values = unsigned(Args.size()) + 3;
2145 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2146 Values, NameStr, InsertAtEnd);
2149 /// Provide fast operand accessors
2150 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2152 /// getNumArgOperands - Return the number of invoke arguments.
2154 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2156 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2158 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2159 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2161 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2163 CallingConv::ID getCallingConv() const {
2164 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2166 void setCallingConv(CallingConv::ID CC) {
2167 setInstructionSubclassData(static_cast<unsigned>(CC));
2170 /// getAttributes - Return the parameter attributes for this invoke.
2172 const AttrListPtr &getAttributes() const { return AttributeList; }
2174 /// setAttributes - Set the parameter attributes for this invoke.
2176 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2178 /// addAttribute - adds the attribute to the list of attributes.
2179 void addAttribute(unsigned i, Attributes attr);
2181 /// removeAttribute - removes the attribute from the list of attributes.
2182 void removeAttribute(unsigned i, Attributes attr);
2184 /// @brief Determine whether the call or the callee has the given attribute.
2185 bool paramHasAttr(unsigned i, Attributes attr) const;
2187 /// @brief Extract the alignment for a call or parameter (0=unknown).
2188 unsigned getParamAlignment(unsigned i) const {
2189 return AttributeList.getParamAlignment(i);
2192 /// @brief Return true if the call should not be inlined.
2193 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2194 void setIsNoInline(bool Value = true) {
2195 if (Value) addAttribute(~0, Attribute::NoInline);
2196 else removeAttribute(~0, Attribute::NoInline);
2199 /// @brief Determine if the call does not access memory.
2200 bool doesNotAccessMemory() const {
2201 return paramHasAttr(~0, Attribute::ReadNone);
2203 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2204 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2205 else removeAttribute(~0, Attribute::ReadNone);
2208 /// @brief Determine if the call does not access or only reads memory.
2209 bool onlyReadsMemory() const {
2210 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2212 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2213 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2214 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2217 /// @brief Determine if the call cannot return.
2218 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2219 void setDoesNotReturn(bool DoesNotReturn = true) {
2220 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2221 else removeAttribute(~0, Attribute::NoReturn);
2224 /// @brief Determine if the call cannot unwind.
2225 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2226 void setDoesNotThrow(bool DoesNotThrow = true) {
2227 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2228 else removeAttribute(~0, Attribute::NoUnwind);
2231 /// @brief Determine if the call returns a structure through first
2232 /// pointer argument.
2233 bool hasStructRetAttr() const {
2234 // Be friendly and also check the callee.
2235 return paramHasAttr(1, Attribute::StructRet);
2238 /// @brief Determine if any call argument is an aggregate passed by value.
2239 bool hasByValArgument() const {
2240 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2243 /// getCalledFunction - Return the function called, or null if this is an
2244 /// indirect function invocation.
2246 Function *getCalledFunction() const {
2247 return dyn_cast<Function>(Op<-3>());
2250 /// getCalledValue - Get a pointer to the function that is invoked by this
2252 const Value *getCalledValue() const { return Op<-3>(); }
2253 Value *getCalledValue() { return Op<-3>(); }
2255 /// setCalledFunction - Set the function called.
2256 void setCalledFunction(Value* Fn) {
2260 // get*Dest - Return the destination basic blocks...
2261 BasicBlock *getNormalDest() const {
2262 return cast<BasicBlock>(Op<-2>());
2264 BasicBlock *getUnwindDest() const {
2265 return cast<BasicBlock>(Op<-1>());
2267 void setNormalDest(BasicBlock *B) {
2268 Op<-2>() = reinterpret_cast<Value*>(B);
2270 void setUnwindDest(BasicBlock *B) {
2271 Op<-1>() = reinterpret_cast<Value*>(B);
2274 BasicBlock *getSuccessor(unsigned i) const {
2275 assert(i < 2 && "Successor # out of range for invoke!");
2276 return i == 0 ? getNormalDest() : getUnwindDest();
2279 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2280 assert(idx < 2 && "Successor # out of range for invoke!");
2281 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2284 unsigned getNumSuccessors() const { return 2; }
2286 // Methods for support type inquiry through isa, cast, and dyn_cast:
2287 static inline bool classof(const InvokeInst *) { return true; }
2288 static inline bool classof(const Instruction *I) {
2289 return (I->getOpcode() == Instruction::Invoke);
2291 static inline bool classof(const Value *V) {
2292 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2296 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2297 virtual unsigned getNumSuccessorsV() const;
2298 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2300 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2301 // method so that subclasses cannot accidentally use it.
2302 void setInstructionSubclassData(unsigned short D) {
2303 Instruction::setInstructionSubclassData(D);
2308 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2311 InvokeInst::InvokeInst(Value *Func,
2312 BasicBlock *IfNormal, BasicBlock *IfException,
2313 ArrayRef<Value *> Args, unsigned Values,
2314 const Twine &NameStr, Instruction *InsertBefore)
2315 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2316 ->getElementType())->getReturnType(),
2317 Instruction::Invoke,
2318 OperandTraits<InvokeInst>::op_end(this) - Values,
2319 Values, InsertBefore) {
2320 init(Func, IfNormal, IfException, Args, NameStr);
2322 InvokeInst::InvokeInst(Value *Func,
2323 BasicBlock *IfNormal, BasicBlock *IfException,
2324 ArrayRef<Value *> Args, unsigned Values,
2325 const Twine &NameStr, BasicBlock *InsertAtEnd)
2326 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2327 ->getElementType())->getReturnType(),
2328 Instruction::Invoke,
2329 OperandTraits<InvokeInst>::op_end(this) - Values,
2330 Values, InsertAtEnd) {
2331 init(Func, IfNormal, IfException, Args, NameStr);
2334 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2336 //===----------------------------------------------------------------------===//
2338 //===----------------------------------------------------------------------===//
2340 //===---------------------------------------------------------------------------
2341 /// UnwindInst - Immediately exit the current function, unwinding the stack
2342 /// until an invoke instruction is found.
2344 class UnwindInst : public TerminatorInst {
2345 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2347 virtual UnwindInst *clone_impl() const;
2349 // allocate space for exactly zero operands
2350 void *operator new(size_t s) {
2351 return User::operator new(s, 0);
2353 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2354 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2356 unsigned getNumSuccessors() const { return 0; }
2358 // Methods for support type inquiry through isa, cast, and dyn_cast:
2359 static inline bool classof(const UnwindInst *) { return true; }
2360 static inline bool classof(const Instruction *I) {
2361 return I->getOpcode() == Instruction::Unwind;
2363 static inline bool classof(const Value *V) {
2364 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2367 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2368 virtual unsigned getNumSuccessorsV() const;
2369 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2372 //===----------------------------------------------------------------------===//
2373 // UnreachableInst Class
2374 //===----------------------------------------------------------------------===//
2376 //===---------------------------------------------------------------------------
2377 /// UnreachableInst - This function has undefined behavior. In particular, the
2378 /// presence of this instruction indicates some higher level knowledge that the
2379 /// end of the block cannot be reached.
2381 class UnreachableInst : public TerminatorInst {
2382 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2384 virtual UnreachableInst *clone_impl() const;
2387 // allocate space for exactly zero operands
2388 void *operator new(size_t s) {
2389 return User::operator new(s, 0);
2391 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2392 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2394 unsigned getNumSuccessors() const { return 0; }
2396 // Methods for support type inquiry through isa, cast, and dyn_cast:
2397 static inline bool classof(const UnreachableInst *) { return true; }
2398 static inline bool classof(const Instruction *I) {
2399 return I->getOpcode() == Instruction::Unreachable;
2401 static inline bool classof(const Value *V) {
2402 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2405 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2406 virtual unsigned getNumSuccessorsV() const;
2407 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2410 //===----------------------------------------------------------------------===//
2412 //===----------------------------------------------------------------------===//
2414 /// @brief This class represents a truncation of integer types.
2415 class TruncInst : public CastInst {
2417 /// @brief Clone an identical TruncInst
2418 virtual TruncInst *clone_impl() const;
2421 /// @brief Constructor with insert-before-instruction semantics
2423 Value *S, ///< The value to be truncated
2424 Type *Ty, ///< The (smaller) type to truncate to
2425 const Twine &NameStr = "", ///< A name for the new instruction
2426 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2429 /// @brief Constructor with insert-at-end-of-block semantics
2431 Value *S, ///< The value to be truncated
2432 Type *Ty, ///< The (smaller) type to truncate to
2433 const Twine &NameStr, ///< A name for the new instruction
2434 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2437 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2438 static inline bool classof(const TruncInst *) { return true; }
2439 static inline bool classof(const Instruction *I) {
2440 return I->getOpcode() == Trunc;
2442 static inline bool classof(const Value *V) {
2443 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2447 //===----------------------------------------------------------------------===//
2449 //===----------------------------------------------------------------------===//
2451 /// @brief This class represents zero extension of integer types.
2452 class ZExtInst : public CastInst {
2454 /// @brief Clone an identical ZExtInst
2455 virtual ZExtInst *clone_impl() const;
2458 /// @brief Constructor with insert-before-instruction semantics
2460 Value *S, ///< The value to be zero extended
2461 Type *Ty, ///< The type to zero extend to
2462 const Twine &NameStr = "", ///< A name for the new instruction
2463 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2466 /// @brief Constructor with insert-at-end semantics.
2468 Value *S, ///< The value to be zero extended
2469 Type *Ty, ///< The type to zero extend to
2470 const Twine &NameStr, ///< A name for the new instruction
2471 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2474 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2475 static inline bool classof(const ZExtInst *) { return true; }
2476 static inline bool classof(const Instruction *I) {
2477 return I->getOpcode() == ZExt;
2479 static inline bool classof(const Value *V) {
2480 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2484 //===----------------------------------------------------------------------===//
2486 //===----------------------------------------------------------------------===//
2488 /// @brief This class represents a sign extension of integer types.
2489 class SExtInst : public CastInst {
2491 /// @brief Clone an identical SExtInst
2492 virtual SExtInst *clone_impl() const;
2495 /// @brief Constructor with insert-before-instruction semantics
2497 Value *S, ///< The value to be sign extended
2498 Type *Ty, ///< The type to sign extend to
2499 const Twine &NameStr = "", ///< A name for the new instruction
2500 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2503 /// @brief Constructor with insert-at-end-of-block semantics
2505 Value *S, ///< The value to be sign extended
2506 Type *Ty, ///< The type to sign extend to
2507 const Twine &NameStr, ///< A name for the new instruction
2508 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2511 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2512 static inline bool classof(const SExtInst *) { return true; }
2513 static inline bool classof(const Instruction *I) {
2514 return I->getOpcode() == SExt;
2516 static inline bool classof(const Value *V) {
2517 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2521 //===----------------------------------------------------------------------===//
2522 // FPTruncInst Class
2523 //===----------------------------------------------------------------------===//
2525 /// @brief This class represents a truncation of floating point types.
2526 class FPTruncInst : public CastInst {
2528 /// @brief Clone an identical FPTruncInst
2529 virtual FPTruncInst *clone_impl() const;
2532 /// @brief Constructor with insert-before-instruction semantics
2534 Value *S, ///< The value to be truncated
2535 Type *Ty, ///< The type to truncate to
2536 const Twine &NameStr = "", ///< A name for the new instruction
2537 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2540 /// @brief Constructor with insert-before-instruction semantics
2542 Value *S, ///< The value to be truncated
2543 Type *Ty, ///< The type to truncate to
2544 const Twine &NameStr, ///< A name for the new instruction
2545 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2548 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2549 static inline bool classof(const FPTruncInst *) { return true; }
2550 static inline bool classof(const Instruction *I) {
2551 return I->getOpcode() == FPTrunc;
2553 static inline bool classof(const Value *V) {
2554 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2558 //===----------------------------------------------------------------------===//
2560 //===----------------------------------------------------------------------===//
2562 /// @brief This class represents an extension of floating point types.
2563 class FPExtInst : public CastInst {
2565 /// @brief Clone an identical FPExtInst
2566 virtual FPExtInst *clone_impl() const;
2569 /// @brief Constructor with insert-before-instruction semantics
2571 Value *S, ///< The value to be extended
2572 Type *Ty, ///< The type to extend to
2573 const Twine &NameStr = "", ///< A name for the new instruction
2574 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2577 /// @brief Constructor with insert-at-end-of-block semantics
2579 Value *S, ///< The value to be extended
2580 Type *Ty, ///< The type to extend to
2581 const Twine &NameStr, ///< A name for the new instruction
2582 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2585 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2586 static inline bool classof(const FPExtInst *) { return true; }
2587 static inline bool classof(const Instruction *I) {
2588 return I->getOpcode() == FPExt;
2590 static inline bool classof(const Value *V) {
2591 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2595 //===----------------------------------------------------------------------===//
2597 //===----------------------------------------------------------------------===//
2599 /// @brief This class represents a cast unsigned integer to floating point.
2600 class UIToFPInst : public CastInst {
2602 /// @brief Clone an identical UIToFPInst
2603 virtual UIToFPInst *clone_impl() const;
2606 /// @brief Constructor with insert-before-instruction semantics
2608 Value *S, ///< The value to be converted
2609 Type *Ty, ///< The type to convert to
2610 const Twine &NameStr = "", ///< A name for the new instruction
2611 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2614 /// @brief Constructor with insert-at-end-of-block semantics
2616 Value *S, ///< The value to be converted
2617 Type *Ty, ///< The type to convert to
2618 const Twine &NameStr, ///< A name for the new instruction
2619 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2622 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2623 static inline bool classof(const UIToFPInst *) { return true; }
2624 static inline bool classof(const Instruction *I) {
2625 return I->getOpcode() == UIToFP;
2627 static inline bool classof(const Value *V) {
2628 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2632 //===----------------------------------------------------------------------===//
2634 //===----------------------------------------------------------------------===//
2636 /// @brief This class represents a cast from signed integer to floating point.
2637 class SIToFPInst : public CastInst {
2639 /// @brief Clone an identical SIToFPInst
2640 virtual SIToFPInst *clone_impl() const;
2643 /// @brief Constructor with insert-before-instruction semantics
2645 Value *S, ///< The value to be converted
2646 Type *Ty, ///< The type to convert to
2647 const Twine &NameStr = "", ///< A name for the new instruction
2648 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2651 /// @brief Constructor with insert-at-end-of-block semantics
2653 Value *S, ///< The value to be converted
2654 Type *Ty, ///< The type to convert to
2655 const Twine &NameStr, ///< A name for the new instruction
2656 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2659 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2660 static inline bool classof(const SIToFPInst *) { return true; }
2661 static inline bool classof(const Instruction *I) {
2662 return I->getOpcode() == SIToFP;
2664 static inline bool classof(const Value *V) {
2665 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2669 //===----------------------------------------------------------------------===//
2671 //===----------------------------------------------------------------------===//
2673 /// @brief This class represents a cast from floating point to unsigned integer
2674 class FPToUIInst : public CastInst {
2676 /// @brief Clone an identical FPToUIInst
2677 virtual FPToUIInst *clone_impl() const;
2680 /// @brief Constructor with insert-before-instruction semantics
2682 Value *S, ///< The value to be converted
2683 Type *Ty, ///< The type to convert to
2684 const Twine &NameStr = "", ///< A name for the new instruction
2685 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2688 /// @brief Constructor with insert-at-end-of-block semantics
2690 Value *S, ///< The value to be converted
2691 Type *Ty, ///< The type to convert to
2692 const Twine &NameStr, ///< A name for the new instruction
2693 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2696 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2697 static inline bool classof(const FPToUIInst *) { return true; }
2698 static inline bool classof(const Instruction *I) {
2699 return I->getOpcode() == FPToUI;
2701 static inline bool classof(const Value *V) {
2702 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2706 //===----------------------------------------------------------------------===//
2708 //===----------------------------------------------------------------------===//
2710 /// @brief This class represents a cast from floating point to signed integer.
2711 class FPToSIInst : public CastInst {
2713 /// @brief Clone an identical FPToSIInst
2714 virtual FPToSIInst *clone_impl() const;
2717 /// @brief Constructor with insert-before-instruction semantics
2719 Value *S, ///< The value to be converted
2720 Type *Ty, ///< The type to convert to
2721 const Twine &NameStr = "", ///< A name for the new instruction
2722 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2725 /// @brief Constructor with insert-at-end-of-block semantics
2727 Value *S, ///< The value to be converted
2728 Type *Ty, ///< The type to convert to
2729 const Twine &NameStr, ///< A name for the new instruction
2730 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2733 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2734 static inline bool classof(const FPToSIInst *) { return true; }
2735 static inline bool classof(const Instruction *I) {
2736 return I->getOpcode() == FPToSI;
2738 static inline bool classof(const Value *V) {
2739 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2743 //===----------------------------------------------------------------------===//
2744 // IntToPtrInst Class
2745 //===----------------------------------------------------------------------===//
2747 /// @brief This class represents a cast from an integer to a pointer.
2748 class IntToPtrInst : public CastInst {
2750 /// @brief Constructor with insert-before-instruction semantics
2752 Value *S, ///< The value to be converted
2753 Type *Ty, ///< The type to convert to
2754 const Twine &NameStr = "", ///< A name for the new instruction
2755 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2758 /// @brief Constructor with insert-at-end-of-block semantics
2760 Value *S, ///< The value to be converted
2761 Type *Ty, ///< The type to convert to
2762 const Twine &NameStr, ///< A name for the new instruction
2763 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2766 /// @brief Clone an identical IntToPtrInst
2767 virtual IntToPtrInst *clone_impl() const;
2769 // Methods for support type inquiry through isa, cast, and dyn_cast:
2770 static inline bool classof(const IntToPtrInst *) { return true; }
2771 static inline bool classof(const Instruction *I) {
2772 return I->getOpcode() == IntToPtr;
2774 static inline bool classof(const Value *V) {
2775 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2779 //===----------------------------------------------------------------------===//
2780 // PtrToIntInst Class
2781 //===----------------------------------------------------------------------===//
2783 /// @brief This class represents a cast from a pointer to an integer
2784 class PtrToIntInst : public CastInst {
2786 /// @brief Clone an identical PtrToIntInst
2787 virtual PtrToIntInst *clone_impl() const;
2790 /// @brief Constructor with insert-before-instruction semantics
2792 Value *S, ///< The value to be converted
2793 Type *Ty, ///< The type to convert to
2794 const Twine &NameStr = "", ///< A name for the new instruction
2795 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2798 /// @brief Constructor with insert-at-end-of-block semantics
2800 Value *S, ///< The value to be converted
2801 Type *Ty, ///< The type to convert to
2802 const Twine &NameStr, ///< A name for the new instruction
2803 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2806 // Methods for support type inquiry through isa, cast, and dyn_cast:
2807 static inline bool classof(const PtrToIntInst *) { return true; }
2808 static inline bool classof(const Instruction *I) {
2809 return I->getOpcode() == PtrToInt;
2811 static inline bool classof(const Value *V) {
2812 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2816 //===----------------------------------------------------------------------===//
2817 // BitCastInst Class
2818 //===----------------------------------------------------------------------===//
2820 /// @brief This class represents a no-op cast from one type to another.
2821 class BitCastInst : public CastInst {
2823 /// @brief Clone an identical BitCastInst
2824 virtual BitCastInst *clone_impl() const;
2827 /// @brief Constructor with insert-before-instruction semantics
2829 Value *S, ///< The value to be casted
2830 Type *Ty, ///< The type to casted to
2831 const Twine &NameStr = "", ///< A name for the new instruction
2832 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2835 /// @brief Constructor with insert-at-end-of-block semantics
2837 Value *S, ///< The value to be casted
2838 Type *Ty, ///< The type to casted to
2839 const Twine &NameStr, ///< A name for the new instruction
2840 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2843 // Methods for support type inquiry through isa, cast, and dyn_cast:
2844 static inline bool classof(const BitCastInst *) { return true; }
2845 static inline bool classof(const Instruction *I) {
2846 return I->getOpcode() == BitCast;
2848 static inline bool classof(const Value *V) {
2849 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2853 } // End llvm namespace