blob: 4f1222f43f68bbff4f65fe650b8127251e300079 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner84e66db2007-12-29 19:59:42 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
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.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_INSTRUCTIONS_H
17#define LLVM_INSTRUCTIONS_H
18
David Greeneb1c4a7b2007-08-01 03:43:44 +000019#include <iterator>
20
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021#include "llvm/InstrTypes.h"
David Greeneb1c4a7b2007-08-01 03:43:44 +000022#include "llvm/DerivedTypes.h"
Dale Johannesenf4666f52008-02-19 21:38:47 +000023#include "llvm/ParameterAttributes.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000024
25namespace llvm {
26
27class BasicBlock;
28class ConstantInt;
29class PointerType;
30class VectorType;
31class ConstantRange;
32class APInt;
33class ParamAttrsList;
34
35//===----------------------------------------------------------------------===//
36// AllocationInst Class
37//===----------------------------------------------------------------------===//
38
39/// AllocationInst - This class is the common base class of MallocInst and
40/// AllocaInst.
41///
42class AllocationInst : public UnaryInstruction {
43 unsigned Alignment;
44protected:
45 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
46 const std::string &Name = "", Instruction *InsertBefore = 0);
47 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
48 const std::string &Name, BasicBlock *InsertAtEnd);
49public:
Gordon Henriksenc8ddfa62007-12-10 02:14:30 +000050 // Out of line virtual method, so the vtable, etc has a home.
51 virtual ~AllocationInst();
52
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053 /// isArrayAllocation - Return true if there is an allocation size parameter
54 /// to the allocation instruction that is not 1.
55 ///
56 bool isArrayAllocation() const;
57
58 /// getArraySize - Get the number of element allocated, for a simple
59 /// allocation of a single element, this will return a constant 1 value.
60 ///
61 inline const Value *getArraySize() const { return getOperand(0); }
62 inline Value *getArraySize() { return getOperand(0); }
63
64 /// getType - Overload to return most specific pointer type
65 ///
66 inline const PointerType *getType() const {
67 return reinterpret_cast<const PointerType*>(Instruction::getType());
68 }
69
70 /// getAllocatedType - Return the type that is being allocated by the
71 /// instruction.
72 ///
73 const Type *getAllocatedType() const;
74
75 /// getAlignment - Return the alignment of the memory that is being allocated
76 /// by the instruction.
77 ///
78 unsigned getAlignment() const { return Alignment; }
79 void setAlignment(unsigned Align) {
80 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
81 Alignment = Align;
82 }
83
84 virtual Instruction *clone() const = 0;
85
86 // Methods for support type inquiry through isa, cast, and dyn_cast:
87 static inline bool classof(const AllocationInst *) { return true; }
88 static inline bool classof(const Instruction *I) {
89 return I->getOpcode() == Instruction::Alloca ||
90 I->getOpcode() == Instruction::Malloc;
91 }
92 static inline bool classof(const Value *V) {
93 return isa<Instruction>(V) && classof(cast<Instruction>(V));
94 }
95};
96
97
98//===----------------------------------------------------------------------===//
99// MallocInst Class
100//===----------------------------------------------------------------------===//
101
102/// MallocInst - an instruction to allocated memory on the heap
103///
104class MallocInst : public AllocationInst {
105 MallocInst(const MallocInst &MI);
106public:
107 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
108 const std::string &Name = "",
109 Instruction *InsertBefore = 0)
110 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
111 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
112 BasicBlock *InsertAtEnd)
113 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
114
115 MallocInst(const Type *Ty, const std::string &Name,
116 Instruction *InsertBefore = 0)
117 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
118 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
119 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
120
121 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
122 const std::string &Name, BasicBlock *InsertAtEnd)
123 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
124 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
125 const std::string &Name = "",
126 Instruction *InsertBefore = 0)
127 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
128
129 virtual MallocInst *clone() const;
130
131 // Methods for support type inquiry through isa, cast, and dyn_cast:
132 static inline bool classof(const MallocInst *) { return true; }
133 static inline bool classof(const Instruction *I) {
134 return (I->getOpcode() == Instruction::Malloc);
135 }
136 static inline bool classof(const Value *V) {
137 return isa<Instruction>(V) && classof(cast<Instruction>(V));
138 }
139};
140
141
142//===----------------------------------------------------------------------===//
143// AllocaInst Class
144//===----------------------------------------------------------------------===//
145
146/// AllocaInst - an instruction to allocate memory on the stack
147///
148class AllocaInst : public AllocationInst {
149 AllocaInst(const AllocaInst &);
150public:
151 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
152 const std::string &Name = "",
153 Instruction *InsertBefore = 0)
154 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
155 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
156 BasicBlock *InsertAtEnd)
157 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
158
159 AllocaInst(const Type *Ty, const std::string &Name,
160 Instruction *InsertBefore = 0)
161 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
162 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
163 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
164
165 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
166 const std::string &Name = "", Instruction *InsertBefore = 0)
167 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
168 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
169 const std::string &Name, BasicBlock *InsertAtEnd)
170 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
171
172 virtual AllocaInst *clone() const;
173
174 // Methods for support type inquiry through isa, cast, and dyn_cast:
175 static inline bool classof(const AllocaInst *) { return true; }
176 static inline bool classof(const Instruction *I) {
177 return (I->getOpcode() == Instruction::Alloca);
178 }
179 static inline bool classof(const Value *V) {
180 return isa<Instruction>(V) && classof(cast<Instruction>(V));
181 }
182};
183
184
185//===----------------------------------------------------------------------===//
186// FreeInst Class
187//===----------------------------------------------------------------------===//
188
189/// FreeInst - an instruction to deallocate memory
190///
191class FreeInst : public UnaryInstruction {
192 void AssertOK();
193public:
194 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
195 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
196
197 virtual FreeInst *clone() const;
198
199 // Accessor methods for consistency with other memory operations
200 Value *getPointerOperand() { return getOperand(0); }
201 const Value *getPointerOperand() const { return getOperand(0); }
202
203 // Methods for support type inquiry through isa, cast, and dyn_cast:
204 static inline bool classof(const FreeInst *) { return true; }
205 static inline bool classof(const Instruction *I) {
206 return (I->getOpcode() == Instruction::Free);
207 }
208 static inline bool classof(const Value *V) {
209 return isa<Instruction>(V) && classof(cast<Instruction>(V));
210 }
211};
212
213
214//===----------------------------------------------------------------------===//
215// LoadInst Class
216//===----------------------------------------------------------------------===//
217
218/// LoadInst - an instruction for reading from memory. This uses the
219/// SubclassData field in Value to store whether or not the load is volatile.
220///
221class LoadInst : public UnaryInstruction {
222
223 LoadInst(const LoadInst &LI)
224 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
225 setVolatile(LI.isVolatile());
226 setAlignment(LI.getAlignment());
227
228#ifndef NDEBUG
229 AssertOK();
230#endif
231 }
232 void AssertOK();
233public:
234 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
235 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
236 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
237 Instruction *InsertBefore = 0);
238 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
239 Instruction *InsertBefore = 0);
240 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
241 BasicBlock *InsertAtEnd);
Dan Gohmane59e58d2007-07-18 20:51:11 +0000242 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
243 BasicBlock *InsertAtEnd);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244
245 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
246 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
247 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
248 Instruction *InsertBefore = 0);
249 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
250 BasicBlock *InsertAtEnd);
251
252 /// isVolatile - Return true if this is a load from a volatile memory
253 /// location.
254 ///
255 bool isVolatile() const { return SubclassData & 1; }
256
257 /// setVolatile - Specify whether this is a volatile load or not.
258 ///
259 void setVolatile(bool V) {
Hartmut Kaiser2e15f662007-10-17 14:56:40 +0000260 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261 }
262
263 virtual LoadInst *clone() const;
264
265 /// getAlignment - Return the alignment of the access that is being performed
266 ///
267 unsigned getAlignment() const {
268 return (1 << (SubclassData>>1)) >> 1;
269 }
270
271 void setAlignment(unsigned Align);
272
273 Value *getPointerOperand() { return getOperand(0); }
274 const Value *getPointerOperand() const { return getOperand(0); }
275 static unsigned getPointerOperandIndex() { return 0U; }
276
277 // Methods for support type inquiry through isa, cast, and dyn_cast:
278 static inline bool classof(const LoadInst *) { return true; }
279 static inline bool classof(const Instruction *I) {
280 return I->getOpcode() == Instruction::Load;
281 }
282 static inline bool classof(const Value *V) {
283 return isa<Instruction>(V) && classof(cast<Instruction>(V));
284 }
285};
286
287
288//===----------------------------------------------------------------------===//
289// StoreInst Class
290//===----------------------------------------------------------------------===//
291
292/// StoreInst - an instruction for storing to memory
293///
294class StoreInst : public Instruction {
295 Use Ops[2];
296
297 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
298 Ops[0].init(SI.Ops[0], this);
299 Ops[1].init(SI.Ops[1], this);
300 setVolatile(SI.isVolatile());
301 setAlignment(SI.getAlignment());
302
303#ifndef NDEBUG
304 AssertOK();
305#endif
306 }
307 void AssertOK();
308public:
309 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
310 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
311 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
312 Instruction *InsertBefore = 0);
313 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
314 unsigned Align, Instruction *InsertBefore = 0);
315 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
Dan Gohmane59e58d2007-07-18 20:51:11 +0000316 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
317 unsigned Align, BasicBlock *InsertAtEnd);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000318
319
320 /// isVolatile - Return true if this is a load from a volatile memory
321 /// location.
322 ///
323 bool isVolatile() const { return SubclassData & 1; }
324
325 /// setVolatile - Specify whether this is a volatile load or not.
326 ///
327 void setVolatile(bool V) {
Hartmut Kaiser2e15f662007-10-17 14:56:40 +0000328 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329 }
330
331 /// Transparently provide more efficient getOperand methods.
332 Value *getOperand(unsigned i) const {
333 assert(i < 2 && "getOperand() out of range!");
334 return Ops[i];
335 }
336 void setOperand(unsigned i, Value *Val) {
337 assert(i < 2 && "setOperand() out of range!");
338 Ops[i] = Val;
339 }
340 unsigned getNumOperands() const { return 2; }
341
342 /// getAlignment - Return the alignment of the access that is being performed
343 ///
344 unsigned getAlignment() const {
345 return (1 << (SubclassData>>1)) >> 1;
346 }
347
348 void setAlignment(unsigned Align);
349
350 virtual StoreInst *clone() const;
351
352 Value *getPointerOperand() { return getOperand(1); }
353 const Value *getPointerOperand() const { return getOperand(1); }
354 static unsigned getPointerOperandIndex() { return 1U; }
355
356 // Methods for support type inquiry through isa, cast, and dyn_cast:
357 static inline bool classof(const StoreInst *) { return true; }
358 static inline bool classof(const Instruction *I) {
359 return I->getOpcode() == Instruction::Store;
360 }
361 static inline bool classof(const Value *V) {
362 return isa<Instruction>(V) && classof(cast<Instruction>(V));
363 }
364};
365
366
367//===----------------------------------------------------------------------===//
368// GetElementPtrInst Class
369//===----------------------------------------------------------------------===//
370
David Greene393be882007-09-04 15:46:09 +0000371// checkType - Simple wrapper function to give a better assertion failure
372// message on bad indexes for a gep instruction.
373//
374static inline const Type *checkType(const Type *Ty) {
375 assert(Ty && "Invalid GetElementPtrInst indices for type!");
376 return Ty;
377}
378
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
380/// access elements of arrays and structs
381///
382class GetElementPtrInst : public Instruction {
383 GetElementPtrInst(const GetElementPtrInst &GEPI)
384 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
385 0, GEPI.getNumOperands()) {
386 Use *OL = OperandList = new Use[NumOperands];
387 Use *GEPIOL = GEPI.OperandList;
388 for (unsigned i = 0, E = NumOperands; i != E; ++i)
389 OL[i].init(GEPIOL[i], this);
390 }
391 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392 void init(Value *Ptr, Value *Idx);
David Greene393be882007-09-04 15:46:09 +0000393
394 template<typename InputIterator>
395 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
396 const std::string &Name,
397 // This argument ensures that we have an iterator we can
398 // do arithmetic on in constant time
399 std::random_access_iterator_tag) {
400 typename std::iterator_traits<InputIterator>::difference_type NumIdx =
401 std::distance(IdxBegin, IdxEnd);
402
403 if (NumIdx > 0) {
404 // This requires that the itoerator points to contiguous memory.
405 init(Ptr, &*IdxBegin, NumIdx);
406 }
407 else {
408 init(Ptr, 0, NumIdx);
409 }
410
411 setName(Name);
412 }
413
414 /// getIndexedType - Returns the type of the element that would be loaded with
415 /// a load instruction with the specified parameters.
416 ///
417 /// A null type is returned if the indices are invalid for the specified
418 /// pointer type.
419 ///
420 static const Type *getIndexedType(const Type *Ptr,
421 Value* const *Idx, unsigned NumIdx,
422 bool AllowStructLeaf = false);
423
424 template<typename InputIterator>
425 static const Type *getIndexedType(const Type *Ptr,
426 InputIterator IdxBegin,
427 InputIterator IdxEnd,
428 bool AllowStructLeaf,
429 // This argument ensures that we
430 // have an iterator we can do
431 // arithmetic on in constant time
432 std::random_access_iterator_tag) {
433 typename std::iterator_traits<InputIterator>::difference_type NumIdx =
434 std::distance(IdxBegin, IdxEnd);
435
436 if (NumIdx > 0) {
437 // This requires that the iterator points to contiguous memory.
438 return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
439 AllowStructLeaf));
440 }
441 else {
442 return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
443 }
444 }
445
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446public:
447 /// Constructors - Create a getelementptr instruction with a base pointer an
448 /// list of indices. The first ctor can optionally insert before an existing
449 /// instruction, the second appends the new instruction to the specified
450 /// BasicBlock.
David Greene393be882007-09-04 15:46:09 +0000451 template<typename InputIterator>
452 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
453 InputIterator IdxEnd,
454 const std::string &Name = "",
455 Instruction *InsertBefore =0)
456 : Instruction(PointerType::get(
457 checkType(getIndexedType(Ptr->getType(),
Christopher Lamb44d62f62007-12-11 08:59:05 +0000458 IdxBegin, IdxEnd, true)),
459 cast<PointerType>(Ptr->getType())->getAddressSpace()),
David Greene393be882007-09-04 15:46:09 +0000460 GetElementPtr, 0, 0, InsertBefore) {
461 init(Ptr, IdxBegin, IdxEnd, Name,
462 typename std::iterator_traits<InputIterator>::iterator_category());
463 }
464 template<typename InputIterator>
465 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
466 const std::string &Name, BasicBlock *InsertAtEnd)
467 : Instruction(PointerType::get(
468 checkType(getIndexedType(Ptr->getType(),
Christopher Lamb44d62f62007-12-11 08:59:05 +0000469 IdxBegin, IdxEnd, true)),
470 cast<PointerType>(Ptr->getType())->getAddressSpace()),
David Greene393be882007-09-04 15:46:09 +0000471 GetElementPtr, 0, 0, InsertAtEnd) {
472 init(Ptr, IdxBegin, IdxEnd, Name,
473 typename std::iterator_traits<InputIterator>::iterator_category());
474 }
475
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476 /// Constructors - These two constructors are convenience methods because one
477 /// and two index getelementptr instructions are so common.
478 GetElementPtrInst(Value *Ptr, Value *Idx,
479 const std::string &Name = "", Instruction *InsertBefore =0);
480 GetElementPtrInst(Value *Ptr, Value *Idx,
481 const std::string &Name, BasicBlock *InsertAtEnd);
Gordon Henriksenc8ddfa62007-12-10 02:14:30 +0000482 ~GetElementPtrInst();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483
484 virtual GetElementPtrInst *clone() const;
485
486 // getType - Overload to return most specific pointer type...
487 inline const PointerType *getType() const {
488 return reinterpret_cast<const PointerType*>(Instruction::getType());
489 }
490
491 /// getIndexedType - Returns the type of the element that would be loaded with
492 /// a load instruction with the specified parameters.
493 ///
494 /// A null type is returned if the indices are invalid for the specified
495 /// pointer type.
496 ///
David Greene393be882007-09-04 15:46:09 +0000497 template<typename InputIterator>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498 static const Type *getIndexedType(const Type *Ptr,
David Greene393be882007-09-04 15:46:09 +0000499 InputIterator IdxBegin,
500 InputIterator IdxEnd,
501 bool AllowStructLeaf = false) {
502 return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf,
503 typename std::iterator_traits<InputIterator>::
504 iterator_category()));
505 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
507
508 inline op_iterator idx_begin() { return op_begin()+1; }
509 inline const_op_iterator idx_begin() const { return op_begin()+1; }
510 inline op_iterator idx_end() { return op_end(); }
511 inline const_op_iterator idx_end() const { return op_end(); }
512
513 Value *getPointerOperand() {
514 return getOperand(0);
515 }
516 const Value *getPointerOperand() const {
517 return getOperand(0);
518 }
519 static unsigned getPointerOperandIndex() {
520 return 0U; // get index for modifying correct operand
521 }
522
523 inline unsigned getNumIndices() const { // Note: always non-negative
524 return getNumOperands() - 1;
525 }
526
527 inline bool hasIndices() const {
528 return getNumOperands() > 1;
529 }
530
531 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
532 /// zeros. If so, the result pointer and the first operand have the same
533 /// value, just potentially different types.
534 bool hasAllZeroIndices() const;
535
536 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
537 /// constant integers. If so, the result pointer and the first operand have
538 /// a constant offset between them.
539 bool hasAllConstantIndices() const;
540
541
542 // Methods for support type inquiry through isa, cast, and dyn_cast:
543 static inline bool classof(const GetElementPtrInst *) { return true; }
544 static inline bool classof(const Instruction *I) {
545 return (I->getOpcode() == Instruction::GetElementPtr);
546 }
547 static inline bool classof(const Value *V) {
548 return isa<Instruction>(V) && classof(cast<Instruction>(V));
549 }
550};
551
552//===----------------------------------------------------------------------===//
553// ICmpInst Class
554//===----------------------------------------------------------------------===//
555
556/// This instruction compares its operands according to the predicate given
557/// to the constructor. It only operates on integers, pointers, or packed
558/// vectors of integrals. The two operands must be the same type.
559/// @brief Represent an integer comparison operator.
560class ICmpInst: public CmpInst {
561public:
562 /// This enumeration lists the possible predicates for the ICmpInst. The
563 /// values in the range 0-31 are reserved for FCmpInst while values in the
564 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
565 /// predicate values are not overlapping between the classes.
566 enum Predicate {
567 ICMP_EQ = 32, ///< equal
568 ICMP_NE = 33, ///< not equal
569 ICMP_UGT = 34, ///< unsigned greater than
570 ICMP_UGE = 35, ///< unsigned greater or equal
571 ICMP_ULT = 36, ///< unsigned less than
572 ICMP_ULE = 37, ///< unsigned less or equal
573 ICMP_SGT = 38, ///< signed greater than
574 ICMP_SGE = 39, ///< signed greater or equal
575 ICMP_SLT = 40, ///< signed less than
576 ICMP_SLE = 41, ///< signed less or equal
577 FIRST_ICMP_PREDICATE = ICMP_EQ,
578 LAST_ICMP_PREDICATE = ICMP_SLE,
579 BAD_ICMP_PREDICATE = ICMP_SLE + 1
580 };
581
582 /// @brief Constructor with insert-before-instruction semantics.
583 ICmpInst(
584 Predicate pred, ///< The predicate to use for the comparison
585 Value *LHS, ///< The left-hand-side of the expression
586 Value *RHS, ///< The right-hand-side of the expression
587 const std::string &Name = "", ///< Name of the instruction
588 Instruction *InsertBefore = 0 ///< Where to insert
589 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
590 }
591
592 /// @brief Constructor with insert-at-block-end semantics.
593 ICmpInst(
594 Predicate pred, ///< The predicate to use for the comparison
595 Value *LHS, ///< The left-hand-side of the expression
596 Value *RHS, ///< The right-hand-side of the expression
597 const std::string &Name, ///< Name of the instruction
598 BasicBlock *InsertAtEnd ///< Block to insert into.
599 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
600 }
601
602 /// @brief Return the predicate for this instruction.
603 Predicate getPredicate() const { return Predicate(SubclassData); }
604
605 /// @brief Set the predicate for this instruction to the specified value.
606 void setPredicate(Predicate P) { SubclassData = P; }
607
608 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
609 /// @returns the inverse predicate for the instruction's current predicate.
610 /// @brief Return the inverse of the instruction's predicate.
611 Predicate getInversePredicate() const {
612 return getInversePredicate(getPredicate());
613 }
614
615 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
616 /// @returns the inverse predicate for predicate provided in \p pred.
617 /// @brief Return the inverse of a given predicate
618 static Predicate getInversePredicate(Predicate pred);
619
620 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
621 /// @returns the predicate that would be the result of exchanging the two
622 /// operands of the ICmpInst instruction without changing the result
623 /// produced.
624 /// @brief Return the predicate as if the operands were swapped
625 Predicate getSwappedPredicate() const {
626 return getSwappedPredicate(getPredicate());
627 }
628
629 /// This is a static version that you can use without an instruction
630 /// available.
631 /// @brief Return the predicate as if the operands were swapped.
632 static Predicate getSwappedPredicate(Predicate pred);
633
634 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
635 /// @returns the predicate that would be the result if the operand were
636 /// regarded as signed.
637 /// @brief Return the signed version of the predicate
638 Predicate getSignedPredicate() const {
639 return getSignedPredicate(getPredicate());
640 }
641
642 /// This is a static version that you can use without an instruction.
643 /// @brief Return the signed version of the predicate.
644 static Predicate getSignedPredicate(Predicate pred);
645
Nick Lewyckyd4264dc2008-01-28 03:48:02 +0000646 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
647 /// @returns the predicate that would be the result if the operand were
648 /// regarded as unsigned.
649 /// @brief Return the unsigned version of the predicate
650 Predicate getUnsignedPredicate() const {
651 return getUnsignedPredicate(getPredicate());
652 }
653
654 /// This is a static version that you can use without an instruction.
655 /// @brief Return the unsigned version of the predicate.
656 static Predicate getUnsignedPredicate(Predicate pred);
657
Chris Lattner8a3ba202007-11-22 23:43:29 +0000658 /// isEquality - Return true if this predicate is either EQ or NE. This also
659 /// tests for commutativity.
660 static bool isEquality(Predicate P) {
661 return P == ICMP_EQ || P == ICMP_NE;
662 }
663
664 /// isEquality - Return true if this predicate is either EQ or NE. This also
665 /// tests for commutativity.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000666 bool isEquality() const {
Chris Lattner8a3ba202007-11-22 23:43:29 +0000667 return isEquality(getPredicate());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000668 }
669
670 /// @returns true if the predicate of this ICmpInst is commutative
671 /// @brief Determine if this relation is commutative.
672 bool isCommutative() const { return isEquality(); }
673
Chris Lattner8a3ba202007-11-22 23:43:29 +0000674 /// isRelational - Return true if the predicate is relational (not EQ or NE).
675 ///
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676 bool isRelational() const {
677 return !isEquality();
678 }
679
Chris Lattner8a3ba202007-11-22 23:43:29 +0000680 /// isRelational - Return true if the predicate is relational (not EQ or NE).
681 ///
682 static bool isRelational(Predicate P) {
683 return !isEquality(P);
684 }
685
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000686 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
687 /// @brief Determine if this instruction's predicate is signed.
Chris Lattner389c9142007-09-15 06:51:03 +0000688 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689
690 /// @returns true if the predicate provided is signed, false otherwise
691 /// @brief Determine if the predicate is signed.
692 static bool isSignedPredicate(Predicate pred);
693
694 /// Initialize a set of values that all satisfy the predicate with C.
695 /// @brief Make a ConstantRange for a relation with a constant value.
696 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
697
698 /// Exchange the two operands to this instruction in such a way that it does
699 /// not modify the semantics of the instruction. The predicate value may be
700 /// changed to retain the same result if the predicate is order dependent
701 /// (e.g. ult).
702 /// @brief Swap operands and adjust predicate.
703 void swapOperands() {
704 SubclassData = getSwappedPredicate();
705 std::swap(Ops[0], Ops[1]);
706 }
707
Chris Lattner3c7088f2007-08-24 20:48:18 +0000708 virtual ICmpInst *clone() const;
709
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000710 // Methods for support type inquiry through isa, cast, and dyn_cast:
711 static inline bool classof(const ICmpInst *) { return true; }
712 static inline bool classof(const Instruction *I) {
713 return I->getOpcode() == Instruction::ICmp;
714 }
715 static inline bool classof(const Value *V) {
716 return isa<Instruction>(V) && classof(cast<Instruction>(V));
717 }
718};
719
720//===----------------------------------------------------------------------===//
721// FCmpInst Class
722//===----------------------------------------------------------------------===//
723
724/// This instruction compares its operands according to the predicate given
725/// to the constructor. It only operates on floating point values or packed
726/// vectors of floating point values. The operands must be identical types.
727/// @brief Represents a floating point comparison operator.
728class FCmpInst: public CmpInst {
729public:
730 /// This enumeration lists the possible predicates for the FCmpInst. Values
731 /// in the range 0-31 are reserved for FCmpInst.
732 enum Predicate {
733 // Opcode U L G E Intuitive operation
734 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
735 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
736 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
737 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
738 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
739 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
740 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
741 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
742 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
743 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
744 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
745 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
746 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
747 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
748 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
749 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
750 FIRST_FCMP_PREDICATE = FCMP_FALSE,
751 LAST_FCMP_PREDICATE = FCMP_TRUE,
752 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
753 };
754
755 /// @brief Constructor with insert-before-instruction semantics.
756 FCmpInst(
757 Predicate pred, ///< The predicate to use for the comparison
758 Value *LHS, ///< The left-hand-side of the expression
759 Value *RHS, ///< The right-hand-side of the expression
760 const std::string &Name = "", ///< Name of the instruction
761 Instruction *InsertBefore = 0 ///< Where to insert
762 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
763 }
764
765 /// @brief Constructor with insert-at-block-end semantics.
766 FCmpInst(
767 Predicate pred, ///< The predicate to use for the comparison
768 Value *LHS, ///< The left-hand-side of the expression
769 Value *RHS, ///< The right-hand-side of the expression
770 const std::string &Name, ///< Name of the instruction
771 BasicBlock *InsertAtEnd ///< Block to insert into.
772 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
773 }
774
775 /// @brief Return the predicate for this instruction.
776 Predicate getPredicate() const { return Predicate(SubclassData); }
777
778 /// @brief Set the predicate for this instruction to the specified value.
779 void setPredicate(Predicate P) { SubclassData = P; }
780
781 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
782 /// @returns the inverse predicate for the instructions current predicate.
783 /// @brief Return the inverse of the predicate
784 Predicate getInversePredicate() const {
785 return getInversePredicate(getPredicate());
786 }
787
788 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
789 /// @returns the inverse predicate for \p pred.
790 /// @brief Return the inverse of a given predicate
791 static Predicate getInversePredicate(Predicate pred);
792
793 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
794 /// @returns the predicate that would be the result of exchanging the two
795 /// operands of the ICmpInst instruction without changing the result
796 /// produced.
797 /// @brief Return the predicate as if the operands were swapped
798 Predicate getSwappedPredicate() const {
799 return getSwappedPredicate(getPredicate());
800 }
801
802 /// This is a static version that you can use without an instruction
803 /// available.
804 /// @brief Return the predicate as if the operands were swapped.
805 static Predicate getSwappedPredicate(Predicate Opcode);
806
807 /// This also tests for commutativity. If isEquality() returns true then
808 /// the predicate is also commutative. Only the equality predicates are
809 /// commutative.
810 /// @returns true if the predicate of this instruction is EQ or NE.
811 /// @brief Determine if this is an equality predicate.
812 bool isEquality() const {
813 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
814 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
815 }
816 bool isCommutative() const { return isEquality(); }
817
818 /// @returns true if the predicate is relational (not EQ or NE).
819 /// @brief Determine if this a relational predicate.
820 bool isRelational() const { return !isEquality(); }
821
822 /// Exchange the two operands to this instruction in such a way that it does
823 /// not modify the semantics of the instruction. The predicate value may be
824 /// changed to retain the same result if the predicate is order dependent
825 /// (e.g. ult).
826 /// @brief Swap operands and adjust predicate.
827 void swapOperands() {
828 SubclassData = getSwappedPredicate();
829 std::swap(Ops[0], Ops[1]);
830 }
831
Chris Lattner3c7088f2007-08-24 20:48:18 +0000832 virtual FCmpInst *clone() const;
833
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000834 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
835 static inline bool classof(const FCmpInst *) { return true; }
836 static inline bool classof(const Instruction *I) {
837 return I->getOpcode() == Instruction::FCmp;
838 }
839 static inline bool classof(const Value *V) {
840 return isa<Instruction>(V) && classof(cast<Instruction>(V));
841 }
842};
843
844//===----------------------------------------------------------------------===//
845// CallInst Class
846//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000847/// CallInst - This class represents a function call, abstracting a target
848/// machine's calling convention. This class uses low bit of the SubClassData
849/// field to indicate whether or not this is a tail call. The rest of the bits
850/// hold the calling convention of the call.
851///
David Greeneb1c4a7b2007-08-01 03:43:44 +0000852
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853class CallInst : public Instruction {
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000854 const ParamAttrsList *ParamAttrs; ///< parameter attributes for call
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000855 CallInst(const CallInst &CI);
856 void init(Value *Func, Value* const *Params, unsigned NumParams);
857 void init(Value *Func, Value *Actual1, Value *Actual2);
858 void init(Value *Func, Value *Actual);
859 void init(Value *Func);
860
David Greeneb1c4a7b2007-08-01 03:43:44 +0000861 template<typename InputIterator>
862 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
863 const std::string &Name,
864 // This argument ensures that we have an iterator we can
865 // do arithmetic on in constant time
866 std::random_access_iterator_tag) {
Chris Lattnerb7cbe5192007-08-29 16:32:50 +0000867 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
David Greeneb1c4a7b2007-08-01 03:43:44 +0000868
Chris Lattnerb7cbe5192007-08-29 16:32:50 +0000869 // This requires that the iterator points to contiguous memory.
870 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
David Greeneb1c4a7b2007-08-01 03:43:44 +0000871 setName(Name);
872 }
873
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000874public:
David Greeneb1c4a7b2007-08-01 03:43:44 +0000875 /// Construct a CallInst given a range of arguments. InputIterator
876 /// must be a random-access iterator pointing to contiguous storage
877 /// (e.g. a std::vector<>::iterator). Checks are made for
878 /// random-accessness but not for contiguous storage as that would
879 /// incur runtime overhead.
880 /// @brief Construct a CallInst from a range of arguments
881 template<typename InputIterator>
882 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
883 const std::string &Name = "", Instruction *InsertBefore = 0)
884 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
885 ->getElementType())->getReturnType(),
886 Instruction::Call, 0, 0, InsertBefore) {
887 init(Func, ArgBegin, ArgEnd, Name,
888 typename std::iterator_traits<InputIterator>::iterator_category());
889 }
890
891 /// Construct a CallInst given a range of arguments. InputIterator
892 /// must be a random-access iterator pointing to contiguous storage
893 /// (e.g. a std::vector<>::iterator). Checks are made for
894 /// random-accessness but not for contiguous storage as that would
895 /// incur runtime overhead.
896 /// @brief Construct a CallInst from a range of arguments
897 template<typename InputIterator>
898 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
899 const std::string &Name, BasicBlock *InsertAtEnd)
900 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
901 ->getElementType())->getReturnType(),
902 Instruction::Call, 0, 0, InsertAtEnd) {
903 init(Func, ArgBegin, ArgEnd, Name,
904 typename std::iterator_traits<InputIterator>::iterator_category());
905 }
906
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000907 CallInst(Value *F, Value *Actual, const std::string& Name = "",
908 Instruction *InsertBefore = 0);
909 CallInst(Value *F, Value *Actual, const std::string& Name,
910 BasicBlock *InsertAtEnd);
911 explicit CallInst(Value *F, const std::string &Name = "",
912 Instruction *InsertBefore = 0);
913 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
Gordon Henriksenc8ddfa62007-12-10 02:14:30 +0000914 ~CallInst();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000915
916 virtual CallInst *clone() const;
917
918 bool isTailCall() const { return SubclassData & 1; }
919 void setTailCall(bool isTailCall = true) {
920 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
921 }
922
923 /// getCallingConv/setCallingConv - Get or set the calling convention of this
924 /// function call.
925 unsigned getCallingConv() const { return SubclassData >> 1; }
926 void setCallingConv(unsigned CC) {
927 SubclassData = (SubclassData & 1) | (CC << 1);
928 }
929
930 /// Obtains a pointer to the ParamAttrsList object which holds the
931 /// parameter attributes information, if any.
932 /// @returns 0 if no attributes have been set.
933 /// @brief Get the parameter attributes.
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000934 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000935
936 /// Sets the parameter attributes for this CallInst. To construct a
937 /// ParamAttrsList, see ParameterAttributes.h
938 /// @brief Set the parameter attributes.
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000939 void setParamAttrs(const ParamAttrsList *attrs);
940
Duncan Sands637ec552007-11-28 17:07:01 +0000941 /// @brief Determine whether the call or the callee has the given attribute.
Chris Lattneref5d8a22008-01-02 23:42:30 +0000942 bool paramHasAttr(uint16_t i, unsigned attr) const;
Duncan Sands637ec552007-11-28 17:07:01 +0000943
Duncan Sands79d28872007-12-03 20:06:50 +0000944 /// @brief Determine if the call does not access memory.
Chris Lattneref5d8a22008-01-02 23:42:30 +0000945 bool doesNotAccessMemory() const;
946
Duncan Sands79d28872007-12-03 20:06:50 +0000947 /// @brief Determine if the call does not access or only reads memory.
Chris Lattneref5d8a22008-01-02 23:42:30 +0000948 bool onlyReadsMemory() const;
949
Duncan Sands7f511cf2007-12-10 19:09:40 +0000950 /// @brief Determine if the call cannot return.
Chris Lattneref5d8a22008-01-02 23:42:30 +0000951 bool doesNotReturn() const;
Duncan Sands7f511cf2007-12-10 19:09:40 +0000952
Duncan Sands79d28872007-12-03 20:06:50 +0000953 /// @brief Determine if the call cannot unwind.
Chris Lattneref5d8a22008-01-02 23:42:30 +0000954 bool doesNotThrow() const;
Duncan Sands2937e352007-12-19 21:13:37 +0000955 void setDoesNotThrow(bool doesNotThrow = true);
Duncan Sands79d28872007-12-03 20:06:50 +0000956
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000957 /// @brief Determine if the call returns a structure.
Chris Lattneref5d8a22008-01-02 23:42:30 +0000958 bool isStructReturn() const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000959
Evan Chengde867962008-01-12 18:57:32 +0000960 /// @brief Determine if any call argument is an aggregate passed by value.
961 bool hasByValArgument() const;
962
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963 /// getCalledFunction - Return the function being called by this instruction
964 /// if it is a direct call. If it is a call through a function pointer,
965 /// return null.
966 Function *getCalledFunction() const {
Dan Gohman4039bd22007-09-24 15:46:02 +0000967 return dyn_cast<Function>(getOperand(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000968 }
969
970 /// getCalledValue - Get a pointer to the function that is invoked by this
971 /// instruction
972 inline const Value *getCalledValue() const { return getOperand(0); }
973 inline Value *getCalledValue() { return getOperand(0); }
974
975 // Methods for support type inquiry through isa, cast, and dyn_cast:
976 static inline bool classof(const CallInst *) { return true; }
977 static inline bool classof(const Instruction *I) {
978 return I->getOpcode() == Instruction::Call;
979 }
980 static inline bool classof(const Value *V) {
981 return isa<Instruction>(V) && classof(cast<Instruction>(V));
982 }
983};
984
985//===----------------------------------------------------------------------===//
986// SelectInst Class
987//===----------------------------------------------------------------------===//
988
989/// SelectInst - This class represents the LLVM 'select' instruction.
990///
991class SelectInst : public Instruction {
992 Use Ops[3];
993
994 void init(Value *C, Value *S1, Value *S2) {
995 Ops[0].init(C, this);
996 Ops[1].init(S1, this);
997 Ops[2].init(S2, this);
998 }
999
1000 SelectInst(const SelectInst &SI)
1001 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
1002 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
1003 }
1004public:
1005 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
1006 Instruction *InsertBefore = 0)
1007 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
1008 init(C, S1, S2);
1009 setName(Name);
1010 }
1011 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1012 BasicBlock *InsertAtEnd)
1013 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
1014 init(C, S1, S2);
1015 setName(Name);
1016 }
1017
1018 Value *getCondition() const { return Ops[0]; }
1019 Value *getTrueValue() const { return Ops[1]; }
1020 Value *getFalseValue() const { return Ops[2]; }
1021
1022 /// Transparently provide more efficient getOperand methods.
1023 Value *getOperand(unsigned i) const {
1024 assert(i < 3 && "getOperand() out of range!");
1025 return Ops[i];
1026 }
1027 void setOperand(unsigned i, Value *Val) {
1028 assert(i < 3 && "setOperand() out of range!");
1029 Ops[i] = Val;
1030 }
1031 unsigned getNumOperands() const { return 3; }
1032
1033 OtherOps getOpcode() const {
1034 return static_cast<OtherOps>(Instruction::getOpcode());
1035 }
1036
1037 virtual SelectInst *clone() const;
1038
1039 // Methods for support type inquiry through isa, cast, and dyn_cast:
1040 static inline bool classof(const SelectInst *) { return true; }
1041 static inline bool classof(const Instruction *I) {
1042 return I->getOpcode() == Instruction::Select;
1043 }
1044 static inline bool classof(const Value *V) {
1045 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1046 }
1047};
1048
1049//===----------------------------------------------------------------------===//
1050// VAArgInst Class
1051//===----------------------------------------------------------------------===//
1052
1053/// VAArgInst - This class represents the va_arg llvm instruction, which returns
1054/// an argument of the specified type given a va_list and increments that list
1055///
1056class VAArgInst : public UnaryInstruction {
1057 VAArgInst(const VAArgInst &VAA)
1058 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1059public:
1060 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1061 Instruction *InsertBefore = 0)
1062 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1063 setName(Name);
1064 }
1065 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1066 BasicBlock *InsertAtEnd)
1067 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1068 setName(Name);
1069 }
1070
1071 virtual VAArgInst *clone() const;
1072
1073 // Methods for support type inquiry through isa, cast, and dyn_cast:
1074 static inline bool classof(const VAArgInst *) { return true; }
1075 static inline bool classof(const Instruction *I) {
1076 return I->getOpcode() == VAArg;
1077 }
1078 static inline bool classof(const Value *V) {
1079 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1080 }
1081};
1082
1083//===----------------------------------------------------------------------===//
1084// ExtractElementInst Class
1085//===----------------------------------------------------------------------===//
1086
1087/// ExtractElementInst - This instruction extracts a single (scalar)
1088/// element from a VectorType value
1089///
1090class ExtractElementInst : public Instruction {
1091 Use Ops[2];
1092 ExtractElementInst(const ExtractElementInst &EE) :
1093 Instruction(EE.getType(), ExtractElement, Ops, 2) {
1094 Ops[0].init(EE.Ops[0], this);
1095 Ops[1].init(EE.Ops[1], this);
1096 }
1097
1098public:
1099 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1100 Instruction *InsertBefore = 0);
1101 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1102 Instruction *InsertBefore = 0);
1103 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1104 BasicBlock *InsertAtEnd);
1105 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1106 BasicBlock *InsertAtEnd);
1107
1108 /// isValidOperands - Return true if an extractelement instruction can be
1109 /// formed with the specified operands.
1110 static bool isValidOperands(const Value *Vec, const Value *Idx);
1111
1112 virtual ExtractElementInst *clone() const;
1113
1114 /// Transparently provide more efficient getOperand methods.
1115 Value *getOperand(unsigned i) const {
1116 assert(i < 2 && "getOperand() out of range!");
1117 return Ops[i];
1118 }
1119 void setOperand(unsigned i, Value *Val) {
1120 assert(i < 2 && "setOperand() out of range!");
1121 Ops[i] = Val;
1122 }
1123 unsigned getNumOperands() const { return 2; }
1124
1125 // Methods for support type inquiry through isa, cast, and dyn_cast:
1126 static inline bool classof(const ExtractElementInst *) { return true; }
1127 static inline bool classof(const Instruction *I) {
1128 return I->getOpcode() == Instruction::ExtractElement;
1129 }
1130 static inline bool classof(const Value *V) {
1131 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1132 }
1133};
1134
1135//===----------------------------------------------------------------------===//
1136// InsertElementInst Class
1137//===----------------------------------------------------------------------===//
1138
1139/// InsertElementInst - This instruction inserts a single (scalar)
1140/// element into a VectorType value
1141///
1142class InsertElementInst : public Instruction {
1143 Use Ops[3];
1144 InsertElementInst(const InsertElementInst &IE);
1145public:
1146 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1147 const std::string &Name = "",Instruction *InsertBefore = 0);
1148 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1149 const std::string &Name = "",Instruction *InsertBefore = 0);
1150 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1151 const std::string &Name, BasicBlock *InsertAtEnd);
1152 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1153 const std::string &Name, BasicBlock *InsertAtEnd);
1154
1155 /// isValidOperands - Return true if an insertelement instruction can be
1156 /// formed with the specified operands.
1157 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1158 const Value *Idx);
1159
1160 virtual InsertElementInst *clone() const;
1161
1162 /// getType - Overload to return most specific vector type.
1163 ///
1164 inline const VectorType *getType() const {
1165 return reinterpret_cast<const VectorType*>(Instruction::getType());
1166 }
1167
1168 /// Transparently provide more efficient getOperand methods.
1169 Value *getOperand(unsigned i) const {
1170 assert(i < 3 && "getOperand() out of range!");
1171 return Ops[i];
1172 }
1173 void setOperand(unsigned i, Value *Val) {
1174 assert(i < 3 && "setOperand() out of range!");
1175 Ops[i] = Val;
1176 }
1177 unsigned getNumOperands() const { return 3; }
1178
1179 // Methods for support type inquiry through isa, cast, and dyn_cast:
1180 static inline bool classof(const InsertElementInst *) { return true; }
1181 static inline bool classof(const Instruction *I) {
1182 return I->getOpcode() == Instruction::InsertElement;
1183 }
1184 static inline bool classof(const Value *V) {
1185 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1186 }
1187};
1188
1189//===----------------------------------------------------------------------===//
1190// ShuffleVectorInst Class
1191//===----------------------------------------------------------------------===//
1192
1193/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1194/// input vectors.
1195///
1196class ShuffleVectorInst : public Instruction {
1197 Use Ops[3];
1198 ShuffleVectorInst(const ShuffleVectorInst &IE);
1199public:
1200 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1201 const std::string &Name = "", Instruction *InsertBefor = 0);
1202 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1203 const std::string &Name, BasicBlock *InsertAtEnd);
1204
1205 /// isValidOperands - Return true if a shufflevector instruction can be
1206 /// formed with the specified operands.
1207 static bool isValidOperands(const Value *V1, const Value *V2,
1208 const Value *Mask);
1209
1210 virtual ShuffleVectorInst *clone() const;
1211
1212 /// getType - Overload to return most specific vector type.
1213 ///
1214 inline const VectorType *getType() const {
1215 return reinterpret_cast<const VectorType*>(Instruction::getType());
1216 }
1217
1218 /// Transparently provide more efficient getOperand methods.
1219 Value *getOperand(unsigned i) const {
1220 assert(i < 3 && "getOperand() out of range!");
1221 return Ops[i];
1222 }
1223 void setOperand(unsigned i, Value *Val) {
1224 assert(i < 3 && "setOperand() out of range!");
1225 Ops[i] = Val;
1226 }
1227 unsigned getNumOperands() const { return 3; }
1228
1229 // Methods for support type inquiry through isa, cast, and dyn_cast:
1230 static inline bool classof(const ShuffleVectorInst *) { return true; }
1231 static inline bool classof(const Instruction *I) {
1232 return I->getOpcode() == Instruction::ShuffleVector;
1233 }
1234 static inline bool classof(const Value *V) {
1235 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1236 }
1237};
1238
1239
1240//===----------------------------------------------------------------------===//
1241// PHINode Class
1242//===----------------------------------------------------------------------===//
1243
1244// PHINode - The PHINode class is used to represent the magical mystical PHI
1245// node, that can not exist in nature, but can be synthesized in a computer
1246// scientist's overactive imagination.
1247//
1248class PHINode : public Instruction {
1249 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1250 /// the number actually in use.
1251 unsigned ReservedSpace;
1252 PHINode(const PHINode &PN);
1253public:
1254 explicit PHINode(const Type *Ty, const std::string &Name = "",
1255 Instruction *InsertBefore = 0)
1256 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1257 ReservedSpace(0) {
1258 setName(Name);
1259 }
1260
1261 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1262 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1263 ReservedSpace(0) {
1264 setName(Name);
1265 }
1266
Gordon Henriksenc8ddfa62007-12-10 02:14:30 +00001267 ~PHINode();
1268
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001269 /// reserveOperandSpace - This method can be used to avoid repeated
1270 /// reallocation of PHI operand lists by reserving space for the correct
1271 /// number of operands before adding them. Unlike normal vector reserves,
1272 /// this method can also be used to trim the operand space.
1273 void reserveOperandSpace(unsigned NumValues) {
1274 resizeOperands(NumValues*2);
1275 }
1276
1277 virtual PHINode *clone() const;
1278
1279 /// getNumIncomingValues - Return the number of incoming edges
1280 ///
1281 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1282
1283 /// getIncomingValue - Return incoming value number x
1284 ///
1285 Value *getIncomingValue(unsigned i) const {
1286 assert(i*2 < getNumOperands() && "Invalid value number!");
1287 return getOperand(i*2);
1288 }
1289 void setIncomingValue(unsigned i, Value *V) {
1290 assert(i*2 < getNumOperands() && "Invalid value number!");
1291 setOperand(i*2, V);
1292 }
1293 unsigned getOperandNumForIncomingValue(unsigned i) {
1294 return i*2;
1295 }
1296
1297 /// getIncomingBlock - Return incoming basic block number x
1298 ///
1299 BasicBlock *getIncomingBlock(unsigned i) const {
1300 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1301 }
1302 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1303 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1304 }
1305 unsigned getOperandNumForIncomingBlock(unsigned i) {
1306 return i*2+1;
1307 }
1308
1309 /// addIncoming - Add an incoming value to the end of the PHI list
1310 ///
1311 void addIncoming(Value *V, BasicBlock *BB) {
1312 assert(getType() == V->getType() &&
1313 "All operands to PHI node must be the same type as the PHI node!");
1314 unsigned OpNo = NumOperands;
1315 if (OpNo+2 > ReservedSpace)
1316 resizeOperands(0); // Get more space!
1317 // Initialize some new operands.
1318 NumOperands = OpNo+2;
1319 OperandList[OpNo].init(V, this);
1320 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1321 }
1322
1323 /// removeIncomingValue - Remove an incoming value. This is useful if a
1324 /// predecessor basic block is deleted. The value removed is returned.
1325 ///
1326 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1327 /// is true), the PHI node is destroyed and any uses of it are replaced with
1328 /// dummy values. The only time there should be zero incoming values to a PHI
1329 /// node is when the block is dead, so this strategy is sound.
1330 ///
1331 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1332
1333 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1334 int Idx = getBasicBlockIndex(BB);
1335 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1336 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1337 }
1338
1339 /// getBasicBlockIndex - Return the first index of the specified basic
1340 /// block in the value list for this PHI. Returns -1 if no instance.
1341 ///
1342 int getBasicBlockIndex(const BasicBlock *BB) const {
1343 Use *OL = OperandList;
1344 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1345 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1346 return -1;
1347 }
1348
1349 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1350 return getIncomingValue(getBasicBlockIndex(BB));
1351 }
1352
1353 /// hasConstantValue - If the specified PHI node always merges together the
1354 /// same value, return the value, otherwise return null.
1355 ///
1356 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1357
1358 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1359 static inline bool classof(const PHINode *) { return true; }
1360 static inline bool classof(const Instruction *I) {
1361 return I->getOpcode() == Instruction::PHI;
1362 }
1363 static inline bool classof(const Value *V) {
1364 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1365 }
1366 private:
1367 void resizeOperands(unsigned NumOperands);
1368};
1369
1370//===----------------------------------------------------------------------===//
1371// ReturnInst Class
1372//===----------------------------------------------------------------------===//
1373
1374//===---------------------------------------------------------------------------
1375/// ReturnInst - Return a value (possibly void), from a function. Execution
1376/// does not continue in this function any longer.
1377///
1378class ReturnInst : public TerminatorInst {
1379 Use RetVal; // Return Value: null if 'void'.
1380 ReturnInst(const ReturnInst &RI);
1381 void init(Value *RetVal);
1382
1383public:
1384 // ReturnInst constructors:
1385 // ReturnInst() - 'ret void' instruction
1386 // ReturnInst( null) - 'ret void' instruction
1387 // ReturnInst(Value* X) - 'ret X' instruction
1388 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1389 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1390 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1391 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1392 //
1393 // NOTE: If the Value* passed is of type void then the constructor behaves as
1394 // if it was passed NULL.
1395 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1396 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1397 explicit ReturnInst(BasicBlock *InsertAtEnd);
1398
1399 virtual ReturnInst *clone() const;
1400
1401 // Transparently provide more efficient getOperand methods.
1402 Value *getOperand(unsigned i) const {
1403 assert(i < getNumOperands() && "getOperand() out of range!");
1404 return RetVal;
1405 }
1406 void setOperand(unsigned i, Value *Val) {
1407 assert(i < getNumOperands() && "setOperand() out of range!");
1408 RetVal = Val;
1409 }
1410
1411 Value *getReturnValue() const { return RetVal; }
1412
1413 unsigned getNumSuccessors() const { return 0; }
1414
1415 // Methods for support type inquiry through isa, cast, and dyn_cast:
1416 static inline bool classof(const ReturnInst *) { return true; }
1417 static inline bool classof(const Instruction *I) {
1418 return (I->getOpcode() == Instruction::Ret);
1419 }
1420 static inline bool classof(const Value *V) {
1421 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1422 }
1423 private:
1424 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1425 virtual unsigned getNumSuccessorsV() const;
1426 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1427};
1428
1429//===----------------------------------------------------------------------===//
1430// BranchInst Class
1431//===----------------------------------------------------------------------===//
1432
1433//===---------------------------------------------------------------------------
1434/// BranchInst - Conditional or Unconditional Branch instruction.
1435///
1436class BranchInst : public TerminatorInst {
1437 /// Ops list - Branches are strange. The operands are ordered:
1438 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1439 /// they don't have to check for cond/uncond branchness.
1440 Use Ops[3];
1441 BranchInst(const BranchInst &BI);
1442 void AssertOK();
1443public:
1444 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1445 // BranchInst(BB *B) - 'br B'
1446 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1447 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1448 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1449 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1450 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1451 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1452 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1453 Instruction *InsertBefore = 0);
1454 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1455 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1456 BasicBlock *InsertAtEnd);
1457
1458 /// Transparently provide more efficient getOperand methods.
1459 Value *getOperand(unsigned i) const {
1460 assert(i < getNumOperands() && "getOperand() out of range!");
1461 return Ops[i];
1462 }
1463 void setOperand(unsigned i, Value *Val) {
1464 assert(i < getNumOperands() && "setOperand() out of range!");
1465 Ops[i] = Val;
1466 }
1467
1468 virtual BranchInst *clone() const;
1469
1470 inline bool isUnconditional() const { return getNumOperands() == 1; }
1471 inline bool isConditional() const { return getNumOperands() == 3; }
1472
1473 inline Value *getCondition() const {
1474 assert(isConditional() && "Cannot get condition of an uncond branch!");
1475 return getOperand(2);
1476 }
1477
1478 void setCondition(Value *V) {
1479 assert(isConditional() && "Cannot set condition of unconditional branch!");
1480 setOperand(2, V);
1481 }
1482
1483 // setUnconditionalDest - Change the current branch to an unconditional branch
1484 // targeting the specified block.
1485 // FIXME: Eliminate this ugly method.
1486 void setUnconditionalDest(BasicBlock *Dest) {
1487 if (isConditional()) { // Convert this to an uncond branch.
1488 NumOperands = 1;
1489 Ops[1].set(0);
1490 Ops[2].set(0);
1491 }
1492 setOperand(0, reinterpret_cast<Value*>(Dest));
1493 }
1494
1495 unsigned getNumSuccessors() const { return 1+isConditional(); }
1496
1497 BasicBlock *getSuccessor(unsigned i) const {
1498 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1499 return cast<BasicBlock>(getOperand(i));
1500 }
1501
1502 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1503 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1504 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1505 }
1506
1507 // Methods for support type inquiry through isa, cast, and dyn_cast:
1508 static inline bool classof(const BranchInst *) { return true; }
1509 static inline bool classof(const Instruction *I) {
1510 return (I->getOpcode() == Instruction::Br);
1511 }
1512 static inline bool classof(const Value *V) {
1513 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1514 }
1515private:
1516 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1517 virtual unsigned getNumSuccessorsV() const;
1518 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1519};
1520
1521//===----------------------------------------------------------------------===//
1522// SwitchInst Class
1523//===----------------------------------------------------------------------===//
1524
1525//===---------------------------------------------------------------------------
1526/// SwitchInst - Multiway switch
1527///
1528class SwitchInst : public TerminatorInst {
1529 unsigned ReservedSpace;
1530 // Operand[0] = Value to switch on
1531 // Operand[1] = Default basic block destination
1532 // Operand[2n ] = Value to match
1533 // Operand[2n+1] = BasicBlock to go to on match
1534 SwitchInst(const SwitchInst &RI);
1535 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1536 void resizeOperands(unsigned No);
1537public:
1538 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1539 /// switch on and a default destination. The number of additional cases can
1540 /// be specified here to make memory allocation more efficient. This
1541 /// constructor can also autoinsert before another instruction.
1542 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1543 Instruction *InsertBefore = 0);
1544
1545 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1546 /// switch on and a default destination. The number of additional cases can
1547 /// be specified here to make memory allocation more efficient. This
1548 /// constructor also autoinserts at the end of the specified BasicBlock.
1549 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1550 BasicBlock *InsertAtEnd);
Gordon Henriksenc8ddfa62007-12-10 02:14:30 +00001551 ~SwitchInst();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001552
1553
1554 // Accessor Methods for Switch stmt
1555 inline Value *getCondition() const { return getOperand(0); }
1556 void setCondition(Value *V) { setOperand(0, V); }
1557
1558 inline BasicBlock *getDefaultDest() const {
1559 return cast<BasicBlock>(getOperand(1));
1560 }
1561
1562 /// getNumCases - return the number of 'cases' in this switch instruction.
1563 /// Note that case #0 is always the default case.
1564 unsigned getNumCases() const {
1565 return getNumOperands()/2;
1566 }
1567
1568 /// getCaseValue - Return the specified case value. Note that case #0, the
1569 /// default destination, does not have a case value.
1570 ConstantInt *getCaseValue(unsigned i) {
1571 assert(i && i < getNumCases() && "Illegal case value to get!");
1572 return getSuccessorValue(i);
1573 }
1574
1575 /// getCaseValue - Return the specified case value. Note that case #0, the
1576 /// default destination, does not have a case value.
1577 const ConstantInt *getCaseValue(unsigned i) const {
1578 assert(i && i < getNumCases() && "Illegal case value to get!");
1579 return getSuccessorValue(i);
1580 }
1581
1582 /// findCaseValue - Search all of the case values for the specified constant.
1583 /// If it is explicitly handled, return the case number of it, otherwise
1584 /// return 0 to indicate that it is handled by the default handler.
1585 unsigned findCaseValue(const ConstantInt *C) const {
1586 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1587 if (getCaseValue(i) == C)
1588 return i;
1589 return 0;
1590 }
1591
1592 /// findCaseDest - Finds the unique case value for a given successor. Returns
1593 /// null if the successor is not found, not unique, or is the default case.
1594 ConstantInt *findCaseDest(BasicBlock *BB) {
1595 if (BB == getDefaultDest()) return NULL;
1596
1597 ConstantInt *CI = NULL;
1598 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1599 if (getSuccessor(i) == BB) {
1600 if (CI) return NULL; // Multiple cases lead to BB.
1601 else CI = getCaseValue(i);
1602 }
1603 }
1604 return CI;
1605 }
1606
1607 /// addCase - Add an entry to the switch instruction...
1608 ///
1609 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1610
1611 /// removeCase - This method removes the specified successor from the switch
1612 /// instruction. Note that this cannot be used to remove the default
1613 /// destination (successor #0).
1614 ///
1615 void removeCase(unsigned idx);
1616
1617 virtual SwitchInst *clone() const;
1618
1619 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1620 BasicBlock *getSuccessor(unsigned idx) const {
1621 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1622 return cast<BasicBlock>(getOperand(idx*2+1));
1623 }
1624 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1625 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1626 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1627 }
1628
1629 // getSuccessorValue - Return the value associated with the specified
1630 // successor.
1631 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1632 assert(idx < getNumSuccessors() && "Successor # out of range!");
1633 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1634 }
1635
1636 // Methods for support type inquiry through isa, cast, and dyn_cast:
1637 static inline bool classof(const SwitchInst *) { return true; }
1638 static inline bool classof(const Instruction *I) {
1639 return I->getOpcode() == Instruction::Switch;
1640 }
1641 static inline bool classof(const Value *V) {
1642 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1643 }
1644private:
1645 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1646 virtual unsigned getNumSuccessorsV() const;
1647 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1648};
1649
1650//===----------------------------------------------------------------------===//
1651// InvokeInst Class
1652//===----------------------------------------------------------------------===//
1653
1654//===---------------------------------------------------------------------------
1655
1656/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1657/// calling convention of the call.
1658///
1659class InvokeInst : public TerminatorInst {
Duncan Sandsf5588dc2007-11-27 13:23:08 +00001660 const ParamAttrsList *ParamAttrs;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001661 InvokeInst(const InvokeInst &BI);
1662 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1663 Value* const *Args, unsigned NumArgs);
David Greene8278ef52007-08-27 19:04:21 +00001664
1665 template<typename InputIterator>
1666 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1667 InputIterator ArgBegin, InputIterator ArgEnd,
1668 const std::string &Name,
1669 // This argument ensures that we have an iterator we can
1670 // do arithmetic on in constant time
1671 std::random_access_iterator_tag) {
Chris Lattnerb7cbe5192007-08-29 16:32:50 +00001672 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
David Greene8278ef52007-08-27 19:04:21 +00001673
Chris Lattnerb7cbe5192007-08-29 16:32:50 +00001674 // This requires that the iterator points to contiguous memory.
1675 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
David Greene8278ef52007-08-27 19:04:21 +00001676 setName(Name);
1677 }
1678
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001679public:
David Greene8278ef52007-08-27 19:04:21 +00001680 /// Construct an InvokeInst given a range of arguments.
1681 /// InputIterator must be a random-access iterator pointing to
1682 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1683 /// made for random-accessness but not for contiguous storage as
1684 /// that would incur runtime overhead.
1685 ///
1686 /// @brief Construct an InvokeInst from a range of arguments
1687 template<typename InputIterator>
1688 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1689 InputIterator ArgBegin, InputIterator ArgEnd,
1690 const std::string &Name = "", Instruction *InsertBefore = 0)
1691 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1692 ->getElementType())->getReturnType(),
1693 Instruction::Invoke, 0, 0, InsertBefore) {
1694 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1695 typename std::iterator_traits<InputIterator>::iterator_category());
1696 }
1697
1698 /// Construct an InvokeInst given a range of arguments.
1699 /// InputIterator must be a random-access iterator pointing to
1700 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1701 /// made for random-accessness but not for contiguous storage as
1702 /// that would incur runtime overhead.
1703 ///
1704 /// @brief Construct an InvokeInst from a range of arguments
1705 template<typename InputIterator>
1706 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1707 InputIterator ArgBegin, InputIterator ArgEnd,
1708 const std::string &Name, BasicBlock *InsertAtEnd)
1709 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1710 ->getElementType())->getReturnType(),
1711 Instruction::Invoke, 0, 0, InsertAtEnd) {
1712 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1713 typename std::iterator_traits<InputIterator>::iterator_category());
1714 }
1715
Gordon Henriksenc8ddfa62007-12-10 02:14:30 +00001716 ~InvokeInst();
1717
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001718 virtual InvokeInst *clone() const;
1719
1720 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1721 /// function call.
1722 unsigned getCallingConv() const { return SubclassData; }
1723 void setCallingConv(unsigned CC) {
1724 SubclassData = CC;
1725 }
1726
1727 /// Obtains a pointer to the ParamAttrsList object which holds the
1728 /// parameter attributes information, if any.
1729 /// @returns 0 if no attributes have been set.
1730 /// @brief Get the parameter attributes.
Duncan Sandsf5588dc2007-11-27 13:23:08 +00001731 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001732
1733 /// Sets the parameter attributes for this InvokeInst. To construct a
1734 /// ParamAttrsList, see ParameterAttributes.h
1735 /// @brief Set the parameter attributes.
Duncan Sandsf5588dc2007-11-27 13:23:08 +00001736 void setParamAttrs(const ParamAttrsList *attrs);
1737
Duncan Sands637ec552007-11-28 17:07:01 +00001738 /// @brief Determine whether the call or the callee has the given attribute.
Dale Johannesenf4666f52008-02-19 21:38:47 +00001739 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
Duncan Sands637ec552007-11-28 17:07:01 +00001740
Duncan Sands79d28872007-12-03 20:06:50 +00001741 /// @brief Determine if the call does not access memory.
Chris Lattneref5d8a22008-01-02 23:42:30 +00001742 bool doesNotAccessMemory() const;
Duncan Sands79d28872007-12-03 20:06:50 +00001743
1744 /// @brief Determine if the call does not access or only reads memory.
Chris Lattneref5d8a22008-01-02 23:42:30 +00001745 bool onlyReadsMemory() const;
Duncan Sands79d28872007-12-03 20:06:50 +00001746
Duncan Sands7f511cf2007-12-10 19:09:40 +00001747 /// @brief Determine if the call cannot return.
Chris Lattneref5d8a22008-01-02 23:42:30 +00001748 bool doesNotReturn() const;
Duncan Sands7f511cf2007-12-10 19:09:40 +00001749
Duncan Sands79d28872007-12-03 20:06:50 +00001750 /// @brief Determine if the call cannot unwind.
Chris Lattneref5d8a22008-01-02 23:42:30 +00001751 bool doesNotThrow() const;
Duncan Sands2937e352007-12-19 21:13:37 +00001752 void setDoesNotThrow(bool doesNotThrow = true);
Duncan Sands79d28872007-12-03 20:06:50 +00001753
Duncan Sandsf5588dc2007-11-27 13:23:08 +00001754 /// @brief Determine if the call returns a structure.
Chris Lattneref5d8a22008-01-02 23:42:30 +00001755 bool isStructReturn() const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001756
1757 /// getCalledFunction - Return the function called, or null if this is an
1758 /// indirect function invocation.
1759 ///
1760 Function *getCalledFunction() const {
1761 return dyn_cast<Function>(getOperand(0));
1762 }
1763
1764 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1765 inline Value *getCalledValue() const { return getOperand(0); }
1766
1767 // get*Dest - Return the destination basic blocks...
1768 BasicBlock *getNormalDest() const {
1769 return cast<BasicBlock>(getOperand(1));
1770 }
1771 BasicBlock *getUnwindDest() const {
1772 return cast<BasicBlock>(getOperand(2));
1773 }
1774 void setNormalDest(BasicBlock *B) {
1775 setOperand(1, reinterpret_cast<Value*>(B));
1776 }
1777
1778 void setUnwindDest(BasicBlock *B) {
1779 setOperand(2, reinterpret_cast<Value*>(B));
1780 }
1781
1782 inline BasicBlock *getSuccessor(unsigned i) const {
1783 assert(i < 2 && "Successor # out of range for invoke!");
1784 return i == 0 ? getNormalDest() : getUnwindDest();
1785 }
1786
1787 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1788 assert(idx < 2 && "Successor # out of range for invoke!");
1789 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1790 }
1791
1792 unsigned getNumSuccessors() const { return 2; }
1793
1794 // Methods for support type inquiry through isa, cast, and dyn_cast:
1795 static inline bool classof(const InvokeInst *) { return true; }
1796 static inline bool classof(const Instruction *I) {
1797 return (I->getOpcode() == Instruction::Invoke);
1798 }
1799 static inline bool classof(const Value *V) {
1800 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1801 }
1802private:
1803 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1804 virtual unsigned getNumSuccessorsV() const;
1805 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1806};
1807
1808
1809//===----------------------------------------------------------------------===//
1810// UnwindInst Class
1811//===----------------------------------------------------------------------===//
1812
1813//===---------------------------------------------------------------------------
1814/// UnwindInst - Immediately exit the current function, unwinding the stack
1815/// until an invoke instruction is found.
1816///
1817class UnwindInst : public TerminatorInst {
1818public:
1819 explicit UnwindInst(Instruction *InsertBefore = 0);
1820 explicit UnwindInst(BasicBlock *InsertAtEnd);
1821
1822 virtual UnwindInst *clone() const;
1823
1824 unsigned getNumSuccessors() const { return 0; }
1825
1826 // Methods for support type inquiry through isa, cast, and dyn_cast:
1827 static inline bool classof(const UnwindInst *) { return true; }
1828 static inline bool classof(const Instruction *I) {
1829 return I->getOpcode() == Instruction::Unwind;
1830 }
1831 static inline bool classof(const Value *V) {
1832 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1833 }
1834private:
1835 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1836 virtual unsigned getNumSuccessorsV() const;
1837 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1838};
1839
1840//===----------------------------------------------------------------------===//
1841// UnreachableInst Class
1842//===----------------------------------------------------------------------===//
1843
1844//===---------------------------------------------------------------------------
1845/// UnreachableInst - This function has undefined behavior. In particular, the
1846/// presence of this instruction indicates some higher level knowledge that the
1847/// end of the block cannot be reached.
1848///
1849class UnreachableInst : public TerminatorInst {
1850public:
1851 explicit UnreachableInst(Instruction *InsertBefore = 0);
1852 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1853
1854 virtual UnreachableInst *clone() const;
1855
1856 unsigned getNumSuccessors() const { return 0; }
1857
1858 // Methods for support type inquiry through isa, cast, and dyn_cast:
1859 static inline bool classof(const UnreachableInst *) { return true; }
1860 static inline bool classof(const Instruction *I) {
1861 return I->getOpcode() == Instruction::Unreachable;
1862 }
1863 static inline bool classof(const Value *V) {
1864 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1865 }
1866private:
1867 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1868 virtual unsigned getNumSuccessorsV() const;
1869 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1870};
1871
1872//===----------------------------------------------------------------------===//
1873// TruncInst Class
1874//===----------------------------------------------------------------------===//
1875
1876/// @brief This class represents a truncation of integer types.
1877class TruncInst : public CastInst {
1878 /// Private copy constructor
1879 TruncInst(const TruncInst &CI)
1880 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1881 }
1882public:
1883 /// @brief Constructor with insert-before-instruction semantics
1884 TruncInst(
1885 Value *S, ///< The value to be truncated
1886 const Type *Ty, ///< The (smaller) type to truncate to
1887 const std::string &Name = "", ///< A name for the new instruction
1888 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1889 );
1890
1891 /// @brief Constructor with insert-at-end-of-block semantics
1892 TruncInst(
1893 Value *S, ///< The value to be truncated
1894 const Type *Ty, ///< The (smaller) type to truncate to
1895 const std::string &Name, ///< A name for the new instruction
1896 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1897 );
1898
1899 /// @brief Clone an identical TruncInst
1900 virtual CastInst *clone() const;
1901
1902 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1903 static inline bool classof(const TruncInst *) { return true; }
1904 static inline bool classof(const Instruction *I) {
1905 return I->getOpcode() == Trunc;
1906 }
1907 static inline bool classof(const Value *V) {
1908 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1909 }
1910};
1911
1912//===----------------------------------------------------------------------===//
1913// ZExtInst Class
1914//===----------------------------------------------------------------------===//
1915
1916/// @brief This class represents zero extension of integer types.
1917class ZExtInst : public CastInst {
1918 /// @brief Private copy constructor
1919 ZExtInst(const ZExtInst &CI)
1920 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1921 }
1922public:
1923 /// @brief Constructor with insert-before-instruction semantics
1924 ZExtInst(
1925 Value *S, ///< The value to be zero extended
1926 const Type *Ty, ///< The type to zero extend to
1927 const std::string &Name = "", ///< A name for the new instruction
1928 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1929 );
1930
1931 /// @brief Constructor with insert-at-end semantics.
1932 ZExtInst(
1933 Value *S, ///< The value to be zero extended
1934 const Type *Ty, ///< The type to zero extend to
1935 const std::string &Name, ///< A name for the new instruction
1936 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1937 );
1938
1939 /// @brief Clone an identical ZExtInst
1940 virtual CastInst *clone() const;
1941
1942 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1943 static inline bool classof(const ZExtInst *) { return true; }
1944 static inline bool classof(const Instruction *I) {
1945 return I->getOpcode() == ZExt;
1946 }
1947 static inline bool classof(const Value *V) {
1948 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1949 }
1950};
1951
1952//===----------------------------------------------------------------------===//
1953// SExtInst Class
1954//===----------------------------------------------------------------------===//
1955
1956/// @brief This class represents a sign extension of integer types.
1957class SExtInst : public CastInst {
1958 /// @brief Private copy constructor
1959 SExtInst(const SExtInst &CI)
1960 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1961 }
1962public:
1963 /// @brief Constructor with insert-before-instruction semantics
1964 SExtInst(
1965 Value *S, ///< The value to be sign extended
1966 const Type *Ty, ///< The type to sign extend to
1967 const std::string &Name = "", ///< A name for the new instruction
1968 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1969 );
1970
1971 /// @brief Constructor with insert-at-end-of-block semantics
1972 SExtInst(
1973 Value *S, ///< The value to be sign extended
1974 const Type *Ty, ///< The type to sign extend to
1975 const std::string &Name, ///< A name for the new instruction
1976 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1977 );
1978
1979 /// @brief Clone an identical SExtInst
1980 virtual CastInst *clone() const;
1981
1982 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1983 static inline bool classof(const SExtInst *) { return true; }
1984 static inline bool classof(const Instruction *I) {
1985 return I->getOpcode() == SExt;
1986 }
1987 static inline bool classof(const Value *V) {
1988 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1989 }
1990};
1991
1992//===----------------------------------------------------------------------===//
1993// FPTruncInst Class
1994//===----------------------------------------------------------------------===//
1995
1996/// @brief This class represents a truncation of floating point types.
1997class FPTruncInst : public CastInst {
1998 FPTruncInst(const FPTruncInst &CI)
1999 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2000 }
2001public:
2002 /// @brief Constructor with insert-before-instruction semantics
2003 FPTruncInst(
2004 Value *S, ///< The value to be truncated
2005 const Type *Ty, ///< The type to truncate to
2006 const std::string &Name = "", ///< A name for the new instruction
2007 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2008 );
2009
2010 /// @brief Constructor with insert-before-instruction semantics
2011 FPTruncInst(
2012 Value *S, ///< The value to be truncated
2013 const Type *Ty, ///< The type to truncate to
2014 const std::string &Name, ///< A name for the new instruction
2015 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2016 );
2017
2018 /// @brief Clone an identical FPTruncInst
2019 virtual CastInst *clone() const;
2020
2021 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2022 static inline bool classof(const FPTruncInst *) { return true; }
2023 static inline bool classof(const Instruction *I) {
2024 return I->getOpcode() == FPTrunc;
2025 }
2026 static inline bool classof(const Value *V) {
2027 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2028 }
2029};
2030
2031//===----------------------------------------------------------------------===//
2032// FPExtInst Class
2033//===----------------------------------------------------------------------===//
2034
2035/// @brief This class represents an extension of floating point types.
2036class FPExtInst : public CastInst {
2037 FPExtInst(const FPExtInst &CI)
2038 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2039 }
2040public:
2041 /// @brief Constructor with insert-before-instruction semantics
2042 FPExtInst(
2043 Value *S, ///< The value to be extended
2044 const Type *Ty, ///< The type to extend to
2045 const std::string &Name = "", ///< A name for the new instruction
2046 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2047 );
2048
2049 /// @brief Constructor with insert-at-end-of-block semantics
2050 FPExtInst(
2051 Value *S, ///< The value to be extended
2052 const Type *Ty, ///< The type to extend to
2053 const std::string &Name, ///< A name for the new instruction
2054 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2055 );
2056
2057 /// @brief Clone an identical FPExtInst
2058 virtual CastInst *clone() const;
2059
2060 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2061 static inline bool classof(const FPExtInst *) { return true; }
2062 static inline bool classof(const Instruction *I) {
2063 return I->getOpcode() == FPExt;
2064 }
2065 static inline bool classof(const Value *V) {
2066 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2067 }
2068};
2069
2070//===----------------------------------------------------------------------===//
2071// UIToFPInst Class
2072//===----------------------------------------------------------------------===//
2073
2074/// @brief This class represents a cast unsigned integer to floating point.
2075class UIToFPInst : public CastInst {
2076 UIToFPInst(const UIToFPInst &CI)
2077 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2078 }
2079public:
2080 /// @brief Constructor with insert-before-instruction semantics
2081 UIToFPInst(
2082 Value *S, ///< The value to be converted
2083 const Type *Ty, ///< The type to convert to
2084 const std::string &Name = "", ///< A name for the new instruction
2085 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2086 );
2087
2088 /// @brief Constructor with insert-at-end-of-block semantics
2089 UIToFPInst(
2090 Value *S, ///< The value to be converted
2091 const Type *Ty, ///< The type to convert to
2092 const std::string &Name, ///< A name for the new instruction
2093 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2094 );
2095
2096 /// @brief Clone an identical UIToFPInst
2097 virtual CastInst *clone() const;
2098
2099 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2100 static inline bool classof(const UIToFPInst *) { return true; }
2101 static inline bool classof(const Instruction *I) {
2102 return I->getOpcode() == UIToFP;
2103 }
2104 static inline bool classof(const Value *V) {
2105 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2106 }
2107};
2108
2109//===----------------------------------------------------------------------===//
2110// SIToFPInst Class
2111//===----------------------------------------------------------------------===//
2112
2113/// @brief This class represents a cast from signed integer to floating point.
2114class SIToFPInst : public CastInst {
2115 SIToFPInst(const SIToFPInst &CI)
2116 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2117 }
2118public:
2119 /// @brief Constructor with insert-before-instruction semantics
2120 SIToFPInst(
2121 Value *S, ///< The value to be converted
2122 const Type *Ty, ///< The type to convert to
2123 const std::string &Name = "", ///< A name for the new instruction
2124 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2125 );
2126
2127 /// @brief Constructor with insert-at-end-of-block semantics
2128 SIToFPInst(
2129 Value *S, ///< The value to be converted
2130 const Type *Ty, ///< The type to convert to
2131 const std::string &Name, ///< A name for the new instruction
2132 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2133 );
2134
2135 /// @brief Clone an identical SIToFPInst
2136 virtual CastInst *clone() const;
2137
2138 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2139 static inline bool classof(const SIToFPInst *) { return true; }
2140 static inline bool classof(const Instruction *I) {
2141 return I->getOpcode() == SIToFP;
2142 }
2143 static inline bool classof(const Value *V) {
2144 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2145 }
2146};
2147
2148//===----------------------------------------------------------------------===//
2149// FPToUIInst Class
2150//===----------------------------------------------------------------------===//
2151
2152/// @brief This class represents a cast from floating point to unsigned integer
2153class FPToUIInst : public CastInst {
2154 FPToUIInst(const FPToUIInst &CI)
2155 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2156 }
2157public:
2158 /// @brief Constructor with insert-before-instruction semantics
2159 FPToUIInst(
2160 Value *S, ///< The value to be converted
2161 const Type *Ty, ///< The type to convert to
2162 const std::string &Name = "", ///< A name for the new instruction
2163 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2164 );
2165
2166 /// @brief Constructor with insert-at-end-of-block semantics
2167 FPToUIInst(
2168 Value *S, ///< The value to be converted
2169 const Type *Ty, ///< The type to convert to
2170 const std::string &Name, ///< A name for the new instruction
2171 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2172 );
2173
2174 /// @brief Clone an identical FPToUIInst
2175 virtual CastInst *clone() const;
2176
2177 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2178 static inline bool classof(const FPToUIInst *) { return true; }
2179 static inline bool classof(const Instruction *I) {
2180 return I->getOpcode() == FPToUI;
2181 }
2182 static inline bool classof(const Value *V) {
2183 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2184 }
2185};
2186
2187//===----------------------------------------------------------------------===//
2188// FPToSIInst Class
2189//===----------------------------------------------------------------------===//
2190
2191/// @brief This class represents a cast from floating point to signed integer.
2192class FPToSIInst : public CastInst {
2193 FPToSIInst(const FPToSIInst &CI)
2194 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2195 }
2196public:
2197 /// @brief Constructor with insert-before-instruction semantics
2198 FPToSIInst(
2199 Value *S, ///< The value to be converted
2200 const Type *Ty, ///< The type to convert to
2201 const std::string &Name = "", ///< A name for the new instruction
2202 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2203 );
2204
2205 /// @brief Constructor with insert-at-end-of-block semantics
2206 FPToSIInst(
2207 Value *S, ///< The value to be converted
2208 const Type *Ty, ///< The type to convert to
2209 const std::string &Name, ///< A name for the new instruction
2210 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2211 );
2212
2213 /// @brief Clone an identical FPToSIInst
2214 virtual CastInst *clone() const;
2215
2216 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2217 static inline bool classof(const FPToSIInst *) { return true; }
2218 static inline bool classof(const Instruction *I) {
2219 return I->getOpcode() == FPToSI;
2220 }
2221 static inline bool classof(const Value *V) {
2222 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2223 }
2224};
2225
2226//===----------------------------------------------------------------------===//
2227// IntToPtrInst Class
2228//===----------------------------------------------------------------------===//
2229
2230/// @brief This class represents a cast from an integer to a pointer.
2231class IntToPtrInst : public CastInst {
2232 IntToPtrInst(const IntToPtrInst &CI)
2233 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2234 }
2235public:
2236 /// @brief Constructor with insert-before-instruction semantics
2237 IntToPtrInst(
2238 Value *S, ///< The value to be converted
2239 const Type *Ty, ///< The type to convert to
2240 const std::string &Name = "", ///< A name for the new instruction
2241 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2242 );
2243
2244 /// @brief Constructor with insert-at-end-of-block semantics
2245 IntToPtrInst(
2246 Value *S, ///< The value to be converted
2247 const Type *Ty, ///< The type to convert to
2248 const std::string &Name, ///< A name for the new instruction
2249 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2250 );
2251
2252 /// @brief Clone an identical IntToPtrInst
2253 virtual CastInst *clone() const;
2254
2255 // Methods for support type inquiry through isa, cast, and dyn_cast:
2256 static inline bool classof(const IntToPtrInst *) { return true; }
2257 static inline bool classof(const Instruction *I) {
2258 return I->getOpcode() == IntToPtr;
2259 }
2260 static inline bool classof(const Value *V) {
2261 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2262 }
2263};
2264
2265//===----------------------------------------------------------------------===//
2266// PtrToIntInst Class
2267//===----------------------------------------------------------------------===//
2268
2269/// @brief This class represents a cast from a pointer to an integer
2270class PtrToIntInst : public CastInst {
2271 PtrToIntInst(const PtrToIntInst &CI)
2272 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2273 }
2274public:
2275 /// @brief Constructor with insert-before-instruction semantics
2276 PtrToIntInst(
2277 Value *S, ///< The value to be converted
2278 const Type *Ty, ///< The type to convert to
2279 const std::string &Name = "", ///< A name for the new instruction
2280 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2281 );
2282
2283 /// @brief Constructor with insert-at-end-of-block semantics
2284 PtrToIntInst(
2285 Value *S, ///< The value to be converted
2286 const Type *Ty, ///< The type to convert to
2287 const std::string &Name, ///< A name for the new instruction
2288 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2289 );
2290
2291 /// @brief Clone an identical PtrToIntInst
2292 virtual CastInst *clone() const;
2293
2294 // Methods for support type inquiry through isa, cast, and dyn_cast:
2295 static inline bool classof(const PtrToIntInst *) { return true; }
2296 static inline bool classof(const Instruction *I) {
2297 return I->getOpcode() == PtrToInt;
2298 }
2299 static inline bool classof(const Value *V) {
2300 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2301 }
2302};
2303
2304//===----------------------------------------------------------------------===//
2305// BitCastInst Class
2306//===----------------------------------------------------------------------===//
2307
2308/// @brief This class represents a no-op cast from one type to another.
2309class BitCastInst : public CastInst {
2310 BitCastInst(const BitCastInst &CI)
2311 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2312 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002313public:
2314 /// @brief Constructor with insert-before-instruction semantics
2315 BitCastInst(
2316 Value *S, ///< The value to be casted
2317 const Type *Ty, ///< The type to casted to
2318 const std::string &Name = "", ///< A name for the new instruction
2319 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2320 );
2321
2322 /// @brief Constructor with insert-at-end-of-block semantics
2323 BitCastInst(
2324 Value *S, ///< The value to be casted
2325 const Type *Ty, ///< The type to casted to
2326 const std::string &Name, ///< A name for the new instruction
2327 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2328 );
2329
2330 /// @brief Clone an identical BitCastInst
2331 virtual CastInst *clone() const;
2332
2333 // Methods for support type inquiry through isa, cast, and dyn_cast:
2334 static inline bool classof(const BitCastInst *) { return true; }
2335 static inline bool classof(const Instruction *I) {
2336 return I->getOpcode() == BitCast;
2337 }
2338 static inline bool classof(const Value *V) {
2339 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2340 }
2341};
2342
Devang Pateld081ef02008-02-19 22:15:16 +00002343//===----------------------------------------------------------------------===//
2344// GetResultInst Class
2345//===----------------------------------------------------------------------===//
2346
2347/// GetResultInst - This instruction extracts individual result value from
2348/// aggregate value, where aggregate value is returned by CallInst.
2349///
2350class GetResultInst : public Instruction {
2351 Use Ops[2];
2352 GetResultInst(const GetResultInst &GRI) :
2353 Instruction(GRI.getType(), Instruction::GetResult, Ops, 2) {
2354 Ops[0].init(GRI.Ops[0], this);
2355 Ops[1].init(GRI.Ops[1], this);
2356 }
2357
2358public:
2359 explicit GetResultInst(Value *Aggr, Value *Index,
2360 const std::string &Name = "",
2361 Instruction *InsertBefore = 0);
2362
2363 /// isValidOperands - Return true if an getresult instruction can be
2364 /// formed with the specified operands.
2365 static bool isValidOperands(const Value *Aggr, const Value *Idx);
2366
2367 virtual GetResultInst *clone() const;
2368
2369 // getType - Get aggregate value element type
2370 inline const Type *getType() const {
2371 return Ops[0]->getType();
2372 }
2373
Devang Patelb211bf52008-02-20 18:36:16 +00002374 inline Value *getAggregateValue() {
Devang Pateld081ef02008-02-19 22:15:16 +00002375 return getOperand(0);
2376 }
Devang Patelb211bf52008-02-20 18:36:16 +00002377
2378 inline const Value *getAggregateValue() const {
2379 return getOperand(0);
2380 }
2381
2382 const Value *getIndex() {
Devang Pateld081ef02008-02-19 22:15:16 +00002383 return getOperand(1);
2384 }
2385
2386 unsigned getNumOperands() const { return 2; }
2387
2388 // Methods for support type inquiry through isa, cast, and dyn_cast:
2389 static inline bool classof(const GetResultInst *) { return true; }
2390 static inline bool classof(const Instruction *I) {
2391 return (I->getOpcode() == Instruction::GetResult);
2392 }
2393 static inline bool classof(const Value *V) {
2394 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2395 }
2396};
2397
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002398} // End llvm namespace
2399
2400#endif