blob: cdce9ecdfe867cdb1d8868118a43afb1b74bca6e [file] [log] [blame]
Chris Lattnera892a3a2003-01-27 22:08:52 +00001//===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
Misha Brukman9769ab22005-04-21 20:19:05 +00002//
John Criswell6fbcc262003-10-20 20:19:47 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman9769ab22005-04-21 20:19:05 +00007//
John Criswell6fbcc262003-10-20 20:19:47 +00008//===----------------------------------------------------------------------===//
Chris Lattnera892a3a2003-01-27 22:08:52 +00009//
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 Greene52eec542007-08-01 03:43:44 +000019#include <iterator>
20
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000021#include "llvm/InstrTypes.h"
David Greene52eec542007-08-01 03:43:44 +000022#include "llvm/DerivedTypes.h"
Duncan Sandsafa3b6d2007-11-28 17:07:01 +000023#include "llvm/ParameterAttributes.h"
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000024
25namespace llvm {
26
Chris Lattner1fca5ff2004-10-27 16:14:51 +000027class BasicBlock;
Chris Lattnerd1a32602005-02-24 05:32:09 +000028class ConstantInt;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000029class PointerType;
Reid Spencer9d6565a2007-02-15 02:26:10 +000030class VectorType;
Reid Spencer3da43842007-02-28 22:00:54 +000031class ConstantRange;
32class APInt;
Reid Spencer4746ecf2007-04-09 15:01:12 +000033class ParamAttrsList;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000034
35//===----------------------------------------------------------------------===//
36// AllocationInst Class
37//===----------------------------------------------------------------------===//
38
39/// AllocationInst - This class is the common base class of MallocInst and
40/// AllocaInst.
41///
Chris Lattner454928e2005-01-29 00:31:36 +000042class AllocationInst : public UnaryInstruction {
Nate Begeman14b05292005-11-05 09:21:28 +000043 unsigned Alignment;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000044protected:
Nate Begeman14b05292005-11-05 09:21:28 +000045 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000046 const std::string &Name = "", Instruction *InsertBefore = 0);
Nate Begeman14b05292005-11-05 09:21:28 +000047 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000048 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000049public:
Gordon Henriksenafba8fe2007-12-10 02:14:30 +000050 // Out of line virtual method, so the vtable, etc has a home.
51 virtual ~AllocationInst();
52
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +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 ///
Chris Lattner454928e2005-01-29 00:31:36 +000061 inline const Value *getArraySize() const { return getOperand(0); }
62 inline Value *getArraySize() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000063
64 /// getType - Overload to return most specific pointer type
65 ///
66 inline const PointerType *getType() const {
Misha Brukman9769ab22005-04-21 20:19:05 +000067 return reinterpret_cast<const PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000068 }
69
70 /// getAllocatedType - Return the type that is being allocated by the
71 /// instruction.
72 ///
73 const Type *getAllocatedType() const;
74
Nate Begeman14b05292005-11-05 09:21:28 +000075 /// getAlignment - Return the alignment of the memory that is being allocated
76 /// by the instruction.
77 ///
78 unsigned getAlignment() const { return Alignment; }
Chris Lattner8ae779d2005-11-05 21:58:30 +000079 void setAlignment(unsigned Align) {
80 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
81 Alignment = Align;
82 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +000083
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000084 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)
Nate Begeman14b05292005-11-05 09:21:28 +0000110 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000111 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
112 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000113 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000114
115 MallocInst(const Type *Ty, const std::string &Name,
116 Instruction *InsertBefore = 0)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000117 : 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) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000120
121 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
Nate Begeman14b05292005-11-05 09:21:28 +0000122 const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000123 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
124 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
Nate Begeman14b05292005-11-05 09:21:28 +0000125 const std::string &Name = "",
126 Instruction *InsertBefore = 0)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000127 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000128
Chris Lattnerf319e832004-10-15 23:52:05 +0000129 virtual MallocInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000130
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)
Nate Begeman14b05292005-11-05 09:21:28 +0000154 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000155 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
156 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000157 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
Chris Lattnerb77780e2006-05-10 04:38:35 +0000158
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) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000164
Chris Lattnerb77780e2006-05-10 04:38:35 +0000165 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
166 const std::string &Name = "", Instruction *InsertBefore = 0)
167 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
Nate Begeman14b05292005-11-05 09:21:28 +0000168 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
169 const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000170 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000171
Chris Lattnerf319e832004-10-15 23:52:05 +0000172 virtual AllocaInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000173
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///
Chris Lattner454928e2005-01-29 00:31:36 +0000191class FreeInst : public UnaryInstruction {
192 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000193public:
194 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
195 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
196
Chris Lattnerf319e832004-10-15 23:52:05 +0000197 virtual FreeInst *clone() const;
Owen Andersonc9edf0b2007-07-06 23:13:31 +0000198
199 // Accessor methods for consistency with other memory operations
200 Value *getPointerOperand() { return getOperand(0); }
201 const Value *getPointerOperand() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000202
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000203 // 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
Chris Lattner88fe29a2005-02-05 01:44:18 +0000218/// LoadInst - an instruction for reading from memory. This uses the
219/// SubclassData field in Value to store whether or not the load is volatile.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000220///
Chris Lattner454928e2005-01-29 00:31:36 +0000221class LoadInst : public UnaryInstruction {
Christopher Lamb43c7f372007-04-22 19:24:39 +0000222
Chris Lattner454928e2005-01-29 00:31:36 +0000223 LoadInst(const LoadInst &LI)
Chris Lattner88fe29a2005-02-05 01:44:18 +0000224 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
225 setVolatile(LI.isVolatile());
Christopher Lamb43c7f372007-04-22 19:24:39 +0000226 setAlignment(LI.getAlignment());
Misha Brukman9769ab22005-04-21 20:19:05 +0000227
Chris Lattner454928e2005-01-29 00:31:36 +0000228#ifndef NDEBUG
229 AssertOK();
230#endif
231 }
232 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000233public:
234 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
235 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000236 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,
Chris Lattnerf00042a2007-02-13 07:54:42 +0000239 Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000240 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
241 BasicBlock *InsertAtEnd);
Dan Gohman6ab2d182007-07-18 20:51:11 +0000242 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
243 BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000244
Chris Lattnerf00042a2007-02-13 07:54:42 +0000245 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
246 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000247 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
Chris Lattnerf00042a2007-02-13 07:54:42 +0000248 Instruction *InsertBefore = 0);
249 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
250 BasicBlock *InsertAtEnd);
251
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000252 /// isVolatile - Return true if this is a load from a volatile memory
253 /// location.
254 ///
Christopher Lamb43c7f372007-04-22 19:24:39 +0000255 bool isVolatile() const { return SubclassData & 1; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000256
257 /// setVolatile - Specify whether this is a volatile load or not.
258 ///
Christopher Lamb43c7f372007-04-22 19:24:39 +0000259 void setVolatile(bool V) {
Hartmut Kaiserefd4a512007-10-17 14:56:40 +0000260 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000261 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000262
Chris Lattnerf319e832004-10-15 23:52:05 +0000263 virtual LoadInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000264
Christopher Lamb43c7f372007-04-22 19:24:39 +0000265 /// getAlignment - Return the alignment of the access that is being performed
266 ///
267 unsigned getAlignment() const {
Christopher Lamb032507d2007-04-22 22:22:02 +0000268 return (1 << (SubclassData>>1)) >> 1;
Christopher Lamb43c7f372007-04-22 19:24:39 +0000269 }
270
271 void setAlignment(unsigned Align);
272
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000273 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
Misha Brukman9769ab22005-04-21 20:19:05 +0000292/// StoreInst - an instruction for storing to memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000293///
294class StoreInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000295 Use Ops[2];
Christopher Lamb43c7f372007-04-22 19:24:39 +0000296
Chris Lattner88fe29a2005-02-05 01:44:18 +0000297 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000298 Ops[0].init(SI.Ops[0], this);
299 Ops[1].init(SI.Ops[1], this);
Chris Lattner88fe29a2005-02-05 01:44:18 +0000300 setVolatile(SI.isVolatile());
Christopher Lamb43c7f372007-04-22 19:24:39 +0000301 setAlignment(SI.getAlignment());
302
Chris Lattner454928e2005-01-29 00:31:36 +0000303#ifndef NDEBUG
304 AssertOK();
305#endif
306 }
307 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000308public:
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);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000313 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
314 unsigned Align, Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000315 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
Dan Gohman6ab2d182007-07-18 20:51:11 +0000316 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
317 unsigned Align, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000318
319
320 /// isVolatile - Return true if this is a load from a volatile memory
321 /// location.
322 ///
Christopher Lamb43c7f372007-04-22 19:24:39 +0000323 bool isVolatile() const { return SubclassData & 1; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000324
325 /// setVolatile - Specify whether this is a volatile load or not.
326 ///
Christopher Lamb43c7f372007-04-22 19:24:39 +0000327 void setVolatile(bool V) {
Hartmut Kaiserefd4a512007-10-17 14:56:40 +0000328 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000329 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000330
Chris Lattner454928e2005-01-29 00:31:36 +0000331 /// Transparently provide more efficient getOperand methods.
Misha Brukman9769ab22005-04-21 20:19:05 +0000332 Value *getOperand(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000333 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
Christopher Lamb43c7f372007-04-22 19:24:39 +0000342 /// getAlignment - Return the alignment of the access that is being performed
343 ///
344 unsigned getAlignment() const {
Christopher Lamb032507d2007-04-22 22:22:02 +0000345 return (1 << (SubclassData>>1)) >> 1;
Christopher Lamb43c7f372007-04-22 19:24:39 +0000346 }
347
348 void setAlignment(unsigned Align);
349
Chris Lattnerf319e832004-10-15 23:52:05 +0000350 virtual StoreInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000351
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000352 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 Greeneb8f74792007-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
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000379/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
380/// access elements of arrays and structs
381///
382class GetElementPtrInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000383 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);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000390 }
Chris Lattner6ffbe172007-01-31 19:47:18 +0000391 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
Chris Lattner38bacf22005-05-03 05:43:30 +0000392 void init(Value *Ptr, Value *Idx);
David Greeneb8f74792007-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
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +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 Greeneb8f74792007-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 Lambfe63fb92007-12-11 08:59:05 +0000458 IdxBegin, IdxEnd, true)),
459 cast<PointerType>(Ptr->getType())->getAddressSpace()),
David Greeneb8f74792007-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 Lambfe63fb92007-12-11 08:59:05 +0000469 IdxBegin, IdxEnd, true)),
470 cast<PointerType>(Ptr->getType())->getAddressSpace()),
David Greeneb8f74792007-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
Chris Lattner38bacf22005-05-03 05:43:30 +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 Henriksenafba8fe2007-12-10 02:14:30 +0000482 ~GetElementPtrInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000483
Chris Lattnerf319e832004-10-15 23:52:05 +0000484 virtual GetElementPtrInst *clone() const;
Misha Brukman9769ab22005-04-21 20:19:05 +0000485
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000486 // 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 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000494 /// A null type is returned if the indices are invalid for the specified
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000495 /// pointer type.
496 ///
David Greeneb8f74792007-09-04 15:46:09 +0000497 template<typename InputIterator>
Misha Brukman9769ab22005-04-21 20:19:05 +0000498 static const Type *getIndexedType(const Type *Ptr,
David Greeneb8f74792007-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 }
Chris Lattner38bacf22005-05-03 05:43:30 +0000506 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
Misha Brukman9769ab22005-04-21 20:19:05 +0000507
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000508 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 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000526
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000527 inline bool hasIndices() const {
528 return getNumOperands() > 1;
529 }
Chris Lattner6f771d42007-04-14 00:12:57 +0000530
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;
Chris Lattner6b0974c2007-04-27 20:35:56 +0000535
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
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000541
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//===----------------------------------------------------------------------===//
Reid Spencer45fb3f32006-11-20 01:22:35 +0000553// 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,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000578 LAST_ICMP_PREDICATE = ICMP_SLE,
579 BAD_ICMP_PREDICATE = ICMP_SLE + 1
Reid Spencer45fb3f32006-11-20 01:22:35 +0000580 };
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
Chris Lattnerb769d562007-01-14 19:41:24 +0000605 /// @brief Set the predicate for this instruction to the specified value.
606 void setPredicate(Predicate P) { SubclassData = P; }
607
Reid Spencer45fb3f32006-11-20 01:22:35 +0000608 /// 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.
Reid Spencere4d87aa2006-12-23 06:05:41 +0000632 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);
Reid Spencer45fb3f32006-11-20 01:22:35 +0000645
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000646 /// isEquality - Return true if this predicate is either EQ or NE. This also
647 /// tests for commutativity.
648 static bool isEquality(Predicate P) {
649 return P == ICMP_EQ || P == ICMP_NE;
650 }
651
652 /// isEquality - Return true if this predicate is either EQ or NE. This also
653 /// tests for commutativity.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000654 bool isEquality() const {
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000655 return isEquality(getPredicate());
Reid Spencer45fb3f32006-11-20 01:22:35 +0000656 }
Reid Spencere4d87aa2006-12-23 06:05:41 +0000657
658 /// @returns true if the predicate of this ICmpInst is commutative
659 /// @brief Determine if this relation is commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000660 bool isCommutative() const { return isEquality(); }
661
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000662 /// isRelational - Return true if the predicate is relational (not EQ or NE).
663 ///
Reid Spencer45fb3f32006-11-20 01:22:35 +0000664 bool isRelational() const {
665 return !isEquality();
666 }
667
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000668 /// isRelational - Return true if the predicate is relational (not EQ or NE).
669 ///
670 static bool isRelational(Predicate P) {
671 return !isEquality(P);
672 }
673
Reid Spencere4d87aa2006-12-23 06:05:41 +0000674 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
675 /// @brief Determine if this instruction's predicate is signed.
Chris Lattner5bda9e42007-09-15 06:51:03 +0000676 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
Reid Spencere4d87aa2006-12-23 06:05:41 +0000677
678 /// @returns true if the predicate provided is signed, false otherwise
679 /// @brief Determine if the predicate is signed.
680 static bool isSignedPredicate(Predicate pred);
681
Reid Spencer3da43842007-02-28 22:00:54 +0000682 /// Initialize a set of values that all satisfy the predicate with C.
683 /// @brief Make a ConstantRange for a relation with a constant value.
684 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
685
Reid Spencer45fb3f32006-11-20 01:22:35 +0000686 /// Exchange the two operands to this instruction in such a way that it does
687 /// not modify the semantics of the instruction. The predicate value may be
688 /// changed to retain the same result if the predicate is order dependent
689 /// (e.g. ult).
690 /// @brief Swap operands and adjust predicate.
691 void swapOperands() {
692 SubclassData = getSwappedPredicate();
693 std::swap(Ops[0], Ops[1]);
694 }
695
Chris Lattnercd406fe2007-08-24 20:48:18 +0000696 virtual ICmpInst *clone() const;
697
Reid Spencer45fb3f32006-11-20 01:22:35 +0000698 // Methods for support type inquiry through isa, cast, and dyn_cast:
699 static inline bool classof(const ICmpInst *) { return true; }
700 static inline bool classof(const Instruction *I) {
701 return I->getOpcode() == Instruction::ICmp;
702 }
703 static inline bool classof(const Value *V) {
704 return isa<Instruction>(V) && classof(cast<Instruction>(V));
705 }
706};
707
708//===----------------------------------------------------------------------===//
709// FCmpInst Class
710//===----------------------------------------------------------------------===//
711
712/// This instruction compares its operands according to the predicate given
713/// to the constructor. It only operates on floating point values or packed
714/// vectors of floating point values. The operands must be identical types.
715/// @brief Represents a floating point comparison operator.
716class FCmpInst: public CmpInst {
717public:
718 /// This enumeration lists the possible predicates for the FCmpInst. Values
719 /// in the range 0-31 are reserved for FCmpInst.
720 enum Predicate {
721 // Opcode U L G E Intuitive operation
722 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
723 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
724 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
725 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
726 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
727 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
728 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
729 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
730 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
731 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
732 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
733 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
734 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
735 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
736 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
737 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
738 FIRST_FCMP_PREDICATE = FCMP_FALSE,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000739 LAST_FCMP_PREDICATE = FCMP_TRUE,
740 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
Reid Spencer45fb3f32006-11-20 01:22:35 +0000741 };
742
743 /// @brief Constructor with insert-before-instruction semantics.
744 FCmpInst(
745 Predicate pred, ///< The predicate to use for the comparison
746 Value *LHS, ///< The left-hand-side of the expression
747 Value *RHS, ///< The right-hand-side of the expression
748 const std::string &Name = "", ///< Name of the instruction
749 Instruction *InsertBefore = 0 ///< Where to insert
750 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
751 }
752
753 /// @brief Constructor with insert-at-block-end semantics.
754 FCmpInst(
755 Predicate pred, ///< The predicate to use for the comparison
756 Value *LHS, ///< The left-hand-side of the expression
757 Value *RHS, ///< The right-hand-side of the expression
758 const std::string &Name, ///< Name of the instruction
759 BasicBlock *InsertAtEnd ///< Block to insert into.
760 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
761 }
762
763 /// @brief Return the predicate for this instruction.
764 Predicate getPredicate() const { return Predicate(SubclassData); }
765
Chris Lattnerb769d562007-01-14 19:41:24 +0000766 /// @brief Set the predicate for this instruction to the specified value.
767 void setPredicate(Predicate P) { SubclassData = P; }
768
Reid Spencer45fb3f32006-11-20 01:22:35 +0000769 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
770 /// @returns the inverse predicate for the instructions current predicate.
771 /// @brief Return the inverse of the predicate
772 Predicate getInversePredicate() const {
773 return getInversePredicate(getPredicate());
774 }
775
776 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
777 /// @returns the inverse predicate for \p pred.
778 /// @brief Return the inverse of a given predicate
779 static Predicate getInversePredicate(Predicate pred);
780
781 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
782 /// @returns the predicate that would be the result of exchanging the two
783 /// operands of the ICmpInst instruction without changing the result
784 /// produced.
785 /// @brief Return the predicate as if the operands were swapped
786 Predicate getSwappedPredicate() const {
787 return getSwappedPredicate(getPredicate());
788 }
789
790 /// This is a static version that you can use without an instruction
791 /// available.
792 /// @brief Return the predicate as if the operands were swapped.
793 static Predicate getSwappedPredicate(Predicate Opcode);
794
795 /// This also tests for commutativity. If isEquality() returns true then
796 /// the predicate is also commutative. Only the equality predicates are
797 /// commutative.
798 /// @returns true if the predicate of this instruction is EQ or NE.
799 /// @brief Determine if this is an equality predicate.
800 bool isEquality() const {
801 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
802 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
803 }
804 bool isCommutative() const { return isEquality(); }
805
806 /// @returns true if the predicate is relational (not EQ or NE).
807 /// @brief Determine if this a relational predicate.
808 bool isRelational() const { return !isEquality(); }
809
810 /// Exchange the two operands to this instruction in such a way that it does
811 /// not modify the semantics of the instruction. The predicate value may be
812 /// changed to retain the same result if the predicate is order dependent
813 /// (e.g. ult).
814 /// @brief Swap operands and adjust predicate.
815 void swapOperands() {
816 SubclassData = getSwappedPredicate();
817 std::swap(Ops[0], Ops[1]);
818 }
819
Chris Lattnercd406fe2007-08-24 20:48:18 +0000820 virtual FCmpInst *clone() const;
821
Reid Spencer45fb3f32006-11-20 01:22:35 +0000822 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
823 static inline bool classof(const FCmpInst *) { return true; }
824 static inline bool classof(const Instruction *I) {
825 return I->getOpcode() == Instruction::FCmp;
826 }
827 static inline bool classof(const Value *V) {
828 return isa<Instruction>(V) && classof(cast<Instruction>(V));
829 }
830};
831
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000832//===----------------------------------------------------------------------===//
833// CallInst Class
834//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000835/// CallInst - This class represents a function call, abstracting a target
Chris Lattner3340ffe2005-05-06 20:26:26 +0000836/// machine's calling convention. This class uses low bit of the SubClassData
837/// field to indicate whether or not this is a tail call. The rest of the bits
838/// hold the calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000839///
David Greene52eec542007-08-01 03:43:44 +0000840
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000841class CallInst : public Instruction {
Duncan Sandsdc024672007-11-27 13:23:08 +0000842 const ParamAttrsList *ParamAttrs; ///< parameter attributes for call
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000843 CallInst(const CallInst &CI);
Chris Lattnerd54f4322007-02-13 00:58:44 +0000844 void init(Value *Func, Value* const *Params, unsigned NumParams);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000845 void init(Value *Func, Value *Actual1, Value *Actual2);
846 void init(Value *Func, Value *Actual);
847 void init(Value *Func);
848
David Greene52eec542007-08-01 03:43:44 +0000849 template<typename InputIterator>
850 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
851 const std::string &Name,
852 // This argument ensures that we have an iterator we can
853 // do arithmetic on in constant time
854 std::random_access_iterator_tag) {
Chris Lattnera5c0d1e2007-08-29 16:32:50 +0000855 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
David Greene52eec542007-08-01 03:43:44 +0000856
Chris Lattnera5c0d1e2007-08-29 16:32:50 +0000857 // This requires that the iterator points to contiguous memory.
858 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
David Greene52eec542007-08-01 03:43:44 +0000859 setName(Name);
860 }
861
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000862public:
David Greene52eec542007-08-01 03:43:44 +0000863 /// Construct a CallInst given a range of arguments. InputIterator
864 /// must be a random-access iterator pointing to contiguous storage
865 /// (e.g. a std::vector<>::iterator). Checks are made for
866 /// random-accessness but not for contiguous storage as that would
867 /// incur runtime overhead.
868 /// @brief Construct a CallInst from a range of arguments
869 template<typename InputIterator>
870 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
871 const std::string &Name = "", Instruction *InsertBefore = 0)
872 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
873 ->getElementType())->getReturnType(),
874 Instruction::Call, 0, 0, InsertBefore) {
875 init(Func, ArgBegin, ArgEnd, Name,
876 typename std::iterator_traits<InputIterator>::iterator_category());
877 }
878
879 /// Construct a CallInst given a range of arguments. InputIterator
880 /// must be a random-access iterator pointing to contiguous storage
881 /// (e.g. a std::vector<>::iterator). Checks are made for
882 /// random-accessness but not for contiguous storage as that would
883 /// incur runtime overhead.
884 /// @brief Construct a CallInst from a range of arguments
885 template<typename InputIterator>
886 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
887 const std::string &Name, BasicBlock *InsertAtEnd)
888 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
889 ->getElementType())->getReturnType(),
890 Instruction::Call, 0, 0, InsertAtEnd) {
891 init(Func, ArgBegin, ArgEnd, Name,
892 typename std::iterator_traits<InputIterator>::iterator_category());
893 }
894
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000895 CallInst(Value *F, Value *Actual, const std::string& Name = "",
896 Instruction *InsertBefore = 0);
897 CallInst(Value *F, Value *Actual, const std::string& Name,
898 BasicBlock *InsertAtEnd);
Misha Brukman9769ab22005-04-21 20:19:05 +0000899 explicit CallInst(Value *F, const std::string &Name = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000900 Instruction *InsertBefore = 0);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000901 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
Gordon Henriksenafba8fe2007-12-10 02:14:30 +0000902 ~CallInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000903
Chris Lattnerf319e832004-10-15 23:52:05 +0000904 virtual CallInst *clone() const;
Chris Lattnerbb5493d2007-02-15 23:15:00 +0000905
Chris Lattner3340ffe2005-05-06 20:26:26 +0000906 bool isTailCall() const { return SubclassData & 1; }
907 void setTailCall(bool isTailCall = true) {
Jeff Cohen39cef602005-05-07 02:44:04 +0000908 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
Chris Lattner3340ffe2005-05-06 20:26:26 +0000909 }
910
911 /// getCallingConv/setCallingConv - Get or set the calling convention of this
912 /// function call.
913 unsigned getCallingConv() const { return SubclassData >> 1; }
914 void setCallingConv(unsigned CC) {
915 SubclassData = (SubclassData & 1) | (CC << 1);
916 }
Chris Lattnerddb6db42005-05-06 05:51:46 +0000917
Reid Spencerfa3e9122007-04-09 18:00:57 +0000918 /// Obtains a pointer to the ParamAttrsList object which holds the
919 /// parameter attributes information, if any.
920 /// @returns 0 if no attributes have been set.
Reid Spencer4746ecf2007-04-09 15:01:12 +0000921 /// @brief Get the parameter attributes.
Duncan Sandsdc024672007-11-27 13:23:08 +0000922 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
Reid Spencer4746ecf2007-04-09 15:01:12 +0000923
924 /// Sets the parameter attributes for this CallInst. To construct a
925 /// ParamAttrsList, see ParameterAttributes.h
926 /// @brief Set the parameter attributes.
Duncan Sandsdc024672007-11-27 13:23:08 +0000927 void setParamAttrs(const ParamAttrsList *attrs);
928
Duncan Sandsafa3b6d2007-11-28 17:07:01 +0000929 /// @brief Determine whether the call or the callee has the given attribute.
930 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
931
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000932 /// @brief Determine if the call does not access memory.
933 bool doesNotAccessMemory() const {
934 return paramHasAttr(0, ParamAttr::ReadNone);
935 }
936
937 /// @brief Determine if the call does not access or only reads memory.
938 bool onlyReadsMemory() const {
939 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
940 }
941
Duncan Sandscbb8bad2007-12-10 19:09:40 +0000942 /// @brief Determine if the call cannot return.
Duncan Sands2b0e8992007-12-18 09:59:50 +0000943 bool doesNotReturn() const {
Duncan Sandscbb8bad2007-12-10 19:09:40 +0000944 return paramHasAttr(0, ParamAttr::NoReturn);
945 }
946
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000947 /// @brief Determine if the call cannot unwind.
Duncan Sands2b0e8992007-12-18 09:59:50 +0000948 bool doesNotThrow() const {
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000949 return paramHasAttr(0, ParamAttr::NoUnwind);
950 }
951
Duncan Sandsdc024672007-11-27 13:23:08 +0000952 /// @brief Determine if the call returns a structure.
Duncan Sandsafa3b6d2007-11-28 17:07:01 +0000953 bool isStructReturn() const {
954 // Be friendly and also check the callee.
955 return paramHasAttr(1, ParamAttr::StructRet);
956 }
Reid Spencer4746ecf2007-04-09 15:01:12 +0000957
Chris Lattner721aef62004-11-18 17:46:57 +0000958 /// getCalledFunction - Return the function being called by this instruction
959 /// if it is a direct call. If it is a call through a function pointer,
960 /// return null.
961 Function *getCalledFunction() const {
Dan Gohman11a7dbf2007-09-24 15:46:02 +0000962 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +0000963 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000964
Reid Spencerc25ec252006-12-29 04:10:59 +0000965 /// getCalledValue - Get a pointer to the function that is invoked by this
966 /// instruction
Chris Lattner454928e2005-01-29 00:31:36 +0000967 inline const Value *getCalledValue() const { return getOperand(0); }
968 inline Value *getCalledValue() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000969
970 // Methods for support type inquiry through isa, cast, and dyn_cast:
971 static inline bool classof(const CallInst *) { return true; }
972 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000973 return I->getOpcode() == Instruction::Call;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000974 }
975 static inline bool classof(const Value *V) {
976 return isa<Instruction>(V) && classof(cast<Instruction>(V));
977 }
978};
979
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000980//===----------------------------------------------------------------------===//
981// SelectInst Class
982//===----------------------------------------------------------------------===//
983
984/// SelectInst - This class represents the LLVM 'select' instruction.
985///
986class SelectInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000987 Use Ops[3];
988
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000989 void init(Value *C, Value *S1, Value *S2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000990 Ops[0].init(C, this);
991 Ops[1].init(S1, this);
992 Ops[2].init(S2, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000993 }
994
Chris Lattner454928e2005-01-29 00:31:36 +0000995 SelectInst(const SelectInst &SI)
996 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
997 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
998 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000999public:
1000 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
1001 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001002 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001003 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +00001004 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001005 }
1006 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1007 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001008 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001009 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +00001010 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001011 }
1012
Chris Lattner454928e2005-01-29 00:31:36 +00001013 Value *getCondition() const { return Ops[0]; }
1014 Value *getTrueValue() const { return Ops[1]; }
1015 Value *getFalseValue() const { return Ops[2]; }
1016
1017 /// Transparently provide more efficient getOperand methods.
1018 Value *getOperand(unsigned i) const {
1019 assert(i < 3 && "getOperand() out of range!");
1020 return Ops[i];
1021 }
1022 void setOperand(unsigned i, Value *Val) {
1023 assert(i < 3 && "setOperand() out of range!");
1024 Ops[i] = Val;
1025 }
1026 unsigned getNumOperands() const { return 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001027
1028 OtherOps getOpcode() const {
1029 return static_cast<OtherOps>(Instruction::getOpcode());
1030 }
1031
Chris Lattnerf319e832004-10-15 23:52:05 +00001032 virtual SelectInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001033
1034 // Methods for support type inquiry through isa, cast, and dyn_cast:
1035 static inline bool classof(const SelectInst *) { return true; }
1036 static inline bool classof(const Instruction *I) {
1037 return I->getOpcode() == Instruction::Select;
1038 }
1039 static inline bool classof(const Value *V) {
1040 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1041 }
1042};
1043
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001044//===----------------------------------------------------------------------===//
1045// VAArgInst Class
1046//===----------------------------------------------------------------------===//
1047
1048/// VAArgInst - This class represents the va_arg llvm instruction, which returns
Andrew Lenharthf5428212005-06-18 18:31:30 +00001049/// an argument of the specified type given a va_list and increments that list
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001050///
Chris Lattner454928e2005-01-29 00:31:36 +00001051class VAArgInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001052 VAArgInst(const VAArgInst &VAA)
Chris Lattner454928e2005-01-29 00:31:36 +00001053 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001054public:
1055 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1056 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001057 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
Chris Lattnerf00042a2007-02-13 07:54:42 +00001058 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001059 }
1060 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1061 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001062 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
Chris Lattnerf00042a2007-02-13 07:54:42 +00001063 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001064 }
1065
Chris Lattnerf319e832004-10-15 23:52:05 +00001066 virtual VAArgInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001067
1068 // Methods for support type inquiry through isa, cast, and dyn_cast:
1069 static inline bool classof(const VAArgInst *) { return true; }
1070 static inline bool classof(const Instruction *I) {
1071 return I->getOpcode() == VAArg;
1072 }
1073 static inline bool classof(const Value *V) {
1074 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1075 }
1076};
1077
1078//===----------------------------------------------------------------------===//
Robert Bocchino49b78a52006-01-10 19:04:13 +00001079// ExtractElementInst Class
1080//===----------------------------------------------------------------------===//
1081
1082/// ExtractElementInst - This instruction extracts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +00001083/// element from a VectorType value
Robert Bocchino49b78a52006-01-10 19:04:13 +00001084///
1085class ExtractElementInst : public Instruction {
1086 Use Ops[2];
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001087 ExtractElementInst(const ExtractElementInst &EE) :
Robert Bocchinof9993442006-01-17 20:05:59 +00001088 Instruction(EE.getType(), ExtractElement, Ops, 2) {
1089 Ops[0].init(EE.Ops[0], this);
1090 Ops[1].init(EE.Ops[1], this);
Robert Bocchino49b78a52006-01-10 19:04:13 +00001091 }
1092
1093public:
Chris Lattner9fc18d22006-04-08 01:15:18 +00001094 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1095 Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +00001096 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1097 Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +00001098 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1099 BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +00001100 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1101 BasicBlock *InsertAtEnd);
Robert Bocchino49b78a52006-01-10 19:04:13 +00001102
Chris Lattnerfa495842006-04-08 04:04:54 +00001103 /// isValidOperands - Return true if an extractelement instruction can be
1104 /// formed with the specified operands.
1105 static bool isValidOperands(const Value *Vec, const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001106
Robert Bocchino49b78a52006-01-10 19:04:13 +00001107 virtual ExtractElementInst *clone() const;
1108
Robert Bocchino49b78a52006-01-10 19:04:13 +00001109 /// Transparently provide more efficient getOperand methods.
1110 Value *getOperand(unsigned i) const {
1111 assert(i < 2 && "getOperand() out of range!");
1112 return Ops[i];
1113 }
1114 void setOperand(unsigned i, Value *Val) {
1115 assert(i < 2 && "setOperand() out of range!");
1116 Ops[i] = Val;
1117 }
1118 unsigned getNumOperands() const { return 2; }
1119
1120 // Methods for support type inquiry through isa, cast, and dyn_cast:
1121 static inline bool classof(const ExtractElementInst *) { return true; }
1122 static inline bool classof(const Instruction *I) {
1123 return I->getOpcode() == Instruction::ExtractElement;
1124 }
1125 static inline bool classof(const Value *V) {
1126 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1127 }
1128};
1129
1130//===----------------------------------------------------------------------===//
Robert Bocchinof9993442006-01-17 20:05:59 +00001131// InsertElementInst Class
1132//===----------------------------------------------------------------------===//
1133
1134/// InsertElementInst - This instruction inserts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +00001135/// element into a VectorType value
Robert Bocchinof9993442006-01-17 20:05:59 +00001136///
1137class InsertElementInst : public Instruction {
1138 Use Ops[3];
Chris Lattner6a56ed42006-04-14 22:20:07 +00001139 InsertElementInst(const InsertElementInst &IE);
Robert Bocchinof9993442006-01-17 20:05:59 +00001140public:
Chris Lattner9fc18d22006-04-08 01:15:18 +00001141 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1142 const std::string &Name = "",Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +00001143 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1144 const std::string &Name = "",Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +00001145 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
Robert Bocchinof9993442006-01-17 20:05:59 +00001146 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +00001147 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1148 const std::string &Name, BasicBlock *InsertAtEnd);
Robert Bocchinof9993442006-01-17 20:05:59 +00001149
Chris Lattnerfa495842006-04-08 04:04:54 +00001150 /// isValidOperands - Return true if an insertelement instruction can be
1151 /// formed with the specified operands.
1152 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1153 const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001154
Robert Bocchinof9993442006-01-17 20:05:59 +00001155 virtual InsertElementInst *clone() const;
1156
Reid Spencerac9dcb92007-02-15 03:39:18 +00001157 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +00001158 ///
Reid Spencer9d6565a2007-02-15 02:26:10 +00001159 inline const VectorType *getType() const {
1160 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +00001161 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001162
Robert Bocchinof9993442006-01-17 20:05:59 +00001163 /// Transparently provide more efficient getOperand methods.
1164 Value *getOperand(unsigned i) const {
1165 assert(i < 3 && "getOperand() out of range!");
1166 return Ops[i];
1167 }
1168 void setOperand(unsigned i, Value *Val) {
1169 assert(i < 3 && "setOperand() out of range!");
1170 Ops[i] = Val;
1171 }
1172 unsigned getNumOperands() const { return 3; }
1173
1174 // Methods for support type inquiry through isa, cast, and dyn_cast:
1175 static inline bool classof(const InsertElementInst *) { return true; }
1176 static inline bool classof(const Instruction *I) {
1177 return I->getOpcode() == Instruction::InsertElement;
1178 }
1179 static inline bool classof(const Value *V) {
1180 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1181 }
1182};
1183
1184//===----------------------------------------------------------------------===//
Chris Lattner9fc18d22006-04-08 01:15:18 +00001185// ShuffleVectorInst Class
1186//===----------------------------------------------------------------------===//
1187
1188/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1189/// input vectors.
1190///
1191class ShuffleVectorInst : public Instruction {
1192 Use Ops[3];
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001193 ShuffleVectorInst(const ShuffleVectorInst &IE);
Chris Lattner9fc18d22006-04-08 01:15:18 +00001194public:
1195 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1196 const std::string &Name = "", Instruction *InsertBefor = 0);
1197 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1198 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001199
Chris Lattnerfa495842006-04-08 04:04:54 +00001200 /// isValidOperands - Return true if a shufflevector instruction can be
Chris Lattner9fc18d22006-04-08 01:15:18 +00001201 /// formed with the specified operands.
1202 static bool isValidOperands(const Value *V1, const Value *V2,
1203 const Value *Mask);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001204
Chris Lattner9fc18d22006-04-08 01:15:18 +00001205 virtual ShuffleVectorInst *clone() const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001206
Reid Spencerac9dcb92007-02-15 03:39:18 +00001207 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +00001208 ///
Reid Spencer9d6565a2007-02-15 02:26:10 +00001209 inline const VectorType *getType() const {
1210 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +00001211 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001212
Chris Lattner9fc18d22006-04-08 01:15:18 +00001213 /// Transparently provide more efficient getOperand methods.
1214 Value *getOperand(unsigned i) const {
1215 assert(i < 3 && "getOperand() out of range!");
1216 return Ops[i];
1217 }
1218 void setOperand(unsigned i, Value *Val) {
1219 assert(i < 3 && "setOperand() out of range!");
1220 Ops[i] = Val;
1221 }
1222 unsigned getNumOperands() const { return 3; }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001223
Chris Lattner9fc18d22006-04-08 01:15:18 +00001224 // Methods for support type inquiry through isa, cast, and dyn_cast:
1225 static inline bool classof(const ShuffleVectorInst *) { return true; }
1226 static inline bool classof(const Instruction *I) {
1227 return I->getOpcode() == Instruction::ShuffleVector;
1228 }
1229 static inline bool classof(const Value *V) {
1230 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1231 }
1232};
1233
1234
1235//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001236// PHINode Class
1237//===----------------------------------------------------------------------===//
1238
1239// PHINode - The PHINode class is used to represent the magical mystical PHI
1240// node, that can not exist in nature, but can be synthesized in a computer
1241// scientist's overactive imagination.
1242//
1243class PHINode : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +00001244 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1245 /// the number actually in use.
1246 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001247 PHINode(const PHINode &PN);
1248public:
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001249 explicit PHINode(const Type *Ty, const std::string &Name = "",
1250 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001251 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
Chris Lattner454928e2005-01-29 00:31:36 +00001252 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001253 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001254 }
1255
1256 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001257 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
Chris Lattner454928e2005-01-29 00:31:36 +00001258 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001259 setName(Name);
Chris Lattner454928e2005-01-29 00:31:36 +00001260 }
1261
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00001262 ~PHINode();
1263
Chris Lattner454928e2005-01-29 00:31:36 +00001264 /// reserveOperandSpace - This method can be used to avoid repeated
1265 /// reallocation of PHI operand lists by reserving space for the correct
1266 /// number of operands before adding them. Unlike normal vector reserves,
1267 /// this method can also be used to trim the operand space.
1268 void reserveOperandSpace(unsigned NumValues) {
1269 resizeOperands(NumValues*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001270 }
1271
Chris Lattnerf319e832004-10-15 23:52:05 +00001272 virtual PHINode *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001273
1274 /// getNumIncomingValues - Return the number of incoming edges
1275 ///
Chris Lattner454928e2005-01-29 00:31:36 +00001276 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001277
Reid Spencerc773de62006-05-19 19:07:54 +00001278 /// getIncomingValue - Return incoming value number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001279 ///
1280 Value *getIncomingValue(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001281 assert(i*2 < getNumOperands() && "Invalid value number!");
1282 return getOperand(i*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001283 }
1284 void setIncomingValue(unsigned i, Value *V) {
Chris Lattner454928e2005-01-29 00:31:36 +00001285 assert(i*2 < getNumOperands() && "Invalid value number!");
1286 setOperand(i*2, V);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001287 }
Chris Lattner454928e2005-01-29 00:31:36 +00001288 unsigned getOperandNumForIncomingValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001289 return i*2;
1290 }
1291
Reid Spencerc773de62006-05-19 19:07:54 +00001292 /// getIncomingBlock - Return incoming basic block number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001293 ///
Misha Brukman9769ab22005-04-21 20:19:05 +00001294 BasicBlock *getIncomingBlock(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001295 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001296 }
1297 void setIncomingBlock(unsigned i, BasicBlock *BB) {
Chris Lattner454928e2005-01-29 00:31:36 +00001298 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001299 }
1300 unsigned getOperandNumForIncomingBlock(unsigned i) {
1301 return i*2+1;
1302 }
1303
1304 /// addIncoming - Add an incoming value to the end of the PHI list
1305 ///
1306 void addIncoming(Value *V, BasicBlock *BB) {
1307 assert(getType() == V->getType() &&
1308 "All operands to PHI node must be the same type as the PHI node!");
Chris Lattner454928e2005-01-29 00:31:36 +00001309 unsigned OpNo = NumOperands;
1310 if (OpNo+2 > ReservedSpace)
1311 resizeOperands(0); // Get more space!
1312 // Initialize some new operands.
1313 NumOperands = OpNo+2;
1314 OperandList[OpNo].init(V, this);
1315 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001316 }
Misha Brukman9769ab22005-04-21 20:19:05 +00001317
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001318 /// removeIncomingValue - Remove an incoming value. This is useful if a
1319 /// predecessor basic block is deleted. The value removed is returned.
1320 ///
1321 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1322 /// is true), the PHI node is destroyed and any uses of it are replaced with
1323 /// dummy values. The only time there should be zero incoming values to a PHI
1324 /// node is when the block is dead, so this strategy is sound.
1325 ///
1326 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1327
1328 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1329 int Idx = getBasicBlockIndex(BB);
1330 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1331 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1332 }
1333
Misha Brukman9769ab22005-04-21 20:19:05 +00001334 /// getBasicBlockIndex - Return the first index of the specified basic
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001335 /// block in the value list for this PHI. Returns -1 if no instance.
1336 ///
1337 int getBasicBlockIndex(const BasicBlock *BB) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001338 Use *OL = OperandList;
Misha Brukman9769ab22005-04-21 20:19:05 +00001339 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
Chris Lattner454928e2005-01-29 00:31:36 +00001340 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001341 return -1;
1342 }
1343
1344 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1345 return getIncomingValue(getBasicBlockIndex(BB));
1346 }
1347
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001348 /// hasConstantValue - If the specified PHI node always merges together the
Nate Begemana83ba0f2005-08-04 23:24:19 +00001349 /// same value, return the value, otherwise return null.
1350 ///
Chris Lattner9acbd612005-08-05 00:49:06 +00001351 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001352
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001353 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1354 static inline bool classof(const PHINode *) { return true; }
1355 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +00001356 return I->getOpcode() == Instruction::PHI;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001357 }
1358 static inline bool classof(const Value *V) {
1359 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1360 }
Chris Lattner454928e2005-01-29 00:31:36 +00001361 private:
1362 void resizeOperands(unsigned NumOperands);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001363};
1364
1365//===----------------------------------------------------------------------===//
1366// ReturnInst Class
1367//===----------------------------------------------------------------------===//
1368
1369//===---------------------------------------------------------------------------
1370/// ReturnInst - Return a value (possibly void), from a function. Execution
1371/// does not continue in this function any longer.
1372///
1373class ReturnInst : public TerminatorInst {
Chris Lattner910c80a2007-02-24 00:55:48 +00001374 Use RetVal; // Return Value: null if 'void'.
1375 ReturnInst(const ReturnInst &RI);
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001376 void init(Value *RetVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001377
1378public:
1379 // ReturnInst constructors:
1380 // ReturnInst() - 'ret void' instruction
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001381 // ReturnInst( null) - 'ret void' instruction
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001382 // ReturnInst(Value* X) - 'ret X' instruction
1383 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1384 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1385 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1386 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001387 //
1388 // NOTE: If the Value* passed is of type void then the constructor behaves as
1389 // if it was passed NULL.
Chris Lattner910c80a2007-02-24 00:55:48 +00001390 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1391 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1392 explicit ReturnInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001393
Chris Lattnerf319e832004-10-15 23:52:05 +00001394 virtual ReturnInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001395
Chris Lattner454928e2005-01-29 00:31:36 +00001396 // Transparently provide more efficient getOperand methods.
1397 Value *getOperand(unsigned i) const {
1398 assert(i < getNumOperands() && "getOperand() out of range!");
1399 return RetVal;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001400 }
Chris Lattner454928e2005-01-29 00:31:36 +00001401 void setOperand(unsigned i, Value *Val) {
1402 assert(i < getNumOperands() && "setOperand() out of range!");
1403 RetVal = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001404 }
1405
Chris Lattner454928e2005-01-29 00:31:36 +00001406 Value *getReturnValue() const { return RetVal; }
1407
1408 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001409
1410 // Methods for support type inquiry through isa, cast, and dyn_cast:
1411 static inline bool classof(const ReturnInst *) { return true; }
1412 static inline bool classof(const Instruction *I) {
1413 return (I->getOpcode() == Instruction::Ret);
1414 }
1415 static inline bool classof(const Value *V) {
1416 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1417 }
Chris Lattner454928e2005-01-29 00:31:36 +00001418 private:
1419 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1420 virtual unsigned getNumSuccessorsV() const;
1421 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001422};
1423
1424//===----------------------------------------------------------------------===//
1425// BranchInst Class
1426//===----------------------------------------------------------------------===//
1427
1428//===---------------------------------------------------------------------------
1429/// BranchInst - Conditional or Unconditional Branch instruction.
1430///
1431class BranchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001432 /// Ops list - Branches are strange. The operands are ordered:
1433 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1434 /// they don't have to check for cond/uncond branchness.
1435 Use Ops[3];
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001436 BranchInst(const BranchInst &BI);
Chris Lattner454928e2005-01-29 00:31:36 +00001437 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001438public:
1439 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1440 // BranchInst(BB *B) - 'br B'
1441 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1442 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1443 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1444 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1445 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
Chris Lattner910c80a2007-02-24 00:55:48 +00001446 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001447 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00001448 Instruction *InsertBefore = 0);
1449 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001450 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00001451 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001452
1453 /// Transparently provide more efficient getOperand methods.
1454 Value *getOperand(unsigned i) const {
1455 assert(i < getNumOperands() && "getOperand() out of range!");
1456 return Ops[i];
1457 }
1458 void setOperand(unsigned i, Value *Val) {
1459 assert(i < getNumOperands() && "setOperand() out of range!");
1460 Ops[i] = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001461 }
1462
Chris Lattnerf319e832004-10-15 23:52:05 +00001463 virtual BranchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001464
Chris Lattner454928e2005-01-29 00:31:36 +00001465 inline bool isUnconditional() const { return getNumOperands() == 1; }
1466 inline bool isConditional() const { return getNumOperands() == 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001467
1468 inline Value *getCondition() const {
1469 assert(isConditional() && "Cannot get condition of an uncond branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001470 return getOperand(2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001471 }
1472
1473 void setCondition(Value *V) {
1474 assert(isConditional() && "Cannot set condition of unconditional branch!");
1475 setOperand(2, V);
1476 }
1477
1478 // setUnconditionalDest - Change the current branch to an unconditional branch
1479 // targeting the specified block.
Chris Lattner454928e2005-01-29 00:31:36 +00001480 // FIXME: Eliminate this ugly method.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001481 void setUnconditionalDest(BasicBlock *Dest) {
Chris Lattner454928e2005-01-29 00:31:36 +00001482 if (isConditional()) { // Convert this to an uncond branch.
1483 NumOperands = 1;
1484 Ops[1].set(0);
1485 Ops[2].set(0);
1486 }
1487 setOperand(0, reinterpret_cast<Value*>(Dest));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001488 }
1489
Chris Lattner454928e2005-01-29 00:31:36 +00001490 unsigned getNumSuccessors() const { return 1+isConditional(); }
1491
1492 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001493 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
Dan Gohmanb96039e2007-05-11 20:59:29 +00001494 return cast<BasicBlock>(getOperand(i));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001495 }
1496
Chris Lattner454928e2005-01-29 00:31:36 +00001497 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001498 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001499 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001500 }
1501
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001502 // Methods for support type inquiry through isa, cast, and dyn_cast:
1503 static inline bool classof(const BranchInst *) { return true; }
1504 static inline bool classof(const Instruction *I) {
1505 return (I->getOpcode() == Instruction::Br);
1506 }
1507 static inline bool classof(const Value *V) {
1508 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1509 }
Chris Lattner454928e2005-01-29 00:31:36 +00001510private:
1511 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1512 virtual unsigned getNumSuccessorsV() const;
1513 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001514};
1515
1516//===----------------------------------------------------------------------===//
1517// SwitchInst Class
1518//===----------------------------------------------------------------------===//
1519
1520//===---------------------------------------------------------------------------
1521/// SwitchInst - Multiway switch
1522///
1523class SwitchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001524 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001525 // Operand[0] = Value to switch on
1526 // Operand[1] = Default basic block destination
1527 // Operand[2n ] = Value to match
1528 // Operand[2n+1] = BasicBlock to go to on match
1529 SwitchInst(const SwitchInst &RI);
Chris Lattner454928e2005-01-29 00:31:36 +00001530 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1531 void resizeOperands(unsigned No);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001532public:
Chris Lattner454928e2005-01-29 00:31:36 +00001533 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1534 /// switch on and a default destination. The number of additional cases can
1535 /// be specified here to make memory allocation more efficient. This
1536 /// constructor can also autoinsert before another instruction.
1537 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00001538 Instruction *InsertBefore = 0);
1539
Chris Lattner454928e2005-01-29 00:31:36 +00001540 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1541 /// switch on and a default destination. The number of additional cases can
1542 /// be specified here to make memory allocation more efficient. This
1543 /// constructor also autoinserts at the end of the specified BasicBlock.
1544 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00001545 BasicBlock *InsertAtEnd);
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00001546 ~SwitchInst();
Chris Lattner454928e2005-01-29 00:31:36 +00001547
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001548
1549 // Accessor Methods for Switch stmt
Chris Lattner454928e2005-01-29 00:31:36 +00001550 inline Value *getCondition() const { return getOperand(0); }
1551 void setCondition(Value *V) { setOperand(0, V); }
Chris Lattnerbfaf88a2004-12-10 20:35:47 +00001552
Chris Lattner454928e2005-01-29 00:31:36 +00001553 inline BasicBlock *getDefaultDest() const {
1554 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001555 }
1556
1557 /// getNumCases - return the number of 'cases' in this switch instruction.
1558 /// Note that case #0 is always the default case.
1559 unsigned getNumCases() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001560 return getNumOperands()/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001561 }
1562
1563 /// getCaseValue - Return the specified case value. Note that case #0, the
1564 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001565 ConstantInt *getCaseValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001566 assert(i && i < getNumCases() && "Illegal case value to get!");
1567 return getSuccessorValue(i);
1568 }
1569
1570 /// getCaseValue - Return the specified case value. Note that case #0, the
1571 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001572 const ConstantInt *getCaseValue(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001573 assert(i && i < getNumCases() && "Illegal case value to get!");
1574 return getSuccessorValue(i);
1575 }
1576
1577 /// findCaseValue - Search all of the case values for the specified constant.
1578 /// If it is explicitly handled, return the case number of it, otherwise
1579 /// return 0 to indicate that it is handled by the default handler.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001580 unsigned findCaseValue(const ConstantInt *C) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001581 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1582 if (getCaseValue(i) == C)
1583 return i;
1584 return 0;
1585 }
1586
Nick Lewycky011f1842006-09-18 19:03:59 +00001587 /// findCaseDest - Finds the unique case value for a given successor. Returns
1588 /// null if the successor is not found, not unique, or is the default case.
1589 ConstantInt *findCaseDest(BasicBlock *BB) {
Nick Lewyckyd7915442006-09-18 20:44:37 +00001590 if (BB == getDefaultDest()) return NULL;
1591
Nick Lewycky011f1842006-09-18 19:03:59 +00001592 ConstantInt *CI = NULL;
1593 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1594 if (getSuccessor(i) == BB) {
1595 if (CI) return NULL; // Multiple cases lead to BB.
1596 else CI = getCaseValue(i);
1597 }
1598 }
1599 return CI;
1600 }
1601
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001602 /// addCase - Add an entry to the switch instruction...
1603 ///
Chris Lattnerd1a32602005-02-24 05:32:09 +00001604 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001605
1606 /// removeCase - This method removes the specified successor from the switch
1607 /// instruction. Note that this cannot be used to remove the default
1608 /// destination (successor #0).
1609 ///
1610 void removeCase(unsigned idx);
1611
Chris Lattner454928e2005-01-29 00:31:36 +00001612 virtual SwitchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001613
Chris Lattner454928e2005-01-29 00:31:36 +00001614 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1615 BasicBlock *getSuccessor(unsigned idx) const {
1616 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1617 return cast<BasicBlock>(getOperand(idx*2+1));
1618 }
1619 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001620 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001621 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001622 }
1623
1624 // getSuccessorValue - Return the value associated with the specified
1625 // successor.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001626 inline ConstantInt *getSuccessorValue(unsigned idx) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001627 assert(idx < getNumSuccessors() && "Successor # out of range!");
Reid Spenceredd5d9e2005-05-15 16:13:11 +00001628 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001629 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001630
1631 // Methods for support type inquiry through isa, cast, and dyn_cast:
1632 static inline bool classof(const SwitchInst *) { return true; }
1633 static inline bool classof(const Instruction *I) {
Chris Lattnerd1a32602005-02-24 05:32:09 +00001634 return I->getOpcode() == Instruction::Switch;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001635 }
1636 static inline bool classof(const Value *V) {
1637 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1638 }
Chris Lattner454928e2005-01-29 00:31:36 +00001639private:
1640 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1641 virtual unsigned getNumSuccessorsV() const;
1642 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001643};
1644
1645//===----------------------------------------------------------------------===//
1646// InvokeInst Class
1647//===----------------------------------------------------------------------===//
1648
1649//===---------------------------------------------------------------------------
Chris Lattner3340ffe2005-05-06 20:26:26 +00001650
1651/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1652/// calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001653///
1654class InvokeInst : public TerminatorInst {
Duncan Sandsdc024672007-11-27 13:23:08 +00001655 const ParamAttrsList *ParamAttrs;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001656 InvokeInst(const InvokeInst &BI);
1657 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Chris Lattnerd2dd1502007-02-13 01:04:01 +00001658 Value* const *Args, unsigned NumArgs);
David Greenef1355a52007-08-27 19:04:21 +00001659
1660 template<typename InputIterator>
1661 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1662 InputIterator ArgBegin, InputIterator ArgEnd,
1663 const std::string &Name,
1664 // This argument ensures that we have an iterator we can
1665 // do arithmetic on in constant time
1666 std::random_access_iterator_tag) {
Chris Lattnera5c0d1e2007-08-29 16:32:50 +00001667 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
David Greenef1355a52007-08-27 19:04:21 +00001668
Chris Lattnera5c0d1e2007-08-29 16:32:50 +00001669 // This requires that the iterator points to contiguous memory.
1670 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
David Greenef1355a52007-08-27 19:04:21 +00001671 setName(Name);
1672 }
1673
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001674public:
David Greenef1355a52007-08-27 19:04:21 +00001675 /// Construct an InvokeInst given a range of arguments.
1676 /// InputIterator must be a random-access iterator pointing to
1677 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1678 /// made for random-accessness but not for contiguous storage as
1679 /// that would incur runtime overhead.
1680 ///
1681 /// @brief Construct an InvokeInst from a range of arguments
1682 template<typename InputIterator>
1683 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1684 InputIterator ArgBegin, InputIterator ArgEnd,
1685 const std::string &Name = "", Instruction *InsertBefore = 0)
1686 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1687 ->getElementType())->getReturnType(),
1688 Instruction::Invoke, 0, 0, InsertBefore) {
1689 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1690 typename std::iterator_traits<InputIterator>::iterator_category());
1691 }
1692
1693 /// Construct an InvokeInst given a range of arguments.
1694 /// InputIterator must be a random-access iterator pointing to
1695 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1696 /// made for random-accessness but not for contiguous storage as
1697 /// that would incur runtime overhead.
1698 ///
1699 /// @brief Construct an InvokeInst from a range of arguments
1700 template<typename InputIterator>
1701 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1702 InputIterator ArgBegin, InputIterator ArgEnd,
1703 const std::string &Name, BasicBlock *InsertAtEnd)
1704 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1705 ->getElementType())->getReturnType(),
1706 Instruction::Invoke, 0, 0, InsertAtEnd) {
1707 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1708 typename std::iterator_traits<InputIterator>::iterator_category());
1709 }
1710
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00001711 ~InvokeInst();
1712
Chris Lattnerf319e832004-10-15 23:52:05 +00001713 virtual InvokeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001714
Chris Lattner3340ffe2005-05-06 20:26:26 +00001715 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1716 /// function call.
1717 unsigned getCallingConv() const { return SubclassData; }
1718 void setCallingConv(unsigned CC) {
1719 SubclassData = CC;
1720 }
1721
Reid Spencerfa3e9122007-04-09 18:00:57 +00001722 /// Obtains a pointer to the ParamAttrsList object which holds the
1723 /// parameter attributes information, if any.
1724 /// @returns 0 if no attributes have been set.
1725 /// @brief Get the parameter attributes.
Duncan Sandsdc024672007-11-27 13:23:08 +00001726 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
Reid Spencerfa3e9122007-04-09 18:00:57 +00001727
1728 /// Sets the parameter attributes for this InvokeInst. To construct a
1729 /// ParamAttrsList, see ParameterAttributes.h
1730 /// @brief Set the parameter attributes.
Duncan Sandsdc024672007-11-27 13:23:08 +00001731 void setParamAttrs(const ParamAttrsList *attrs);
1732
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00001733 /// @brief Determine whether the call or the callee has the given attribute.
1734 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
1735
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001736 /// @brief Determine if the call does not access memory.
1737 bool doesNotAccessMemory() const {
1738 return paramHasAttr(0, ParamAttr::ReadNone);
1739 }
1740
1741 /// @brief Determine if the call does not access or only reads memory.
1742 bool onlyReadsMemory() const {
1743 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1744 }
1745
Duncan Sandscbb8bad2007-12-10 19:09:40 +00001746 /// @brief Determine if the call cannot return.
Duncan Sands2b0e8992007-12-18 09:59:50 +00001747 bool doesNotReturn() const {
Duncan Sandscbb8bad2007-12-10 19:09:40 +00001748 return paramHasAttr(0, ParamAttr::NoReturn);
1749 }
1750
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001751 /// @brief Determine if the call cannot unwind.
Duncan Sands2b0e8992007-12-18 09:59:50 +00001752 bool doesNotThrow() const {
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001753 return paramHasAttr(0, ParamAttr::NoUnwind);
1754 }
1755
Duncan Sandsdc024672007-11-27 13:23:08 +00001756 /// @brief Determine if the call returns a structure.
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00001757 bool isStructReturn() const {
1758 // Be friendly and also check the callee.
1759 return paramHasAttr(1, ParamAttr::StructRet);
1760 }
Reid Spencerfa3e9122007-04-09 18:00:57 +00001761
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001762 /// getCalledFunction - Return the function called, or null if this is an
Chris Lattner721aef62004-11-18 17:46:57 +00001763 /// indirect function invocation.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001764 ///
Chris Lattner721aef62004-11-18 17:46:57 +00001765 Function *getCalledFunction() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001766 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +00001767 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001768
1769 // getCalledValue - Get a pointer to a function that is invoked by this inst.
Chris Lattner454928e2005-01-29 00:31:36 +00001770 inline Value *getCalledValue() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001771
1772 // get*Dest - Return the destination basic blocks...
Chris Lattner454928e2005-01-29 00:31:36 +00001773 BasicBlock *getNormalDest() const {
1774 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001775 }
Chris Lattner454928e2005-01-29 00:31:36 +00001776 BasicBlock *getUnwindDest() const {
1777 return cast<BasicBlock>(getOperand(2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001778 }
Chris Lattner454928e2005-01-29 00:31:36 +00001779 void setNormalDest(BasicBlock *B) {
1780 setOperand(1, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001781 }
1782
Chris Lattner454928e2005-01-29 00:31:36 +00001783 void setUnwindDest(BasicBlock *B) {
1784 setOperand(2, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001785 }
1786
Chris Lattner454928e2005-01-29 00:31:36 +00001787 inline BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001788 assert(i < 2 && "Successor # out of range for invoke!");
1789 return i == 0 ? getNormalDest() : getUnwindDest();
1790 }
1791
Chris Lattner454928e2005-01-29 00:31:36 +00001792 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001793 assert(idx < 2 && "Successor # out of range for invoke!");
Chris Lattner454928e2005-01-29 00:31:36 +00001794 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001795 }
1796
Chris Lattner454928e2005-01-29 00:31:36 +00001797 unsigned getNumSuccessors() const { return 2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001798
1799 // Methods for support type inquiry through isa, cast, and dyn_cast:
1800 static inline bool classof(const InvokeInst *) { return true; }
1801 static inline bool classof(const Instruction *I) {
1802 return (I->getOpcode() == Instruction::Invoke);
1803 }
1804 static inline bool classof(const Value *V) {
1805 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1806 }
Chris Lattner454928e2005-01-29 00:31:36 +00001807private:
1808 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1809 virtual unsigned getNumSuccessorsV() const;
1810 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001811};
1812
1813
1814//===----------------------------------------------------------------------===//
1815// UnwindInst Class
1816//===----------------------------------------------------------------------===//
1817
1818//===---------------------------------------------------------------------------
1819/// UnwindInst - Immediately exit the current function, unwinding the stack
1820/// until an invoke instruction is found.
1821///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001822class UnwindInst : public TerminatorInst {
1823public:
Chris Lattner910c80a2007-02-24 00:55:48 +00001824 explicit UnwindInst(Instruction *InsertBefore = 0);
1825 explicit UnwindInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001826
Chris Lattnerf319e832004-10-15 23:52:05 +00001827 virtual UnwindInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001828
Chris Lattner454928e2005-01-29 00:31:36 +00001829 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001830
1831 // Methods for support type inquiry through isa, cast, and dyn_cast:
1832 static inline bool classof(const UnwindInst *) { return true; }
1833 static inline bool classof(const Instruction *I) {
1834 return I->getOpcode() == Instruction::Unwind;
1835 }
1836 static inline bool classof(const Value *V) {
1837 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1838 }
Chris Lattner454928e2005-01-29 00:31:36 +00001839private:
1840 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1841 virtual unsigned getNumSuccessorsV() const;
1842 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001843};
1844
Chris Lattner076b3f12004-10-16 18:05:54 +00001845//===----------------------------------------------------------------------===//
1846// UnreachableInst Class
1847//===----------------------------------------------------------------------===//
1848
1849//===---------------------------------------------------------------------------
1850/// UnreachableInst - This function has undefined behavior. In particular, the
1851/// presence of this instruction indicates some higher level knowledge that the
1852/// end of the block cannot be reached.
1853///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001854class UnreachableInst : public TerminatorInst {
1855public:
Chris Lattner910c80a2007-02-24 00:55:48 +00001856 explicit UnreachableInst(Instruction *InsertBefore = 0);
1857 explicit UnreachableInst(BasicBlock *InsertAtEnd);
Chris Lattner076b3f12004-10-16 18:05:54 +00001858
1859 virtual UnreachableInst *clone() const;
1860
Chris Lattner454928e2005-01-29 00:31:36 +00001861 unsigned getNumSuccessors() const { return 0; }
Chris Lattner076b3f12004-10-16 18:05:54 +00001862
1863 // Methods for support type inquiry through isa, cast, and dyn_cast:
1864 static inline bool classof(const UnreachableInst *) { return true; }
1865 static inline bool classof(const Instruction *I) {
1866 return I->getOpcode() == Instruction::Unreachable;
1867 }
1868 static inline bool classof(const Value *V) {
1869 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1870 }
Chris Lattner454928e2005-01-29 00:31:36 +00001871private:
1872 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1873 virtual unsigned getNumSuccessorsV() const;
1874 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattner076b3f12004-10-16 18:05:54 +00001875};
1876
Reid Spencer3da59db2006-11-27 01:05:10 +00001877//===----------------------------------------------------------------------===//
1878// TruncInst Class
1879//===----------------------------------------------------------------------===//
1880
1881/// @brief This class represents a truncation of integer types.
1882class TruncInst : public CastInst {
1883 /// Private copy constructor
1884 TruncInst(const TruncInst &CI)
1885 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1886 }
1887public:
1888 /// @brief Constructor with insert-before-instruction semantics
1889 TruncInst(
1890 Value *S, ///< The value to be truncated
1891 const Type *Ty, ///< The (smaller) type to truncate to
1892 const std::string &Name = "", ///< A name for the new instruction
1893 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1894 );
1895
1896 /// @brief Constructor with insert-at-end-of-block semantics
1897 TruncInst(
1898 Value *S, ///< The value to be truncated
1899 const Type *Ty, ///< The (smaller) type to truncate to
1900 const std::string &Name, ///< A name for the new instruction
1901 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1902 );
1903
1904 /// @brief Clone an identical TruncInst
1905 virtual CastInst *clone() const;
1906
1907 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1908 static inline bool classof(const TruncInst *) { return true; }
1909 static inline bool classof(const Instruction *I) {
1910 return I->getOpcode() == Trunc;
1911 }
1912 static inline bool classof(const Value *V) {
1913 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1914 }
1915};
1916
1917//===----------------------------------------------------------------------===//
1918// ZExtInst Class
1919//===----------------------------------------------------------------------===//
1920
1921/// @brief This class represents zero extension of integer types.
1922class ZExtInst : public CastInst {
1923 /// @brief Private copy constructor
1924 ZExtInst(const ZExtInst &CI)
1925 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1926 }
1927public:
1928 /// @brief Constructor with insert-before-instruction semantics
1929 ZExtInst(
1930 Value *S, ///< The value to be zero extended
1931 const Type *Ty, ///< The type to zero extend to
1932 const std::string &Name = "", ///< A name for the new instruction
1933 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1934 );
1935
1936 /// @brief Constructor with insert-at-end semantics.
1937 ZExtInst(
1938 Value *S, ///< The value to be zero extended
1939 const Type *Ty, ///< The type to zero extend to
1940 const std::string &Name, ///< A name for the new instruction
1941 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1942 );
1943
1944 /// @brief Clone an identical ZExtInst
1945 virtual CastInst *clone() const;
1946
1947 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1948 static inline bool classof(const ZExtInst *) { return true; }
1949 static inline bool classof(const Instruction *I) {
1950 return I->getOpcode() == ZExt;
1951 }
1952 static inline bool classof(const Value *V) {
1953 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1954 }
1955};
1956
1957//===----------------------------------------------------------------------===//
1958// SExtInst Class
1959//===----------------------------------------------------------------------===//
1960
1961/// @brief This class represents a sign extension of integer types.
1962class SExtInst : public CastInst {
1963 /// @brief Private copy constructor
1964 SExtInst(const SExtInst &CI)
1965 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1966 }
1967public:
1968 /// @brief Constructor with insert-before-instruction semantics
1969 SExtInst(
1970 Value *S, ///< The value to be sign extended
1971 const Type *Ty, ///< The type to sign extend to
1972 const std::string &Name = "", ///< A name for the new instruction
1973 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1974 );
1975
1976 /// @brief Constructor with insert-at-end-of-block semantics
1977 SExtInst(
1978 Value *S, ///< The value to be sign extended
1979 const Type *Ty, ///< The type to sign extend to
1980 const std::string &Name, ///< A name for the new instruction
1981 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1982 );
1983
1984 /// @brief Clone an identical SExtInst
1985 virtual CastInst *clone() const;
1986
1987 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1988 static inline bool classof(const SExtInst *) { return true; }
1989 static inline bool classof(const Instruction *I) {
1990 return I->getOpcode() == SExt;
1991 }
1992 static inline bool classof(const Value *V) {
1993 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1994 }
1995};
1996
1997//===----------------------------------------------------------------------===//
1998// FPTruncInst Class
1999//===----------------------------------------------------------------------===//
2000
2001/// @brief This class represents a truncation of floating point types.
2002class FPTruncInst : public CastInst {
2003 FPTruncInst(const FPTruncInst &CI)
2004 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2005 }
2006public:
2007 /// @brief Constructor with insert-before-instruction semantics
2008 FPTruncInst(
2009 Value *S, ///< The value to be truncated
2010 const Type *Ty, ///< The type to truncate to
2011 const std::string &Name = "", ///< A name for the new instruction
2012 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2013 );
2014
2015 /// @brief Constructor with insert-before-instruction semantics
2016 FPTruncInst(
2017 Value *S, ///< The value to be truncated
2018 const Type *Ty, ///< The type to truncate to
2019 const std::string &Name, ///< A name for the new instruction
2020 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2021 );
2022
2023 /// @brief Clone an identical FPTruncInst
2024 virtual CastInst *clone() const;
2025
2026 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2027 static inline bool classof(const FPTruncInst *) { return true; }
2028 static inline bool classof(const Instruction *I) {
2029 return I->getOpcode() == FPTrunc;
2030 }
2031 static inline bool classof(const Value *V) {
2032 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2033 }
2034};
2035
2036//===----------------------------------------------------------------------===//
2037// FPExtInst Class
2038//===----------------------------------------------------------------------===//
2039
2040/// @brief This class represents an extension of floating point types.
2041class FPExtInst : public CastInst {
2042 FPExtInst(const FPExtInst &CI)
2043 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2044 }
2045public:
2046 /// @brief Constructor with insert-before-instruction semantics
2047 FPExtInst(
2048 Value *S, ///< The value to be extended
2049 const Type *Ty, ///< The type to extend to
2050 const std::string &Name = "", ///< A name for the new instruction
2051 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2052 );
2053
2054 /// @brief Constructor with insert-at-end-of-block semantics
2055 FPExtInst(
2056 Value *S, ///< The value to be extended
2057 const Type *Ty, ///< The type to extend to
2058 const std::string &Name, ///< A name for the new instruction
2059 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2060 );
2061
2062 /// @brief Clone an identical FPExtInst
2063 virtual CastInst *clone() const;
2064
2065 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2066 static inline bool classof(const FPExtInst *) { return true; }
2067 static inline bool classof(const Instruction *I) {
2068 return I->getOpcode() == FPExt;
2069 }
2070 static inline bool classof(const Value *V) {
2071 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2072 }
2073};
2074
2075//===----------------------------------------------------------------------===//
2076// UIToFPInst Class
2077//===----------------------------------------------------------------------===//
2078
2079/// @brief This class represents a cast unsigned integer to floating point.
2080class UIToFPInst : public CastInst {
2081 UIToFPInst(const UIToFPInst &CI)
2082 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2083 }
2084public:
2085 /// @brief Constructor with insert-before-instruction semantics
2086 UIToFPInst(
2087 Value *S, ///< The value to be converted
2088 const Type *Ty, ///< The type to convert to
2089 const std::string &Name = "", ///< A name for the new instruction
2090 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2091 );
2092
2093 /// @brief Constructor with insert-at-end-of-block semantics
2094 UIToFPInst(
2095 Value *S, ///< The value to be converted
2096 const Type *Ty, ///< The type to convert to
2097 const std::string &Name, ///< A name for the new instruction
2098 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2099 );
2100
2101 /// @brief Clone an identical UIToFPInst
2102 virtual CastInst *clone() const;
2103
2104 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2105 static inline bool classof(const UIToFPInst *) { return true; }
2106 static inline bool classof(const Instruction *I) {
2107 return I->getOpcode() == UIToFP;
2108 }
2109 static inline bool classof(const Value *V) {
2110 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2111 }
2112};
2113
2114//===----------------------------------------------------------------------===//
2115// SIToFPInst Class
2116//===----------------------------------------------------------------------===//
2117
2118/// @brief This class represents a cast from signed integer to floating point.
2119class SIToFPInst : public CastInst {
2120 SIToFPInst(const SIToFPInst &CI)
2121 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2122 }
2123public:
2124 /// @brief Constructor with insert-before-instruction semantics
2125 SIToFPInst(
2126 Value *S, ///< The value to be converted
2127 const Type *Ty, ///< The type to convert to
2128 const std::string &Name = "", ///< A name for the new instruction
2129 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2130 );
2131
2132 /// @brief Constructor with insert-at-end-of-block semantics
2133 SIToFPInst(
2134 Value *S, ///< The value to be converted
2135 const Type *Ty, ///< The type to convert to
2136 const std::string &Name, ///< A name for the new instruction
2137 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2138 );
2139
2140 /// @brief Clone an identical SIToFPInst
2141 virtual CastInst *clone() const;
2142
2143 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2144 static inline bool classof(const SIToFPInst *) { return true; }
2145 static inline bool classof(const Instruction *I) {
2146 return I->getOpcode() == SIToFP;
2147 }
2148 static inline bool classof(const Value *V) {
2149 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2150 }
2151};
2152
2153//===----------------------------------------------------------------------===//
2154// FPToUIInst Class
2155//===----------------------------------------------------------------------===//
2156
2157/// @brief This class represents a cast from floating point to unsigned integer
2158class FPToUIInst : public CastInst {
2159 FPToUIInst(const FPToUIInst &CI)
2160 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2161 }
2162public:
2163 /// @brief Constructor with insert-before-instruction semantics
2164 FPToUIInst(
2165 Value *S, ///< The value to be converted
2166 const Type *Ty, ///< The type to convert to
2167 const std::string &Name = "", ///< A name for the new instruction
2168 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2169 );
2170
2171 /// @brief Constructor with insert-at-end-of-block semantics
2172 FPToUIInst(
2173 Value *S, ///< The value to be converted
2174 const Type *Ty, ///< The type to convert to
2175 const std::string &Name, ///< A name for the new instruction
2176 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2177 );
2178
2179 /// @brief Clone an identical FPToUIInst
2180 virtual CastInst *clone() const;
2181
2182 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2183 static inline bool classof(const FPToUIInst *) { return true; }
2184 static inline bool classof(const Instruction *I) {
2185 return I->getOpcode() == FPToUI;
2186 }
2187 static inline bool classof(const Value *V) {
2188 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2189 }
2190};
2191
2192//===----------------------------------------------------------------------===//
2193// FPToSIInst Class
2194//===----------------------------------------------------------------------===//
2195
2196/// @brief This class represents a cast from floating point to signed integer.
2197class FPToSIInst : public CastInst {
2198 FPToSIInst(const FPToSIInst &CI)
2199 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2200 }
2201public:
2202 /// @brief Constructor with insert-before-instruction semantics
2203 FPToSIInst(
2204 Value *S, ///< The value to be converted
2205 const Type *Ty, ///< The type to convert to
2206 const std::string &Name = "", ///< A name for the new instruction
2207 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2208 );
2209
2210 /// @brief Constructor with insert-at-end-of-block semantics
2211 FPToSIInst(
2212 Value *S, ///< The value to be converted
2213 const Type *Ty, ///< The type to convert to
2214 const std::string &Name, ///< A name for the new instruction
2215 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2216 );
2217
2218 /// @brief Clone an identical FPToSIInst
2219 virtual CastInst *clone() const;
2220
2221 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2222 static inline bool classof(const FPToSIInst *) { return true; }
2223 static inline bool classof(const Instruction *I) {
2224 return I->getOpcode() == FPToSI;
2225 }
2226 static inline bool classof(const Value *V) {
2227 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2228 }
2229};
2230
2231//===----------------------------------------------------------------------===//
2232// IntToPtrInst Class
2233//===----------------------------------------------------------------------===//
2234
2235/// @brief This class represents a cast from an integer to a pointer.
2236class IntToPtrInst : public CastInst {
2237 IntToPtrInst(const IntToPtrInst &CI)
2238 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2239 }
2240public:
2241 /// @brief Constructor with insert-before-instruction semantics
2242 IntToPtrInst(
2243 Value *S, ///< The value to be converted
2244 const Type *Ty, ///< The type to convert to
2245 const std::string &Name = "", ///< A name for the new instruction
2246 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2247 );
2248
2249 /// @brief Constructor with insert-at-end-of-block semantics
2250 IntToPtrInst(
2251 Value *S, ///< The value to be converted
2252 const Type *Ty, ///< The type to convert to
2253 const std::string &Name, ///< A name for the new instruction
2254 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2255 );
2256
2257 /// @brief Clone an identical IntToPtrInst
2258 virtual CastInst *clone() const;
2259
2260 // Methods for support type inquiry through isa, cast, and dyn_cast:
2261 static inline bool classof(const IntToPtrInst *) { return true; }
2262 static inline bool classof(const Instruction *I) {
2263 return I->getOpcode() == IntToPtr;
2264 }
2265 static inline bool classof(const Value *V) {
2266 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2267 }
2268};
2269
2270//===----------------------------------------------------------------------===//
2271// PtrToIntInst Class
2272//===----------------------------------------------------------------------===//
2273
2274/// @brief This class represents a cast from a pointer to an integer
2275class PtrToIntInst : public CastInst {
2276 PtrToIntInst(const PtrToIntInst &CI)
2277 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2278 }
2279public:
2280 /// @brief Constructor with insert-before-instruction semantics
2281 PtrToIntInst(
2282 Value *S, ///< The value to be converted
2283 const Type *Ty, ///< The type to convert to
2284 const std::string &Name = "", ///< A name for the new instruction
2285 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2286 );
2287
2288 /// @brief Constructor with insert-at-end-of-block semantics
2289 PtrToIntInst(
2290 Value *S, ///< The value to be converted
2291 const Type *Ty, ///< The type to convert to
2292 const std::string &Name, ///< A name for the new instruction
2293 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2294 );
2295
2296 /// @brief Clone an identical PtrToIntInst
2297 virtual CastInst *clone() const;
2298
2299 // Methods for support type inquiry through isa, cast, and dyn_cast:
2300 static inline bool classof(const PtrToIntInst *) { return true; }
2301 static inline bool classof(const Instruction *I) {
2302 return I->getOpcode() == PtrToInt;
2303 }
2304 static inline bool classof(const Value *V) {
2305 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2306 }
2307};
2308
2309//===----------------------------------------------------------------------===//
2310// BitCastInst Class
2311//===----------------------------------------------------------------------===//
2312
2313/// @brief This class represents a no-op cast from one type to another.
2314class BitCastInst : public CastInst {
2315 BitCastInst(const BitCastInst &CI)
2316 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2317 }
2318public:
2319 /// @brief Constructor with insert-before-instruction semantics
2320 BitCastInst(
2321 Value *S, ///< The value to be casted
2322 const Type *Ty, ///< The type to casted to
2323 const std::string &Name = "", ///< A name for the new instruction
2324 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2325 );
2326
2327 /// @brief Constructor with insert-at-end-of-block semantics
2328 BitCastInst(
2329 Value *S, ///< The value to be casted
2330 const Type *Ty, ///< The type to casted to
2331 const std::string &Name, ///< A name for the new instruction
2332 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2333 );
2334
2335 /// @brief Clone an identical BitCastInst
2336 virtual CastInst *clone() const;
2337
2338 // Methods for support type inquiry through isa, cast, and dyn_cast:
2339 static inline bool classof(const BitCastInst *) { return true; }
2340 static inline bool classof(const Instruction *I) {
2341 return I->getOpcode() == BitCast;
2342 }
2343 static inline bool classof(const Value *V) {
2344 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2345 }
2346};
2347
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002348} // End llvm namespace
Chris Lattnera892a3a2003-01-27 22:08:52 +00002349
2350#endif