1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
19 #include "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/ADT/SmallVector.h"
33 //===----------------------------------------------------------------------===//
35 //===----------------------------------------------------------------------===//
37 /// AllocaInst - an instruction to allocate memory on the stack
39 class AllocaInst : public UnaryInstruction {
41 virtual AllocaInst *clone_impl() const;
43 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
44 const Twine &Name = "", Instruction *InsertBefore = 0);
45 AllocaInst(const Type *Ty, Value *ArraySize,
46 const Twine &Name, BasicBlock *InsertAtEnd);
48 AllocaInst(const Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
49 AllocaInst(const Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
51 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
52 const Twine &Name = "", Instruction *InsertBefore = 0);
53 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
54 const Twine &Name, BasicBlock *InsertAtEnd);
56 // Out of line virtual method, so the vtable, etc. has a home.
57 virtual ~AllocaInst();
59 /// isArrayAllocation - Return true if there is an allocation size parameter
60 /// to the allocation instruction that is not 1.
62 bool isArrayAllocation() const;
64 /// getArraySize - Get the number of elements allocated. For a simple
65 /// allocation of a single element, this will return a constant 1 value.
67 const Value *getArraySize() const { return getOperand(0); }
68 Value *getArraySize() { return getOperand(0); }
70 /// getType - Overload to return most specific pointer type
72 const PointerType *getType() const {
73 return reinterpret_cast<const PointerType*>(Instruction::getType());
76 /// getAllocatedType - Return the type that is being allocated by the
79 const Type *getAllocatedType() const;
81 /// getAlignment - Return the alignment of the memory that is being allocated
82 /// by the instruction.
84 unsigned getAlignment() const {
85 return (1u << getSubclassDataFromInstruction()) >> 1;
87 void setAlignment(unsigned Align);
89 /// isStaticAlloca - Return true if this alloca is in the entry block of the
90 /// function and is a constant size. If so, the code generator will fold it
91 /// into the prolog/epilog code, so it is basically free.
92 bool isStaticAlloca() const;
94 // Methods for support type inquiry through isa, cast, and dyn_cast:
95 static inline bool classof(const AllocaInst *) { return true; }
96 static inline bool classof(const Instruction *I) {
97 return (I->getOpcode() == Instruction::Alloca);
99 static inline bool classof(const Value *V) {
100 return isa<Instruction>(V) && classof(cast<Instruction>(V));
103 // Shadow Instruction::setInstructionSubclassData with a private forwarding
104 // method so that subclasses cannot accidentally use it.
105 void setInstructionSubclassData(unsigned short D) {
106 Instruction::setInstructionSubclassData(D);
111 //===----------------------------------------------------------------------===//
113 //===----------------------------------------------------------------------===//
115 /// LoadInst - an instruction for reading from memory. This uses the
116 /// SubclassData field in Value to store whether or not the load is volatile.
118 class LoadInst : public UnaryInstruction {
121 virtual LoadInst *clone_impl() const;
123 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
124 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
125 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
126 Instruction *InsertBefore = 0);
127 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
128 unsigned Align, Instruction *InsertBefore = 0);
129 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
130 BasicBlock *InsertAtEnd);
131 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
132 unsigned Align, BasicBlock *InsertAtEnd);
134 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
135 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
136 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
137 bool isVolatile = false, Instruction *InsertBefore = 0);
138 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
139 BasicBlock *InsertAtEnd);
141 /// isVolatile - Return true if this is a load from a volatile memory
144 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
146 /// setVolatile - Specify whether this is a volatile load or not.
148 void setVolatile(bool V) {
149 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
153 /// getAlignment - Return the alignment of the access that is being performed
155 unsigned getAlignment() const {
156 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
159 void setAlignment(unsigned Align);
161 Value *getPointerOperand() { return getOperand(0); }
162 const Value *getPointerOperand() const { return getOperand(0); }
163 static unsigned getPointerOperandIndex() { return 0U; }
165 unsigned getPointerAddressSpace() const {
166 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
170 // Methods for support type inquiry through isa, cast, and dyn_cast:
171 static inline bool classof(const LoadInst *) { return true; }
172 static inline bool classof(const Instruction *I) {
173 return I->getOpcode() == Instruction::Load;
175 static inline bool classof(const Value *V) {
176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
179 // Shadow Instruction::setInstructionSubclassData with a private forwarding
180 // method so that subclasses cannot accidentally use it.
181 void setInstructionSubclassData(unsigned short D) {
182 Instruction::setInstructionSubclassData(D);
187 //===----------------------------------------------------------------------===//
189 //===----------------------------------------------------------------------===//
191 /// StoreInst - an instruction for storing to memory
193 class StoreInst : public Instruction {
194 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
197 virtual StoreInst *clone_impl() const;
199 // allocate space for exactly two operands
200 void *operator new(size_t s) {
201 return User::operator new(s, 2);
203 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
204 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
205 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
206 Instruction *InsertBefore = 0);
207 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
208 unsigned Align, Instruction *InsertBefore = 0);
209 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
210 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
211 unsigned Align, BasicBlock *InsertAtEnd);
214 /// isVolatile - Return true if this is a load from a volatile memory
217 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
219 /// setVolatile - Specify whether this is a volatile load or not.
221 void setVolatile(bool V) {
222 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
226 /// Transparently provide more efficient getOperand methods.
227 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
229 /// getAlignment - Return the alignment of the access that is being performed
231 unsigned getAlignment() const {
232 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
235 void setAlignment(unsigned Align);
237 Value *getValueOperand() { return getOperand(0); }
238 const Value *getValueOperand() const { return getOperand(0); }
240 Value *getPointerOperand() { return getOperand(1); }
241 const Value *getPointerOperand() const { return getOperand(1); }
242 static unsigned getPointerOperandIndex() { return 1U; }
244 unsigned getPointerAddressSpace() const {
245 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
248 // Methods for support type inquiry through isa, cast, and dyn_cast:
249 static inline bool classof(const StoreInst *) { return true; }
250 static inline bool classof(const Instruction *I) {
251 return I->getOpcode() == Instruction::Store;
253 static inline bool classof(const Value *V) {
254 return isa<Instruction>(V) && classof(cast<Instruction>(V));
257 // Shadow Instruction::setInstructionSubclassData with a private forwarding
258 // method so that subclasses cannot accidentally use it.
259 void setInstructionSubclassData(unsigned short D) {
260 Instruction::setInstructionSubclassData(D);
265 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<2> {
268 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
270 //===----------------------------------------------------------------------===//
271 // GetElementPtrInst Class
272 //===----------------------------------------------------------------------===//
274 // checkType - Simple wrapper function to give a better assertion failure
275 // message on bad indexes for a gep instruction.
277 static inline const Type *checkType(const Type *Ty) {
278 assert(Ty && "Invalid GetElementPtrInst indices for type!");
282 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
283 /// access elements of arrays and structs
285 class GetElementPtrInst : public Instruction {
286 GetElementPtrInst(const GetElementPtrInst &GEPI);
287 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
288 const Twine &NameStr);
289 void init(Value *Ptr, Value *Idx, const Twine &NameStr);
291 template<typename RandomAccessIterator>
292 void init(Value *Ptr,
293 RandomAccessIterator IdxBegin,
294 RandomAccessIterator IdxEnd,
295 const Twine &NameStr,
296 // This argument ensures that we have an iterator we can
297 // do arithmetic on in constant time
298 std::random_access_iterator_tag) {
299 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
302 // This requires that the iterator points to contiguous memory.
303 init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
304 // we have to build an array here
307 init(Ptr, 0, NumIdx, NameStr);
311 /// getIndexedType - Returns the type of the element that would be loaded with
312 /// a load instruction with the specified parameters.
314 /// Null is returned if the indices are invalid for the specified
317 template<typename RandomAccessIterator>
318 static const Type *getIndexedType(const Type *Ptr,
319 RandomAccessIterator IdxBegin,
320 RandomAccessIterator IdxEnd,
321 // This argument ensures that we
322 // have an iterator we can do
323 // arithmetic on in constant time
324 std::random_access_iterator_tag) {
325 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
328 // This requires that the iterator points to contiguous memory.
329 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
331 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
334 /// Constructors - Create a getelementptr instruction with a base pointer an
335 /// list of indices. The first ctor can optionally insert before an existing
336 /// instruction, the second appends the new instruction to the specified
338 template<typename RandomAccessIterator>
339 inline GetElementPtrInst(Value *Ptr, RandomAccessIterator IdxBegin,
340 RandomAccessIterator IdxEnd,
342 const Twine &NameStr,
343 Instruction *InsertBefore);
344 template<typename RandomAccessIterator>
345 inline GetElementPtrInst(Value *Ptr,
346 RandomAccessIterator IdxBegin,
347 RandomAccessIterator IdxEnd,
349 const Twine &NameStr, BasicBlock *InsertAtEnd);
351 /// Constructors - These two constructors are convenience methods because one
352 /// and two index getelementptr instructions are so common.
353 GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
354 Instruction *InsertBefore = 0);
355 GetElementPtrInst(Value *Ptr, Value *Idx,
356 const Twine &NameStr, BasicBlock *InsertAtEnd);
358 virtual GetElementPtrInst *clone_impl() const;
360 template<typename RandomAccessIterator>
361 static GetElementPtrInst *Create(Value *Ptr, RandomAccessIterator IdxBegin,
362 RandomAccessIterator IdxEnd,
363 const Twine &NameStr = "",
364 Instruction *InsertBefore = 0) {
365 typename std::iterator_traits<RandomAccessIterator>::difference_type
366 Values = 1 + std::distance(IdxBegin, IdxEnd);
368 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
370 template<typename RandomAccessIterator>
371 static GetElementPtrInst *Create(Value *Ptr,
372 RandomAccessIterator IdxBegin,
373 RandomAccessIterator IdxEnd,
374 const Twine &NameStr,
375 BasicBlock *InsertAtEnd) {
376 typename std::iterator_traits<RandomAccessIterator>::difference_type
377 Values = 1 + std::distance(IdxBegin, IdxEnd);
379 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
382 /// Constructors - These two creators are convenience methods because one
383 /// index getelementptr instructions are so common.
384 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
385 const Twine &NameStr = "",
386 Instruction *InsertBefore = 0) {
387 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
389 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
390 const Twine &NameStr,
391 BasicBlock *InsertAtEnd) {
392 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
395 /// Create an "inbounds" getelementptr. See the documentation for the
396 /// "inbounds" flag in LangRef.html for details.
397 template<typename RandomAccessIterator>
398 static GetElementPtrInst *CreateInBounds(Value *Ptr,
399 RandomAccessIterator IdxBegin,
400 RandomAccessIterator IdxEnd,
401 const Twine &NameStr = "",
402 Instruction *InsertBefore = 0) {
403 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
404 NameStr, InsertBefore);
405 GEP->setIsInBounds(true);
408 template<typename RandomAccessIterator>
409 static GetElementPtrInst *CreateInBounds(Value *Ptr,
410 RandomAccessIterator IdxBegin,
411 RandomAccessIterator IdxEnd,
412 const Twine &NameStr,
413 BasicBlock *InsertAtEnd) {
414 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
415 NameStr, InsertAtEnd);
416 GEP->setIsInBounds(true);
419 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
420 const Twine &NameStr = "",
421 Instruction *InsertBefore = 0) {
422 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
423 GEP->setIsInBounds(true);
426 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
427 const Twine &NameStr,
428 BasicBlock *InsertAtEnd) {
429 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
430 GEP->setIsInBounds(true);
434 /// Transparently provide more efficient getOperand methods.
435 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
437 // getType - Overload to return most specific pointer type...
438 const PointerType *getType() const {
439 return reinterpret_cast<const PointerType*>(Instruction::getType());
442 /// getIndexedType - Returns the type of the element that would be loaded with
443 /// a load instruction with the specified parameters.
445 /// Null is returned if the indices are invalid for the specified
448 template<typename RandomAccessIterator>
449 static const Type *getIndexedType(const Type *Ptr,
450 RandomAccessIterator IdxBegin,
451 RandomAccessIterator IdxEnd) {
452 return getIndexedType(Ptr, IdxBegin, IdxEnd,
453 typename std::iterator_traits<RandomAccessIterator>::
454 iterator_category());
457 static const Type *getIndexedType(const Type *Ptr,
458 Value* const *Idx, unsigned NumIdx);
460 static const Type *getIndexedType(const Type *Ptr,
461 uint64_t const *Idx, unsigned NumIdx);
463 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
465 inline op_iterator idx_begin() { return op_begin()+1; }
466 inline const_op_iterator idx_begin() const { return op_begin()+1; }
467 inline op_iterator idx_end() { return op_end(); }
468 inline const_op_iterator idx_end() const { return op_end(); }
470 Value *getPointerOperand() {
471 return getOperand(0);
473 const Value *getPointerOperand() const {
474 return getOperand(0);
476 static unsigned getPointerOperandIndex() {
477 return 0U; // get index for modifying correct operand
480 unsigned getPointerAddressSpace() const {
481 return cast<PointerType>(getType())->getAddressSpace();
484 /// getPointerOperandType - Method to return the pointer operand as a
486 const PointerType *getPointerOperandType() const {
487 return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
491 unsigned getNumIndices() const { // Note: always non-negative
492 return getNumOperands() - 1;
495 bool hasIndices() const {
496 return getNumOperands() > 1;
499 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
500 /// zeros. If so, the result pointer and the first operand have the same
501 /// value, just potentially different types.
502 bool hasAllZeroIndices() const;
504 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
505 /// constant integers. If so, the result pointer and the first operand have
506 /// a constant offset between them.
507 bool hasAllConstantIndices() const;
509 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
510 /// See LangRef.html for the meaning of inbounds on a getelementptr.
511 void setIsInBounds(bool b = true);
513 /// isInBounds - Determine whether the GEP has the inbounds flag.
514 bool isInBounds() const;
516 // Methods for support type inquiry through isa, cast, and dyn_cast:
517 static inline bool classof(const GetElementPtrInst *) { return true; }
518 static inline bool classof(const Instruction *I) {
519 return (I->getOpcode() == Instruction::GetElementPtr);
521 static inline bool classof(const Value *V) {
522 return isa<Instruction>(V) && classof(cast<Instruction>(V));
527 struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<1> {
530 template<typename RandomAccessIterator>
531 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
532 RandomAccessIterator IdxBegin,
533 RandomAccessIterator IdxEnd,
535 const Twine &NameStr,
536 Instruction *InsertBefore)
537 : Instruction(PointerType::get(checkType(
538 getIndexedType(Ptr->getType(),
540 cast<PointerType>(Ptr->getType())
541 ->getAddressSpace()),
543 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
544 Values, InsertBefore) {
545 init(Ptr, IdxBegin, IdxEnd, NameStr,
546 typename std::iterator_traits<RandomAccessIterator>
547 ::iterator_category());
549 template<typename RandomAccessIterator>
550 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
551 RandomAccessIterator IdxBegin,
552 RandomAccessIterator IdxEnd,
554 const Twine &NameStr,
555 BasicBlock *InsertAtEnd)
556 : Instruction(PointerType::get(checkType(
557 getIndexedType(Ptr->getType(),
559 cast<PointerType>(Ptr->getType())
560 ->getAddressSpace()),
562 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
563 Values, InsertAtEnd) {
564 init(Ptr, IdxBegin, IdxEnd, NameStr,
565 typename std::iterator_traits<RandomAccessIterator>
566 ::iterator_category());
570 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
573 //===----------------------------------------------------------------------===//
575 //===----------------------------------------------------------------------===//
577 /// This instruction compares its operands according to the predicate given
578 /// to the constructor. It only operates on integers or pointers. The operands
579 /// must be identical types.
580 /// @brief Represent an integer comparison operator.
581 class ICmpInst: public CmpInst {
583 /// @brief Clone an indentical ICmpInst
584 virtual ICmpInst *clone_impl() const;
586 /// @brief Constructor with insert-before-instruction semantics.
588 Instruction *InsertBefore, ///< Where to insert
589 Predicate pred, ///< The predicate to use for the comparison
590 Value *LHS, ///< The left-hand-side of the expression
591 Value *RHS, ///< The right-hand-side of the expression
592 const Twine &NameStr = "" ///< Name of the instruction
593 ) : CmpInst(makeCmpResultType(LHS->getType()),
594 Instruction::ICmp, pred, LHS, RHS, NameStr,
596 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
597 pred <= CmpInst::LAST_ICMP_PREDICATE &&
598 "Invalid ICmp predicate value");
599 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
600 "Both operands to ICmp instruction are not of the same type!");
601 // Check that the operands are the right type
602 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
603 getOperand(0)->getType()->isPointerTy()) &&
604 "Invalid operand types for ICmp instruction");
607 /// @brief Constructor with insert-at-end semantics.
609 BasicBlock &InsertAtEnd, ///< Block to insert into.
610 Predicate pred, ///< The predicate to use for the comparison
611 Value *LHS, ///< The left-hand-side of the expression
612 Value *RHS, ///< The right-hand-side of the expression
613 const Twine &NameStr = "" ///< Name of the instruction
614 ) : CmpInst(makeCmpResultType(LHS->getType()),
615 Instruction::ICmp, pred, LHS, RHS, NameStr,
617 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
618 pred <= CmpInst::LAST_ICMP_PREDICATE &&
619 "Invalid ICmp predicate value");
620 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
621 "Both operands to ICmp instruction are not of the same type!");
622 // Check that the operands are the right type
623 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
624 getOperand(0)->getType()->isPointerTy()) &&
625 "Invalid operand types for ICmp instruction");
628 /// @brief Constructor with no-insertion semantics
630 Predicate pred, ///< The predicate to use for the comparison
631 Value *LHS, ///< The left-hand-side of the expression
632 Value *RHS, ///< The right-hand-side of the expression
633 const Twine &NameStr = "" ///< Name of the instruction
634 ) : CmpInst(makeCmpResultType(LHS->getType()),
635 Instruction::ICmp, pred, LHS, RHS, NameStr) {
636 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
637 pred <= CmpInst::LAST_ICMP_PREDICATE &&
638 "Invalid ICmp predicate value");
639 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
640 "Both operands to ICmp instruction are not of the same type!");
641 // Check that the operands are the right type
642 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
643 getOperand(0)->getType()->isPointerTy()) &&
644 "Invalid operand types for ICmp instruction");
647 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
648 /// @returns the predicate that would be the result if the operand were
649 /// regarded as signed.
650 /// @brief Return the signed version of the predicate
651 Predicate getSignedPredicate() const {
652 return getSignedPredicate(getPredicate());
655 /// This is a static version that you can use without an instruction.
656 /// @brief Return the signed version of the predicate.
657 static Predicate getSignedPredicate(Predicate pred);
659 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
660 /// @returns the predicate that would be the result if the operand were
661 /// regarded as unsigned.
662 /// @brief Return the unsigned version of the predicate
663 Predicate getUnsignedPredicate() const {
664 return getUnsignedPredicate(getPredicate());
667 /// This is a static version that you can use without an instruction.
668 /// @brief Return the unsigned version of the predicate.
669 static Predicate getUnsignedPredicate(Predicate pred);
671 /// isEquality - Return true if this predicate is either EQ or NE. This also
672 /// tests for commutativity.
673 static bool isEquality(Predicate P) {
674 return P == ICMP_EQ || P == ICMP_NE;
677 /// isEquality - Return true if this predicate is either EQ or NE. This also
678 /// tests for commutativity.
679 bool isEquality() const {
680 return isEquality(getPredicate());
683 /// @returns true if the predicate of this ICmpInst is commutative
684 /// @brief Determine if this relation is commutative.
685 bool isCommutative() const { return isEquality(); }
687 /// isRelational - Return true if the predicate is relational (not EQ or NE).
689 bool isRelational() const {
690 return !isEquality();
693 /// isRelational - Return true if the predicate is relational (not EQ or NE).
695 static bool isRelational(Predicate P) {
696 return !isEquality(P);
699 /// Initialize a set of values that all satisfy the predicate with C.
700 /// @brief Make a ConstantRange for a relation with a constant value.
701 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
703 /// Exchange the two operands to this instruction in such a way that it does
704 /// not modify the semantics of the instruction. The predicate value may be
705 /// changed to retain the same result if the predicate is order dependent
707 /// @brief Swap operands and adjust predicate.
708 void swapOperands() {
709 setPredicate(getSwappedPredicate());
710 Op<0>().swap(Op<1>());
713 // Methods for support type inquiry through isa, cast, and dyn_cast:
714 static inline bool classof(const ICmpInst *) { return true; }
715 static inline bool classof(const Instruction *I) {
716 return I->getOpcode() == Instruction::ICmp;
718 static inline bool classof(const Value *V) {
719 return isa<Instruction>(V) && classof(cast<Instruction>(V));
724 //===----------------------------------------------------------------------===//
726 //===----------------------------------------------------------------------===//
728 /// This instruction compares its operands according to the predicate given
729 /// to the constructor. It only operates on floating point values or packed
730 /// vectors of floating point values. The operands must be identical types.
731 /// @brief Represents a floating point comparison operator.
732 class FCmpInst: public CmpInst {
734 /// @brief Clone an indentical FCmpInst
735 virtual FCmpInst *clone_impl() const;
737 /// @brief Constructor with insert-before-instruction semantics.
739 Instruction *InsertBefore, ///< Where to insert
740 Predicate pred, ///< The predicate to use for the comparison
741 Value *LHS, ///< The left-hand-side of the expression
742 Value *RHS, ///< The right-hand-side of the expression
743 const Twine &NameStr = "" ///< Name of the instruction
744 ) : CmpInst(makeCmpResultType(LHS->getType()),
745 Instruction::FCmp, pred, LHS, RHS, NameStr,
747 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
748 "Invalid FCmp predicate value");
749 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
750 "Both operands to FCmp instruction are not of the same type!");
751 // Check that the operands are the right type
752 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
753 "Invalid operand types for FCmp instruction");
756 /// @brief Constructor with insert-at-end semantics.
758 BasicBlock &InsertAtEnd, ///< Block to insert into.
759 Predicate pred, ///< The predicate to use for the comparison
760 Value *LHS, ///< The left-hand-side of the expression
761 Value *RHS, ///< The right-hand-side of the expression
762 const Twine &NameStr = "" ///< Name of the instruction
763 ) : CmpInst(makeCmpResultType(LHS->getType()),
764 Instruction::FCmp, pred, LHS, RHS, NameStr,
766 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
767 "Invalid FCmp predicate value");
768 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
769 "Both operands to FCmp instruction are not of the same type!");
770 // Check that the operands are the right type
771 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
772 "Invalid operand types for FCmp instruction");
775 /// @brief Constructor with no-insertion semantics
777 Predicate pred, ///< The predicate to use for the comparison
778 Value *LHS, ///< The left-hand-side of the expression
779 Value *RHS, ///< The right-hand-side of the expression
780 const Twine &NameStr = "" ///< Name of the instruction
781 ) : CmpInst(makeCmpResultType(LHS->getType()),
782 Instruction::FCmp, pred, LHS, RHS, NameStr) {
783 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
784 "Invalid FCmp predicate value");
785 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
786 "Both operands to FCmp instruction are not of the same type!");
787 // Check that the operands are the right type
788 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
789 "Invalid operand types for FCmp instruction");
792 /// @returns true if the predicate of this instruction is EQ or NE.
793 /// @brief Determine if this is an equality predicate.
794 bool isEquality() const {
795 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
796 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
799 /// @returns true if the predicate of this instruction is commutative.
800 /// @brief Determine if this is a commutative predicate.
801 bool isCommutative() const {
802 return isEquality() ||
803 getPredicate() == FCMP_FALSE ||
804 getPredicate() == FCMP_TRUE ||
805 getPredicate() == FCMP_ORD ||
806 getPredicate() == FCMP_UNO;
809 /// @returns true if the predicate is relational (not EQ or NE).
810 /// @brief Determine if this a relational predicate.
811 bool isRelational() const { return !isEquality(); }
813 /// Exchange the two operands to this instruction in such a way that it does
814 /// not modify the semantics of the instruction. The predicate value may be
815 /// changed to retain the same result if the predicate is order dependent
817 /// @brief Swap operands and adjust predicate.
818 void swapOperands() {
819 setPredicate(getSwappedPredicate());
820 Op<0>().swap(Op<1>());
823 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
824 static inline bool classof(const FCmpInst *) { return true; }
825 static inline bool classof(const Instruction *I) {
826 return I->getOpcode() == Instruction::FCmp;
828 static inline bool classof(const Value *V) {
829 return isa<Instruction>(V) && classof(cast<Instruction>(V));
833 //===----------------------------------------------------------------------===//
834 /// CallInst - This class represents a function call, abstracting a target
835 /// machine's calling convention. This class uses low bit of the SubClassData
836 /// field to indicate whether or not this is a tail call. The rest of the bits
837 /// hold the calling convention of the call.
839 class CallInst : public Instruction {
840 AttrListPtr AttributeList; ///< parameter attributes for call
841 CallInst(const CallInst &CI);
842 void init(Value *Func, Value* const *Params, unsigned NumParams);
843 void init(Value *Func, Value *Actual1, Value *Actual2);
844 void init(Value *Func, Value *Actual);
845 void init(Value *Func);
847 template<typename RandomAccessIterator>
848 void init(Value *Func,
849 RandomAccessIterator ArgBegin,
850 RandomAccessIterator ArgEnd,
851 const Twine &NameStr,
852 // This argument ensures that we have an iterator we can
853 // do arithmetic on in constant time
854 std::random_access_iterator_tag) {
855 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
857 // This requires that the iterator points to contiguous memory.
858 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
862 /// Construct a CallInst given a range of arguments. RandomAccessIterator
863 /// must be a random-access iterator pointing to contiguous storage
864 /// (e.g. a std::vector<>::iterator). Checks are made for
865 /// random-accessness but not for contiguous storage as that would
866 /// incur runtime overhead.
867 /// @brief Construct a CallInst from a range of arguments
868 template<typename RandomAccessIterator>
869 CallInst(Value *Func,
870 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
871 const Twine &NameStr, Instruction *InsertBefore);
873 /// Construct a CallInst given a range of arguments. RandomAccessIterator
874 /// must be a random-access iterator pointing to contiguous storage
875 /// (e.g. a std::vector<>::iterator). Checks are made for
876 /// random-accessness but not for contiguous storage as that would
877 /// incur runtime overhead.
878 /// @brief Construct a CallInst from a range of arguments
879 template<typename RandomAccessIterator>
880 inline CallInst(Value *Func,
881 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
882 const Twine &NameStr, BasicBlock *InsertAtEnd);
884 CallInst(Value *F, Value *Actual, const Twine &NameStr,
885 Instruction *InsertBefore);
886 CallInst(Value *F, Value *Actual, const Twine &NameStr,
887 BasicBlock *InsertAtEnd);
888 explicit CallInst(Value *F, const Twine &NameStr,
889 Instruction *InsertBefore);
890 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
892 virtual CallInst *clone_impl() const;
894 template<typename RandomAccessIterator>
895 static CallInst *Create(Value *Func,
896 RandomAccessIterator ArgBegin,
897 RandomAccessIterator ArgEnd,
898 const Twine &NameStr = "",
899 Instruction *InsertBefore = 0) {
900 return new(unsigned(ArgEnd - ArgBegin + 1))
901 CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore);
903 template<typename RandomAccessIterator>
904 static CallInst *Create(Value *Func,
905 RandomAccessIterator ArgBegin,
906 RandomAccessIterator ArgEnd,
907 const Twine &NameStr, BasicBlock *InsertAtEnd) {
908 return new(unsigned(ArgEnd - ArgBegin + 1))
909 CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd);
911 static CallInst *Create(Value *F, Value *Actual,
912 const Twine &NameStr = "",
913 Instruction *InsertBefore = 0) {
914 return new(2) CallInst(F, Actual, NameStr, InsertBefore);
916 static CallInst *Create(Value *F, Value *Actual, const Twine &NameStr,
917 BasicBlock *InsertAtEnd) {
918 return new(2) CallInst(F, Actual, NameStr, InsertAtEnd);
920 static CallInst *Create(Value *F, const Twine &NameStr = "",
921 Instruction *InsertBefore = 0) {
922 return new(1) CallInst(F, NameStr, InsertBefore);
924 static CallInst *Create(Value *F, const Twine &NameStr,
925 BasicBlock *InsertAtEnd) {
926 return new(1) CallInst(F, NameStr, InsertAtEnd);
928 /// CreateMalloc - Generate the IR for a call to malloc:
929 /// 1. Compute the malloc call's argument as the specified type's size,
930 /// possibly multiplied by the array size if the array size is not
932 /// 2. Call malloc with that argument.
933 /// 3. Bitcast the result of the malloc call to the specified type.
934 static Instruction *CreateMalloc(Instruction *InsertBefore,
935 const Type *IntPtrTy, const Type *AllocTy,
936 Value *AllocSize, Value *ArraySize = 0,
937 Function* MallocF = 0,
938 const Twine &Name = "");
939 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
940 const Type *IntPtrTy, const Type *AllocTy,
941 Value *AllocSize, Value *ArraySize = 0,
942 Function* MallocF = 0,
943 const Twine &Name = "");
944 /// CreateFree - Generate the IR for a call to the builtin free function.
945 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
946 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
950 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
951 void setTailCall(bool isTC = true) {
952 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
956 /// Provide fast operand accessors
957 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
959 /// getNumArgOperands - Return the number of call arguments.
961 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
963 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
965 Value *getArgOperand(unsigned i) const { return getOperand(i); }
966 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
968 /// getCallingConv/setCallingConv - Get or set the calling convention of this
970 CallingConv::ID getCallingConv() const {
971 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
973 void setCallingConv(CallingConv::ID CC) {
974 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
975 (static_cast<unsigned>(CC) << 1));
978 /// getAttributes - Return the parameter attributes for this call.
980 const AttrListPtr &getAttributes() const { return AttributeList; }
982 /// setAttributes - Set the parameter attributes for this call.
984 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
986 /// addAttribute - adds the attribute to the list of attributes.
987 void addAttribute(unsigned i, Attributes attr);
989 /// removeAttribute - removes the attribute from the list of attributes.
990 void removeAttribute(unsigned i, Attributes attr);
992 /// @brief Determine whether the call or the callee has the given attribute.
993 bool paramHasAttr(unsigned i, Attributes attr) const;
995 /// @brief Extract the alignment for a call or parameter (0=unknown).
996 unsigned getParamAlignment(unsigned i) const {
997 return AttributeList.getParamAlignment(i);
1000 /// @brief Return true if the call should not be inlined.
1001 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
1002 void setIsNoInline(bool Value = true) {
1003 if (Value) addAttribute(~0, Attribute::NoInline);
1004 else removeAttribute(~0, Attribute::NoInline);
1007 /// @brief Determine if the call does not access memory.
1008 bool doesNotAccessMemory() const {
1009 return paramHasAttr(~0, Attribute::ReadNone);
1011 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1012 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1013 else removeAttribute(~0, Attribute::ReadNone);
1016 /// @brief Determine if the call does not access or only reads memory.
1017 bool onlyReadsMemory() const {
1018 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1020 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1021 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1022 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1025 /// @brief Determine if the call cannot return.
1026 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
1027 void setDoesNotReturn(bool DoesNotReturn = true) {
1028 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1029 else removeAttribute(~0, Attribute::NoReturn);
1032 /// @brief Determine if the call cannot unwind.
1033 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
1034 void setDoesNotThrow(bool DoesNotThrow = true) {
1035 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1036 else removeAttribute(~0, Attribute::NoUnwind);
1039 /// @brief Determine if the call returns a structure through first
1040 /// pointer argument.
1041 bool hasStructRetAttr() const {
1042 // Be friendly and also check the callee.
1043 return paramHasAttr(1, Attribute::StructRet);
1046 /// @brief Determine if any call argument is an aggregate passed by value.
1047 bool hasByValArgument() const {
1048 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1051 /// getCalledFunction - Return the function called, or null if this is an
1052 /// indirect function invocation.
1054 Function *getCalledFunction() const {
1055 return dyn_cast<Function>(Op<-1>());
1058 /// getCalledValue - Get a pointer to the function that is invoked by this
1060 const Value *getCalledValue() const { return Op<-1>(); }
1061 Value *getCalledValue() { return Op<-1>(); }
1063 /// setCalledFunction - Set the function called.
1064 void setCalledFunction(Value* Fn) {
1068 /// isInlineAsm - Check if this call is an inline asm statement.
1069 bool isInlineAsm() const {
1070 return isa<InlineAsm>(Op<-1>());
1073 // Methods for support type inquiry through isa, cast, and dyn_cast:
1074 static inline bool classof(const CallInst *) { return true; }
1075 static inline bool classof(const Instruction *I) {
1076 return I->getOpcode() == Instruction::Call;
1078 static inline bool classof(const Value *V) {
1079 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1082 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1083 // method so that subclasses cannot accidentally use it.
1084 void setInstructionSubclassData(unsigned short D) {
1085 Instruction::setInstructionSubclassData(D);
1090 struct OperandTraits<CallInst> : public VariadicOperandTraits<1> {
1093 template<typename RandomAccessIterator>
1094 CallInst::CallInst(Value *Func,
1095 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
1096 const Twine &NameStr, BasicBlock *InsertAtEnd)
1097 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1098 ->getElementType())->getReturnType(),
1100 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1101 unsigned(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1102 init(Func, ArgBegin, ArgEnd, NameStr,
1103 typename std::iterator_traits<RandomAccessIterator>
1104 ::iterator_category());
1107 template<typename RandomAccessIterator>
1108 CallInst::CallInst(Value *Func,
1109 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
1110 const Twine &NameStr, Instruction *InsertBefore)
1111 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1112 ->getElementType())->getReturnType(),
1114 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1115 unsigned(ArgEnd - ArgBegin + 1), InsertBefore) {
1116 init(Func, ArgBegin, ArgEnd, NameStr,
1117 typename std::iterator_traits<RandomAccessIterator>
1118 ::iterator_category());
1122 // Note: if you get compile errors about private methods then
1123 // please update your code to use the high-level operand
1124 // interfaces. See line 943 above.
1125 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1127 //===----------------------------------------------------------------------===//
1129 //===----------------------------------------------------------------------===//
1131 /// SelectInst - This class represents the LLVM 'select' instruction.
1133 class SelectInst : public Instruction {
1134 void init(Value *C, Value *S1, Value *S2) {
1135 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1141 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1142 Instruction *InsertBefore)
1143 : Instruction(S1->getType(), Instruction::Select,
1144 &Op<0>(), 3, InsertBefore) {
1148 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1149 BasicBlock *InsertAtEnd)
1150 : Instruction(S1->getType(), Instruction::Select,
1151 &Op<0>(), 3, InsertAtEnd) {
1156 virtual SelectInst *clone_impl() const;
1158 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1159 const Twine &NameStr = "",
1160 Instruction *InsertBefore = 0) {
1161 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1163 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1164 const Twine &NameStr,
1165 BasicBlock *InsertAtEnd) {
1166 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1169 const Value *getCondition() const { return Op<0>(); }
1170 const Value *getTrueValue() const { return Op<1>(); }
1171 const Value *getFalseValue() const { return Op<2>(); }
1172 Value *getCondition() { return Op<0>(); }
1173 Value *getTrueValue() { return Op<1>(); }
1174 Value *getFalseValue() { return Op<2>(); }
1176 /// areInvalidOperands - Return a string if the specified operands are invalid
1177 /// for a select operation, otherwise return null.
1178 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1180 /// Transparently provide more efficient getOperand methods.
1181 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1183 OtherOps getOpcode() const {
1184 return static_cast<OtherOps>(Instruction::getOpcode());
1187 // Methods for support type inquiry through isa, cast, and dyn_cast:
1188 static inline bool classof(const SelectInst *) { return true; }
1189 static inline bool classof(const Instruction *I) {
1190 return I->getOpcode() == Instruction::Select;
1192 static inline bool classof(const Value *V) {
1193 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1198 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> {
1201 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1203 //===----------------------------------------------------------------------===//
1205 //===----------------------------------------------------------------------===//
1207 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1208 /// an argument of the specified type given a va_list and increments that list
1210 class VAArgInst : public UnaryInstruction {
1212 virtual VAArgInst *clone_impl() const;
1215 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1216 Instruction *InsertBefore = 0)
1217 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1220 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1221 BasicBlock *InsertAtEnd)
1222 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1226 Value *getPointerOperand() { return getOperand(0); }
1227 const Value *getPointerOperand() const { return getOperand(0); }
1228 static unsigned getPointerOperandIndex() { return 0U; }
1230 // Methods for support type inquiry through isa, cast, and dyn_cast:
1231 static inline bool classof(const VAArgInst *) { return true; }
1232 static inline bool classof(const Instruction *I) {
1233 return I->getOpcode() == VAArg;
1235 static inline bool classof(const Value *V) {
1236 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1240 //===----------------------------------------------------------------------===//
1241 // ExtractElementInst Class
1242 //===----------------------------------------------------------------------===//
1244 /// ExtractElementInst - This instruction extracts a single (scalar)
1245 /// element from a VectorType value
1247 class ExtractElementInst : public Instruction {
1248 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1249 Instruction *InsertBefore = 0);
1250 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1251 BasicBlock *InsertAtEnd);
1253 virtual ExtractElementInst *clone_impl() const;
1256 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1257 const Twine &NameStr = "",
1258 Instruction *InsertBefore = 0) {
1259 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1261 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1262 const Twine &NameStr,
1263 BasicBlock *InsertAtEnd) {
1264 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1267 /// isValidOperands - Return true if an extractelement instruction can be
1268 /// formed with the specified operands.
1269 static bool isValidOperands(const Value *Vec, const Value *Idx);
1271 Value *getVectorOperand() { return Op<0>(); }
1272 Value *getIndexOperand() { return Op<1>(); }
1273 const Value *getVectorOperand() const { return Op<0>(); }
1274 const Value *getIndexOperand() const { return Op<1>(); }
1276 const VectorType *getVectorOperandType() const {
1277 return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
1281 /// Transparently provide more efficient getOperand methods.
1282 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1284 // Methods for support type inquiry through isa, cast, and dyn_cast:
1285 static inline bool classof(const ExtractElementInst *) { return true; }
1286 static inline bool classof(const Instruction *I) {
1287 return I->getOpcode() == Instruction::ExtractElement;
1289 static inline bool classof(const Value *V) {
1290 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1295 struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> {
1298 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1300 //===----------------------------------------------------------------------===//
1301 // InsertElementInst Class
1302 //===----------------------------------------------------------------------===//
1304 /// InsertElementInst - This instruction inserts a single (scalar)
1305 /// element into a VectorType value
1307 class InsertElementInst : public Instruction {
1308 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1309 const Twine &NameStr = "",
1310 Instruction *InsertBefore = 0);
1311 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1312 const Twine &NameStr, BasicBlock *InsertAtEnd);
1314 virtual InsertElementInst *clone_impl() const;
1317 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1318 const Twine &NameStr = "",
1319 Instruction *InsertBefore = 0) {
1320 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1322 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1323 const Twine &NameStr,
1324 BasicBlock *InsertAtEnd) {
1325 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1328 /// isValidOperands - Return true if an insertelement instruction can be
1329 /// formed with the specified operands.
1330 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1333 /// getType - Overload to return most specific vector type.
1335 const VectorType *getType() const {
1336 return reinterpret_cast<const VectorType*>(Instruction::getType());
1339 /// Transparently provide more efficient getOperand methods.
1340 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1342 // Methods for support type inquiry through isa, cast, and dyn_cast:
1343 static inline bool classof(const InsertElementInst *) { return true; }
1344 static inline bool classof(const Instruction *I) {
1345 return I->getOpcode() == Instruction::InsertElement;
1347 static inline bool classof(const Value *V) {
1348 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1353 struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
1356 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1358 //===----------------------------------------------------------------------===//
1359 // ShuffleVectorInst Class
1360 //===----------------------------------------------------------------------===//
1362 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1365 class ShuffleVectorInst : public Instruction {
1367 virtual ShuffleVectorInst *clone_impl() const;
1370 // allocate space for exactly three operands
1371 void *operator new(size_t s) {
1372 return User::operator new(s, 3);
1374 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1375 const Twine &NameStr = "",
1376 Instruction *InsertBefor = 0);
1377 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1378 const Twine &NameStr, BasicBlock *InsertAtEnd);
1380 /// isValidOperands - Return true if a shufflevector instruction can be
1381 /// formed with the specified operands.
1382 static bool isValidOperands(const Value *V1, const Value *V2,
1385 /// getType - Overload to return most specific vector type.
1387 const VectorType *getType() const {
1388 return reinterpret_cast<const VectorType*>(Instruction::getType());
1391 /// Transparently provide more efficient getOperand methods.
1392 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1394 /// getMaskValue - Return the index from the shuffle mask for the specified
1395 /// output result. This is either -1 if the element is undef or a number less
1396 /// than 2*numelements.
1397 int getMaskValue(unsigned i) const;
1399 // Methods for support type inquiry through isa, cast, and dyn_cast:
1400 static inline bool classof(const ShuffleVectorInst *) { return true; }
1401 static inline bool classof(const Instruction *I) {
1402 return I->getOpcode() == Instruction::ShuffleVector;
1404 static inline bool classof(const Value *V) {
1405 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1410 struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
1413 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1415 //===----------------------------------------------------------------------===//
1416 // ExtractValueInst Class
1417 //===----------------------------------------------------------------------===//
1419 /// ExtractValueInst - This instruction extracts a struct member or array
1420 /// element value from an aggregate value.
1422 class ExtractValueInst : public UnaryInstruction {
1423 SmallVector<unsigned, 4> Indices;
1425 ExtractValueInst(const ExtractValueInst &EVI);
1426 void init(const unsigned *Idx, unsigned NumIdx,
1427 const Twine &NameStr);
1428 void init(unsigned Idx, const Twine &NameStr);
1430 template<typename RandomAccessIterator>
1431 void init(RandomAccessIterator IdxBegin,
1432 RandomAccessIterator IdxEnd,
1433 const Twine &NameStr,
1434 // This argument ensures that we have an iterator we can
1435 // do arithmetic on in constant time
1436 std::random_access_iterator_tag) {
1437 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1439 // There's no fundamental reason why we require at least one index
1440 // (other than weirdness with &*IdxBegin being invalid; see
1441 // getelementptr's init routine for example). But there's no
1442 // present need to support it.
1443 assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
1445 // This requires that the iterator points to contiguous memory.
1446 init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1447 // we have to build an array here
1450 /// getIndexedType - Returns the type of the element that would be extracted
1451 /// with an extractvalue instruction with the specified parameters.
1453 /// Null is returned if the indices are invalid for the specified type.
1455 static const Type *getIndexedType(const Type *Agg,
1456 const unsigned *Idx, unsigned NumIdx);
1458 template<typename RandomAccessIterator>
1459 static const Type *getIndexedType(const Type *Ptr,
1460 RandomAccessIterator IdxBegin,
1461 RandomAccessIterator IdxEnd,
1462 // This argument ensures that we
1463 // have an iterator we can do
1464 // arithmetic on in constant time
1465 std::random_access_iterator_tag) {
1466 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1469 // This requires that the iterator points to contiguous memory.
1470 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
1472 return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
1475 /// Constructors - Create a extractvalue instruction with a base aggregate
1476 /// value and a list of indices. The first ctor can optionally insert before
1477 /// an existing instruction, the second appends the new instruction to the
1478 /// specified BasicBlock.
1479 template<typename RandomAccessIterator>
1480 inline ExtractValueInst(Value *Agg,
1481 RandomAccessIterator IdxBegin,
1482 RandomAccessIterator IdxEnd,
1483 const Twine &NameStr,
1484 Instruction *InsertBefore);
1485 template<typename RandomAccessIterator>
1486 inline ExtractValueInst(Value *Agg,
1487 RandomAccessIterator IdxBegin,
1488 RandomAccessIterator IdxEnd,
1489 const Twine &NameStr, BasicBlock *InsertAtEnd);
1491 // allocate space for exactly one operand
1492 void *operator new(size_t s) {
1493 return User::operator new(s, 1);
1496 virtual ExtractValueInst *clone_impl() const;
1499 template<typename RandomAccessIterator>
1500 static ExtractValueInst *Create(Value *Agg,
1501 RandomAccessIterator IdxBegin,
1502 RandomAccessIterator IdxEnd,
1503 const Twine &NameStr = "",
1504 Instruction *InsertBefore = 0) {
1506 ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
1508 template<typename RandomAccessIterator>
1509 static ExtractValueInst *Create(Value *Agg,
1510 RandomAccessIterator IdxBegin,
1511 RandomAccessIterator IdxEnd,
1512 const Twine &NameStr,
1513 BasicBlock *InsertAtEnd) {
1514 return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
1517 /// Constructors - These two creators are convenience methods because one
1518 /// index extractvalue instructions are much more common than those with
1520 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1521 const Twine &NameStr = "",
1522 Instruction *InsertBefore = 0) {
1523 unsigned Idxs[1] = { Idx };
1524 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
1526 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1527 const Twine &NameStr,
1528 BasicBlock *InsertAtEnd) {
1529 unsigned Idxs[1] = { Idx };
1530 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
1533 /// getIndexedType - Returns the type of the element that would be extracted
1534 /// with an extractvalue instruction with the specified parameters.
1536 /// Null is returned if the indices are invalid for the specified type.
1538 template<typename RandomAccessIterator>
1539 static const Type *getIndexedType(const Type *Ptr,
1540 RandomAccessIterator IdxBegin,
1541 RandomAccessIterator IdxEnd) {
1542 return getIndexedType(Ptr, IdxBegin, IdxEnd,
1543 typename std::iterator_traits<RandomAccessIterator>::
1544 iterator_category());
1546 static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
1548 typedef const unsigned* idx_iterator;
1549 inline idx_iterator idx_begin() const { return Indices.begin(); }
1550 inline idx_iterator idx_end() const { return Indices.end(); }
1552 Value *getAggregateOperand() {
1553 return getOperand(0);
1555 const Value *getAggregateOperand() const {
1556 return getOperand(0);
1558 static unsigned getAggregateOperandIndex() {
1559 return 0U; // get index for modifying correct operand
1562 unsigned getNumIndices() const { // Note: always non-negative
1563 return (unsigned)Indices.size();
1566 bool hasIndices() const {
1570 // Methods for support type inquiry through isa, cast, and dyn_cast:
1571 static inline bool classof(const ExtractValueInst *) { return true; }
1572 static inline bool classof(const Instruction *I) {
1573 return I->getOpcode() == Instruction::ExtractValue;
1575 static inline bool classof(const Value *V) {
1576 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1580 template<typename RandomAccessIterator>
1581 ExtractValueInst::ExtractValueInst(Value *Agg,
1582 RandomAccessIterator IdxBegin,
1583 RandomAccessIterator IdxEnd,
1584 const Twine &NameStr,
1585 Instruction *InsertBefore)
1586 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1588 ExtractValue, Agg, InsertBefore) {
1589 init(IdxBegin, IdxEnd, NameStr,
1590 typename std::iterator_traits<RandomAccessIterator>
1591 ::iterator_category());
1593 template<typename RandomAccessIterator>
1594 ExtractValueInst::ExtractValueInst(Value *Agg,
1595 RandomAccessIterator IdxBegin,
1596 RandomAccessIterator IdxEnd,
1597 const Twine &NameStr,
1598 BasicBlock *InsertAtEnd)
1599 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1601 ExtractValue, Agg, InsertAtEnd) {
1602 init(IdxBegin, IdxEnd, NameStr,
1603 typename std::iterator_traits<RandomAccessIterator>
1604 ::iterator_category());
1608 //===----------------------------------------------------------------------===//
1609 // InsertValueInst Class
1610 //===----------------------------------------------------------------------===//
1612 /// InsertValueInst - This instruction inserts a struct field of array element
1613 /// value into an aggregate value.
1615 class InsertValueInst : public Instruction {
1616 SmallVector<unsigned, 4> Indices;
1618 void *operator new(size_t, unsigned); // Do not implement
1619 InsertValueInst(const InsertValueInst &IVI);
1620 void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1621 const Twine &NameStr);
1622 void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
1624 template<typename RandomAccessIterator>
1625 void init(Value *Agg, Value *Val,
1626 RandomAccessIterator IdxBegin, RandomAccessIterator IdxEnd,
1627 const Twine &NameStr,
1628 // This argument ensures that we have an iterator we can
1629 // do arithmetic on in constant time
1630 std::random_access_iterator_tag) {
1631 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1633 // There's no fundamental reason why we require at least one index
1634 // (other than weirdness with &*IdxBegin being invalid; see
1635 // getelementptr's init routine for example). But there's no
1636 // present need to support it.
1637 assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1639 // This requires that the iterator points to contiguous memory.
1640 init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1641 // we have to build an array here
1644 /// Constructors - Create a insertvalue instruction with a base aggregate
1645 /// value, a value to insert, and a list of indices. The first ctor can
1646 /// optionally insert before an existing instruction, the second appends
1647 /// the new instruction to the specified BasicBlock.
1648 template<typename RandomAccessIterator>
1649 inline InsertValueInst(Value *Agg, Value *Val,
1650 RandomAccessIterator IdxBegin,
1651 RandomAccessIterator IdxEnd,
1652 const Twine &NameStr,
1653 Instruction *InsertBefore);
1654 template<typename RandomAccessIterator>
1655 inline InsertValueInst(Value *Agg, Value *Val,
1656 RandomAccessIterator IdxBegin,
1657 RandomAccessIterator IdxEnd,
1658 const Twine &NameStr, BasicBlock *InsertAtEnd);
1660 /// Constructors - These two constructors are convenience methods because one
1661 /// and two index insertvalue instructions are so common.
1662 InsertValueInst(Value *Agg, Value *Val,
1663 unsigned Idx, const Twine &NameStr = "",
1664 Instruction *InsertBefore = 0);
1665 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1666 const Twine &NameStr, BasicBlock *InsertAtEnd);
1668 virtual InsertValueInst *clone_impl() const;
1670 // allocate space for exactly two operands
1671 void *operator new(size_t s) {
1672 return User::operator new(s, 2);
1675 template<typename RandomAccessIterator>
1676 static InsertValueInst *Create(Value *Agg, Value *Val,
1677 RandomAccessIterator IdxBegin,
1678 RandomAccessIterator IdxEnd,
1679 const Twine &NameStr = "",
1680 Instruction *InsertBefore = 0) {
1681 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1682 NameStr, InsertBefore);
1684 template<typename RandomAccessIterator>
1685 static InsertValueInst *Create(Value *Agg, Value *Val,
1686 RandomAccessIterator IdxBegin,
1687 RandomAccessIterator IdxEnd,
1688 const Twine &NameStr,
1689 BasicBlock *InsertAtEnd) {
1690 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1691 NameStr, InsertAtEnd);
1694 /// Constructors - These two creators are convenience methods because one
1695 /// index insertvalue instructions are much more common than those with
1697 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1698 const Twine &NameStr = "",
1699 Instruction *InsertBefore = 0) {
1700 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
1702 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1703 const Twine &NameStr,
1704 BasicBlock *InsertAtEnd) {
1705 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
1708 /// Transparently provide more efficient getOperand methods.
1709 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1711 typedef const unsigned* idx_iterator;
1712 inline idx_iterator idx_begin() const { return Indices.begin(); }
1713 inline idx_iterator idx_end() const { return Indices.end(); }
1715 Value *getAggregateOperand() {
1716 return getOperand(0);
1718 const Value *getAggregateOperand() const {
1719 return getOperand(0);
1721 static unsigned getAggregateOperandIndex() {
1722 return 0U; // get index for modifying correct operand
1725 Value *getInsertedValueOperand() {
1726 return getOperand(1);
1728 const Value *getInsertedValueOperand() const {
1729 return getOperand(1);
1731 static unsigned getInsertedValueOperandIndex() {
1732 return 1U; // get index for modifying correct operand
1735 unsigned getNumIndices() const { // Note: always non-negative
1736 return (unsigned)Indices.size();
1739 bool hasIndices() const {
1743 // Methods for support type inquiry through isa, cast, and dyn_cast:
1744 static inline bool classof(const InsertValueInst *) { return true; }
1745 static inline bool classof(const Instruction *I) {
1746 return I->getOpcode() == Instruction::InsertValue;
1748 static inline bool classof(const Value *V) {
1749 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1754 struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
1757 template<typename RandomAccessIterator>
1758 InsertValueInst::InsertValueInst(Value *Agg,
1760 RandomAccessIterator IdxBegin,
1761 RandomAccessIterator IdxEnd,
1762 const Twine &NameStr,
1763 Instruction *InsertBefore)
1764 : Instruction(Agg->getType(), InsertValue,
1765 OperandTraits<InsertValueInst>::op_begin(this),
1767 init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1768 typename std::iterator_traits<RandomAccessIterator>
1769 ::iterator_category());
1771 template<typename RandomAccessIterator>
1772 InsertValueInst::InsertValueInst(Value *Agg,
1774 RandomAccessIterator IdxBegin,
1775 RandomAccessIterator IdxEnd,
1776 const Twine &NameStr,
1777 BasicBlock *InsertAtEnd)
1778 : Instruction(Agg->getType(), InsertValue,
1779 OperandTraits<InsertValueInst>::op_begin(this),
1781 init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1782 typename std::iterator_traits<RandomAccessIterator>
1783 ::iterator_category());
1786 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1788 //===----------------------------------------------------------------------===//
1790 //===----------------------------------------------------------------------===//
1792 // PHINode - The PHINode class is used to represent the magical mystical PHI
1793 // node, that can not exist in nature, but can be synthesized in a computer
1794 // scientist's overactive imagination.
1796 class PHINode : public Instruction {
1797 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1798 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1799 /// the number actually in use.
1800 unsigned ReservedSpace;
1801 PHINode(const PHINode &PN);
1802 // allocate space for exactly zero operands
1803 void *operator new(size_t s) {
1804 return User::operator new(s, 0);
1806 explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1807 Instruction *InsertBefore = 0)
1808 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1813 PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1814 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1819 virtual PHINode *clone_impl() const;
1821 static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1822 Instruction *InsertBefore = 0) {
1823 return new PHINode(Ty, NameStr, InsertBefore);
1825 static PHINode *Create(const Type *Ty, const Twine &NameStr,
1826 BasicBlock *InsertAtEnd) {
1827 return new PHINode(Ty, NameStr, InsertAtEnd);
1831 /// reserveOperandSpace - This method can be used to avoid repeated
1832 /// reallocation of PHI operand lists by reserving space for the correct
1833 /// number of operands before adding them. Unlike normal vector reserves,
1834 /// this method can also be used to trim the operand space.
1835 void reserveOperandSpace(unsigned NumValues) {
1836 resizeOperands(NumValues*2);
1839 /// Provide fast operand accessors
1840 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1842 /// getNumIncomingValues - Return the number of incoming edges
1844 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1846 /// getIncomingValue - Return incoming value number x
1848 Value *getIncomingValue(unsigned i) const {
1849 assert(i*2 < getNumOperands() && "Invalid value number!");
1850 return getOperand(i*2);
1852 void setIncomingValue(unsigned i, Value *V) {
1853 assert(i*2 < getNumOperands() && "Invalid value number!");
1856 static unsigned getOperandNumForIncomingValue(unsigned i) {
1859 static unsigned getIncomingValueNumForOperand(unsigned i) {
1860 assert(i % 2 == 0 && "Invalid incoming-value operand index!");
1864 /// getIncomingBlock - Return incoming basic block number @p i.
1866 BasicBlock *getIncomingBlock(unsigned i) const {
1867 return cast<BasicBlock>(getOperand(i*2+1));
1870 /// getIncomingBlock - Return incoming basic block corresponding
1871 /// to an operand of the PHI.
1873 BasicBlock *getIncomingBlock(const Use &U) const {
1874 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1875 return cast<BasicBlock>((&U + 1)->get());
1878 /// getIncomingBlock - Return incoming basic block corresponding
1879 /// to value use iterator.
1881 template <typename U>
1882 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1883 return getIncomingBlock(I.getUse());
1887 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1888 setOperand(i*2+1, (Value*)BB);
1890 static unsigned getOperandNumForIncomingBlock(unsigned i) {
1893 static unsigned getIncomingBlockNumForOperand(unsigned i) {
1894 assert(i % 2 == 1 && "Invalid incoming-block operand index!");
1898 /// addIncoming - Add an incoming value to the end of the PHI list
1900 void addIncoming(Value *V, BasicBlock *BB) {
1901 assert(V && "PHI node got a null value!");
1902 assert(BB && "PHI node got a null basic block!");
1903 assert(getType() == V->getType() &&
1904 "All operands to PHI node must be the same type as the PHI node!");
1905 unsigned OpNo = NumOperands;
1906 if (OpNo+2 > ReservedSpace)
1907 resizeOperands(0); // Get more space!
1908 // Initialize some new operands.
1909 NumOperands = OpNo+2;
1910 OperandList[OpNo] = V;
1911 OperandList[OpNo+1] = (Value*)BB;
1914 /// removeIncomingValue - Remove an incoming value. This is useful if a
1915 /// predecessor basic block is deleted. The value removed is returned.
1917 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1918 /// is true), the PHI node is destroyed and any uses of it are replaced with
1919 /// dummy values. The only time there should be zero incoming values to a PHI
1920 /// node is when the block is dead, so this strategy is sound.
1922 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1924 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1925 int Idx = getBasicBlockIndex(BB);
1926 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1927 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1930 /// getBasicBlockIndex - Return the first index of the specified basic
1931 /// block in the value list for this PHI. Returns -1 if no instance.
1933 int getBasicBlockIndex(const BasicBlock *BB) const {
1934 Use *OL = OperandList;
1935 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1936 if (OL[i+1].get() == (const Value*)BB) return i/2;
1940 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1941 return getIncomingValue(getBasicBlockIndex(BB));
1944 /// hasConstantValue - If the specified PHI node always merges together the
1945 /// same value, return the value, otherwise return null.
1946 Value *hasConstantValue() const;
1948 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1949 static inline bool classof(const PHINode *) { return true; }
1950 static inline bool classof(const Instruction *I) {
1951 return I->getOpcode() == Instruction::PHI;
1953 static inline bool classof(const Value *V) {
1954 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1957 void resizeOperands(unsigned NumOperands);
1961 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1964 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1967 //===----------------------------------------------------------------------===//
1969 //===----------------------------------------------------------------------===//
1971 //===---------------------------------------------------------------------------
1972 /// ReturnInst - Return a value (possibly void), from a function. Execution
1973 /// does not continue in this function any longer.
1975 class ReturnInst : public TerminatorInst {
1976 ReturnInst(const ReturnInst &RI);
1979 // ReturnInst constructors:
1980 // ReturnInst() - 'ret void' instruction
1981 // ReturnInst( null) - 'ret void' instruction
1982 // ReturnInst(Value* X) - 'ret X' instruction
1983 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1984 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1985 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1986 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1988 // NOTE: If the Value* passed is of type void then the constructor behaves as
1989 // if it was passed NULL.
1990 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1991 Instruction *InsertBefore = 0);
1992 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1993 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1995 virtual ReturnInst *clone_impl() const;
1997 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1998 Instruction *InsertBefore = 0) {
1999 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2001 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2002 BasicBlock *InsertAtEnd) {
2003 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2005 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2006 return new(0) ReturnInst(C, InsertAtEnd);
2008 virtual ~ReturnInst();
2010 /// Provide fast operand accessors
2011 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2013 /// Convenience accessor. Returns null if there is no return value.
2014 Value *getReturnValue() const {
2015 return getNumOperands() != 0 ? getOperand(0) : 0;
2018 unsigned getNumSuccessors() const { return 0; }
2020 // Methods for support type inquiry through isa, cast, and dyn_cast:
2021 static inline bool classof(const ReturnInst *) { return true; }
2022 static inline bool classof(const Instruction *I) {
2023 return (I->getOpcode() == Instruction::Ret);
2025 static inline bool classof(const Value *V) {
2026 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2029 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2030 virtual unsigned getNumSuccessorsV() const;
2031 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2035 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<> {
2038 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2040 //===----------------------------------------------------------------------===//
2042 //===----------------------------------------------------------------------===//
2044 //===---------------------------------------------------------------------------
2045 /// BranchInst - Conditional or Unconditional Branch instruction.
2047 class BranchInst : public TerminatorInst {
2048 /// Ops list - Branches are strange. The operands are ordered:
2049 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2050 /// they don't have to check for cond/uncond branchness. These are mostly
2051 /// accessed relative from op_end().
2052 BranchInst(const BranchInst &BI);
2054 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2055 // BranchInst(BB *B) - 'br B'
2056 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2057 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2058 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2059 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2060 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2061 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2062 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2063 Instruction *InsertBefore = 0);
2064 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2065 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2066 BasicBlock *InsertAtEnd);
2068 virtual BranchInst *clone_impl() const;
2070 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2071 return new(1, true) BranchInst(IfTrue, InsertBefore);
2073 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2074 Value *Cond, Instruction *InsertBefore = 0) {
2075 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2077 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2078 return new(1, true) BranchInst(IfTrue, InsertAtEnd);
2080 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2081 Value *Cond, BasicBlock *InsertAtEnd) {
2082 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2087 /// Transparently provide more efficient getOperand methods.
2088 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2090 bool isUnconditional() const { return getNumOperands() == 1; }
2091 bool isConditional() const { return getNumOperands() == 3; }
2093 Value *getCondition() const {
2094 assert(isConditional() && "Cannot get condition of an uncond branch!");
2098 void setCondition(Value *V) {
2099 assert(isConditional() && "Cannot set condition of unconditional branch!");
2103 // setUnconditionalDest - Change the current branch to an unconditional branch
2104 // targeting the specified block.
2105 // FIXME: Eliminate this ugly method.
2106 void setUnconditionalDest(BasicBlock *Dest) {
2107 Op<-1>() = (Value*)Dest;
2108 if (isConditional()) { // Convert this to an uncond branch.
2112 OperandList = op_begin();
2116 unsigned getNumSuccessors() const { return 1+isConditional(); }
2118 BasicBlock *getSuccessor(unsigned i) const {
2119 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2120 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2123 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2124 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2125 *(&Op<-1>() - idx) = (Value*)NewSucc;
2128 // Methods for support type inquiry through isa, cast, and dyn_cast:
2129 static inline bool classof(const BranchInst *) { return true; }
2130 static inline bool classof(const Instruction *I) {
2131 return (I->getOpcode() == Instruction::Br);
2133 static inline bool classof(const Value *V) {
2134 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2137 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2138 virtual unsigned getNumSuccessorsV() const;
2139 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2143 struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
2145 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2147 //===----------------------------------------------------------------------===//
2149 //===----------------------------------------------------------------------===//
2151 //===---------------------------------------------------------------------------
2152 /// SwitchInst - Multiway switch
2154 class SwitchInst : public TerminatorInst {
2155 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2156 unsigned ReservedSpace;
2157 // Operand[0] = Value to switch on
2158 // Operand[1] = Default basic block destination
2159 // Operand[2n ] = Value to match
2160 // Operand[2n+1] = BasicBlock to go to on match
2161 SwitchInst(const SwitchInst &SI);
2162 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2163 void resizeOperands(unsigned No);
2164 // allocate space for exactly zero operands
2165 void *operator new(size_t s) {
2166 return User::operator new(s, 0);
2168 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2169 /// switch on and a default destination. The number of additional cases can
2170 /// be specified here to make memory allocation more efficient. This
2171 /// constructor can also autoinsert before another instruction.
2172 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2173 Instruction *InsertBefore);
2175 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2176 /// switch on and a default destination. The number of additional cases can
2177 /// be specified here to make memory allocation more efficient. This
2178 /// constructor also autoinserts at the end of the specified BasicBlock.
2179 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2180 BasicBlock *InsertAtEnd);
2182 virtual SwitchInst *clone_impl() const;
2184 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2185 unsigned NumCases, Instruction *InsertBefore = 0) {
2186 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2188 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2189 unsigned NumCases, BasicBlock *InsertAtEnd) {
2190 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2194 /// Provide fast operand accessors
2195 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2197 // Accessor Methods for Switch stmt
2198 Value *getCondition() const { return getOperand(0); }
2199 void setCondition(Value *V) { setOperand(0, V); }
2201 BasicBlock *getDefaultDest() const {
2202 return cast<BasicBlock>(getOperand(1));
2205 /// getNumCases - return the number of 'cases' in this switch instruction.
2206 /// Note that case #0 is always the default case.
2207 unsigned getNumCases() const {
2208 return getNumOperands()/2;
2211 /// getCaseValue - Return the specified case value. Note that case #0, the
2212 /// default destination, does not have a case value.
2213 ConstantInt *getCaseValue(unsigned i) {
2214 assert(i && i < getNumCases() && "Illegal case value to get!");
2215 return getSuccessorValue(i);
2218 /// getCaseValue - Return the specified case value. Note that case #0, the
2219 /// default destination, does not have a case value.
2220 const ConstantInt *getCaseValue(unsigned i) const {
2221 assert(i && i < getNumCases() && "Illegal case value to get!");
2222 return getSuccessorValue(i);
2225 /// findCaseValue - Search all of the case values for the specified constant.
2226 /// If it is explicitly handled, return the case number of it, otherwise
2227 /// return 0 to indicate that it is handled by the default handler.
2228 unsigned findCaseValue(const ConstantInt *C) const {
2229 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2230 if (getCaseValue(i) == C)
2235 /// findCaseDest - Finds the unique case value for a given successor. Returns
2236 /// null if the successor is not found, not unique, or is the default case.
2237 ConstantInt *findCaseDest(BasicBlock *BB) {
2238 if (BB == getDefaultDest()) return NULL;
2240 ConstantInt *CI = NULL;
2241 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2242 if (getSuccessor(i) == BB) {
2243 if (CI) return NULL; // Multiple cases lead to BB.
2244 else CI = getCaseValue(i);
2250 /// addCase - Add an entry to the switch instruction...
2252 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2254 /// removeCase - This method removes the specified successor from the switch
2255 /// instruction. Note that this cannot be used to remove the default
2256 /// destination (successor #0).
2258 void removeCase(unsigned idx);
2260 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2261 BasicBlock *getSuccessor(unsigned idx) const {
2262 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2263 return cast<BasicBlock>(getOperand(idx*2+1));
2265 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2266 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2267 setOperand(idx*2+1, (Value*)NewSucc);
2270 // getSuccessorValue - Return the value associated with the specified
2272 ConstantInt *getSuccessorValue(unsigned idx) const {
2273 assert(idx < getNumSuccessors() && "Successor # out of range!");
2274 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2277 // Methods for support type inquiry through isa, cast, and dyn_cast:
2278 static inline bool classof(const SwitchInst *) { return true; }
2279 static inline bool classof(const Instruction *I) {
2280 return I->getOpcode() == Instruction::Switch;
2282 static inline bool classof(const Value *V) {
2283 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2286 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2287 virtual unsigned getNumSuccessorsV() const;
2288 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2292 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2295 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2298 //===----------------------------------------------------------------------===//
2299 // IndirectBrInst Class
2300 //===----------------------------------------------------------------------===//
2302 //===---------------------------------------------------------------------------
2303 /// IndirectBrInst - Indirect Branch Instruction.
2305 class IndirectBrInst : public TerminatorInst {
2306 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2307 unsigned ReservedSpace;
2308 // Operand[0] = Value to switch on
2309 // Operand[1] = Default basic block destination
2310 // Operand[2n ] = Value to match
2311 // Operand[2n+1] = BasicBlock to go to on match
2312 IndirectBrInst(const IndirectBrInst &IBI);
2313 void init(Value *Address, unsigned NumDests);
2314 void resizeOperands(unsigned No);
2315 // allocate space for exactly zero operands
2316 void *operator new(size_t s) {
2317 return User::operator new(s, 0);
2319 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2320 /// Address to jump to. The number of expected destinations can be specified
2321 /// here to make memory allocation more efficient. This constructor can also
2322 /// autoinsert before another instruction.
2323 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2325 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2326 /// Address to jump to. The number of expected destinations can be specified
2327 /// here to make memory allocation more efficient. This constructor also
2328 /// autoinserts at the end of the specified BasicBlock.
2329 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2331 virtual IndirectBrInst *clone_impl() const;
2333 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2334 Instruction *InsertBefore = 0) {
2335 return new IndirectBrInst(Address, NumDests, InsertBefore);
2337 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2338 BasicBlock *InsertAtEnd) {
2339 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2343 /// Provide fast operand accessors.
2344 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2346 // Accessor Methods for IndirectBrInst instruction.
2347 Value *getAddress() { return getOperand(0); }
2348 const Value *getAddress() const { return getOperand(0); }
2349 void setAddress(Value *V) { setOperand(0, V); }
2352 /// getNumDestinations - return the number of possible destinations in this
2353 /// indirectbr instruction.
2354 unsigned getNumDestinations() const { return getNumOperands()-1; }
2356 /// getDestination - Return the specified destination.
2357 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2358 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2360 /// addDestination - Add a destination.
2362 void addDestination(BasicBlock *Dest);
2364 /// removeDestination - This method removes the specified successor from the
2365 /// indirectbr instruction.
2366 void removeDestination(unsigned i);
2368 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2369 BasicBlock *getSuccessor(unsigned i) const {
2370 return cast<BasicBlock>(getOperand(i+1));
2372 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2373 setOperand(i+1, (Value*)NewSucc);
2376 // Methods for support type inquiry through isa, cast, and dyn_cast:
2377 static inline bool classof(const IndirectBrInst *) { return true; }
2378 static inline bool classof(const Instruction *I) {
2379 return I->getOpcode() == Instruction::IndirectBr;
2381 static inline bool classof(const Value *V) {
2382 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2385 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2386 virtual unsigned getNumSuccessorsV() const;
2387 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2391 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2394 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2397 //===----------------------------------------------------------------------===//
2399 //===----------------------------------------------------------------------===//
2401 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2402 /// calling convention of the call.
2404 class InvokeInst : public TerminatorInst {
2405 AttrListPtr AttributeList;
2406 InvokeInst(const InvokeInst &BI);
2407 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2408 Value* const *Args, unsigned NumArgs);
2410 template<typename RandomAccessIterator>
2411 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2412 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2413 const Twine &NameStr,
2414 // This argument ensures that we have an iterator we can
2415 // do arithmetic on in constant time
2416 std::random_access_iterator_tag) {
2417 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2419 // This requires that the iterator points to contiguous memory.
2420 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2424 /// Construct an InvokeInst given a range of arguments.
2425 /// RandomAccessIterator must be a random-access iterator pointing to
2426 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2427 /// made for random-accessness but not for contiguous storage as
2428 /// that would incur runtime overhead.
2430 /// @brief Construct an InvokeInst from a range of arguments
2431 template<typename RandomAccessIterator>
2432 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2433 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2435 const Twine &NameStr, Instruction *InsertBefore);
2437 /// Construct an InvokeInst given a range of arguments.
2438 /// RandomAccessIterator must be a random-access iterator pointing to
2439 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2440 /// made for random-accessness but not for contiguous storage as
2441 /// that would incur runtime overhead.
2443 /// @brief Construct an InvokeInst from a range of arguments
2444 template<typename RandomAccessIterator>
2445 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2446 RandomAccessIterator ArgBegin, RandomAccessIterator ArgEnd,
2448 const Twine &NameStr, BasicBlock *InsertAtEnd);
2450 virtual InvokeInst *clone_impl() const;
2452 template<typename RandomAccessIterator>
2453 static InvokeInst *Create(Value *Func,
2454 BasicBlock *IfNormal, BasicBlock *IfException,
2455 RandomAccessIterator ArgBegin,
2456 RandomAccessIterator ArgEnd,
2457 const Twine &NameStr = "",
2458 Instruction *InsertBefore = 0) {
2459 unsigned Values(ArgEnd - ArgBegin + 3);
2460 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2461 Values, NameStr, InsertBefore);
2463 template<typename RandomAccessIterator>
2464 static InvokeInst *Create(Value *Func,
2465 BasicBlock *IfNormal, BasicBlock *IfException,
2466 RandomAccessIterator ArgBegin,
2467 RandomAccessIterator ArgEnd,
2468 const Twine &NameStr,
2469 BasicBlock *InsertAtEnd) {
2470 unsigned Values(ArgEnd - ArgBegin + 3);
2471 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2472 Values, NameStr, InsertAtEnd);
2475 /// Provide fast operand accessors
2476 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2478 /// getNumArgOperands - Return the number of invoke arguments.
2480 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2482 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2484 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2485 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2487 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2489 CallingConv::ID getCallingConv() const {
2490 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2492 void setCallingConv(CallingConv::ID CC) {
2493 setInstructionSubclassData(static_cast<unsigned>(CC));
2496 /// getAttributes - Return the parameter attributes for this invoke.
2498 const AttrListPtr &getAttributes() const { return AttributeList; }
2500 /// setAttributes - Set the parameter attributes for this invoke.
2502 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2504 /// addAttribute - adds the attribute to the list of attributes.
2505 void addAttribute(unsigned i, Attributes attr);
2507 /// removeAttribute - removes the attribute from the list of attributes.
2508 void removeAttribute(unsigned i, Attributes attr);
2510 /// @brief Determine whether the call or the callee has the given attribute.
2511 bool paramHasAttr(unsigned i, Attributes attr) const;
2513 /// @brief Extract the alignment for a call or parameter (0=unknown).
2514 unsigned getParamAlignment(unsigned i) const {
2515 return AttributeList.getParamAlignment(i);
2518 /// @brief Return true if the call should not be inlined.
2519 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2520 void setIsNoInline(bool Value = true) {
2521 if (Value) addAttribute(~0, Attribute::NoInline);
2522 else removeAttribute(~0, Attribute::NoInline);
2525 /// @brief Determine if the call does not access memory.
2526 bool doesNotAccessMemory() const {
2527 return paramHasAttr(~0, Attribute::ReadNone);
2529 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2530 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2531 else removeAttribute(~0, Attribute::ReadNone);
2534 /// @brief Determine if the call does not access or only reads memory.
2535 bool onlyReadsMemory() const {
2536 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2538 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2539 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2540 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2543 /// @brief Determine if the call cannot return.
2544 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2545 void setDoesNotReturn(bool DoesNotReturn = true) {
2546 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2547 else removeAttribute(~0, Attribute::NoReturn);
2550 /// @brief Determine if the call cannot unwind.
2551 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2552 void setDoesNotThrow(bool DoesNotThrow = true) {
2553 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2554 else removeAttribute(~0, Attribute::NoUnwind);
2557 /// @brief Determine if the call returns a structure through first
2558 /// pointer argument.
2559 bool hasStructRetAttr() const {
2560 // Be friendly and also check the callee.
2561 return paramHasAttr(1, Attribute::StructRet);
2564 /// @brief Determine if any call argument is an aggregate passed by value.
2565 bool hasByValArgument() const {
2566 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2569 /// getCalledFunction - Return the function called, or null if this is an
2570 /// indirect function invocation.
2572 Function *getCalledFunction() const {
2573 return dyn_cast<Function>(Op<-3>());
2576 /// getCalledValue - Get a pointer to the function that is invoked by this
2578 const Value *getCalledValue() const { return Op<-3>(); }
2579 Value *getCalledValue() { return Op<-3>(); }
2581 /// setCalledFunction - Set the function called.
2582 void setCalledFunction(Value* Fn) {
2586 // get*Dest - Return the destination basic blocks...
2587 BasicBlock *getNormalDest() const {
2588 return cast<BasicBlock>(Op<-2>());
2590 BasicBlock *getUnwindDest() const {
2591 return cast<BasicBlock>(Op<-1>());
2593 void setNormalDest(BasicBlock *B) {
2594 Op<-2>() = reinterpret_cast<Value*>(B);
2596 void setUnwindDest(BasicBlock *B) {
2597 Op<-1>() = reinterpret_cast<Value*>(B);
2600 BasicBlock *getSuccessor(unsigned i) const {
2601 assert(i < 2 && "Successor # out of range for invoke!");
2602 return i == 0 ? getNormalDest() : getUnwindDest();
2605 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2606 assert(idx < 2 && "Successor # out of range for invoke!");
2607 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2610 unsigned getNumSuccessors() const { return 2; }
2612 // Methods for support type inquiry through isa, cast, and dyn_cast:
2613 static inline bool classof(const InvokeInst *) { return true; }
2614 static inline bool classof(const Instruction *I) {
2615 return (I->getOpcode() == Instruction::Invoke);
2617 static inline bool classof(const Value *V) {
2618 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2622 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2623 virtual unsigned getNumSuccessorsV() const;
2624 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2626 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2627 // method so that subclasses cannot accidentally use it.
2628 void setInstructionSubclassData(unsigned short D) {
2629 Instruction::setInstructionSubclassData(D);
2634 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
2637 template<typename RandomAccessIterator>
2638 InvokeInst::InvokeInst(Value *Func,
2639 BasicBlock *IfNormal, BasicBlock *IfException,
2640 RandomAccessIterator ArgBegin,
2641 RandomAccessIterator ArgEnd,
2643 const Twine &NameStr, Instruction *InsertBefore)
2644 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2645 ->getElementType())->getReturnType(),
2646 Instruction::Invoke,
2647 OperandTraits<InvokeInst>::op_end(this) - Values,
2648 Values, InsertBefore) {
2649 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2650 typename std::iterator_traits<RandomAccessIterator>
2651 ::iterator_category());
2653 template<typename RandomAccessIterator>
2654 InvokeInst::InvokeInst(Value *Func,
2655 BasicBlock *IfNormal, BasicBlock *IfException,
2656 RandomAccessIterator ArgBegin,
2657 RandomAccessIterator ArgEnd,
2659 const Twine &NameStr, BasicBlock *InsertAtEnd)
2660 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2661 ->getElementType())->getReturnType(),
2662 Instruction::Invoke,
2663 OperandTraits<InvokeInst>::op_end(this) - Values,
2664 Values, InsertAtEnd) {
2665 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2666 typename std::iterator_traits<RandomAccessIterator>
2667 ::iterator_category());
2670 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2672 //===----------------------------------------------------------------------===//
2674 //===----------------------------------------------------------------------===//
2676 //===---------------------------------------------------------------------------
2677 /// UnwindInst - Immediately exit the current function, unwinding the stack
2678 /// until an invoke instruction is found.
2680 class UnwindInst : public TerminatorInst {
2681 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2683 virtual UnwindInst *clone_impl() const;
2685 // allocate space for exactly zero operands
2686 void *operator new(size_t s) {
2687 return User::operator new(s, 0);
2689 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2690 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2692 unsigned getNumSuccessors() const { return 0; }
2694 // Methods for support type inquiry through isa, cast, and dyn_cast:
2695 static inline bool classof(const UnwindInst *) { return true; }
2696 static inline bool classof(const Instruction *I) {
2697 return I->getOpcode() == Instruction::Unwind;
2699 static inline bool classof(const Value *V) {
2700 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2703 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2704 virtual unsigned getNumSuccessorsV() const;
2705 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2708 //===----------------------------------------------------------------------===//
2709 // UnreachableInst Class
2710 //===----------------------------------------------------------------------===//
2712 //===---------------------------------------------------------------------------
2713 /// UnreachableInst - This function has undefined behavior. In particular, the
2714 /// presence of this instruction indicates some higher level knowledge that the
2715 /// end of the block cannot be reached.
2717 class UnreachableInst : public TerminatorInst {
2718 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2720 virtual UnreachableInst *clone_impl() const;
2723 // allocate space for exactly zero operands
2724 void *operator new(size_t s) {
2725 return User::operator new(s, 0);
2727 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2728 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2730 unsigned getNumSuccessors() const { return 0; }
2732 // Methods for support type inquiry through isa, cast, and dyn_cast:
2733 static inline bool classof(const UnreachableInst *) { return true; }
2734 static inline bool classof(const Instruction *I) {
2735 return I->getOpcode() == Instruction::Unreachable;
2737 static inline bool classof(const Value *V) {
2738 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2741 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2742 virtual unsigned getNumSuccessorsV() const;
2743 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2746 //===----------------------------------------------------------------------===//
2748 //===----------------------------------------------------------------------===//
2750 /// @brief This class represents a truncation of integer types.
2751 class TruncInst : public CastInst {
2753 /// @brief Clone an identical TruncInst
2754 virtual TruncInst *clone_impl() const;
2757 /// @brief Constructor with insert-before-instruction semantics
2759 Value *S, ///< The value to be truncated
2760 const Type *Ty, ///< The (smaller) type to truncate to
2761 const Twine &NameStr = "", ///< A name for the new instruction
2762 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2765 /// @brief Constructor with insert-at-end-of-block semantics
2767 Value *S, ///< The value to be truncated
2768 const Type *Ty, ///< The (smaller) type to truncate to
2769 const Twine &NameStr, ///< A name for the new instruction
2770 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2773 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2774 static inline bool classof(const TruncInst *) { return true; }
2775 static inline bool classof(const Instruction *I) {
2776 return I->getOpcode() == Trunc;
2778 static inline bool classof(const Value *V) {
2779 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2783 //===----------------------------------------------------------------------===//
2785 //===----------------------------------------------------------------------===//
2787 /// @brief This class represents zero extension of integer types.
2788 class ZExtInst : public CastInst {
2790 /// @brief Clone an identical ZExtInst
2791 virtual ZExtInst *clone_impl() const;
2794 /// @brief Constructor with insert-before-instruction semantics
2796 Value *S, ///< The value to be zero extended
2797 const Type *Ty, ///< The type to zero extend to
2798 const Twine &NameStr = "", ///< A name for the new instruction
2799 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2802 /// @brief Constructor with insert-at-end semantics.
2804 Value *S, ///< The value to be zero extended
2805 const Type *Ty, ///< The type to zero extend to
2806 const Twine &NameStr, ///< A name for the new instruction
2807 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2810 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2811 static inline bool classof(const ZExtInst *) { return true; }
2812 static inline bool classof(const Instruction *I) {
2813 return I->getOpcode() == ZExt;
2815 static inline bool classof(const Value *V) {
2816 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2820 //===----------------------------------------------------------------------===//
2822 //===----------------------------------------------------------------------===//
2824 /// @brief This class represents a sign extension of integer types.
2825 class SExtInst : public CastInst {
2827 /// @brief Clone an identical SExtInst
2828 virtual SExtInst *clone_impl() const;
2831 /// @brief Constructor with insert-before-instruction semantics
2833 Value *S, ///< The value to be sign extended
2834 const Type *Ty, ///< The type to sign extend to
2835 const Twine &NameStr = "", ///< A name for the new instruction
2836 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2839 /// @brief Constructor with insert-at-end-of-block semantics
2841 Value *S, ///< The value to be sign extended
2842 const Type *Ty, ///< The type to sign extend to
2843 const Twine &NameStr, ///< A name for the new instruction
2844 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2847 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2848 static inline bool classof(const SExtInst *) { return true; }
2849 static inline bool classof(const Instruction *I) {
2850 return I->getOpcode() == SExt;
2852 static inline bool classof(const Value *V) {
2853 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2857 //===----------------------------------------------------------------------===//
2858 // FPTruncInst Class
2859 //===----------------------------------------------------------------------===//
2861 /// @brief This class represents a truncation of floating point types.
2862 class FPTruncInst : public CastInst {
2864 /// @brief Clone an identical FPTruncInst
2865 virtual FPTruncInst *clone_impl() const;
2868 /// @brief Constructor with insert-before-instruction semantics
2870 Value *S, ///< The value to be truncated
2871 const Type *Ty, ///< The type to truncate to
2872 const Twine &NameStr = "", ///< A name for the new instruction
2873 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2876 /// @brief Constructor with insert-before-instruction semantics
2878 Value *S, ///< The value to be truncated
2879 const Type *Ty, ///< The type to truncate to
2880 const Twine &NameStr, ///< A name for the new instruction
2881 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2884 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2885 static inline bool classof(const FPTruncInst *) { return true; }
2886 static inline bool classof(const Instruction *I) {
2887 return I->getOpcode() == FPTrunc;
2889 static inline bool classof(const Value *V) {
2890 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2894 //===----------------------------------------------------------------------===//
2896 //===----------------------------------------------------------------------===//
2898 /// @brief This class represents an extension of floating point types.
2899 class FPExtInst : public CastInst {
2901 /// @brief Clone an identical FPExtInst
2902 virtual FPExtInst *clone_impl() const;
2905 /// @brief Constructor with insert-before-instruction semantics
2907 Value *S, ///< The value to be extended
2908 const Type *Ty, ///< The type to extend to
2909 const Twine &NameStr = "", ///< A name for the new instruction
2910 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2913 /// @brief Constructor with insert-at-end-of-block semantics
2915 Value *S, ///< The value to be extended
2916 const Type *Ty, ///< The type to extend to
2917 const Twine &NameStr, ///< A name for the new instruction
2918 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2921 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2922 static inline bool classof(const FPExtInst *) { return true; }
2923 static inline bool classof(const Instruction *I) {
2924 return I->getOpcode() == FPExt;
2926 static inline bool classof(const Value *V) {
2927 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2931 //===----------------------------------------------------------------------===//
2933 //===----------------------------------------------------------------------===//
2935 /// @brief This class represents a cast unsigned integer to floating point.
2936 class UIToFPInst : public CastInst {
2938 /// @brief Clone an identical UIToFPInst
2939 virtual UIToFPInst *clone_impl() const;
2942 /// @brief Constructor with insert-before-instruction semantics
2944 Value *S, ///< The value to be converted
2945 const Type *Ty, ///< The type to convert to
2946 const Twine &NameStr = "", ///< A name for the new instruction
2947 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2950 /// @brief Constructor with insert-at-end-of-block semantics
2952 Value *S, ///< The value to be converted
2953 const Type *Ty, ///< The type to convert to
2954 const Twine &NameStr, ///< A name for the new instruction
2955 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2958 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2959 static inline bool classof(const UIToFPInst *) { return true; }
2960 static inline bool classof(const Instruction *I) {
2961 return I->getOpcode() == UIToFP;
2963 static inline bool classof(const Value *V) {
2964 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2968 //===----------------------------------------------------------------------===//
2970 //===----------------------------------------------------------------------===//
2972 /// @brief This class represents a cast from signed integer to floating point.
2973 class SIToFPInst : public CastInst {
2975 /// @brief Clone an identical SIToFPInst
2976 virtual SIToFPInst *clone_impl() const;
2979 /// @brief Constructor with insert-before-instruction semantics
2981 Value *S, ///< The value to be converted
2982 const Type *Ty, ///< The type to convert to
2983 const Twine &NameStr = "", ///< A name for the new instruction
2984 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2987 /// @brief Constructor with insert-at-end-of-block semantics
2989 Value *S, ///< The value to be converted
2990 const Type *Ty, ///< The type to convert to
2991 const Twine &NameStr, ///< A name for the new instruction
2992 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2995 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2996 static inline bool classof(const SIToFPInst *) { return true; }
2997 static inline bool classof(const Instruction *I) {
2998 return I->getOpcode() == SIToFP;
3000 static inline bool classof(const Value *V) {
3001 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3005 //===----------------------------------------------------------------------===//
3007 //===----------------------------------------------------------------------===//
3009 /// @brief This class represents a cast from floating point to unsigned integer
3010 class FPToUIInst : public CastInst {
3012 /// @brief Clone an identical FPToUIInst
3013 virtual FPToUIInst *clone_impl() const;
3016 /// @brief Constructor with insert-before-instruction semantics
3018 Value *S, ///< The value to be converted
3019 const Type *Ty, ///< The type to convert to
3020 const Twine &NameStr = "", ///< A name for the new instruction
3021 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3024 /// @brief Constructor with insert-at-end-of-block semantics
3026 Value *S, ///< The value to be converted
3027 const Type *Ty, ///< The type to convert to
3028 const Twine &NameStr, ///< A name for the new instruction
3029 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3032 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3033 static inline bool classof(const FPToUIInst *) { return true; }
3034 static inline bool classof(const Instruction *I) {
3035 return I->getOpcode() == FPToUI;
3037 static inline bool classof(const Value *V) {
3038 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3042 //===----------------------------------------------------------------------===//
3044 //===----------------------------------------------------------------------===//
3046 /// @brief This class represents a cast from floating point to signed integer.
3047 class FPToSIInst : public CastInst {
3049 /// @brief Clone an identical FPToSIInst
3050 virtual FPToSIInst *clone_impl() const;
3053 /// @brief Constructor with insert-before-instruction semantics
3055 Value *S, ///< The value to be converted
3056 const Type *Ty, ///< The type to convert to
3057 const Twine &NameStr = "", ///< A name for the new instruction
3058 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3061 /// @brief Constructor with insert-at-end-of-block semantics
3063 Value *S, ///< The value to be converted
3064 const Type *Ty, ///< The type to convert to
3065 const Twine &NameStr, ///< A name for the new instruction
3066 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3069 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3070 static inline bool classof(const FPToSIInst *) { return true; }
3071 static inline bool classof(const Instruction *I) {
3072 return I->getOpcode() == FPToSI;
3074 static inline bool classof(const Value *V) {
3075 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3079 //===----------------------------------------------------------------------===//
3080 // IntToPtrInst Class
3081 //===----------------------------------------------------------------------===//
3083 /// @brief This class represents a cast from an integer to a pointer.
3084 class IntToPtrInst : public CastInst {
3086 /// @brief Constructor with insert-before-instruction semantics
3088 Value *S, ///< The value to be converted
3089 const Type *Ty, ///< The type to convert to
3090 const Twine &NameStr = "", ///< A name for the new instruction
3091 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3094 /// @brief Constructor with insert-at-end-of-block semantics
3096 Value *S, ///< The value to be converted
3097 const Type *Ty, ///< The type to convert to
3098 const Twine &NameStr, ///< A name for the new instruction
3099 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3102 /// @brief Clone an identical IntToPtrInst
3103 virtual IntToPtrInst *clone_impl() const;
3105 // Methods for support type inquiry through isa, cast, and dyn_cast:
3106 static inline bool classof(const IntToPtrInst *) { return true; }
3107 static inline bool classof(const Instruction *I) {
3108 return I->getOpcode() == IntToPtr;
3110 static inline bool classof(const Value *V) {
3111 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3115 //===----------------------------------------------------------------------===//
3116 // PtrToIntInst Class
3117 //===----------------------------------------------------------------------===//
3119 /// @brief This class represents a cast from a pointer to an integer
3120 class PtrToIntInst : public CastInst {
3122 /// @brief Clone an identical PtrToIntInst
3123 virtual PtrToIntInst *clone_impl() const;
3126 /// @brief Constructor with insert-before-instruction semantics
3128 Value *S, ///< The value to be converted
3129 const Type *Ty, ///< The type to convert to
3130 const Twine &NameStr = "", ///< A name for the new instruction
3131 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3134 /// @brief Constructor with insert-at-end-of-block semantics
3136 Value *S, ///< The value to be converted
3137 const Type *Ty, ///< The type to convert to
3138 const Twine &NameStr, ///< A name for the new instruction
3139 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3142 // Methods for support type inquiry through isa, cast, and dyn_cast:
3143 static inline bool classof(const PtrToIntInst *) { return true; }
3144 static inline bool classof(const Instruction *I) {
3145 return I->getOpcode() == PtrToInt;
3147 static inline bool classof(const Value *V) {
3148 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3152 //===----------------------------------------------------------------------===//
3153 // BitCastInst Class
3154 //===----------------------------------------------------------------------===//
3156 /// @brief This class represents a no-op cast from one type to another.
3157 class BitCastInst : public CastInst {
3159 /// @brief Clone an identical BitCastInst
3160 virtual BitCastInst *clone_impl() const;
3163 /// @brief Constructor with insert-before-instruction semantics
3165 Value *S, ///< The value to be casted
3166 const Type *Ty, ///< The type to casted to
3167 const Twine &NameStr = "", ///< A name for the new instruction
3168 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3171 /// @brief Constructor with insert-at-end-of-block semantics
3173 Value *S, ///< The value to be casted
3174 const Type *Ty, ///< The type to casted to
3175 const Twine &NameStr, ///< A name for the new instruction
3176 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3179 // Methods for support type inquiry through isa, cast, and dyn_cast:
3180 static inline bool classof(const BitCastInst *) { return true; }
3181 static inline bool classof(const Instruction *I) {
3182 return I->getOpcode() == BitCast;
3184 static inline bool classof(const Value *V) {
3185 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3189 } // End llvm namespace