1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
19 #include "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/ADT/SmallVector.h"
34 //===----------------------------------------------------------------------===//
36 //===----------------------------------------------------------------------===//
38 /// AllocaInst - an instruction to allocate memory on the stack
40 class AllocaInst : public UnaryInstruction {
42 virtual AllocaInst *clone_impl() const;
44 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
45 const Twine &Name = "", Instruction *InsertBefore = 0);
46 AllocaInst(const Type *Ty, Value *ArraySize,
47 const Twine &Name, BasicBlock *InsertAtEnd);
49 AllocaInst(const Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
50 AllocaInst(const Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
52 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
53 const Twine &Name = "", Instruction *InsertBefore = 0);
54 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
55 const Twine &Name, BasicBlock *InsertAtEnd);
57 // Out of line virtual method, so the vtable, etc. has a home.
58 virtual ~AllocaInst();
60 /// isArrayAllocation - Return true if there is an allocation size parameter
61 /// to the allocation instruction that is not 1.
63 bool isArrayAllocation() const;
65 /// getArraySize - Get the number of elements allocated. For a simple
66 /// allocation of a single element, this will return a constant 1 value.
68 const Value *getArraySize() const { return getOperand(0); }
69 Value *getArraySize() { return getOperand(0); }
71 /// getType - Overload to return most specific pointer type
73 const PointerType *getType() const {
74 return reinterpret_cast<const PointerType*>(Instruction::getType());
77 /// getAllocatedType - Return the type that is being allocated by the
80 const Type *getAllocatedType() const;
82 /// getAlignment - Return the alignment of the memory that is being allocated
83 /// by the instruction.
85 unsigned getAlignment() const {
86 return (1u << getSubclassDataFromInstruction()) >> 1;
88 void setAlignment(unsigned Align);
90 /// isStaticAlloca - Return true if this alloca is in the entry block of the
91 /// function and is a constant size. If so, the code generator will fold it
92 /// into the prolog/epilog code, so it is basically free.
93 bool isStaticAlloca() const;
95 // Methods for support type inquiry through isa, cast, and dyn_cast:
96 static inline bool classof(const AllocaInst *) { return true; }
97 static inline bool classof(const Instruction *I) {
98 return (I->getOpcode() == Instruction::Alloca);
100 static inline bool classof(const Value *V) {
101 return isa<Instruction>(V) && classof(cast<Instruction>(V));
104 // Shadow Instruction::setInstructionSubclassData with a private forwarding
105 // method so that subclasses cannot accidentally use it.
106 void setInstructionSubclassData(unsigned short D) {
107 Instruction::setInstructionSubclassData(D);
112 //===----------------------------------------------------------------------===//
114 //===----------------------------------------------------------------------===//
116 /// LoadInst - an instruction for reading from memory. This uses the
117 /// SubclassData field in Value to store whether or not the load is volatile.
119 class LoadInst : public UnaryInstruction {
122 virtual LoadInst *clone_impl() const;
124 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
125 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
126 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
127 Instruction *InsertBefore = 0);
128 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
129 unsigned Align, Instruction *InsertBefore = 0);
130 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
131 BasicBlock *InsertAtEnd);
132 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
133 unsigned Align, BasicBlock *InsertAtEnd);
135 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
136 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
137 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
138 bool isVolatile = false, Instruction *InsertBefore = 0);
139 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
140 BasicBlock *InsertAtEnd);
142 /// isVolatile - Return true if this is a load from a volatile memory
145 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
147 /// setVolatile - Specify whether this is a volatile load or not.
149 void setVolatile(bool V) {
150 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
154 /// getAlignment - Return the alignment of the access that is being performed
156 unsigned getAlignment() const {
157 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
160 void setAlignment(unsigned Align);
162 Value *getPointerOperand() { return getOperand(0); }
163 const Value *getPointerOperand() const { return getOperand(0); }
164 static unsigned getPointerOperandIndex() { return 0U; }
166 unsigned getPointerAddressSpace() const {
167 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
171 // Methods for support type inquiry through isa, cast, and dyn_cast:
172 static inline bool classof(const LoadInst *) { return true; }
173 static inline bool classof(const Instruction *I) {
174 return I->getOpcode() == Instruction::Load;
176 static inline bool classof(const Value *V) {
177 return isa<Instruction>(V) && classof(cast<Instruction>(V));
180 // Shadow Instruction::setInstructionSubclassData with a private forwarding
181 // method so that subclasses cannot accidentally use it.
182 void setInstructionSubclassData(unsigned short D) {
183 Instruction::setInstructionSubclassData(D);
188 //===----------------------------------------------------------------------===//
190 //===----------------------------------------------------------------------===//
192 /// StoreInst - an instruction for storing to memory
194 class StoreInst : public Instruction {
195 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
198 virtual StoreInst *clone_impl() const;
200 // allocate space for exactly two operands
201 void *operator new(size_t s) {
202 return User::operator new(s, 2);
204 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
205 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
206 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
207 Instruction *InsertBefore = 0);
208 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
209 unsigned Align, Instruction *InsertBefore = 0);
210 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
211 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
212 unsigned Align, BasicBlock *InsertAtEnd);
215 /// isVolatile - Return true if this is a load from a volatile memory
218 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
220 /// setVolatile - Specify whether this is a volatile load or not.
222 void setVolatile(bool V) {
223 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
227 /// Transparently provide more efficient getOperand methods.
228 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
230 /// getAlignment - Return the alignment of the access that is being performed
232 unsigned getAlignment() const {
233 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
236 void setAlignment(unsigned Align);
238 Value *getValueOperand() { return getOperand(0); }
239 const Value *getValueOperand() const { return getOperand(0); }
241 Value *getPointerOperand() { return getOperand(1); }
242 const Value *getPointerOperand() const { return getOperand(1); }
243 static unsigned getPointerOperandIndex() { return 1U; }
245 unsigned getPointerAddressSpace() const {
246 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
249 // Methods for support type inquiry through isa, cast, and dyn_cast:
250 static inline bool classof(const StoreInst *) { return true; }
251 static inline bool classof(const Instruction *I) {
252 return I->getOpcode() == Instruction::Store;
254 static inline bool classof(const Value *V) {
255 return isa<Instruction>(V) && classof(cast<Instruction>(V));
258 // Shadow Instruction::setInstructionSubclassData with a private forwarding
259 // method so that subclasses cannot accidentally use it.
260 void setInstructionSubclassData(unsigned short D) {
261 Instruction::setInstructionSubclassData(D);
266 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<2> {
269 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
271 //===----------------------------------------------------------------------===//
272 // GetElementPtrInst Class
273 //===----------------------------------------------------------------------===//
275 // checkType - Simple wrapper function to give a better assertion failure
276 // message on bad indexes for a gep instruction.
278 static inline const Type *checkType(const Type *Ty) {
279 assert(Ty && "Invalid GetElementPtrInst indices for type!");
283 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
284 /// access elements of arrays and structs
286 class GetElementPtrInst : public Instruction {
287 GetElementPtrInst(const GetElementPtrInst &GEPI);
288 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
289 const Twine &NameStr);
290 void init(Value *Ptr, Value *Idx, const Twine &NameStr);
292 template<typename InputIterator>
293 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
294 const Twine &NameStr,
295 // This argument ensures that we have an iterator we can
296 // do arithmetic on in constant time
297 std::random_access_iterator_tag) {
298 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
301 // This requires that the iterator points to contiguous memory.
302 init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
303 // we have to build an array here
306 init(Ptr, 0, NumIdx, NameStr);
310 /// getIndexedType - Returns the type of the element that would be loaded with
311 /// a load instruction with the specified parameters.
313 /// Null is returned if the indices are invalid for the specified
316 template<typename InputIterator>
317 static const Type *getIndexedType(const Type *Ptr,
318 InputIterator IdxBegin,
319 InputIterator IdxEnd,
320 // This argument ensures that we
321 // have an iterator we can do
322 // arithmetic on in constant time
323 std::random_access_iterator_tag) {
324 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
327 // This requires that the iterator points to contiguous memory.
328 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
330 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
333 /// Constructors - Create a getelementptr instruction with a base pointer an
334 /// list of indices. The first ctor can optionally insert before an existing
335 /// instruction, the second appends the new instruction to the specified
337 template<typename InputIterator>
338 inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
339 InputIterator IdxEnd,
341 const Twine &NameStr,
342 Instruction *InsertBefore);
343 template<typename InputIterator>
344 inline GetElementPtrInst(Value *Ptr,
345 InputIterator IdxBegin, InputIterator IdxEnd,
347 const Twine &NameStr, BasicBlock *InsertAtEnd);
349 /// Constructors - These two constructors are convenience methods because one
350 /// and two index getelementptr instructions are so common.
351 GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
352 Instruction *InsertBefore = 0);
353 GetElementPtrInst(Value *Ptr, Value *Idx,
354 const Twine &NameStr, BasicBlock *InsertAtEnd);
356 virtual GetElementPtrInst *clone_impl() const;
358 template<typename InputIterator>
359 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
360 InputIterator IdxEnd,
361 const Twine &NameStr = "",
362 Instruction *InsertBefore = 0) {
363 typename std::iterator_traits<InputIterator>::difference_type Values =
364 1 + std::distance(IdxBegin, IdxEnd);
366 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
368 template<typename InputIterator>
369 static GetElementPtrInst *Create(Value *Ptr,
370 InputIterator IdxBegin, InputIterator IdxEnd,
371 const Twine &NameStr,
372 BasicBlock *InsertAtEnd) {
373 typename std::iterator_traits<InputIterator>::difference_type Values =
374 1 + std::distance(IdxBegin, IdxEnd);
376 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
379 /// Constructors - These two creators are convenience methods because one
380 /// index getelementptr instructions are so common.
381 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
382 const Twine &NameStr = "",
383 Instruction *InsertBefore = 0) {
384 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
386 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
387 const Twine &NameStr,
388 BasicBlock *InsertAtEnd) {
389 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
392 /// Create an "inbounds" getelementptr. See the documentation for the
393 /// "inbounds" flag in LangRef.html for details.
394 template<typename InputIterator>
395 static GetElementPtrInst *CreateInBounds(Value *Ptr, InputIterator IdxBegin,
396 InputIterator IdxEnd,
397 const Twine &NameStr = "",
398 Instruction *InsertBefore = 0) {
399 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
400 NameStr, InsertBefore);
401 GEP->setIsInBounds(true);
404 template<typename InputIterator>
405 static GetElementPtrInst *CreateInBounds(Value *Ptr,
406 InputIterator IdxBegin,
407 InputIterator IdxEnd,
408 const Twine &NameStr,
409 BasicBlock *InsertAtEnd) {
410 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
411 NameStr, InsertAtEnd);
412 GEP->setIsInBounds(true);
415 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
416 const Twine &NameStr = "",
417 Instruction *InsertBefore = 0) {
418 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
419 GEP->setIsInBounds(true);
422 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
423 const Twine &NameStr,
424 BasicBlock *InsertAtEnd) {
425 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
426 GEP->setIsInBounds(true);
430 /// Transparently provide more efficient getOperand methods.
431 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
433 // getType - Overload to return most specific pointer type...
434 const PointerType *getType() const {
435 return reinterpret_cast<const PointerType*>(Instruction::getType());
438 /// getIndexedType - Returns the type of the element that would be loaded with
439 /// a load instruction with the specified parameters.
441 /// Null is returned if the indices are invalid for the specified
444 template<typename InputIterator>
445 static const Type *getIndexedType(const Type *Ptr,
446 InputIterator IdxBegin,
447 InputIterator IdxEnd) {
448 return getIndexedType(Ptr, IdxBegin, IdxEnd,
449 typename std::iterator_traits<InputIterator>::
450 iterator_category());
453 static const Type *getIndexedType(const Type *Ptr,
454 Value* const *Idx, unsigned NumIdx);
456 static const Type *getIndexedType(const Type *Ptr,
457 uint64_t const *Idx, unsigned NumIdx);
459 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
461 inline op_iterator idx_begin() { return op_begin()+1; }
462 inline const_op_iterator idx_begin() const { return op_begin()+1; }
463 inline op_iterator idx_end() { return op_end(); }
464 inline const_op_iterator idx_end() const { return op_end(); }
466 Value *getPointerOperand() {
467 return getOperand(0);
469 const Value *getPointerOperand() const {
470 return getOperand(0);
472 static unsigned getPointerOperandIndex() {
473 return 0U; // get index for modifying correct operand
476 unsigned getPointerAddressSpace() const {
477 return cast<PointerType>(getType())->getAddressSpace();
480 /// getPointerOperandType - Method to return the pointer operand as a
482 const PointerType *getPointerOperandType() const {
483 return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
487 unsigned getNumIndices() const { // Note: always non-negative
488 return getNumOperands() - 1;
491 bool hasIndices() const {
492 return getNumOperands() > 1;
495 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
496 /// zeros. If so, the result pointer and the first operand have the same
497 /// value, just potentially different types.
498 bool hasAllZeroIndices() const;
500 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
501 /// constant integers. If so, the result pointer and the first operand have
502 /// a constant offset between them.
503 bool hasAllConstantIndices() const;
505 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
506 /// See LangRef.html for the meaning of inbounds on a getelementptr.
507 void setIsInBounds(bool b = true);
509 /// isInBounds - Determine whether the GEP has the inbounds flag.
510 bool isInBounds() const;
512 // Methods for support type inquiry through isa, cast, and dyn_cast:
513 static inline bool classof(const GetElementPtrInst *) { return true; }
514 static inline bool classof(const Instruction *I) {
515 return (I->getOpcode() == Instruction::GetElementPtr);
517 static inline bool classof(const Value *V) {
518 return isa<Instruction>(V) && classof(cast<Instruction>(V));
523 struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<1> {
526 template<typename InputIterator>
527 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
528 InputIterator IdxBegin,
529 InputIterator IdxEnd,
531 const Twine &NameStr,
532 Instruction *InsertBefore)
533 : Instruction(PointerType::get(checkType(
534 getIndexedType(Ptr->getType(),
536 cast<PointerType>(Ptr->getType())
537 ->getAddressSpace()),
539 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
540 Values, InsertBefore) {
541 init(Ptr, IdxBegin, IdxEnd, NameStr,
542 typename std::iterator_traits<InputIterator>::iterator_category());
544 template<typename InputIterator>
545 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
546 InputIterator IdxBegin,
547 InputIterator IdxEnd,
549 const Twine &NameStr,
550 BasicBlock *InsertAtEnd)
551 : Instruction(PointerType::get(checkType(
552 getIndexedType(Ptr->getType(),
554 cast<PointerType>(Ptr->getType())
555 ->getAddressSpace()),
557 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
558 Values, InsertAtEnd) {
559 init(Ptr, IdxBegin, IdxEnd, NameStr,
560 typename std::iterator_traits<InputIterator>::iterator_category());
564 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
567 //===----------------------------------------------------------------------===//
569 //===----------------------------------------------------------------------===//
571 /// This instruction compares its operands according to the predicate given
572 /// to the constructor. It only operates on integers or pointers. The operands
573 /// must be identical types.
574 /// @brief Represent an integer comparison operator.
575 class ICmpInst: public CmpInst {
577 /// @brief Clone an indentical ICmpInst
578 virtual ICmpInst *clone_impl() const;
580 /// @brief Constructor with insert-before-instruction semantics.
582 Instruction *InsertBefore, ///< Where to insert
583 Predicate pred, ///< The predicate to use for the comparison
584 Value *LHS, ///< The left-hand-side of the expression
585 Value *RHS, ///< The right-hand-side of the expression
586 const Twine &NameStr = "" ///< Name of the instruction
587 ) : CmpInst(makeCmpResultType(LHS->getType()),
588 Instruction::ICmp, pred, LHS, RHS, NameStr,
590 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
591 pred <= CmpInst::LAST_ICMP_PREDICATE &&
592 "Invalid ICmp predicate value");
593 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
594 "Both operands to ICmp instruction are not of the same type!");
595 // Check that the operands are the right type
596 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
597 getOperand(0)->getType()->isPointerTy()) &&
598 "Invalid operand types for ICmp instruction");
601 /// @brief Constructor with insert-at-end semantics.
603 BasicBlock &InsertAtEnd, ///< Block to insert into.
604 Predicate pred, ///< The predicate to use for the comparison
605 Value *LHS, ///< The left-hand-side of the expression
606 Value *RHS, ///< The right-hand-side of the expression
607 const Twine &NameStr = "" ///< Name of the instruction
608 ) : CmpInst(makeCmpResultType(LHS->getType()),
609 Instruction::ICmp, pred, LHS, RHS, NameStr,
611 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
612 pred <= CmpInst::LAST_ICMP_PREDICATE &&
613 "Invalid ICmp predicate value");
614 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
615 "Both operands to ICmp instruction are not of the same type!");
616 // Check that the operands are the right type
617 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
618 getOperand(0)->getType()->isPointerTy()) &&
619 "Invalid operand types for ICmp instruction");
622 /// @brief Constructor with no-insertion semantics
624 Predicate pred, ///< The predicate to use for the comparison
625 Value *LHS, ///< The left-hand-side of the expression
626 Value *RHS, ///< The right-hand-side of the expression
627 const Twine &NameStr = "" ///< Name of the instruction
628 ) : CmpInst(makeCmpResultType(LHS->getType()),
629 Instruction::ICmp, pred, LHS, RHS, NameStr) {
630 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
631 pred <= CmpInst::LAST_ICMP_PREDICATE &&
632 "Invalid ICmp predicate value");
633 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
634 "Both operands to ICmp instruction are not of the same type!");
635 // Check that the operands are the right type
636 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
637 getOperand(0)->getType()->isPointerTy()) &&
638 "Invalid operand types for ICmp instruction");
641 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
642 /// @returns the predicate that would be the result if the operand were
643 /// regarded as signed.
644 /// @brief Return the signed version of the predicate
645 Predicate getSignedPredicate() const {
646 return getSignedPredicate(getPredicate());
649 /// This is a static version that you can use without an instruction.
650 /// @brief Return the signed version of the predicate.
651 static Predicate getSignedPredicate(Predicate pred);
653 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
654 /// @returns the predicate that would be the result if the operand were
655 /// regarded as unsigned.
656 /// @brief Return the unsigned version of the predicate
657 Predicate getUnsignedPredicate() const {
658 return getUnsignedPredicate(getPredicate());
661 /// This is a static version that you can use without an instruction.
662 /// @brief Return the unsigned version of the predicate.
663 static Predicate getUnsignedPredicate(Predicate pred);
665 /// isEquality - Return true if this predicate is either EQ or NE. This also
666 /// tests for commutativity.
667 static bool isEquality(Predicate P) {
668 return P == ICMP_EQ || P == ICMP_NE;
671 /// isEquality - Return true if this predicate is either EQ or NE. This also
672 /// tests for commutativity.
673 bool isEquality() const {
674 return isEquality(getPredicate());
677 /// @returns true if the predicate of this ICmpInst is commutative
678 /// @brief Determine if this relation is commutative.
679 bool isCommutative() const { return isEquality(); }
681 /// isRelational - Return true if the predicate is relational (not EQ or NE).
683 bool isRelational() const {
684 return !isEquality();
687 /// isRelational - Return true if the predicate is relational (not EQ or NE).
689 static bool isRelational(Predicate P) {
690 return !isEquality(P);
693 /// Initialize a set of values that all satisfy the predicate with C.
694 /// @brief Make a ConstantRange for a relation with a constant value.
695 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
697 /// Exchange the two operands to this instruction in such a way that it does
698 /// not modify the semantics of the instruction. The predicate value may be
699 /// changed to retain the same result if the predicate is order dependent
701 /// @brief Swap operands and adjust predicate.
702 void swapOperands() {
703 setPredicate(getSwappedPredicate());
704 Op<0>().swap(Op<1>());
707 // Methods for support type inquiry through isa, cast, and dyn_cast:
708 static inline bool classof(const ICmpInst *) { return true; }
709 static inline bool classof(const Instruction *I) {
710 return I->getOpcode() == Instruction::ICmp;
712 static inline bool classof(const Value *V) {
713 return isa<Instruction>(V) && classof(cast<Instruction>(V));
718 //===----------------------------------------------------------------------===//
720 //===----------------------------------------------------------------------===//
722 /// This instruction compares its operands according to the predicate given
723 /// to the constructor. It only operates on floating point values or packed
724 /// vectors of floating point values. The operands must be identical types.
725 /// @brief Represents a floating point comparison operator.
726 class FCmpInst: public CmpInst {
728 /// @brief Clone an indentical FCmpInst
729 virtual FCmpInst *clone_impl() const;
731 /// @brief Constructor with insert-before-instruction semantics.
733 Instruction *InsertBefore, ///< Where to insert
734 Predicate pred, ///< The predicate to use for the comparison
735 Value *LHS, ///< The left-hand-side of the expression
736 Value *RHS, ///< The right-hand-side of the expression
737 const Twine &NameStr = "" ///< Name of the instruction
738 ) : CmpInst(makeCmpResultType(LHS->getType()),
739 Instruction::FCmp, pred, LHS, RHS, NameStr,
741 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
742 "Invalid FCmp predicate value");
743 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
744 "Both operands to FCmp instruction are not of the same type!");
745 // Check that the operands are the right type
746 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
747 "Invalid operand types for FCmp instruction");
750 /// @brief Constructor with insert-at-end semantics.
752 BasicBlock &InsertAtEnd, ///< Block to insert into.
753 Predicate pred, ///< The predicate to use for the comparison
754 Value *LHS, ///< The left-hand-side of the expression
755 Value *RHS, ///< The right-hand-side of the expression
756 const Twine &NameStr = "" ///< Name of the instruction
757 ) : CmpInst(makeCmpResultType(LHS->getType()),
758 Instruction::FCmp, pred, LHS, RHS, NameStr,
760 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
761 "Invalid FCmp predicate value");
762 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
763 "Both operands to FCmp instruction are not of the same type!");
764 // Check that the operands are the right type
765 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
766 "Invalid operand types for FCmp instruction");
769 /// @brief Constructor with no-insertion semantics
771 Predicate pred, ///< The predicate to use for the comparison
772 Value *LHS, ///< The left-hand-side of the expression
773 Value *RHS, ///< The right-hand-side of the expression
774 const Twine &NameStr = "" ///< Name of the instruction
775 ) : CmpInst(makeCmpResultType(LHS->getType()),
776 Instruction::FCmp, pred, LHS, RHS, NameStr) {
777 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
778 "Invalid FCmp predicate value");
779 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
780 "Both operands to FCmp instruction are not of the same type!");
781 // Check that the operands are the right type
782 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
783 "Invalid operand types for FCmp instruction");
786 /// @returns true if the predicate of this instruction is EQ or NE.
787 /// @brief Determine if this is an equality predicate.
788 bool isEquality() const {
789 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
790 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
793 /// @returns true if the predicate of this instruction is commutative.
794 /// @brief Determine if this is a commutative predicate.
795 bool isCommutative() const {
796 return isEquality() ||
797 getPredicate() == FCMP_FALSE ||
798 getPredicate() == FCMP_TRUE ||
799 getPredicate() == FCMP_ORD ||
800 getPredicate() == FCMP_UNO;
803 /// @returns true if the predicate is relational (not EQ or NE).
804 /// @brief Determine if this a relational predicate.
805 bool isRelational() const { return !isEquality(); }
807 /// Exchange the two operands to this instruction in such a way that it does
808 /// not modify the semantics of the instruction. The predicate value may be
809 /// changed to retain the same result if the predicate is order dependent
811 /// @brief Swap operands and adjust predicate.
812 void swapOperands() {
813 setPredicate(getSwappedPredicate());
814 Op<0>().swap(Op<1>());
817 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
818 static inline bool classof(const FCmpInst *) { return true; }
819 static inline bool classof(const Instruction *I) {
820 return I->getOpcode() == Instruction::FCmp;
822 static inline bool classof(const Value *V) {
823 return isa<Instruction>(V) && classof(cast<Instruction>(V));
827 //===----------------------------------------------------------------------===//
828 /// CallInst - This class represents a function call, abstracting a target
829 /// machine's calling convention. This class uses low bit of the SubClassData
830 /// field to indicate whether or not this is a tail call. The rest of the bits
831 /// hold the calling convention of the call.
833 class CallInst : public Instruction {
834 AttrListPtr AttributeList; ///< parameter attributes for call
835 CallInst(const CallInst &CI);
836 void init(Value *Func, Value* const *Params, unsigned NumParams);
837 void init(Value *Func, Value *Actual1, Value *Actual2);
838 void init(Value *Func, Value *Actual);
839 void init(Value *Func);
841 template<typename InputIterator>
842 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
843 const Twine &NameStr,
844 // This argument ensures that we have an iterator we can
845 // do arithmetic on in constant time
846 std::random_access_iterator_tag) {
847 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
849 // This requires that the iterator points to contiguous memory.
850 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
854 /// Construct a CallInst given a range of arguments. InputIterator
855 /// must be a random-access iterator pointing to contiguous storage
856 /// (e.g. a std::vector<>::iterator). Checks are made for
857 /// random-accessness but not for contiguous storage as that would
858 /// incur runtime overhead.
859 /// @brief Construct a CallInst from a range of arguments
860 template<typename InputIterator>
861 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
862 const Twine &NameStr, Instruction *InsertBefore);
864 /// Construct a CallInst given a range of arguments. InputIterator
865 /// must be a random-access iterator pointing to contiguous storage
866 /// (e.g. a std::vector<>::iterator). Checks are made for
867 /// random-accessness but not for contiguous storage as that would
868 /// incur runtime overhead.
869 /// @brief Construct a CallInst from a range of arguments
870 template<typename InputIterator>
871 inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
872 const Twine &NameStr, BasicBlock *InsertAtEnd);
874 CallInst(Value *F, Value *Actual, const Twine &NameStr,
875 Instruction *InsertBefore);
876 CallInst(Value *F, Value *Actual, const Twine &NameStr,
877 BasicBlock *InsertAtEnd);
878 explicit CallInst(Value *F, const Twine &NameStr,
879 Instruction *InsertBefore);
880 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
882 virtual CallInst *clone_impl() const;
884 template<typename InputIterator>
885 static CallInst *Create(Value *Func,
886 InputIterator ArgBegin, InputIterator ArgEnd,
887 const Twine &NameStr = "",
888 Instruction *InsertBefore = 0) {
889 return new((unsigned)(ArgEnd - ArgBegin + 1))
890 CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore);
892 template<typename InputIterator>
893 static CallInst *Create(Value *Func,
894 InputIterator ArgBegin, InputIterator ArgEnd,
895 const Twine &NameStr, BasicBlock *InsertAtEnd) {
896 return new((unsigned)(ArgEnd - ArgBegin + 1))
897 CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd);
899 static CallInst *Create(Value *F, Value *Actual,
900 const Twine &NameStr = "",
901 Instruction *InsertBefore = 0) {
902 return new(2) CallInst(F, Actual, NameStr, InsertBefore);
904 static CallInst *Create(Value *F, Value *Actual, const Twine &NameStr,
905 BasicBlock *InsertAtEnd) {
906 return new(2) CallInst(F, Actual, NameStr, InsertAtEnd);
908 static CallInst *Create(Value *F, const Twine &NameStr = "",
909 Instruction *InsertBefore = 0) {
910 return new(1) CallInst(F, NameStr, InsertBefore);
912 static CallInst *Create(Value *F, const Twine &NameStr,
913 BasicBlock *InsertAtEnd) {
914 return new(1) CallInst(F, NameStr, InsertAtEnd);
916 /// CreateMalloc - Generate the IR for a call to malloc:
917 /// 1. Compute the malloc call's argument as the specified type's size,
918 /// possibly multiplied by the array size if the array size is not
920 /// 2. Call malloc with that argument.
921 /// 3. Bitcast the result of the malloc call to the specified type.
922 static Instruction *CreateMalloc(Instruction *InsertBefore,
923 const Type *IntPtrTy, const Type *AllocTy,
924 Value *AllocSize, Value *ArraySize = 0,
925 const Twine &Name = "");
926 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
927 const Type *IntPtrTy, const Type *AllocTy,
928 Value *AllocSize, Value *ArraySize = 0,
929 Function* MallocF = 0,
930 const Twine &Name = "");
931 /// CreateFree - Generate the IR for a call to the builtin free function.
932 static void CreateFree(Value* Source, Instruction *InsertBefore);
933 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
937 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
938 void setTailCall(bool isTC = true) {
939 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
943 /// @deprecated these "define hacks" will go away soon
944 /// @brief coerce out-of-tree code to abandon the low-level interfaces
945 /// @detail see below comments and update your code to high-level interfaces
946 /// in LLVM v2.8-only code
947 /// - getOperand(N+1) ---> getArgOperand(N)
948 /// - setOperand(N+1, V) ---> setArgOperand(N, V)
949 /// - getNumOperands() ---> getNumArgOperands()+1 // note the "+1"!
951 /// in backward compatible code please consult llvm/Support/CallSite.h,
952 /// you should create a callsite using the CallInst pointer and call its methods
954 # define public private
955 # define protected private
956 /// Provide fast operand accessors
957 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
962 enum { ArgOffset = 1 }; ///< temporary, do not use for new code!
963 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
964 Value *getArgOperand(unsigned i) const { return getOperand(i + ArgOffset); }
965 void setArgOperand(unsigned i, Value *v) { setOperand(i + ArgOffset, v); }
967 /// Provide compile-time errors for accessing operand 0
968 /// @deprecated these will go away soon
969 /// @detail see below comments and update your code to high-level interfaces
970 /// - getOperand(0) ---> getCalledValue(), or possibly getCalledFunction()
971 /// - setOperand(0, V) ---> setCalledFunction(V)
974 void getOperand(void*); // NO IMPL ---> use getCalledValue (or possibly getCalledFunction) instead
975 void setOperand(void*, Value*); // NO IMPL ---> use setCalledFunction instead
978 /// getCallingConv/setCallingConv - Get or set the calling convention of this
980 CallingConv::ID getCallingConv() const {
981 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
983 void setCallingConv(CallingConv::ID CC) {
984 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
985 (static_cast<unsigned>(CC) << 1));
988 /// getAttributes - Return the parameter attributes for this call.
990 const AttrListPtr &getAttributes() const { return AttributeList; }
992 /// setAttributes - Set the parameter attributes for this call.
994 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
996 /// addAttribute - adds the attribute to the list of attributes.
997 void addAttribute(unsigned i, Attributes attr);
999 /// removeAttribute - removes the attribute from the list of attributes.
1000 void removeAttribute(unsigned i, Attributes attr);
1002 /// @brief Determine whether the call or the callee has the given attribute.
1003 bool paramHasAttr(unsigned i, Attributes attr) const;
1005 /// @brief Extract the alignment for a call or parameter (0=unknown).
1006 unsigned getParamAlignment(unsigned i) const {
1007 return AttributeList.getParamAlignment(i);
1010 /// @brief Return true if the call should not be inlined.
1011 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
1012 void setIsNoInline(bool Value) {
1013 if (Value) addAttribute(~0, Attribute::NoInline);
1014 else removeAttribute(~0, Attribute::NoInline);
1017 /// @brief Determine if the call does not access memory.
1018 bool doesNotAccessMemory() const {
1019 return paramHasAttr(~0, Attribute::ReadNone);
1021 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1022 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1023 else removeAttribute(~0, Attribute::ReadNone);
1026 /// @brief Determine if the call does not access or only reads memory.
1027 bool onlyReadsMemory() const {
1028 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1030 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1031 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1032 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1035 /// @brief Determine if the call cannot return.
1036 bool doesNotReturn() const {
1037 return paramHasAttr(~0, Attribute::NoReturn);
1039 void setDoesNotReturn(bool DoesNotReturn = true) {
1040 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1041 else removeAttribute(~0, Attribute::NoReturn);
1044 /// @brief Determine if the call cannot unwind.
1045 bool doesNotThrow() const {
1046 return paramHasAttr(~0, Attribute::NoUnwind);
1048 void setDoesNotThrow(bool DoesNotThrow = true) {
1049 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1050 else removeAttribute(~0, Attribute::NoUnwind);
1053 /// @brief Determine if the call returns a structure through first
1054 /// pointer argument.
1055 bool hasStructRetAttr() const {
1056 // Be friendly and also check the callee.
1057 return paramHasAttr(1, Attribute::StructRet);
1060 /// @brief Determine if any call argument is an aggregate passed by value.
1061 bool hasByValArgument() const {
1062 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1065 /// getCalledFunction - Return the function called, or null if this is an
1066 /// indirect function invocation.
1068 Function *getCalledFunction() const {
1069 return dyn_cast<Function>(Op<ArgOffset -1>());
1072 /// getCalledValue - Get a pointer to the function that is invoked by this
1074 const Value *getCalledValue() const { return Op<ArgOffset -1>(); }
1075 Value *getCalledValue() { return Op<ArgOffset -1>(); }
1077 /// setCalledFunction - Set the function called.
1078 void setCalledFunction(Value* Fn) {
1079 Op<ArgOffset -1>() = Fn;
1082 // Methods for support type inquiry through isa, cast, and dyn_cast:
1083 static inline bool classof(const CallInst *) { return true; }
1084 static inline bool classof(const Instruction *I) {
1085 return I->getOpcode() == Instruction::Call;
1087 static inline bool classof(const Value *V) {
1088 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1091 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1092 // method so that subclasses cannot accidentally use it.
1093 void setInstructionSubclassData(unsigned short D) {
1094 Instruction::setInstructionSubclassData(D);
1099 struct OperandTraits<CallInst> : public VariadicOperandTraits<1> {
1102 template<typename InputIterator>
1103 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1104 const Twine &NameStr, BasicBlock *InsertAtEnd)
1105 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1106 ->getElementType())->getReturnType(),
1108 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1109 unsigned(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1110 init(Func, ArgBegin, ArgEnd, NameStr,
1111 typename std::iterator_traits<InputIterator>::iterator_category());
1114 template<typename InputIterator>
1115 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1116 const Twine &NameStr, Instruction *InsertBefore)
1117 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1118 ->getElementType())->getReturnType(),
1120 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1121 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
1122 init(Func, ArgBegin, ArgEnd, NameStr,
1123 typename std::iterator_traits<InputIterator>::iterator_category());
1127 // Note: if you get compile errors about private methods then
1128 // please update your code to use the high-level operand
1129 // interfaces. See line 943 above.
1130 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1132 //===----------------------------------------------------------------------===//
1134 //===----------------------------------------------------------------------===//
1136 /// SelectInst - This class represents the LLVM 'select' instruction.
1138 class SelectInst : public Instruction {
1139 void init(Value *C, Value *S1, Value *S2) {
1140 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1146 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1147 Instruction *InsertBefore)
1148 : Instruction(S1->getType(), Instruction::Select,
1149 &Op<0>(), 3, InsertBefore) {
1153 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1154 BasicBlock *InsertAtEnd)
1155 : Instruction(S1->getType(), Instruction::Select,
1156 &Op<0>(), 3, InsertAtEnd) {
1161 virtual SelectInst *clone_impl() const;
1163 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1164 const Twine &NameStr = "",
1165 Instruction *InsertBefore = 0) {
1166 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1168 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1169 const Twine &NameStr,
1170 BasicBlock *InsertAtEnd) {
1171 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1174 const Value *getCondition() const { return Op<0>(); }
1175 const Value *getTrueValue() const { return Op<1>(); }
1176 const Value *getFalseValue() const { return Op<2>(); }
1177 Value *getCondition() { return Op<0>(); }
1178 Value *getTrueValue() { return Op<1>(); }
1179 Value *getFalseValue() { return Op<2>(); }
1181 /// areInvalidOperands - Return a string if the specified operands are invalid
1182 /// for a select operation, otherwise return null.
1183 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1185 /// Transparently provide more efficient getOperand methods.
1186 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1188 OtherOps getOpcode() const {
1189 return static_cast<OtherOps>(Instruction::getOpcode());
1192 // Methods for support type inquiry through isa, cast, and dyn_cast:
1193 static inline bool classof(const SelectInst *) { return true; }
1194 static inline bool classof(const Instruction *I) {
1195 return I->getOpcode() == Instruction::Select;
1197 static inline bool classof(const Value *V) {
1198 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1203 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> {
1206 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1208 //===----------------------------------------------------------------------===//
1210 //===----------------------------------------------------------------------===//
1212 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1213 /// an argument of the specified type given a va_list and increments that list
1215 class VAArgInst : public UnaryInstruction {
1217 virtual VAArgInst *clone_impl() const;
1220 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1221 Instruction *InsertBefore = 0)
1222 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1225 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1226 BasicBlock *InsertAtEnd)
1227 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1231 // Methods for support type inquiry through isa, cast, and dyn_cast:
1232 static inline bool classof(const VAArgInst *) { return true; }
1233 static inline bool classof(const Instruction *I) {
1234 return I->getOpcode() == VAArg;
1236 static inline bool classof(const Value *V) {
1237 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1241 //===----------------------------------------------------------------------===//
1242 // ExtractElementInst Class
1243 //===----------------------------------------------------------------------===//
1245 /// ExtractElementInst - This instruction extracts a single (scalar)
1246 /// element from a VectorType value
1248 class ExtractElementInst : public Instruction {
1249 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1250 Instruction *InsertBefore = 0);
1251 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1252 BasicBlock *InsertAtEnd);
1254 virtual ExtractElementInst *clone_impl() const;
1257 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1258 const Twine &NameStr = "",
1259 Instruction *InsertBefore = 0) {
1260 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1262 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1263 const Twine &NameStr,
1264 BasicBlock *InsertAtEnd) {
1265 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1268 /// isValidOperands - Return true if an extractelement instruction can be
1269 /// formed with the specified operands.
1270 static bool isValidOperands(const Value *Vec, const Value *Idx);
1272 Value *getVectorOperand() { return Op<0>(); }
1273 Value *getIndexOperand() { return Op<1>(); }
1274 const Value *getVectorOperand() const { return Op<0>(); }
1275 const Value *getIndexOperand() const { return Op<1>(); }
1277 const VectorType *getVectorOperandType() const {
1278 return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
1282 /// Transparently provide more efficient getOperand methods.
1283 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1285 // Methods for support type inquiry through isa, cast, and dyn_cast:
1286 static inline bool classof(const ExtractElementInst *) { return true; }
1287 static inline bool classof(const Instruction *I) {
1288 return I->getOpcode() == Instruction::ExtractElement;
1290 static inline bool classof(const Value *V) {
1291 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1296 struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> {
1299 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1301 //===----------------------------------------------------------------------===//
1302 // InsertElementInst Class
1303 //===----------------------------------------------------------------------===//
1305 /// InsertElementInst - This instruction inserts a single (scalar)
1306 /// element into a VectorType value
1308 class InsertElementInst : public Instruction {
1309 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1310 const Twine &NameStr = "",
1311 Instruction *InsertBefore = 0);
1312 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1313 const Twine &NameStr, BasicBlock *InsertAtEnd);
1315 virtual InsertElementInst *clone_impl() const;
1318 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1319 const Twine &NameStr = "",
1320 Instruction *InsertBefore = 0) {
1321 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1323 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1324 const Twine &NameStr,
1325 BasicBlock *InsertAtEnd) {
1326 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1329 /// isValidOperands - Return true if an insertelement instruction can be
1330 /// formed with the specified operands.
1331 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1334 /// getType - Overload to return most specific vector type.
1336 const VectorType *getType() const {
1337 return reinterpret_cast<const VectorType*>(Instruction::getType());
1340 /// Transparently provide more efficient getOperand methods.
1341 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1343 // Methods for support type inquiry through isa, cast, and dyn_cast:
1344 static inline bool classof(const InsertElementInst *) { return true; }
1345 static inline bool classof(const Instruction *I) {
1346 return I->getOpcode() == Instruction::InsertElement;
1348 static inline bool classof(const Value *V) {
1349 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1354 struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
1357 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1359 //===----------------------------------------------------------------------===//
1360 // ShuffleVectorInst Class
1361 //===----------------------------------------------------------------------===//
1363 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1366 class ShuffleVectorInst : public Instruction {
1368 virtual ShuffleVectorInst *clone_impl() const;
1371 // allocate space for exactly three operands
1372 void *operator new(size_t s) {
1373 return User::operator new(s, 3);
1375 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1376 const Twine &NameStr = "",
1377 Instruction *InsertBefor = 0);
1378 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1379 const Twine &NameStr, BasicBlock *InsertAtEnd);
1381 /// isValidOperands - Return true if a shufflevector instruction can be
1382 /// formed with the specified operands.
1383 static bool isValidOperands(const Value *V1, const Value *V2,
1386 /// getType - Overload to return most specific vector type.
1388 const VectorType *getType() const {
1389 return reinterpret_cast<const VectorType*>(Instruction::getType());
1392 /// Transparently provide more efficient getOperand methods.
1393 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1395 /// getMaskValue - Return the index from the shuffle mask for the specified
1396 /// output result. This is either -1 if the element is undef or a number less
1397 /// than 2*numelements.
1398 int getMaskValue(unsigned i) const;
1400 // Methods for support type inquiry through isa, cast, and dyn_cast:
1401 static inline bool classof(const ShuffleVectorInst *) { return true; }
1402 static inline bool classof(const Instruction *I) {
1403 return I->getOpcode() == Instruction::ShuffleVector;
1405 static inline bool classof(const Value *V) {
1406 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1411 struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
1414 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1416 //===----------------------------------------------------------------------===//
1417 // ExtractValueInst Class
1418 //===----------------------------------------------------------------------===//
1420 /// ExtractValueInst - This instruction extracts a struct member or array
1421 /// element value from an aggregate value.
1423 class ExtractValueInst : public UnaryInstruction {
1424 SmallVector<unsigned, 4> Indices;
1426 ExtractValueInst(const ExtractValueInst &EVI);
1427 void init(const unsigned *Idx, unsigned NumIdx,
1428 const Twine &NameStr);
1429 void init(unsigned Idx, const Twine &NameStr);
1431 template<typename InputIterator>
1432 void init(InputIterator IdxBegin, InputIterator 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
1456 static const Type *getIndexedType(const Type *Agg,
1457 const unsigned *Idx, unsigned NumIdx);
1459 template<typename InputIterator>
1460 static const Type *getIndexedType(const Type *Ptr,
1461 InputIterator IdxBegin,
1462 InputIterator IdxEnd,
1463 // This argument ensures that we
1464 // have an iterator we can do
1465 // arithmetic on in constant time
1466 std::random_access_iterator_tag) {
1467 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1470 // This requires that the iterator points to contiguous memory.
1471 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
1473 return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
1476 /// Constructors - Create a extractvalue instruction with a base aggregate
1477 /// value and a list of indices. The first ctor can optionally insert before
1478 /// an existing instruction, the second appends the new instruction to the
1479 /// specified BasicBlock.
1480 template<typename InputIterator>
1481 inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
1482 InputIterator IdxEnd,
1483 const Twine &NameStr,
1484 Instruction *InsertBefore);
1485 template<typename InputIterator>
1486 inline ExtractValueInst(Value *Agg,
1487 InputIterator IdxBegin, InputIterator IdxEnd,
1488 const Twine &NameStr, BasicBlock *InsertAtEnd);
1490 // allocate space for exactly one operand
1491 void *operator new(size_t s) {
1492 return User::operator new(s, 1);
1495 virtual ExtractValueInst *clone_impl() const;
1498 template<typename InputIterator>
1499 static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
1500 InputIterator IdxEnd,
1501 const Twine &NameStr = "",
1502 Instruction *InsertBefore = 0) {
1504 ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
1506 template<typename InputIterator>
1507 static ExtractValueInst *Create(Value *Agg,
1508 InputIterator IdxBegin, InputIterator IdxEnd,
1509 const Twine &NameStr,
1510 BasicBlock *InsertAtEnd) {
1511 return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
1514 /// Constructors - These two creators are convenience methods because one
1515 /// index extractvalue instructions are much more common than those with
1517 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1518 const Twine &NameStr = "",
1519 Instruction *InsertBefore = 0) {
1520 unsigned Idxs[1] = { Idx };
1521 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
1523 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1524 const Twine &NameStr,
1525 BasicBlock *InsertAtEnd) {
1526 unsigned Idxs[1] = { Idx };
1527 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
1530 /// getIndexedType - Returns the type of the element that would be extracted
1531 /// with an extractvalue instruction with the specified parameters.
1533 /// Null is returned if the indices are invalid for the specified
1536 template<typename InputIterator>
1537 static const Type *getIndexedType(const Type *Ptr,
1538 InputIterator IdxBegin,
1539 InputIterator IdxEnd) {
1540 return getIndexedType(Ptr, IdxBegin, IdxEnd,
1541 typename std::iterator_traits<InputIterator>::
1542 iterator_category());
1544 static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
1546 typedef const unsigned* idx_iterator;
1547 inline idx_iterator idx_begin() const { return Indices.begin(); }
1548 inline idx_iterator idx_end() const { return Indices.end(); }
1550 Value *getAggregateOperand() {
1551 return getOperand(0);
1553 const Value *getAggregateOperand() const {
1554 return getOperand(0);
1556 static unsigned getAggregateOperandIndex() {
1557 return 0U; // get index for modifying correct operand
1560 unsigned getNumIndices() const { // Note: always non-negative
1561 return (unsigned)Indices.size();
1564 bool hasIndices() const {
1568 // Methods for support type inquiry through isa, cast, and dyn_cast:
1569 static inline bool classof(const ExtractValueInst *) { return true; }
1570 static inline bool classof(const Instruction *I) {
1571 return I->getOpcode() == Instruction::ExtractValue;
1573 static inline bool classof(const Value *V) {
1574 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1578 template<typename InputIterator>
1579 ExtractValueInst::ExtractValueInst(Value *Agg,
1580 InputIterator IdxBegin,
1581 InputIterator IdxEnd,
1582 const Twine &NameStr,
1583 Instruction *InsertBefore)
1584 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1586 ExtractValue, Agg, InsertBefore) {
1587 init(IdxBegin, IdxEnd, NameStr,
1588 typename std::iterator_traits<InputIterator>::iterator_category());
1590 template<typename InputIterator>
1591 ExtractValueInst::ExtractValueInst(Value *Agg,
1592 InputIterator IdxBegin,
1593 InputIterator IdxEnd,
1594 const Twine &NameStr,
1595 BasicBlock *InsertAtEnd)
1596 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1598 ExtractValue, Agg, InsertAtEnd) {
1599 init(IdxBegin, IdxEnd, NameStr,
1600 typename std::iterator_traits<InputIterator>::iterator_category());
1604 //===----------------------------------------------------------------------===//
1605 // InsertValueInst Class
1606 //===----------------------------------------------------------------------===//
1608 /// InsertValueInst - This instruction inserts a struct field of array element
1609 /// value into an aggregate value.
1611 class InsertValueInst : public Instruction {
1612 SmallVector<unsigned, 4> Indices;
1614 void *operator new(size_t, unsigned); // Do not implement
1615 InsertValueInst(const InsertValueInst &IVI);
1616 void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1617 const Twine &NameStr);
1618 void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
1620 template<typename InputIterator>
1621 void init(Value *Agg, Value *Val,
1622 InputIterator IdxBegin, InputIterator IdxEnd,
1623 const Twine &NameStr,
1624 // This argument ensures that we have an iterator we can
1625 // do arithmetic on in constant time
1626 std::random_access_iterator_tag) {
1627 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1629 // There's no fundamental reason why we require at least one index
1630 // (other than weirdness with &*IdxBegin being invalid; see
1631 // getelementptr's init routine for example). But there's no
1632 // present need to support it.
1633 assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1635 // This requires that the iterator points to contiguous memory.
1636 init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1637 // we have to build an array here
1640 /// Constructors - Create a insertvalue instruction with a base aggregate
1641 /// value, a value to insert, and a list of indices. The first ctor can
1642 /// optionally insert before an existing instruction, the second appends
1643 /// the new instruction to the specified BasicBlock.
1644 template<typename InputIterator>
1645 inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
1646 InputIterator IdxEnd,
1647 const Twine &NameStr,
1648 Instruction *InsertBefore);
1649 template<typename InputIterator>
1650 inline InsertValueInst(Value *Agg, Value *Val,
1651 InputIterator IdxBegin, InputIterator IdxEnd,
1652 const Twine &NameStr, BasicBlock *InsertAtEnd);
1654 /// Constructors - These two constructors are convenience methods because one
1655 /// and two index insertvalue instructions are so common.
1656 InsertValueInst(Value *Agg, Value *Val,
1657 unsigned Idx, const Twine &NameStr = "",
1658 Instruction *InsertBefore = 0);
1659 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1660 const Twine &NameStr, BasicBlock *InsertAtEnd);
1662 virtual InsertValueInst *clone_impl() const;
1664 // allocate space for exactly two operands
1665 void *operator new(size_t s) {
1666 return User::operator new(s, 2);
1669 template<typename InputIterator>
1670 static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
1671 InputIterator IdxEnd,
1672 const Twine &NameStr = "",
1673 Instruction *InsertBefore = 0) {
1674 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1675 NameStr, InsertBefore);
1677 template<typename InputIterator>
1678 static InsertValueInst *Create(Value *Agg, Value *Val,
1679 InputIterator IdxBegin, InputIterator IdxEnd,
1680 const Twine &NameStr,
1681 BasicBlock *InsertAtEnd) {
1682 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1683 NameStr, InsertAtEnd);
1686 /// Constructors - These two creators are convenience methods because one
1687 /// index insertvalue instructions are much more common than those with
1689 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1690 const Twine &NameStr = "",
1691 Instruction *InsertBefore = 0) {
1692 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
1694 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1695 const Twine &NameStr,
1696 BasicBlock *InsertAtEnd) {
1697 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
1700 /// Transparently provide more efficient getOperand methods.
1701 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1703 typedef const unsigned* idx_iterator;
1704 inline idx_iterator idx_begin() const { return Indices.begin(); }
1705 inline idx_iterator idx_end() const { return Indices.end(); }
1707 Value *getAggregateOperand() {
1708 return getOperand(0);
1710 const Value *getAggregateOperand() const {
1711 return getOperand(0);
1713 static unsigned getAggregateOperandIndex() {
1714 return 0U; // get index for modifying correct operand
1717 Value *getInsertedValueOperand() {
1718 return getOperand(1);
1720 const Value *getInsertedValueOperand() const {
1721 return getOperand(1);
1723 static unsigned getInsertedValueOperandIndex() {
1724 return 1U; // get index for modifying correct operand
1727 unsigned getNumIndices() const { // Note: always non-negative
1728 return (unsigned)Indices.size();
1731 bool hasIndices() const {
1735 // Methods for support type inquiry through isa, cast, and dyn_cast:
1736 static inline bool classof(const InsertValueInst *) { return true; }
1737 static inline bool classof(const Instruction *I) {
1738 return I->getOpcode() == Instruction::InsertValue;
1740 static inline bool classof(const Value *V) {
1741 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1746 struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
1749 template<typename InputIterator>
1750 InsertValueInst::InsertValueInst(Value *Agg,
1752 InputIterator IdxBegin,
1753 InputIterator IdxEnd,
1754 const Twine &NameStr,
1755 Instruction *InsertBefore)
1756 : Instruction(Agg->getType(), InsertValue,
1757 OperandTraits<InsertValueInst>::op_begin(this),
1759 init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1760 typename std::iterator_traits<InputIterator>::iterator_category());
1762 template<typename InputIterator>
1763 InsertValueInst::InsertValueInst(Value *Agg,
1765 InputIterator IdxBegin,
1766 InputIterator IdxEnd,
1767 const Twine &NameStr,
1768 BasicBlock *InsertAtEnd)
1769 : Instruction(Agg->getType(), InsertValue,
1770 OperandTraits<InsertValueInst>::op_begin(this),
1772 init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1773 typename std::iterator_traits<InputIterator>::iterator_category());
1776 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1778 //===----------------------------------------------------------------------===//
1780 //===----------------------------------------------------------------------===//
1782 // PHINode - The PHINode class is used to represent the magical mystical PHI
1783 // node, that can not exist in nature, but can be synthesized in a computer
1784 // scientist's overactive imagination.
1786 class PHINode : public Instruction {
1787 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1788 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1789 /// the number actually in use.
1790 unsigned ReservedSpace;
1791 PHINode(const PHINode &PN);
1792 // allocate space for exactly zero operands
1793 void *operator new(size_t s) {
1794 return User::operator new(s, 0);
1796 explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1797 Instruction *InsertBefore = 0)
1798 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1803 PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1804 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1809 virtual PHINode *clone_impl() const;
1811 static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1812 Instruction *InsertBefore = 0) {
1813 return new PHINode(Ty, NameStr, InsertBefore);
1815 static PHINode *Create(const Type *Ty, const Twine &NameStr,
1816 BasicBlock *InsertAtEnd) {
1817 return new PHINode(Ty, NameStr, InsertAtEnd);
1821 /// reserveOperandSpace - This method can be used to avoid repeated
1822 /// reallocation of PHI operand lists by reserving space for the correct
1823 /// number of operands before adding them. Unlike normal vector reserves,
1824 /// this method can also be used to trim the operand space.
1825 void reserveOperandSpace(unsigned NumValues) {
1826 resizeOperands(NumValues*2);
1829 /// Provide fast operand accessors
1830 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1832 /// getNumIncomingValues - Return the number of incoming edges
1834 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1836 /// getIncomingValue - Return incoming value number x
1838 Value *getIncomingValue(unsigned i) const {
1839 assert(i*2 < getNumOperands() && "Invalid value number!");
1840 return getOperand(i*2);
1842 void setIncomingValue(unsigned i, Value *V) {
1843 assert(i*2 < getNumOperands() && "Invalid value number!");
1846 static unsigned getOperandNumForIncomingValue(unsigned i) {
1849 static unsigned getIncomingValueNumForOperand(unsigned i) {
1850 assert(i % 2 == 0 && "Invalid incoming-value operand index!");
1854 /// getIncomingBlock - Return incoming basic block number @p i.
1856 BasicBlock *getIncomingBlock(unsigned i) const {
1857 return cast<BasicBlock>(getOperand(i*2+1));
1860 /// getIncomingBlock - Return incoming basic block corresponding
1861 /// to an operand of the PHI.
1863 BasicBlock *getIncomingBlock(const Use &U) const {
1864 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1865 return cast<BasicBlock>((&U + 1)->get());
1868 /// getIncomingBlock - Return incoming basic block corresponding
1869 /// to value use iterator.
1871 template <typename U>
1872 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1873 return getIncomingBlock(I.getUse());
1877 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1878 setOperand(i*2+1, (Value*)BB);
1880 static unsigned getOperandNumForIncomingBlock(unsigned i) {
1883 static unsigned getIncomingBlockNumForOperand(unsigned i) {
1884 assert(i % 2 == 1 && "Invalid incoming-block operand index!");
1888 /// addIncoming - Add an incoming value to the end of the PHI list
1890 void addIncoming(Value *V, BasicBlock *BB) {
1891 assert(V && "PHI node got a null value!");
1892 assert(BB && "PHI node got a null basic block!");
1893 assert(getType() == V->getType() &&
1894 "All operands to PHI node must be the same type as the PHI node!");
1895 unsigned OpNo = NumOperands;
1896 if (OpNo+2 > ReservedSpace)
1897 resizeOperands(0); // Get more space!
1898 // Initialize some new operands.
1899 NumOperands = OpNo+2;
1900 OperandList[OpNo] = V;
1901 OperandList[OpNo+1] = (Value*)BB;
1904 /// removeIncomingValue - Remove an incoming value. This is useful if a
1905 /// predecessor basic block is deleted. The value removed is returned.
1907 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1908 /// is true), the PHI node is destroyed and any uses of it are replaced with
1909 /// dummy values. The only time there should be zero incoming values to a PHI
1910 /// node is when the block is dead, so this strategy is sound.
1912 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1914 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1915 int Idx = getBasicBlockIndex(BB);
1916 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1917 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1920 /// getBasicBlockIndex - Return the first index of the specified basic
1921 /// block in the value list for this PHI. Returns -1 if no instance.
1923 int getBasicBlockIndex(const BasicBlock *BB) const {
1924 Use *OL = OperandList;
1925 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1926 if (OL[i+1].get() == (const Value*)BB) return i/2;
1930 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1931 return getIncomingValue(getBasicBlockIndex(BB));
1934 /// hasConstantValue - If the specified PHI node always merges together the
1935 /// same value, return the value, otherwise return null.
1937 /// If the PHI has undef operands, but all the rest of the operands are
1938 /// some unique value, return that value if it can be proved that the
1939 /// value dominates the PHI. If DT is null, use a conservative check,
1940 /// otherwise use DT to test for dominance.
1942 Value *hasConstantValue(DominatorTree *DT = 0) const;
1944 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1945 static inline bool classof(const PHINode *) { return true; }
1946 static inline bool classof(const Instruction *I) {
1947 return I->getOpcode() == Instruction::PHI;
1949 static inline bool classof(const Value *V) {
1950 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1953 void resizeOperands(unsigned NumOperands);
1957 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1960 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1963 //===----------------------------------------------------------------------===//
1965 //===----------------------------------------------------------------------===//
1967 //===---------------------------------------------------------------------------
1968 /// ReturnInst - Return a value (possibly void), from a function. Execution
1969 /// does not continue in this function any longer.
1971 class ReturnInst : public TerminatorInst {
1972 ReturnInst(const ReturnInst &RI);
1975 // ReturnInst constructors:
1976 // ReturnInst() - 'ret void' instruction
1977 // ReturnInst( null) - 'ret void' instruction
1978 // ReturnInst(Value* X) - 'ret X' instruction
1979 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1980 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1981 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1982 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1984 // NOTE: If the Value* passed is of type void then the constructor behaves as
1985 // if it was passed NULL.
1986 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1987 Instruction *InsertBefore = 0);
1988 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1989 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1991 virtual ReturnInst *clone_impl() const;
1993 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1994 Instruction *InsertBefore = 0) {
1995 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1997 static ReturnInst* Create(LLVMContext &C, Value *retVal,
1998 BasicBlock *InsertAtEnd) {
1999 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2001 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2002 return new(0) ReturnInst(C, InsertAtEnd);
2004 virtual ~ReturnInst();
2006 /// Provide fast operand accessors
2007 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2009 /// Convenience accessor
2010 Value *getReturnValue(unsigned n = 0) const {
2011 return n < getNumOperands()
2016 unsigned getNumSuccessors() const { return 0; }
2018 // Methods for support type inquiry through isa, cast, and dyn_cast:
2019 static inline bool classof(const ReturnInst *) { return true; }
2020 static inline bool classof(const Instruction *I) {
2021 return (I->getOpcode() == Instruction::Ret);
2023 static inline bool classof(const Value *V) {
2024 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2027 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2028 virtual unsigned getNumSuccessorsV() const;
2029 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2033 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<> {
2036 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2038 //===----------------------------------------------------------------------===//
2040 //===----------------------------------------------------------------------===//
2042 //===---------------------------------------------------------------------------
2043 /// BranchInst - Conditional or Unconditional Branch instruction.
2045 class BranchInst : public TerminatorInst {
2046 /// Ops list - Branches are strange. The operands are ordered:
2047 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2048 /// they don't have to check for cond/uncond branchness. These are mostly
2049 /// accessed relative from op_end().
2050 BranchInst(const BranchInst &BI);
2052 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2053 // BranchInst(BB *B) - 'br B'
2054 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2055 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2056 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2057 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2058 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2059 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2060 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2061 Instruction *InsertBefore = 0);
2062 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2063 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2064 BasicBlock *InsertAtEnd);
2066 virtual BranchInst *clone_impl() const;
2068 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2069 return new(1, true) BranchInst(IfTrue, InsertBefore);
2071 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2072 Value *Cond, Instruction *InsertBefore = 0) {
2073 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2075 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2076 return new(1, true) BranchInst(IfTrue, InsertAtEnd);
2078 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2079 Value *Cond, BasicBlock *InsertAtEnd) {
2080 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2085 /// Transparently provide more efficient getOperand methods.
2086 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2088 bool isUnconditional() const { return getNumOperands() == 1; }
2089 bool isConditional() const { return getNumOperands() == 3; }
2091 Value *getCondition() const {
2092 assert(isConditional() && "Cannot get condition of an uncond branch!");
2096 void setCondition(Value *V) {
2097 assert(isConditional() && "Cannot set condition of unconditional branch!");
2101 // setUnconditionalDest - Change the current branch to an unconditional branch
2102 // targeting the specified block.
2103 // FIXME: Eliminate this ugly method.
2104 void setUnconditionalDest(BasicBlock *Dest) {
2105 Op<-1>() = (Value*)Dest;
2106 if (isConditional()) { // Convert this to an uncond branch.
2110 OperandList = op_begin();
2114 unsigned getNumSuccessors() const { return 1+isConditional(); }
2116 BasicBlock *getSuccessor(unsigned i) const {
2117 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2118 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2121 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2122 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2123 *(&Op<-1>() - idx) = (Value*)NewSucc;
2126 // Methods for support type inquiry through isa, cast, and dyn_cast:
2127 static inline bool classof(const BranchInst *) { return true; }
2128 static inline bool classof(const Instruction *I) {
2129 return (I->getOpcode() == Instruction::Br);
2131 static inline bool classof(const Value *V) {
2132 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2135 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2136 virtual unsigned getNumSuccessorsV() const;
2137 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2141 struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
2143 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2145 //===----------------------------------------------------------------------===//
2147 //===----------------------------------------------------------------------===//
2149 //===---------------------------------------------------------------------------
2150 /// SwitchInst - Multiway switch
2152 class SwitchInst : public TerminatorInst {
2153 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2154 unsigned ReservedSpace;
2155 // Operand[0] = Value to switch on
2156 // Operand[1] = Default basic block destination
2157 // Operand[2n ] = Value to match
2158 // Operand[2n+1] = BasicBlock to go to on match
2159 SwitchInst(const SwitchInst &SI);
2160 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
2161 void resizeOperands(unsigned No);
2162 // allocate space for exactly zero operands
2163 void *operator new(size_t s) {
2164 return User::operator new(s, 0);
2166 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2167 /// switch on and a default destination. The number of additional cases can
2168 /// be specified here to make memory allocation more efficient. This
2169 /// constructor can also autoinsert before another instruction.
2170 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2171 Instruction *InsertBefore);
2173 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2174 /// switch on and a default destination. The number of additional cases can
2175 /// be specified here to make memory allocation more efficient. This
2176 /// constructor also autoinserts at the end of the specified BasicBlock.
2177 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2178 BasicBlock *InsertAtEnd);
2180 virtual SwitchInst *clone_impl() const;
2182 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2183 unsigned NumCases, Instruction *InsertBefore = 0) {
2184 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2186 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2187 unsigned NumCases, BasicBlock *InsertAtEnd) {
2188 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2192 /// Provide fast operand accessors
2193 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2195 // Accessor Methods for Switch stmt
2196 Value *getCondition() const { return getOperand(0); }
2197 void setCondition(Value *V) { setOperand(0, V); }
2199 BasicBlock *getDefaultDest() const {
2200 return cast<BasicBlock>(getOperand(1));
2203 /// getNumCases - return the number of 'cases' in this switch instruction.
2204 /// Note that case #0 is always the default case.
2205 unsigned getNumCases() const {
2206 return getNumOperands()/2;
2209 /// getCaseValue - Return the specified case value. Note that case #0, the
2210 /// default destination, does not have a case value.
2211 ConstantInt *getCaseValue(unsigned i) {
2212 assert(i && i < getNumCases() && "Illegal case value to get!");
2213 return getSuccessorValue(i);
2216 /// getCaseValue - Return the specified case value. Note that case #0, the
2217 /// default destination, does not have a case value.
2218 const ConstantInt *getCaseValue(unsigned i) const {
2219 assert(i && i < getNumCases() && "Illegal case value to get!");
2220 return getSuccessorValue(i);
2223 /// findCaseValue - Search all of the case values for the specified constant.
2224 /// If it is explicitly handled, return the case number of it, otherwise
2225 /// return 0 to indicate that it is handled by the default handler.
2226 unsigned findCaseValue(const ConstantInt *C) const {
2227 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2228 if (getCaseValue(i) == C)
2233 /// findCaseDest - Finds the unique case value for a given successor. Returns
2234 /// null if the successor is not found, not unique, or is the default case.
2235 ConstantInt *findCaseDest(BasicBlock *BB) {
2236 if (BB == getDefaultDest()) return NULL;
2238 ConstantInt *CI = NULL;
2239 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2240 if (getSuccessor(i) == BB) {
2241 if (CI) return NULL; // Multiple cases lead to BB.
2242 else CI = getCaseValue(i);
2248 /// addCase - Add an entry to the switch instruction...
2250 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2252 /// removeCase - This method removes the specified successor from the switch
2253 /// instruction. Note that this cannot be used to remove the default
2254 /// destination (successor #0).
2256 void removeCase(unsigned idx);
2258 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2259 BasicBlock *getSuccessor(unsigned idx) const {
2260 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2261 return cast<BasicBlock>(getOperand(idx*2+1));
2263 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2264 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2265 setOperand(idx*2+1, (Value*)NewSucc);
2268 // getSuccessorValue - Return the value associated with the specified
2270 ConstantInt *getSuccessorValue(unsigned idx) const {
2271 assert(idx < getNumSuccessors() && "Successor # out of range!");
2272 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2275 // Methods for support type inquiry through isa, cast, and dyn_cast:
2276 static inline bool classof(const SwitchInst *) { return true; }
2277 static inline bool classof(const Instruction *I) {
2278 return I->getOpcode() == Instruction::Switch;
2280 static inline bool classof(const Value *V) {
2281 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2284 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2285 virtual unsigned getNumSuccessorsV() const;
2286 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2290 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2293 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2296 //===----------------------------------------------------------------------===//
2297 // IndirectBrInst Class
2298 //===----------------------------------------------------------------------===//
2300 //===---------------------------------------------------------------------------
2301 /// IndirectBrInst - Indirect Branch Instruction.
2303 class IndirectBrInst : public TerminatorInst {
2304 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2305 unsigned ReservedSpace;
2306 // Operand[0] = Value to switch on
2307 // Operand[1] = Default basic block destination
2308 // Operand[2n ] = Value to match
2309 // Operand[2n+1] = BasicBlock to go to on match
2310 IndirectBrInst(const IndirectBrInst &IBI);
2311 void init(Value *Address, unsigned NumDests);
2312 void resizeOperands(unsigned No);
2313 // allocate space for exactly zero operands
2314 void *operator new(size_t s) {
2315 return User::operator new(s, 0);
2317 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2318 /// Address to jump to. The number of expected destinations can be specified
2319 /// here to make memory allocation more efficient. This constructor can also
2320 /// autoinsert before another instruction.
2321 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2323 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2324 /// Address to jump to. The number of expected destinations can be specified
2325 /// here to make memory allocation more efficient. This constructor also
2326 /// autoinserts at the end of the specified BasicBlock.
2327 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2329 virtual IndirectBrInst *clone_impl() const;
2331 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2332 Instruction *InsertBefore = 0) {
2333 return new IndirectBrInst(Address, NumDests, InsertBefore);
2335 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2336 BasicBlock *InsertAtEnd) {
2337 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2341 /// Provide fast operand accessors.
2342 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2344 // Accessor Methods for IndirectBrInst instruction.
2345 Value *getAddress() { return getOperand(0); }
2346 const Value *getAddress() const { return getOperand(0); }
2347 void setAddress(Value *V) { setOperand(0, V); }
2350 /// getNumDestinations - return the number of possible destinations in this
2351 /// indirectbr instruction.
2352 unsigned getNumDestinations() const { return getNumOperands()-1; }
2354 /// getDestination - Return the specified destination.
2355 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2356 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2358 /// addDestination - Add a destination.
2360 void addDestination(BasicBlock *Dest);
2362 /// removeDestination - This method removes the specified successor from the
2363 /// indirectbr instruction.
2364 void removeDestination(unsigned i);
2366 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2367 BasicBlock *getSuccessor(unsigned i) const {
2368 return cast<BasicBlock>(getOperand(i+1));
2370 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2371 setOperand(i+1, (Value*)NewSucc);
2374 // Methods for support type inquiry through isa, cast, and dyn_cast:
2375 static inline bool classof(const IndirectBrInst *) { return true; }
2376 static inline bool classof(const Instruction *I) {
2377 return I->getOpcode() == Instruction::IndirectBr;
2379 static inline bool classof(const Value *V) {
2380 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2383 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2384 virtual unsigned getNumSuccessorsV() const;
2385 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2389 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2392 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2395 //===----------------------------------------------------------------------===//
2397 //===----------------------------------------------------------------------===//
2399 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2400 /// calling convention of the call.
2402 class InvokeInst : public TerminatorInst {
2403 AttrListPtr AttributeList;
2404 InvokeInst(const InvokeInst &BI);
2405 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2406 Value* const *Args, unsigned NumArgs);
2408 template<typename InputIterator>
2409 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2410 InputIterator ArgBegin, InputIterator ArgEnd,
2411 const Twine &NameStr,
2412 // This argument ensures that we have an iterator we can
2413 // do arithmetic on in constant time
2414 std::random_access_iterator_tag) {
2415 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2417 // This requires that the iterator points to contiguous memory.
2418 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2422 /// Construct an InvokeInst given a range of arguments.
2423 /// InputIterator must be a random-access iterator pointing to
2424 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2425 /// made for random-accessness but not for contiguous storage as
2426 /// that would incur runtime overhead.
2428 /// @brief Construct an InvokeInst from a range of arguments
2429 template<typename InputIterator>
2430 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2431 InputIterator ArgBegin, InputIterator ArgEnd,
2433 const Twine &NameStr, Instruction *InsertBefore);
2435 /// Construct an InvokeInst given a range of arguments.
2436 /// InputIterator must be a random-access iterator pointing to
2437 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2438 /// made for random-accessness but not for contiguous storage as
2439 /// that would incur runtime overhead.
2441 /// @brief Construct an InvokeInst from a range of arguments
2442 template<typename InputIterator>
2443 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2444 InputIterator ArgBegin, InputIterator ArgEnd,
2446 const Twine &NameStr, BasicBlock *InsertAtEnd);
2448 virtual InvokeInst *clone_impl() const;
2450 template<typename InputIterator>
2451 static InvokeInst *Create(Value *Func,
2452 BasicBlock *IfNormal, BasicBlock *IfException,
2453 InputIterator ArgBegin, InputIterator ArgEnd,
2454 const Twine &NameStr = "",
2455 Instruction *InsertBefore = 0) {
2456 unsigned Values(ArgEnd - ArgBegin + 3);
2457 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2458 Values, NameStr, InsertBefore);
2460 template<typename InputIterator>
2461 static InvokeInst *Create(Value *Func,
2462 BasicBlock *IfNormal, BasicBlock *IfException,
2463 InputIterator ArgBegin, InputIterator ArgEnd,
2464 const Twine &NameStr,
2465 BasicBlock *InsertAtEnd) {
2466 unsigned Values(ArgEnd - ArgBegin + 3);
2467 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2468 Values, NameStr, InsertAtEnd);
2471 /// Provide fast operand accessors
2472 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2474 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2475 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2476 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2478 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2480 CallingConv::ID getCallingConv() const {
2481 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2483 void setCallingConv(CallingConv::ID CC) {
2484 setInstructionSubclassData(static_cast<unsigned>(CC));
2487 /// getAttributes - Return the parameter attributes for this invoke.
2489 const AttrListPtr &getAttributes() const { return AttributeList; }
2491 /// setAttributes - Set the parameter attributes for this invoke.
2493 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2495 /// addAttribute - adds the attribute to the list of attributes.
2496 void addAttribute(unsigned i, Attributes attr);
2498 /// removeAttribute - removes the attribute from the list of attributes.
2499 void removeAttribute(unsigned i, Attributes attr);
2501 /// @brief Determine whether the call or the callee has the given attribute.
2502 bool paramHasAttr(unsigned i, Attributes attr) const;
2504 /// @brief Extract the alignment for a call or parameter (0=unknown).
2505 unsigned getParamAlignment(unsigned i) const {
2506 return AttributeList.getParamAlignment(i);
2509 /// @brief Return true if the call should not be inlined.
2510 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2511 void setIsNoInline(bool Value) {
2512 if (Value) addAttribute(~0, Attribute::NoInline);
2513 else removeAttribute(~0, Attribute::NoInline);
2516 /// @brief Determine if the call does not access memory.
2517 bool doesNotAccessMemory() const {
2518 return paramHasAttr(~0, Attribute::ReadNone);
2520 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2521 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2522 else removeAttribute(~0, Attribute::ReadNone);
2525 /// @brief Determine if the call does not access or only reads memory.
2526 bool onlyReadsMemory() const {
2527 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2529 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2530 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2531 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2534 /// @brief Determine if the call cannot return.
2535 bool doesNotReturn() const {
2536 return paramHasAttr(~0, Attribute::NoReturn);
2538 void setDoesNotReturn(bool DoesNotReturn = true) {
2539 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2540 else removeAttribute(~0, Attribute::NoReturn);
2543 /// @brief Determine if the call cannot unwind.
2544 bool doesNotThrow() const {
2545 return paramHasAttr(~0, Attribute::NoUnwind);
2547 void setDoesNotThrow(bool DoesNotThrow = true) {
2548 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2549 else removeAttribute(~0, Attribute::NoUnwind);
2552 /// @brief Determine if the call returns a structure through first
2553 /// pointer argument.
2554 bool hasStructRetAttr() const {
2555 // Be friendly and also check the callee.
2556 return paramHasAttr(1, Attribute::StructRet);
2559 /// @brief Determine if any call argument is an aggregate passed by value.
2560 bool hasByValArgument() const {
2561 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2564 /// getCalledFunction - Return the function called, or null if this is an
2565 /// indirect function invocation.
2567 Function *getCalledFunction() const {
2568 return dyn_cast<Function>(Op<-3>());
2571 /// getCalledValue - Get a pointer to the function that is invoked by this
2573 const Value *getCalledValue() const { return Op<-3>(); }
2574 Value *getCalledValue() { return Op<-3>(); }
2576 /// setCalledFunction - Set the function called.
2577 void setCalledFunction(Value* Fn) {
2581 // get*Dest - Return the destination basic blocks...
2582 BasicBlock *getNormalDest() const {
2583 return cast<BasicBlock>(Op<-2>());
2585 BasicBlock *getUnwindDest() const {
2586 return cast<BasicBlock>(Op<-1>());
2588 void setNormalDest(BasicBlock *B) {
2589 Op<-2>() = reinterpret_cast<Value*>(B);
2591 void setUnwindDest(BasicBlock *B) {
2592 Op<-1>() = reinterpret_cast<Value*>(B);
2595 BasicBlock *getSuccessor(unsigned i) const {
2596 assert(i < 2 && "Successor # out of range for invoke!");
2597 return i == 0 ? getNormalDest() : getUnwindDest();
2600 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2601 assert(idx < 2 && "Successor # out of range for invoke!");
2602 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2605 unsigned getNumSuccessors() const { return 2; }
2607 // Methods for support type inquiry through isa, cast, and dyn_cast:
2608 static inline bool classof(const InvokeInst *) { return true; }
2609 static inline bool classof(const Instruction *I) {
2610 return (I->getOpcode() == Instruction::Invoke);
2612 static inline bool classof(const Value *V) {
2613 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2617 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2618 virtual unsigned getNumSuccessorsV() const;
2619 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2621 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2622 // method so that subclasses cannot accidentally use it.
2623 void setInstructionSubclassData(unsigned short D) {
2624 Instruction::setInstructionSubclassData(D);
2629 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
2632 template<typename InputIterator>
2633 InvokeInst::InvokeInst(Value *Func,
2634 BasicBlock *IfNormal, BasicBlock *IfException,
2635 InputIterator ArgBegin, InputIterator ArgEnd,
2637 const Twine &NameStr, Instruction *InsertBefore)
2638 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2639 ->getElementType())->getReturnType(),
2640 Instruction::Invoke,
2641 OperandTraits<InvokeInst>::op_end(this) - Values,
2642 Values, InsertBefore) {
2643 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2644 typename std::iterator_traits<InputIterator>::iterator_category());
2646 template<typename InputIterator>
2647 InvokeInst::InvokeInst(Value *Func,
2648 BasicBlock *IfNormal, BasicBlock *IfException,
2649 InputIterator ArgBegin, InputIterator ArgEnd,
2651 const Twine &NameStr, BasicBlock *InsertAtEnd)
2652 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2653 ->getElementType())->getReturnType(),
2654 Instruction::Invoke,
2655 OperandTraits<InvokeInst>::op_end(this) - Values,
2656 Values, InsertAtEnd) {
2657 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2658 typename std::iterator_traits<InputIterator>::iterator_category());
2661 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2663 //===----------------------------------------------------------------------===//
2665 //===----------------------------------------------------------------------===//
2667 //===---------------------------------------------------------------------------
2668 /// UnwindInst - Immediately exit the current function, unwinding the stack
2669 /// until an invoke instruction is found.
2671 class UnwindInst : public TerminatorInst {
2672 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2674 virtual UnwindInst *clone_impl() const;
2676 // allocate space for exactly zero operands
2677 void *operator new(size_t s) {
2678 return User::operator new(s, 0);
2680 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2681 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2683 unsigned getNumSuccessors() const { return 0; }
2685 // Methods for support type inquiry through isa, cast, and dyn_cast:
2686 static inline bool classof(const UnwindInst *) { return true; }
2687 static inline bool classof(const Instruction *I) {
2688 return I->getOpcode() == Instruction::Unwind;
2690 static inline bool classof(const Value *V) {
2691 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2694 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2695 virtual unsigned getNumSuccessorsV() const;
2696 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2699 //===----------------------------------------------------------------------===//
2700 // UnreachableInst Class
2701 //===----------------------------------------------------------------------===//
2703 //===---------------------------------------------------------------------------
2704 /// UnreachableInst - This function has undefined behavior. In particular, the
2705 /// presence of this instruction indicates some higher level knowledge that the
2706 /// end of the block cannot be reached.
2708 class UnreachableInst : public TerminatorInst {
2709 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2711 virtual UnreachableInst *clone_impl() const;
2714 // allocate space for exactly zero operands
2715 void *operator new(size_t s) {
2716 return User::operator new(s, 0);
2718 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2719 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2721 unsigned getNumSuccessors() const { return 0; }
2723 // Methods for support type inquiry through isa, cast, and dyn_cast:
2724 static inline bool classof(const UnreachableInst *) { return true; }
2725 static inline bool classof(const Instruction *I) {
2726 return I->getOpcode() == Instruction::Unreachable;
2728 static inline bool classof(const Value *V) {
2729 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2732 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2733 virtual unsigned getNumSuccessorsV() const;
2734 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2737 //===----------------------------------------------------------------------===//
2739 //===----------------------------------------------------------------------===//
2741 /// @brief This class represents a truncation of integer types.
2742 class TruncInst : public CastInst {
2744 /// @brief Clone an identical TruncInst
2745 virtual TruncInst *clone_impl() const;
2748 /// @brief Constructor with insert-before-instruction semantics
2750 Value *S, ///< The value to be truncated
2751 const Type *Ty, ///< The (smaller) type to truncate to
2752 const Twine &NameStr = "", ///< A name for the new instruction
2753 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2756 /// @brief Constructor with insert-at-end-of-block semantics
2758 Value *S, ///< The value to be truncated
2759 const Type *Ty, ///< The (smaller) type to truncate to
2760 const Twine &NameStr, ///< A name for the new instruction
2761 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2764 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2765 static inline bool classof(const TruncInst *) { return true; }
2766 static inline bool classof(const Instruction *I) {
2767 return I->getOpcode() == Trunc;
2769 static inline bool classof(const Value *V) {
2770 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2774 //===----------------------------------------------------------------------===//
2776 //===----------------------------------------------------------------------===//
2778 /// @brief This class represents zero extension of integer types.
2779 class ZExtInst : public CastInst {
2781 /// @brief Clone an identical ZExtInst
2782 virtual ZExtInst *clone_impl() const;
2785 /// @brief Constructor with insert-before-instruction semantics
2787 Value *S, ///< The value to be zero extended
2788 const Type *Ty, ///< The type to zero extend to
2789 const Twine &NameStr = "", ///< A name for the new instruction
2790 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2793 /// @brief Constructor with insert-at-end semantics.
2795 Value *S, ///< The value to be zero extended
2796 const Type *Ty, ///< The type to zero extend to
2797 const Twine &NameStr, ///< A name for the new instruction
2798 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2801 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2802 static inline bool classof(const ZExtInst *) { return true; }
2803 static inline bool classof(const Instruction *I) {
2804 return I->getOpcode() == ZExt;
2806 static inline bool classof(const Value *V) {
2807 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2811 //===----------------------------------------------------------------------===//
2813 //===----------------------------------------------------------------------===//
2815 /// @brief This class represents a sign extension of integer types.
2816 class SExtInst : public CastInst {
2818 /// @brief Clone an identical SExtInst
2819 virtual SExtInst *clone_impl() const;
2822 /// @brief Constructor with insert-before-instruction semantics
2824 Value *S, ///< The value to be sign extended
2825 const Type *Ty, ///< The type to sign extend to
2826 const Twine &NameStr = "", ///< A name for the new instruction
2827 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2830 /// @brief Constructor with insert-at-end-of-block semantics
2832 Value *S, ///< The value to be sign extended
2833 const Type *Ty, ///< The type to sign extend to
2834 const Twine &NameStr, ///< A name for the new instruction
2835 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2838 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2839 static inline bool classof(const SExtInst *) { return true; }
2840 static inline bool classof(const Instruction *I) {
2841 return I->getOpcode() == SExt;
2843 static inline bool classof(const Value *V) {
2844 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2848 //===----------------------------------------------------------------------===//
2849 // FPTruncInst Class
2850 //===----------------------------------------------------------------------===//
2852 /// @brief This class represents a truncation of floating point types.
2853 class FPTruncInst : public CastInst {
2855 /// @brief Clone an identical FPTruncInst
2856 virtual FPTruncInst *clone_impl() const;
2859 /// @brief Constructor with insert-before-instruction semantics
2861 Value *S, ///< The value to be truncated
2862 const Type *Ty, ///< The type to truncate to
2863 const Twine &NameStr = "", ///< A name for the new instruction
2864 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2867 /// @brief Constructor with insert-before-instruction semantics
2869 Value *S, ///< The value to be truncated
2870 const Type *Ty, ///< The type to truncate to
2871 const Twine &NameStr, ///< A name for the new instruction
2872 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2875 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2876 static inline bool classof(const FPTruncInst *) { return true; }
2877 static inline bool classof(const Instruction *I) {
2878 return I->getOpcode() == FPTrunc;
2880 static inline bool classof(const Value *V) {
2881 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2885 //===----------------------------------------------------------------------===//
2887 //===----------------------------------------------------------------------===//
2889 /// @brief This class represents an extension of floating point types.
2890 class FPExtInst : public CastInst {
2892 /// @brief Clone an identical FPExtInst
2893 virtual FPExtInst *clone_impl() const;
2896 /// @brief Constructor with insert-before-instruction semantics
2898 Value *S, ///< The value to be extended
2899 const Type *Ty, ///< The type to extend to
2900 const Twine &NameStr = "", ///< A name for the new instruction
2901 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2904 /// @brief Constructor with insert-at-end-of-block semantics
2906 Value *S, ///< The value to be extended
2907 const Type *Ty, ///< The type to extend to
2908 const Twine &NameStr, ///< A name for the new instruction
2909 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2912 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2913 static inline bool classof(const FPExtInst *) { return true; }
2914 static inline bool classof(const Instruction *I) {
2915 return I->getOpcode() == FPExt;
2917 static inline bool classof(const Value *V) {
2918 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2922 //===----------------------------------------------------------------------===//
2924 //===----------------------------------------------------------------------===//
2926 /// @brief This class represents a cast unsigned integer to floating point.
2927 class UIToFPInst : public CastInst {
2929 /// @brief Clone an identical UIToFPInst
2930 virtual UIToFPInst *clone_impl() const;
2933 /// @brief Constructor with insert-before-instruction semantics
2935 Value *S, ///< The value to be converted
2936 const Type *Ty, ///< The type to convert to
2937 const Twine &NameStr = "", ///< A name for the new instruction
2938 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2941 /// @brief Constructor with insert-at-end-of-block semantics
2943 Value *S, ///< The value to be converted
2944 const Type *Ty, ///< The type to convert to
2945 const Twine &NameStr, ///< A name for the new instruction
2946 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2949 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2950 static inline bool classof(const UIToFPInst *) { return true; }
2951 static inline bool classof(const Instruction *I) {
2952 return I->getOpcode() == UIToFP;
2954 static inline bool classof(const Value *V) {
2955 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2959 //===----------------------------------------------------------------------===//
2961 //===----------------------------------------------------------------------===//
2963 /// @brief This class represents a cast from signed integer to floating point.
2964 class SIToFPInst : public CastInst {
2966 /// @brief Clone an identical SIToFPInst
2967 virtual SIToFPInst *clone_impl() const;
2970 /// @brief Constructor with insert-before-instruction semantics
2972 Value *S, ///< The value to be converted
2973 const Type *Ty, ///< The type to convert to
2974 const Twine &NameStr = "", ///< A name for the new instruction
2975 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2978 /// @brief Constructor with insert-at-end-of-block semantics
2980 Value *S, ///< The value to be converted
2981 const Type *Ty, ///< The type to convert to
2982 const Twine &NameStr, ///< A name for the new instruction
2983 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2986 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2987 static inline bool classof(const SIToFPInst *) { return true; }
2988 static inline bool classof(const Instruction *I) {
2989 return I->getOpcode() == SIToFP;
2991 static inline bool classof(const Value *V) {
2992 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2996 //===----------------------------------------------------------------------===//
2998 //===----------------------------------------------------------------------===//
3000 /// @brief This class represents a cast from floating point to unsigned integer
3001 class FPToUIInst : public CastInst {
3003 /// @brief Clone an identical FPToUIInst
3004 virtual FPToUIInst *clone_impl() const;
3007 /// @brief Constructor with insert-before-instruction semantics
3009 Value *S, ///< The value to be converted
3010 const Type *Ty, ///< The type to convert to
3011 const Twine &NameStr = "", ///< A name for the new instruction
3012 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3015 /// @brief Constructor with insert-at-end-of-block semantics
3017 Value *S, ///< The value to be converted
3018 const Type *Ty, ///< The type to convert to
3019 const Twine &NameStr, ///< A name for the new instruction
3020 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3023 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3024 static inline bool classof(const FPToUIInst *) { return true; }
3025 static inline bool classof(const Instruction *I) {
3026 return I->getOpcode() == FPToUI;
3028 static inline bool classof(const Value *V) {
3029 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3033 //===----------------------------------------------------------------------===//
3035 //===----------------------------------------------------------------------===//
3037 /// @brief This class represents a cast from floating point to signed integer.
3038 class FPToSIInst : public CastInst {
3040 /// @brief Clone an identical FPToSIInst
3041 virtual FPToSIInst *clone_impl() const;
3044 /// @brief Constructor with insert-before-instruction semantics
3046 Value *S, ///< The value to be converted
3047 const Type *Ty, ///< The type to convert to
3048 const Twine &NameStr = "", ///< A name for the new instruction
3049 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3052 /// @brief Constructor with insert-at-end-of-block semantics
3054 Value *S, ///< The value to be converted
3055 const Type *Ty, ///< The type to convert to
3056 const Twine &NameStr, ///< A name for the new instruction
3057 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3060 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3061 static inline bool classof(const FPToSIInst *) { return true; }
3062 static inline bool classof(const Instruction *I) {
3063 return I->getOpcode() == FPToSI;
3065 static inline bool classof(const Value *V) {
3066 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3070 //===----------------------------------------------------------------------===//
3071 // IntToPtrInst Class
3072 //===----------------------------------------------------------------------===//
3074 /// @brief This class represents a cast from an integer to a pointer.
3075 class IntToPtrInst : public CastInst {
3077 /// @brief Constructor with insert-before-instruction semantics
3079 Value *S, ///< The value to be converted
3080 const Type *Ty, ///< The type to convert to
3081 const Twine &NameStr = "", ///< A name for the new instruction
3082 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3085 /// @brief Constructor with insert-at-end-of-block semantics
3087 Value *S, ///< The value to be converted
3088 const Type *Ty, ///< The type to convert to
3089 const Twine &NameStr, ///< A name for the new instruction
3090 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3093 /// @brief Clone an identical IntToPtrInst
3094 virtual IntToPtrInst *clone_impl() const;
3096 // Methods for support type inquiry through isa, cast, and dyn_cast:
3097 static inline bool classof(const IntToPtrInst *) { return true; }
3098 static inline bool classof(const Instruction *I) {
3099 return I->getOpcode() == IntToPtr;
3101 static inline bool classof(const Value *V) {
3102 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3106 //===----------------------------------------------------------------------===//
3107 // PtrToIntInst Class
3108 //===----------------------------------------------------------------------===//
3110 /// @brief This class represents a cast from a pointer to an integer
3111 class PtrToIntInst : public CastInst {
3113 /// @brief Clone an identical PtrToIntInst
3114 virtual PtrToIntInst *clone_impl() const;
3117 /// @brief Constructor with insert-before-instruction semantics
3119 Value *S, ///< The value to be converted
3120 const Type *Ty, ///< The type to convert to
3121 const Twine &NameStr = "", ///< A name for the new instruction
3122 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3125 /// @brief Constructor with insert-at-end-of-block semantics
3127 Value *S, ///< The value to be converted
3128 const Type *Ty, ///< The type to convert to
3129 const Twine &NameStr, ///< A name for the new instruction
3130 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3133 // Methods for support type inquiry through isa, cast, and dyn_cast:
3134 static inline bool classof(const PtrToIntInst *) { return true; }
3135 static inline bool classof(const Instruction *I) {
3136 return I->getOpcode() == PtrToInt;
3138 static inline bool classof(const Value *V) {
3139 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3143 //===----------------------------------------------------------------------===//
3144 // BitCastInst Class
3145 //===----------------------------------------------------------------------===//
3147 /// @brief This class represents a no-op cast from one type to another.
3148 class BitCastInst : public CastInst {
3150 /// @brief Clone an identical BitCastInst
3151 virtual BitCastInst *clone_impl() const;
3154 /// @brief Constructor with insert-before-instruction semantics
3156 Value *S, ///< The value to be casted
3157 const Type *Ty, ///< The type to casted to
3158 const Twine &NameStr = "", ///< A name for the new instruction
3159 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3162 /// @brief Constructor with insert-at-end-of-block semantics
3164 Value *S, ///< The value to be casted
3165 const Type *Ty, ///< The type to casted to
3166 const Twine &NameStr, ///< A name for the new instruction
3167 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3170 // Methods for support type inquiry through isa, cast, and dyn_cast:
3171 static inline bool classof(const BitCastInst *) { return true; }
3172 static inline bool classof(const Instruction *I) {
3173 return I->getOpcode() == BitCast;
3175 static inline bool classof(const Value *V) {
3176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3180 } // End llvm namespace