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/ArrayRef.h"
24 #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 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<StoreInst, 2> {
269 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
271 //===----------------------------------------------------------------------===//
272 // GetElementPtrInst Class
273 //===----------------------------------------------------------------------===//
275 // checkGEPType - Simple wrapper function to give a better assertion failure
276 // message on bad indexes for a gep instruction.
278 static inline const Type *checkGEPType(const Type *Ty) {
279 assert(Ty && "Invalid GetElementPtrInst indices for type!");
283 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
284 /// access elements of arrays and structs
286 class GetElementPtrInst : public Instruction {
287 GetElementPtrInst(const GetElementPtrInst &GEPI);
288 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
289 const Twine &NameStr);
290 void init(Value *Ptr, Value *Idx, const Twine &NameStr);
292 template<typename RandomAccessIterator>
293 void init(Value *Ptr,
294 RandomAccessIterator IdxBegin,
295 RandomAccessIterator IdxEnd,
296 const Twine &NameStr,
297 // This argument ensures that we have an iterator we can
298 // do arithmetic on in constant time
299 std::random_access_iterator_tag) {
300 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
303 // This requires that the iterator points to contiguous memory.
304 init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
305 // we have to build an array here
308 init(Ptr, 0, NumIdx, NameStr);
312 /// getIndexedType - Returns the type of the element that would be loaded with
313 /// a load instruction with the specified parameters.
315 /// Null is returned if the indices are invalid for the specified
318 template<typename RandomAccessIterator>
319 static Type *getIndexedType(const Type *Ptr,
320 RandomAccessIterator IdxBegin,
321 RandomAccessIterator IdxEnd,
322 // This argument ensures that we
323 // have an iterator we can do
324 // arithmetic on in constant time
325 std::random_access_iterator_tag) {
326 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
329 // This requires that the iterator points to contiguous memory.
330 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
332 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
335 /// Constructors - Create a getelementptr instruction with a base pointer an
336 /// list of indices. The first ctor can optionally insert before an existing
337 /// instruction, the second appends the new instruction to the specified
339 template<typename RandomAccessIterator>
340 inline GetElementPtrInst(Value *Ptr, RandomAccessIterator IdxBegin,
341 RandomAccessIterator IdxEnd,
343 const Twine &NameStr,
344 Instruction *InsertBefore);
345 template<typename RandomAccessIterator>
346 inline GetElementPtrInst(Value *Ptr,
347 RandomAccessIterator IdxBegin,
348 RandomAccessIterator IdxEnd,
350 const Twine &NameStr, BasicBlock *InsertAtEnd);
352 /// Constructors - These two constructors are convenience methods because one
353 /// and two index getelementptr instructions are so common.
354 GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
355 Instruction *InsertBefore = 0);
356 GetElementPtrInst(Value *Ptr, Value *Idx,
357 const Twine &NameStr, BasicBlock *InsertAtEnd);
359 virtual GetElementPtrInst *clone_impl() const;
361 template<typename RandomAccessIterator>
362 static GetElementPtrInst *Create(Value *Ptr, RandomAccessIterator IdxBegin,
363 RandomAccessIterator IdxEnd,
364 const Twine &NameStr = "",
365 Instruction *InsertBefore = 0) {
366 typename std::iterator_traits<RandomAccessIterator>::difference_type
367 Values = 1 + std::distance(IdxBegin, IdxEnd);
369 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
371 template<typename RandomAccessIterator>
372 static GetElementPtrInst *Create(Value *Ptr,
373 RandomAccessIterator IdxBegin,
374 RandomAccessIterator IdxEnd,
375 const Twine &NameStr,
376 BasicBlock *InsertAtEnd) {
377 typename std::iterator_traits<RandomAccessIterator>::difference_type
378 Values = 1 + std::distance(IdxBegin, IdxEnd);
380 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
383 /// Constructors - These two creators are convenience methods because one
384 /// index getelementptr instructions are so common.
385 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
386 const Twine &NameStr = "",
387 Instruction *InsertBefore = 0) {
388 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
390 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
391 const Twine &NameStr,
392 BasicBlock *InsertAtEnd) {
393 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
396 /// Create an "inbounds" getelementptr. See the documentation for the
397 /// "inbounds" flag in LangRef.html for details.
398 template<typename RandomAccessIterator>
399 static GetElementPtrInst *CreateInBounds(Value *Ptr,
400 RandomAccessIterator IdxBegin,
401 RandomAccessIterator IdxEnd,
402 const Twine &NameStr = "",
403 Instruction *InsertBefore = 0) {
404 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
405 NameStr, InsertBefore);
406 GEP->setIsInBounds(true);
409 template<typename RandomAccessIterator>
410 static GetElementPtrInst *CreateInBounds(Value *Ptr,
411 RandomAccessIterator IdxBegin,
412 RandomAccessIterator IdxEnd,
413 const Twine &NameStr,
414 BasicBlock *InsertAtEnd) {
415 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
416 NameStr, InsertAtEnd);
417 GEP->setIsInBounds(true);
420 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
421 const Twine &NameStr = "",
422 Instruction *InsertBefore = 0) {
423 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
424 GEP->setIsInBounds(true);
427 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
428 const Twine &NameStr,
429 BasicBlock *InsertAtEnd) {
430 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
431 GEP->setIsInBounds(true);
435 /// Transparently provide more efficient getOperand methods.
436 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
438 // getType - Overload to return most specific pointer type...
439 const PointerType *getType() const {
440 return reinterpret_cast<const PointerType*>(Instruction::getType());
443 /// getIndexedType - Returns the type of the element that would be loaded with
444 /// a load instruction with the specified parameters.
446 /// Null is returned if the indices are invalid for the specified
449 template<typename RandomAccessIterator>
450 static Type *getIndexedType(const Type *Ptr, RandomAccessIterator IdxBegin,
451 RandomAccessIterator IdxEnd) {
452 return getIndexedType(Ptr, IdxBegin, IdxEnd,
453 typename std::iterator_traits<RandomAccessIterator>::
454 iterator_category());
457 // FIXME: Use ArrayRef
458 static Type *getIndexedType(const Type *Ptr,
459 Value* const *Idx, unsigned NumIdx);
460 static Type *getIndexedType(const Type *Ptr,
461 Constant* const *Idx, unsigned NumIdx);
463 static Type *getIndexedType(const Type *Ptr,
464 uint64_t const *Idx, unsigned NumIdx);
465 static Type *getIndexedType(const Type *Ptr, Value *Idx);
467 inline op_iterator idx_begin() { return op_begin()+1; }
468 inline const_op_iterator idx_begin() const { return op_begin()+1; }
469 inline op_iterator idx_end() { return op_end(); }
470 inline const_op_iterator idx_end() const { return op_end(); }
472 Value *getPointerOperand() {
473 return getOperand(0);
475 const Value *getPointerOperand() const {
476 return getOperand(0);
478 static unsigned getPointerOperandIndex() {
479 return 0U; // get index for modifying correct operand
482 unsigned getPointerAddressSpace() const {
483 return cast<PointerType>(getType())->getAddressSpace();
486 /// getPointerOperandType - Method to return the pointer operand as a
488 const PointerType *getPointerOperandType() const {
489 return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
493 unsigned getNumIndices() const { // Note: always non-negative
494 return getNumOperands() - 1;
497 bool hasIndices() const {
498 return getNumOperands() > 1;
501 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
502 /// zeros. If so, the result pointer and the first operand have the same
503 /// value, just potentially different types.
504 bool hasAllZeroIndices() const;
506 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
507 /// constant integers. If so, the result pointer and the first operand have
508 /// a constant offset between them.
509 bool hasAllConstantIndices() const;
511 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
512 /// See LangRef.html for the meaning of inbounds on a getelementptr.
513 void setIsInBounds(bool b = true);
515 /// isInBounds - Determine whether the GEP has the inbounds flag.
516 bool isInBounds() const;
518 // Methods for support type inquiry through isa, cast, and dyn_cast:
519 static inline bool classof(const GetElementPtrInst *) { return true; }
520 static inline bool classof(const Instruction *I) {
521 return (I->getOpcode() == Instruction::GetElementPtr);
523 static inline bool classof(const Value *V) {
524 return isa<Instruction>(V) && classof(cast<Instruction>(V));
529 struct OperandTraits<GetElementPtrInst> :
530 public VariadicOperandTraits<GetElementPtrInst, 1> {
533 template<typename RandomAccessIterator>
534 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
535 RandomAccessIterator IdxBegin,
536 RandomAccessIterator IdxEnd,
538 const Twine &NameStr,
539 Instruction *InsertBefore)
540 : Instruction(PointerType::get(checkGEPType(
541 getIndexedType(Ptr->getType(),
543 cast<PointerType>(Ptr->getType())
544 ->getAddressSpace()),
546 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
547 Values, InsertBefore) {
548 init(Ptr, IdxBegin, IdxEnd, NameStr,
549 typename std::iterator_traits<RandomAccessIterator>
550 ::iterator_category());
552 template<typename RandomAccessIterator>
553 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
554 RandomAccessIterator IdxBegin,
555 RandomAccessIterator IdxEnd,
557 const Twine &NameStr,
558 BasicBlock *InsertAtEnd)
559 : Instruction(PointerType::get(checkGEPType(
560 getIndexedType(Ptr->getType(),
562 cast<PointerType>(Ptr->getType())
563 ->getAddressSpace()),
565 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
566 Values, InsertAtEnd) {
567 init(Ptr, IdxBegin, IdxEnd, NameStr,
568 typename std::iterator_traits<RandomAccessIterator>
569 ::iterator_category());
573 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
576 //===----------------------------------------------------------------------===//
578 //===----------------------------------------------------------------------===//
580 /// This instruction compares its operands according to the predicate given
581 /// to the constructor. It only operates on integers or pointers. The operands
582 /// must be identical types.
583 /// @brief Represent an integer comparison operator.
584 class ICmpInst: public CmpInst {
586 /// @brief Clone an identical ICmpInst
587 virtual ICmpInst *clone_impl() const;
589 /// @brief Constructor with insert-before-instruction semantics.
591 Instruction *InsertBefore, ///< Where to insert
592 Predicate pred, ///< The predicate to use for the comparison
593 Value *LHS, ///< The left-hand-side of the expression
594 Value *RHS, ///< The right-hand-side of the expression
595 const Twine &NameStr = "" ///< Name of the instruction
596 ) : CmpInst(makeCmpResultType(LHS->getType()),
597 Instruction::ICmp, pred, LHS, RHS, NameStr,
599 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
600 pred <= CmpInst::LAST_ICMP_PREDICATE &&
601 "Invalid ICmp predicate value");
602 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
603 "Both operands to ICmp instruction are not of the same type!");
604 // Check that the operands are the right type
605 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
606 getOperand(0)->getType()->isPointerTy()) &&
607 "Invalid operand types for ICmp instruction");
610 /// @brief Constructor with insert-at-end semantics.
612 BasicBlock &InsertAtEnd, ///< Block to insert into.
613 Predicate pred, ///< The predicate to use for the comparison
614 Value *LHS, ///< The left-hand-side of the expression
615 Value *RHS, ///< The right-hand-side of the expression
616 const Twine &NameStr = "" ///< Name of the instruction
617 ) : CmpInst(makeCmpResultType(LHS->getType()),
618 Instruction::ICmp, pred, LHS, RHS, NameStr,
620 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
621 pred <= CmpInst::LAST_ICMP_PREDICATE &&
622 "Invalid ICmp predicate value");
623 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
624 "Both operands to ICmp instruction are not of the same type!");
625 // Check that the operands are the right type
626 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
627 getOperand(0)->getType()->isPointerTy()) &&
628 "Invalid operand types for ICmp instruction");
631 /// @brief Constructor with no-insertion semantics
633 Predicate pred, ///< The predicate to use for the comparison
634 Value *LHS, ///< The left-hand-side of the expression
635 Value *RHS, ///< The right-hand-side of the expression
636 const Twine &NameStr = "" ///< Name of the instruction
637 ) : CmpInst(makeCmpResultType(LHS->getType()),
638 Instruction::ICmp, pred, LHS, RHS, NameStr) {
639 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
640 pred <= CmpInst::LAST_ICMP_PREDICATE &&
641 "Invalid ICmp predicate value");
642 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
643 "Both operands to ICmp instruction are not of the same type!");
644 // Check that the operands are the right type
645 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
646 getOperand(0)->getType()->isPointerTy()) &&
647 "Invalid operand types for ICmp instruction");
650 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
651 /// @returns the predicate that would be the result if the operand were
652 /// regarded as signed.
653 /// @brief Return the signed version of the predicate
654 Predicate getSignedPredicate() const {
655 return getSignedPredicate(getPredicate());
658 /// This is a static version that you can use without an instruction.
659 /// @brief Return the signed version of the predicate.
660 static Predicate getSignedPredicate(Predicate pred);
662 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
663 /// @returns the predicate that would be the result if the operand were
664 /// regarded as unsigned.
665 /// @brief Return the unsigned version of the predicate
666 Predicate getUnsignedPredicate() const {
667 return getUnsignedPredicate(getPredicate());
670 /// This is a static version that you can use without an instruction.
671 /// @brief Return the unsigned version of the predicate.
672 static Predicate getUnsignedPredicate(Predicate pred);
674 /// isEquality - Return true if this predicate is either EQ or NE. This also
675 /// tests for commutativity.
676 static bool isEquality(Predicate P) {
677 return P == ICMP_EQ || P == ICMP_NE;
680 /// isEquality - Return true if this predicate is either EQ or NE. This also
681 /// tests for commutativity.
682 bool isEquality() const {
683 return isEquality(getPredicate());
686 /// @returns true if the predicate of this ICmpInst is commutative
687 /// @brief Determine if this relation is commutative.
688 bool isCommutative() const { return isEquality(); }
690 /// isRelational - Return true if the predicate is relational (not EQ or NE).
692 bool isRelational() const {
693 return !isEquality();
696 /// isRelational - Return true if the predicate is relational (not EQ or NE).
698 static bool isRelational(Predicate P) {
699 return !isEquality(P);
702 /// Initialize a set of values that all satisfy the predicate with C.
703 /// @brief Make a ConstantRange for a relation with a constant value.
704 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
706 /// Exchange the two operands to this instruction in such a way that it does
707 /// not modify the semantics of the instruction. The predicate value may be
708 /// changed to retain the same result if the predicate is order dependent
710 /// @brief Swap operands and adjust predicate.
711 void swapOperands() {
712 setPredicate(getSwappedPredicate());
713 Op<0>().swap(Op<1>());
716 // Methods for support type inquiry through isa, cast, and dyn_cast:
717 static inline bool classof(const ICmpInst *) { return true; }
718 static inline bool classof(const Instruction *I) {
719 return I->getOpcode() == Instruction::ICmp;
721 static inline bool classof(const Value *V) {
722 return isa<Instruction>(V) && classof(cast<Instruction>(V));
727 //===----------------------------------------------------------------------===//
729 //===----------------------------------------------------------------------===//
731 /// This instruction compares its operands according to the predicate given
732 /// to the constructor. It only operates on floating point values or packed
733 /// vectors of floating point values. The operands must be identical types.
734 /// @brief Represents a floating point comparison operator.
735 class FCmpInst: public CmpInst {
737 /// @brief Clone an identical FCmpInst
738 virtual FCmpInst *clone_impl() const;
740 /// @brief Constructor with insert-before-instruction semantics.
742 Instruction *InsertBefore, ///< Where to insert
743 Predicate pred, ///< The predicate to use for the comparison
744 Value *LHS, ///< The left-hand-side of the expression
745 Value *RHS, ///< The right-hand-side of the expression
746 const Twine &NameStr = "" ///< Name of the instruction
747 ) : CmpInst(makeCmpResultType(LHS->getType()),
748 Instruction::FCmp, pred, LHS, RHS, NameStr,
750 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
751 "Invalid FCmp predicate value");
752 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
753 "Both operands to FCmp instruction are not of the same type!");
754 // Check that the operands are the right type
755 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
756 "Invalid operand types for FCmp instruction");
759 /// @brief Constructor with insert-at-end semantics.
761 BasicBlock &InsertAtEnd, ///< Block to insert into.
762 Predicate pred, ///< The predicate to use for the comparison
763 Value *LHS, ///< The left-hand-side of the expression
764 Value *RHS, ///< The right-hand-side of the expression
765 const Twine &NameStr = "" ///< Name of the instruction
766 ) : CmpInst(makeCmpResultType(LHS->getType()),
767 Instruction::FCmp, pred, LHS, RHS, NameStr,
769 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
770 "Invalid FCmp predicate value");
771 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
772 "Both operands to FCmp instruction are not of the same type!");
773 // Check that the operands are the right type
774 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
775 "Invalid operand types for FCmp instruction");
778 /// @brief Constructor with no-insertion semantics
780 Predicate pred, ///< The predicate to use for the comparison
781 Value *LHS, ///< The left-hand-side of the expression
782 Value *RHS, ///< The right-hand-side of the expression
783 const Twine &NameStr = "" ///< Name of the instruction
784 ) : CmpInst(makeCmpResultType(LHS->getType()),
785 Instruction::FCmp, pred, LHS, RHS, NameStr) {
786 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
787 "Invalid FCmp predicate value");
788 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
789 "Both operands to FCmp instruction are not of the same type!");
790 // Check that the operands are the right type
791 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
792 "Invalid operand types for FCmp instruction");
795 /// @returns true if the predicate of this instruction is EQ or NE.
796 /// @brief Determine if this is an equality predicate.
797 bool isEquality() const {
798 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
799 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
802 /// @returns true if the predicate of this instruction is commutative.
803 /// @brief Determine if this is a commutative predicate.
804 bool isCommutative() const {
805 return isEquality() ||
806 getPredicate() == FCMP_FALSE ||
807 getPredicate() == FCMP_TRUE ||
808 getPredicate() == FCMP_ORD ||
809 getPredicate() == FCMP_UNO;
812 /// @returns true if the predicate is relational (not EQ or NE).
813 /// @brief Determine if this a relational predicate.
814 bool isRelational() const { return !isEquality(); }
816 /// Exchange the two operands to this instruction in such a way that it does
817 /// not modify the semantics of the instruction. The predicate value may be
818 /// changed to retain the same result if the predicate is order dependent
820 /// @brief Swap operands and adjust predicate.
821 void swapOperands() {
822 setPredicate(getSwappedPredicate());
823 Op<0>().swap(Op<1>());
826 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
827 static inline bool classof(const FCmpInst *) { return true; }
828 static inline bool classof(const Instruction *I) {
829 return I->getOpcode() == Instruction::FCmp;
831 static inline bool classof(const Value *V) {
832 return isa<Instruction>(V) && classof(cast<Instruction>(V));
836 //===----------------------------------------------------------------------===//
837 /// CallInst - This class represents a function call, abstracting a target
838 /// machine's calling convention. This class uses low bit of the SubClassData
839 /// field to indicate whether or not this is a tail call. The rest of the bits
840 /// hold the calling convention of the call.
842 class CallInst : public Instruction {
843 AttrListPtr AttributeList; ///< parameter attributes for call
844 CallInst(const CallInst &CI);
845 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
846 void init(Value *Func, const Twine &NameStr);
848 /// Construct a CallInst given a range of arguments.
849 /// @brief Construct a CallInst from a range of arguments
850 inline CallInst(Value *Func, ArrayRef<Value *> Args,
851 const Twine &NameStr, Instruction *InsertBefore);
853 /// Construct a CallInst given a range of arguments.
854 /// @brief Construct a CallInst from a range of arguments
855 inline CallInst(Value *Func, ArrayRef<Value *> Args,
856 const Twine &NameStr, BasicBlock *InsertAtEnd);
858 CallInst(Value *F, Value *Actual, const Twine &NameStr,
859 Instruction *InsertBefore);
860 CallInst(Value *F, Value *Actual, const Twine &NameStr,
861 BasicBlock *InsertAtEnd);
862 explicit CallInst(Value *F, const Twine &NameStr,
863 Instruction *InsertBefore);
864 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
866 virtual CallInst *clone_impl() const;
868 static CallInst *Create(Value *Func,
869 ArrayRef<Value *> Args,
870 const Twine &NameStr = "",
871 Instruction *InsertBefore = 0) {
872 return new(unsigned(Args.size() + 1))
873 CallInst(Func, Args, NameStr, InsertBefore);
875 static CallInst *Create(Value *Func,
876 ArrayRef<Value *> Args,
877 const Twine &NameStr, BasicBlock *InsertAtEnd) {
878 return new(unsigned(Args.size() + 1))
879 CallInst(Func, Args, NameStr, InsertAtEnd);
881 static CallInst *Create(Value *F, const Twine &NameStr = "",
882 Instruction *InsertBefore = 0) {
883 return new(1) CallInst(F, NameStr, InsertBefore);
885 static CallInst *Create(Value *F, const Twine &NameStr,
886 BasicBlock *InsertAtEnd) {
887 return new(1) CallInst(F, NameStr, InsertAtEnd);
889 /// CreateMalloc - Generate the IR for a call to malloc:
890 /// 1. Compute the malloc call's argument as the specified type's size,
891 /// possibly multiplied by the array size if the array size is not
893 /// 2. Call malloc with that argument.
894 /// 3. Bitcast the result of the malloc call to the specified type.
895 static Instruction *CreateMalloc(Instruction *InsertBefore,
896 const Type *IntPtrTy, const Type *AllocTy,
897 Value *AllocSize, Value *ArraySize = 0,
898 Function* MallocF = 0,
899 const Twine &Name = "");
900 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
901 const Type *IntPtrTy, const Type *AllocTy,
902 Value *AllocSize, Value *ArraySize = 0,
903 Function* MallocF = 0,
904 const Twine &Name = "");
905 /// CreateFree - Generate the IR for a call to the builtin free function.
906 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
907 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
911 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
912 void setTailCall(bool isTC = true) {
913 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
917 /// Provide fast operand accessors
918 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
920 /// getNumArgOperands - Return the number of call arguments.
922 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
924 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
926 Value *getArgOperand(unsigned i) const { return getOperand(i); }
927 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
929 /// getCallingConv/setCallingConv - Get or set the calling convention of this
931 CallingConv::ID getCallingConv() const {
932 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
934 void setCallingConv(CallingConv::ID CC) {
935 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
936 (static_cast<unsigned>(CC) << 1));
939 /// getAttributes - Return the parameter attributes for this call.
941 const AttrListPtr &getAttributes() const { return AttributeList; }
943 /// setAttributes - Set the parameter attributes for this call.
945 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
947 /// addAttribute - adds the attribute to the list of attributes.
948 void addAttribute(unsigned i, Attributes attr);
950 /// removeAttribute - removes the attribute from the list of attributes.
951 void removeAttribute(unsigned i, Attributes attr);
953 /// @brief Determine whether the call or the callee has the given attribute.
954 bool paramHasAttr(unsigned i, Attributes attr) const;
956 /// @brief Extract the alignment for a call or parameter (0=unknown).
957 unsigned getParamAlignment(unsigned i) const {
958 return AttributeList.getParamAlignment(i);
961 /// @brief Return true if the call should not be inlined.
962 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
963 void setIsNoInline(bool Value = true) {
964 if (Value) addAttribute(~0, Attribute::NoInline);
965 else removeAttribute(~0, Attribute::NoInline);
968 /// @brief Determine if the call does not access memory.
969 bool doesNotAccessMemory() const {
970 return paramHasAttr(~0, Attribute::ReadNone);
972 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
973 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
974 else removeAttribute(~0, Attribute::ReadNone);
977 /// @brief Determine if the call does not access or only reads memory.
978 bool onlyReadsMemory() const {
979 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
981 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
982 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
983 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
986 /// @brief Determine if the call cannot return.
987 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
988 void setDoesNotReturn(bool DoesNotReturn = true) {
989 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
990 else removeAttribute(~0, Attribute::NoReturn);
993 /// @brief Determine if the call cannot unwind.
994 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
995 void setDoesNotThrow(bool DoesNotThrow = true) {
996 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
997 else removeAttribute(~0, Attribute::NoUnwind);
1000 /// @brief Determine if the call returns a structure through first
1001 /// pointer argument.
1002 bool hasStructRetAttr() const {
1003 // Be friendly and also check the callee.
1004 return paramHasAttr(1, Attribute::StructRet);
1007 /// @brief Determine if any call argument is an aggregate passed by value.
1008 bool hasByValArgument() const {
1009 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1012 /// getCalledFunction - Return the function called, or null if this is an
1013 /// indirect function invocation.
1015 Function *getCalledFunction() const {
1016 return dyn_cast<Function>(Op<-1>());
1019 /// getCalledValue - Get a pointer to the function that is invoked by this
1021 const Value *getCalledValue() const { return Op<-1>(); }
1022 Value *getCalledValue() { return Op<-1>(); }
1024 /// setCalledFunction - Set the function called.
1025 void setCalledFunction(Value* Fn) {
1029 /// isInlineAsm - Check if this call is an inline asm statement.
1030 bool isInlineAsm() const {
1031 return isa<InlineAsm>(Op<-1>());
1034 // Methods for support type inquiry through isa, cast, and dyn_cast:
1035 static inline bool classof(const CallInst *) { return true; }
1036 static inline bool classof(const Instruction *I) {
1037 return I->getOpcode() == Instruction::Call;
1039 static inline bool classof(const Value *V) {
1040 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1043 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1044 // method so that subclasses cannot accidentally use it.
1045 void setInstructionSubclassData(unsigned short D) {
1046 Instruction::setInstructionSubclassData(D);
1051 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1054 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1055 const Twine &NameStr, BasicBlock *InsertAtEnd)
1056 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1057 ->getElementType())->getReturnType(),
1059 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1060 unsigned(Args.size() + 1), InsertAtEnd) {
1061 init(Func, Args, NameStr);
1064 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1065 const Twine &NameStr, Instruction *InsertBefore)
1066 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1067 ->getElementType())->getReturnType(),
1069 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1070 unsigned(Args.size() + 1), InsertBefore) {
1071 init(Func, Args, NameStr);
1075 // Note: if you get compile errors about private methods then
1076 // please update your code to use the high-level operand
1077 // interfaces. See line 943 above.
1078 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1080 //===----------------------------------------------------------------------===//
1082 //===----------------------------------------------------------------------===//
1084 /// SelectInst - This class represents the LLVM 'select' instruction.
1086 class SelectInst : public Instruction {
1087 void init(Value *C, Value *S1, Value *S2) {
1088 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1094 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1095 Instruction *InsertBefore)
1096 : Instruction(S1->getType(), Instruction::Select,
1097 &Op<0>(), 3, InsertBefore) {
1101 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1102 BasicBlock *InsertAtEnd)
1103 : Instruction(S1->getType(), Instruction::Select,
1104 &Op<0>(), 3, InsertAtEnd) {
1109 virtual SelectInst *clone_impl() const;
1111 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1112 const Twine &NameStr = "",
1113 Instruction *InsertBefore = 0) {
1114 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1116 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1117 const Twine &NameStr,
1118 BasicBlock *InsertAtEnd) {
1119 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1122 const Value *getCondition() const { return Op<0>(); }
1123 const Value *getTrueValue() const { return Op<1>(); }
1124 const Value *getFalseValue() const { return Op<2>(); }
1125 Value *getCondition() { return Op<0>(); }
1126 Value *getTrueValue() { return Op<1>(); }
1127 Value *getFalseValue() { return Op<2>(); }
1129 /// areInvalidOperands - Return a string if the specified operands are invalid
1130 /// for a select operation, otherwise return null.
1131 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1133 /// Transparently provide more efficient getOperand methods.
1134 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1136 OtherOps getOpcode() const {
1137 return static_cast<OtherOps>(Instruction::getOpcode());
1140 // Methods for support type inquiry through isa, cast, and dyn_cast:
1141 static inline bool classof(const SelectInst *) { return true; }
1142 static inline bool classof(const Instruction *I) {
1143 return I->getOpcode() == Instruction::Select;
1145 static inline bool classof(const Value *V) {
1146 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1151 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1154 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1156 //===----------------------------------------------------------------------===//
1158 //===----------------------------------------------------------------------===//
1160 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1161 /// an argument of the specified type given a va_list and increments that list
1163 class VAArgInst : public UnaryInstruction {
1165 virtual VAArgInst *clone_impl() const;
1168 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1169 Instruction *InsertBefore = 0)
1170 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1173 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1174 BasicBlock *InsertAtEnd)
1175 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1179 Value *getPointerOperand() { return getOperand(0); }
1180 const Value *getPointerOperand() const { return getOperand(0); }
1181 static unsigned getPointerOperandIndex() { return 0U; }
1183 // Methods for support type inquiry through isa, cast, and dyn_cast:
1184 static inline bool classof(const VAArgInst *) { return true; }
1185 static inline bool classof(const Instruction *I) {
1186 return I->getOpcode() == VAArg;
1188 static inline bool classof(const Value *V) {
1189 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1193 //===----------------------------------------------------------------------===//
1194 // ExtractElementInst Class
1195 //===----------------------------------------------------------------------===//
1197 /// ExtractElementInst - This instruction extracts a single (scalar)
1198 /// element from a VectorType value
1200 class ExtractElementInst : public Instruction {
1201 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1202 Instruction *InsertBefore = 0);
1203 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1204 BasicBlock *InsertAtEnd);
1206 virtual ExtractElementInst *clone_impl() const;
1209 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1210 const Twine &NameStr = "",
1211 Instruction *InsertBefore = 0) {
1212 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1214 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1215 const Twine &NameStr,
1216 BasicBlock *InsertAtEnd) {
1217 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1220 /// isValidOperands - Return true if an extractelement instruction can be
1221 /// formed with the specified operands.
1222 static bool isValidOperands(const Value *Vec, const Value *Idx);
1224 Value *getVectorOperand() { return Op<0>(); }
1225 Value *getIndexOperand() { return Op<1>(); }
1226 const Value *getVectorOperand() const { return Op<0>(); }
1227 const Value *getIndexOperand() const { return Op<1>(); }
1229 const VectorType *getVectorOperandType() const {
1230 return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
1234 /// Transparently provide more efficient getOperand methods.
1235 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1237 // Methods for support type inquiry through isa, cast, and dyn_cast:
1238 static inline bool classof(const ExtractElementInst *) { return true; }
1239 static inline bool classof(const Instruction *I) {
1240 return I->getOpcode() == Instruction::ExtractElement;
1242 static inline bool classof(const Value *V) {
1243 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1248 struct OperandTraits<ExtractElementInst> :
1249 public FixedNumOperandTraits<ExtractElementInst, 2> {
1252 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1254 //===----------------------------------------------------------------------===//
1255 // InsertElementInst Class
1256 //===----------------------------------------------------------------------===//
1258 /// InsertElementInst - This instruction inserts a single (scalar)
1259 /// element into a VectorType value
1261 class InsertElementInst : public Instruction {
1262 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1263 const Twine &NameStr = "",
1264 Instruction *InsertBefore = 0);
1265 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1266 const Twine &NameStr, BasicBlock *InsertAtEnd);
1268 virtual InsertElementInst *clone_impl() const;
1271 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1272 const Twine &NameStr = "",
1273 Instruction *InsertBefore = 0) {
1274 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1276 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1277 const Twine &NameStr,
1278 BasicBlock *InsertAtEnd) {
1279 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1282 /// isValidOperands - Return true if an insertelement instruction can be
1283 /// formed with the specified operands.
1284 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1287 /// getType - Overload to return most specific vector type.
1289 const VectorType *getType() const {
1290 return reinterpret_cast<const VectorType*>(Instruction::getType());
1293 /// Transparently provide more efficient getOperand methods.
1294 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1296 // Methods for support type inquiry through isa, cast, and dyn_cast:
1297 static inline bool classof(const InsertElementInst *) { return true; }
1298 static inline bool classof(const Instruction *I) {
1299 return I->getOpcode() == Instruction::InsertElement;
1301 static inline bool classof(const Value *V) {
1302 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1307 struct OperandTraits<InsertElementInst> :
1308 public FixedNumOperandTraits<InsertElementInst, 3> {
1311 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1313 //===----------------------------------------------------------------------===//
1314 // ShuffleVectorInst Class
1315 //===----------------------------------------------------------------------===//
1317 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1320 class ShuffleVectorInst : public Instruction {
1322 virtual ShuffleVectorInst *clone_impl() const;
1325 // allocate space for exactly three operands
1326 void *operator new(size_t s) {
1327 return User::operator new(s, 3);
1329 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1330 const Twine &NameStr = "",
1331 Instruction *InsertBefor = 0);
1332 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1333 const Twine &NameStr, BasicBlock *InsertAtEnd);
1335 /// isValidOperands - Return true if a shufflevector instruction can be
1336 /// formed with the specified operands.
1337 static bool isValidOperands(const Value *V1, const Value *V2,
1340 /// getType - Overload to return most specific vector type.
1342 const VectorType *getType() const {
1343 return reinterpret_cast<const VectorType*>(Instruction::getType());
1346 /// Transparently provide more efficient getOperand methods.
1347 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1349 /// getMaskValue - Return the index from the shuffle mask for the specified
1350 /// output result. This is either -1 if the element is undef or a number less
1351 /// than 2*numelements.
1352 int getMaskValue(unsigned i) const;
1354 // Methods for support type inquiry through isa, cast, and dyn_cast:
1355 static inline bool classof(const ShuffleVectorInst *) { return true; }
1356 static inline bool classof(const Instruction *I) {
1357 return I->getOpcode() == Instruction::ShuffleVector;
1359 static inline bool classof(const Value *V) {
1360 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1365 struct OperandTraits<ShuffleVectorInst> :
1366 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1369 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1371 //===----------------------------------------------------------------------===//
1372 // ExtractValueInst Class
1373 //===----------------------------------------------------------------------===//
1375 /// ExtractValueInst - This instruction extracts a struct member or array
1376 /// element value from an aggregate value.
1378 class ExtractValueInst : public UnaryInstruction {
1379 SmallVector<unsigned, 4> Indices;
1381 ExtractValueInst(const ExtractValueInst &EVI);
1382 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1384 /// Constructors - Create a extractvalue instruction with a base aggregate
1385 /// value and a list of indices. The first ctor can optionally insert before
1386 /// an existing instruction, the second appends the new instruction to the
1387 /// specified BasicBlock.
1388 inline ExtractValueInst(Value *Agg,
1389 ArrayRef<unsigned> Idxs,
1390 const Twine &NameStr,
1391 Instruction *InsertBefore);
1392 inline ExtractValueInst(Value *Agg,
1393 ArrayRef<unsigned> Idxs,
1394 const Twine &NameStr, BasicBlock *InsertAtEnd);
1396 // allocate space for exactly one operand
1397 void *operator new(size_t s) {
1398 return User::operator new(s, 1);
1401 virtual ExtractValueInst *clone_impl() const;
1404 static ExtractValueInst *Create(Value *Agg,
1405 ArrayRef<unsigned> Idxs,
1406 const Twine &NameStr = "",
1407 Instruction *InsertBefore = 0) {
1409 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1411 static ExtractValueInst *Create(Value *Agg,
1412 ArrayRef<unsigned> Idxs,
1413 const Twine &NameStr,
1414 BasicBlock *InsertAtEnd) {
1415 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1418 /// getIndexedType - Returns the type of the element that would be extracted
1419 /// with an extractvalue instruction with the specified parameters.
1421 /// Null is returned if the indices are invalid for the specified type.
1422 static Type *getIndexedType(const Type *Agg, ArrayRef<unsigned> Idxs);
1424 typedef const unsigned* idx_iterator;
1425 inline idx_iterator idx_begin() const { return Indices.begin(); }
1426 inline idx_iterator idx_end() const { return Indices.end(); }
1428 Value *getAggregateOperand() {
1429 return getOperand(0);
1431 const Value *getAggregateOperand() const {
1432 return getOperand(0);
1434 static unsigned getAggregateOperandIndex() {
1435 return 0U; // get index for modifying correct operand
1438 ArrayRef<unsigned> getIndices() const {
1442 unsigned getNumIndices() const {
1443 return (unsigned)Indices.size();
1446 bool hasIndices() const {
1450 // Methods for support type inquiry through isa, cast, and dyn_cast:
1451 static inline bool classof(const ExtractValueInst *) { return true; }
1452 static inline bool classof(const Instruction *I) {
1453 return I->getOpcode() == Instruction::ExtractValue;
1455 static inline bool classof(const Value *V) {
1456 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1460 ExtractValueInst::ExtractValueInst(Value *Agg,
1461 ArrayRef<unsigned> Idxs,
1462 const Twine &NameStr,
1463 Instruction *InsertBefore)
1464 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1465 ExtractValue, Agg, InsertBefore) {
1466 init(Idxs, NameStr);
1468 ExtractValueInst::ExtractValueInst(Value *Agg,
1469 ArrayRef<unsigned> Idxs,
1470 const Twine &NameStr,
1471 BasicBlock *InsertAtEnd)
1472 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1473 ExtractValue, Agg, InsertAtEnd) {
1474 init(Idxs, NameStr);
1478 //===----------------------------------------------------------------------===//
1479 // InsertValueInst Class
1480 //===----------------------------------------------------------------------===//
1482 /// InsertValueInst - This instruction inserts a struct field of array element
1483 /// value into an aggregate value.
1485 class InsertValueInst : public Instruction {
1486 SmallVector<unsigned, 4> Indices;
1488 void *operator new(size_t, unsigned); // Do not implement
1489 InsertValueInst(const InsertValueInst &IVI);
1490 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1491 const Twine &NameStr);
1493 /// Constructors - Create a insertvalue instruction with a base aggregate
1494 /// value, a value to insert, and a list of indices. The first ctor can
1495 /// optionally insert before an existing instruction, the second appends
1496 /// the new instruction to the specified BasicBlock.
1497 inline InsertValueInst(Value *Agg, Value *Val,
1498 ArrayRef<unsigned> Idxs,
1499 const Twine &NameStr,
1500 Instruction *InsertBefore);
1501 inline InsertValueInst(Value *Agg, Value *Val,
1502 ArrayRef<unsigned> Idxs,
1503 const Twine &NameStr, BasicBlock *InsertAtEnd);
1505 /// Constructors - These two constructors are convenience methods because one
1506 /// and two index insertvalue instructions are so common.
1507 InsertValueInst(Value *Agg, Value *Val,
1508 unsigned Idx, const Twine &NameStr = "",
1509 Instruction *InsertBefore = 0);
1510 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1511 const Twine &NameStr, BasicBlock *InsertAtEnd);
1513 virtual InsertValueInst *clone_impl() const;
1515 // allocate space for exactly two operands
1516 void *operator new(size_t s) {
1517 return User::operator new(s, 2);
1520 static InsertValueInst *Create(Value *Agg, Value *Val,
1521 ArrayRef<unsigned> Idxs,
1522 const Twine &NameStr = "",
1523 Instruction *InsertBefore = 0) {
1524 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1526 static InsertValueInst *Create(Value *Agg, Value *Val,
1527 ArrayRef<unsigned> Idxs,
1528 const Twine &NameStr,
1529 BasicBlock *InsertAtEnd) {
1530 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1533 /// Transparently provide more efficient getOperand methods.
1534 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1536 typedef const unsigned* idx_iterator;
1537 inline idx_iterator idx_begin() const { return Indices.begin(); }
1538 inline idx_iterator idx_end() const { return Indices.end(); }
1540 Value *getAggregateOperand() {
1541 return getOperand(0);
1543 const Value *getAggregateOperand() const {
1544 return getOperand(0);
1546 static unsigned getAggregateOperandIndex() {
1547 return 0U; // get index for modifying correct operand
1550 Value *getInsertedValueOperand() {
1551 return getOperand(1);
1553 const Value *getInsertedValueOperand() const {
1554 return getOperand(1);
1556 static unsigned getInsertedValueOperandIndex() {
1557 return 1U; // get index for modifying correct operand
1560 ArrayRef<unsigned> getIndices() const {
1564 unsigned getNumIndices() const {
1565 return (unsigned)Indices.size();
1568 bool hasIndices() const {
1572 // Methods for support type inquiry through isa, cast, and dyn_cast:
1573 static inline bool classof(const InsertValueInst *) { return true; }
1574 static inline bool classof(const Instruction *I) {
1575 return I->getOpcode() == Instruction::InsertValue;
1577 static inline bool classof(const Value *V) {
1578 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1583 struct OperandTraits<InsertValueInst> :
1584 public FixedNumOperandTraits<InsertValueInst, 2> {
1587 InsertValueInst::InsertValueInst(Value *Agg,
1589 ArrayRef<unsigned> Idxs,
1590 const Twine &NameStr,
1591 Instruction *InsertBefore)
1592 : Instruction(Agg->getType(), InsertValue,
1593 OperandTraits<InsertValueInst>::op_begin(this),
1595 init(Agg, Val, Idxs, NameStr);
1597 InsertValueInst::InsertValueInst(Value *Agg,
1599 ArrayRef<unsigned> Idxs,
1600 const Twine &NameStr,
1601 BasicBlock *InsertAtEnd)
1602 : Instruction(Agg->getType(), InsertValue,
1603 OperandTraits<InsertValueInst>::op_begin(this),
1605 init(Agg, Val, Idxs, NameStr);
1608 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1610 //===----------------------------------------------------------------------===//
1612 //===----------------------------------------------------------------------===//
1614 // PHINode - The PHINode class is used to represent the magical mystical PHI
1615 // node, that can not exist in nature, but can be synthesized in a computer
1616 // scientist's overactive imagination.
1618 class PHINode : public Instruction {
1619 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1620 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1621 /// the number actually in use.
1622 unsigned ReservedSpace;
1623 PHINode(const PHINode &PN);
1624 // allocate space for exactly zero operands
1625 void *operator new(size_t s) {
1626 return User::operator new(s, 0);
1628 explicit PHINode(const Type *Ty, unsigned NumReservedValues,
1629 const Twine &NameStr = "", Instruction *InsertBefore = 0)
1630 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1631 ReservedSpace(NumReservedValues) {
1633 OperandList = allocHungoffUses(ReservedSpace);
1636 PHINode(const Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1637 BasicBlock *InsertAtEnd)
1638 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1639 ReservedSpace(NumReservedValues) {
1641 OperandList = allocHungoffUses(ReservedSpace);
1644 // allocHungoffUses - this is more complicated than the generic
1645 // User::allocHungoffUses, because we have to allocate Uses for the incoming
1646 // values and pointers to the incoming blocks, all in one allocation.
1647 Use *allocHungoffUses(unsigned) const;
1649 virtual PHINode *clone_impl() const;
1651 /// Constructors - NumReservedValues is a hint for the number of incoming
1652 /// edges that this phi node will have (use 0 if you really have no idea).
1653 static PHINode *Create(const Type *Ty, unsigned NumReservedValues,
1654 const Twine &NameStr = "",
1655 Instruction *InsertBefore = 0) {
1656 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1658 static PHINode *Create(const Type *Ty, unsigned NumReservedValues,
1659 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1660 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
1664 /// Provide fast operand accessors
1665 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1667 // Block iterator interface. This provides access to the list of incoming
1668 // basic blocks, which parallels the list of incoming values.
1670 typedef BasicBlock **block_iterator;
1671 typedef BasicBlock * const *const_block_iterator;
1673 block_iterator block_begin() {
1675 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
1676 return reinterpret_cast<block_iterator>(ref + 1);
1679 const_block_iterator block_begin() const {
1680 const Use::UserRef *ref =
1681 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
1682 return reinterpret_cast<const_block_iterator>(ref + 1);
1685 block_iterator block_end() {
1686 return block_begin() + getNumOperands();
1689 const_block_iterator block_end() const {
1690 return block_begin() + getNumOperands();
1693 /// getNumIncomingValues - Return the number of incoming edges
1695 unsigned getNumIncomingValues() const { return getNumOperands(); }
1697 /// getIncomingValue - Return incoming value number x
1699 Value *getIncomingValue(unsigned i) const {
1700 return getOperand(i);
1702 void setIncomingValue(unsigned i, Value *V) {
1705 static unsigned getOperandNumForIncomingValue(unsigned i) {
1708 static unsigned getIncomingValueNumForOperand(unsigned i) {
1712 /// getIncomingBlock - Return incoming basic block number @p i.
1714 BasicBlock *getIncomingBlock(unsigned i) const {
1715 return block_begin()[i];
1718 /// getIncomingBlock - Return incoming basic block corresponding
1719 /// to an operand of the PHI.
1721 BasicBlock *getIncomingBlock(const Use &U) const {
1722 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1723 return getIncomingBlock(unsigned(&U - op_begin()));
1726 /// getIncomingBlock - Return incoming basic block corresponding
1727 /// to value use iterator.
1729 template <typename U>
1730 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1731 return getIncomingBlock(I.getUse());
1734 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1735 block_begin()[i] = BB;
1738 /// addIncoming - Add an incoming value to the end of the PHI list
1740 void addIncoming(Value *V, BasicBlock *BB) {
1741 assert(V && "PHI node got a null value!");
1742 assert(BB && "PHI node got a null basic block!");
1743 assert(getType() == V->getType() &&
1744 "All operands to PHI node must be the same type as the PHI node!");
1745 if (NumOperands == ReservedSpace)
1746 growOperands(); // Get more space!
1747 // Initialize some new operands.
1749 setIncomingValue(NumOperands - 1, V);
1750 setIncomingBlock(NumOperands - 1, BB);
1753 /// removeIncomingValue - Remove an incoming value. This is useful if a
1754 /// predecessor basic block is deleted. The value removed is returned.
1756 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1757 /// is true), the PHI node is destroyed and any uses of it are replaced with
1758 /// dummy values. The only time there should be zero incoming values to a PHI
1759 /// node is when the block is dead, so this strategy is sound.
1761 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1763 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1764 int Idx = getBasicBlockIndex(BB);
1765 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1766 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1769 /// getBasicBlockIndex - Return the first index of the specified basic
1770 /// block in the value list for this PHI. Returns -1 if no instance.
1772 int getBasicBlockIndex(const BasicBlock *BB) const {
1773 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
1774 if (block_begin()[i] == BB)
1779 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1780 int Idx = getBasicBlockIndex(BB);
1781 assert(Idx >= 0 && "Invalid basic block argument!");
1782 return getIncomingValue(Idx);
1785 /// hasConstantValue - If the specified PHI node always merges together the
1786 /// same value, return the value, otherwise return null.
1787 Value *hasConstantValue() const;
1789 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1790 static inline bool classof(const PHINode *) { return true; }
1791 static inline bool classof(const Instruction *I) {
1792 return I->getOpcode() == Instruction::PHI;
1794 static inline bool classof(const Value *V) {
1795 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1798 void growOperands();
1802 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1805 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1808 //===----------------------------------------------------------------------===//
1810 //===----------------------------------------------------------------------===//
1812 //===---------------------------------------------------------------------------
1813 /// ReturnInst - Return a value (possibly void), from a function. Execution
1814 /// does not continue in this function any longer.
1816 class ReturnInst : public TerminatorInst {
1817 ReturnInst(const ReturnInst &RI);
1820 // ReturnInst constructors:
1821 // ReturnInst() - 'ret void' instruction
1822 // ReturnInst( null) - 'ret void' instruction
1823 // ReturnInst(Value* X) - 'ret X' instruction
1824 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1825 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1826 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1827 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1829 // NOTE: If the Value* passed is of type void then the constructor behaves as
1830 // if it was passed NULL.
1831 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1832 Instruction *InsertBefore = 0);
1833 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1834 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1836 virtual ReturnInst *clone_impl() const;
1838 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1839 Instruction *InsertBefore = 0) {
1840 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1842 static ReturnInst* Create(LLVMContext &C, Value *retVal,
1843 BasicBlock *InsertAtEnd) {
1844 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
1846 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
1847 return new(0) ReturnInst(C, InsertAtEnd);
1849 virtual ~ReturnInst();
1851 /// Provide fast operand accessors
1852 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1854 /// Convenience accessor. Returns null if there is no return value.
1855 Value *getReturnValue() const {
1856 return getNumOperands() != 0 ? getOperand(0) : 0;
1859 unsigned getNumSuccessors() const { return 0; }
1861 // Methods for support type inquiry through isa, cast, and dyn_cast:
1862 static inline bool classof(const ReturnInst *) { return true; }
1863 static inline bool classof(const Instruction *I) {
1864 return (I->getOpcode() == Instruction::Ret);
1866 static inline bool classof(const Value *V) {
1867 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1870 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1871 virtual unsigned getNumSuccessorsV() const;
1872 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1876 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
1879 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1881 //===----------------------------------------------------------------------===//
1883 //===----------------------------------------------------------------------===//
1885 //===---------------------------------------------------------------------------
1886 /// BranchInst - Conditional or Unconditional Branch instruction.
1888 class BranchInst : public TerminatorInst {
1889 /// Ops list - Branches are strange. The operands are ordered:
1890 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
1891 /// they don't have to check for cond/uncond branchness. These are mostly
1892 /// accessed relative from op_end().
1893 BranchInst(const BranchInst &BI);
1895 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1896 // BranchInst(BB *B) - 'br B'
1897 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1898 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1899 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1900 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1901 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1902 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1903 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1904 Instruction *InsertBefore = 0);
1905 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1906 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1907 BasicBlock *InsertAtEnd);
1909 virtual BranchInst *clone_impl() const;
1911 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1912 return new(1) BranchInst(IfTrue, InsertBefore);
1914 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1915 Value *Cond, Instruction *InsertBefore = 0) {
1916 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1918 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1919 return new(1) BranchInst(IfTrue, InsertAtEnd);
1921 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1922 Value *Cond, BasicBlock *InsertAtEnd) {
1923 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1926 /// Transparently provide more efficient getOperand methods.
1927 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1929 bool isUnconditional() const { return getNumOperands() == 1; }
1930 bool isConditional() const { return getNumOperands() == 3; }
1932 Value *getCondition() const {
1933 assert(isConditional() && "Cannot get condition of an uncond branch!");
1937 void setCondition(Value *V) {
1938 assert(isConditional() && "Cannot set condition of unconditional branch!");
1942 unsigned getNumSuccessors() const { return 1+isConditional(); }
1944 BasicBlock *getSuccessor(unsigned i) const {
1945 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1946 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
1949 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1950 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1951 *(&Op<-1>() - idx) = (Value*)NewSucc;
1954 // Methods for support type inquiry through isa, cast, and dyn_cast:
1955 static inline bool classof(const BranchInst *) { return true; }
1956 static inline bool classof(const Instruction *I) {
1957 return (I->getOpcode() == Instruction::Br);
1959 static inline bool classof(const Value *V) {
1960 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1963 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1964 virtual unsigned getNumSuccessorsV() const;
1965 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1969 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
1972 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
1974 //===----------------------------------------------------------------------===//
1976 //===----------------------------------------------------------------------===//
1978 //===---------------------------------------------------------------------------
1979 /// SwitchInst - Multiway switch
1981 class SwitchInst : public TerminatorInst {
1982 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1983 unsigned ReservedSpace;
1984 // Operand[0] = Value to switch on
1985 // Operand[1] = Default basic block destination
1986 // Operand[2n ] = Value to match
1987 // Operand[2n+1] = BasicBlock to go to on match
1988 SwitchInst(const SwitchInst &SI);
1989 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
1990 void growOperands();
1991 // allocate space for exactly zero operands
1992 void *operator new(size_t s) {
1993 return User::operator new(s, 0);
1995 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1996 /// switch on and a default destination. The number of additional cases can
1997 /// be specified here to make memory allocation more efficient. This
1998 /// constructor can also autoinsert before another instruction.
1999 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2000 Instruction *InsertBefore);
2002 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2003 /// switch on and a default destination. The number of additional cases can
2004 /// be specified here to make memory allocation more efficient. This
2005 /// constructor also autoinserts at the end of the specified BasicBlock.
2006 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2007 BasicBlock *InsertAtEnd);
2009 virtual SwitchInst *clone_impl() const;
2011 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2012 unsigned NumCases, Instruction *InsertBefore = 0) {
2013 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2015 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2016 unsigned NumCases, BasicBlock *InsertAtEnd) {
2017 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2021 /// Provide fast operand accessors
2022 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2024 // Accessor Methods for Switch stmt
2025 Value *getCondition() const { return getOperand(0); }
2026 void setCondition(Value *V) { setOperand(0, V); }
2028 BasicBlock *getDefaultDest() const {
2029 return cast<BasicBlock>(getOperand(1));
2032 /// getNumCases - return the number of 'cases' in this switch instruction.
2033 /// Note that case #0 is always the default case.
2034 unsigned getNumCases() const {
2035 return getNumOperands()/2;
2038 /// getCaseValue - Return the specified case value. Note that case #0, the
2039 /// default destination, does not have a case value.
2040 ConstantInt *getCaseValue(unsigned i) {
2041 assert(i && i < getNumCases() && "Illegal case value to get!");
2042 return getSuccessorValue(i);
2045 /// getCaseValue - Return the specified case value. Note that case #0, the
2046 /// default destination, does not have a case value.
2047 const ConstantInt *getCaseValue(unsigned i) const {
2048 assert(i && i < getNumCases() && "Illegal case value to get!");
2049 return getSuccessorValue(i);
2052 /// findCaseValue - Search all of the case values for the specified constant.
2053 /// If it is explicitly handled, return the case number of it, otherwise
2054 /// return 0 to indicate that it is handled by the default handler.
2055 unsigned findCaseValue(const ConstantInt *C) const {
2056 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2057 if (getCaseValue(i) == C)
2062 /// findCaseDest - Finds the unique case value for a given successor. Returns
2063 /// null if the successor is not found, not unique, or is the default case.
2064 ConstantInt *findCaseDest(BasicBlock *BB) {
2065 if (BB == getDefaultDest()) return NULL;
2067 ConstantInt *CI = NULL;
2068 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2069 if (getSuccessor(i) == BB) {
2070 if (CI) return NULL; // Multiple cases lead to BB.
2071 else CI = getCaseValue(i);
2077 /// addCase - Add an entry to the switch instruction...
2079 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2081 /// removeCase - This method removes the specified successor from the switch
2082 /// instruction. Note that this cannot be used to remove the default
2083 /// destination (successor #0). Also note that this operation may reorder the
2084 /// remaining cases at index idx and above.
2086 void removeCase(unsigned idx);
2088 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2089 BasicBlock *getSuccessor(unsigned idx) const {
2090 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2091 return cast<BasicBlock>(getOperand(idx*2+1));
2093 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2094 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2095 setOperand(idx*2+1, (Value*)NewSucc);
2098 // getSuccessorValue - Return the value associated with the specified
2100 ConstantInt *getSuccessorValue(unsigned idx) const {
2101 assert(idx < getNumSuccessors() && "Successor # out of range!");
2102 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2105 // Methods for support type inquiry through isa, cast, and dyn_cast:
2106 static inline bool classof(const SwitchInst *) { return true; }
2107 static inline bool classof(const Instruction *I) {
2108 return I->getOpcode() == Instruction::Switch;
2110 static inline bool classof(const Value *V) {
2111 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2114 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2115 virtual unsigned getNumSuccessorsV() const;
2116 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2120 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2123 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2126 //===----------------------------------------------------------------------===//
2127 // IndirectBrInst Class
2128 //===----------------------------------------------------------------------===//
2130 //===---------------------------------------------------------------------------
2131 /// IndirectBrInst - Indirect Branch Instruction.
2133 class IndirectBrInst : public TerminatorInst {
2134 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2135 unsigned ReservedSpace;
2136 // Operand[0] = Value to switch on
2137 // Operand[1] = Default basic block destination
2138 // Operand[2n ] = Value to match
2139 // Operand[2n+1] = BasicBlock to go to on match
2140 IndirectBrInst(const IndirectBrInst &IBI);
2141 void init(Value *Address, unsigned NumDests);
2142 void growOperands();
2143 // allocate space for exactly zero operands
2144 void *operator new(size_t s) {
2145 return User::operator new(s, 0);
2147 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2148 /// Address to jump to. The number of expected destinations can be specified
2149 /// here to make memory allocation more efficient. This constructor can also
2150 /// autoinsert before another instruction.
2151 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2153 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2154 /// Address to jump to. The number of expected destinations can be specified
2155 /// here to make memory allocation more efficient. This constructor also
2156 /// autoinserts at the end of the specified BasicBlock.
2157 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2159 virtual IndirectBrInst *clone_impl() const;
2161 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2162 Instruction *InsertBefore = 0) {
2163 return new IndirectBrInst(Address, NumDests, InsertBefore);
2165 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2166 BasicBlock *InsertAtEnd) {
2167 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2171 /// Provide fast operand accessors.
2172 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2174 // Accessor Methods for IndirectBrInst instruction.
2175 Value *getAddress() { return getOperand(0); }
2176 const Value *getAddress() const { return getOperand(0); }
2177 void setAddress(Value *V) { setOperand(0, V); }
2180 /// getNumDestinations - return the number of possible destinations in this
2181 /// indirectbr instruction.
2182 unsigned getNumDestinations() const { return getNumOperands()-1; }
2184 /// getDestination - Return the specified destination.
2185 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2186 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2188 /// addDestination - Add a destination.
2190 void addDestination(BasicBlock *Dest);
2192 /// removeDestination - This method removes the specified successor from the
2193 /// indirectbr instruction.
2194 void removeDestination(unsigned i);
2196 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2197 BasicBlock *getSuccessor(unsigned i) const {
2198 return cast<BasicBlock>(getOperand(i+1));
2200 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2201 setOperand(i+1, (Value*)NewSucc);
2204 // Methods for support type inquiry through isa, cast, and dyn_cast:
2205 static inline bool classof(const IndirectBrInst *) { return true; }
2206 static inline bool classof(const Instruction *I) {
2207 return I->getOpcode() == Instruction::IndirectBr;
2209 static inline bool classof(const Value *V) {
2210 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2213 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2214 virtual unsigned getNumSuccessorsV() const;
2215 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2219 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2222 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2225 //===----------------------------------------------------------------------===//
2227 //===----------------------------------------------------------------------===//
2229 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2230 /// calling convention of the call.
2232 class InvokeInst : public TerminatorInst {
2233 AttrListPtr AttributeList;
2234 InvokeInst(const InvokeInst &BI);
2235 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2236 ArrayRef<Value *> Args, const Twine &NameStr);
2238 /// Construct an InvokeInst given a range of arguments.
2240 /// @brief Construct an InvokeInst from a range of arguments
2241 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2242 ArrayRef<Value *> Args, unsigned Values,
2243 const Twine &NameStr, Instruction *InsertBefore);
2245 /// Construct an InvokeInst given a range of arguments.
2247 /// @brief Construct an InvokeInst from a range of arguments
2248 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2249 ArrayRef<Value *> Args, unsigned Values,
2250 const Twine &NameStr, BasicBlock *InsertAtEnd);
2252 virtual InvokeInst *clone_impl() const;
2254 static InvokeInst *Create(Value *Func,
2255 BasicBlock *IfNormal, BasicBlock *IfException,
2256 ArrayRef<Value *> Args, const Twine &NameStr = "",
2257 Instruction *InsertBefore = 0) {
2258 unsigned Values = unsigned(Args.size()) + 3;
2259 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2260 Values, NameStr, InsertBefore);
2262 static InvokeInst *Create(Value *Func,
2263 BasicBlock *IfNormal, BasicBlock *IfException,
2264 ArrayRef<Value *> Args, const Twine &NameStr,
2265 BasicBlock *InsertAtEnd) {
2266 unsigned Values = unsigned(Args.size()) + 3;
2267 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2268 Values, NameStr, InsertAtEnd);
2271 /// Provide fast operand accessors
2272 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2274 /// getNumArgOperands - Return the number of invoke arguments.
2276 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2278 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2280 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2281 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2283 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2285 CallingConv::ID getCallingConv() const {
2286 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2288 void setCallingConv(CallingConv::ID CC) {
2289 setInstructionSubclassData(static_cast<unsigned>(CC));
2292 /// getAttributes - Return the parameter attributes for this invoke.
2294 const AttrListPtr &getAttributes() const { return AttributeList; }
2296 /// setAttributes - Set the parameter attributes for this invoke.
2298 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2300 /// addAttribute - adds the attribute to the list of attributes.
2301 void addAttribute(unsigned i, Attributes attr);
2303 /// removeAttribute - removes the attribute from the list of attributes.
2304 void removeAttribute(unsigned i, Attributes attr);
2306 /// @brief Determine whether the call or the callee has the given attribute.
2307 bool paramHasAttr(unsigned i, Attributes attr) const;
2309 /// @brief Extract the alignment for a call or parameter (0=unknown).
2310 unsigned getParamAlignment(unsigned i) const {
2311 return AttributeList.getParamAlignment(i);
2314 /// @brief Return true if the call should not be inlined.
2315 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2316 void setIsNoInline(bool Value = true) {
2317 if (Value) addAttribute(~0, Attribute::NoInline);
2318 else removeAttribute(~0, Attribute::NoInline);
2321 /// @brief Determine if the call does not access memory.
2322 bool doesNotAccessMemory() const {
2323 return paramHasAttr(~0, Attribute::ReadNone);
2325 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2326 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2327 else removeAttribute(~0, Attribute::ReadNone);
2330 /// @brief Determine if the call does not access or only reads memory.
2331 bool onlyReadsMemory() const {
2332 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2334 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2335 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2336 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2339 /// @brief Determine if the call cannot return.
2340 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2341 void setDoesNotReturn(bool DoesNotReturn = true) {
2342 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2343 else removeAttribute(~0, Attribute::NoReturn);
2346 /// @brief Determine if the call cannot unwind.
2347 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2348 void setDoesNotThrow(bool DoesNotThrow = true) {
2349 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2350 else removeAttribute(~0, Attribute::NoUnwind);
2353 /// @brief Determine if the call returns a structure through first
2354 /// pointer argument.
2355 bool hasStructRetAttr() const {
2356 // Be friendly and also check the callee.
2357 return paramHasAttr(1, Attribute::StructRet);
2360 /// @brief Determine if any call argument is an aggregate passed by value.
2361 bool hasByValArgument() const {
2362 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2365 /// getCalledFunction - Return the function called, or null if this is an
2366 /// indirect function invocation.
2368 Function *getCalledFunction() const {
2369 return dyn_cast<Function>(Op<-3>());
2372 /// getCalledValue - Get a pointer to the function that is invoked by this
2374 const Value *getCalledValue() const { return Op<-3>(); }
2375 Value *getCalledValue() { return Op<-3>(); }
2377 /// setCalledFunction - Set the function called.
2378 void setCalledFunction(Value* Fn) {
2382 // get*Dest - Return the destination basic blocks...
2383 BasicBlock *getNormalDest() const {
2384 return cast<BasicBlock>(Op<-2>());
2386 BasicBlock *getUnwindDest() const {
2387 return cast<BasicBlock>(Op<-1>());
2389 void setNormalDest(BasicBlock *B) {
2390 Op<-2>() = reinterpret_cast<Value*>(B);
2392 void setUnwindDest(BasicBlock *B) {
2393 Op<-1>() = reinterpret_cast<Value*>(B);
2396 BasicBlock *getSuccessor(unsigned i) const {
2397 assert(i < 2 && "Successor # out of range for invoke!");
2398 return i == 0 ? getNormalDest() : getUnwindDest();
2401 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2402 assert(idx < 2 && "Successor # out of range for invoke!");
2403 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2406 unsigned getNumSuccessors() const { return 2; }
2408 // Methods for support type inquiry through isa, cast, and dyn_cast:
2409 static inline bool classof(const InvokeInst *) { return true; }
2410 static inline bool classof(const Instruction *I) {
2411 return (I->getOpcode() == Instruction::Invoke);
2413 static inline bool classof(const Value *V) {
2414 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2418 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2419 virtual unsigned getNumSuccessorsV() const;
2420 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2422 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2423 // method so that subclasses cannot accidentally use it.
2424 void setInstructionSubclassData(unsigned short D) {
2425 Instruction::setInstructionSubclassData(D);
2430 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2433 InvokeInst::InvokeInst(Value *Func,
2434 BasicBlock *IfNormal, BasicBlock *IfException,
2435 ArrayRef<Value *> Args, unsigned Values,
2436 const Twine &NameStr, Instruction *InsertBefore)
2437 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2438 ->getElementType())->getReturnType(),
2439 Instruction::Invoke,
2440 OperandTraits<InvokeInst>::op_end(this) - Values,
2441 Values, InsertBefore) {
2442 init(Func, IfNormal, IfException, Args, NameStr);
2444 InvokeInst::InvokeInst(Value *Func,
2445 BasicBlock *IfNormal, BasicBlock *IfException,
2446 ArrayRef<Value *> Args, unsigned Values,
2447 const Twine &NameStr, BasicBlock *InsertAtEnd)
2448 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2449 ->getElementType())->getReturnType(),
2450 Instruction::Invoke,
2451 OperandTraits<InvokeInst>::op_end(this) - Values,
2452 Values, InsertAtEnd) {
2453 init(Func, IfNormal, IfException, Args, NameStr);
2456 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2458 //===----------------------------------------------------------------------===//
2460 //===----------------------------------------------------------------------===//
2462 //===---------------------------------------------------------------------------
2463 /// UnwindInst - Immediately exit the current function, unwinding the stack
2464 /// until an invoke instruction is found.
2466 class UnwindInst : public TerminatorInst {
2467 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2469 virtual UnwindInst *clone_impl() const;
2471 // allocate space for exactly zero operands
2472 void *operator new(size_t s) {
2473 return User::operator new(s, 0);
2475 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2476 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2478 unsigned getNumSuccessors() const { return 0; }
2480 // Methods for support type inquiry through isa, cast, and dyn_cast:
2481 static inline bool classof(const UnwindInst *) { return true; }
2482 static inline bool classof(const Instruction *I) {
2483 return I->getOpcode() == Instruction::Unwind;
2485 static inline bool classof(const Value *V) {
2486 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2489 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2490 virtual unsigned getNumSuccessorsV() const;
2491 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2494 //===----------------------------------------------------------------------===//
2495 // UnreachableInst Class
2496 //===----------------------------------------------------------------------===//
2498 //===---------------------------------------------------------------------------
2499 /// UnreachableInst - This function has undefined behavior. In particular, the
2500 /// presence of this instruction indicates some higher level knowledge that the
2501 /// end of the block cannot be reached.
2503 class UnreachableInst : public TerminatorInst {
2504 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2506 virtual UnreachableInst *clone_impl() const;
2509 // allocate space for exactly zero operands
2510 void *operator new(size_t s) {
2511 return User::operator new(s, 0);
2513 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2514 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2516 unsigned getNumSuccessors() const { return 0; }
2518 // Methods for support type inquiry through isa, cast, and dyn_cast:
2519 static inline bool classof(const UnreachableInst *) { return true; }
2520 static inline bool classof(const Instruction *I) {
2521 return I->getOpcode() == Instruction::Unreachable;
2523 static inline bool classof(const Value *V) {
2524 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2527 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2528 virtual unsigned getNumSuccessorsV() const;
2529 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2532 //===----------------------------------------------------------------------===//
2534 //===----------------------------------------------------------------------===//
2536 /// @brief This class represents a truncation of integer types.
2537 class TruncInst : public CastInst {
2539 /// @brief Clone an identical TruncInst
2540 virtual TruncInst *clone_impl() const;
2543 /// @brief Constructor with insert-before-instruction semantics
2545 Value *S, ///< The value to be truncated
2546 const Type *Ty, ///< The (smaller) type to truncate to
2547 const Twine &NameStr = "", ///< A name for the new instruction
2548 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2551 /// @brief Constructor with insert-at-end-of-block semantics
2553 Value *S, ///< The value to be truncated
2554 const Type *Ty, ///< The (smaller) type to truncate to
2555 const Twine &NameStr, ///< A name for the new instruction
2556 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2559 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2560 static inline bool classof(const TruncInst *) { return true; }
2561 static inline bool classof(const Instruction *I) {
2562 return I->getOpcode() == Trunc;
2564 static inline bool classof(const Value *V) {
2565 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2569 //===----------------------------------------------------------------------===//
2571 //===----------------------------------------------------------------------===//
2573 /// @brief This class represents zero extension of integer types.
2574 class ZExtInst : public CastInst {
2576 /// @brief Clone an identical ZExtInst
2577 virtual ZExtInst *clone_impl() const;
2580 /// @brief Constructor with insert-before-instruction semantics
2582 Value *S, ///< The value to be zero extended
2583 const Type *Ty, ///< The type to zero extend to
2584 const Twine &NameStr = "", ///< A name for the new instruction
2585 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2588 /// @brief Constructor with insert-at-end semantics.
2590 Value *S, ///< The value to be zero extended
2591 const Type *Ty, ///< The type to zero extend to
2592 const Twine &NameStr, ///< A name for the new instruction
2593 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2596 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2597 static inline bool classof(const ZExtInst *) { return true; }
2598 static inline bool classof(const Instruction *I) {
2599 return I->getOpcode() == ZExt;
2601 static inline bool classof(const Value *V) {
2602 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2606 //===----------------------------------------------------------------------===//
2608 //===----------------------------------------------------------------------===//
2610 /// @brief This class represents a sign extension of integer types.
2611 class SExtInst : public CastInst {
2613 /// @brief Clone an identical SExtInst
2614 virtual SExtInst *clone_impl() const;
2617 /// @brief Constructor with insert-before-instruction semantics
2619 Value *S, ///< The value to be sign extended
2620 const Type *Ty, ///< The type to sign extend to
2621 const Twine &NameStr = "", ///< A name for the new instruction
2622 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2625 /// @brief Constructor with insert-at-end-of-block semantics
2627 Value *S, ///< The value to be sign extended
2628 const Type *Ty, ///< The type to sign extend to
2629 const Twine &NameStr, ///< A name for the new instruction
2630 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2633 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2634 static inline bool classof(const SExtInst *) { return true; }
2635 static inline bool classof(const Instruction *I) {
2636 return I->getOpcode() == SExt;
2638 static inline bool classof(const Value *V) {
2639 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2643 //===----------------------------------------------------------------------===//
2644 // FPTruncInst Class
2645 //===----------------------------------------------------------------------===//
2647 /// @brief This class represents a truncation of floating point types.
2648 class FPTruncInst : public CastInst {
2650 /// @brief Clone an identical FPTruncInst
2651 virtual FPTruncInst *clone_impl() const;
2654 /// @brief Constructor with insert-before-instruction semantics
2656 Value *S, ///< The value to be truncated
2657 const Type *Ty, ///< The type to truncate to
2658 const Twine &NameStr = "", ///< A name for the new instruction
2659 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2662 /// @brief Constructor with insert-before-instruction semantics
2664 Value *S, ///< The value to be truncated
2665 const Type *Ty, ///< The type to truncate to
2666 const Twine &NameStr, ///< A name for the new instruction
2667 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2670 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2671 static inline bool classof(const FPTruncInst *) { return true; }
2672 static inline bool classof(const Instruction *I) {
2673 return I->getOpcode() == FPTrunc;
2675 static inline bool classof(const Value *V) {
2676 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2680 //===----------------------------------------------------------------------===//
2682 //===----------------------------------------------------------------------===//
2684 /// @brief This class represents an extension of floating point types.
2685 class FPExtInst : public CastInst {
2687 /// @brief Clone an identical FPExtInst
2688 virtual FPExtInst *clone_impl() const;
2691 /// @brief Constructor with insert-before-instruction semantics
2693 Value *S, ///< The value to be extended
2694 const Type *Ty, ///< The type to extend to
2695 const Twine &NameStr = "", ///< A name for the new instruction
2696 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2699 /// @brief Constructor with insert-at-end-of-block semantics
2701 Value *S, ///< The value to be extended
2702 const Type *Ty, ///< The type to extend to
2703 const Twine &NameStr, ///< A name for the new instruction
2704 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2707 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2708 static inline bool classof(const FPExtInst *) { return true; }
2709 static inline bool classof(const Instruction *I) {
2710 return I->getOpcode() == FPExt;
2712 static inline bool classof(const Value *V) {
2713 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2717 //===----------------------------------------------------------------------===//
2719 //===----------------------------------------------------------------------===//
2721 /// @brief This class represents a cast unsigned integer to floating point.
2722 class UIToFPInst : public CastInst {
2724 /// @brief Clone an identical UIToFPInst
2725 virtual UIToFPInst *clone_impl() const;
2728 /// @brief Constructor with insert-before-instruction semantics
2730 Value *S, ///< The value to be converted
2731 const Type *Ty, ///< The type to convert to
2732 const Twine &NameStr = "", ///< A name for the new instruction
2733 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2736 /// @brief Constructor with insert-at-end-of-block semantics
2738 Value *S, ///< The value to be converted
2739 const Type *Ty, ///< The type to convert to
2740 const Twine &NameStr, ///< A name for the new instruction
2741 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2744 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2745 static inline bool classof(const UIToFPInst *) { return true; }
2746 static inline bool classof(const Instruction *I) {
2747 return I->getOpcode() == UIToFP;
2749 static inline bool classof(const Value *V) {
2750 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2754 //===----------------------------------------------------------------------===//
2756 //===----------------------------------------------------------------------===//
2758 /// @brief This class represents a cast from signed integer to floating point.
2759 class SIToFPInst : public CastInst {
2761 /// @brief Clone an identical SIToFPInst
2762 virtual SIToFPInst *clone_impl() const;
2765 /// @brief Constructor with insert-before-instruction semantics
2767 Value *S, ///< The value to be converted
2768 const Type *Ty, ///< The type to convert to
2769 const Twine &NameStr = "", ///< A name for the new instruction
2770 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2773 /// @brief Constructor with insert-at-end-of-block semantics
2775 Value *S, ///< The value to be converted
2776 const Type *Ty, ///< The type to convert to
2777 const Twine &NameStr, ///< A name for the new instruction
2778 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2781 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2782 static inline bool classof(const SIToFPInst *) { return true; }
2783 static inline bool classof(const Instruction *I) {
2784 return I->getOpcode() == SIToFP;
2786 static inline bool classof(const Value *V) {
2787 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2791 //===----------------------------------------------------------------------===//
2793 //===----------------------------------------------------------------------===//
2795 /// @brief This class represents a cast from floating point to unsigned integer
2796 class FPToUIInst : public CastInst {
2798 /// @brief Clone an identical FPToUIInst
2799 virtual FPToUIInst *clone_impl() const;
2802 /// @brief Constructor with insert-before-instruction semantics
2804 Value *S, ///< The value to be converted
2805 const Type *Ty, ///< The type to convert to
2806 const Twine &NameStr = "", ///< A name for the new instruction
2807 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2810 /// @brief Constructor with insert-at-end-of-block semantics
2812 Value *S, ///< The value to be converted
2813 const Type *Ty, ///< The type to convert to
2814 const Twine &NameStr, ///< A name for the new instruction
2815 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2818 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2819 static inline bool classof(const FPToUIInst *) { return true; }
2820 static inline bool classof(const Instruction *I) {
2821 return I->getOpcode() == FPToUI;
2823 static inline bool classof(const Value *V) {
2824 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2828 //===----------------------------------------------------------------------===//
2830 //===----------------------------------------------------------------------===//
2832 /// @brief This class represents a cast from floating point to signed integer.
2833 class FPToSIInst : public CastInst {
2835 /// @brief Clone an identical FPToSIInst
2836 virtual FPToSIInst *clone_impl() const;
2839 /// @brief Constructor with insert-before-instruction semantics
2841 Value *S, ///< The value to be converted
2842 const Type *Ty, ///< The type to convert to
2843 const Twine &NameStr = "", ///< A name for the new instruction
2844 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2847 /// @brief Constructor with insert-at-end-of-block semantics
2849 Value *S, ///< The value to be converted
2850 const Type *Ty, ///< The type to convert to
2851 const Twine &NameStr, ///< A name for the new instruction
2852 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2855 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2856 static inline bool classof(const FPToSIInst *) { return true; }
2857 static inline bool classof(const Instruction *I) {
2858 return I->getOpcode() == FPToSI;
2860 static inline bool classof(const Value *V) {
2861 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2865 //===----------------------------------------------------------------------===//
2866 // IntToPtrInst Class
2867 //===----------------------------------------------------------------------===//
2869 /// @brief This class represents a cast from an integer to a pointer.
2870 class IntToPtrInst : public CastInst {
2872 /// @brief Constructor with insert-before-instruction semantics
2874 Value *S, ///< The value to be converted
2875 const Type *Ty, ///< The type to convert to
2876 const Twine &NameStr = "", ///< A name for the new instruction
2877 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2880 /// @brief Constructor with insert-at-end-of-block semantics
2882 Value *S, ///< The value to be converted
2883 const Type *Ty, ///< The type to convert to
2884 const Twine &NameStr, ///< A name for the new instruction
2885 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2888 /// @brief Clone an identical IntToPtrInst
2889 virtual IntToPtrInst *clone_impl() const;
2891 // Methods for support type inquiry through isa, cast, and dyn_cast:
2892 static inline bool classof(const IntToPtrInst *) { return true; }
2893 static inline bool classof(const Instruction *I) {
2894 return I->getOpcode() == IntToPtr;
2896 static inline bool classof(const Value *V) {
2897 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2901 //===----------------------------------------------------------------------===//
2902 // PtrToIntInst Class
2903 //===----------------------------------------------------------------------===//
2905 /// @brief This class represents a cast from a pointer to an integer
2906 class PtrToIntInst : public CastInst {
2908 /// @brief Clone an identical PtrToIntInst
2909 virtual PtrToIntInst *clone_impl() const;
2912 /// @brief Constructor with insert-before-instruction semantics
2914 Value *S, ///< The value to be converted
2915 const Type *Ty, ///< The type to convert to
2916 const Twine &NameStr = "", ///< A name for the new instruction
2917 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2920 /// @brief Constructor with insert-at-end-of-block semantics
2922 Value *S, ///< The value to be converted
2923 const Type *Ty, ///< The type to convert to
2924 const Twine &NameStr, ///< A name for the new instruction
2925 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2928 // Methods for support type inquiry through isa, cast, and dyn_cast:
2929 static inline bool classof(const PtrToIntInst *) { return true; }
2930 static inline bool classof(const Instruction *I) {
2931 return I->getOpcode() == PtrToInt;
2933 static inline bool classof(const Value *V) {
2934 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2938 //===----------------------------------------------------------------------===//
2939 // BitCastInst Class
2940 //===----------------------------------------------------------------------===//
2942 /// @brief This class represents a no-op cast from one type to another.
2943 class BitCastInst : public CastInst {
2945 /// @brief Clone an identical BitCastInst
2946 virtual BitCastInst *clone_impl() const;
2949 /// @brief Constructor with insert-before-instruction semantics
2951 Value *S, ///< The value to be casted
2952 const Type *Ty, ///< The type to casted to
2953 const Twine &NameStr = "", ///< A name for the new instruction
2954 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2957 /// @brief Constructor with insert-at-end-of-block semantics
2959 Value *S, ///< The value to be casted
2960 const Type *Ty, ///< The type to casted to
2961 const Twine &NameStr, ///< A name for the new instruction
2962 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2965 // Methods for support type inquiry through isa, cast, and dyn_cast:
2966 static inline bool classof(const BitCastInst *) { return true; }
2967 static inline bool classof(const Instruction *I) {
2968 return I->getOpcode() == BitCast;
2970 static inline bool classof(const Value *V) {
2971 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2975 } // End llvm namespace