1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
19 #include "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/ADT/SmallVector.h"
33 //===----------------------------------------------------------------------===//
35 //===----------------------------------------------------------------------===//
37 /// AllocaInst - an instruction to allocate memory on the stack
39 class AllocaInst : public UnaryInstruction {
41 virtual AllocaInst *clone_impl() const;
43 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
44 const Twine &Name = "", Instruction *InsertBefore = 0);
45 AllocaInst(const Type *Ty, Value *ArraySize,
46 const Twine &Name, BasicBlock *InsertAtEnd);
48 AllocaInst(const Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
49 AllocaInst(const Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
51 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
52 const Twine &Name = "", Instruction *InsertBefore = 0);
53 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
54 const Twine &Name, BasicBlock *InsertAtEnd);
56 // Out of line virtual method, so the vtable, etc. has a home.
57 virtual ~AllocaInst();
59 /// isArrayAllocation - Return true if there is an allocation size parameter
60 /// to the allocation instruction that is not 1.
62 bool isArrayAllocation() const;
64 /// getArraySize - Get the number of elements allocated. For a simple
65 /// allocation of a single element, this will return a constant 1 value.
67 const Value *getArraySize() const { return getOperand(0); }
68 Value *getArraySize() { return getOperand(0); }
70 /// getType - Overload to return most specific pointer type
72 const PointerType *getType() const {
73 return reinterpret_cast<const PointerType*>(Instruction::getType());
76 /// getAllocatedType - Return the type that is being allocated by the
79 const Type *getAllocatedType() const;
81 /// getAlignment - Return the alignment of the memory that is being allocated
82 /// by the instruction.
84 unsigned getAlignment() const {
85 return (1u << getSubclassDataFromInstruction()) >> 1;
87 void setAlignment(unsigned Align);
89 /// isStaticAlloca - Return true if this alloca is in the entry block of the
90 /// function and is a constant size. If so, the code generator will fold it
91 /// into the prolog/epilog code, so it is basically free.
92 bool isStaticAlloca() const;
94 // Methods for support type inquiry through isa, cast, and dyn_cast:
95 static inline bool classof(const AllocaInst *) { return true; }
96 static inline bool classof(const Instruction *I) {
97 return (I->getOpcode() == Instruction::Alloca);
99 static inline bool classof(const Value *V) {
100 return isa<Instruction>(V) && classof(cast<Instruction>(V));
103 // Shadow Instruction::setInstructionSubclassData with a private forwarding
104 // method so that subclasses cannot accidentally use it.
105 void setInstructionSubclassData(unsigned short D) {
106 Instruction::setInstructionSubclassData(D);
111 //===----------------------------------------------------------------------===//
113 //===----------------------------------------------------------------------===//
115 /// LoadInst - an instruction for reading from memory. This uses the
116 /// SubclassData field in Value to store whether or not the load is volatile.
118 class LoadInst : public UnaryInstruction {
121 virtual LoadInst *clone_impl() const;
123 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
124 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
125 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
126 Instruction *InsertBefore = 0);
127 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
128 unsigned Align, Instruction *InsertBefore = 0);
129 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
130 BasicBlock *InsertAtEnd);
131 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
132 unsigned Align, BasicBlock *InsertAtEnd);
134 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
135 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
136 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
137 bool isVolatile = false, Instruction *InsertBefore = 0);
138 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
139 BasicBlock *InsertAtEnd);
141 /// isVolatile - Return true if this is a load from a volatile memory
144 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
146 /// setVolatile - Specify whether this is a volatile load or not.
148 void setVolatile(bool V) {
149 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
153 /// getAlignment - Return the alignment of the access that is being performed
155 unsigned getAlignment() const {
156 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
159 void setAlignment(unsigned Align);
161 Value *getPointerOperand() { return getOperand(0); }
162 const Value *getPointerOperand() const { return getOperand(0); }
163 static unsigned getPointerOperandIndex() { return 0U; }
165 unsigned getPointerAddressSpace() const {
166 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
170 // Methods for support type inquiry through isa, cast, and dyn_cast:
171 static inline bool classof(const LoadInst *) { return true; }
172 static inline bool classof(const Instruction *I) {
173 return I->getOpcode() == Instruction::Load;
175 static inline bool classof(const Value *V) {
176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
179 // Shadow Instruction::setInstructionSubclassData with a private forwarding
180 // method so that subclasses cannot accidentally use it.
181 void setInstructionSubclassData(unsigned short D) {
182 Instruction::setInstructionSubclassData(D);
187 //===----------------------------------------------------------------------===//
189 //===----------------------------------------------------------------------===//
191 /// StoreInst - an instruction for storing to memory
193 class StoreInst : public Instruction {
194 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
197 virtual StoreInst *clone_impl() const;
199 // allocate space for exactly two operands
200 void *operator new(size_t s) {
201 return User::operator new(s, 2);
203 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
204 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
205 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
206 Instruction *InsertBefore = 0);
207 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
208 unsigned Align, Instruction *InsertBefore = 0);
209 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
210 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
211 unsigned Align, BasicBlock *InsertAtEnd);
214 /// isVolatile - Return true if this is a load from a volatile memory
217 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
219 /// setVolatile - Specify whether this is a volatile load or not.
221 void setVolatile(bool V) {
222 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
226 /// Transparently provide more efficient getOperand methods.
227 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
229 /// getAlignment - Return the alignment of the access that is being performed
231 unsigned getAlignment() const {
232 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
235 void setAlignment(unsigned Align);
237 Value *getValueOperand() { return getOperand(0); }
238 const Value *getValueOperand() const { return getOperand(0); }
240 Value *getPointerOperand() { return getOperand(1); }
241 const Value *getPointerOperand() const { return getOperand(1); }
242 static unsigned getPointerOperandIndex() { return 1U; }
244 unsigned getPointerAddressSpace() const {
245 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
248 // Methods for support type inquiry through isa, cast, and dyn_cast:
249 static inline bool classof(const StoreInst *) { return true; }
250 static inline bool classof(const Instruction *I) {
251 return I->getOpcode() == Instruction::Store;
253 static inline bool classof(const Value *V) {
254 return isa<Instruction>(V) && classof(cast<Instruction>(V));
257 // Shadow Instruction::setInstructionSubclassData with a private forwarding
258 // method so that subclasses cannot accidentally use it.
259 void setInstructionSubclassData(unsigned short D) {
260 Instruction::setInstructionSubclassData(D);
265 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
268 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
270 //===----------------------------------------------------------------------===//
271 // GetElementPtrInst Class
272 //===----------------------------------------------------------------------===//
274 // checkType - Simple wrapper function to give a better assertion failure
275 // message on bad indexes for a gep instruction.
277 static inline const Type *checkType(const Type *Ty) {
278 assert(Ty && "Invalid GetElementPtrInst indices for type!");
282 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
283 /// access elements of arrays and structs
285 class GetElementPtrInst : public Instruction {
286 GetElementPtrInst(const GetElementPtrInst &GEPI);
287 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
288 const Twine &NameStr);
289 void init(Value *Ptr, Value *Idx, const Twine &NameStr);
291 template<typename RandomAccessIterator>
292 void init(Value *Ptr,
293 RandomAccessIterator IdxBegin,
294 RandomAccessIterator IdxEnd,
295 const Twine &NameStr,
296 // This argument ensures that we have an iterator we can
297 // do arithmetic on in constant time
298 std::random_access_iterator_tag) {
299 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
302 // This requires that the iterator points to contiguous memory.
303 init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
304 // we have to build an array here
307 init(Ptr, 0, NumIdx, NameStr);
311 /// getIndexedType - Returns the type of the element that would be loaded with
312 /// a load instruction with the specified parameters.
314 /// Null is returned if the indices are invalid for the specified
317 template<typename RandomAccessIterator>
318 static const Type *getIndexedType(const Type *Ptr,
319 RandomAccessIterator IdxBegin,
320 RandomAccessIterator IdxEnd,
321 // This argument ensures that we
322 // have an iterator we can do
323 // arithmetic on in constant time
324 std::random_access_iterator_tag) {
325 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
328 // This requires that the iterator points to contiguous memory.
329 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
331 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
334 /// Constructors - Create a getelementptr instruction with a base pointer an
335 /// list of indices. The first ctor can optionally insert before an existing
336 /// instruction, the second appends the new instruction to the specified
338 template<typename RandomAccessIterator>
339 inline GetElementPtrInst(Value *Ptr, RandomAccessIterator IdxBegin,
340 RandomAccessIterator IdxEnd,
342 const Twine &NameStr,
343 Instruction *InsertBefore);
344 template<typename RandomAccessIterator>
345 inline GetElementPtrInst(Value *Ptr,
346 RandomAccessIterator IdxBegin,
347 RandomAccessIterator IdxEnd,
349 const Twine &NameStr, BasicBlock *InsertAtEnd);
351 /// Constructors - These two constructors are convenience methods because one
352 /// and two index getelementptr instructions are so common.
353 GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
354 Instruction *InsertBefore = 0);
355 GetElementPtrInst(Value *Ptr, Value *Idx,
356 const Twine &NameStr, BasicBlock *InsertAtEnd);
358 virtual GetElementPtrInst *clone_impl() const;
360 template<typename RandomAccessIterator>
361 static GetElementPtrInst *Create(Value *Ptr, RandomAccessIterator IdxBegin,
362 RandomAccessIterator IdxEnd,
363 const Twine &NameStr = "",
364 Instruction *InsertBefore = 0) {
365 typename std::iterator_traits<RandomAccessIterator>::difference_type
366 Values = 1 + std::distance(IdxBegin, IdxEnd);
368 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
370 template<typename RandomAccessIterator>
371 static GetElementPtrInst *Create(Value *Ptr,
372 RandomAccessIterator IdxBegin,
373 RandomAccessIterator IdxEnd,
374 const Twine &NameStr,
375 BasicBlock *InsertAtEnd) {
376 typename std::iterator_traits<RandomAccessIterator>::difference_type
377 Values = 1 + std::distance(IdxBegin, IdxEnd);
379 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
382 /// Constructors - These two creators are convenience methods because one
383 /// index getelementptr instructions are so common.
384 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
385 const Twine &NameStr = "",
386 Instruction *InsertBefore = 0) {
387 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
389 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
390 const Twine &NameStr,
391 BasicBlock *InsertAtEnd) {
392 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
395 /// Create an "inbounds" getelementptr. See the documentation for the
396 /// "inbounds" flag in LangRef.html for details.
397 template<typename RandomAccessIterator>
398 static GetElementPtrInst *CreateInBounds(Value *Ptr,
399 RandomAccessIterator IdxBegin,
400 RandomAccessIterator IdxEnd,
401 const Twine &NameStr = "",
402 Instruction *InsertBefore = 0) {
403 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
404 NameStr, InsertBefore);
405 GEP->setIsInBounds(true);
408 template<typename RandomAccessIterator>
409 static GetElementPtrInst *CreateInBounds(Value *Ptr,
410 RandomAccessIterator IdxBegin,
411 RandomAccessIterator IdxEnd,
412 const Twine &NameStr,
413 BasicBlock *InsertAtEnd) {
414 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
415 NameStr, InsertAtEnd);
416 GEP->setIsInBounds(true);
419 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
420 const Twine &NameStr = "",
421 Instruction *InsertBefore = 0) {
422 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
423 GEP->setIsInBounds(true);
426 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
427 const Twine &NameStr,
428 BasicBlock *InsertAtEnd) {
429 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
430 GEP->setIsInBounds(true);
434 /// Transparently provide more efficient getOperand methods.
435 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
437 // getType - Overload to return most specific pointer type...
438 const PointerType *getType() const {
439 return reinterpret_cast<const PointerType*>(Instruction::getType());
442 /// getIndexedType - Returns the type of the element that would be loaded with
443 /// a load instruction with the specified parameters.
445 /// Null is returned if the indices are invalid for the specified
448 template<typename RandomAccessIterator>
449 static const Type *getIndexedType(const Type *Ptr,
450 RandomAccessIterator IdxBegin,
451 RandomAccessIterator IdxEnd) {
452 return getIndexedType(Ptr, IdxBegin, IdxEnd,
453 typename std::iterator_traits<RandomAccessIterator>::
454 iterator_category());
457 static const Type *getIndexedType(const Type *Ptr,
458 Value* const *Idx, unsigned NumIdx);
460 static const Type *getIndexedType(const Type *Ptr,
461 uint64_t const *Idx, unsigned NumIdx);
463 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
465 inline op_iterator idx_begin() { return op_begin()+1; }
466 inline const_op_iterator idx_begin() const { return op_begin()+1; }
467 inline op_iterator idx_end() { return op_end(); }
468 inline const_op_iterator idx_end() const { return op_end(); }
470 Value *getPointerOperand() {
471 return getOperand(0);
473 const Value *getPointerOperand() const {
474 return getOperand(0);
476 static unsigned getPointerOperandIndex() {
477 return 0U; // get index for modifying correct operand
480 unsigned getPointerAddressSpace() const {
481 return cast<PointerType>(getType())->getAddressSpace();
484 /// getPointerOperandType - Method to return the pointer operand as a
486 const PointerType *getPointerOperandType() const {
487 return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
491 unsigned getNumIndices() const { // Note: always non-negative
492 return getNumOperands() - 1;
495 bool hasIndices() const {
496 return getNumOperands() > 1;
499 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
500 /// zeros. If so, the result pointer and the first operand have the same
501 /// value, just potentially different types.
502 bool hasAllZeroIndices() const;
504 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
505 /// constant integers. If so, the result pointer and the first operand have
506 /// a constant offset between them.
507 bool hasAllConstantIndices() const;
509 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
510 /// See LangRef.html for the meaning of inbounds on a getelementptr.
511 void setIsInBounds(bool b = true);
513 /// isInBounds - Determine whether the GEP has the inbounds flag.
514 bool isInBounds() const;
516 // Methods for support type inquiry through isa, cast, and dyn_cast:
517 static inline bool classof(const GetElementPtrInst *) { return true; }
518 static inline bool classof(const Instruction *I) {
519 return (I->getOpcode() == Instruction::GetElementPtr);
521 static inline bool classof(const Value *V) {
522 return isa<Instruction>(V) && classof(cast<Instruction>(V));
527 struct OperandTraits<GetElementPtrInst> :
528 public VariadicOperandTraits<GetElementPtrInst, 1> {
531 template<typename RandomAccessIterator>
532 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
533 RandomAccessIterator IdxBegin,
534 RandomAccessIterator IdxEnd,
536 const Twine &NameStr,
537 Instruction *InsertBefore)
538 : Instruction(PointerType::get(checkType(
539 getIndexedType(Ptr->getType(),
541 cast<PointerType>(Ptr->getType())
542 ->getAddressSpace()),
544 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
545 Values, InsertBefore) {
546 init(Ptr, IdxBegin, IdxEnd, NameStr,
547 typename std::iterator_traits<RandomAccessIterator>
548 ::iterator_category());
550 template<typename RandomAccessIterator>
551 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
552 RandomAccessIterator IdxBegin,
553 RandomAccessIterator IdxEnd,
555 const Twine &NameStr,
556 BasicBlock *InsertAtEnd)
557 : Instruction(PointerType::get(checkType(
558 getIndexedType(Ptr->getType(),
560 cast<PointerType>(Ptr->getType())
561 ->getAddressSpace()),
563 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
564 Values, InsertAtEnd) {
565 init(Ptr, IdxBegin, IdxEnd, NameStr,
566 typename std::iterator_traits<RandomAccessIterator>
567 ::iterator_category());
571 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
574 //===----------------------------------------------------------------------===//
576 //===----------------------------------------------------------------------===//
578 /// This instruction compares its operands according to the predicate given
579 /// to the constructor. It only operates on integers or pointers. The operands
580 /// must be identical types.
581 /// @brief Represent an integer comparison operator.
582 class ICmpInst: public CmpInst {
584 /// @brief Clone an indentical ICmpInst
585 virtual ICmpInst *clone_impl() const;
587 /// @brief Constructor with insert-before-instruction semantics.
589 Instruction *InsertBefore, ///< Where to insert
590 Predicate pred, ///< The predicate to use for the comparison
591 Value *LHS, ///< The left-hand-side of the expression
592 Value *RHS, ///< The right-hand-side of the expression
593 const Twine &NameStr = "" ///< Name of the instruction
594 ) : CmpInst(makeCmpResultType(LHS->getType()),
595 Instruction::ICmp, pred, LHS, RHS, NameStr,
597 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
598 pred <= CmpInst::LAST_ICMP_PREDICATE &&
599 "Invalid ICmp predicate value");
600 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
601 "Both operands to ICmp instruction are not of the same type!");
602 // Check that the operands are the right type
603 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
604 getOperand(0)->getType()->isPointerTy()) &&
605 "Invalid operand types for ICmp instruction");
608 /// @brief Constructor with insert-at-end semantics.
610 BasicBlock &InsertAtEnd, ///< Block to insert into.
611 Predicate pred, ///< The predicate to use for the comparison
612 Value *LHS, ///< The left-hand-side of the expression
613 Value *RHS, ///< The right-hand-side of the expression
614 const Twine &NameStr = "" ///< Name of the instruction
615 ) : CmpInst(makeCmpResultType(LHS->getType()),
616 Instruction::ICmp, pred, LHS, RHS, NameStr,
618 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
619 pred <= CmpInst::LAST_ICMP_PREDICATE &&
620 "Invalid ICmp predicate value");
621 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
622 "Both operands to ICmp instruction are not of the same type!");
623 // Check that the operands are the right type
624 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
625 getOperand(0)->getType()->isPointerTy()) &&
626 "Invalid operand types for ICmp instruction");
629 /// @brief Constructor with no-insertion semantics
631 Predicate pred, ///< The predicate to use for the comparison
632 Value *LHS, ///< The left-hand-side of the expression
633 Value *RHS, ///< The right-hand-side of the expression
634 const Twine &NameStr = "" ///< Name of the instruction
635 ) : CmpInst(makeCmpResultType(LHS->getType()),
636 Instruction::ICmp, pred, LHS, RHS, NameStr) {
637 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
638 pred <= CmpInst::LAST_ICMP_PREDICATE &&
639 "Invalid ICmp predicate value");
640 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
641 "Both operands to ICmp instruction are not of the same type!");
642 // Check that the operands are the right type
643 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
644 getOperand(0)->getType()->isPointerTy()) &&
645 "Invalid operand types for ICmp instruction");
648 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
649 /// @returns the predicate that would be the result if the operand were
650 /// regarded as signed.
651 /// @brief Return the signed version of the predicate
652 Predicate getSignedPredicate() const {
653 return getSignedPredicate(getPredicate());
656 /// This is a static version that you can use without an instruction.
657 /// @brief Return the signed version of the predicate.
658 static Predicate getSignedPredicate(Predicate pred);
660 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
661 /// @returns the predicate that would be the result if the operand were
662 /// regarded as unsigned.
663 /// @brief Return the unsigned version of the predicate
664 Predicate getUnsignedPredicate() const {
665 return getUnsignedPredicate(getPredicate());
668 /// This is a static version that you can use without an instruction.
669 /// @brief Return the unsigned version of the predicate.
670 static Predicate getUnsignedPredicate(Predicate pred);
672 /// isEquality - Return true if this predicate is either EQ or NE. This also
673 /// tests for commutativity.
674 static bool isEquality(Predicate P) {
675 return P == ICMP_EQ || P == ICMP_NE;
678 /// isEquality - Return true if this predicate is either EQ or NE. This also
679 /// tests for commutativity.
680 bool isEquality() const {
681 return isEquality(getPredicate());
684 /// @returns true if the predicate of this ICmpInst is commutative
685 /// @brief Determine if this relation is commutative.
686 bool isCommutative() const { return isEquality(); }
688 /// isRelational - Return true if the predicate is relational (not EQ or NE).
690 bool isRelational() const {
691 return !isEquality();
694 /// isRelational - Return true if the predicate is relational (not EQ or NE).
696 static bool isRelational(Predicate P) {
697 return !isEquality(P);
700 /// Initialize a set of values that all satisfy the predicate with C.
701 /// @brief Make a ConstantRange for a relation with a constant value.
702 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
704 /// Exchange the two operands to this instruction in such a way that it does
705 /// not modify the semantics of the instruction. The predicate value may be
706 /// changed to retain the same result if the predicate is order dependent
708 /// @brief Swap operands and adjust predicate.
709 void swapOperands() {
710 setPredicate(getSwappedPredicate());
711 Op<0>().swap(Op<1>());
714 // Methods for support type inquiry through isa, cast, and dyn_cast:
715 static inline bool classof(const ICmpInst *) { return true; }
716 static inline bool classof(const Instruction *I) {
717 return I->getOpcode() == Instruction::ICmp;
719 static inline bool classof(const Value *V) {
720 return isa<Instruction>(V) && classof(cast<Instruction>(V));
725 //===----------------------------------------------------------------------===//
727 //===----------------------------------------------------------------------===//
729 /// This instruction compares its operands according to the predicate given
730 /// to the constructor. It only operates on floating point values or packed
731 /// vectors of floating point values. The operands must be identical types.
732 /// @brief Represents a floating point comparison operator.
733 class FCmpInst: public CmpInst {
735 /// @brief Clone an indentical FCmpInst
736 virtual FCmpInst *clone_impl() const;
738 /// @brief Constructor with insert-before-instruction semantics.
740 Instruction *InsertBefore, ///< Where to insert
741 Predicate pred, ///< The predicate to use for the comparison
742 Value *LHS, ///< The left-hand-side of the expression
743 Value *RHS, ///< The right-hand-side of the expression
744 const Twine &NameStr = "" ///< Name of the instruction
745 ) : CmpInst(makeCmpResultType(LHS->getType()),
746 Instruction::FCmp, pred, LHS, RHS, NameStr,
748 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
749 "Invalid FCmp predicate value");
750 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
751 "Both operands to FCmp instruction are not of the same type!");
752 // Check that the operands are the right type
753 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
754 "Invalid operand types for FCmp instruction");
757 /// @brief Constructor with insert-at-end semantics.
759 BasicBlock &InsertAtEnd, ///< Block to insert into.
760 Predicate pred, ///< The predicate to use for the comparison
761 Value *LHS, ///< The left-hand-side of the expression
762 Value *RHS, ///< The right-hand-side of the expression
763 const Twine &NameStr = "" ///< Name of the instruction
764 ) : CmpInst(makeCmpResultType(LHS->getType()),
765 Instruction::FCmp, pred, LHS, RHS, NameStr,
767 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
768 "Invalid FCmp predicate value");
769 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
770 "Both operands to FCmp instruction are not of the same type!");
771 // Check that the operands are the right type
772 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
773 "Invalid operand types for FCmp instruction");
776 /// @brief Constructor with no-insertion semantics
778 Predicate pred, ///< The predicate to use for the comparison
779 Value *LHS, ///< The left-hand-side of the expression
780 Value *RHS, ///< The right-hand-side of the expression
781 const Twine &NameStr = "" ///< Name of the instruction
782 ) : CmpInst(makeCmpResultType(LHS->getType()),
783 Instruction::FCmp, pred, LHS, RHS, NameStr) {
784 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
785 "Invalid FCmp predicate value");
786 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
787 "Both operands to FCmp instruction are not of the same type!");
788 // Check that the operands are the right type
789 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
790 "Invalid operand types for FCmp instruction");
793 /// @returns true if the predicate of this instruction is EQ or NE.
794 /// @brief Determine if this is an equality predicate.
795 bool isEquality() const {
796 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
797 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
800 /// @returns true if the predicate of this instruction is commutative.
801 /// @brief Determine if this is a commutative predicate.
802 bool isCommutative() const {
803 return isEquality() ||
804 getPredicate() == FCMP_FALSE ||
805 getPredicate() == FCMP_TRUE ||
806 getPredicate() == FCMP_ORD ||
807 getPredicate() == FCMP_UNO;
810 /// @returns true if the predicate is relational (not EQ or NE).
811 /// @brief Determine if this a relational predicate.
812 bool isRelational() const { return !isEquality(); }
814 /// Exchange the two operands to this instruction in such a way that it does
815 /// not modify the semantics of the instruction. The predicate value may be
816 /// changed to retain the same result if the predicate is order dependent
818 /// @brief Swap operands and adjust predicate.
819 void swapOperands() {
820 setPredicate(getSwappedPredicate());
821 Op<0>().swap(Op<1>());
824 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
825 static inline bool classof(const FCmpInst *) { return true; }
826 static inline bool classof(const Instruction *I) {
827 return I->getOpcode() == Instruction::FCmp;
829 static inline bool classof(const Value *V) {
830 return isa<Instruction>(V) && classof(cast<Instruction>(V));
834 //===----------------------------------------------------------------------===//
835 /// CallInst - This class represents a function call, abstracting a target
836 /// machine's calling convention. This class uses low bit of the SubClassData
837 /// field to indicate whether or not this is a tail call. The rest of the bits
838 /// hold the calling convention of the call.
840 class CallInst : public Instruction {
841 AttrListPtr AttributeList; ///< parameter attributes for call
842 CallInst(const CallInst &CI);
843 void init(Value *Func, Value* const *Params, unsigned NumParams);
844 void init(Value *Func, Value *Actual1, Value *Actual2);
845 void init(Value *Func, Value *Actual);
846 void init(Value *Func);
848 template<typename RandomAccessIterator>
849 void init(Value *Func,
850 RandomAccessIterator ArgBegin,
851 RandomAccessIterator ArgEnd,
852 const Twine &NameStr,
853 // This argument ensures that we have an iterator we can
854 // do arithmetic on in constant time
855 std::random_access_iterator_tag) {
856 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
858 // This requires that the iterator points to contiguous memory.
859 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
863 /// Construct a CallInst given a range of arguments. RandomAccessIterator
864 /// must be a random-access iterator pointing to contiguous storage
865 /// (e.g. a std::vector<>::iterator). Checks are made for
866 /// random-accessness but not for contiguous storage as that would
867 /// incur runtime overhead.
868 /// @brief Construct a CallInst from a range of arguments
869 template<typename RandomAccessIterator>
870 CallInst(Value *Func,
871 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
872 const Twine &NameStr, Instruction *InsertBefore);
874 /// Construct a CallInst given a range of arguments. RandomAccessIterator
875 /// must be a random-access iterator pointing to contiguous storage
876 /// (e.g. a std::vector<>::iterator). Checks are made for
877 /// random-accessness but not for contiguous storage as that would
878 /// incur runtime overhead.
879 /// @brief Construct a CallInst from a range of arguments
880 template<typename RandomAccessIterator>
881 inline CallInst(Value *Func,
882 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
883 const Twine &NameStr, BasicBlock *InsertAtEnd);
885 CallInst(Value *F, Value *Actual, const Twine &NameStr,
886 Instruction *InsertBefore);
887 CallInst(Value *F, Value *Actual, const Twine &NameStr,
888 BasicBlock *InsertAtEnd);
889 explicit CallInst(Value *F, const Twine &NameStr,
890 Instruction *InsertBefore);
891 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
893 virtual CallInst *clone_impl() const;
895 template<typename RandomAccessIterator>
896 static CallInst *Create(Value *Func,
897 RandomAccessIterator ArgBegin,
898 RandomAccessIterator ArgEnd,
899 const Twine &NameStr = "",
900 Instruction *InsertBefore = 0) {
901 return new(unsigned(ArgEnd - ArgBegin + 1))
902 CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore);
904 template<typename RandomAccessIterator>
905 static CallInst *Create(Value *Func,
906 RandomAccessIterator ArgBegin,
907 RandomAccessIterator ArgEnd,
908 const Twine &NameStr, BasicBlock *InsertAtEnd) {
909 return new(unsigned(ArgEnd - ArgBegin + 1))
910 CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd);
912 static CallInst *Create(Value *F, Value *Actual,
913 const Twine &NameStr = "",
914 Instruction *InsertBefore = 0) {
915 return new(2) CallInst(F, Actual, NameStr, InsertBefore);
917 static CallInst *Create(Value *F, Value *Actual, const Twine &NameStr,
918 BasicBlock *InsertAtEnd) {
919 return new(2) CallInst(F, Actual, NameStr, InsertAtEnd);
921 static CallInst *Create(Value *F, const Twine &NameStr = "",
922 Instruction *InsertBefore = 0) {
923 return new(1) CallInst(F, NameStr, InsertBefore);
925 static CallInst *Create(Value *F, const Twine &NameStr,
926 BasicBlock *InsertAtEnd) {
927 return new(1) CallInst(F, NameStr, InsertAtEnd);
929 /// CreateMalloc - Generate the IR for a call to malloc:
930 /// 1. Compute the malloc call's argument as the specified type's size,
931 /// possibly multiplied by the array size if the array size is not
933 /// 2. Call malloc with that argument.
934 /// 3. Bitcast the result of the malloc call to the specified type.
935 static Instruction *CreateMalloc(Instruction *InsertBefore,
936 const Type *IntPtrTy, const Type *AllocTy,
937 Value *AllocSize, Value *ArraySize = 0,
938 Function* MallocF = 0,
939 const Twine &Name = "");
940 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
941 const Type *IntPtrTy, const Type *AllocTy,
942 Value *AllocSize, Value *ArraySize = 0,
943 Function* MallocF = 0,
944 const Twine &Name = "");
945 /// CreateFree - Generate the IR for a call to the builtin free function.
946 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
947 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
951 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
952 void setTailCall(bool isTC = true) {
953 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
957 /// Provide fast operand accessors
958 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
960 /// getNumArgOperands - Return the number of call arguments.
962 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
964 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
966 Value *getArgOperand(unsigned i) const { return getOperand(i); }
967 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
969 /// getCallingConv/setCallingConv - Get or set the calling convention of this
971 CallingConv::ID getCallingConv() const {
972 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
974 void setCallingConv(CallingConv::ID CC) {
975 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
976 (static_cast<unsigned>(CC) << 1));
979 /// getAttributes - Return the parameter attributes for this call.
981 const AttrListPtr &getAttributes() const { return AttributeList; }
983 /// setAttributes - Set the parameter attributes for this call.
985 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
987 /// addAttribute - adds the attribute to the list of attributes.
988 void addAttribute(unsigned i, Attributes attr);
990 /// removeAttribute - removes the attribute from the list of attributes.
991 void removeAttribute(unsigned i, Attributes attr);
993 /// @brief Determine whether the call or the callee has the given attribute.
994 bool paramHasAttr(unsigned i, Attributes attr) const;
996 /// @brief Extract the alignment for a call or parameter (0=unknown).
997 unsigned getParamAlignment(unsigned i) const {
998 return AttributeList.getParamAlignment(i);
1001 /// @brief Return true if the call should not be inlined.
1002 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
1003 void setIsNoInline(bool Value = true) {
1004 if (Value) addAttribute(~0, Attribute::NoInline);
1005 else removeAttribute(~0, Attribute::NoInline);
1008 /// @brief Determine if the call does not access memory.
1009 bool doesNotAccessMemory() const {
1010 return paramHasAttr(~0, Attribute::ReadNone);
1012 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1013 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1014 else removeAttribute(~0, Attribute::ReadNone);
1017 /// @brief Determine if the call does not access or only reads memory.
1018 bool onlyReadsMemory() const {
1019 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1021 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1022 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1023 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1026 /// @brief Determine if the call cannot return.
1027 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
1028 void setDoesNotReturn(bool DoesNotReturn = true) {
1029 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1030 else removeAttribute(~0, Attribute::NoReturn);
1033 /// @brief Determine if the call cannot unwind.
1034 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
1035 void setDoesNotThrow(bool DoesNotThrow = true) {
1036 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1037 else removeAttribute(~0, Attribute::NoUnwind);
1040 /// @brief Determine if the call returns a structure through first
1041 /// pointer argument.
1042 bool hasStructRetAttr() const {
1043 // Be friendly and also check the callee.
1044 return paramHasAttr(1, Attribute::StructRet);
1047 /// @brief Determine if any call argument is an aggregate passed by value.
1048 bool hasByValArgument() const {
1049 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1052 /// getCalledFunction - Return the function called, or null if this is an
1053 /// indirect function invocation.
1055 Function *getCalledFunction() const {
1056 return dyn_cast<Function>(Op<-1>());
1059 /// getCalledValue - Get a pointer to the function that is invoked by this
1061 const Value *getCalledValue() const { return Op<-1>(); }
1062 Value *getCalledValue() { return Op<-1>(); }
1064 /// setCalledFunction - Set the function called.
1065 void setCalledFunction(Value* Fn) {
1069 /// isInlineAsm - Check if this call is an inline asm statement.
1070 bool isInlineAsm() const {
1071 return isa<InlineAsm>(Op<-1>());
1074 // Methods for support type inquiry through isa, cast, and dyn_cast:
1075 static inline bool classof(const CallInst *) { return true; }
1076 static inline bool classof(const Instruction *I) {
1077 return I->getOpcode() == Instruction::Call;
1079 static inline bool classof(const Value *V) {
1080 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1083 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1084 // method so that subclasses cannot accidentally use it.
1085 void setInstructionSubclassData(unsigned short D) {
1086 Instruction::setInstructionSubclassData(D);
1091 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1094 template<typename RandomAccessIterator>
1095 CallInst::CallInst(Value *Func,
1096 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
1097 const Twine &NameStr, BasicBlock *InsertAtEnd)
1098 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1099 ->getElementType())->getReturnType(),
1101 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1102 unsigned(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1103 init(Func, ArgBegin, ArgEnd, NameStr,
1104 typename std::iterator_traits<RandomAccessIterator>
1105 ::iterator_category());
1108 template<typename RandomAccessIterator>
1109 CallInst::CallInst(Value *Func,
1110 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
1111 const Twine &NameStr, Instruction *InsertBefore)
1112 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1113 ->getElementType())->getReturnType(),
1115 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1116 unsigned(ArgEnd - ArgBegin + 1), InsertBefore) {
1117 init(Func, ArgBegin, ArgEnd, NameStr,
1118 typename std::iterator_traits<RandomAccessIterator>
1119 ::iterator_category());
1123 // Note: if you get compile errors about private methods then
1124 // please update your code to use the high-level operand
1125 // interfaces. See line 943 above.
1126 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1128 //===----------------------------------------------------------------------===//
1130 //===----------------------------------------------------------------------===//
1132 /// SelectInst - This class represents the LLVM 'select' instruction.
1134 class SelectInst : public Instruction {
1135 void init(Value *C, Value *S1, Value *S2) {
1136 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1142 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1143 Instruction *InsertBefore)
1144 : Instruction(S1->getType(), Instruction::Select,
1145 &Op<0>(), 3, InsertBefore) {
1149 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1150 BasicBlock *InsertAtEnd)
1151 : Instruction(S1->getType(), Instruction::Select,
1152 &Op<0>(), 3, InsertAtEnd) {
1157 virtual SelectInst *clone_impl() const;
1159 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1160 const Twine &NameStr = "",
1161 Instruction *InsertBefore = 0) {
1162 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1164 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1165 const Twine &NameStr,
1166 BasicBlock *InsertAtEnd) {
1167 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1170 const Value *getCondition() const { return Op<0>(); }
1171 const Value *getTrueValue() const { return Op<1>(); }
1172 const Value *getFalseValue() const { return Op<2>(); }
1173 Value *getCondition() { return Op<0>(); }
1174 Value *getTrueValue() { return Op<1>(); }
1175 Value *getFalseValue() { return Op<2>(); }
1177 /// areInvalidOperands - Return a string if the specified operands are invalid
1178 /// for a select operation, otherwise return null.
1179 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1181 /// Transparently provide more efficient getOperand methods.
1182 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1184 OtherOps getOpcode() const {
1185 return static_cast<OtherOps>(Instruction::getOpcode());
1188 // Methods for support type inquiry through isa, cast, and dyn_cast:
1189 static inline bool classof(const SelectInst *) { return true; }
1190 static inline bool classof(const Instruction *I) {
1191 return I->getOpcode() == Instruction::Select;
1193 static inline bool classof(const Value *V) {
1194 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1199 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1202 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1204 //===----------------------------------------------------------------------===//
1206 //===----------------------------------------------------------------------===//
1208 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1209 /// an argument of the specified type given a va_list and increments that list
1211 class VAArgInst : public UnaryInstruction {
1213 virtual VAArgInst *clone_impl() const;
1216 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1217 Instruction *InsertBefore = 0)
1218 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1221 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1222 BasicBlock *InsertAtEnd)
1223 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1227 Value *getPointerOperand() { return getOperand(0); }
1228 const Value *getPointerOperand() const { return getOperand(0); }
1229 static unsigned getPointerOperandIndex() { return 0U; }
1231 // Methods for support type inquiry through isa, cast, and dyn_cast:
1232 static inline bool classof(const VAArgInst *) { return true; }
1233 static inline bool classof(const Instruction *I) {
1234 return I->getOpcode() == VAArg;
1236 static inline bool classof(const Value *V) {
1237 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1241 //===----------------------------------------------------------------------===//
1242 // ExtractElementInst Class
1243 //===----------------------------------------------------------------------===//
1245 /// ExtractElementInst - This instruction extracts a single (scalar)
1246 /// element from a VectorType value
1248 class ExtractElementInst : public Instruction {
1249 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1250 Instruction *InsertBefore = 0);
1251 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1252 BasicBlock *InsertAtEnd);
1254 virtual ExtractElementInst *clone_impl() const;
1257 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1258 const Twine &NameStr = "",
1259 Instruction *InsertBefore = 0) {
1260 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1262 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1263 const Twine &NameStr,
1264 BasicBlock *InsertAtEnd) {
1265 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1268 /// isValidOperands - Return true if an extractelement instruction can be
1269 /// formed with the specified operands.
1270 static bool isValidOperands(const Value *Vec, const Value *Idx);
1272 Value *getVectorOperand() { return Op<0>(); }
1273 Value *getIndexOperand() { return Op<1>(); }
1274 const Value *getVectorOperand() const { return Op<0>(); }
1275 const Value *getIndexOperand() const { return Op<1>(); }
1277 const VectorType *getVectorOperandType() const {
1278 return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
1282 /// Transparently provide more efficient getOperand methods.
1283 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1285 // Methods for support type inquiry through isa, cast, and dyn_cast:
1286 static inline bool classof(const ExtractElementInst *) { return true; }
1287 static inline bool classof(const Instruction *I) {
1288 return I->getOpcode() == Instruction::ExtractElement;
1290 static inline bool classof(const Value *V) {
1291 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1296 struct OperandTraits<ExtractElementInst> :
1297 public FixedNumOperandTraits<ExtractElementInst, 2> {
1300 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1302 //===----------------------------------------------------------------------===//
1303 // InsertElementInst Class
1304 //===----------------------------------------------------------------------===//
1306 /// InsertElementInst - This instruction inserts a single (scalar)
1307 /// element into a VectorType value
1309 class InsertElementInst : public Instruction {
1310 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1311 const Twine &NameStr = "",
1312 Instruction *InsertBefore = 0);
1313 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1314 const Twine &NameStr, BasicBlock *InsertAtEnd);
1316 virtual InsertElementInst *clone_impl() const;
1319 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1320 const Twine &NameStr = "",
1321 Instruction *InsertBefore = 0) {
1322 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1324 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1325 const Twine &NameStr,
1326 BasicBlock *InsertAtEnd) {
1327 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1330 /// isValidOperands - Return true if an insertelement instruction can be
1331 /// formed with the specified operands.
1332 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1335 /// getType - Overload to return most specific vector type.
1337 const VectorType *getType() const {
1338 return reinterpret_cast<const VectorType*>(Instruction::getType());
1341 /// Transparently provide more efficient getOperand methods.
1342 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1344 // Methods for support type inquiry through isa, cast, and dyn_cast:
1345 static inline bool classof(const InsertElementInst *) { return true; }
1346 static inline bool classof(const Instruction *I) {
1347 return I->getOpcode() == Instruction::InsertElement;
1349 static inline bool classof(const Value *V) {
1350 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1355 struct OperandTraits<InsertElementInst> :
1356 public FixedNumOperandTraits<InsertElementInst, 3> {
1359 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1361 //===----------------------------------------------------------------------===//
1362 // ShuffleVectorInst Class
1363 //===----------------------------------------------------------------------===//
1365 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1368 class ShuffleVectorInst : public Instruction {
1370 virtual ShuffleVectorInst *clone_impl() const;
1373 // allocate space for exactly three operands
1374 void *operator new(size_t s) {
1375 return User::operator new(s, 3);
1377 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1378 const Twine &NameStr = "",
1379 Instruction *InsertBefor = 0);
1380 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1381 const Twine &NameStr, BasicBlock *InsertAtEnd);
1383 /// isValidOperands - Return true if a shufflevector instruction can be
1384 /// formed with the specified operands.
1385 static bool isValidOperands(const Value *V1, const Value *V2,
1388 /// getType - Overload to return most specific vector type.
1390 const VectorType *getType() const {
1391 return reinterpret_cast<const VectorType*>(Instruction::getType());
1394 /// Transparently provide more efficient getOperand methods.
1395 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1397 /// getMaskValue - Return the index from the shuffle mask for the specified
1398 /// output result. This is either -1 if the element is undef or a number less
1399 /// than 2*numelements.
1400 int getMaskValue(unsigned i) const;
1402 // Methods for support type inquiry through isa, cast, and dyn_cast:
1403 static inline bool classof(const ShuffleVectorInst *) { return true; }
1404 static inline bool classof(const Instruction *I) {
1405 return I->getOpcode() == Instruction::ShuffleVector;
1407 static inline bool classof(const Value *V) {
1408 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1413 struct OperandTraits<ShuffleVectorInst> :
1414 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1417 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1419 //===----------------------------------------------------------------------===//
1420 // ExtractValueInst Class
1421 //===----------------------------------------------------------------------===//
1423 /// ExtractValueInst - This instruction extracts a struct member or array
1424 /// element value from an aggregate value.
1426 class ExtractValueInst : public UnaryInstruction {
1427 SmallVector<unsigned, 4> Indices;
1429 ExtractValueInst(const ExtractValueInst &EVI);
1430 void init(const unsigned *Idx, unsigned NumIdx,
1431 const Twine &NameStr);
1432 void init(unsigned Idx, const Twine &NameStr);
1434 template<typename RandomAccessIterator>
1435 void init(RandomAccessIterator IdxBegin,
1436 RandomAccessIterator IdxEnd,
1437 const Twine &NameStr,
1438 // This argument ensures that we have an iterator we can
1439 // do arithmetic on in constant time
1440 std::random_access_iterator_tag) {
1441 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1443 // There's no fundamental reason why we require at least one index
1444 // (other than weirdness with &*IdxBegin being invalid; see
1445 // getelementptr's init routine for example). But there's no
1446 // present need to support it.
1447 assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
1449 // This requires that the iterator points to contiguous memory.
1450 init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1451 // we have to build an array here
1454 /// getIndexedType - Returns the type of the element that would be extracted
1455 /// with an extractvalue instruction with the specified parameters.
1457 /// Null is returned if the indices are invalid for the specified type.
1459 static const Type *getIndexedType(const Type *Agg,
1460 const unsigned *Idx, unsigned NumIdx);
1462 template<typename RandomAccessIterator>
1463 static const Type *getIndexedType(const Type *Ptr,
1464 RandomAccessIterator IdxBegin,
1465 RandomAccessIterator IdxEnd,
1466 // This argument ensures that we
1467 // have an iterator we can do
1468 // arithmetic on in constant time
1469 std::random_access_iterator_tag) {
1470 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1473 // This requires that the iterator points to contiguous memory.
1474 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
1476 return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
1479 /// Constructors - Create a extractvalue instruction with a base aggregate
1480 /// value and a list of indices. The first ctor can optionally insert before
1481 /// an existing instruction, the second appends the new instruction to the
1482 /// specified BasicBlock.
1483 template<typename RandomAccessIterator>
1484 inline ExtractValueInst(Value *Agg,
1485 RandomAccessIterator IdxBegin,
1486 RandomAccessIterator IdxEnd,
1487 const Twine &NameStr,
1488 Instruction *InsertBefore);
1489 template<typename RandomAccessIterator>
1490 inline ExtractValueInst(Value *Agg,
1491 RandomAccessIterator IdxBegin,
1492 RandomAccessIterator IdxEnd,
1493 const Twine &NameStr, BasicBlock *InsertAtEnd);
1495 // allocate space for exactly one operand
1496 void *operator new(size_t s) {
1497 return User::operator new(s, 1);
1500 virtual ExtractValueInst *clone_impl() const;
1503 template<typename RandomAccessIterator>
1504 static ExtractValueInst *Create(Value *Agg,
1505 RandomAccessIterator IdxBegin,
1506 RandomAccessIterator IdxEnd,
1507 const Twine &NameStr = "",
1508 Instruction *InsertBefore = 0) {
1510 ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
1512 template<typename RandomAccessIterator>
1513 static ExtractValueInst *Create(Value *Agg,
1514 RandomAccessIterator IdxBegin,
1515 RandomAccessIterator IdxEnd,
1516 const Twine &NameStr,
1517 BasicBlock *InsertAtEnd) {
1518 return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
1521 /// Constructors - These two creators are convenience methods because one
1522 /// index extractvalue instructions are much more common than those with
1524 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1525 const Twine &NameStr = "",
1526 Instruction *InsertBefore = 0) {
1527 unsigned Idxs[1] = { Idx };
1528 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
1530 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1531 const Twine &NameStr,
1532 BasicBlock *InsertAtEnd) {
1533 unsigned Idxs[1] = { Idx };
1534 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
1537 /// getIndexedType - Returns the type of the element that would be extracted
1538 /// with an extractvalue instruction with the specified parameters.
1540 /// Null is returned if the indices are invalid for the specified type.
1542 template<typename RandomAccessIterator>
1543 static const Type *getIndexedType(const Type *Ptr,
1544 RandomAccessIterator IdxBegin,
1545 RandomAccessIterator IdxEnd) {
1546 return getIndexedType(Ptr, IdxBegin, IdxEnd,
1547 typename std::iterator_traits<RandomAccessIterator>::
1548 iterator_category());
1550 static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
1552 typedef const unsigned* idx_iterator;
1553 inline idx_iterator idx_begin() const { return Indices.begin(); }
1554 inline idx_iterator idx_end() const { return Indices.end(); }
1556 Value *getAggregateOperand() {
1557 return getOperand(0);
1559 const Value *getAggregateOperand() const {
1560 return getOperand(0);
1562 static unsigned getAggregateOperandIndex() {
1563 return 0U; // get index for modifying correct operand
1566 unsigned getNumIndices() const { // Note: always non-negative
1567 return (unsigned)Indices.size();
1570 bool hasIndices() const {
1574 // Methods for support type inquiry through isa, cast, and dyn_cast:
1575 static inline bool classof(const ExtractValueInst *) { return true; }
1576 static inline bool classof(const Instruction *I) {
1577 return I->getOpcode() == Instruction::ExtractValue;
1579 static inline bool classof(const Value *V) {
1580 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1584 template<typename RandomAccessIterator>
1585 ExtractValueInst::ExtractValueInst(Value *Agg,
1586 RandomAccessIterator IdxBegin,
1587 RandomAccessIterator IdxEnd,
1588 const Twine &NameStr,
1589 Instruction *InsertBefore)
1590 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1592 ExtractValue, Agg, InsertBefore) {
1593 init(IdxBegin, IdxEnd, NameStr,
1594 typename std::iterator_traits<RandomAccessIterator>
1595 ::iterator_category());
1597 template<typename RandomAccessIterator>
1598 ExtractValueInst::ExtractValueInst(Value *Agg,
1599 RandomAccessIterator IdxBegin,
1600 RandomAccessIterator IdxEnd,
1601 const Twine &NameStr,
1602 BasicBlock *InsertAtEnd)
1603 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1605 ExtractValue, Agg, InsertAtEnd) {
1606 init(IdxBegin, IdxEnd, NameStr,
1607 typename std::iterator_traits<RandomAccessIterator>
1608 ::iterator_category());
1612 //===----------------------------------------------------------------------===//
1613 // InsertValueInst Class
1614 //===----------------------------------------------------------------------===//
1616 /// InsertValueInst - This instruction inserts a struct field of array element
1617 /// value into an aggregate value.
1619 class InsertValueInst : public Instruction {
1620 SmallVector<unsigned, 4> Indices;
1622 void *operator new(size_t, unsigned); // Do not implement
1623 InsertValueInst(const InsertValueInst &IVI);
1624 void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1625 const Twine &NameStr);
1626 void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
1628 template<typename RandomAccessIterator>
1629 void init(Value *Agg, Value *Val,
1630 RandomAccessIterator IdxBegin, RandomAccessIterator IdxEnd,
1631 const Twine &NameStr,
1632 // This argument ensures that we have an iterator we can
1633 // do arithmetic on in constant time
1634 std::random_access_iterator_tag) {
1635 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1637 // There's no fundamental reason why we require at least one index
1638 // (other than weirdness with &*IdxBegin being invalid; see
1639 // getelementptr's init routine for example). But there's no
1640 // present need to support it.
1641 assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1643 // This requires that the iterator points to contiguous memory.
1644 init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1645 // we have to build an array here
1648 /// Constructors - Create a insertvalue instruction with a base aggregate
1649 /// value, a value to insert, and a list of indices. The first ctor can
1650 /// optionally insert before an existing instruction, the second appends
1651 /// the new instruction to the specified BasicBlock.
1652 template<typename RandomAccessIterator>
1653 inline InsertValueInst(Value *Agg, Value *Val,
1654 RandomAccessIterator IdxBegin,
1655 RandomAccessIterator IdxEnd,
1656 const Twine &NameStr,
1657 Instruction *InsertBefore);
1658 template<typename RandomAccessIterator>
1659 inline InsertValueInst(Value *Agg, Value *Val,
1660 RandomAccessIterator IdxBegin,
1661 RandomAccessIterator IdxEnd,
1662 const Twine &NameStr, BasicBlock *InsertAtEnd);
1664 /// Constructors - These two constructors are convenience methods because one
1665 /// and two index insertvalue instructions are so common.
1666 InsertValueInst(Value *Agg, Value *Val,
1667 unsigned Idx, const Twine &NameStr = "",
1668 Instruction *InsertBefore = 0);
1669 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1670 const Twine &NameStr, BasicBlock *InsertAtEnd);
1672 virtual InsertValueInst *clone_impl() const;
1674 // allocate space for exactly two operands
1675 void *operator new(size_t s) {
1676 return User::operator new(s, 2);
1679 template<typename RandomAccessIterator>
1680 static InsertValueInst *Create(Value *Agg, Value *Val,
1681 RandomAccessIterator IdxBegin,
1682 RandomAccessIterator IdxEnd,
1683 const Twine &NameStr = "",
1684 Instruction *InsertBefore = 0) {
1685 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1686 NameStr, InsertBefore);
1688 template<typename RandomAccessIterator>
1689 static InsertValueInst *Create(Value *Agg, Value *Val,
1690 RandomAccessIterator IdxBegin,
1691 RandomAccessIterator IdxEnd,
1692 const Twine &NameStr,
1693 BasicBlock *InsertAtEnd) {
1694 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1695 NameStr, InsertAtEnd);
1698 /// Constructors - These two creators are convenience methods because one
1699 /// index insertvalue instructions are much more common than those with
1701 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1702 const Twine &NameStr = "",
1703 Instruction *InsertBefore = 0) {
1704 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
1706 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1707 const Twine &NameStr,
1708 BasicBlock *InsertAtEnd) {
1709 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
1712 /// Transparently provide more efficient getOperand methods.
1713 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1715 typedef const unsigned* idx_iterator;
1716 inline idx_iterator idx_begin() const { return Indices.begin(); }
1717 inline idx_iterator idx_end() const { return Indices.end(); }
1719 Value *getAggregateOperand() {
1720 return getOperand(0);
1722 const Value *getAggregateOperand() const {
1723 return getOperand(0);
1725 static unsigned getAggregateOperandIndex() {
1726 return 0U; // get index for modifying correct operand
1729 Value *getInsertedValueOperand() {
1730 return getOperand(1);
1732 const Value *getInsertedValueOperand() const {
1733 return getOperand(1);
1735 static unsigned getInsertedValueOperandIndex() {
1736 return 1U; // get index for modifying correct operand
1739 unsigned getNumIndices() const { // Note: always non-negative
1740 return (unsigned)Indices.size();
1743 bool hasIndices() const {
1747 // Methods for support type inquiry through isa, cast, and dyn_cast:
1748 static inline bool classof(const InsertValueInst *) { return true; }
1749 static inline bool classof(const Instruction *I) {
1750 return I->getOpcode() == Instruction::InsertValue;
1752 static inline bool classof(const Value *V) {
1753 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1758 struct OperandTraits<InsertValueInst> :
1759 public FixedNumOperandTraits<InsertValueInst, 2> {
1762 template<typename RandomAccessIterator>
1763 InsertValueInst::InsertValueInst(Value *Agg,
1765 RandomAccessIterator IdxBegin,
1766 RandomAccessIterator IdxEnd,
1767 const Twine &NameStr,
1768 Instruction *InsertBefore)
1769 : Instruction(Agg->getType(), InsertValue,
1770 OperandTraits<InsertValueInst>::op_begin(this),
1772 init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1773 typename std::iterator_traits<RandomAccessIterator>
1774 ::iterator_category());
1776 template<typename RandomAccessIterator>
1777 InsertValueInst::InsertValueInst(Value *Agg,
1779 RandomAccessIterator IdxBegin,
1780 RandomAccessIterator IdxEnd,
1781 const Twine &NameStr,
1782 BasicBlock *InsertAtEnd)
1783 : Instruction(Agg->getType(), InsertValue,
1784 OperandTraits<InsertValueInst>::op_begin(this),
1786 init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1787 typename std::iterator_traits<RandomAccessIterator>
1788 ::iterator_category());
1791 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1793 //===----------------------------------------------------------------------===//
1795 //===----------------------------------------------------------------------===//
1797 // PHINode - The PHINode class is used to represent the magical mystical PHI
1798 // node, that can not exist in nature, but can be synthesized in a computer
1799 // scientist's overactive imagination.
1801 class PHINode : public Instruction {
1802 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1803 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1804 /// the number actually in use.
1805 unsigned ReservedSpace;
1806 PHINode(const PHINode &PN);
1807 // allocate space for exactly zero operands
1808 void *operator new(size_t s) {
1809 return User::operator new(s, 0);
1811 explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1812 Instruction *InsertBefore = 0)
1813 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1818 PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1819 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1824 virtual PHINode *clone_impl() const;
1826 static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1827 Instruction *InsertBefore = 0) {
1828 return new PHINode(Ty, NameStr, InsertBefore);
1830 static PHINode *Create(const Type *Ty, const Twine &NameStr,
1831 BasicBlock *InsertAtEnd) {
1832 return new PHINode(Ty, NameStr, InsertAtEnd);
1836 /// reserveOperandSpace - This method can be used to avoid repeated
1837 /// reallocation of PHI operand lists by reserving space for the correct
1838 /// number of operands before adding them. Unlike normal vector reserves,
1839 /// this method can also be used to trim the operand space.
1840 void reserveOperandSpace(unsigned NumValues) {
1841 resizeOperands(NumValues*2);
1844 /// Provide fast operand accessors
1845 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1847 /// getNumIncomingValues - Return the number of incoming edges
1849 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1851 /// getIncomingValue - Return incoming value number x
1853 Value *getIncomingValue(unsigned i) const {
1854 assert(i*2 < getNumOperands() && "Invalid value number!");
1855 return getOperand(i*2);
1857 void setIncomingValue(unsigned i, Value *V) {
1858 assert(i*2 < getNumOperands() && "Invalid value number!");
1861 static unsigned getOperandNumForIncomingValue(unsigned i) {
1864 static unsigned getIncomingValueNumForOperand(unsigned i) {
1865 assert(i % 2 == 0 && "Invalid incoming-value operand index!");
1869 /// getIncomingBlock - Return incoming basic block number @p i.
1871 BasicBlock *getIncomingBlock(unsigned i) const {
1872 return cast<BasicBlock>(getOperand(i*2+1));
1875 /// getIncomingBlock - Return incoming basic block corresponding
1876 /// to an operand of the PHI.
1878 BasicBlock *getIncomingBlock(const Use &U) const {
1879 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1880 return cast<BasicBlock>((&U + 1)->get());
1883 /// getIncomingBlock - Return incoming basic block corresponding
1884 /// to value use iterator.
1886 template <typename U>
1887 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1888 return getIncomingBlock(I.getUse());
1892 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1893 setOperand(i*2+1, (Value*)BB);
1895 static unsigned getOperandNumForIncomingBlock(unsigned i) {
1898 static unsigned getIncomingBlockNumForOperand(unsigned i) {
1899 assert(i % 2 == 1 && "Invalid incoming-block operand index!");
1903 /// addIncoming - Add an incoming value to the end of the PHI list
1905 void addIncoming(Value *V, BasicBlock *BB) {
1906 assert(V && "PHI node got a null value!");
1907 assert(BB && "PHI node got a null basic block!");
1908 assert(getType() == V->getType() &&
1909 "All operands to PHI node must be the same type as the PHI node!");
1910 unsigned OpNo = NumOperands;
1911 if (OpNo+2 > ReservedSpace)
1912 resizeOperands(0); // Get more space!
1913 // Initialize some new operands.
1914 NumOperands = OpNo+2;
1915 OperandList[OpNo] = V;
1916 OperandList[OpNo+1] = (Value*)BB;
1919 /// removeIncomingValue - Remove an incoming value. This is useful if a
1920 /// predecessor basic block is deleted. The value removed is returned.
1922 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1923 /// is true), the PHI node is destroyed and any uses of it are replaced with
1924 /// dummy values. The only time there should be zero incoming values to a PHI
1925 /// node is when the block is dead, so this strategy is sound.
1927 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1929 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1930 int Idx = getBasicBlockIndex(BB);
1931 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1932 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1935 /// getBasicBlockIndex - Return the first index of the specified basic
1936 /// block in the value list for this PHI. Returns -1 if no instance.
1938 int getBasicBlockIndex(const BasicBlock *BB) const {
1939 Use *OL = OperandList;
1940 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1941 if (OL[i+1].get() == (const Value*)BB) return i/2;
1945 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1946 return getIncomingValue(getBasicBlockIndex(BB));
1949 /// hasConstantValue - If the specified PHI node always merges together the
1950 /// same value, return the value, otherwise return null.
1951 Value *hasConstantValue() const;
1953 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1954 static inline bool classof(const PHINode *) { return true; }
1955 static inline bool classof(const Instruction *I) {
1956 return I->getOpcode() == Instruction::PHI;
1958 static inline bool classof(const Value *V) {
1959 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1962 void resizeOperands(unsigned NumOperands);
1966 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1969 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1972 //===----------------------------------------------------------------------===//
1974 //===----------------------------------------------------------------------===//
1976 //===---------------------------------------------------------------------------
1977 /// ReturnInst - Return a value (possibly void), from a function. Execution
1978 /// does not continue in this function any longer.
1980 class ReturnInst : public TerminatorInst {
1981 ReturnInst(const ReturnInst &RI);
1984 // ReturnInst constructors:
1985 // ReturnInst() - 'ret void' instruction
1986 // ReturnInst( null) - 'ret void' instruction
1987 // ReturnInst(Value* X) - 'ret X' instruction
1988 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1989 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1990 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1991 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1993 // NOTE: If the Value* passed is of type void then the constructor behaves as
1994 // if it was passed NULL.
1995 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1996 Instruction *InsertBefore = 0);
1997 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1998 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2000 virtual ReturnInst *clone_impl() const;
2002 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2003 Instruction *InsertBefore = 0) {
2004 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2006 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2007 BasicBlock *InsertAtEnd) {
2008 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2010 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2011 return new(0) ReturnInst(C, InsertAtEnd);
2013 virtual ~ReturnInst();
2015 /// Provide fast operand accessors
2016 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2018 /// Convenience accessor. Returns null if there is no return value.
2019 Value *getReturnValue() const {
2020 return getNumOperands() != 0 ? getOperand(0) : 0;
2023 unsigned getNumSuccessors() const { return 0; }
2025 // Methods for support type inquiry through isa, cast, and dyn_cast:
2026 static inline bool classof(const ReturnInst *) { return true; }
2027 static inline bool classof(const Instruction *I) {
2028 return (I->getOpcode() == Instruction::Ret);
2030 static inline bool classof(const Value *V) {
2031 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2034 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2035 virtual unsigned getNumSuccessorsV() const;
2036 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2040 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2043 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2045 //===----------------------------------------------------------------------===//
2047 //===----------------------------------------------------------------------===//
2049 //===---------------------------------------------------------------------------
2050 /// BranchInst - Conditional or Unconditional Branch instruction.
2052 class BranchInst : public TerminatorInst {
2053 /// Ops list - Branches are strange. The operands are ordered:
2054 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2055 /// they don't have to check for cond/uncond branchness. These are mostly
2056 /// accessed relative from op_end().
2057 BranchInst(const BranchInst &BI);
2059 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2060 // BranchInst(BB *B) - 'br B'
2061 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2062 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2063 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2064 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2065 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2066 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2067 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2068 Instruction *InsertBefore = 0);
2069 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2070 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2071 BasicBlock *InsertAtEnd);
2073 virtual BranchInst *clone_impl() const;
2075 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2076 return new(1) BranchInst(IfTrue, InsertBefore);
2078 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2079 Value *Cond, Instruction *InsertBefore = 0) {
2080 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2082 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2083 return new(1) BranchInst(IfTrue, InsertAtEnd);
2085 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2086 Value *Cond, BasicBlock *InsertAtEnd) {
2087 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2090 /// Transparently provide more efficient getOperand methods.
2091 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2093 bool isUnconditional() const { return getNumOperands() == 1; }
2094 bool isConditional() const { return getNumOperands() == 3; }
2096 Value *getCondition() const {
2097 assert(isConditional() && "Cannot get condition of an uncond branch!");
2101 void setCondition(Value *V) {
2102 assert(isConditional() && "Cannot set condition of unconditional branch!");
2106 unsigned getNumSuccessors() const { return 1+isConditional(); }
2108 BasicBlock *getSuccessor(unsigned i) const {
2109 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2110 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2113 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2114 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2115 *(&Op<-1>() - idx) = (Value*)NewSucc;
2118 // Methods for support type inquiry through isa, cast, and dyn_cast:
2119 static inline bool classof(const BranchInst *) { return true; }
2120 static inline bool classof(const Instruction *I) {
2121 return (I->getOpcode() == Instruction::Br);
2123 static inline bool classof(const Value *V) {
2124 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2127 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2128 virtual unsigned getNumSuccessorsV() const;
2129 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2133 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2136 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2138 //===----------------------------------------------------------------------===//
2140 //===----------------------------------------------------------------------===//
2142 //===---------------------------------------------------------------------------
2143 /// SwitchInst - Multiway switch
2145 class SwitchInst : public TerminatorInst {
2146 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2147 unsigned ReservedSpace;
2148 // Operand[0] = Value to switch on
2149 // Operand[1] = Default basic block destination
2150 // Operand[2n ] = Value to match
2151 // Operand[2n+1] = BasicBlock to go to on match
2152 SwitchInst(const SwitchInst &SI);
2153 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2154 void resizeOperands(unsigned No);
2155 // allocate space for exactly zero operands
2156 void *operator new(size_t s) {
2157 return User::operator new(s, 0);
2159 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2160 /// switch on and a default destination. The number of additional cases can
2161 /// be specified here to make memory allocation more efficient. This
2162 /// constructor can also autoinsert before another instruction.
2163 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2164 Instruction *InsertBefore);
2166 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2167 /// switch on and a default destination. The number of additional cases can
2168 /// be specified here to make memory allocation more efficient. This
2169 /// constructor also autoinserts at the end of the specified BasicBlock.
2170 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2171 BasicBlock *InsertAtEnd);
2173 virtual SwitchInst *clone_impl() const;
2175 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2176 unsigned NumCases, Instruction *InsertBefore = 0) {
2177 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2179 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2180 unsigned NumCases, BasicBlock *InsertAtEnd) {
2181 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2185 /// Provide fast operand accessors
2186 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2188 // Accessor Methods for Switch stmt
2189 Value *getCondition() const { return getOperand(0); }
2190 void setCondition(Value *V) { setOperand(0, V); }
2192 BasicBlock *getDefaultDest() const {
2193 return cast<BasicBlock>(getOperand(1));
2196 /// getNumCases - return the number of 'cases' in this switch instruction.
2197 /// Note that case #0 is always the default case.
2198 unsigned getNumCases() const {
2199 return getNumOperands()/2;
2202 /// getCaseValue - Return the specified case value. Note that case #0, the
2203 /// default destination, does not have a case value.
2204 ConstantInt *getCaseValue(unsigned i) {
2205 assert(i && i < getNumCases() && "Illegal case value to get!");
2206 return getSuccessorValue(i);
2209 /// getCaseValue - Return the specified case value. Note that case #0, the
2210 /// default destination, does not have a case value.
2211 const ConstantInt *getCaseValue(unsigned i) const {
2212 assert(i && i < getNumCases() && "Illegal case value to get!");
2213 return getSuccessorValue(i);
2216 /// findCaseValue - Search all of the case values for the specified constant.
2217 /// If it is explicitly handled, return the case number of it, otherwise
2218 /// return 0 to indicate that it is handled by the default handler.
2219 unsigned findCaseValue(const ConstantInt *C) const {
2220 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2221 if (getCaseValue(i) == C)
2226 /// findCaseDest - Finds the unique case value for a given successor. Returns
2227 /// null if the successor is not found, not unique, or is the default case.
2228 ConstantInt *findCaseDest(BasicBlock *BB) {
2229 if (BB == getDefaultDest()) return NULL;
2231 ConstantInt *CI = NULL;
2232 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2233 if (getSuccessor(i) == BB) {
2234 if (CI) return NULL; // Multiple cases lead to BB.
2235 else CI = getCaseValue(i);
2241 /// addCase - Add an entry to the switch instruction...
2243 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2245 /// removeCase - This method removes the specified successor from the switch
2246 /// instruction. Note that this cannot be used to remove the default
2247 /// destination (successor #0).
2249 void removeCase(unsigned idx);
2251 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2252 BasicBlock *getSuccessor(unsigned idx) const {
2253 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2254 return cast<BasicBlock>(getOperand(idx*2+1));
2256 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2257 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2258 setOperand(idx*2+1, (Value*)NewSucc);
2261 // getSuccessorValue - Return the value associated with the specified
2263 ConstantInt *getSuccessorValue(unsigned idx) const {
2264 assert(idx < getNumSuccessors() && "Successor # out of range!");
2265 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2268 // Methods for support type inquiry through isa, cast, and dyn_cast:
2269 static inline bool classof(const SwitchInst *) { return true; }
2270 static inline bool classof(const Instruction *I) {
2271 return I->getOpcode() == Instruction::Switch;
2273 static inline bool classof(const Value *V) {
2274 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2277 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2278 virtual unsigned getNumSuccessorsV() const;
2279 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2283 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2286 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2289 //===----------------------------------------------------------------------===//
2290 // IndirectBrInst Class
2291 //===----------------------------------------------------------------------===//
2293 //===---------------------------------------------------------------------------
2294 /// IndirectBrInst - Indirect Branch Instruction.
2296 class IndirectBrInst : public TerminatorInst {
2297 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2298 unsigned ReservedSpace;
2299 // Operand[0] = Value to switch on
2300 // Operand[1] = Default basic block destination
2301 // Operand[2n ] = Value to match
2302 // Operand[2n+1] = BasicBlock to go to on match
2303 IndirectBrInst(const IndirectBrInst &IBI);
2304 void init(Value *Address, unsigned NumDests);
2305 void resizeOperands(unsigned No);
2306 // allocate space for exactly zero operands
2307 void *operator new(size_t s) {
2308 return User::operator new(s, 0);
2310 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2311 /// Address to jump to. The number of expected destinations can be specified
2312 /// here to make memory allocation more efficient. This constructor can also
2313 /// autoinsert before another instruction.
2314 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2316 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2317 /// Address to jump to. The number of expected destinations can be specified
2318 /// here to make memory allocation more efficient. This constructor also
2319 /// autoinserts at the end of the specified BasicBlock.
2320 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2322 virtual IndirectBrInst *clone_impl() const;
2324 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2325 Instruction *InsertBefore = 0) {
2326 return new IndirectBrInst(Address, NumDests, InsertBefore);
2328 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2329 BasicBlock *InsertAtEnd) {
2330 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2334 /// Provide fast operand accessors.
2335 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2337 // Accessor Methods for IndirectBrInst instruction.
2338 Value *getAddress() { return getOperand(0); }
2339 const Value *getAddress() const { return getOperand(0); }
2340 void setAddress(Value *V) { setOperand(0, V); }
2343 /// getNumDestinations - return the number of possible destinations in this
2344 /// indirectbr instruction.
2345 unsigned getNumDestinations() const { return getNumOperands()-1; }
2347 /// getDestination - Return the specified destination.
2348 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2349 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2351 /// addDestination - Add a destination.
2353 void addDestination(BasicBlock *Dest);
2355 /// removeDestination - This method removes the specified successor from the
2356 /// indirectbr instruction.
2357 void removeDestination(unsigned i);
2359 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2360 BasicBlock *getSuccessor(unsigned i) const {
2361 return cast<BasicBlock>(getOperand(i+1));
2363 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2364 setOperand(i+1, (Value*)NewSucc);
2367 // Methods for support type inquiry through isa, cast, and dyn_cast:
2368 static inline bool classof(const IndirectBrInst *) { return true; }
2369 static inline bool classof(const Instruction *I) {
2370 return I->getOpcode() == Instruction::IndirectBr;
2372 static inline bool classof(const Value *V) {
2373 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2376 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2377 virtual unsigned getNumSuccessorsV() const;
2378 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2382 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2385 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2388 //===----------------------------------------------------------------------===//
2390 //===----------------------------------------------------------------------===//
2392 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2393 /// calling convention of the call.
2395 class InvokeInst : public TerminatorInst {
2396 AttrListPtr AttributeList;
2397 InvokeInst(const InvokeInst &BI);
2398 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2399 Value* const *Args, unsigned NumArgs);
2401 template<typename RandomAccessIterator>
2402 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2403 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2404 const Twine &NameStr,
2405 // This argument ensures that we have an iterator we can
2406 // do arithmetic on in constant time
2407 std::random_access_iterator_tag) {
2408 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2410 // This requires that the iterator points to contiguous memory.
2411 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2415 /// Construct an InvokeInst given a range of arguments.
2416 /// RandomAccessIterator must be a random-access iterator pointing to
2417 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2418 /// made for random-accessness but not for contiguous storage as
2419 /// that would incur runtime overhead.
2421 /// @brief Construct an InvokeInst from a range of arguments
2422 template<typename RandomAccessIterator>
2423 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2424 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2426 const Twine &NameStr, Instruction *InsertBefore);
2428 /// Construct an InvokeInst given a range of arguments.
2429 /// RandomAccessIterator must be a random-access iterator pointing to
2430 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2431 /// made for random-accessness but not for contiguous storage as
2432 /// that would incur runtime overhead.
2434 /// @brief Construct an InvokeInst from a range of arguments
2435 template<typename RandomAccessIterator>
2436 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2437 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2439 const Twine &NameStr, BasicBlock *InsertAtEnd);
2441 virtual InvokeInst *clone_impl() const;
2443 template<typename RandomAccessIterator>
2444 static InvokeInst *Create(Value *Func,
2445 BasicBlock *IfNormal, BasicBlock *IfException,
2446 RandomAccessIterator ArgBegin,
2447 RandomAccessIterator ArgEnd,
2448 const Twine &NameStr = "",
2449 Instruction *InsertBefore = 0) {
2450 unsigned Values(ArgEnd - ArgBegin + 3);
2451 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2452 Values, NameStr, InsertBefore);
2454 template<typename RandomAccessIterator>
2455 static InvokeInst *Create(Value *Func,
2456 BasicBlock *IfNormal, BasicBlock *IfException,
2457 RandomAccessIterator ArgBegin,
2458 RandomAccessIterator ArgEnd,
2459 const Twine &NameStr,
2460 BasicBlock *InsertAtEnd) {
2461 unsigned Values(ArgEnd - ArgBegin + 3);
2462 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2463 Values, NameStr, InsertAtEnd);
2466 /// Provide fast operand accessors
2467 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2469 /// getNumArgOperands - Return the number of invoke arguments.
2471 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2473 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2475 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2476 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2478 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2480 CallingConv::ID getCallingConv() const {
2481 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2483 void setCallingConv(CallingConv::ID CC) {
2484 setInstructionSubclassData(static_cast<unsigned>(CC));
2487 /// getAttributes - Return the parameter attributes for this invoke.
2489 const AttrListPtr &getAttributes() const { return AttributeList; }
2491 /// setAttributes - Set the parameter attributes for this invoke.
2493 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2495 /// addAttribute - adds the attribute to the list of attributes.
2496 void addAttribute(unsigned i, Attributes attr);
2498 /// removeAttribute - removes the attribute from the list of attributes.
2499 void removeAttribute(unsigned i, Attributes attr);
2501 /// @brief Determine whether the call or the callee has the given attribute.
2502 bool paramHasAttr(unsigned i, Attributes attr) const;
2504 /// @brief Extract the alignment for a call or parameter (0=unknown).
2505 unsigned getParamAlignment(unsigned i) const {
2506 return AttributeList.getParamAlignment(i);
2509 /// @brief Return true if the call should not be inlined.
2510 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2511 void setIsNoInline(bool Value = true) {
2512 if (Value) addAttribute(~0, Attribute::NoInline);
2513 else removeAttribute(~0, Attribute::NoInline);
2516 /// @brief Determine if the call does not access memory.
2517 bool doesNotAccessMemory() const {
2518 return paramHasAttr(~0, Attribute::ReadNone);
2520 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2521 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2522 else removeAttribute(~0, Attribute::ReadNone);
2525 /// @brief Determine if the call does not access or only reads memory.
2526 bool onlyReadsMemory() const {
2527 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2529 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2530 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2531 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2534 /// @brief Determine if the call cannot return.
2535 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2536 void setDoesNotReturn(bool DoesNotReturn = true) {
2537 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2538 else removeAttribute(~0, Attribute::NoReturn);
2541 /// @brief Determine if the call cannot unwind.
2542 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2543 void setDoesNotThrow(bool DoesNotThrow = true) {
2544 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2545 else removeAttribute(~0, Attribute::NoUnwind);
2548 /// @brief Determine if the call returns a structure through first
2549 /// pointer argument.
2550 bool hasStructRetAttr() const {
2551 // Be friendly and also check the callee.
2552 return paramHasAttr(1, Attribute::StructRet);
2555 /// @brief Determine if any call argument is an aggregate passed by value.
2556 bool hasByValArgument() const {
2557 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2560 /// getCalledFunction - Return the function called, or null if this is an
2561 /// indirect function invocation.
2563 Function *getCalledFunction() const {
2564 return dyn_cast<Function>(Op<-3>());
2567 /// getCalledValue - Get a pointer to the function that is invoked by this
2569 const Value *getCalledValue() const { return Op<-3>(); }
2570 Value *getCalledValue() { return Op<-3>(); }
2572 /// setCalledFunction - Set the function called.
2573 void setCalledFunction(Value* Fn) {
2577 // get*Dest - Return the destination basic blocks...
2578 BasicBlock *getNormalDest() const {
2579 return cast<BasicBlock>(Op<-2>());
2581 BasicBlock *getUnwindDest() const {
2582 return cast<BasicBlock>(Op<-1>());
2584 void setNormalDest(BasicBlock *B) {
2585 Op<-2>() = reinterpret_cast<Value*>(B);
2587 void setUnwindDest(BasicBlock *B) {
2588 Op<-1>() = reinterpret_cast<Value*>(B);
2591 BasicBlock *getSuccessor(unsigned i) const {
2592 assert(i < 2 && "Successor # out of range for invoke!");
2593 return i == 0 ? getNormalDest() : getUnwindDest();
2596 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2597 assert(idx < 2 && "Successor # out of range for invoke!");
2598 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2601 unsigned getNumSuccessors() const { return 2; }
2603 // Methods for support type inquiry through isa, cast, and dyn_cast:
2604 static inline bool classof(const InvokeInst *) { return true; }
2605 static inline bool classof(const Instruction *I) {
2606 return (I->getOpcode() == Instruction::Invoke);
2608 static inline bool classof(const Value *V) {
2609 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2613 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2614 virtual unsigned getNumSuccessorsV() const;
2615 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2617 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2618 // method so that subclasses cannot accidentally use it.
2619 void setInstructionSubclassData(unsigned short D) {
2620 Instruction::setInstructionSubclassData(D);
2625 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2628 template<typename RandomAccessIterator>
2629 InvokeInst::InvokeInst(Value *Func,
2630 BasicBlock *IfNormal, BasicBlock *IfException,
2631 RandomAccessIterator ArgBegin,
2632 RandomAccessIterator ArgEnd,
2634 const Twine &NameStr, Instruction *InsertBefore)
2635 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2636 ->getElementType())->getReturnType(),
2637 Instruction::Invoke,
2638 OperandTraits<InvokeInst>::op_end(this) - Values,
2639 Values, InsertBefore) {
2640 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2641 typename std::iterator_traits<RandomAccessIterator>
2642 ::iterator_category());
2644 template<typename RandomAccessIterator>
2645 InvokeInst::InvokeInst(Value *Func,
2646 BasicBlock *IfNormal, BasicBlock *IfException,
2647 RandomAccessIterator ArgBegin,
2648 RandomAccessIterator ArgEnd,
2650 const Twine &NameStr, BasicBlock *InsertAtEnd)
2651 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2652 ->getElementType())->getReturnType(),
2653 Instruction::Invoke,
2654 OperandTraits<InvokeInst>::op_end(this) - Values,
2655 Values, InsertAtEnd) {
2656 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2657 typename std::iterator_traits<RandomAccessIterator>
2658 ::iterator_category());
2661 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2663 //===----------------------------------------------------------------------===//
2665 //===----------------------------------------------------------------------===//
2667 //===---------------------------------------------------------------------------
2668 /// UnwindInst - Immediately exit the current function, unwinding the stack
2669 /// until an invoke instruction is found.
2671 class UnwindInst : public TerminatorInst {
2672 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2674 virtual UnwindInst *clone_impl() const;
2676 // allocate space for exactly zero operands
2677 void *operator new(size_t s) {
2678 return User::operator new(s, 0);
2680 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2681 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2683 unsigned getNumSuccessors() const { return 0; }
2685 // Methods for support type inquiry through isa, cast, and dyn_cast:
2686 static inline bool classof(const UnwindInst *) { return true; }
2687 static inline bool classof(const Instruction *I) {
2688 return I->getOpcode() == Instruction::Unwind;
2690 static inline bool classof(const Value *V) {
2691 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2694 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2695 virtual unsigned getNumSuccessorsV() const;
2696 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2699 //===----------------------------------------------------------------------===//
2700 // UnreachableInst Class
2701 //===----------------------------------------------------------------------===//
2703 //===---------------------------------------------------------------------------
2704 /// UnreachableInst - This function has undefined behavior. In particular, the
2705 /// presence of this instruction indicates some higher level knowledge that the
2706 /// end of the block cannot be reached.
2708 class UnreachableInst : public TerminatorInst {
2709 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2711 virtual UnreachableInst *clone_impl() const;
2714 // allocate space for exactly zero operands
2715 void *operator new(size_t s) {
2716 return User::operator new(s, 0);
2718 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2719 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2721 unsigned getNumSuccessors() const { return 0; }
2723 // Methods for support type inquiry through isa, cast, and dyn_cast:
2724 static inline bool classof(const UnreachableInst *) { return true; }
2725 static inline bool classof(const Instruction *I) {
2726 return I->getOpcode() == Instruction::Unreachable;
2728 static inline bool classof(const Value *V) {
2729 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2732 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2733 virtual unsigned getNumSuccessorsV() const;
2734 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2737 //===----------------------------------------------------------------------===//
2739 //===----------------------------------------------------------------------===//
2741 /// @brief This class represents a truncation of integer types.
2742 class TruncInst : public CastInst {
2744 /// @brief Clone an identical TruncInst
2745 virtual TruncInst *clone_impl() const;
2748 /// @brief Constructor with insert-before-instruction semantics
2750 Value *S, ///< The value to be truncated
2751 const Type *Ty, ///< The (smaller) type to truncate to
2752 const Twine &NameStr = "", ///< A name for the new instruction
2753 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2756 /// @brief Constructor with insert-at-end-of-block semantics
2758 Value *S, ///< The value to be truncated
2759 const Type *Ty, ///< The (smaller) type to truncate to
2760 const Twine &NameStr, ///< A name for the new instruction
2761 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2764 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2765 static inline bool classof(const TruncInst *) { return true; }
2766 static inline bool classof(const Instruction *I) {
2767 return I->getOpcode() == Trunc;
2769 static inline bool classof(const Value *V) {
2770 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2774 //===----------------------------------------------------------------------===//
2776 //===----------------------------------------------------------------------===//
2778 /// @brief This class represents zero extension of integer types.
2779 class ZExtInst : public CastInst {
2781 /// @brief Clone an identical ZExtInst
2782 virtual ZExtInst *clone_impl() const;
2785 /// @brief Constructor with insert-before-instruction semantics
2787 Value *S, ///< The value to be zero extended
2788 const Type *Ty, ///< The type to zero extend to
2789 const Twine &NameStr = "", ///< A name for the new instruction
2790 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2793 /// @brief Constructor with insert-at-end semantics.
2795 Value *S, ///< The value to be zero extended
2796 const Type *Ty, ///< The type to zero extend to
2797 const Twine &NameStr, ///< A name for the new instruction
2798 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2801 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2802 static inline bool classof(const ZExtInst *) { return true; }
2803 static inline bool classof(const Instruction *I) {
2804 return I->getOpcode() == ZExt;
2806 static inline bool classof(const Value *V) {
2807 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2811 //===----------------------------------------------------------------------===//
2813 //===----------------------------------------------------------------------===//
2815 /// @brief This class represents a sign extension of integer types.
2816 class SExtInst : public CastInst {
2818 /// @brief Clone an identical SExtInst
2819 virtual SExtInst *clone_impl() const;
2822 /// @brief Constructor with insert-before-instruction semantics
2824 Value *S, ///< The value to be sign extended
2825 const Type *Ty, ///< The type to sign extend to
2826 const Twine &NameStr = "", ///< A name for the new instruction
2827 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2830 /// @brief Constructor with insert-at-end-of-block semantics
2832 Value *S, ///< The value to be sign extended
2833 const Type *Ty, ///< The type to sign extend to
2834 const Twine &NameStr, ///< A name for the new instruction
2835 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2838 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2839 static inline bool classof(const SExtInst *) { return true; }
2840 static inline bool classof(const Instruction *I) {
2841 return I->getOpcode() == SExt;
2843 static inline bool classof(const Value *V) {
2844 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2848 //===----------------------------------------------------------------------===//
2849 // FPTruncInst Class
2850 //===----------------------------------------------------------------------===//
2852 /// @brief This class represents a truncation of floating point types.
2853 class FPTruncInst : public CastInst {
2855 /// @brief Clone an identical FPTruncInst
2856 virtual FPTruncInst *clone_impl() const;
2859 /// @brief Constructor with insert-before-instruction semantics
2861 Value *S, ///< The value to be truncated
2862 const Type *Ty, ///< The type to truncate to
2863 const Twine &NameStr = "", ///< A name for the new instruction
2864 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2867 /// @brief Constructor with insert-before-instruction semantics
2869 Value *S, ///< The value to be truncated
2870 const Type *Ty, ///< The type to truncate to
2871 const Twine &NameStr, ///< A name for the new instruction
2872 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2875 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2876 static inline bool classof(const FPTruncInst *) { return true; }
2877 static inline bool classof(const Instruction *I) {
2878 return I->getOpcode() == FPTrunc;
2880 static inline bool classof(const Value *V) {
2881 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2885 //===----------------------------------------------------------------------===//
2887 //===----------------------------------------------------------------------===//
2889 /// @brief This class represents an extension of floating point types.
2890 class FPExtInst : public CastInst {
2892 /// @brief Clone an identical FPExtInst
2893 virtual FPExtInst *clone_impl() const;
2896 /// @brief Constructor with insert-before-instruction semantics
2898 Value *S, ///< The value to be extended
2899 const Type *Ty, ///< The type to extend to
2900 const Twine &NameStr = "", ///< A name for the new instruction
2901 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2904 /// @brief Constructor with insert-at-end-of-block semantics
2906 Value *S, ///< The value to be extended
2907 const Type *Ty, ///< The type to extend to
2908 const Twine &NameStr, ///< A name for the new instruction
2909 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2912 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2913 static inline bool classof(const FPExtInst *) { return true; }
2914 static inline bool classof(const Instruction *I) {
2915 return I->getOpcode() == FPExt;
2917 static inline bool classof(const Value *V) {
2918 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2922 //===----------------------------------------------------------------------===//
2924 //===----------------------------------------------------------------------===//
2926 /// @brief This class represents a cast unsigned integer to floating point.
2927 class UIToFPInst : public CastInst {
2929 /// @brief Clone an identical UIToFPInst
2930 virtual UIToFPInst *clone_impl() const;
2933 /// @brief Constructor with insert-before-instruction semantics
2935 Value *S, ///< The value to be converted
2936 const Type *Ty, ///< The type to convert to
2937 const Twine &NameStr = "", ///< A name for the new instruction
2938 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2941 /// @brief Constructor with insert-at-end-of-block semantics
2943 Value *S, ///< The value to be converted
2944 const Type *Ty, ///< The type to convert to
2945 const Twine &NameStr, ///< A name for the new instruction
2946 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2949 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2950 static inline bool classof(const UIToFPInst *) { return true; }
2951 static inline bool classof(const Instruction *I) {
2952 return I->getOpcode() == UIToFP;
2954 static inline bool classof(const Value *V) {
2955 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2959 //===----------------------------------------------------------------------===//
2961 //===----------------------------------------------------------------------===//
2963 /// @brief This class represents a cast from signed integer to floating point.
2964 class SIToFPInst : public CastInst {
2966 /// @brief Clone an identical SIToFPInst
2967 virtual SIToFPInst *clone_impl() const;
2970 /// @brief Constructor with insert-before-instruction semantics
2972 Value *S, ///< The value to be converted
2973 const Type *Ty, ///< The type to convert to
2974 const Twine &NameStr = "", ///< A name for the new instruction
2975 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2978 /// @brief Constructor with insert-at-end-of-block semantics
2980 Value *S, ///< The value to be converted
2981 const Type *Ty, ///< The type to convert to
2982 const Twine &NameStr, ///< A name for the new instruction
2983 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2986 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2987 static inline bool classof(const SIToFPInst *) { return true; }
2988 static inline bool classof(const Instruction *I) {
2989 return I->getOpcode() == SIToFP;
2991 static inline bool classof(const Value *V) {
2992 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2996 //===----------------------------------------------------------------------===//
2998 //===----------------------------------------------------------------------===//
3000 /// @brief This class represents a cast from floating point to unsigned integer
3001 class FPToUIInst : public CastInst {
3003 /// @brief Clone an identical FPToUIInst
3004 virtual FPToUIInst *clone_impl() const;
3007 /// @brief Constructor with insert-before-instruction semantics
3009 Value *S, ///< The value to be converted
3010 const Type *Ty, ///< The type to convert to
3011 const Twine &NameStr = "", ///< A name for the new instruction
3012 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3015 /// @brief Constructor with insert-at-end-of-block semantics
3017 Value *S, ///< The value to be converted
3018 const Type *Ty, ///< The type to convert to
3019 const Twine &NameStr, ///< A name for the new instruction
3020 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3023 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3024 static inline bool classof(const FPToUIInst *) { return true; }
3025 static inline bool classof(const Instruction *I) {
3026 return I->getOpcode() == FPToUI;
3028 static inline bool classof(const Value *V) {
3029 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3033 //===----------------------------------------------------------------------===//
3035 //===----------------------------------------------------------------------===//
3037 /// @brief This class represents a cast from floating point to signed integer.
3038 class FPToSIInst : public CastInst {
3040 /// @brief Clone an identical FPToSIInst
3041 virtual FPToSIInst *clone_impl() const;
3044 /// @brief Constructor with insert-before-instruction semantics
3046 Value *S, ///< The value to be converted
3047 const Type *Ty, ///< The type to convert to
3048 const Twine &NameStr = "", ///< A name for the new instruction
3049 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3052 /// @brief Constructor with insert-at-end-of-block semantics
3054 Value *S, ///< The value to be converted
3055 const Type *Ty, ///< The type to convert to
3056 const Twine &NameStr, ///< A name for the new instruction
3057 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3060 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3061 static inline bool classof(const FPToSIInst *) { return true; }
3062 static inline bool classof(const Instruction *I) {
3063 return I->getOpcode() == FPToSI;
3065 static inline bool classof(const Value *V) {
3066 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3070 //===----------------------------------------------------------------------===//
3071 // IntToPtrInst Class
3072 //===----------------------------------------------------------------------===//
3074 /// @brief This class represents a cast from an integer to a pointer.
3075 class IntToPtrInst : public CastInst {
3077 /// @brief Constructor with insert-before-instruction semantics
3079 Value *S, ///< The value to be converted
3080 const Type *Ty, ///< The type to convert to
3081 const Twine &NameStr = "", ///< A name for the new instruction
3082 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3085 /// @brief Constructor with insert-at-end-of-block semantics
3087 Value *S, ///< The value to be converted
3088 const Type *Ty, ///< The type to convert to
3089 const Twine &NameStr, ///< A name for the new instruction
3090 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3093 /// @brief Clone an identical IntToPtrInst
3094 virtual IntToPtrInst *clone_impl() const;
3096 // Methods for support type inquiry through isa, cast, and dyn_cast:
3097 static inline bool classof(const IntToPtrInst *) { return true; }
3098 static inline bool classof(const Instruction *I) {
3099 return I->getOpcode() == IntToPtr;
3101 static inline bool classof(const Value *V) {
3102 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3106 //===----------------------------------------------------------------------===//
3107 // PtrToIntInst Class
3108 //===----------------------------------------------------------------------===//
3110 /// @brief This class represents a cast from a pointer to an integer
3111 class PtrToIntInst : public CastInst {
3113 /// @brief Clone an identical PtrToIntInst
3114 virtual PtrToIntInst *clone_impl() const;
3117 /// @brief Constructor with insert-before-instruction semantics
3119 Value *S, ///< The value to be converted
3120 const Type *Ty, ///< The type to convert to
3121 const Twine &NameStr = "", ///< A name for the new instruction
3122 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3125 /// @brief Constructor with insert-at-end-of-block semantics
3127 Value *S, ///< The value to be converted
3128 const Type *Ty, ///< The type to convert to
3129 const Twine &NameStr, ///< A name for the new instruction
3130 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3133 // Methods for support type inquiry through isa, cast, and dyn_cast:
3134 static inline bool classof(const PtrToIntInst *) { return true; }
3135 static inline bool classof(const Instruction *I) {
3136 return I->getOpcode() == PtrToInt;
3138 static inline bool classof(const Value *V) {
3139 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3143 //===----------------------------------------------------------------------===//
3144 // BitCastInst Class
3145 //===----------------------------------------------------------------------===//
3147 /// @brief This class represents a no-op cast from one type to another.
3148 class BitCastInst : public CastInst {
3150 /// @brief Clone an identical BitCastInst
3151 virtual BitCastInst *clone_impl() const;
3154 /// @brief Constructor with insert-before-instruction semantics
3156 Value *S, ///< The value to be casted
3157 const Type *Ty, ///< The type to casted to
3158 const Twine &NameStr = "", ///< A name for the new instruction
3159 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3162 /// @brief Constructor with insert-at-end-of-block semantics
3164 Value *S, ///< The value to be casted
3165 const Type *Ty, ///< The type to casted to
3166 const Twine &NameStr, ///< A name for the new instruction
3167 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3170 // Methods for support type inquiry through isa, cast, and dyn_cast:
3171 static inline bool classof(const BitCastInst *) { return true; }
3172 static inline bool classof(const Instruction *I) {
3173 return I->getOpcode() == BitCast;
3175 static inline bool classof(const Value *V) {
3176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3180 } // End llvm namespace