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"
34 //===----------------------------------------------------------------------===//
36 //===----------------------------------------------------------------------===//
38 /// AllocaInst - an instruction to allocate memory on the stack
40 class AllocaInst : public UnaryInstruction {
42 virtual AllocaInst *clone_impl() const;
44 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
45 const Twine &Name = "", Instruction *InsertBefore = 0);
46 AllocaInst(const Type *Ty, Value *ArraySize,
47 const Twine &Name, BasicBlock *InsertAtEnd);
49 AllocaInst(const Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
50 AllocaInst(const Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
52 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
53 const Twine &Name = "", Instruction *InsertBefore = 0);
54 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
55 const Twine &Name, BasicBlock *InsertAtEnd);
57 // Out of line virtual method, so the vtable, etc. has a home.
58 virtual ~AllocaInst();
60 /// isArrayAllocation - Return true if there is an allocation size parameter
61 /// to the allocation instruction that is not 1.
63 bool isArrayAllocation() const;
65 /// getArraySize - Get the number of elements allocated. For a simple
66 /// allocation of a single element, this will return a constant 1 value.
68 const Value *getArraySize() const { return getOperand(0); }
69 Value *getArraySize() { return getOperand(0); }
71 /// getType - Overload to return most specific pointer type
73 const PointerType *getType() const {
74 return reinterpret_cast<const PointerType*>(Instruction::getType());
77 /// getAllocatedType - Return the type that is being allocated by the
80 const Type *getAllocatedType() const;
82 /// getAlignment - Return the alignment of the memory that is being allocated
83 /// by the instruction.
85 unsigned getAlignment() const {
86 return (1u << getSubclassDataFromInstruction()) >> 1;
88 void setAlignment(unsigned Align);
90 /// isStaticAlloca - Return true if this alloca is in the entry block of the
91 /// function and is a constant size. If so, the code generator will fold it
92 /// into the prolog/epilog code, so it is basically free.
93 bool isStaticAlloca() const;
95 // Methods for support type inquiry through isa, cast, and dyn_cast:
96 static inline bool classof(const AllocaInst *) { return true; }
97 static inline bool classof(const Instruction *I) {
98 return (I->getOpcode() == Instruction::Alloca);
100 static inline bool classof(const Value *V) {
101 return isa<Instruction>(V) && classof(cast<Instruction>(V));
104 // Shadow Instruction::setInstructionSubclassData with a private forwarding
105 // method so that subclasses cannot accidentally use it.
106 void setInstructionSubclassData(unsigned short D) {
107 Instruction::setInstructionSubclassData(D);
112 //===----------------------------------------------------------------------===//
114 //===----------------------------------------------------------------------===//
116 /// LoadInst - an instruction for reading from memory. This uses the
117 /// SubclassData field in Value to store whether or not the load is volatile.
119 class LoadInst : public UnaryInstruction {
122 virtual LoadInst *clone_impl() const;
124 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
125 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
126 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
127 Instruction *InsertBefore = 0);
128 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
129 unsigned Align, Instruction *InsertBefore = 0);
130 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
131 BasicBlock *InsertAtEnd);
132 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
133 unsigned Align, BasicBlock *InsertAtEnd);
135 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
136 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
137 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
138 bool isVolatile = false, Instruction *InsertBefore = 0);
139 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
140 BasicBlock *InsertAtEnd);
142 /// isVolatile - Return true if this is a load from a volatile memory
145 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
147 /// setVolatile - Specify whether this is a volatile load or not.
149 void setVolatile(bool V) {
150 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
154 /// getAlignment - Return the alignment of the access that is being performed
156 unsigned getAlignment() const {
157 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
160 void setAlignment(unsigned Align);
162 Value *getPointerOperand() { return getOperand(0); }
163 const Value *getPointerOperand() const { return getOperand(0); }
164 static unsigned getPointerOperandIndex() { return 0U; }
166 unsigned getPointerAddressSpace() const {
167 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
171 // Methods for support type inquiry through isa, cast, and dyn_cast:
172 static inline bool classof(const LoadInst *) { return true; }
173 static inline bool classof(const Instruction *I) {
174 return I->getOpcode() == Instruction::Load;
176 static inline bool classof(const Value *V) {
177 return isa<Instruction>(V) && classof(cast<Instruction>(V));
180 // Shadow Instruction::setInstructionSubclassData with a private forwarding
181 // method so that subclasses cannot accidentally use it.
182 void setInstructionSubclassData(unsigned short D) {
183 Instruction::setInstructionSubclassData(D);
188 //===----------------------------------------------------------------------===//
190 //===----------------------------------------------------------------------===//
192 /// StoreInst - an instruction for storing to memory
194 class StoreInst : public Instruction {
195 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
198 virtual StoreInst *clone_impl() const;
200 // allocate space for exactly two operands
201 void *operator new(size_t s) {
202 return User::operator new(s, 2);
204 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
205 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
206 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
207 Instruction *InsertBefore = 0);
208 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
209 unsigned Align, Instruction *InsertBefore = 0);
210 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
211 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
212 unsigned Align, BasicBlock *InsertAtEnd);
215 /// isVolatile - Return true if this is a load from a volatile memory
218 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
220 /// setVolatile - Specify whether this is a volatile load or not.
222 void setVolatile(bool V) {
223 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
227 /// Transparently provide more efficient getOperand methods.
228 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
230 /// getAlignment - Return the alignment of the access that is being performed
232 unsigned getAlignment() const {
233 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
236 void setAlignment(unsigned Align);
238 Value *getValueOperand() { return getOperand(0); }
239 const Value *getValueOperand() const { return getOperand(0); }
241 Value *getPointerOperand() { return getOperand(1); }
242 const Value *getPointerOperand() const { return getOperand(1); }
243 static unsigned getPointerOperandIndex() { return 1U; }
245 unsigned getPointerAddressSpace() const {
246 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
249 // Methods for support type inquiry through isa, cast, and dyn_cast:
250 static inline bool classof(const StoreInst *) { return true; }
251 static inline bool classof(const Instruction *I) {
252 return I->getOpcode() == Instruction::Store;
254 static inline bool classof(const Value *V) {
255 return isa<Instruction>(V) && classof(cast<Instruction>(V));
258 // Shadow Instruction::setInstructionSubclassData with a private forwarding
259 // method so that subclasses cannot accidentally use it.
260 void setInstructionSubclassData(unsigned short D) {
261 Instruction::setInstructionSubclassData(D);
266 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<2> {
269 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
271 //===----------------------------------------------------------------------===//
272 // GetElementPtrInst Class
273 //===----------------------------------------------------------------------===//
275 // checkType - Simple wrapper function to give a better assertion failure
276 // message on bad indexes for a gep instruction.
278 static inline const Type *checkType(const Type *Ty) {
279 assert(Ty && "Invalid GetElementPtrInst indices for type!");
283 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
284 /// access elements of arrays and structs
286 class GetElementPtrInst : public Instruction {
287 GetElementPtrInst(const GetElementPtrInst &GEPI);
288 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
289 const Twine &NameStr);
290 void init(Value *Ptr, Value *Idx, const Twine &NameStr);
292 template<typename RandomAccessIterator>
293 void init(Value *Ptr,
294 RandomAccessIterator IdxBegin,
295 RandomAccessIterator IdxEnd,
296 const Twine &NameStr,
297 // This argument ensures that we have an iterator we can
298 // do arithmetic on in constant time
299 std::random_access_iterator_tag) {
300 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
303 // This requires that the iterator points to contiguous memory.
304 init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
305 // we have to build an array here
308 init(Ptr, 0, NumIdx, NameStr);
312 /// getIndexedType - Returns the type of the element that would be loaded with
313 /// a load instruction with the specified parameters.
315 /// Null is returned if the indices are invalid for the specified
318 template<typename RandomAccessIterator>
319 static const Type *getIndexedType(const Type *Ptr,
320 RandomAccessIterator IdxBegin,
321 RandomAccessIterator IdxEnd,
322 // This argument ensures that we
323 // have an iterator we can do
324 // arithmetic on in constant time
325 std::random_access_iterator_tag) {
326 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
329 // This requires that the iterator points to contiguous memory.
330 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
332 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
335 /// Constructors - Create a getelementptr instruction with a base pointer an
336 /// list of indices. The first ctor can optionally insert before an existing
337 /// instruction, the second appends the new instruction to the specified
339 template<typename RandomAccessIterator>
340 inline GetElementPtrInst(Value *Ptr, RandomAccessIterator IdxBegin,
341 RandomAccessIterator IdxEnd,
343 const Twine &NameStr,
344 Instruction *InsertBefore);
345 template<typename RandomAccessIterator>
346 inline GetElementPtrInst(Value *Ptr,
347 RandomAccessIterator IdxBegin,
348 RandomAccessIterator IdxEnd,
350 const Twine &NameStr, BasicBlock *InsertAtEnd);
352 /// Constructors - These two constructors are convenience methods because one
353 /// and two index getelementptr instructions are so common.
354 GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
355 Instruction *InsertBefore = 0);
356 GetElementPtrInst(Value *Ptr, Value *Idx,
357 const Twine &NameStr, BasicBlock *InsertAtEnd);
359 virtual GetElementPtrInst *clone_impl() const;
361 template<typename RandomAccessIterator>
362 static GetElementPtrInst *Create(Value *Ptr, RandomAccessIterator IdxBegin,
363 RandomAccessIterator IdxEnd,
364 const Twine &NameStr = "",
365 Instruction *InsertBefore = 0) {
366 typename std::iterator_traits<RandomAccessIterator>::difference_type
367 Values = 1 + std::distance(IdxBegin, IdxEnd);
369 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
371 template<typename RandomAccessIterator>
372 static GetElementPtrInst *Create(Value *Ptr,
373 RandomAccessIterator IdxBegin,
374 RandomAccessIterator IdxEnd,
375 const Twine &NameStr,
376 BasicBlock *InsertAtEnd) {
377 typename std::iterator_traits<RandomAccessIterator>::difference_type
378 Values = 1 + std::distance(IdxBegin, IdxEnd);
380 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
383 /// Constructors - These two creators are convenience methods because one
384 /// index getelementptr instructions are so common.
385 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
386 const Twine &NameStr = "",
387 Instruction *InsertBefore = 0) {
388 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
390 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
391 const Twine &NameStr,
392 BasicBlock *InsertAtEnd) {
393 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
396 /// Create an "inbounds" getelementptr. See the documentation for the
397 /// "inbounds" flag in LangRef.html for details.
398 template<typename RandomAccessIterator>
399 static GetElementPtrInst *CreateInBounds(Value *Ptr,
400 RandomAccessIterator IdxBegin,
401 RandomAccessIterator IdxEnd,
402 const Twine &NameStr = "",
403 Instruction *InsertBefore = 0) {
404 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
405 NameStr, InsertBefore);
406 GEP->setIsInBounds(true);
409 template<typename RandomAccessIterator>
410 static GetElementPtrInst *CreateInBounds(Value *Ptr,
411 RandomAccessIterator IdxBegin,
412 RandomAccessIterator IdxEnd,
413 const Twine &NameStr,
414 BasicBlock *InsertAtEnd) {
415 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
416 NameStr, InsertAtEnd);
417 GEP->setIsInBounds(true);
420 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
421 const Twine &NameStr = "",
422 Instruction *InsertBefore = 0) {
423 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
424 GEP->setIsInBounds(true);
427 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
428 const Twine &NameStr,
429 BasicBlock *InsertAtEnd) {
430 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
431 GEP->setIsInBounds(true);
435 /// Transparently provide more efficient getOperand methods.
436 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
438 // getType - Overload to return most specific pointer type...
439 const PointerType *getType() const {
440 return reinterpret_cast<const PointerType*>(Instruction::getType());
443 /// getIndexedType - Returns the type of the element that would be loaded with
444 /// a load instruction with the specified parameters.
446 /// Null is returned if the indices are invalid for the specified
449 template<typename RandomAccessIterator>
450 static const Type *getIndexedType(const Type *Ptr,
451 RandomAccessIterator IdxBegin,
452 RandomAccessIterator IdxEnd) {
453 return getIndexedType(Ptr, IdxBegin, IdxEnd,
454 typename std::iterator_traits<RandomAccessIterator>::
455 iterator_category());
458 static const Type *getIndexedType(const Type *Ptr,
459 Value* const *Idx, unsigned NumIdx);
461 static const Type *getIndexedType(const Type *Ptr,
462 uint64_t const *Idx, unsigned NumIdx);
464 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
466 inline op_iterator idx_begin() { return op_begin()+1; }
467 inline const_op_iterator idx_begin() const { return op_begin()+1; }
468 inline op_iterator idx_end() { return op_end(); }
469 inline const_op_iterator idx_end() const { return op_end(); }
471 Value *getPointerOperand() {
472 return getOperand(0);
474 const Value *getPointerOperand() const {
475 return getOperand(0);
477 static unsigned getPointerOperandIndex() {
478 return 0U; // get index for modifying correct operand
481 unsigned getPointerAddressSpace() const {
482 return cast<PointerType>(getType())->getAddressSpace();
485 /// getPointerOperandType - Method to return the pointer operand as a
487 const PointerType *getPointerOperandType() const {
488 return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
492 unsigned getNumIndices() const { // Note: always non-negative
493 return getNumOperands() - 1;
496 bool hasIndices() const {
497 return getNumOperands() > 1;
500 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
501 /// zeros. If so, the result pointer and the first operand have the same
502 /// value, just potentially different types.
503 bool hasAllZeroIndices() const;
505 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
506 /// constant integers. If so, the result pointer and the first operand have
507 /// a constant offset between them.
508 bool hasAllConstantIndices() const;
510 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
511 /// See LangRef.html for the meaning of inbounds on a getelementptr.
512 void setIsInBounds(bool b = true);
514 /// isInBounds - Determine whether the GEP has the inbounds flag.
515 bool isInBounds() const;
517 // Methods for support type inquiry through isa, cast, and dyn_cast:
518 static inline bool classof(const GetElementPtrInst *) { return true; }
519 static inline bool classof(const Instruction *I) {
520 return (I->getOpcode() == Instruction::GetElementPtr);
522 static inline bool classof(const Value *V) {
523 return isa<Instruction>(V) && classof(cast<Instruction>(V));
528 struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<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<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<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> : public FixedNumOperandTraits<2> {
1299 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1301 //===----------------------------------------------------------------------===//
1302 // InsertElementInst Class
1303 //===----------------------------------------------------------------------===//
1305 /// InsertElementInst - This instruction inserts a single (scalar)
1306 /// element into a VectorType value
1308 class InsertElementInst : public Instruction {
1309 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1310 const Twine &NameStr = "",
1311 Instruction *InsertBefore = 0);
1312 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1313 const Twine &NameStr, BasicBlock *InsertAtEnd);
1315 virtual InsertElementInst *clone_impl() const;
1318 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1319 const Twine &NameStr = "",
1320 Instruction *InsertBefore = 0) {
1321 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1323 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1324 const Twine &NameStr,
1325 BasicBlock *InsertAtEnd) {
1326 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1329 /// isValidOperands - Return true if an insertelement instruction can be
1330 /// formed with the specified operands.
1331 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1334 /// getType - Overload to return most specific vector type.
1336 const VectorType *getType() const {
1337 return reinterpret_cast<const VectorType*>(Instruction::getType());
1340 /// Transparently provide more efficient getOperand methods.
1341 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1343 // Methods for support type inquiry through isa, cast, and dyn_cast:
1344 static inline bool classof(const InsertElementInst *) { return true; }
1345 static inline bool classof(const Instruction *I) {
1346 return I->getOpcode() == Instruction::InsertElement;
1348 static inline bool classof(const Value *V) {
1349 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1354 struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
1357 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1359 //===----------------------------------------------------------------------===//
1360 // ShuffleVectorInst Class
1361 //===----------------------------------------------------------------------===//
1363 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1366 class ShuffleVectorInst : public Instruction {
1368 virtual ShuffleVectorInst *clone_impl() const;
1371 // allocate space for exactly three operands
1372 void *operator new(size_t s) {
1373 return User::operator new(s, 3);
1375 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1376 const Twine &NameStr = "",
1377 Instruction *InsertBefor = 0);
1378 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1379 const Twine &NameStr, BasicBlock *InsertAtEnd);
1381 /// isValidOperands - Return true if a shufflevector instruction can be
1382 /// formed with the specified operands.
1383 static bool isValidOperands(const Value *V1, const Value *V2,
1386 /// getType - Overload to return most specific vector type.
1388 const VectorType *getType() const {
1389 return reinterpret_cast<const VectorType*>(Instruction::getType());
1392 /// Transparently provide more efficient getOperand methods.
1393 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1395 /// getMaskValue - Return the index from the shuffle mask for the specified
1396 /// output result. This is either -1 if the element is undef or a number less
1397 /// than 2*numelements.
1398 int getMaskValue(unsigned i) const;
1400 // Methods for support type inquiry through isa, cast, and dyn_cast:
1401 static inline bool classof(const ShuffleVectorInst *) { return true; }
1402 static inline bool classof(const Instruction *I) {
1403 return I->getOpcode() == Instruction::ShuffleVector;
1405 static inline bool classof(const Value *V) {
1406 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1411 struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
1414 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1416 //===----------------------------------------------------------------------===//
1417 // ExtractValueInst Class
1418 //===----------------------------------------------------------------------===//
1420 /// ExtractValueInst - This instruction extracts a struct member or array
1421 /// element value from an aggregate value.
1423 class ExtractValueInst : public UnaryInstruction {
1424 SmallVector<unsigned, 4> Indices;
1426 ExtractValueInst(const ExtractValueInst &EVI);
1427 void init(const unsigned *Idx, unsigned NumIdx,
1428 const Twine &NameStr);
1429 void init(unsigned Idx, const Twine &NameStr);
1431 template<typename RandomAccessIterator>
1432 void init(RandomAccessIterator IdxBegin,
1433 RandomAccessIterator IdxEnd,
1434 const Twine &NameStr,
1435 // This argument ensures that we have an iterator we can
1436 // do arithmetic on in constant time
1437 std::random_access_iterator_tag) {
1438 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1440 // There's no fundamental reason why we require at least one index
1441 // (other than weirdness with &*IdxBegin being invalid; see
1442 // getelementptr's init routine for example). But there's no
1443 // present need to support it.
1444 assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
1446 // This requires that the iterator points to contiguous memory.
1447 init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1448 // we have to build an array here
1451 /// getIndexedType - Returns the type of the element that would be extracted
1452 /// with an extractvalue instruction with the specified parameters.
1454 /// Null is returned if the indices are invalid for the specified
1457 static const Type *getIndexedType(const Type *Agg,
1458 const unsigned *Idx, unsigned NumIdx);
1460 template<typename RandomAccessIterator>
1461 static const Type *getIndexedType(const Type *Ptr,
1462 RandomAccessIterator IdxBegin,
1463 RandomAccessIterator IdxEnd,
1464 // This argument ensures that we
1465 // have an iterator we can do
1466 // arithmetic on in constant time
1467 std::random_access_iterator_tag) {
1468 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1471 // This requires that the iterator points to contiguous memory.
1472 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
1474 return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
1477 /// Constructors - Create a extractvalue instruction with a base aggregate
1478 /// value and a list of indices. The first ctor can optionally insert before
1479 /// an existing instruction, the second appends the new instruction to the
1480 /// specified BasicBlock.
1481 template<typename RandomAccessIterator>
1482 inline ExtractValueInst(Value *Agg,
1483 RandomAccessIterator IdxBegin,
1484 RandomAccessIterator IdxEnd,
1485 const Twine &NameStr,
1486 Instruction *InsertBefore);
1487 template<typename RandomAccessIterator>
1488 inline ExtractValueInst(Value *Agg,
1489 RandomAccessIterator IdxBegin,
1490 RandomAccessIterator IdxEnd,
1491 const Twine &NameStr, BasicBlock *InsertAtEnd);
1493 // allocate space for exactly one operand
1494 void *operator new(size_t s) {
1495 return User::operator new(s, 1);
1498 virtual ExtractValueInst *clone_impl() const;
1501 template<typename RandomAccessIterator>
1502 static ExtractValueInst *Create(Value *Agg,
1503 RandomAccessIterator IdxBegin,
1504 RandomAccessIterator IdxEnd,
1505 const Twine &NameStr = "",
1506 Instruction *InsertBefore = 0) {
1508 ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
1510 template<typename RandomAccessIterator>
1511 static ExtractValueInst *Create(Value *Agg,
1512 RandomAccessIterator IdxBegin,
1513 RandomAccessIterator IdxEnd,
1514 const Twine &NameStr,
1515 BasicBlock *InsertAtEnd) {
1516 return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
1519 /// Constructors - These two creators are convenience methods because one
1520 /// index extractvalue instructions are much more common than those with
1522 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1523 const Twine &NameStr = "",
1524 Instruction *InsertBefore = 0) {
1525 unsigned Idxs[1] = { Idx };
1526 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
1528 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1529 const Twine &NameStr,
1530 BasicBlock *InsertAtEnd) {
1531 unsigned Idxs[1] = { Idx };
1532 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
1535 /// getIndexedType - Returns the type of the element that would be extracted
1536 /// with an extractvalue instruction with the specified parameters.
1538 /// Null is returned if the indices are invalid for the specified
1541 template<typename RandomAccessIterator>
1542 static const Type *getIndexedType(const Type *Ptr,
1543 RandomAccessIterator IdxBegin,
1544 RandomAccessIterator IdxEnd) {
1545 return getIndexedType(Ptr, IdxBegin, IdxEnd,
1546 typename std::iterator_traits<RandomAccessIterator>::
1547 iterator_category());
1549 static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
1551 typedef const unsigned* idx_iterator;
1552 inline idx_iterator idx_begin() const { return Indices.begin(); }
1553 inline idx_iterator idx_end() const { return Indices.end(); }
1555 Value *getAggregateOperand() {
1556 return getOperand(0);
1558 const Value *getAggregateOperand() const {
1559 return getOperand(0);
1561 static unsigned getAggregateOperandIndex() {
1562 return 0U; // get index for modifying correct operand
1565 unsigned getNumIndices() const { // Note: always non-negative
1566 return (unsigned)Indices.size();
1569 bool hasIndices() const {
1573 // Methods for support type inquiry through isa, cast, and dyn_cast:
1574 static inline bool classof(const ExtractValueInst *) { return true; }
1575 static inline bool classof(const Instruction *I) {
1576 return I->getOpcode() == Instruction::ExtractValue;
1578 static inline bool classof(const Value *V) {
1579 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1583 template<typename RandomAccessIterator>
1584 ExtractValueInst::ExtractValueInst(Value *Agg,
1585 RandomAccessIterator IdxBegin,
1586 RandomAccessIterator IdxEnd,
1587 const Twine &NameStr,
1588 Instruction *InsertBefore)
1589 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1591 ExtractValue, Agg, InsertBefore) {
1592 init(IdxBegin, IdxEnd, NameStr,
1593 typename std::iterator_traits<RandomAccessIterator>
1594 ::iterator_category());
1596 template<typename RandomAccessIterator>
1597 ExtractValueInst::ExtractValueInst(Value *Agg,
1598 RandomAccessIterator IdxBegin,
1599 RandomAccessIterator IdxEnd,
1600 const Twine &NameStr,
1601 BasicBlock *InsertAtEnd)
1602 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1604 ExtractValue, Agg, InsertAtEnd) {
1605 init(IdxBegin, IdxEnd, NameStr,
1606 typename std::iterator_traits<RandomAccessIterator>
1607 ::iterator_category());
1611 //===----------------------------------------------------------------------===//
1612 // InsertValueInst Class
1613 //===----------------------------------------------------------------------===//
1615 /// InsertValueInst - This instruction inserts a struct field of array element
1616 /// value into an aggregate value.
1618 class InsertValueInst : public Instruction {
1619 SmallVector<unsigned, 4> Indices;
1621 void *operator new(size_t, unsigned); // Do not implement
1622 InsertValueInst(const InsertValueInst &IVI);
1623 void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1624 const Twine &NameStr);
1625 void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
1627 template<typename RandomAccessIterator>
1628 void init(Value *Agg, Value *Val,
1629 RandomAccessIterator IdxBegin, RandomAccessIterator IdxEnd,
1630 const Twine &NameStr,
1631 // This argument ensures that we have an iterator we can
1632 // do arithmetic on in constant time
1633 std::random_access_iterator_tag) {
1634 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1636 // There's no fundamental reason why we require at least one index
1637 // (other than weirdness with &*IdxBegin being invalid; see
1638 // getelementptr's init routine for example). But there's no
1639 // present need to support it.
1640 assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1642 // This requires that the iterator points to contiguous memory.
1643 init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1644 // we have to build an array here
1647 /// Constructors - Create a insertvalue instruction with a base aggregate
1648 /// value, a value to insert, and a list of indices. The first ctor can
1649 /// optionally insert before an existing instruction, the second appends
1650 /// the new instruction to the specified BasicBlock.
1651 template<typename RandomAccessIterator>
1652 inline InsertValueInst(Value *Agg, Value *Val,
1653 RandomAccessIterator IdxBegin,
1654 RandomAccessIterator IdxEnd,
1655 const Twine &NameStr,
1656 Instruction *InsertBefore);
1657 template<typename RandomAccessIterator>
1658 inline InsertValueInst(Value *Agg, Value *Val,
1659 RandomAccessIterator IdxBegin,
1660 RandomAccessIterator IdxEnd,
1661 const Twine &NameStr, BasicBlock *InsertAtEnd);
1663 /// Constructors - These two constructors are convenience methods because one
1664 /// and two index insertvalue instructions are so common.
1665 InsertValueInst(Value *Agg, Value *Val,
1666 unsigned Idx, const Twine &NameStr = "",
1667 Instruction *InsertBefore = 0);
1668 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1669 const Twine &NameStr, BasicBlock *InsertAtEnd);
1671 virtual InsertValueInst *clone_impl() const;
1673 // allocate space for exactly two operands
1674 void *operator new(size_t s) {
1675 return User::operator new(s, 2);
1678 template<typename RandomAccessIterator>
1679 static InsertValueInst *Create(Value *Agg, Value *Val,
1680 RandomAccessIterator IdxBegin,
1681 RandomAccessIterator IdxEnd,
1682 const Twine &NameStr = "",
1683 Instruction *InsertBefore = 0) {
1684 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1685 NameStr, InsertBefore);
1687 template<typename RandomAccessIterator>
1688 static InsertValueInst *Create(Value *Agg, Value *Val,
1689 RandomAccessIterator IdxBegin,
1690 RandomAccessIterator IdxEnd,
1691 const Twine &NameStr,
1692 BasicBlock *InsertAtEnd) {
1693 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1694 NameStr, InsertAtEnd);
1697 /// Constructors - These two creators are convenience methods because one
1698 /// index insertvalue instructions are much more common than those with
1700 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1701 const Twine &NameStr = "",
1702 Instruction *InsertBefore = 0) {
1703 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
1705 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1706 const Twine &NameStr,
1707 BasicBlock *InsertAtEnd) {
1708 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
1711 /// Transparently provide more efficient getOperand methods.
1712 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1714 typedef const unsigned* idx_iterator;
1715 inline idx_iterator idx_begin() const { return Indices.begin(); }
1716 inline idx_iterator idx_end() const { return Indices.end(); }
1718 Value *getAggregateOperand() {
1719 return getOperand(0);
1721 const Value *getAggregateOperand() const {
1722 return getOperand(0);
1724 static unsigned getAggregateOperandIndex() {
1725 return 0U; // get index for modifying correct operand
1728 Value *getInsertedValueOperand() {
1729 return getOperand(1);
1731 const Value *getInsertedValueOperand() const {
1732 return getOperand(1);
1734 static unsigned getInsertedValueOperandIndex() {
1735 return 1U; // get index for modifying correct operand
1738 unsigned getNumIndices() const { // Note: always non-negative
1739 return (unsigned)Indices.size();
1742 bool hasIndices() const {
1746 // Methods for support type inquiry through isa, cast, and dyn_cast:
1747 static inline bool classof(const InsertValueInst *) { return true; }
1748 static inline bool classof(const Instruction *I) {
1749 return I->getOpcode() == Instruction::InsertValue;
1751 static inline bool classof(const Value *V) {
1752 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1757 struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
1760 template<typename RandomAccessIterator>
1761 InsertValueInst::InsertValueInst(Value *Agg,
1763 RandomAccessIterator IdxBegin,
1764 RandomAccessIterator IdxEnd,
1765 const Twine &NameStr,
1766 Instruction *InsertBefore)
1767 : Instruction(Agg->getType(), InsertValue,
1768 OperandTraits<InsertValueInst>::op_begin(this),
1770 init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1771 typename std::iterator_traits<RandomAccessIterator>
1772 ::iterator_category());
1774 template<typename RandomAccessIterator>
1775 InsertValueInst::InsertValueInst(Value *Agg,
1777 RandomAccessIterator IdxBegin,
1778 RandomAccessIterator IdxEnd,
1779 const Twine &NameStr,
1780 BasicBlock *InsertAtEnd)
1781 : Instruction(Agg->getType(), InsertValue,
1782 OperandTraits<InsertValueInst>::op_begin(this),
1784 init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1785 typename std::iterator_traits<RandomAccessIterator>
1786 ::iterator_category());
1789 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1791 //===----------------------------------------------------------------------===//
1793 //===----------------------------------------------------------------------===//
1795 // PHINode - The PHINode class is used to represent the magical mystical PHI
1796 // node, that can not exist in nature, but can be synthesized in a computer
1797 // scientist's overactive imagination.
1799 class PHINode : public Instruction {
1800 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1801 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1802 /// the number actually in use.
1803 unsigned ReservedSpace;
1804 PHINode(const PHINode &PN);
1805 // allocate space for exactly zero operands
1806 void *operator new(size_t s) {
1807 return User::operator new(s, 0);
1809 explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1810 Instruction *InsertBefore = 0)
1811 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1816 PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1817 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1822 virtual PHINode *clone_impl() const;
1824 static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1825 Instruction *InsertBefore = 0) {
1826 return new PHINode(Ty, NameStr, InsertBefore);
1828 static PHINode *Create(const Type *Ty, const Twine &NameStr,
1829 BasicBlock *InsertAtEnd) {
1830 return new PHINode(Ty, NameStr, InsertAtEnd);
1834 /// reserveOperandSpace - This method can be used to avoid repeated
1835 /// reallocation of PHI operand lists by reserving space for the correct
1836 /// number of operands before adding them. Unlike normal vector reserves,
1837 /// this method can also be used to trim the operand space.
1838 void reserveOperandSpace(unsigned NumValues) {
1839 resizeOperands(NumValues*2);
1842 /// Provide fast operand accessors
1843 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1845 /// getNumIncomingValues - Return the number of incoming edges
1847 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1849 /// getIncomingValue - Return incoming value number x
1851 Value *getIncomingValue(unsigned i) const {
1852 assert(i*2 < getNumOperands() && "Invalid value number!");
1853 return getOperand(i*2);
1855 void setIncomingValue(unsigned i, Value *V) {
1856 assert(i*2 < getNumOperands() && "Invalid value number!");
1859 static unsigned getOperandNumForIncomingValue(unsigned i) {
1862 static unsigned getIncomingValueNumForOperand(unsigned i) {
1863 assert(i % 2 == 0 && "Invalid incoming-value operand index!");
1867 /// getIncomingBlock - Return incoming basic block number @p i.
1869 BasicBlock *getIncomingBlock(unsigned i) const {
1870 return cast<BasicBlock>(getOperand(i*2+1));
1873 /// getIncomingBlock - Return incoming basic block corresponding
1874 /// to an operand of the PHI.
1876 BasicBlock *getIncomingBlock(const Use &U) const {
1877 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1878 return cast<BasicBlock>((&U + 1)->get());
1881 /// getIncomingBlock - Return incoming basic block corresponding
1882 /// to value use iterator.
1884 template <typename U>
1885 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1886 return getIncomingBlock(I.getUse());
1890 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1891 setOperand(i*2+1, (Value*)BB);
1893 static unsigned getOperandNumForIncomingBlock(unsigned i) {
1896 static unsigned getIncomingBlockNumForOperand(unsigned i) {
1897 assert(i % 2 == 1 && "Invalid incoming-block operand index!");
1901 /// addIncoming - Add an incoming value to the end of the PHI list
1903 void addIncoming(Value *V, BasicBlock *BB) {
1904 assert(V && "PHI node got a null value!");
1905 assert(BB && "PHI node got a null basic block!");
1906 assert(getType() == V->getType() &&
1907 "All operands to PHI node must be the same type as the PHI node!");
1908 unsigned OpNo = NumOperands;
1909 if (OpNo+2 > ReservedSpace)
1910 resizeOperands(0); // Get more space!
1911 // Initialize some new operands.
1912 NumOperands = OpNo+2;
1913 OperandList[OpNo] = V;
1914 OperandList[OpNo+1] = (Value*)BB;
1917 /// removeIncomingValue - Remove an incoming value. This is useful if a
1918 /// predecessor basic block is deleted. The value removed is returned.
1920 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1921 /// is true), the PHI node is destroyed and any uses of it are replaced with
1922 /// dummy values. The only time there should be zero incoming values to a PHI
1923 /// node is when the block is dead, so this strategy is sound.
1925 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1927 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1928 int Idx = getBasicBlockIndex(BB);
1929 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1930 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1933 /// getBasicBlockIndex - Return the first index of the specified basic
1934 /// block in the value list for this PHI. Returns -1 if no instance.
1936 int getBasicBlockIndex(const BasicBlock *BB) const {
1937 Use *OL = OperandList;
1938 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1939 if (OL[i+1].get() == (const Value*)BB) return i/2;
1943 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1944 return getIncomingValue(getBasicBlockIndex(BB));
1947 /// hasConstantValue - If the specified PHI node always merges together the
1948 /// same value, return the value, otherwise return null.
1950 /// If the PHI has undef operands, but all the rest of the operands are
1951 /// some unique value, return that value if it can be proved that the
1952 /// value dominates the PHI. If DT is null, use a conservative check,
1953 /// otherwise use DT to test for dominance.
1955 Value *hasConstantValue(DominatorTree *DT = 0) const;
1957 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1958 static inline bool classof(const PHINode *) { return true; }
1959 static inline bool classof(const Instruction *I) {
1960 return I->getOpcode() == Instruction::PHI;
1962 static inline bool classof(const Value *V) {
1963 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1966 void resizeOperands(unsigned NumOperands);
1970 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1973 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1976 //===----------------------------------------------------------------------===//
1978 //===----------------------------------------------------------------------===//
1980 //===---------------------------------------------------------------------------
1981 /// ReturnInst - Return a value (possibly void), from a function. Execution
1982 /// does not continue in this function any longer.
1984 class ReturnInst : public TerminatorInst {
1985 ReturnInst(const ReturnInst &RI);
1988 // ReturnInst constructors:
1989 // ReturnInst() - 'ret void' instruction
1990 // ReturnInst( null) - 'ret void' instruction
1991 // ReturnInst(Value* X) - 'ret X' instruction
1992 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1993 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1994 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1995 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1997 // NOTE: If the Value* passed is of type void then the constructor behaves as
1998 // if it was passed NULL.
1999 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2000 Instruction *InsertBefore = 0);
2001 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2002 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2004 virtual ReturnInst *clone_impl() const;
2006 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2007 Instruction *InsertBefore = 0) {
2008 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2010 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2011 BasicBlock *InsertAtEnd) {
2012 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2014 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2015 return new(0) ReturnInst(C, InsertAtEnd);
2017 virtual ~ReturnInst();
2019 /// Provide fast operand accessors
2020 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2022 /// Convenience accessor. Returns null if there is no return value.
2023 Value *getReturnValue() const {
2024 return getNumOperands() != 0 ? getOperand(0) : 0;
2027 unsigned getNumSuccessors() const { return 0; }
2029 // Methods for support type inquiry through isa, cast, and dyn_cast:
2030 static inline bool classof(const ReturnInst *) { return true; }
2031 static inline bool classof(const Instruction *I) {
2032 return (I->getOpcode() == Instruction::Ret);
2034 static inline bool classof(const Value *V) {
2035 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2038 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2039 virtual unsigned getNumSuccessorsV() const;
2040 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2044 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<> {
2047 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2049 //===----------------------------------------------------------------------===//
2051 //===----------------------------------------------------------------------===//
2053 //===---------------------------------------------------------------------------
2054 /// BranchInst - Conditional or Unconditional Branch instruction.
2056 class BranchInst : public TerminatorInst {
2057 /// Ops list - Branches are strange. The operands are ordered:
2058 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2059 /// they don't have to check for cond/uncond branchness. These are mostly
2060 /// accessed relative from op_end().
2061 BranchInst(const BranchInst &BI);
2063 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2064 // BranchInst(BB *B) - 'br B'
2065 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2066 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2067 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2068 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2069 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2070 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2071 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2072 Instruction *InsertBefore = 0);
2073 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2074 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2075 BasicBlock *InsertAtEnd);
2077 virtual BranchInst *clone_impl() const;
2079 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2080 return new(1, true) BranchInst(IfTrue, InsertBefore);
2082 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2083 Value *Cond, Instruction *InsertBefore = 0) {
2084 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2086 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2087 return new(1, true) BranchInst(IfTrue, InsertAtEnd);
2089 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2090 Value *Cond, BasicBlock *InsertAtEnd) {
2091 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2096 /// Transparently provide more efficient getOperand methods.
2097 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2099 bool isUnconditional() const { return getNumOperands() == 1; }
2100 bool isConditional() const { return getNumOperands() == 3; }
2102 Value *getCondition() const {
2103 assert(isConditional() && "Cannot get condition of an uncond branch!");
2107 void setCondition(Value *V) {
2108 assert(isConditional() && "Cannot set condition of unconditional branch!");
2112 // setUnconditionalDest - Change the current branch to an unconditional branch
2113 // targeting the specified block.
2114 // FIXME: Eliminate this ugly method.
2115 void setUnconditionalDest(BasicBlock *Dest) {
2116 Op<-1>() = (Value*)Dest;
2117 if (isConditional()) { // Convert this to an uncond branch.
2121 OperandList = op_begin();
2125 unsigned getNumSuccessors() const { return 1+isConditional(); }
2127 BasicBlock *getSuccessor(unsigned i) const {
2128 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2129 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2132 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2133 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2134 *(&Op<-1>() - idx) = (Value*)NewSucc;
2137 // Methods for support type inquiry through isa, cast, and dyn_cast:
2138 static inline bool classof(const BranchInst *) { return true; }
2139 static inline bool classof(const Instruction *I) {
2140 return (I->getOpcode() == Instruction::Br);
2142 static inline bool classof(const Value *V) {
2143 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2146 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2147 virtual unsigned getNumSuccessorsV() const;
2148 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2152 struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
2154 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2156 //===----------------------------------------------------------------------===//
2158 //===----------------------------------------------------------------------===//
2160 //===---------------------------------------------------------------------------
2161 /// SwitchInst - Multiway switch
2163 class SwitchInst : public TerminatorInst {
2164 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2165 unsigned ReservedSpace;
2166 // Operand[0] = Value to switch on
2167 // Operand[1] = Default basic block destination
2168 // Operand[2n ] = Value to match
2169 // Operand[2n+1] = BasicBlock to go to on match
2170 SwitchInst(const SwitchInst &SI);
2171 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
2172 void resizeOperands(unsigned No);
2173 // allocate space for exactly zero operands
2174 void *operator new(size_t s) {
2175 return User::operator new(s, 0);
2177 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2178 /// switch on and a default destination. The number of additional cases can
2179 /// be specified here to make memory allocation more efficient. This
2180 /// constructor can also autoinsert before another instruction.
2181 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2182 Instruction *InsertBefore);
2184 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2185 /// switch on and a default destination. The number of additional cases can
2186 /// be specified here to make memory allocation more efficient. This
2187 /// constructor also autoinserts at the end of the specified BasicBlock.
2188 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2189 BasicBlock *InsertAtEnd);
2191 virtual SwitchInst *clone_impl() const;
2193 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2194 unsigned NumCases, Instruction *InsertBefore = 0) {
2195 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2197 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2198 unsigned NumCases, BasicBlock *InsertAtEnd) {
2199 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2203 /// Provide fast operand accessors
2204 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2206 // Accessor Methods for Switch stmt
2207 Value *getCondition() const { return getOperand(0); }
2208 void setCondition(Value *V) { setOperand(0, V); }
2210 BasicBlock *getDefaultDest() const {
2211 return cast<BasicBlock>(getOperand(1));
2214 /// getNumCases - return the number of 'cases' in this switch instruction.
2215 /// Note that case #0 is always the default case.
2216 unsigned getNumCases() const {
2217 return getNumOperands()/2;
2220 /// getCaseValue - Return the specified case value. Note that case #0, the
2221 /// default destination, does not have a case value.
2222 ConstantInt *getCaseValue(unsigned i) {
2223 assert(i && i < getNumCases() && "Illegal case value to get!");
2224 return getSuccessorValue(i);
2227 /// getCaseValue - Return the specified case value. Note that case #0, the
2228 /// default destination, does not have a case value.
2229 const ConstantInt *getCaseValue(unsigned i) const {
2230 assert(i && i < getNumCases() && "Illegal case value to get!");
2231 return getSuccessorValue(i);
2234 /// findCaseValue - Search all of the case values for the specified constant.
2235 /// If it is explicitly handled, return the case number of it, otherwise
2236 /// return 0 to indicate that it is handled by the default handler.
2237 unsigned findCaseValue(const ConstantInt *C) const {
2238 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2239 if (getCaseValue(i) == C)
2244 /// findCaseDest - Finds the unique case value for a given successor. Returns
2245 /// null if the successor is not found, not unique, or is the default case.
2246 ConstantInt *findCaseDest(BasicBlock *BB) {
2247 if (BB == getDefaultDest()) return NULL;
2249 ConstantInt *CI = NULL;
2250 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2251 if (getSuccessor(i) == BB) {
2252 if (CI) return NULL; // Multiple cases lead to BB.
2253 else CI = getCaseValue(i);
2259 /// addCase - Add an entry to the switch instruction...
2261 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2263 /// removeCase - This method removes the specified successor from the switch
2264 /// instruction. Note that this cannot be used to remove the default
2265 /// destination (successor #0).
2267 void removeCase(unsigned idx);
2269 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2270 BasicBlock *getSuccessor(unsigned idx) const {
2271 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2272 return cast<BasicBlock>(getOperand(idx*2+1));
2274 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2275 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2276 setOperand(idx*2+1, (Value*)NewSucc);
2279 // getSuccessorValue - Return the value associated with the specified
2281 ConstantInt *getSuccessorValue(unsigned idx) const {
2282 assert(idx < getNumSuccessors() && "Successor # out of range!");
2283 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2286 // Methods for support type inquiry through isa, cast, and dyn_cast:
2287 static inline bool classof(const SwitchInst *) { return true; }
2288 static inline bool classof(const Instruction *I) {
2289 return I->getOpcode() == Instruction::Switch;
2291 static inline bool classof(const Value *V) {
2292 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2295 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2296 virtual unsigned getNumSuccessorsV() const;
2297 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2301 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2304 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2307 //===----------------------------------------------------------------------===//
2308 // IndirectBrInst Class
2309 //===----------------------------------------------------------------------===//
2311 //===---------------------------------------------------------------------------
2312 /// IndirectBrInst - Indirect Branch Instruction.
2314 class IndirectBrInst : public TerminatorInst {
2315 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2316 unsigned ReservedSpace;
2317 // Operand[0] = Value to switch on
2318 // Operand[1] = Default basic block destination
2319 // Operand[2n ] = Value to match
2320 // Operand[2n+1] = BasicBlock to go to on match
2321 IndirectBrInst(const IndirectBrInst &IBI);
2322 void init(Value *Address, unsigned NumDests);
2323 void resizeOperands(unsigned No);
2324 // allocate space for exactly zero operands
2325 void *operator new(size_t s) {
2326 return User::operator new(s, 0);
2328 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2329 /// Address to jump to. The number of expected destinations can be specified
2330 /// here to make memory allocation more efficient. This constructor can also
2331 /// autoinsert before another instruction.
2332 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2334 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2335 /// Address to jump to. The number of expected destinations can be specified
2336 /// here to make memory allocation more efficient. This constructor also
2337 /// autoinserts at the end of the specified BasicBlock.
2338 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2340 virtual IndirectBrInst *clone_impl() const;
2342 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2343 Instruction *InsertBefore = 0) {
2344 return new IndirectBrInst(Address, NumDests, InsertBefore);
2346 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2347 BasicBlock *InsertAtEnd) {
2348 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2352 /// Provide fast operand accessors.
2353 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2355 // Accessor Methods for IndirectBrInst instruction.
2356 Value *getAddress() { return getOperand(0); }
2357 const Value *getAddress() const { return getOperand(0); }
2358 void setAddress(Value *V) { setOperand(0, V); }
2361 /// getNumDestinations - return the number of possible destinations in this
2362 /// indirectbr instruction.
2363 unsigned getNumDestinations() const { return getNumOperands()-1; }
2365 /// getDestination - Return the specified destination.
2366 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2367 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2369 /// addDestination - Add a destination.
2371 void addDestination(BasicBlock *Dest);
2373 /// removeDestination - This method removes the specified successor from the
2374 /// indirectbr instruction.
2375 void removeDestination(unsigned i);
2377 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2378 BasicBlock *getSuccessor(unsigned i) const {
2379 return cast<BasicBlock>(getOperand(i+1));
2381 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2382 setOperand(i+1, (Value*)NewSucc);
2385 // Methods for support type inquiry through isa, cast, and dyn_cast:
2386 static inline bool classof(const IndirectBrInst *) { return true; }
2387 static inline bool classof(const Instruction *I) {
2388 return I->getOpcode() == Instruction::IndirectBr;
2390 static inline bool classof(const Value *V) {
2391 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2394 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2395 virtual unsigned getNumSuccessorsV() const;
2396 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2400 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2403 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2406 //===----------------------------------------------------------------------===//
2408 //===----------------------------------------------------------------------===//
2410 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2411 /// calling convention of the call.
2413 class InvokeInst : public TerminatorInst {
2414 AttrListPtr AttributeList;
2415 InvokeInst(const InvokeInst &BI);
2416 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2417 Value* const *Args, unsigned NumArgs);
2419 template<typename RandomAccessIterator>
2420 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2421 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2422 const Twine &NameStr,
2423 // This argument ensures that we have an iterator we can
2424 // do arithmetic on in constant time
2425 std::random_access_iterator_tag) {
2426 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2428 // This requires that the iterator points to contiguous memory.
2429 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2433 /// Construct an InvokeInst given a range of arguments.
2434 /// RandomAccessIterator must be a random-access iterator pointing to
2435 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2436 /// made for random-accessness but not for contiguous storage as
2437 /// that would incur runtime overhead.
2439 /// @brief Construct an InvokeInst from a range of arguments
2440 template<typename RandomAccessIterator>
2441 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2442 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2444 const Twine &NameStr, Instruction *InsertBefore);
2446 /// Construct an InvokeInst given a range of arguments.
2447 /// RandomAccessIterator must be a random-access iterator pointing to
2448 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2449 /// made for random-accessness but not for contiguous storage as
2450 /// that would incur runtime overhead.
2452 /// @brief Construct an InvokeInst from a range of arguments
2453 template<typename RandomAccessIterator>
2454 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2455 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2457 const Twine &NameStr, BasicBlock *InsertAtEnd);
2459 virtual InvokeInst *clone_impl() const;
2461 template<typename RandomAccessIterator>
2462 static InvokeInst *Create(Value *Func,
2463 BasicBlock *IfNormal, BasicBlock *IfException,
2464 RandomAccessIterator ArgBegin,
2465 RandomAccessIterator ArgEnd,
2466 const Twine &NameStr = "",
2467 Instruction *InsertBefore = 0) {
2468 unsigned Values(ArgEnd - ArgBegin + 3);
2469 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2470 Values, NameStr, InsertBefore);
2472 template<typename RandomAccessIterator>
2473 static InvokeInst *Create(Value *Func,
2474 BasicBlock *IfNormal, BasicBlock *IfException,
2475 RandomAccessIterator ArgBegin,
2476 RandomAccessIterator ArgEnd,
2477 const Twine &NameStr,
2478 BasicBlock *InsertAtEnd) {
2479 unsigned Values(ArgEnd - ArgBegin + 3);
2480 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2481 Values, NameStr, InsertAtEnd);
2484 /// Provide fast operand accessors
2485 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2487 /// getNumArgOperands - Return the number of invoke arguments.
2489 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2491 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2493 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2494 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2496 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2498 CallingConv::ID getCallingConv() const {
2499 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2501 void setCallingConv(CallingConv::ID CC) {
2502 setInstructionSubclassData(static_cast<unsigned>(CC));
2505 /// getAttributes - Return the parameter attributes for this invoke.
2507 const AttrListPtr &getAttributes() const { return AttributeList; }
2509 /// setAttributes - Set the parameter attributes for this invoke.
2511 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2513 /// addAttribute - adds the attribute to the list of attributes.
2514 void addAttribute(unsigned i, Attributes attr);
2516 /// removeAttribute - removes the attribute from the list of attributes.
2517 void removeAttribute(unsigned i, Attributes attr);
2519 /// @brief Determine whether the call or the callee has the given attribute.
2520 bool paramHasAttr(unsigned i, Attributes attr) const;
2522 /// @brief Extract the alignment for a call or parameter (0=unknown).
2523 unsigned getParamAlignment(unsigned i) const {
2524 return AttributeList.getParamAlignment(i);
2527 /// @brief Return true if the call should not be inlined.
2528 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2529 void setIsNoInline(bool Value = true) {
2530 if (Value) addAttribute(~0, Attribute::NoInline);
2531 else removeAttribute(~0, Attribute::NoInline);
2534 /// @brief Determine if the call does not access memory.
2535 bool doesNotAccessMemory() const {
2536 return paramHasAttr(~0, Attribute::ReadNone);
2538 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2539 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2540 else removeAttribute(~0, Attribute::ReadNone);
2543 /// @brief Determine if the call does not access or only reads memory.
2544 bool onlyReadsMemory() const {
2545 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2547 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2548 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2549 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2552 /// @brief Determine if the call cannot return.
2553 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2554 void setDoesNotReturn(bool DoesNotReturn = true) {
2555 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2556 else removeAttribute(~0, Attribute::NoReturn);
2559 /// @brief Determine if the call cannot unwind.
2560 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2561 void setDoesNotThrow(bool DoesNotThrow = true) {
2562 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2563 else removeAttribute(~0, Attribute::NoUnwind);
2566 /// @brief Determine if the call returns a structure through first
2567 /// pointer argument.
2568 bool hasStructRetAttr() const {
2569 // Be friendly and also check the callee.
2570 return paramHasAttr(1, Attribute::StructRet);
2573 /// @brief Determine if any call argument is an aggregate passed by value.
2574 bool hasByValArgument() const {
2575 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2578 /// getCalledFunction - Return the function called, or null if this is an
2579 /// indirect function invocation.
2581 Function *getCalledFunction() const {
2582 return dyn_cast<Function>(Op<-3>());
2585 /// getCalledValue - Get a pointer to the function that is invoked by this
2587 const Value *getCalledValue() const { return Op<-3>(); }
2588 Value *getCalledValue() { return Op<-3>(); }
2590 /// setCalledFunction - Set the function called.
2591 void setCalledFunction(Value* Fn) {
2595 // get*Dest - Return the destination basic blocks...
2596 BasicBlock *getNormalDest() const {
2597 return cast<BasicBlock>(Op<-2>());
2599 BasicBlock *getUnwindDest() const {
2600 return cast<BasicBlock>(Op<-1>());
2602 void setNormalDest(BasicBlock *B) {
2603 Op<-2>() = reinterpret_cast<Value*>(B);
2605 void setUnwindDest(BasicBlock *B) {
2606 Op<-1>() = reinterpret_cast<Value*>(B);
2609 BasicBlock *getSuccessor(unsigned i) const {
2610 assert(i < 2 && "Successor # out of range for invoke!");
2611 return i == 0 ? getNormalDest() : getUnwindDest();
2614 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2615 assert(idx < 2 && "Successor # out of range for invoke!");
2616 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2619 unsigned getNumSuccessors() const { return 2; }
2621 // Methods for support type inquiry through isa, cast, and dyn_cast:
2622 static inline bool classof(const InvokeInst *) { return true; }
2623 static inline bool classof(const Instruction *I) {
2624 return (I->getOpcode() == Instruction::Invoke);
2626 static inline bool classof(const Value *V) {
2627 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2631 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2632 virtual unsigned getNumSuccessorsV() const;
2633 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2635 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2636 // method so that subclasses cannot accidentally use it.
2637 void setInstructionSubclassData(unsigned short D) {
2638 Instruction::setInstructionSubclassData(D);
2643 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
2646 template<typename RandomAccessIterator>
2647 InvokeInst::InvokeInst(Value *Func,
2648 BasicBlock *IfNormal, BasicBlock *IfException,
2649 RandomAccessIterator ArgBegin,
2650 RandomAccessIterator ArgEnd,
2652 const Twine &NameStr, Instruction *InsertBefore)
2653 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2654 ->getElementType())->getReturnType(),
2655 Instruction::Invoke,
2656 OperandTraits<InvokeInst>::op_end(this) - Values,
2657 Values, InsertBefore) {
2658 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2659 typename std::iterator_traits<RandomAccessIterator>
2660 ::iterator_category());
2662 template<typename RandomAccessIterator>
2663 InvokeInst::InvokeInst(Value *Func,
2664 BasicBlock *IfNormal, BasicBlock *IfException,
2665 RandomAccessIterator ArgBegin,
2666 RandomAccessIterator ArgEnd,
2668 const Twine &NameStr, BasicBlock *InsertAtEnd)
2669 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2670 ->getElementType())->getReturnType(),
2671 Instruction::Invoke,
2672 OperandTraits<InvokeInst>::op_end(this) - Values,
2673 Values, InsertAtEnd) {
2674 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2675 typename std::iterator_traits<RandomAccessIterator>
2676 ::iterator_category());
2679 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2681 //===----------------------------------------------------------------------===//
2683 //===----------------------------------------------------------------------===//
2685 //===---------------------------------------------------------------------------
2686 /// UnwindInst - Immediately exit the current function, unwinding the stack
2687 /// until an invoke instruction is found.
2689 class UnwindInst : public TerminatorInst {
2690 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2692 virtual UnwindInst *clone_impl() const;
2694 // allocate space for exactly zero operands
2695 void *operator new(size_t s) {
2696 return User::operator new(s, 0);
2698 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2699 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2701 unsigned getNumSuccessors() const { return 0; }
2703 // Methods for support type inquiry through isa, cast, and dyn_cast:
2704 static inline bool classof(const UnwindInst *) { return true; }
2705 static inline bool classof(const Instruction *I) {
2706 return I->getOpcode() == Instruction::Unwind;
2708 static inline bool classof(const Value *V) {
2709 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2712 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2713 virtual unsigned getNumSuccessorsV() const;
2714 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2717 //===----------------------------------------------------------------------===//
2718 // UnreachableInst Class
2719 //===----------------------------------------------------------------------===//
2721 //===---------------------------------------------------------------------------
2722 /// UnreachableInst - This function has undefined behavior. In particular, the
2723 /// presence of this instruction indicates some higher level knowledge that the
2724 /// end of the block cannot be reached.
2726 class UnreachableInst : public TerminatorInst {
2727 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2729 virtual UnreachableInst *clone_impl() const;
2732 // allocate space for exactly zero operands
2733 void *operator new(size_t s) {
2734 return User::operator new(s, 0);
2736 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2737 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2739 unsigned getNumSuccessors() const { return 0; }
2741 // Methods for support type inquiry through isa, cast, and dyn_cast:
2742 static inline bool classof(const UnreachableInst *) { return true; }
2743 static inline bool classof(const Instruction *I) {
2744 return I->getOpcode() == Instruction::Unreachable;
2746 static inline bool classof(const Value *V) {
2747 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2750 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2751 virtual unsigned getNumSuccessorsV() const;
2752 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2755 //===----------------------------------------------------------------------===//
2757 //===----------------------------------------------------------------------===//
2759 /// @brief This class represents a truncation of integer types.
2760 class TruncInst : public CastInst {
2762 /// @brief Clone an identical TruncInst
2763 virtual TruncInst *clone_impl() const;
2766 /// @brief Constructor with insert-before-instruction semantics
2768 Value *S, ///< The value to be truncated
2769 const Type *Ty, ///< The (smaller) type to truncate to
2770 const Twine &NameStr = "", ///< A name for the new instruction
2771 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2774 /// @brief Constructor with insert-at-end-of-block semantics
2776 Value *S, ///< The value to be truncated
2777 const Type *Ty, ///< The (smaller) type to truncate to
2778 const Twine &NameStr, ///< A name for the new instruction
2779 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2782 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2783 static inline bool classof(const TruncInst *) { return true; }
2784 static inline bool classof(const Instruction *I) {
2785 return I->getOpcode() == Trunc;
2787 static inline bool classof(const Value *V) {
2788 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2792 //===----------------------------------------------------------------------===//
2794 //===----------------------------------------------------------------------===//
2796 /// @brief This class represents zero extension of integer types.
2797 class ZExtInst : public CastInst {
2799 /// @brief Clone an identical ZExtInst
2800 virtual ZExtInst *clone_impl() const;
2803 /// @brief Constructor with insert-before-instruction semantics
2805 Value *S, ///< The value to be zero extended
2806 const Type *Ty, ///< The type to zero extend to
2807 const Twine &NameStr = "", ///< A name for the new instruction
2808 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2811 /// @brief Constructor with insert-at-end semantics.
2813 Value *S, ///< The value to be zero extended
2814 const Type *Ty, ///< The type to zero extend to
2815 const Twine &NameStr, ///< A name for the new instruction
2816 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2819 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2820 static inline bool classof(const ZExtInst *) { return true; }
2821 static inline bool classof(const Instruction *I) {
2822 return I->getOpcode() == ZExt;
2824 static inline bool classof(const Value *V) {
2825 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2829 //===----------------------------------------------------------------------===//
2831 //===----------------------------------------------------------------------===//
2833 /// @brief This class represents a sign extension of integer types.
2834 class SExtInst : public CastInst {
2836 /// @brief Clone an identical SExtInst
2837 virtual SExtInst *clone_impl() const;
2840 /// @brief Constructor with insert-before-instruction semantics
2842 Value *S, ///< The value to be sign extended
2843 const Type *Ty, ///< The type to sign extend to
2844 const Twine &NameStr = "", ///< A name for the new instruction
2845 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2848 /// @brief Constructor with insert-at-end-of-block semantics
2850 Value *S, ///< The value to be sign extended
2851 const Type *Ty, ///< The type to sign extend to
2852 const Twine &NameStr, ///< A name for the new instruction
2853 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2856 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2857 static inline bool classof(const SExtInst *) { return true; }
2858 static inline bool classof(const Instruction *I) {
2859 return I->getOpcode() == SExt;
2861 static inline bool classof(const Value *V) {
2862 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2866 //===----------------------------------------------------------------------===//
2867 // FPTruncInst Class
2868 //===----------------------------------------------------------------------===//
2870 /// @brief This class represents a truncation of floating point types.
2871 class FPTruncInst : public CastInst {
2873 /// @brief Clone an identical FPTruncInst
2874 virtual FPTruncInst *clone_impl() const;
2877 /// @brief Constructor with insert-before-instruction semantics
2879 Value *S, ///< The value to be truncated
2880 const Type *Ty, ///< The type to truncate to
2881 const Twine &NameStr = "", ///< A name for the new instruction
2882 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2885 /// @brief Constructor with insert-before-instruction semantics
2887 Value *S, ///< The value to be truncated
2888 const Type *Ty, ///< The type to truncate to
2889 const Twine &NameStr, ///< A name for the new instruction
2890 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2893 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2894 static inline bool classof(const FPTruncInst *) { return true; }
2895 static inline bool classof(const Instruction *I) {
2896 return I->getOpcode() == FPTrunc;
2898 static inline bool classof(const Value *V) {
2899 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2903 //===----------------------------------------------------------------------===//
2905 //===----------------------------------------------------------------------===//
2907 /// @brief This class represents an extension of floating point types.
2908 class FPExtInst : public CastInst {
2910 /// @brief Clone an identical FPExtInst
2911 virtual FPExtInst *clone_impl() const;
2914 /// @brief Constructor with insert-before-instruction semantics
2916 Value *S, ///< The value to be extended
2917 const Type *Ty, ///< The type to extend to
2918 const Twine &NameStr = "", ///< A name for the new instruction
2919 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2922 /// @brief Constructor with insert-at-end-of-block semantics
2924 Value *S, ///< The value to be extended
2925 const Type *Ty, ///< The type to extend to
2926 const Twine &NameStr, ///< A name for the new instruction
2927 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2930 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2931 static inline bool classof(const FPExtInst *) { return true; }
2932 static inline bool classof(const Instruction *I) {
2933 return I->getOpcode() == FPExt;
2935 static inline bool classof(const Value *V) {
2936 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2940 //===----------------------------------------------------------------------===//
2942 //===----------------------------------------------------------------------===//
2944 /// @brief This class represents a cast unsigned integer to floating point.
2945 class UIToFPInst : public CastInst {
2947 /// @brief Clone an identical UIToFPInst
2948 virtual UIToFPInst *clone_impl() const;
2951 /// @brief Constructor with insert-before-instruction semantics
2953 Value *S, ///< The value to be converted
2954 const Type *Ty, ///< The type to convert to
2955 const Twine &NameStr = "", ///< A name for the new instruction
2956 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2959 /// @brief Constructor with insert-at-end-of-block semantics
2961 Value *S, ///< The value to be converted
2962 const Type *Ty, ///< The type to convert to
2963 const Twine &NameStr, ///< A name for the new instruction
2964 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2967 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2968 static inline bool classof(const UIToFPInst *) { return true; }
2969 static inline bool classof(const Instruction *I) {
2970 return I->getOpcode() == UIToFP;
2972 static inline bool classof(const Value *V) {
2973 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2977 //===----------------------------------------------------------------------===//
2979 //===----------------------------------------------------------------------===//
2981 /// @brief This class represents a cast from signed integer to floating point.
2982 class SIToFPInst : public CastInst {
2984 /// @brief Clone an identical SIToFPInst
2985 virtual SIToFPInst *clone_impl() const;
2988 /// @brief Constructor with insert-before-instruction semantics
2990 Value *S, ///< The value to be converted
2991 const Type *Ty, ///< The type to convert to
2992 const Twine &NameStr = "", ///< A name for the new instruction
2993 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2996 /// @brief Constructor with insert-at-end-of-block semantics
2998 Value *S, ///< The value to be converted
2999 const Type *Ty, ///< The type to convert to
3000 const Twine &NameStr, ///< A name for the new instruction
3001 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3004 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3005 static inline bool classof(const SIToFPInst *) { return true; }
3006 static inline bool classof(const Instruction *I) {
3007 return I->getOpcode() == SIToFP;
3009 static inline bool classof(const Value *V) {
3010 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3014 //===----------------------------------------------------------------------===//
3016 //===----------------------------------------------------------------------===//
3018 /// @brief This class represents a cast from floating point to unsigned integer
3019 class FPToUIInst : public CastInst {
3021 /// @brief Clone an identical FPToUIInst
3022 virtual FPToUIInst *clone_impl() const;
3025 /// @brief Constructor with insert-before-instruction semantics
3027 Value *S, ///< The value to be converted
3028 const Type *Ty, ///< The type to convert to
3029 const Twine &NameStr = "", ///< A name for the new instruction
3030 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3033 /// @brief Constructor with insert-at-end-of-block semantics
3035 Value *S, ///< The value to be converted
3036 const Type *Ty, ///< The type to convert to
3037 const Twine &NameStr, ///< A name for the new instruction
3038 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3041 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3042 static inline bool classof(const FPToUIInst *) { return true; }
3043 static inline bool classof(const Instruction *I) {
3044 return I->getOpcode() == FPToUI;
3046 static inline bool classof(const Value *V) {
3047 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3051 //===----------------------------------------------------------------------===//
3053 //===----------------------------------------------------------------------===//
3055 /// @brief This class represents a cast from floating point to signed integer.
3056 class FPToSIInst : public CastInst {
3058 /// @brief Clone an identical FPToSIInst
3059 virtual FPToSIInst *clone_impl() const;
3062 /// @brief Constructor with insert-before-instruction semantics
3064 Value *S, ///< The value to be converted
3065 const Type *Ty, ///< The type to convert to
3066 const Twine &NameStr = "", ///< A name for the new instruction
3067 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3070 /// @brief Constructor with insert-at-end-of-block semantics
3072 Value *S, ///< The value to be converted
3073 const Type *Ty, ///< The type to convert to
3074 const Twine &NameStr, ///< A name for the new instruction
3075 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3078 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3079 static inline bool classof(const FPToSIInst *) { return true; }
3080 static inline bool classof(const Instruction *I) {
3081 return I->getOpcode() == FPToSI;
3083 static inline bool classof(const Value *V) {
3084 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3088 //===----------------------------------------------------------------------===//
3089 // IntToPtrInst Class
3090 //===----------------------------------------------------------------------===//
3092 /// @brief This class represents a cast from an integer to a pointer.
3093 class IntToPtrInst : public CastInst {
3095 /// @brief Constructor with insert-before-instruction semantics
3097 Value *S, ///< The value to be converted
3098 const Type *Ty, ///< The type to convert to
3099 const Twine &NameStr = "", ///< A name for the new instruction
3100 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3103 /// @brief Constructor with insert-at-end-of-block semantics
3105 Value *S, ///< The value to be converted
3106 const Type *Ty, ///< The type to convert to
3107 const Twine &NameStr, ///< A name for the new instruction
3108 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3111 /// @brief Clone an identical IntToPtrInst
3112 virtual IntToPtrInst *clone_impl() const;
3114 // Methods for support type inquiry through isa, cast, and dyn_cast:
3115 static inline bool classof(const IntToPtrInst *) { return true; }
3116 static inline bool classof(const Instruction *I) {
3117 return I->getOpcode() == IntToPtr;
3119 static inline bool classof(const Value *V) {
3120 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3124 //===----------------------------------------------------------------------===//
3125 // PtrToIntInst Class
3126 //===----------------------------------------------------------------------===//
3128 /// @brief This class represents a cast from a pointer to an integer
3129 class PtrToIntInst : public CastInst {
3131 /// @brief Clone an identical PtrToIntInst
3132 virtual PtrToIntInst *clone_impl() const;
3135 /// @brief Constructor with insert-before-instruction semantics
3137 Value *S, ///< The value to be converted
3138 const Type *Ty, ///< The type to convert to
3139 const Twine &NameStr = "", ///< A name for the new instruction
3140 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3143 /// @brief Constructor with insert-at-end-of-block semantics
3145 Value *S, ///< The value to be converted
3146 const Type *Ty, ///< The type to convert to
3147 const Twine &NameStr, ///< A name for the new instruction
3148 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3151 // Methods for support type inquiry through isa, cast, and dyn_cast:
3152 static inline bool classof(const PtrToIntInst *) { return true; }
3153 static inline bool classof(const Instruction *I) {
3154 return I->getOpcode() == PtrToInt;
3156 static inline bool classof(const Value *V) {
3157 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3161 //===----------------------------------------------------------------------===//
3162 // BitCastInst Class
3163 //===----------------------------------------------------------------------===//
3165 /// @brief This class represents a no-op cast from one type to another.
3166 class BitCastInst : public CastInst {
3168 /// @brief Clone an identical BitCastInst
3169 virtual BitCastInst *clone_impl() const;
3172 /// @brief Constructor with insert-before-instruction semantics
3174 Value *S, ///< The value to be casted
3175 const Type *Ty, ///< The type to casted to
3176 const Twine &NameStr = "", ///< A name for the new instruction
3177 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3180 /// @brief Constructor with insert-at-end-of-block semantics
3182 Value *S, ///< The value to be casted
3183 const Type *Ty, ///< The type to casted to
3184 const Twine &NameStr, ///< A name for the new instruction
3185 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3188 // Methods for support type inquiry through isa, cast, and dyn_cast:
3189 static inline bool classof(const BitCastInst *) { return true; }
3190 static inline bool classof(const Instruction *I) {
3191 return I->getOpcode() == BitCast;
3193 static inline bool classof(const Value *V) {
3194 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3198 } // End llvm namespace