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
21 #include "llvm/InstrTypes.h"
22 #include "llvm/DerivedTypes.h"
23 #include "llvm/ParameterAttributes.h"
24 #include "llvm/BasicBlock.h"
34 //===----------------------------------------------------------------------===//
35 // AllocationInst Class
36 //===----------------------------------------------------------------------===//
38 /// AllocationInst - This class is the common base class of MallocInst and
41 class AllocationInst : public UnaryInstruction {
43 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
44 const std::string &Name = "", Instruction *InsertBefore = 0);
45 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
46 const std::string &Name, BasicBlock *InsertAtEnd);
48 // Out of line virtual method, so the vtable, etc. has a home.
49 virtual ~AllocationInst();
51 /// isArrayAllocation - Return true if there is an allocation size parameter
52 /// to the allocation instruction that is not 1.
54 bool isArrayAllocation() const;
56 /// getArraySize - Get the number of element allocated, for a simple
57 /// allocation of a single element, this will return a constant 1 value.
59 const Value *getArraySize() const { return getOperand(0); }
60 Value *getArraySize() { return getOperand(0); }
62 /// getType - Overload to return most specific pointer type
64 const PointerType *getType() const {
65 return reinterpret_cast<const PointerType*>(Instruction::getType());
68 /// getAllocatedType - Return the type that is being allocated by the
71 const Type *getAllocatedType() const;
73 /// getAlignment - Return the alignment of the memory that is being allocated
74 /// by the instruction.
76 unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
77 void setAlignment(unsigned Align);
79 virtual Instruction *clone() const = 0;
81 // Methods for support type inquiry through isa, cast, and dyn_cast:
82 static inline bool classof(const AllocationInst *) { return true; }
83 static inline bool classof(const Instruction *I) {
84 return I->getOpcode() == Instruction::Alloca ||
85 I->getOpcode() == Instruction::Malloc;
87 static inline bool classof(const Value *V) {
88 return isa<Instruction>(V) && classof(cast<Instruction>(V));
93 //===----------------------------------------------------------------------===//
95 //===----------------------------------------------------------------------===//
97 /// MallocInst - an instruction to allocated memory on the heap
99 class MallocInst : public AllocationInst {
100 MallocInst(const MallocInst &MI);
102 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
103 const std::string &Name = "",
104 Instruction *InsertBefore = 0)
105 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
106 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
107 BasicBlock *InsertAtEnd)
108 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
110 MallocInst(const Type *Ty, const std::string &Name,
111 Instruction *InsertBefore = 0)
112 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
113 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
114 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
116 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
117 const std::string &Name, BasicBlock *InsertAtEnd)
118 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
119 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
120 const std::string &Name = "",
121 Instruction *InsertBefore = 0)
122 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
124 virtual MallocInst *clone() const;
126 // Methods for support type inquiry through isa, cast, and dyn_cast:
127 static inline bool classof(const MallocInst *) { return true; }
128 static inline bool classof(const Instruction *I) {
129 return (I->getOpcode() == Instruction::Malloc);
131 static inline bool classof(const Value *V) {
132 return isa<Instruction>(V) && classof(cast<Instruction>(V));
137 //===----------------------------------------------------------------------===//
139 //===----------------------------------------------------------------------===//
141 /// AllocaInst - an instruction to allocate memory on the stack
143 class AllocaInst : public AllocationInst {
144 AllocaInst(const AllocaInst &);
146 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
147 const std::string &Name = "",
148 Instruction *InsertBefore = 0)
149 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
150 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
151 BasicBlock *InsertAtEnd)
152 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
154 AllocaInst(const Type *Ty, const std::string &Name,
155 Instruction *InsertBefore = 0)
156 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
157 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
158 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
160 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
161 const std::string &Name = "", Instruction *InsertBefore = 0)
162 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
163 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
164 const std::string &Name, BasicBlock *InsertAtEnd)
165 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
167 virtual AllocaInst *clone() const;
169 // Methods for support type inquiry through isa, cast, and dyn_cast:
170 static inline bool classof(const AllocaInst *) { return true; }
171 static inline bool classof(const Instruction *I) {
172 return (I->getOpcode() == Instruction::Alloca);
174 static inline bool classof(const Value *V) {
175 return isa<Instruction>(V) && classof(cast<Instruction>(V));
180 //===----------------------------------------------------------------------===//
182 //===----------------------------------------------------------------------===//
184 /// FreeInst - an instruction to deallocate memory
186 class FreeInst : public UnaryInstruction {
189 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
190 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
192 virtual FreeInst *clone() const;
194 // Accessor methods for consistency with other memory operations
195 Value *getPointerOperand() { return getOperand(0); }
196 const Value *getPointerOperand() const { return getOperand(0); }
198 // Methods for support type inquiry through isa, cast, and dyn_cast:
199 static inline bool classof(const FreeInst *) { return true; }
200 static inline bool classof(const Instruction *I) {
201 return (I->getOpcode() == Instruction::Free);
203 static inline bool classof(const Value *V) {
204 return isa<Instruction>(V) && classof(cast<Instruction>(V));
209 //===----------------------------------------------------------------------===//
211 //===----------------------------------------------------------------------===//
213 /// LoadInst - an instruction for reading from memory. This uses the
214 /// SubclassData field in Value to store whether or not the load is volatile.
216 class LoadInst : public UnaryInstruction {
218 LoadInst(const LoadInst &LI)
219 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
220 setVolatile(LI.isVolatile());
221 setAlignment(LI.getAlignment());
229 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
230 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
231 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
232 Instruction *InsertBefore = 0);
233 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
234 Instruction *InsertBefore = 0);
235 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
236 BasicBlock *InsertAtEnd);
237 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
238 BasicBlock *InsertAtEnd);
240 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
241 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
242 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
243 Instruction *InsertBefore = 0);
244 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
245 BasicBlock *InsertAtEnd);
247 /// isVolatile - Return true if this is a load from a volatile memory
250 bool isVolatile() const { return SubclassData & 1; }
252 /// setVolatile - Specify whether this is a volatile load or not.
254 void setVolatile(bool V) {
255 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
258 virtual LoadInst *clone() const;
260 /// getAlignment - Return the alignment of the access that is being performed
262 unsigned getAlignment() const {
263 return (1 << (SubclassData>>1)) >> 1;
266 void setAlignment(unsigned Align);
268 Value *getPointerOperand() { return getOperand(0); }
269 const Value *getPointerOperand() const { return getOperand(0); }
270 static unsigned getPointerOperandIndex() { return 0U; }
272 // Methods for support type inquiry through isa, cast, and dyn_cast:
273 static inline bool classof(const LoadInst *) { return true; }
274 static inline bool classof(const Instruction *I) {
275 return I->getOpcode() == Instruction::Load;
277 static inline bool classof(const Value *V) {
278 return isa<Instruction>(V) && classof(cast<Instruction>(V));
283 //===----------------------------------------------------------------------===//
285 //===----------------------------------------------------------------------===//
287 /// StoreInst - an instruction for storing to memory
289 class StoreInst : public Instruction {
290 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
292 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store,
294 Op<0>().init(SI.Op<0>(), this);
295 Op<1>().init(SI.Op<1>(), this);
296 setVolatile(SI.isVolatile());
297 setAlignment(SI.getAlignment());
305 // allocate space for exactly two operands
306 void *operator new(size_t s) {
307 return User::operator new(s, 2);
309 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
310 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
311 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
312 Instruction *InsertBefore = 0);
313 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
314 unsigned Align, Instruction *InsertBefore = 0);
315 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
316 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
317 unsigned Align, BasicBlock *InsertAtEnd);
320 /// isVolatile - Return true if this is a load from a volatile memory
323 bool isVolatile() const { return SubclassData & 1; }
325 /// setVolatile - Specify whether this is a volatile load or not.
327 void setVolatile(bool V) {
328 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
331 /// Transparently provide more efficient getOperand methods.
332 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
334 /// getAlignment - Return the alignment of the access that is being performed
336 unsigned getAlignment() const {
337 return (1 << (SubclassData>>1)) >> 1;
340 void setAlignment(unsigned Align);
342 virtual StoreInst *clone() const;
344 Value *getPointerOperand() { return getOperand(1); }
345 const Value *getPointerOperand() const { return getOperand(1); }
346 static unsigned getPointerOperandIndex() { return 1U; }
348 // Methods for support type inquiry through isa, cast, and dyn_cast:
349 static inline bool classof(const StoreInst *) { return true; }
350 static inline bool classof(const Instruction *I) {
351 return I->getOpcode() == Instruction::Store;
353 static inline bool classof(const Value *V) {
354 return isa<Instruction>(V) && classof(cast<Instruction>(V));
359 struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> {
362 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
364 //===----------------------------------------------------------------------===//
365 // GetElementPtrInst Class
366 //===----------------------------------------------------------------------===//
368 // checkType - Simple wrapper function to give a better assertion failure
369 // message on bad indexes for a gep instruction.
371 static inline const Type *checkType(const Type *Ty) {
372 assert(Ty && "Invalid GetElementPtrInst indices for type!");
376 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
377 /// access elements of arrays and structs
379 class GetElementPtrInst : public Instruction {
380 GetElementPtrInst(const GetElementPtrInst &GEPI);
381 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
382 void init(Value *Ptr, Value *Idx);
384 template<typename InputIterator>
385 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
386 const std::string &Name,
387 // This argument ensures that we have an iterator we can
388 // do arithmetic on in constant time
389 std::random_access_iterator_tag) {
390 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
393 // This requires that the iterator points to contiguous memory.
394 init(Ptr, &*IdxBegin, NumIdx); // FIXME: for the general case
395 // we have to build an array here
398 init(Ptr, 0, NumIdx);
404 /// getIndexedType - Returns the type of the element that would be loaded with
405 /// a load instruction with the specified parameters.
407 /// A null type is returned if the indices are invalid for the specified
410 static const Type *getIndexedType(const Type *Ptr,
411 Value* const *Idx, unsigned NumIdx,
412 bool AllowStructLeaf = false);
414 template<typename InputIterator>
415 static const Type *getIndexedType(const Type *Ptr,
416 InputIterator IdxBegin,
417 InputIterator IdxEnd,
418 bool AllowStructLeaf,
419 // This argument ensures that we
420 // have an iterator we can do
421 // arithmetic on in constant time
422 std::random_access_iterator_tag) {
423 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
426 // This requires that the iterator points to contiguous memory.
427 return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
431 return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
435 /// Constructors - Create a getelementptr instruction with a base pointer an
436 /// list of indices. The first ctor can optionally insert before an existing
437 /// instruction, the second appends the new instruction to the specified
439 template<typename InputIterator>
440 inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
441 InputIterator IdxEnd,
443 const std::string &Name,
444 Instruction *InsertBefore);
445 template<typename InputIterator>
446 inline GetElementPtrInst(Value *Ptr,
447 InputIterator IdxBegin, InputIterator IdxEnd,
449 const std::string &Name, BasicBlock *InsertAtEnd);
451 /// Constructors - These two constructors are convenience methods because one
452 /// and two index getelementptr instructions are so common.
453 GetElementPtrInst(Value *Ptr, Value *Idx, const std::string &Name = "",
454 Instruction *InsertBefore = 0);
455 GetElementPtrInst(Value *Ptr, Value *Idx,
456 const std::string &Name, BasicBlock *InsertAtEnd);
458 template<typename InputIterator>
459 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
460 InputIterator IdxEnd,
461 const std::string &Name = "",
462 Instruction *InsertBefore = 0) {
463 typename std::iterator_traits<InputIterator>::difference_type Values =
464 1 + std::distance(IdxBegin, IdxEnd);
466 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertBefore);
468 template<typename InputIterator>
469 static GetElementPtrInst *Create(Value *Ptr,
470 InputIterator IdxBegin, InputIterator IdxEnd,
471 const std::string &Name,
472 BasicBlock *InsertAtEnd) {
473 typename std::iterator_traits<InputIterator>::difference_type Values =
474 1 + std::distance(IdxBegin, IdxEnd);
476 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertAtEnd);
479 /// Constructors - These two creators are convenience methods because one
480 /// index getelementptr instructions are so common.
481 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
482 const std::string &Name = "",
483 Instruction *InsertBefore = 0) {
484 return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
486 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
487 const std::string &Name,
488 BasicBlock *InsertAtEnd) {
489 return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
492 virtual GetElementPtrInst *clone() const;
494 /// Transparently provide more efficient getOperand methods.
495 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
497 // getType - Overload to return most specific pointer type...
498 const PointerType *getType() const {
499 return reinterpret_cast<const PointerType*>(Instruction::getType());
502 /// getIndexedType - Returns the type of the element that would be loaded with
503 /// a load instruction with the specified parameters.
505 /// A null type is returned if the indices are invalid for the specified
508 template<typename InputIterator>
509 static const Type *getIndexedType(const Type *Ptr,
510 InputIterator IdxBegin,
511 InputIterator IdxEnd,
512 bool AllowStructLeaf = false) {
513 return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf,
514 typename std::iterator_traits<InputIterator>::
515 iterator_category()));
517 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
519 inline op_iterator idx_begin() { return op_begin()+1; }
520 inline const_op_iterator idx_begin() const { return op_begin()+1; }
521 inline op_iterator idx_end() { return op_end(); }
522 inline const_op_iterator idx_end() const { return op_end(); }
524 Value *getPointerOperand() {
525 return getOperand(0);
527 const Value *getPointerOperand() const {
528 return getOperand(0);
530 static unsigned getPointerOperandIndex() {
531 return 0U; // get index for modifying correct operand
534 unsigned getNumIndices() const { // Note: always non-negative
535 return getNumOperands() - 1;
538 bool hasIndices() const {
539 return getNumOperands() > 1;
542 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
543 /// zeros. If so, the result pointer and the first operand have the same
544 /// value, just potentially different types.
545 bool hasAllZeroIndices() const;
547 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
548 /// constant integers. If so, the result pointer and the first operand have
549 /// a constant offset between them.
550 bool hasAllConstantIndices() const;
553 // Methods for support type inquiry through isa, cast, and dyn_cast:
554 static inline bool classof(const GetElementPtrInst *) { return true; }
555 static inline bool classof(const Instruction *I) {
556 return (I->getOpcode() == Instruction::GetElementPtr);
558 static inline bool classof(const Value *V) {
559 return isa<Instruction>(V) && classof(cast<Instruction>(V));
564 struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
567 template<typename InputIterator>
568 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
569 InputIterator IdxBegin,
570 InputIterator IdxEnd,
572 const std::string &Name,
573 Instruction *InsertBefore)
574 : Instruction(PointerType::get(checkType(
575 getIndexedType(Ptr->getType(),
576 IdxBegin, IdxEnd, true)),
577 cast<PointerType>(Ptr->getType())
578 ->getAddressSpace()),
580 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
581 Values, InsertBefore) {
582 init(Ptr, IdxBegin, IdxEnd, Name,
583 typename std::iterator_traits<InputIterator>::iterator_category());
585 template<typename InputIterator>
586 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
587 InputIterator IdxBegin,
588 InputIterator IdxEnd,
590 const std::string &Name,
591 BasicBlock *InsertAtEnd)
592 : Instruction(PointerType::get(checkType(
593 getIndexedType(Ptr->getType(),
594 IdxBegin, IdxEnd, true)),
595 cast<PointerType>(Ptr->getType())
596 ->getAddressSpace()),
598 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
599 Values, InsertAtEnd) {
600 init(Ptr, IdxBegin, IdxEnd, Name,
601 typename std::iterator_traits<InputIterator>::iterator_category());
605 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
608 //===----------------------------------------------------------------------===//
610 //===----------------------------------------------------------------------===//
612 /// This instruction compares its operands according to the predicate given
613 /// to the constructor. It only operates on integers or pointers. The operands
614 /// must be identical types.
615 /// @brief Represent an integer comparison operator.
616 class ICmpInst: public CmpInst {
618 /// @brief Constructor with insert-before-instruction semantics.
620 Predicate pred, ///< The predicate to use for the comparison
621 Value *LHS, ///< The left-hand-side of the expression
622 Value *RHS, ///< The right-hand-side of the expression
623 const std::string &Name = "", ///< Name of the instruction
624 Instruction *InsertBefore = 0 ///< Where to insert
625 ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, Name,
627 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
628 pred <= CmpInst::LAST_ICMP_PREDICATE &&
629 "Invalid ICmp predicate value");
630 const Type* Op0Ty = getOperand(0)->getType();
631 const Type* Op1Ty = getOperand(1)->getType();
632 assert(Op0Ty == Op1Ty &&
633 "Both operands to ICmp instruction are not of the same type!");
634 // Check that the operands are the right type
635 assert((Op0Ty->isInteger() || isa<PointerType>(Op0Ty)) &&
636 "Invalid operand types for ICmp instruction");
639 /// @brief Constructor with insert-at-block-end semantics.
641 Predicate pred, ///< The predicate to use for the comparison
642 Value *LHS, ///< The left-hand-side of the expression
643 Value *RHS, ///< The right-hand-side of the expression
644 const std::string &Name, ///< Name of the instruction
645 BasicBlock *InsertAtEnd ///< Block to insert into.
646 ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, Name,
648 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
649 pred <= CmpInst::LAST_ICMP_PREDICATE &&
650 "Invalid ICmp predicate value");
651 const Type* Op0Ty = getOperand(0)->getType();
652 const Type* Op1Ty = getOperand(1)->getType();
653 assert(Op0Ty == Op1Ty &&
654 "Both operands to ICmp instruction are not of the same type!");
655 // Check that the operands are the right type
656 assert((Op0Ty->isInteger() || isa<PointerType>(Op0Ty)) &&
657 "Invalid operand types for ICmp instruction");
660 /// @brief Return the predicate for this instruction.
661 Predicate getPredicate() const { return Predicate(SubclassData); }
663 /// @brief Set the predicate for this instruction to the specified value.
664 void setPredicate(Predicate P) { SubclassData = P; }
666 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
667 /// @returns the inverse predicate for the instruction's current predicate.
668 /// @brief Return the inverse of the instruction's predicate.
669 Predicate getInversePredicate() const {
670 return getInversePredicate(getPredicate());
673 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
674 /// @returns the inverse predicate for predicate provided in \p pred.
675 /// @brief Return the inverse of a given predicate
676 static Predicate getInversePredicate(Predicate pred);
678 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
679 /// @returns the predicate that would be the result of exchanging the two
680 /// operands of the ICmpInst instruction without changing the result
682 /// @brief Return the predicate as if the operands were swapped
683 Predicate getSwappedPredicate() const {
684 return getSwappedPredicate(getPredicate());
687 /// This is a static version that you can use without an instruction
689 /// @brief Return the predicate as if the operands were swapped.
690 static Predicate getSwappedPredicate(Predicate pred);
692 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
693 /// @returns the predicate that would be the result if the operand were
694 /// regarded as signed.
695 /// @brief Return the signed version of the predicate
696 Predicate getSignedPredicate() const {
697 return getSignedPredicate(getPredicate());
700 /// This is a static version that you can use without an instruction.
701 /// @brief Return the signed version of the predicate.
702 static Predicate getSignedPredicate(Predicate pred);
704 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
705 /// @returns the predicate that would be the result if the operand were
706 /// regarded as unsigned.
707 /// @brief Return the unsigned version of the predicate
708 Predicate getUnsignedPredicate() const {
709 return getUnsignedPredicate(getPredicate());
712 /// This is a static version that you can use without an instruction.
713 /// @brief Return the unsigned version of the predicate.
714 static Predicate getUnsignedPredicate(Predicate pred);
716 /// isEquality - Return true if this predicate is either EQ or NE. This also
717 /// tests for commutativity.
718 static bool isEquality(Predicate P) {
719 return P == ICMP_EQ || P == ICMP_NE;
722 /// isEquality - Return true if this predicate is either EQ or NE. This also
723 /// tests for commutativity.
724 bool isEquality() const {
725 return isEquality(getPredicate());
728 /// @returns true if the predicate of this ICmpInst is commutative
729 /// @brief Determine if this relation is commutative.
730 bool isCommutative() const { return isEquality(); }
732 /// isRelational - Return true if the predicate is relational (not EQ or NE).
734 bool isRelational() const {
735 return !isEquality();
738 /// isRelational - Return true if the predicate is relational (not EQ or NE).
740 static bool isRelational(Predicate P) {
741 return !isEquality(P);
744 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
745 /// @brief Determine if this instruction's predicate is signed.
746 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
748 /// @returns true if the predicate provided is signed, false otherwise
749 /// @brief Determine if the predicate is signed.
750 static bool isSignedPredicate(Predicate pred);
752 /// Initialize a set of values that all satisfy the predicate with C.
753 /// @brief Make a ConstantRange for a relation with a constant value.
754 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
756 /// Exchange the two operands to this instruction in such a way that it does
757 /// not modify the semantics of the instruction. The predicate value may be
758 /// changed to retain the same result if the predicate is order dependent
760 /// @brief Swap operands and adjust predicate.
761 void swapOperands() {
762 SubclassData = getSwappedPredicate();
763 Op<0>().swap(Op<1>());
766 virtual ICmpInst *clone() const;
768 // Methods for support type inquiry through isa, cast, and dyn_cast:
769 static inline bool classof(const ICmpInst *) { return true; }
770 static inline bool classof(const Instruction *I) {
771 return I->getOpcode() == Instruction::ICmp;
773 static inline bool classof(const Value *V) {
774 return isa<Instruction>(V) && classof(cast<Instruction>(V));
778 //===----------------------------------------------------------------------===//
780 //===----------------------------------------------------------------------===//
782 /// This instruction compares its operands according to the predicate given
783 /// to the constructor. It only operates on floating point values or packed
784 /// vectors of floating point values. The operands must be identical types.
785 /// @brief Represents a floating point comparison operator.
786 class FCmpInst: public CmpInst {
788 /// @brief Constructor with insert-before-instruction semantics.
790 Predicate pred, ///< The predicate to use for the comparison
791 Value *LHS, ///< The left-hand-side of the expression
792 Value *RHS, ///< The right-hand-side of the expression
793 const std::string &Name = "", ///< Name of the instruction
794 Instruction *InsertBefore = 0 ///< Where to insert
795 ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, Name,
797 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
798 "Invalid FCmp predicate value");
799 const Type* Op0Ty = getOperand(0)->getType();
800 const Type* Op1Ty = getOperand(1)->getType();
801 assert(Op0Ty == Op1Ty &&
802 "Both operands to FCmp instruction are not of the same type!");
803 // Check that the operands are the right type
804 assert(Op0Ty->isFloatingPoint() &&
805 "Invalid operand types for FCmp instruction");
808 /// @brief Constructor with insert-at-block-end semantics.
810 Predicate pred, ///< The predicate to use for the comparison
811 Value *LHS, ///< The left-hand-side of the expression
812 Value *RHS, ///< The right-hand-side of the expression
813 const std::string &Name, ///< Name of the instruction
814 BasicBlock *InsertAtEnd ///< Block to insert into.
815 ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, Name,
817 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
818 "Invalid FCmp predicate value");
819 const Type* Op0Ty = getOperand(0)->getType();
820 const Type* Op1Ty = getOperand(1)->getType();
821 assert(Op0Ty == Op1Ty &&
822 "Both operands to FCmp instruction are not of the same type!");
823 // Check that the operands are the right type
824 assert(Op0Ty->isFloatingPoint() &&
825 "Invalid operand types for FCmp instruction");
828 /// @brief Return the predicate for this instruction.
829 Predicate getPredicate() const { return Predicate(SubclassData); }
831 /// @brief Set the predicate for this instruction to the specified value.
832 void setPredicate(Predicate P) { SubclassData = P; }
834 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
835 /// @returns the inverse predicate for the instructions current predicate.
836 /// @brief Return the inverse of the predicate
837 Predicate getInversePredicate() const {
838 return getInversePredicate(getPredicate());
841 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
842 /// @returns the inverse predicate for \p pred.
843 /// @brief Return the inverse of a given predicate
844 static Predicate getInversePredicate(Predicate pred);
846 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
847 /// @returns the predicate that would be the result of exchanging the two
848 /// operands of the ICmpInst instruction without changing the result
850 /// @brief Return the predicate as if the operands were swapped
851 Predicate getSwappedPredicate() const {
852 return getSwappedPredicate(getPredicate());
855 /// This is a static version that you can use without an instruction
857 /// @brief Return the predicate as if the operands were swapped.
858 static Predicate getSwappedPredicate(Predicate Opcode);
860 /// This also tests for commutativity. If isEquality() returns true then
861 /// the predicate is also commutative. Only the equality predicates are
863 /// @returns true if the predicate of this instruction is EQ or NE.
864 /// @brief Determine if this is an equality predicate.
865 bool isEquality() const {
866 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
867 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
869 bool isCommutative() const { return isEquality(); }
871 /// @returns true if the predicate is relational (not EQ or NE).
872 /// @brief Determine if this a relational predicate.
873 bool isRelational() const { return !isEquality(); }
875 /// Exchange the two operands to this instruction in such a way that it does
876 /// not modify the semantics of the instruction. The predicate value may be
877 /// changed to retain the same result if the predicate is order dependent
879 /// @brief Swap operands and adjust predicate.
880 void swapOperands() {
881 SubclassData = getSwappedPredicate();
882 Op<0>().swap(Op<1>());
885 virtual FCmpInst *clone() const;
887 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
888 static inline bool classof(const FCmpInst *) { return true; }
889 static inline bool classof(const Instruction *I) {
890 return I->getOpcode() == Instruction::FCmp;
892 static inline bool classof(const Value *V) {
893 return isa<Instruction>(V) && classof(cast<Instruction>(V));
897 //===----------------------------------------------------------------------===//
899 //===----------------------------------------------------------------------===//
901 /// This instruction compares its operands according to the predicate given
902 /// to the constructor. It only operates on vectors of integers.
903 /// The operands must be identical types.
904 /// @brief Represents a vector integer comparison operator.
905 class VICmpInst: public CmpInst {
907 /// @brief Constructor with insert-before-instruction semantics.
909 Predicate pred, ///< The predicate to use for the comparison
910 Value *LHS, ///< The left-hand-side of the expression
911 Value *RHS, ///< The right-hand-side of the expression
912 const std::string &Name = "", ///< Name of the instruction
913 Instruction *InsertBefore = 0 ///< Where to insert
914 ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, Name,
918 /// @brief Constructor with insert-at-block-end semantics.
920 Predicate pred, ///< The predicate to use for the comparison
921 Value *LHS, ///< The left-hand-side of the expression
922 Value *RHS, ///< The right-hand-side of the expression
923 const std::string &Name, ///< Name of the instruction
924 BasicBlock *InsertAtEnd ///< Block to insert into.
925 ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, Name,
929 /// @brief Return the predicate for this instruction.
930 Predicate getPredicate() const { return Predicate(SubclassData); }
932 virtual VICmpInst *clone() const;
934 // Methods for support type inquiry through isa, cast, and dyn_cast:
935 static inline bool classof(const VICmpInst *) { return true; }
936 static inline bool classof(const Instruction *I) {
937 return I->getOpcode() == Instruction::VICmp;
939 static inline bool classof(const Value *V) {
940 return isa<Instruction>(V) && classof(cast<Instruction>(V));
944 //===----------------------------------------------------------------------===//
946 //===----------------------------------------------------------------------===//
948 /// This instruction compares its operands according to the predicate given
949 /// to the constructor. It only operates on vectors of floating point values.
950 /// The operands must be identical types.
951 /// @brief Represents a vector floating point comparison operator.
952 class VFCmpInst: public CmpInst {
954 /// @brief Constructor with insert-before-instruction semantics.
956 Predicate pred, ///< The predicate to use for the comparison
957 Value *LHS, ///< The left-hand-side of the expression
958 Value *RHS, ///< The right-hand-side of the expression
959 const std::string &Name = "", ///< Name of the instruction
960 Instruction *InsertBefore = 0 ///< Where to insert
961 ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
962 Instruction::VFCmp, pred, LHS, RHS, Name, InsertBefore) {
965 /// @brief Constructor with insert-at-block-end semantics.
967 Predicate pred, ///< The predicate to use for the comparison
968 Value *LHS, ///< The left-hand-side of the expression
969 Value *RHS, ///< The right-hand-side of the expression
970 const std::string &Name, ///< Name of the instruction
971 BasicBlock *InsertAtEnd ///< Block to insert into.
972 ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
973 Instruction::VFCmp, pred, LHS, RHS, Name, InsertAtEnd) {
976 /// @brief Return the predicate for this instruction.
977 Predicate getPredicate() const { return Predicate(SubclassData); }
979 virtual VFCmpInst *clone() const;
981 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
982 static inline bool classof(const VFCmpInst *) { return true; }
983 static inline bool classof(const Instruction *I) {
984 return I->getOpcode() == Instruction::VFCmp;
986 static inline bool classof(const Value *V) {
987 return isa<Instruction>(V) && classof(cast<Instruction>(V));
991 //===----------------------------------------------------------------------===//
993 //===----------------------------------------------------------------------===//
994 /// CallInst - This class represents a function call, abstracting a target
995 /// machine's calling convention. This class uses low bit of the SubClassData
996 /// field to indicate whether or not this is a tail call. The rest of the bits
997 /// hold the calling convention of the call.
1000 class CallInst : public Instruction {
1001 PAListPtr ParamAttrs; ///< parameter attributes for call
1002 CallInst(const CallInst &CI);
1003 void init(Value *Func, Value* const *Params, unsigned NumParams);
1004 void init(Value *Func, Value *Actual1, Value *Actual2);
1005 void init(Value *Func, Value *Actual);
1006 void init(Value *Func);
1008 template<typename InputIterator>
1009 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1010 const std::string &Name,
1011 // This argument ensures that we have an iterator we can
1012 // do arithmetic on in constant time
1013 std::random_access_iterator_tag) {
1014 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
1016 // This requires that the iterator points to contiguous memory.
1017 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
1021 /// Construct a CallInst given a range of arguments. InputIterator
1022 /// must be a random-access iterator pointing to contiguous storage
1023 /// (e.g. a std::vector<>::iterator). Checks are made for
1024 /// random-accessness but not for contiguous storage as that would
1025 /// incur runtime overhead.
1026 /// @brief Construct a CallInst from a range of arguments
1027 template<typename InputIterator>
1028 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1029 const std::string &Name, Instruction *InsertBefore);
1031 /// Construct a CallInst given a range of arguments. InputIterator
1032 /// must be a random-access iterator pointing to contiguous storage
1033 /// (e.g. a std::vector<>::iterator). Checks are made for
1034 /// random-accessness but not for contiguous storage as that would
1035 /// incur runtime overhead.
1036 /// @brief Construct a CallInst from a range of arguments
1037 template<typename InputIterator>
1038 inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1039 const std::string &Name, BasicBlock *InsertAtEnd);
1041 CallInst(Value *F, Value *Actual, const std::string& Name,
1042 Instruction *InsertBefore);
1043 CallInst(Value *F, Value *Actual, const std::string& Name,
1044 BasicBlock *InsertAtEnd);
1045 explicit CallInst(Value *F, const std::string &Name,
1046 Instruction *InsertBefore);
1047 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
1049 template<typename InputIterator>
1050 static CallInst *Create(Value *Func,
1051 InputIterator ArgBegin, InputIterator ArgEnd,
1052 const std::string &Name = "",
1053 Instruction *InsertBefore = 0) {
1054 return new((unsigned)(ArgEnd - ArgBegin + 1))
1055 CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
1057 template<typename InputIterator>
1058 static CallInst *Create(Value *Func,
1059 InputIterator ArgBegin, InputIterator ArgEnd,
1060 const std::string &Name, BasicBlock *InsertAtEnd) {
1061 return new((unsigned)(ArgEnd - ArgBegin + 1))
1062 CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
1064 static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
1065 Instruction *InsertBefore = 0) {
1066 return new(2) CallInst(F, Actual, Name, InsertBefore);
1068 static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
1069 BasicBlock *InsertAtEnd) {
1070 return new(2) CallInst(F, Actual, Name, InsertAtEnd);
1072 static CallInst *Create(Value *F, const std::string &Name = "",
1073 Instruction *InsertBefore = 0) {
1074 return new(1) CallInst(F, Name, InsertBefore);
1076 static CallInst *Create(Value *F, const std::string &Name,
1077 BasicBlock *InsertAtEnd) {
1078 return new(1) CallInst(F, Name, InsertAtEnd);
1083 virtual CallInst *clone() const;
1085 /// Provide fast operand accessors
1086 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1088 bool isTailCall() const { return SubclassData & 1; }
1089 void setTailCall(bool isTailCall = true) {
1090 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
1093 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1095 unsigned getCallingConv() const { return SubclassData >> 1; }
1096 void setCallingConv(unsigned CC) {
1097 SubclassData = (SubclassData & 1) | (CC << 1);
1100 /// getParamAttrs - Return the parameter attributes for this call.
1102 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
1104 /// setParamAttrs - Sets the parameter attributes for this call.
1105 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
1107 /// @brief Determine whether the call or the callee has the given attribute.
1108 bool paramHasAttr(unsigned i, unsigned attr) const;
1110 /// @brief Extract the alignment for a call or parameter (0=unknown).
1111 unsigned getParamAlignment(unsigned i) const {
1112 return ParamAttrs.getParamAlignment(i);
1115 /// @brief Determine if the call does not access memory.
1116 bool doesNotAccessMemory() const {
1117 return paramHasAttr(0, ParamAttr::ReadNone);
1120 /// @brief Determine if the call does not access or only reads memory.
1121 bool onlyReadsMemory() const {
1122 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1125 /// @brief Determine if the call cannot return.
1126 bool doesNotReturn() const {
1127 return paramHasAttr(0, ParamAttr::NoReturn);
1130 /// @brief Determine if the call cannot unwind.
1131 bool doesNotThrow() const {
1132 return paramHasAttr(0, ParamAttr::NoUnwind);
1134 void setDoesNotThrow(bool doesNotThrow = true);
1136 /// @brief Determine if the call returns a structure through first
1137 /// pointer argument.
1138 bool hasStructRetAttr() const {
1139 // Be friendly and also check the callee.
1140 return paramHasAttr(1, ParamAttr::StructRet);
1143 /// @brief Determine if any call argument is an aggregate passed by value.
1144 bool hasByValArgument() const {
1145 return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal);
1148 /// getCalledFunction - Return the function being called by this instruction
1149 /// if it is a direct call. If it is a call through a function pointer,
1151 Function *getCalledFunction() const {
1152 return dyn_cast<Function>(getOperand(0));
1155 /// getCalledValue - Get a pointer to the function that is invoked by this
1157 const Value *getCalledValue() const { return getOperand(0); }
1158 Value *getCalledValue() { return getOperand(0); }
1160 // Methods for support type inquiry through isa, cast, and dyn_cast:
1161 static inline bool classof(const CallInst *) { return true; }
1162 static inline bool classof(const Instruction *I) {
1163 return I->getOpcode() == Instruction::Call;
1165 static inline bool classof(const Value *V) {
1166 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1171 struct OperandTraits<CallInst> : VariadicOperandTraits<1> {
1174 template<typename InputIterator>
1175 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1176 const std::string &Name, BasicBlock *InsertAtEnd)
1177 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1178 ->getElementType())->getReturnType(),
1180 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1181 (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1182 init(Func, ArgBegin, ArgEnd, Name,
1183 typename std::iterator_traits<InputIterator>::iterator_category());
1186 template<typename InputIterator>
1187 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1188 const std::string &Name, Instruction *InsertBefore)
1189 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1190 ->getElementType())->getReturnType(),
1192 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1193 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
1194 init(Func, ArgBegin, ArgEnd, Name,
1195 typename std::iterator_traits<InputIterator>::iterator_category());
1198 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1200 //===----------------------------------------------------------------------===//
1202 //===----------------------------------------------------------------------===//
1204 /// SelectInst - This class represents the LLVM 'select' instruction.
1206 class SelectInst : public Instruction {
1207 void init(Value *C, Value *S1, Value *S2) {
1213 SelectInst(const SelectInst &SI)
1214 : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) {
1215 init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>());
1217 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1218 Instruction *InsertBefore)
1219 : Instruction(S1->getType(), Instruction::Select,
1220 &Op<0>(), 3, InsertBefore) {
1224 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1225 BasicBlock *InsertAtEnd)
1226 : Instruction(S1->getType(), Instruction::Select,
1227 &Op<0>(), 3, InsertAtEnd) {
1232 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1233 const std::string &Name = "",
1234 Instruction *InsertBefore = 0) {
1235 return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
1237 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1238 const std::string &Name, BasicBlock *InsertAtEnd) {
1239 return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
1242 Value *getCondition() const { return Op<0>(); }
1243 Value *getTrueValue() const { return Op<1>(); }
1244 Value *getFalseValue() const { return Op<2>(); }
1246 /// Transparently provide more efficient getOperand methods.
1247 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1249 OtherOps getOpcode() const {
1250 return static_cast<OtherOps>(Instruction::getOpcode());
1253 virtual SelectInst *clone() const;
1255 // Methods for support type inquiry through isa, cast, and dyn_cast:
1256 static inline bool classof(const SelectInst *) { return true; }
1257 static inline bool classof(const Instruction *I) {
1258 return I->getOpcode() == Instruction::Select;
1260 static inline bool classof(const Value *V) {
1261 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1266 struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> {
1269 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1271 //===----------------------------------------------------------------------===//
1273 //===----------------------------------------------------------------------===//
1275 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1276 /// an argument of the specified type given a va_list and increments that list
1278 class VAArgInst : public UnaryInstruction {
1279 VAArgInst(const VAArgInst &VAA)
1280 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1282 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1283 Instruction *InsertBefore = 0)
1284 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1287 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1288 BasicBlock *InsertAtEnd)
1289 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1293 virtual VAArgInst *clone() const;
1295 // Methods for support type inquiry through isa, cast, and dyn_cast:
1296 static inline bool classof(const VAArgInst *) { return true; }
1297 static inline bool classof(const Instruction *I) {
1298 return I->getOpcode() == VAArg;
1300 static inline bool classof(const Value *V) {
1301 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1305 //===----------------------------------------------------------------------===//
1306 // ExtractElementInst Class
1307 //===----------------------------------------------------------------------===//
1309 /// ExtractElementInst - This instruction extracts a single (scalar)
1310 /// element from a VectorType value
1312 class ExtractElementInst : public Instruction {
1313 ExtractElementInst(const ExtractElementInst &EE) :
1314 Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) {
1315 Op<0>().init(EE.Op<0>(), this);
1316 Op<1>().init(EE.Op<1>(), this);
1320 // allocate space for exactly two operands
1321 void *operator new(size_t s) {
1322 return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor?
1324 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1325 Instruction *InsertBefore = 0);
1326 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1327 Instruction *InsertBefore = 0);
1328 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1329 BasicBlock *InsertAtEnd);
1330 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1331 BasicBlock *InsertAtEnd);
1333 /// isValidOperands - Return true if an extractelement instruction can be
1334 /// formed with the specified operands.
1335 static bool isValidOperands(const Value *Vec, const Value *Idx);
1337 virtual ExtractElementInst *clone() const;
1339 /// Transparently provide more efficient getOperand methods.
1340 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1342 // Methods for support type inquiry through isa, cast, and dyn_cast:
1343 static inline bool classof(const ExtractElementInst *) { return true; }
1344 static inline bool classof(const Instruction *I) {
1345 return I->getOpcode() == Instruction::ExtractElement;
1347 static inline bool classof(const Value *V) {
1348 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1353 struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> {
1356 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1358 //===----------------------------------------------------------------------===//
1359 // InsertElementInst Class
1360 //===----------------------------------------------------------------------===//
1362 /// InsertElementInst - This instruction inserts a single (scalar)
1363 /// element into a VectorType value
1365 class InsertElementInst : public Instruction {
1366 InsertElementInst(const InsertElementInst &IE);
1367 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1368 const std::string &Name = "",Instruction *InsertBefore = 0);
1369 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1370 const std::string &Name = "",Instruction *InsertBefore = 0);
1371 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1372 const std::string &Name, BasicBlock *InsertAtEnd);
1373 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1374 const std::string &Name, BasicBlock *InsertAtEnd);
1376 static InsertElementInst *Create(const InsertElementInst &IE) {
1377 return new(IE.getNumOperands()) InsertElementInst(IE);
1379 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1380 const std::string &Name = "",
1381 Instruction *InsertBefore = 0) {
1382 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1384 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1385 const std::string &Name = "",
1386 Instruction *InsertBefore = 0) {
1387 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1389 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1390 const std::string &Name,
1391 BasicBlock *InsertAtEnd) {
1392 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1394 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1395 const std::string &Name,
1396 BasicBlock *InsertAtEnd) {
1397 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1400 /// isValidOperands - Return true if an insertelement instruction can be
1401 /// formed with the specified operands.
1402 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1405 virtual InsertElementInst *clone() const;
1407 /// getType - Overload to return most specific vector type.
1409 const VectorType *getType() const {
1410 return reinterpret_cast<const VectorType*>(Instruction::getType());
1413 /// Transparently provide more efficient getOperand methods.
1414 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1416 // Methods for support type inquiry through isa, cast, and dyn_cast:
1417 static inline bool classof(const InsertElementInst *) { return true; }
1418 static inline bool classof(const Instruction *I) {
1419 return I->getOpcode() == Instruction::InsertElement;
1421 static inline bool classof(const Value *V) {
1422 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1427 struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> {
1430 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1432 //===----------------------------------------------------------------------===//
1433 // ShuffleVectorInst Class
1434 //===----------------------------------------------------------------------===//
1436 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1439 class ShuffleVectorInst : public Instruction {
1440 ShuffleVectorInst(const ShuffleVectorInst &IE);
1442 // allocate space for exactly three operands
1443 void *operator new(size_t s) {
1444 return User::operator new(s, 3);
1446 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1447 const std::string &Name = "", Instruction *InsertBefor = 0);
1448 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1449 const std::string &Name, BasicBlock *InsertAtEnd);
1451 /// isValidOperands - Return true if a shufflevector instruction can be
1452 /// formed with the specified operands.
1453 static bool isValidOperands(const Value *V1, const Value *V2,
1456 virtual ShuffleVectorInst *clone() const;
1458 /// getType - Overload to return most specific vector type.
1460 const VectorType *getType() const {
1461 return reinterpret_cast<const VectorType*>(Instruction::getType());
1464 /// Transparently provide more efficient getOperand methods.
1465 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1467 /// getMaskValue - Return the index from the shuffle mask for the specified
1468 /// output result. This is either -1 if the element is undef or a number less
1469 /// than 2*numelements.
1470 int getMaskValue(unsigned i) const;
1472 // Methods for support type inquiry through isa, cast, and dyn_cast:
1473 static inline bool classof(const ShuffleVectorInst *) { return true; }
1474 static inline bool classof(const Instruction *I) {
1475 return I->getOpcode() == Instruction::ShuffleVector;
1477 static inline bool classof(const Value *V) {
1478 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1483 struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> {
1486 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, 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(const Type *Ty, const std::string &Name = "",
1507 Instruction *InsertBefore = 0)
1508 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1513 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1514 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1519 static PHINode *Create(const Type *Ty, const std::string &Name = "",
1520 Instruction *InsertBefore = 0) {
1521 return new PHINode(Ty, Name, InsertBefore);
1523 static PHINode *Create(const Type *Ty, const std::string &Name,
1524 BasicBlock *InsertAtEnd) {
1525 return new PHINode(Ty, Name, InsertAtEnd);
1529 /// reserveOperandSpace - This method can be used to avoid repeated
1530 /// reallocation of PHI operand lists by reserving space for the correct
1531 /// number of operands before adding them. Unlike normal vector reserves,
1532 /// this method can also be used to trim the operand space.
1533 void reserveOperandSpace(unsigned NumValues) {
1534 resizeOperands(NumValues*2);
1537 virtual PHINode *clone() const;
1539 /// Provide fast operand accessors
1540 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1542 /// getNumIncomingValues - Return the number of incoming edges
1544 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1546 /// getIncomingValue - Return incoming value number x
1548 Value *getIncomingValue(unsigned i) const {
1549 assert(i*2 < getNumOperands() && "Invalid value number!");
1550 return getOperand(i*2);
1552 void setIncomingValue(unsigned i, Value *V) {
1553 assert(i*2 < getNumOperands() && "Invalid value number!");
1556 unsigned getOperandNumForIncomingValue(unsigned i) {
1560 /// getIncomingBlock - Return incoming basic block number x
1562 BasicBlock *getIncomingBlock(unsigned i) const {
1563 return static_cast<BasicBlock*>(getOperand(i*2+1));
1565 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1566 setOperand(i*2+1, BB);
1568 unsigned getOperandNumForIncomingBlock(unsigned i) {
1572 /// addIncoming - Add an incoming value to the end of the PHI list
1574 void addIncoming(Value *V, BasicBlock *BB) {
1575 assert(V && "PHI node got a null value!");
1576 assert(BB && "PHI node got a null basic block!");
1577 assert(getType() == V->getType() &&
1578 "All operands to PHI node must be the same type as the PHI node!");
1579 unsigned OpNo = NumOperands;
1580 if (OpNo+2 > ReservedSpace)
1581 resizeOperands(0); // Get more space!
1582 // Initialize some new operands.
1583 NumOperands = OpNo+2;
1584 OperandList[OpNo].init(V, this);
1585 OperandList[OpNo+1].init(BB, this);
1588 /// removeIncomingValue - Remove an incoming value. This is useful if a
1589 /// predecessor basic block is deleted. The value removed is returned.
1591 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1592 /// is true), the PHI node is destroyed and any uses of it are replaced with
1593 /// dummy values. The only time there should be zero incoming values to a PHI
1594 /// node is when the block is dead, so this strategy is sound.
1596 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1598 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1599 int Idx = getBasicBlockIndex(BB);
1600 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1601 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1604 /// getBasicBlockIndex - Return the first index of the specified basic
1605 /// block in the value list for this PHI. Returns -1 if no instance.
1607 int getBasicBlockIndex(const BasicBlock *BB) const {
1608 Use *OL = OperandList;
1609 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1610 if (OL[i+1].get() == BB) return i/2;
1614 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1615 return getIncomingValue(getBasicBlockIndex(BB));
1618 /// hasConstantValue - If the specified PHI node always merges together the
1619 /// same value, return the value, otherwise return null.
1621 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1623 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1624 static inline bool classof(const PHINode *) { return true; }
1625 static inline bool classof(const Instruction *I) {
1626 return I->getOpcode() == Instruction::PHI;
1628 static inline bool classof(const Value *V) {
1629 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1632 void resizeOperands(unsigned NumOperands);
1636 struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
1639 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1642 //===----------------------------------------------------------------------===//
1644 //===----------------------------------------------------------------------===//
1646 //===---------------------------------------------------------------------------
1647 /// ReturnInst - Return a value (possibly void), from a function. Execution
1648 /// does not continue in this function any longer.
1650 class ReturnInst : public TerminatorInst {
1651 ReturnInst(const ReturnInst &RI);
1652 void init(Value * const* retVals, unsigned N);
1655 // ReturnInst constructors:
1656 // ReturnInst() - 'ret void' instruction
1657 // ReturnInst( null) - 'ret void' instruction
1658 // ReturnInst(Value* X) - 'ret X' instruction
1659 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1660 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1661 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1662 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1663 // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction
1664 // ReturnInst(Value* X, N, Inst *I) - 'ret X,X+1...X+N-1', insert before I
1665 // ReturnInst(Value* X, N, BB *B) - 'ret X,X+1...X+N-1', insert @ end of B
1667 // NOTE: If the Value* passed is of type void then the constructor behaves as
1668 // if it was passed NULL.
1669 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1670 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1671 ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore = 0);
1672 ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
1673 explicit ReturnInst(BasicBlock *InsertAtEnd);
1675 static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
1676 return new(!!retVal) ReturnInst(retVal, InsertBefore);
1678 static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
1679 return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
1681 static ReturnInst* Create(Value * const* retVals, unsigned N,
1682 Instruction *InsertBefore = 0) {
1683 return new(N) ReturnInst(retVals, N, InsertBefore);
1685 static ReturnInst* Create(Value * const* retVals, unsigned N,
1686 BasicBlock *InsertAtEnd) {
1687 return new(N) ReturnInst(retVals, N, InsertAtEnd);
1689 static ReturnInst* Create(BasicBlock *InsertAtEnd) {
1690 return new(0) ReturnInst(InsertAtEnd);
1692 virtual ~ReturnInst();
1693 inline void operator delete(void*);
1695 virtual ReturnInst *clone() const;
1697 /// Provide fast operand accessors
1698 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1700 /// Convenience accessor
1701 Value *getReturnValue(unsigned n = 0) const {
1702 return n < getNumOperands()
1707 unsigned getNumSuccessors() const { return 0; }
1709 // Methods for support type inquiry through isa, cast, and dyn_cast:
1710 static inline bool classof(const ReturnInst *) { return true; }
1711 static inline bool classof(const Instruction *I) {
1712 return (I->getOpcode() == Instruction::Ret);
1714 static inline bool classof(const Value *V) {
1715 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1718 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1719 virtual unsigned getNumSuccessorsV() const;
1720 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1724 struct OperandTraits<ReturnInst> : VariadicOperandTraits<> {
1727 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1728 void ReturnInst::operator delete(void *it) {
1729 ReturnInst* me(static_cast<ReturnInst*>(it));
1730 Use::zap(OperandTraits<ReturnInst>::op_begin(me),
1731 OperandTraits<ReturnInst>::op_end(me),
1735 //===----------------------------------------------------------------------===//
1737 //===----------------------------------------------------------------------===//
1739 //===---------------------------------------------------------------------------
1740 /// BranchInst - Conditional or Unconditional Branch instruction.
1742 class BranchInst : public TerminatorInst {
1743 /// Ops list - Branches are strange. The operands are ordered:
1744 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1745 /// they don't have to check for cond/uncond branchness.
1746 BranchInst(const BranchInst &BI);
1748 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1749 // BranchInst(BB *B) - 'br B'
1750 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1751 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1752 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1753 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1754 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1755 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1756 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1757 Instruction *InsertBefore = 0);
1758 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1759 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1760 BasicBlock *InsertAtEnd);
1762 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1763 return new(1) BranchInst(IfTrue, InsertBefore);
1765 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1766 Value *Cond, Instruction *InsertBefore = 0) {
1767 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1769 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1770 return new(1) BranchInst(IfTrue, InsertAtEnd);
1772 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1773 Value *Cond, BasicBlock *InsertAtEnd) {
1774 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1778 if (NumOperands == 1)
1779 NumOperands = (unsigned)((Use*)this - OperandList);
1782 /// Transparently provide more efficient getOperand methods.
1783 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1785 virtual BranchInst *clone() const;
1787 bool isUnconditional() const { return getNumOperands() == 1; }
1788 bool isConditional() const { return getNumOperands() == 3; }
1790 Value *getCondition() const {
1791 assert(isConditional() && "Cannot get condition of an uncond branch!");
1792 return getOperand(2);
1795 void setCondition(Value *V) {
1796 assert(isConditional() && "Cannot set condition of unconditional branch!");
1800 // setUnconditionalDest - Change the current branch to an unconditional branch
1801 // targeting the specified block.
1802 // FIXME: Eliminate this ugly method.
1803 void setUnconditionalDest(BasicBlock *Dest) {
1805 if (isConditional()) { // Convert this to an uncond branch.
1812 unsigned getNumSuccessors() const { return 1+isConditional(); }
1814 BasicBlock *getSuccessor(unsigned i) const {
1815 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1816 return cast<BasicBlock>(getOperand(i));
1819 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1820 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1821 setOperand(idx, NewSucc);
1824 // Methods for support type inquiry through isa, cast, and dyn_cast:
1825 static inline bool classof(const BranchInst *) { return true; }
1826 static inline bool classof(const Instruction *I) {
1827 return (I->getOpcode() == Instruction::Br);
1829 static inline bool classof(const Value *V) {
1830 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1833 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1834 virtual unsigned getNumSuccessorsV() const;
1835 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1839 struct OperandTraits<BranchInst> : HungoffOperandTraits<> {
1840 // we need to access operands via OperandList, since
1841 // the NumOperands may change from 3 to 1
1842 static inline void *allocate(unsigned); // FIXME
1845 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
1847 //===----------------------------------------------------------------------===//
1849 //===----------------------------------------------------------------------===//
1851 //===---------------------------------------------------------------------------
1852 /// SwitchInst - Multiway switch
1854 class SwitchInst : public TerminatorInst {
1855 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1856 unsigned ReservedSpace;
1857 // Operand[0] = Value to switch on
1858 // Operand[1] = Default basic block destination
1859 // Operand[2n ] = Value to match
1860 // Operand[2n+1] = BasicBlock to go to on match
1861 SwitchInst(const SwitchInst &RI);
1862 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1863 void resizeOperands(unsigned No);
1864 // allocate space for exactly zero operands
1865 void *operator new(size_t s) {
1866 return User::operator new(s, 0);
1868 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1869 /// switch on and a default destination. The number of additional cases can
1870 /// be specified here to make memory allocation more efficient. This
1871 /// constructor can also autoinsert before another instruction.
1872 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1873 Instruction *InsertBefore = 0);
1875 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1876 /// switch on and a default destination. The number of additional cases can
1877 /// be specified here to make memory allocation more efficient. This
1878 /// constructor also autoinserts at the end of the specified BasicBlock.
1879 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1880 BasicBlock *InsertAtEnd);
1882 static SwitchInst *Create(Value *Value, BasicBlock *Default,
1883 unsigned NumCases, Instruction *InsertBefore = 0) {
1884 return new SwitchInst(Value, Default, NumCases, InsertBefore);
1886 static SwitchInst *Create(Value *Value, BasicBlock *Default,
1887 unsigned NumCases, BasicBlock *InsertAtEnd) {
1888 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
1892 /// Provide fast operand accessors
1893 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1895 // Accessor Methods for Switch stmt
1896 Value *getCondition() const { return getOperand(0); }
1897 void setCondition(Value *V) { setOperand(0, V); }
1899 BasicBlock *getDefaultDest() const {
1900 return cast<BasicBlock>(getOperand(1));
1903 /// getNumCases - return the number of 'cases' in this switch instruction.
1904 /// Note that case #0 is always the default case.
1905 unsigned getNumCases() const {
1906 return getNumOperands()/2;
1909 /// getCaseValue - Return the specified case value. Note that case #0, the
1910 /// default destination, does not have a case value.
1911 ConstantInt *getCaseValue(unsigned i) {
1912 assert(i && i < getNumCases() && "Illegal case value to get!");
1913 return getSuccessorValue(i);
1916 /// getCaseValue - Return the specified case value. Note that case #0, the
1917 /// default destination, does not have a case value.
1918 const ConstantInt *getCaseValue(unsigned i) const {
1919 assert(i && i < getNumCases() && "Illegal case value to get!");
1920 return getSuccessorValue(i);
1923 /// findCaseValue - Search all of the case values for the specified constant.
1924 /// If it is explicitly handled, return the case number of it, otherwise
1925 /// return 0 to indicate that it is handled by the default handler.
1926 unsigned findCaseValue(const ConstantInt *C) const {
1927 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1928 if (getCaseValue(i) == C)
1933 /// findCaseDest - Finds the unique case value for a given successor. Returns
1934 /// null if the successor is not found, not unique, or is the default case.
1935 ConstantInt *findCaseDest(BasicBlock *BB) {
1936 if (BB == getDefaultDest()) return NULL;
1938 ConstantInt *CI = NULL;
1939 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1940 if (getSuccessor(i) == BB) {
1941 if (CI) return NULL; // Multiple cases lead to BB.
1942 else CI = getCaseValue(i);
1948 /// addCase - Add an entry to the switch instruction...
1950 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1952 /// removeCase - This method removes the specified successor from the switch
1953 /// instruction. Note that this cannot be used to remove the default
1954 /// destination (successor #0).
1956 void removeCase(unsigned idx);
1958 virtual SwitchInst *clone() const;
1960 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1961 BasicBlock *getSuccessor(unsigned idx) const {
1962 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1963 return cast<BasicBlock>(getOperand(idx*2+1));
1965 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1966 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1967 setOperand(idx*2+1, NewSucc);
1970 // getSuccessorValue - Return the value associated with the specified
1972 ConstantInt *getSuccessorValue(unsigned idx) const {
1973 assert(idx < getNumSuccessors() && "Successor # out of range!");
1974 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1977 // Methods for support type inquiry through isa, cast, and dyn_cast:
1978 static inline bool classof(const SwitchInst *) { return true; }
1979 static inline bool classof(const Instruction *I) {
1980 return I->getOpcode() == Instruction::Switch;
1982 static inline bool classof(const Value *V) {
1983 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1986 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1987 virtual unsigned getNumSuccessorsV() const;
1988 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1992 struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
1995 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
1998 //===----------------------------------------------------------------------===//
2000 //===----------------------------------------------------------------------===//
2002 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2003 /// calling convention of the call.
2005 class InvokeInst : public TerminatorInst {
2006 PAListPtr ParamAttrs;
2007 InvokeInst(const InvokeInst &BI);
2008 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2009 Value* const *Args, unsigned NumArgs);
2011 template<typename InputIterator>
2012 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2013 InputIterator ArgBegin, InputIterator ArgEnd,
2014 const std::string &Name,
2015 // This argument ensures that we have an iterator we can
2016 // do arithmetic on in constant time
2017 std::random_access_iterator_tag) {
2018 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2020 // This requires that the iterator points to contiguous memory.
2021 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2025 /// Construct an InvokeInst given a range of arguments.
2026 /// InputIterator must be a random-access iterator pointing to
2027 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2028 /// made for random-accessness but not for contiguous storage as
2029 /// that would incur runtime overhead.
2031 /// @brief Construct an InvokeInst from a range of arguments
2032 template<typename InputIterator>
2033 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2034 InputIterator ArgBegin, InputIterator ArgEnd,
2036 const std::string &Name, Instruction *InsertBefore);
2038 /// Construct an InvokeInst given a range of arguments.
2039 /// InputIterator must be a random-access iterator pointing to
2040 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2041 /// made for random-accessness but not for contiguous storage as
2042 /// that would incur runtime overhead.
2044 /// @brief Construct an InvokeInst from a range of arguments
2045 template<typename InputIterator>
2046 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2047 InputIterator ArgBegin, InputIterator ArgEnd,
2049 const std::string &Name, BasicBlock *InsertAtEnd);
2051 template<typename InputIterator>
2052 static InvokeInst *Create(Value *Func,
2053 BasicBlock *IfNormal, BasicBlock *IfException,
2054 InputIterator ArgBegin, InputIterator ArgEnd,
2055 const std::string &Name = "",
2056 Instruction *InsertBefore = 0) {
2057 unsigned Values(ArgEnd - ArgBegin + 3);
2058 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2059 Values, Name, InsertBefore);
2061 template<typename InputIterator>
2062 static InvokeInst *Create(Value *Func,
2063 BasicBlock *IfNormal, BasicBlock *IfException,
2064 InputIterator ArgBegin, InputIterator ArgEnd,
2065 const std::string &Name, BasicBlock *InsertAtEnd) {
2066 unsigned Values(ArgEnd - ArgBegin + 3);
2067 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2068 Values, Name, InsertAtEnd);
2071 virtual InvokeInst *clone() const;
2073 /// Provide fast operand accessors
2074 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2076 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2078 unsigned getCallingConv() const { return SubclassData; }
2079 void setCallingConv(unsigned CC) {
2083 /// getParamAttrs - Return the parameter attributes for this invoke.
2085 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
2087 /// setParamAttrs - Set the parameter attributes for this invoke.
2089 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
2091 /// @brief Determine whether the call or the callee has the given attribute.
2092 bool paramHasAttr(unsigned i, ParameterAttributes attr) const;
2094 /// @brief Extract the alignment for a call or parameter (0=unknown).
2095 unsigned getParamAlignment(unsigned i) const {
2096 return ParamAttrs.getParamAlignment(i);
2099 /// @brief Determine if the call does not access memory.
2100 bool doesNotAccessMemory() const {
2101 return paramHasAttr(0, ParamAttr::ReadNone);
2104 /// @brief Determine if the call does not access or only reads memory.
2105 bool onlyReadsMemory() const {
2106 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
2109 /// @brief Determine if the call cannot return.
2110 bool doesNotReturn() const {
2111 return paramHasAttr(0, ParamAttr::NoReturn);
2114 /// @brief Determine if the call cannot unwind.
2115 bool doesNotThrow() const {
2116 return paramHasAttr(0, ParamAttr::NoUnwind);
2118 void setDoesNotThrow(bool doesNotThrow = true);
2120 /// @brief Determine if the call returns a structure through first
2121 /// pointer argument.
2122 bool hasStructRetAttr() const {
2123 // Be friendly and also check the callee.
2124 return paramHasAttr(1, ParamAttr::StructRet);
2127 /// getCalledFunction - Return the function called, or null if this is an
2128 /// indirect function invocation.
2130 Function *getCalledFunction() const {
2131 return dyn_cast<Function>(getOperand(0));
2134 // getCalledValue - Get a pointer to a function that is invoked by this inst.
2135 Value *getCalledValue() const { return getOperand(0); }
2137 // get*Dest - Return the destination basic blocks...
2138 BasicBlock *getNormalDest() const {
2139 return cast<BasicBlock>(getOperand(1));
2141 BasicBlock *getUnwindDest() const {
2142 return cast<BasicBlock>(getOperand(2));
2144 void setNormalDest(BasicBlock *B) {
2148 void setUnwindDest(BasicBlock *B) {
2152 BasicBlock *getSuccessor(unsigned i) const {
2153 assert(i < 2 && "Successor # out of range for invoke!");
2154 return i == 0 ? getNormalDest() : getUnwindDest();
2157 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2158 assert(idx < 2 && "Successor # out of range for invoke!");
2159 setOperand(idx+1, NewSucc);
2162 unsigned getNumSuccessors() const { return 2; }
2164 // Methods for support type inquiry through isa, cast, and dyn_cast:
2165 static inline bool classof(const InvokeInst *) { return true; }
2166 static inline bool classof(const Instruction *I) {
2167 return (I->getOpcode() == Instruction::Invoke);
2169 static inline bool classof(const Value *V) {
2170 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2173 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2174 virtual unsigned getNumSuccessorsV() const;
2175 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2179 struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> {
2182 template<typename InputIterator>
2183 InvokeInst::InvokeInst(Value *Func,
2184 BasicBlock *IfNormal, BasicBlock *IfException,
2185 InputIterator ArgBegin, InputIterator ArgEnd,
2187 const std::string &Name, Instruction *InsertBefore)
2188 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2189 ->getElementType())->getReturnType(),
2190 Instruction::Invoke,
2191 OperandTraits<InvokeInst>::op_end(this) - Values,
2192 Values, InsertBefore) {
2193 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
2194 typename std::iterator_traits<InputIterator>::iterator_category());
2196 template<typename InputIterator>
2197 InvokeInst::InvokeInst(Value *Func,
2198 BasicBlock *IfNormal, BasicBlock *IfException,
2199 InputIterator ArgBegin, InputIterator ArgEnd,
2201 const std::string &Name, BasicBlock *InsertAtEnd)
2202 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2203 ->getElementType())->getReturnType(),
2204 Instruction::Invoke,
2205 OperandTraits<InvokeInst>::op_end(this) - Values,
2206 Values, InsertAtEnd) {
2207 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
2208 typename std::iterator_traits<InputIterator>::iterator_category());
2211 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2213 //===----------------------------------------------------------------------===//
2215 //===----------------------------------------------------------------------===//
2217 //===---------------------------------------------------------------------------
2218 /// UnwindInst - Immediately exit the current function, unwinding the stack
2219 /// until an invoke instruction is found.
2221 class UnwindInst : public TerminatorInst {
2222 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2224 // allocate space for exactly zero operands
2225 void *operator new(size_t s) {
2226 return User::operator new(s, 0);
2228 explicit UnwindInst(Instruction *InsertBefore = 0);
2229 explicit UnwindInst(BasicBlock *InsertAtEnd);
2231 virtual UnwindInst *clone() const;
2233 unsigned getNumSuccessors() const { return 0; }
2235 // Methods for support type inquiry through isa, cast, and dyn_cast:
2236 static inline bool classof(const UnwindInst *) { return true; }
2237 static inline bool classof(const Instruction *I) {
2238 return I->getOpcode() == Instruction::Unwind;
2240 static inline bool classof(const Value *V) {
2241 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2244 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2245 virtual unsigned getNumSuccessorsV() const;
2246 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2249 //===----------------------------------------------------------------------===//
2250 // UnreachableInst Class
2251 //===----------------------------------------------------------------------===//
2253 //===---------------------------------------------------------------------------
2254 /// UnreachableInst - This function has undefined behavior. In particular, the
2255 /// presence of this instruction indicates some higher level knowledge that the
2256 /// end of the block cannot be reached.
2258 class UnreachableInst : public TerminatorInst {
2259 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2261 // allocate space for exactly zero operands
2262 void *operator new(size_t s) {
2263 return User::operator new(s, 0);
2265 explicit UnreachableInst(Instruction *InsertBefore = 0);
2266 explicit UnreachableInst(BasicBlock *InsertAtEnd);
2268 virtual UnreachableInst *clone() const;
2270 unsigned getNumSuccessors() const { return 0; }
2272 // Methods for support type inquiry through isa, cast, and dyn_cast:
2273 static inline bool classof(const UnreachableInst *) { return true; }
2274 static inline bool classof(const Instruction *I) {
2275 return I->getOpcode() == Instruction::Unreachable;
2277 static inline bool classof(const Value *V) {
2278 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2281 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2282 virtual unsigned getNumSuccessorsV() const;
2283 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2286 //===----------------------------------------------------------------------===//
2288 //===----------------------------------------------------------------------===//
2290 /// @brief This class represents a truncation of integer types.
2291 class TruncInst : public CastInst {
2292 /// Private copy constructor
2293 TruncInst(const TruncInst &CI)
2294 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
2297 /// @brief Constructor with insert-before-instruction semantics
2299 Value *S, ///< The value to be truncated
2300 const Type *Ty, ///< The (smaller) type to truncate to
2301 const std::string &Name = "", ///< A name for the new instruction
2302 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2305 /// @brief Constructor with insert-at-end-of-block semantics
2307 Value *S, ///< The value to be truncated
2308 const Type *Ty, ///< The (smaller) type to truncate to
2309 const std::string &Name, ///< A name for the new instruction
2310 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2313 /// @brief Clone an identical TruncInst
2314 virtual CastInst *clone() const;
2316 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2317 static inline bool classof(const TruncInst *) { return true; }
2318 static inline bool classof(const Instruction *I) {
2319 return I->getOpcode() == Trunc;
2321 static inline bool classof(const Value *V) {
2322 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2326 //===----------------------------------------------------------------------===//
2328 //===----------------------------------------------------------------------===//
2330 /// @brief This class represents zero extension of integer types.
2331 class ZExtInst : public CastInst {
2332 /// @brief Private copy constructor
2333 ZExtInst(const ZExtInst &CI)
2334 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
2337 /// @brief Constructor with insert-before-instruction semantics
2339 Value *S, ///< The value to be zero extended
2340 const Type *Ty, ///< The type to zero extend to
2341 const std::string &Name = "", ///< A name for the new instruction
2342 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2345 /// @brief Constructor with insert-at-end semantics.
2347 Value *S, ///< The value to be zero extended
2348 const Type *Ty, ///< The type to zero extend to
2349 const std::string &Name, ///< A name for the new instruction
2350 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2353 /// @brief Clone an identical ZExtInst
2354 virtual CastInst *clone() const;
2356 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2357 static inline bool classof(const ZExtInst *) { return true; }
2358 static inline bool classof(const Instruction *I) {
2359 return I->getOpcode() == ZExt;
2361 static inline bool classof(const Value *V) {
2362 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2366 //===----------------------------------------------------------------------===//
2368 //===----------------------------------------------------------------------===//
2370 /// @brief This class represents a sign extension of integer types.
2371 class SExtInst : public CastInst {
2372 /// @brief Private copy constructor
2373 SExtInst(const SExtInst &CI)
2374 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
2377 /// @brief Constructor with insert-before-instruction semantics
2379 Value *S, ///< The value to be sign extended
2380 const Type *Ty, ///< The type to sign extend to
2381 const std::string &Name = "", ///< A name for the new instruction
2382 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2385 /// @brief Constructor with insert-at-end-of-block semantics
2387 Value *S, ///< The value to be sign extended
2388 const Type *Ty, ///< The type to sign extend to
2389 const std::string &Name, ///< A name for the new instruction
2390 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2393 /// @brief Clone an identical SExtInst
2394 virtual CastInst *clone() const;
2396 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2397 static inline bool classof(const SExtInst *) { return true; }
2398 static inline bool classof(const Instruction *I) {
2399 return I->getOpcode() == SExt;
2401 static inline bool classof(const Value *V) {
2402 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2406 //===----------------------------------------------------------------------===//
2407 // FPTruncInst Class
2408 //===----------------------------------------------------------------------===//
2410 /// @brief This class represents a truncation of floating point types.
2411 class FPTruncInst : public CastInst {
2412 FPTruncInst(const FPTruncInst &CI)
2413 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2416 /// @brief Constructor with insert-before-instruction semantics
2418 Value *S, ///< The value to be truncated
2419 const Type *Ty, ///< The type to truncate to
2420 const std::string &Name = "", ///< A name for the new instruction
2421 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2424 /// @brief Constructor with insert-before-instruction semantics
2426 Value *S, ///< The value to be truncated
2427 const Type *Ty, ///< The type to truncate to
2428 const std::string &Name, ///< A name for the new instruction
2429 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2432 /// @brief Clone an identical FPTruncInst
2433 virtual CastInst *clone() const;
2435 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2436 static inline bool classof(const FPTruncInst *) { return true; }
2437 static inline bool classof(const Instruction *I) {
2438 return I->getOpcode() == FPTrunc;
2440 static inline bool classof(const Value *V) {
2441 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2445 //===----------------------------------------------------------------------===//
2447 //===----------------------------------------------------------------------===//
2449 /// @brief This class represents an extension of floating point types.
2450 class FPExtInst : public CastInst {
2451 FPExtInst(const FPExtInst &CI)
2452 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2455 /// @brief Constructor with insert-before-instruction semantics
2457 Value *S, ///< The value to be extended
2458 const Type *Ty, ///< The type to extend to
2459 const std::string &Name = "", ///< A name for the new instruction
2460 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2463 /// @brief Constructor with insert-at-end-of-block semantics
2465 Value *S, ///< The value to be extended
2466 const Type *Ty, ///< The type to extend to
2467 const std::string &Name, ///< A name for the new instruction
2468 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2471 /// @brief Clone an identical FPExtInst
2472 virtual CastInst *clone() const;
2474 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2475 static inline bool classof(const FPExtInst *) { return true; }
2476 static inline bool classof(const Instruction *I) {
2477 return I->getOpcode() == FPExt;
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 cast unsigned integer to floating point.
2489 class UIToFPInst : public CastInst {
2490 UIToFPInst(const UIToFPInst &CI)
2491 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2494 /// @brief Constructor with insert-before-instruction semantics
2496 Value *S, ///< The value to be converted
2497 const Type *Ty, ///< The type to convert to
2498 const std::string &Name = "", ///< A name for the new instruction
2499 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2502 /// @brief Constructor with insert-at-end-of-block semantics
2504 Value *S, ///< The value to be converted
2505 const Type *Ty, ///< The type to convert to
2506 const std::string &Name, ///< A name for the new instruction
2507 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2510 /// @brief Clone an identical UIToFPInst
2511 virtual CastInst *clone() const;
2513 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2514 static inline bool classof(const UIToFPInst *) { return true; }
2515 static inline bool classof(const Instruction *I) {
2516 return I->getOpcode() == UIToFP;
2518 static inline bool classof(const Value *V) {
2519 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2523 //===----------------------------------------------------------------------===//
2525 //===----------------------------------------------------------------------===//
2527 /// @brief This class represents a cast from signed integer to floating point.
2528 class SIToFPInst : public CastInst {
2529 SIToFPInst(const SIToFPInst &CI)
2530 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2533 /// @brief Constructor with insert-before-instruction semantics
2535 Value *S, ///< The value to be converted
2536 const Type *Ty, ///< The type to convert to
2537 const std::string &Name = "", ///< A name for the new instruction
2538 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2541 /// @brief Constructor with insert-at-end-of-block semantics
2543 Value *S, ///< The value to be converted
2544 const Type *Ty, ///< The type to convert to
2545 const std::string &Name, ///< A name for the new instruction
2546 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2549 /// @brief Clone an identical SIToFPInst
2550 virtual CastInst *clone() const;
2552 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2553 static inline bool classof(const SIToFPInst *) { return true; }
2554 static inline bool classof(const Instruction *I) {
2555 return I->getOpcode() == SIToFP;
2557 static inline bool classof(const Value *V) {
2558 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2562 //===----------------------------------------------------------------------===//
2564 //===----------------------------------------------------------------------===//
2566 /// @brief This class represents a cast from floating point to unsigned integer
2567 class FPToUIInst : public CastInst {
2568 FPToUIInst(const FPToUIInst &CI)
2569 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2572 /// @brief Constructor with insert-before-instruction semantics
2574 Value *S, ///< The value to be converted
2575 const Type *Ty, ///< The type to convert to
2576 const std::string &Name = "", ///< A name for the new instruction
2577 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2580 /// @brief Constructor with insert-at-end-of-block semantics
2582 Value *S, ///< The value to be converted
2583 const Type *Ty, ///< The type to convert to
2584 const std::string &Name, ///< A name for the new instruction
2585 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2588 /// @brief Clone an identical FPToUIInst
2589 virtual CastInst *clone() const;
2591 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2592 static inline bool classof(const FPToUIInst *) { return true; }
2593 static inline bool classof(const Instruction *I) {
2594 return I->getOpcode() == FPToUI;
2596 static inline bool classof(const Value *V) {
2597 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2601 //===----------------------------------------------------------------------===//
2603 //===----------------------------------------------------------------------===//
2605 /// @brief This class represents a cast from floating point to signed integer.
2606 class FPToSIInst : public CastInst {
2607 FPToSIInst(const FPToSIInst &CI)
2608 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2611 /// @brief Constructor with insert-before-instruction semantics
2613 Value *S, ///< The value to be converted
2614 const Type *Ty, ///< The type to convert to
2615 const std::string &Name = "", ///< A name for the new instruction
2616 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2619 /// @brief Constructor with insert-at-end-of-block semantics
2621 Value *S, ///< The value to be converted
2622 const Type *Ty, ///< The type to convert to
2623 const std::string &Name, ///< A name for the new instruction
2624 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2627 /// @brief Clone an identical FPToSIInst
2628 virtual CastInst *clone() const;
2630 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2631 static inline bool classof(const FPToSIInst *) { return true; }
2632 static inline bool classof(const Instruction *I) {
2633 return I->getOpcode() == FPToSI;
2635 static inline bool classof(const Value *V) {
2636 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2640 //===----------------------------------------------------------------------===//
2641 // IntToPtrInst Class
2642 //===----------------------------------------------------------------------===//
2644 /// @brief This class represents a cast from an integer to a pointer.
2645 class IntToPtrInst : public CastInst {
2646 IntToPtrInst(const IntToPtrInst &CI)
2647 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2650 /// @brief Constructor with insert-before-instruction semantics
2652 Value *S, ///< The value to be converted
2653 const Type *Ty, ///< The type to convert to
2654 const std::string &Name = "", ///< A name for the new instruction
2655 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2658 /// @brief Constructor with insert-at-end-of-block semantics
2660 Value *S, ///< The value to be converted
2661 const Type *Ty, ///< The type to convert to
2662 const std::string &Name, ///< A name for the new instruction
2663 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2666 /// @brief Clone an identical IntToPtrInst
2667 virtual CastInst *clone() const;
2669 // Methods for support type inquiry through isa, cast, and dyn_cast:
2670 static inline bool classof(const IntToPtrInst *) { return true; }
2671 static inline bool classof(const Instruction *I) {
2672 return I->getOpcode() == IntToPtr;
2674 static inline bool classof(const Value *V) {
2675 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2679 //===----------------------------------------------------------------------===//
2680 // PtrToIntInst Class
2681 //===----------------------------------------------------------------------===//
2683 /// @brief This class represents a cast from a pointer to an integer
2684 class PtrToIntInst : public CastInst {
2685 PtrToIntInst(const PtrToIntInst &CI)
2686 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2689 /// @brief Constructor with insert-before-instruction semantics
2691 Value *S, ///< The value to be converted
2692 const Type *Ty, ///< The type to convert to
2693 const std::string &Name = "", ///< A name for the new instruction
2694 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2697 /// @brief Constructor with insert-at-end-of-block semantics
2699 Value *S, ///< The value to be converted
2700 const Type *Ty, ///< The type to convert to
2701 const std::string &Name, ///< A name for the new instruction
2702 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2705 /// @brief Clone an identical PtrToIntInst
2706 virtual CastInst *clone() const;
2708 // Methods for support type inquiry through isa, cast, and dyn_cast:
2709 static inline bool classof(const PtrToIntInst *) { return true; }
2710 static inline bool classof(const Instruction *I) {
2711 return I->getOpcode() == PtrToInt;
2713 static inline bool classof(const Value *V) {
2714 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2718 //===----------------------------------------------------------------------===//
2719 // BitCastInst Class
2720 //===----------------------------------------------------------------------===//
2722 /// @brief This class represents a no-op cast from one type to another.
2723 class BitCastInst : public CastInst {
2724 BitCastInst(const BitCastInst &CI)
2725 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2728 /// @brief Constructor with insert-before-instruction semantics
2730 Value *S, ///< The value to be casted
2731 const Type *Ty, ///< The type to casted to
2732 const std::string &Name = "", ///< A name for the new instruction
2733 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2736 /// @brief Constructor with insert-at-end-of-block semantics
2738 Value *S, ///< The value to be casted
2739 const Type *Ty, ///< The type to casted to
2740 const std::string &Name, ///< A name for the new instruction
2741 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2744 /// @brief Clone an identical BitCastInst
2745 virtual CastInst *clone() const;
2747 // Methods for support type inquiry through isa, cast, and dyn_cast:
2748 static inline bool classof(const BitCastInst *) { return true; }
2749 static inline bool classof(const Instruction *I) {
2750 return I->getOpcode() == BitCast;
2752 static inline bool classof(const Value *V) {
2753 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2757 //===----------------------------------------------------------------------===//
2758 // GetResultInst Class
2759 //===----------------------------------------------------------------------===//
2761 /// GetResultInst - This instruction extracts individual result value from
2762 /// aggregate value, where aggregate value is returned by CallInst.
2764 class GetResultInst : public UnaryInstruction {
2766 GetResultInst(const GetResultInst &GRI) :
2767 UnaryInstruction(GRI.getType(), Instruction::GetResult, GRI.getOperand(0)),
2772 GetResultInst(Value *Aggr, unsigned index,
2773 const std::string &Name = "",
2774 Instruction *InsertBefore = 0);
2776 /// isValidOperands - Return true if an getresult instruction can be
2777 /// formed with the specified operands.
2778 static bool isValidOperands(const Value *Aggr, unsigned index);
2780 virtual GetResultInst *clone() const;
2782 Value *getAggregateValue() {
2783 return getOperand(0);
2786 const Value *getAggregateValue() const {
2787 return getOperand(0);
2790 unsigned getIndex() const {
2794 // Methods for support type inquiry through isa, cast, and dyn_cast:
2795 static inline bool classof(const GetResultInst *) { return true; }
2796 static inline bool classof(const Instruction *I) {
2797 return (I->getOpcode() == Instruction::GetResult);
2799 static inline bool classof(const Value *V) {
2800 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2804 } // End llvm namespace