2003-01-27 22:08:52 +00:00
|
|
|
//===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-01-27 22:08:52 +00:00
|
|
|
//
|
|
|
|
// This file exposes the class definitions of all of the subclasses of the
|
|
|
|
// Instruction class. This is meant to be an easy way to get access to all
|
|
|
|
// instruction subclasses.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_INSTRUCTIONS_H
|
|
|
|
#define LLVM_INSTRUCTIONS_H
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
#include "llvm/InstrTypes.h"
|
2007-08-01 03:43:44 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-09-23 23:03:40 +00:00
|
|
|
#include "llvm/Attributes.h"
|
2009-09-02 08:44:58 +00:00
|
|
|
#include "llvm/CallingConv.h"
|
2008-05-31 00:58:22 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-01-05 17:59:02 +00:00
|
|
|
#include <iterator>
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2005-02-24 05:32:09 +00:00
|
|
|
class ConstantInt;
|
2007-02-28 22:00:54 +00:00
|
|
|
class ConstantRange;
|
|
|
|
class APInt;
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2009-09-03 15:34:35 +00:00
|
|
|
class DominatorTree;
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-23 21:09:37 +00:00
|
|
|
// AllocaInst Class
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-10-23 21:09:37 +00:00
|
|
|
/// AllocaInst - an instruction to allocate memory on the stack
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2009-10-23 21:09:37 +00:00
|
|
|
class AllocaInst : public UnaryInstruction {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual AllocaInst *clone_impl() const;
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2009-10-23 21:09:37 +00:00
|
|
|
explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
|
|
|
|
const Twine &Name = "", Instruction *InsertBefore = 0);
|
|
|
|
AllocaInst(const Type *Ty, Value *ArraySize,
|
|
|
|
const Twine &Name, BasicBlock *InsertAtEnd);
|
|
|
|
|
|
|
|
AllocaInst(const Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
|
|
|
|
AllocaInst(const Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
|
|
|
|
|
|
|
|
AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
|
|
|
|
const Twine &Name = "", Instruction *InsertBefore = 0);
|
|
|
|
AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
|
|
|
|
const Twine &Name, BasicBlock *InsertAtEnd);
|
|
|
|
|
2008-04-06 20:25:17 +00:00
|
|
|
// Out of line virtual method, so the vtable, etc. has a home.
|
2009-10-23 21:09:37 +00:00
|
|
|
virtual ~AllocaInst();
|
2007-12-10 02:14:30 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// isArrayAllocation - Return true if there is an allocation size parameter
|
|
|
|
/// to the allocation instruction that is not 1.
|
|
|
|
///
|
|
|
|
bool isArrayAllocation() const;
|
|
|
|
|
2009-07-07 20:47:48 +00:00
|
|
|
/// getArraySize - Get the number of elements allocated. For a simple
|
2004-07-29 12:17:34 +00:00
|
|
|
/// allocation of a single element, this will return a constant 1 value.
|
|
|
|
///
|
2008-02-23 01:11:02 +00:00
|
|
|
const Value *getArraySize() const { return getOperand(0); }
|
|
|
|
Value *getArraySize() { return getOperand(0); }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
/// getType - Overload to return most specific pointer type
|
|
|
|
///
|
2008-02-23 01:11:02 +00:00
|
|
|
const PointerType *getType() const {
|
2005-04-21 20:19:05 +00:00
|
|
|
return reinterpret_cast<const PointerType*>(Instruction::getType());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getAllocatedType - Return the type that is being allocated by the
|
|
|
|
/// instruction.
|
|
|
|
///
|
|
|
|
const Type *getAllocatedType() const;
|
|
|
|
|
2005-11-05 09:21:28 +00:00
|
|
|
/// getAlignment - Return the alignment of the memory that is being allocated
|
|
|
|
/// by the instruction.
|
|
|
|
///
|
2009-12-29 02:14:09 +00:00
|
|
|
unsigned getAlignment() const {
|
2009-12-29 02:46:09 +00:00
|
|
|
return (1u << getSubclassDataFromInstruction()) >> 1;
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2008-03-24 16:55:58 +00:00
|
|
|
void setAlignment(unsigned Align);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2008-11-26 02:54:17 +00:00
|
|
|
/// isStaticAlloca - Return true if this alloca is in the entry block of the
|
|
|
|
/// function and is a constant size. If so, the code generator will fold it
|
|
|
|
/// into the prolog/epilog code, so it is basically free.
|
|
|
|
bool isStaticAlloca() const;
|
2009-10-23 21:09:37 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const AllocaInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Alloca);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LoadInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-02-05 01:44:18 +00:00
|
|
|
/// LoadInst - an instruction for reading from memory. This uses the
|
|
|
|
/// SubclassData field in Value to store whether or not the load is volatile.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2005-01-29 00:31:36 +00:00
|
|
|
class LoadInst : public UnaryInstruction {
|
|
|
|
void AssertOK();
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual LoadInst *clone_impl() const;
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2009-07-25 04:41:11 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
|
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-08-11 18:11:15 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
|
2007-02-13 07:54:42 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2009-07-25 04:41:11 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
|
2008-07-24 00:08:56 +00:00
|
|
|
unsigned Align, Instruction *InsertBefore = 0);
|
2009-07-25 04:41:11 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
|
2007-07-18 20:51:11 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-07-25 04:41:11 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
|
2008-07-24 00:08:56 +00:00
|
|
|
unsigned Align, BasicBlock *InsertAtEnd);
|
|
|
|
|
2009-08-11 18:11:15 +00:00
|
|
|
LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
|
|
|
|
LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
|
|
|
|
explicit LoadInst(Value *Ptr, const char *NameStr = 0,
|
|
|
|
bool isVolatile = false, Instruction *InsertBefore = 0);
|
|
|
|
LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
|
|
|
|
BasicBlock *InsertAtEnd);
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// isVolatile - Return true if this is a load from a volatile memory
|
|
|
|
/// location.
|
|
|
|
///
|
2009-12-29 02:46:09 +00:00
|
|
|
bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
/// setVolatile - Specify whether this is a volatile load or not.
|
|
|
|
///
|
2009-02-09 17:11:05 +00:00
|
|
|
void setVolatile(bool V) {
|
2009-12-29 02:46:09 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
(V ? 1 : 0));
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2007-04-22 19:24:39 +00:00
|
|
|
/// getAlignment - Return the alignment of the access that is being performed
|
|
|
|
///
|
|
|
|
unsigned getAlignment() const {
|
2009-12-29 02:46:09 +00:00
|
|
|
return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-04-22 19:24:39 +00:00
|
|
|
void setAlignment(unsigned Align);
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
Value *getPointerOperand() { return getOperand(0); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(0); }
|
|
|
|
static unsigned getPointerOperandIndex() { return 0U; }
|
|
|
|
|
2009-08-30 19:45:21 +00:00
|
|
|
unsigned getPointerAddressSpace() const {
|
|
|
|
return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const LoadInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Load;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// StoreInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
/// StoreInst - an instruction for storing to memory
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
|
|
|
class StoreInst : public Instruction {
|
2008-04-06 20:25:17 +00:00
|
|
|
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
2005-01-29 00:31:36 +00:00
|
|
|
void AssertOK();
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual StoreInst *clone_impl() const;
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
|
|
|
|
StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
|
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
|
|
|
|
Instruction *InsertBefore = 0);
|
2007-04-22 19:24:39 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
|
|
|
|
unsigned Align, Instruction *InsertBefore = 0);
|
2004-07-29 12:17:34 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
|
2007-07-18 20:51:11 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
|
|
|
|
unsigned Align, BasicBlock *InsertAtEnd);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// isVolatile - Return true if this is a load from a volatile memory
|
|
|
|
/// location.
|
|
|
|
///
|
2009-12-29 02:46:09 +00:00
|
|
|
bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
/// setVolatile - Specify whether this is a volatile load or not.
|
|
|
|
///
|
2009-02-09 17:11:05 +00:00
|
|
|
void setVolatile(bool V) {
|
2009-12-29 02:46:09 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
(V ? 1 : 0));
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2005-01-29 00:31:36 +00:00
|
|
|
|
2007-04-22 19:24:39 +00:00
|
|
|
/// getAlignment - Return the alignment of the access that is being performed
|
|
|
|
///
|
|
|
|
unsigned getAlignment() const {
|
2009-12-29 02:46:09 +00:00
|
|
|
return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-04-22 19:24:39 +00:00
|
|
|
void setAlignment(unsigned Align);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2010-06-26 23:26:37 +00:00
|
|
|
Value *getValueOperand() { return getOperand(0); }
|
|
|
|
const Value *getValueOperand() const { return getOperand(0); }
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
Value *getPointerOperand() { return getOperand(1); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(1); }
|
|
|
|
static unsigned getPointerOperandIndex() { return 1U; }
|
|
|
|
|
2009-08-30 19:45:21 +00:00
|
|
|
unsigned getPointerAddressSpace() const {
|
|
|
|
return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const StoreInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Store;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<StoreInst> : public FixedNumOperandTraits<2> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// GetElementPtrInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-09-04 15:46:09 +00:00
|
|
|
// checkType - Simple wrapper function to give a better assertion failure
|
|
|
|
// message on bad indexes for a gep instruction.
|
|
|
|
//
|
|
|
|
static inline const Type *checkType(const Type *Ty) {
|
|
|
|
assert(Ty && "Invalid GetElementPtrInst indices for type!");
|
|
|
|
return Ty;
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
|
|
|
|
/// access elements of arrays and structs
|
|
|
|
///
|
|
|
|
class GetElementPtrInst : public Instruction {
|
2008-05-10 08:32:32 +00:00
|
|
|
GetElementPtrInst(const GetElementPtrInst &GEPI);
|
2008-06-05 07:26:15 +00:00
|
|
|
void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr);
|
|
|
|
void init(Value *Ptr, Value *Idx, const Twine &NameStr);
|
2007-09-04 15:46:09 +00:00
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2007-09-04 15:46:09 +00:00
|
|
|
// This argument ensures that we have an iterator we can
|
|
|
|
// do arithmetic on in constant time
|
|
|
|
std::random_access_iterator_tag) {
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-09-04 15:46:09 +00:00
|
|
|
if (NumIdx > 0) {
|
2008-05-10 08:32:32 +00:00
|
|
|
// This requires that the iterator points to contiguous memory.
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
|
2008-05-10 08:32:32 +00:00
|
|
|
// we have to build an array here
|
2007-09-04 15:46:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Ptr, 0, NumIdx, NameStr);
|
2007-09-04 15:46:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getIndexedType - Returns the type of the element that would be loaded with
|
|
|
|
/// a load instruction with the specified parameters.
|
|
|
|
///
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Null is returned if the indices are invalid for the specified
|
2007-09-04 15:46:09 +00:00
|
|
|
/// pointer type.
|
|
|
|
///
|
|
|
|
template<typename InputIterator>
|
|
|
|
static const Type *getIndexedType(const Type *Ptr,
|
2009-02-09 17:11:05 +00:00
|
|
|
InputIterator IdxBegin,
|
2007-09-04 15:46:09 +00:00
|
|
|
InputIterator IdxEnd,
|
|
|
|
// This argument ensures that we
|
|
|
|
// have an iterator we can do
|
|
|
|
// arithmetic on in constant time
|
|
|
|
std::random_access_iterator_tag) {
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
|
2007-09-04 15:46:09 +00:00
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
if (NumIdx > 0)
|
2007-09-04 15:46:09 +00:00
|
|
|
// This requires that the iterator points to contiguous memory.
|
2008-10-29 00:30:54 +00:00
|
|
|
return getIndexedType(Ptr, &*IdxBegin, NumIdx);
|
2008-05-15 19:50:34 +00:00
|
|
|
else
|
|
|
|
return getIndexedType(Ptr, (Value *const*)0, NumIdx);
|
2007-09-04 15:46:09 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// Constructors - Create a getelementptr instruction with a base pointer an
|
|
|
|
/// list of indices. The first ctor can optionally insert before an existing
|
|
|
|
/// instruction, the second appends the new instruction to the specified
|
|
|
|
/// BasicBlock.
|
2007-09-04 15:46:09 +00:00
|
|
|
template<typename InputIterator>
|
2009-02-09 17:11:05 +00:00
|
|
|
inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
|
2008-05-10 08:32:32 +00:00
|
|
|
InputIterator IdxEnd,
|
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2007-09-04 15:46:09 +00:00
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
inline GetElementPtrInst(Value *Ptr,
|
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2007-09-04 15:46:09 +00:00
|
|
|
|
2005-05-03 05:43:30 +00:00
|
|
|
/// Constructors - These two constructors are convenience methods because one
|
|
|
|
/// and two index getelementptr instructions are so common.
|
2009-07-25 04:41:11 +00:00
|
|
|
GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2005-05-03 05:43:30 +00:00
|
|
|
GetElementPtrInst(Value *Ptr, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual GetElementPtrInst *clone_impl() const;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
template<typename InputIterator>
|
2009-02-09 17:11:05 +00:00
|
|
|
static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
|
2008-04-06 20:25:17 +00:00
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-04-06 20:25:17 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2009-02-09 17:11:05 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::difference_type Values =
|
2008-05-10 08:32:32 +00:00
|
|
|
1 + std::distance(IdxBegin, IdxEnd);
|
|
|
|
return new(Values)
|
2008-07-24 00:08:56 +00:00
|
|
|
GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
static GetElementPtrInst *Create(Value *Ptr,
|
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2009-02-09 17:11:05 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::difference_type Values =
|
2008-05-10 08:32:32 +00:00
|
|
|
1 + std::distance(IdxBegin, IdxEnd);
|
|
|
|
return new(Values)
|
2008-07-24 00:08:56 +00:00
|
|
|
GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Constructors - These two creators are convenience methods because one
|
|
|
|
/// index getelementptr instructions are so common.
|
2008-04-06 20:25:17 +00:00
|
|
|
static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
|
|
|
static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-08-11 17:57:01 +00:00
|
|
|
/// Create an "inbounds" getelementptr. See the documentation for the
|
|
|
|
/// "inbounds" flag in LangRef.html for details.
|
|
|
|
template<typename InputIterator>
|
|
|
|
static GetElementPtrInst *CreateInBounds(Value *Ptr, InputIterator IdxBegin,
|
|
|
|
InputIterator IdxEnd,
|
|
|
|
const Twine &NameStr = "",
|
|
|
|
Instruction *InsertBefore = 0) {
|
|
|
|
GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
|
|
|
|
NameStr, InsertBefore);
|
2009-09-07 23:54:19 +00:00
|
|
|
GEP->setIsInBounds(true);
|
2009-08-11 17:57:01 +00:00
|
|
|
return GEP;
|
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
|
|
|
static GetElementPtrInst *CreateInBounds(Value *Ptr,
|
|
|
|
InputIterator IdxBegin,
|
|
|
|
InputIterator IdxEnd,
|
|
|
|
const Twine &NameStr,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
|
|
|
|
NameStr, InsertAtEnd);
|
2009-09-07 23:54:19 +00:00
|
|
|
GEP->setIsInBounds(true);
|
2009-08-11 17:57:01 +00:00
|
|
|
return GEP;
|
|
|
|
}
|
|
|
|
static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
|
|
|
|
const Twine &NameStr = "",
|
|
|
|
Instruction *InsertBefore = 0) {
|
|
|
|
GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
|
2009-09-07 23:54:19 +00:00
|
|
|
GEP->setIsInBounds(true);
|
2009-08-11 17:57:01 +00:00
|
|
|
return GEP;
|
|
|
|
}
|
|
|
|
static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
|
|
|
|
const Twine &NameStr,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
|
2009-09-07 23:54:19 +00:00
|
|
|
GEP->setIsInBounds(true);
|
2009-08-11 17:57:01 +00:00
|
|
|
return GEP;
|
|
|
|
}
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// getType - Overload to return most specific pointer type...
|
2008-02-23 01:11:02 +00:00
|
|
|
const PointerType *getType() const {
|
2004-07-29 12:17:34 +00:00
|
|
|
return reinterpret_cast<const PointerType*>(Instruction::getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getIndexedType - Returns the type of the element that would be loaded with
|
|
|
|
/// a load instruction with the specified parameters.
|
|
|
|
///
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Null is returned if the indices are invalid for the specified
|
2004-07-29 12:17:34 +00:00
|
|
|
/// pointer type.
|
|
|
|
///
|
2007-09-04 15:46:09 +00:00
|
|
|
template<typename InputIterator>
|
2005-04-21 20:19:05 +00:00
|
|
|
static const Type *getIndexedType(const Type *Ptr,
|
2007-09-04 15:46:09 +00:00
|
|
|
InputIterator IdxBegin,
|
2008-05-15 19:50:34 +00:00
|
|
|
InputIterator IdxEnd) {
|
|
|
|
return getIndexedType(Ptr, IdxBegin, IdxEnd,
|
2007-09-04 15:46:09 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::
|
2008-05-15 19:50:34 +00:00
|
|
|
iterator_category());
|
2009-02-09 17:11:05 +00:00
|
|
|
}
|
2008-07-29 08:46:11 +00:00
|
|
|
|
|
|
|
static const Type *getIndexedType(const Type *Ptr,
|
|
|
|
Value* const *Idx, unsigned NumIdx);
|
|
|
|
|
|
|
|
static const Type *getIndexedType(const Type *Ptr,
|
|
|
|
uint64_t const *Idx, unsigned NumIdx);
|
|
|
|
|
2005-05-03 05:43:30 +00:00
|
|
|
static const Type *getIndexedType(const Type *Ptr, Value *Idx);
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
inline op_iterator idx_begin() { return op_begin()+1; }
|
|
|
|
inline const_op_iterator idx_begin() const { return op_begin()+1; }
|
|
|
|
inline op_iterator idx_end() { return op_end(); }
|
|
|
|
inline const_op_iterator idx_end() const { return op_end(); }
|
|
|
|
|
|
|
|
Value *getPointerOperand() {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
const Value *getPointerOperand() const {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
static unsigned getPointerOperandIndex() {
|
|
|
|
return 0U; // get index for modifying correct operand
|
|
|
|
}
|
2009-08-30 20:06:40 +00:00
|
|
|
|
|
|
|
unsigned getPointerAddressSpace() const {
|
|
|
|
return cast<PointerType>(getType())->getAddressSpace();
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2009-01-09 05:27:40 +00:00
|
|
|
/// getPointerOperandType - Method to return the pointer operand as a
|
|
|
|
/// PointerType.
|
|
|
|
const PointerType *getPointerOperandType() const {
|
|
|
|
return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
unsigned getNumIndices() const { // Note: always non-negative
|
2004-07-29 12:17:34 +00:00
|
|
|
return getNumOperands() - 1;
|
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
bool hasIndices() const {
|
2004-07-29 12:17:34 +00:00
|
|
|
return getNumOperands() > 1;
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-04-14 00:12:57 +00:00
|
|
|
/// hasAllZeroIndices - Return true if all of the indices of this GEP are
|
|
|
|
/// zeros. If so, the result pointer and the first operand have the same
|
|
|
|
/// value, just potentially different types.
|
|
|
|
bool hasAllZeroIndices() const;
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-04-27 20:35:56 +00:00
|
|
|
/// hasAllConstantIndices - Return true if all of the indices of this GEP are
|
|
|
|
/// constant integers. If so, the result pointer and the first operand have
|
|
|
|
/// a constant offset between them.
|
|
|
|
bool hasAllConstantIndices() const;
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2009-09-07 23:54:19 +00:00
|
|
|
/// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
|
|
|
|
/// See LangRef.html for the meaning of inbounds on a getelementptr.
|
2009-09-27 21:33:04 +00:00
|
|
|
void setIsInBounds(bool b = true);
|
|
|
|
|
|
|
|
/// isInBounds - Determine whether the GEP has the inbounds flag.
|
|
|
|
bool isInBounds() const;
|
2009-09-07 23:54:19 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const GetElementPtrInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::GetElementPtr);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<1> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
|
2009-02-09 17:11:05 +00:00
|
|
|
InputIterator IdxBegin,
|
2008-05-10 08:32:32 +00:00
|
|
|
InputIterator IdxEnd,
|
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore)
|
|
|
|
: Instruction(PointerType::get(checkType(
|
|
|
|
getIndexedType(Ptr->getType(),
|
2008-05-15 19:50:34 +00:00
|
|
|
IdxBegin, IdxEnd)),
|
2008-05-10 08:32:32 +00:00
|
|
|
cast<PointerType>(Ptr->getType())
|
|
|
|
->getAddressSpace()),
|
|
|
|
GetElementPtr,
|
|
|
|
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
|
|
|
Values, InsertBefore) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Ptr, IdxBegin, IdxEnd, NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
|
|
|
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
|
|
|
|
InputIterator IdxBegin,
|
|
|
|
InputIterator IdxEnd,
|
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
|
|
|
: Instruction(PointerType::get(checkType(
|
|
|
|
getIndexedType(Ptr->getType(),
|
2008-05-15 19:50:34 +00:00
|
|
|
IdxBegin, IdxEnd)),
|
2008-05-10 08:32:32 +00:00
|
|
|
cast<PointerType>(Ptr->getType())
|
|
|
|
->getAddressSpace()),
|
|
|
|
GetElementPtr,
|
|
|
|
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
|
|
|
Values, InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Ptr, IdxBegin, IdxEnd, NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
|
|
|
|
|
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ICmpInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// This instruction compares its operands according to the predicate given
|
2008-05-12 19:01:56 +00:00
|
|
|
/// to the constructor. It only operates on integers or pointers. The operands
|
|
|
|
/// must be identical types.
|
2006-11-20 01:22:35 +00:00
|
|
|
/// @brief Represent an integer comparison operator.
|
|
|
|
class ICmpInst: public CmpInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an indentical ICmpInst
|
|
|
|
virtual ICmpInst *clone_impl() const;
|
2006-11-20 01:22:35 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics.
|
|
|
|
ICmpInst(
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction *InsertBefore, ///< Where to insert
|
2006-11-20 01:22:35 +00:00
|
|
|
Predicate pred, ///< The predicate to use for the comparison
|
|
|
|
Value *LHS, ///< The left-hand-side of the expression
|
|
|
|
Value *RHS, ///< The right-hand-side of the expression
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2008-09-09 01:02:47 +00:00
|
|
|
Instruction::ICmp, pred, LHS, RHS, NameStr,
|
2008-05-12 19:01:56 +00:00
|
|
|
InsertBefore) {
|
|
|
|
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
|
|
|
|
pred <= CmpInst::LAST_ICMP_PREDICATE &&
|
|
|
|
"Invalid ICmp predicate value");
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Both operands to ICmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
|
2010-02-16 11:11:14 +00:00
|
|
|
getOperand(0)->getType()->isPointerTy()) &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Invalid operand types for ICmp instruction");
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 23:48:35 +00:00
|
|
|
/// @brief Constructor with insert-at-end semantics.
|
|
|
|
ICmpInst(
|
|
|
|
BasicBlock &InsertAtEnd, ///< Block to insert into.
|
|
|
|
Predicate pred, ///< The predicate to use for the comparison
|
|
|
|
Value *LHS, ///< The left-hand-side of the expression
|
|
|
|
Value *RHS, ///< The right-hand-side of the expression
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction::ICmp, pred, LHS, RHS, NameStr,
|
|
|
|
&InsertAtEnd) {
|
|
|
|
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
|
|
|
|
pred <= CmpInst::LAST_ICMP_PREDICATE &&
|
|
|
|
"Invalid ICmp predicate value");
|
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
|
|
|
"Both operands to ICmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
|
2010-02-16 11:11:14 +00:00
|
|
|
getOperand(0)->getType()->isPointerTy()) &&
|
2009-07-09 23:48:35 +00:00
|
|
|
"Invalid operand types for ICmp instruction");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Constructor with no-insertion semantics
|
2006-11-20 01:22:35 +00:00
|
|
|
ICmpInst(
|
|
|
|
Predicate pred, ///< The predicate to use for the comparison
|
|
|
|
Value *LHS, ///< The left-hand-side of the expression
|
|
|
|
Value *RHS, ///< The right-hand-side of the expression
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction::ICmp, pred, LHS, RHS, NameStr) {
|
2008-05-12 19:01:56 +00:00
|
|
|
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
|
|
|
|
pred <= CmpInst::LAST_ICMP_PREDICATE &&
|
|
|
|
"Invalid ICmp predicate value");
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Both operands to ICmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
|
2010-02-16 11:11:14 +00:00
|
|
|
getOperand(0)->getType()->isPointerTy()) &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Invalid operand types for ICmp instruction");
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
2006-12-23 06:05:41 +00:00
|
|
|
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
|
|
|
|
/// @returns the predicate that would be the result if the operand were
|
|
|
|
/// regarded as signed.
|
|
|
|
/// @brief Return the signed version of the predicate
|
|
|
|
Predicate getSignedPredicate() const {
|
|
|
|
return getSignedPredicate(getPredicate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This is a static version that you can use without an instruction.
|
|
|
|
/// @brief Return the signed version of the predicate.
|
|
|
|
static Predicate getSignedPredicate(Predicate pred);
|
2006-11-20 01:22:35 +00:00
|
|
|
|
2008-01-28 03:48:02 +00:00
|
|
|
/// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
|
|
|
|
/// @returns the predicate that would be the result if the operand were
|
|
|
|
/// regarded as unsigned.
|
|
|
|
/// @brief Return the unsigned version of the predicate
|
|
|
|
Predicate getUnsignedPredicate() const {
|
|
|
|
return getUnsignedPredicate(getPredicate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This is a static version that you can use without an instruction.
|
|
|
|
/// @brief Return the unsigned version of the predicate.
|
|
|
|
static Predicate getUnsignedPredicate(Predicate pred);
|
|
|
|
|
2007-11-22 23:43:29 +00:00
|
|
|
/// isEquality - Return true if this predicate is either EQ or NE. This also
|
|
|
|
/// tests for commutativity.
|
|
|
|
static bool isEquality(Predicate P) {
|
|
|
|
return P == ICMP_EQ || P == ICMP_NE;
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-11-22 23:43:29 +00:00
|
|
|
/// isEquality - Return true if this predicate is either EQ or NE. This also
|
|
|
|
/// tests for commutativity.
|
2006-11-20 01:22:35 +00:00
|
|
|
bool isEquality() const {
|
2007-11-22 23:43:29 +00:00
|
|
|
return isEquality(getPredicate());
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
2006-12-23 06:05:41 +00:00
|
|
|
|
|
|
|
/// @returns true if the predicate of this ICmpInst is commutative
|
|
|
|
/// @brief Determine if this relation is commutative.
|
2006-11-20 01:22:35 +00:00
|
|
|
bool isCommutative() const { return isEquality(); }
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// isRelational - Return true if the predicate is relational (not EQ or NE).
|
2007-11-22 23:43:29 +00:00
|
|
|
///
|
2006-11-20 01:22:35 +00:00
|
|
|
bool isRelational() const {
|
|
|
|
return !isEquality();
|
|
|
|
}
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// isRelational - Return true if the predicate is relational (not EQ or NE).
|
2007-11-22 23:43:29 +00:00
|
|
|
///
|
|
|
|
static bool isRelational(Predicate P) {
|
|
|
|
return !isEquality(P);
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
|
|
|
/// Initialize a set of values that all satisfy the predicate with C.
|
2007-02-28 22:00:54 +00:00
|
|
|
/// @brief Make a ConstantRange for a relation with a constant value.
|
|
|
|
static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
|
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
/// Exchange the two operands to this instruction in such a way that it does
|
|
|
|
/// not modify the semantics of the instruction. The predicate value may be
|
|
|
|
/// changed to retain the same result if the predicate is order dependent
|
2009-02-09 17:11:05 +00:00
|
|
|
/// (e.g. ult).
|
2006-11-20 01:22:35 +00:00
|
|
|
/// @brief Swap operands and adjust predicate.
|
|
|
|
void swapOperands() {
|
2009-12-29 02:14:09 +00:00
|
|
|
setPredicate(getSwappedPredicate());
|
2008-05-13 22:51:52 +00:00
|
|
|
Op<0>().swap(Op<1>());
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const ICmpInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::ICmp;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2008-09-09 01:02:47 +00:00
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FCmpInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// This instruction compares its operands according to the predicate given
|
2009-02-09 17:11:05 +00:00
|
|
|
/// to the constructor. It only operates on floating point values or packed
|
2006-11-20 01:22:35 +00:00
|
|
|
/// vectors of floating point values. The operands must be identical types.
|
|
|
|
/// @brief Represents a floating point comparison operator.
|
|
|
|
class FCmpInst: public CmpInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an indentical FCmpInst
|
|
|
|
virtual FCmpInst *clone_impl() const;
|
2006-11-20 01:22:35 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics.
|
|
|
|
FCmpInst(
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction *InsertBefore, ///< Where to insert
|
2006-11-20 01:22:35 +00:00
|
|
|
Predicate pred, ///< The predicate to use for the comparison
|
|
|
|
Value *LHS, ///< The left-hand-side of the expression
|
|
|
|
Value *RHS, ///< The right-hand-side of the expression
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2008-09-09 01:02:47 +00:00
|
|
|
Instruction::FCmp, pred, LHS, RHS, NameStr,
|
2008-05-12 19:01:56 +00:00
|
|
|
InsertBefore) {
|
|
|
|
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
|
|
|
|
"Invalid FCmp predicate value");
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Both operands to FCmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Invalid operand types for FCmp instruction");
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
2009-07-09 23:48:35 +00:00
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end semantics.
|
|
|
|
FCmpInst(
|
|
|
|
BasicBlock &InsertAtEnd, ///< Block to insert into.
|
|
|
|
Predicate pred, ///< The predicate to use for the comparison
|
|
|
|
Value *LHS, ///< The left-hand-side of the expression
|
|
|
|
Value *RHS, ///< The right-hand-side of the expression
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction::FCmp, pred, LHS, RHS, NameStr,
|
|
|
|
&InsertAtEnd) {
|
|
|
|
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
|
|
|
|
"Invalid FCmp predicate value");
|
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
|
|
|
"Both operands to FCmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
|
2009-07-09 23:48:35 +00:00
|
|
|
"Invalid operand types for FCmp instruction");
|
|
|
|
}
|
2006-11-20 01:22:35 +00:00
|
|
|
|
2009-07-09 23:48:35 +00:00
|
|
|
/// @brief Constructor with no-insertion semantics
|
2006-11-20 01:22:35 +00:00
|
|
|
FCmpInst(
|
|
|
|
Predicate pred, ///< The predicate to use for the comparison
|
|
|
|
Value *LHS, ///< The left-hand-side of the expression
|
|
|
|
Value *RHS, ///< The right-hand-side of the expression
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction::FCmp, pred, LHS, RHS, NameStr) {
|
2008-05-12 19:01:56 +00:00
|
|
|
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
|
|
|
|
"Invalid FCmp predicate value");
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Both operands to FCmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Invalid operand types for FCmp instruction");
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @returns true if the predicate of this instruction is EQ or NE.
|
|
|
|
/// @brief Determine if this is an equality predicate.
|
|
|
|
bool isEquality() const {
|
2009-12-29 02:14:09 +00:00
|
|
|
return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
|
|
|
|
getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
2008-09-16 16:44:00 +00:00
|
|
|
|
|
|
|
/// @returns true if the predicate of this instruction is commutative.
|
|
|
|
/// @brief Determine if this is a commutative predicate.
|
|
|
|
bool isCommutative() const {
|
|
|
|
return isEquality() ||
|
2009-12-29 02:14:09 +00:00
|
|
|
getPredicate() == FCMP_FALSE ||
|
|
|
|
getPredicate() == FCMP_TRUE ||
|
|
|
|
getPredicate() == FCMP_ORD ||
|
|
|
|
getPredicate() == FCMP_UNO;
|
2008-09-16 16:44:00 +00:00
|
|
|
}
|
2006-11-20 01:22:35 +00:00
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @returns true if the predicate is relational (not EQ or NE).
|
2006-11-20 01:22:35 +00:00
|
|
|
/// @brief Determine if this a relational predicate.
|
|
|
|
bool isRelational() const { return !isEquality(); }
|
|
|
|
|
|
|
|
/// Exchange the two operands to this instruction in such a way that it does
|
|
|
|
/// not modify the semantics of the instruction. The predicate value may be
|
|
|
|
/// changed to retain the same result if the predicate is order dependent
|
2009-02-09 17:11:05 +00:00
|
|
|
/// (e.g. ult).
|
2006-11-20 01:22:35 +00:00
|
|
|
/// @brief Swap operands and adjust predicate.
|
|
|
|
void swapOperands() {
|
2009-12-29 02:14:09 +00:00
|
|
|
setPredicate(getSwappedPredicate());
|
2008-05-13 22:51:52 +00:00
|
|
|
Op<0>().swap(Op<1>());
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const FCmpInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::FCmp;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// CallInst - This class represents a function call, abstracting a target
|
2005-05-06 20:26:26 +00:00
|
|
|
/// machine's calling convention. This class uses low bit of the SubClassData
|
|
|
|
/// field to indicate whether or not this is a tail call. The rest of the bits
|
|
|
|
/// hold the calling convention of the call.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
|
|
|
class CallInst : public Instruction {
|
2008-09-25 21:00:45 +00:00
|
|
|
AttrListPtr AttributeList; ///< parameter attributes for call
|
2004-07-29 12:17:34 +00:00
|
|
|
CallInst(const CallInst &CI);
|
2007-02-13 00:58:44 +00:00
|
|
|
void init(Value *Func, Value* const *Params, unsigned NumParams);
|
2004-07-29 12:17:34 +00:00
|
|
|
void init(Value *Func, Value *Actual1, Value *Actual2);
|
|
|
|
void init(Value *Func, Value *Actual);
|
|
|
|
void init(Value *Func);
|
|
|
|
|
2007-08-01 03:43:44 +00:00
|
|
|
template<typename InputIterator>
|
|
|
|
void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2007-08-01 03:43:44 +00:00
|
|
|
// This argument ensures that we have an iterator we can
|
|
|
|
// do arithmetic on in constant time
|
|
|
|
std::random_access_iterator_tag) {
|
2007-08-29 16:32:50 +00:00
|
|
|
unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-08-29 16:32:50 +00:00
|
|
|
// This requires that the iterator points to contiguous memory.
|
|
|
|
init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2007-08-01 03:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Construct a CallInst given a range of arguments. InputIterator
|
|
|
|
/// must be a random-access iterator pointing to contiguous storage
|
|
|
|
/// (e.g. a std::vector<>::iterator). Checks are made for
|
|
|
|
/// random-accessness but not for contiguous storage as that would
|
|
|
|
/// incur runtime overhead.
|
|
|
|
/// @brief Construct a CallInst from a range of arguments
|
|
|
|
template<typename InputIterator>
|
|
|
|
CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, Instruction *InsertBefore);
|
2007-08-01 03:43:44 +00:00
|
|
|
|
|
|
|
/// Construct a CallInst given a range of arguments. InputIterator
|
|
|
|
/// must be a random-access iterator pointing to contiguous storage
|
|
|
|
/// (e.g. a std::vector<>::iterator). Checks are made for
|
|
|
|
/// random-accessness but not for contiguous storage as that would
|
|
|
|
/// incur runtime overhead.
|
|
|
|
/// @brief Construct a CallInst from a range of arguments
|
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2007-08-01 03:43:44 +00:00
|
|
|
|
2009-07-25 04:41:11 +00:00
|
|
|
CallInst(Value *F, Value *Actual, const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2009-07-25 04:41:11 +00:00
|
|
|
CallInst(Value *F, Value *Actual, const Twine &NameStr,
|
2004-07-29 12:17:34 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-07-25 04:41:11 +00:00
|
|
|
explicit CallInst(Value *F, const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2009-07-25 04:41:11 +00:00
|
|
|
CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual CallInst *clone_impl() const;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
static CallInst *Create(Value *Func,
|
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-05 17:41:03 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2010-07-07 09:29:07 +00:00
|
|
|
return new(unsigned(ArgEnd - ArgBegin + 1))
|
2008-07-24 00:08:56 +00:00
|
|
|
CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
static CallInst *Create(Value *Func,
|
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd) {
|
2010-07-07 09:29:07 +00:00
|
|
|
return new(unsigned(ArgEnd - ArgBegin + 1))
|
2008-07-24 00:08:56 +00:00
|
|
|
CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
static CallInst *Create(Value *F, Value *Actual,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-04-06 20:25:17 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(2) CallInst(F, Actual, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
static CallInst *Create(Value *F, Value *Actual, const Twine &NameStr,
|
2008-04-06 20:25:17 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(2) CallInst(F, Actual, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
static CallInst *Create(Value *F, const Twine &NameStr = "",
|
2008-04-06 20:25:17 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(1) CallInst(F, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
static CallInst *Create(Value *F, const Twine &NameStr,
|
2008-05-05 18:30:58 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(1) CallInst(F, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-09-10 04:36:43 +00:00
|
|
|
/// CreateMalloc - Generate the IR for a call to malloc:
|
|
|
|
/// 1. Compute the malloc call's argument as the specified type's size,
|
|
|
|
/// possibly multiplied by the array size if the array size is not
|
|
|
|
/// constant 1.
|
|
|
|
/// 2. Call malloc with that argument.
|
|
|
|
/// 3. Bitcast the result of the malloc call to the specified type.
|
2009-10-17 23:52:26 +00:00
|
|
|
static Instruction *CreateMalloc(Instruction *InsertBefore,
|
|
|
|
const Type *IntPtrTy, const Type *AllocTy,
|
2009-11-07 00:16:28 +00:00
|
|
|
Value *AllocSize, Value *ArraySize = 0,
|
2010-07-12 00:57:28 +00:00
|
|
|
Function* MallocF = 0,
|
2009-10-17 23:52:26 +00:00
|
|
|
const Twine &Name = "");
|
|
|
|
static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
|
|
|
|
const Type *IntPtrTy, const Type *AllocTy,
|
2009-11-07 00:16:28 +00:00
|
|
|
Value *AllocSize, Value *ArraySize = 0,
|
|
|
|
Function* MallocF = 0,
|
2009-10-17 23:52:26 +00:00
|
|
|
const Twine &Name = "");
|
2009-10-24 04:23:03 +00:00
|
|
|
/// CreateFree - Generate the IR for a call to the builtin free function.
|
2010-07-12 00:57:28 +00:00
|
|
|
static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
|
2009-10-24 04:23:03 +00:00
|
|
|
static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
|
2007-12-10 02:14:30 +00:00
|
|
|
~CallInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-12-29 02:46:09 +00:00
|
|
|
bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
|
2008-07-24 00:08:56 +00:00
|
|
|
void setTailCall(bool isTC = true) {
|
2009-12-29 02:46:09 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
unsigned(isTC));
|
2005-05-06 20:26:26 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 15:44:11 +00:00
|
|
|
/// @deprecated these "define hacks" will go away soon
|
|
|
|
/// @brief coerce out-of-tree code to abandon the low-level interfaces
|
|
|
|
/// @detail see below comments and update your code to high-level interfaces
|
2010-07-13 15:31:36 +00:00
|
|
|
/// - getOperand(0) ---> getCalledValue(), or possibly getCalledFunction
|
|
|
|
/// - setOperand(0, V) ---> setCalledFunction(V)
|
|
|
|
///
|
2010-07-06 15:44:11 +00:00
|
|
|
/// in LLVM v2.8-only code
|
|
|
|
/// - getOperand(N+1) ---> getArgOperand(N)
|
|
|
|
/// - setOperand(N+1, V) ---> setArgOperand(N, V)
|
|
|
|
/// - getNumOperands() ---> getNumArgOperands()+1 // note the "+1"!
|
|
|
|
///
|
|
|
|
/// in backward compatible code please consult llvm/Support/CallSite.h,
|
|
|
|
/// you should create a callsite using the CallInst pointer and call its
|
|
|
|
/// methods
|
|
|
|
///
|
|
|
|
# define public private
|
|
|
|
# define protected private
|
2008-09-26 21:38:45 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2010-07-06 15:44:11 +00:00
|
|
|
# undef public
|
|
|
|
# undef protected
|
|
|
|
public:
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2010-06-07 19:05:06 +00:00
|
|
|
unsigned getNumArgOperands() const { return getNumOperands() - 1; }
|
2010-07-16 09:38:02 +00:00
|
|
|
Value *getArgOperand(unsigned i) const { return getOperand(i); }
|
|
|
|
void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
|
2010-06-07 19:05:06 +00:00
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
/// getCallingConv/setCallingConv - Get or set the calling convention of this
|
|
|
|
/// function call.
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID getCallingConv() const {
|
2009-12-29 02:46:09 +00:00
|
|
|
return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
|
2009-09-02 08:44:58 +00:00
|
|
|
}
|
|
|
|
void setCallingConv(CallingConv::ID CC) {
|
2009-12-29 02:46:09 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
|
|
|
|
(static_cast<unsigned>(CC) << 1));
|
2005-05-06 20:26:26 +00:00
|
|
|
}
|
2005-05-06 05:51:46 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// getAttributes - Return the parameter attributes for this call.
|
2008-03-13 04:33:03 +00:00
|
|
|
///
|
2008-09-25 21:00:45 +00:00
|
|
|
const AttrListPtr &getAttributes() const { return AttributeList; }
|
2007-04-09 15:01:12 +00:00
|
|
|
|
2008-09-26 21:38:45 +00:00
|
|
|
/// setAttributes - Set the parameter attributes for this call.
|
|
|
|
///
|
2008-09-25 21:00:45 +00:00
|
|
|
void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// addAttribute - adds the attribute to the list of attributes.
|
|
|
|
void addAttribute(unsigned i, Attributes attr);
|
2007-11-27 13:23:08 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// removeAttribute - removes the attribute from the list of attributes.
|
|
|
|
void removeAttribute(unsigned i, Attributes attr);
|
2008-07-08 08:38:44 +00:00
|
|
|
|
2007-11-28 17:07:01 +00:00
|
|
|
/// @brief Determine whether the call or the callee has the given attribute.
|
2008-09-26 21:38:45 +00:00
|
|
|
bool paramHasAttr(unsigned i, Attributes attr) const;
|
2007-11-28 17:07:01 +00:00
|
|
|
|
2008-02-22 17:49:45 +00:00
|
|
|
/// @brief Extract the alignment for a call or parameter (0=unknown).
|
2008-03-13 05:00:21 +00:00
|
|
|
unsigned getParamAlignment(unsigned i) const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttributeList.getParamAlignment(i);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2010-03-25 04:49:10 +00:00
|
|
|
|
|
|
|
/// @brief Return true if the call should not be inlined.
|
|
|
|
bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
|
2010-07-06 03:53:22 +00:00
|
|
|
void setIsNoInline(bool Value = true) {
|
2010-03-25 04:49:10 +00:00
|
|
|
if (Value) addAttribute(~0, Attribute::NoInline);
|
|
|
|
else removeAttribute(~0, Attribute::NoInline);
|
|
|
|
}
|
2008-02-22 17:49:45 +00:00
|
|
|
|
2007-12-03 20:06:50 +00:00
|
|
|
/// @brief Determine if the call does not access memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotAccessMemory() const {
|
2008-09-26 22:53:05 +00:00
|
|
|
return paramHasAttr(~0, Attribute::ReadNone);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
void setDoesNotAccessMemory(bool NotAccessMemory = true) {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
|
|
|
|
else removeAttribute(~0, Attribute::ReadNone);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
|
|
|
|
2007-12-03 20:06:50 +00:00
|
|
|
/// @brief Determine if the call does not access or only reads memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool onlyReadsMemory() const {
|
2008-09-26 22:53:05 +00:00
|
|
|
return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
|
|
|
|
else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
|
|
|
|
2007-12-10 19:09:40 +00:00
|
|
|
/// @brief Determine if the call cannot return.
|
2010-07-06 03:53:22 +00:00
|
|
|
bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
|
2008-07-24 00:08:56 +00:00
|
|
|
void setDoesNotReturn(bool DoesNotReturn = true) {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
|
|
|
|
else removeAttribute(~0, Attribute::NoReturn);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-10 19:09:40 +00:00
|
|
|
|
2007-12-03 20:06:50 +00:00
|
|
|
/// @brief Determine if the call cannot unwind.
|
2010-07-06 03:53:22 +00:00
|
|
|
bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
|
2008-07-24 00:08:56 +00:00
|
|
|
void setDoesNotThrow(bool DoesNotThrow = true) {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
|
|
|
|
else removeAttribute(~0, Attribute::NoUnwind);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @brief Determine if the call returns a structure through first
|
2008-03-03 21:46:28 +00:00
|
|
|
/// pointer argument.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool hasStructRetAttr() const {
|
|
|
|
// Be friendly and also check the callee.
|
2008-09-25 21:00:45 +00:00
|
|
|
return paramHasAttr(1, Attribute::StructRet);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2007-04-09 15:01:12 +00:00
|
|
|
|
2008-01-12 18:57:32 +00:00
|
|
|
/// @brief Determine if any call argument is an aggregate passed by value.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool hasByValArgument() const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttributeList.hasAttrSomewhere(Attribute::ByVal);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-01-12 18:57:32 +00:00
|
|
|
|
2008-09-26 21:38:45 +00:00
|
|
|
/// getCalledFunction - Return the function called, or null if this is an
|
|
|
|
/// indirect function invocation.
|
|
|
|
///
|
2004-11-18 17:46:57 +00:00
|
|
|
Function *getCalledFunction() const {
|
2010-07-16 09:38:02 +00:00
|
|
|
return dyn_cast<Function>(Op<-1>());
|
2004-11-18 17:46:57 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// getCalledValue - Get a pointer to the function that is invoked by this
|
2009-10-18 05:08:07 +00:00
|
|
|
/// instruction.
|
2010-07-16 09:38:02 +00:00
|
|
|
const Value *getCalledValue() const { return Op<-1>(); }
|
|
|
|
Value *getCalledValue() { return Op<-1>(); }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-10-18 05:08:07 +00:00
|
|
|
/// setCalledFunction - Set the function called.
|
2009-10-17 00:00:19 +00:00
|
|
|
void setCalledFunction(Value* Fn) {
|
2010-07-16 09:38:02 +00:00
|
|
|
Op<-1>() = Fn;
|
2009-10-17 00:00:19 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const CallInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2005-04-21 20:19:05 +00:00
|
|
|
return I->getOpcode() == Instruction::Call;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<CallInst> : public VariadicOperandTraits<1> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Call,
|
|
|
|
OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
|
2010-06-29 16:27:38 +00:00
|
|
|
unsigned(ArgEnd - ArgBegin + 1), InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Func, ArgBegin, ArgEnd, NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, Instruction *InsertBefore)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Call,
|
|
|
|
OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
|
2010-07-07 09:29:07 +00:00
|
|
|
unsigned(ArgEnd - ArgBegin + 1), InsertBefore) {
|
2009-02-09 17:11:05 +00:00
|
|
|
init(Func, ArgBegin, ArgEnd, NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
|
2010-07-06 15:44:11 +00:00
|
|
|
|
|
|
|
// Note: if you get compile errors about private methods then
|
|
|
|
// please update your code to use the high-level operand
|
|
|
|
// interfaces. See line 943 above.
|
2008-05-10 08:32:32 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SelectInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// SelectInst - This class represents the LLVM 'select' instruction.
|
|
|
|
///
|
|
|
|
class SelectInst : public Instruction {
|
|
|
|
void init(Value *C, Value *S1, Value *S2) {
|
2008-12-29 00:12:50 +00:00
|
|
|
assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
|
2008-05-10 08:32:32 +00:00
|
|
|
Op<0>() = C;
|
|
|
|
Op<1>() = S1;
|
|
|
|
Op<2>() = S2;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:41:11 +00:00
|
|
|
SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore)
|
|
|
|
: Instruction(S1->getType(), Instruction::Select,
|
|
|
|
&Op<0>(), 3, InsertBefore) {
|
2004-07-29 12:17:34 +00:00
|
|
|
init(C, S1, S2);
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
|
2004-07-29 12:17:34 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(S1->getType(), Instruction::Select,
|
|
|
|
&Op<0>(), 3, InsertAtEnd) {
|
2004-07-29 12:17:34 +00:00
|
|
|
init(C, S1, S2);
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual SelectInst *clone_impl() const;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2008-05-05 17:41:03 +00:00
|
|
|
static SelectInst *Create(Value *C, Value *S1, Value *S2,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-05 17:41:03 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-05 17:41:03 +00:00
|
|
|
static SelectInst *Create(Value *C, Value *S1, Value *S2,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-07-24 00:08:56 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-09-08 03:32:53 +00:00
|
|
|
const Value *getCondition() const { return Op<0>(); }
|
|
|
|
const Value *getTrueValue() const { return Op<1>(); }
|
|
|
|
const Value *getFalseValue() const { return Op<2>(); }
|
|
|
|
Value *getCondition() { return Op<0>(); }
|
|
|
|
Value *getTrueValue() { return Op<1>(); }
|
|
|
|
Value *getFalseValue() { return Op<2>(); }
|
|
|
|
|
2008-12-29 00:12:50 +00:00
|
|
|
/// areInvalidOperands - Return a string if the specified operands are invalid
|
|
|
|
/// for a select operation, otherwise return null.
|
|
|
|
static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
|
2005-01-29 00:31:36 +00:00
|
|
|
|
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
OtherOps getOpcode() const {
|
|
|
|
return static_cast<OtherOps>(Instruction::getOpcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SelectInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Select;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VAArgInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// VAArgInst - This class represents the va_arg llvm instruction, which returns
|
2005-06-18 18:31:30 +00:00
|
|
|
/// an argument of the specified type given a va_list and increments that list
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2005-01-29 00:31:36 +00:00
|
|
|
class VAArgInst : public UnaryInstruction {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual VAArgInst *clone_impl() const;
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2009-07-25 04:41:11 +00:00
|
|
|
VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
|
2004-07-29 12:17:34 +00:00
|
|
|
Instruction *InsertBefore = 0)
|
2007-02-24 00:55:48 +00:00
|
|
|
: UnaryInstruction(Ty, VAArg, List, InsertBefore) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
|
2004-07-29 12:17:34 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2007-02-24 00:55:48 +00:00
|
|
|
: UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const VAArgInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == VAArg;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-01-10 19:04:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ExtractElementInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ExtractElementInst - This instruction extracts a single (scalar)
|
2007-02-15 02:26:10 +00:00
|
|
|
/// element from a VectorType value
|
2006-01-10 19:04:13 +00:00
|
|
|
///
|
|
|
|
class ExtractElementInst : public Instruction {
|
2009-07-25 04:41:11 +00:00
|
|
|
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
|
2006-04-08 01:15:18 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2009-07-25 04:41:11 +00:00
|
|
|
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
|
2006-04-08 01:15:18 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual ExtractElementInst *clone_impl() const;
|
|
|
|
|
2009-07-25 02:28:41 +00:00
|
|
|
public:
|
|
|
|
static ExtractElementInst *Create(Value *Vec, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2009-07-25 02:28:41 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
|
|
|
return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
|
|
|
|
}
|
|
|
|
static ExtractElementInst *Create(Value *Vec, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2009-07-25 02:28:41 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
|
|
|
|
}
|
2006-01-10 19:04:13 +00:00
|
|
|
|
2006-04-08 04:04:54 +00:00
|
|
|
/// isValidOperands - Return true if an extractelement instruction can be
|
|
|
|
/// formed with the specified operands.
|
|
|
|
static bool isValidOperands(const Value *Vec, const Value *Idx);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2009-09-08 03:32:53 +00:00
|
|
|
Value *getVectorOperand() { return Op<0>(); }
|
|
|
|
Value *getIndexOperand() { return Op<1>(); }
|
|
|
|
const Value *getVectorOperand() const { return Op<0>(); }
|
|
|
|
const Value *getIndexOperand() const { return Op<1>(); }
|
|
|
|
|
|
|
|
const VectorType *getVectorOperandType() const {
|
2009-09-08 03:39:55 +00:00
|
|
|
return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
|
2009-09-08 03:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-10 19:04:13 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2006-01-10 19:04:13 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const ExtractElementInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::ExtractElement;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
|
|
|
|
|
2006-01-17 20:05:59 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InsertElementInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// InsertElementInst - This instruction inserts a single (scalar)
|
2007-02-15 02:26:10 +00:00
|
|
|
/// element into a VectorType value
|
2006-01-17 20:05:59 +00:00
|
|
|
///
|
|
|
|
class InsertElementInst : public Instruction {
|
2006-04-08 01:15:18 +00:00
|
|
|
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2009-02-09 17:11:05 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2006-04-08 01:15:18 +00:00
|
|
|
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual InsertElementInst *clone_impl() const;
|
|
|
|
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
|
|
|
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-05 17:41:03 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2006-01-17 20:05:59 +00:00
|
|
|
|
2006-04-08 04:04:54 +00:00
|
|
|
/// isValidOperands - Return true if an insertelement instruction can be
|
|
|
|
/// formed with the specified operands.
|
|
|
|
static bool isValidOperands(const Value *Vec, const Value *NewElt,
|
|
|
|
const Value *Idx);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2007-02-15 03:39:18 +00:00
|
|
|
/// getType - Overload to return most specific vector type.
|
2006-04-14 22:20:07 +00:00
|
|
|
///
|
2008-02-23 01:11:02 +00:00
|
|
|
const VectorType *getType() const {
|
2007-02-15 02:26:10 +00:00
|
|
|
return reinterpret_cast<const VectorType*>(Instruction::getType());
|
2006-04-14 22:20:07 +00:00
|
|
|
}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-01-17 20:05:59 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2006-01-17 20:05:59 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const InsertElementInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::InsertElement;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
|
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ShuffleVectorInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
|
|
|
|
/// input vectors.
|
|
|
|
///
|
|
|
|
class ShuffleVectorInst : public Instruction {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual ShuffleVectorInst *clone_impl() const;
|
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly three operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 3);
|
|
|
|
}
|
2006-04-08 01:15:18 +00:00
|
|
|
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-07-24 00:08:56 +00:00
|
|
|
Instruction *InsertBefor = 0);
|
2006-04-08 01:15:18 +00:00
|
|
|
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-04-08 04:04:54 +00:00
|
|
|
/// isValidOperands - Return true if a shufflevector instruction can be
|
2006-04-08 01:15:18 +00:00
|
|
|
/// formed with the specified operands.
|
|
|
|
static bool isValidOperands(const Value *V1, const Value *V2,
|
|
|
|
const Value *Mask);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2007-02-15 03:39:18 +00:00
|
|
|
/// getType - Overload to return most specific vector type.
|
2006-04-14 22:20:07 +00:00
|
|
|
///
|
2008-02-23 01:11:02 +00:00
|
|
|
const VectorType *getType() const {
|
2007-02-15 02:26:10 +00:00
|
|
|
return reinterpret_cast<const VectorType*>(Instruction::getType());
|
2006-04-14 22:20:07 +00:00
|
|
|
}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-03-02 05:28:33 +00:00
|
|
|
/// getMaskValue - Return the index from the shuffle mask for the specified
|
|
|
|
/// output result. This is either -1 if the element is undef or a number less
|
|
|
|
/// than 2*numelements.
|
|
|
|
int getMaskValue(unsigned i) const;
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const ShuffleVectorInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::ShuffleVector;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
|
2006-04-08 01:15:18 +00:00
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ExtractValueInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-05-15 23:35:32 +00:00
|
|
|
/// ExtractValueInst - This instruction extracts a struct member or array
|
|
|
|
/// element value from an aggregate value.
|
2008-05-15 19:50:34 +00:00
|
|
|
///
|
2008-06-06 20:28:12 +00:00
|
|
|
class ExtractValueInst : public UnaryInstruction {
|
2008-05-31 00:58:22 +00:00
|
|
|
SmallVector<unsigned, 4> Indices;
|
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
ExtractValueInst(const ExtractValueInst &EVI);
|
2008-06-06 21:06:32 +00:00
|
|
|
void init(const unsigned *Idx, unsigned NumIdx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr);
|
|
|
|
void init(unsigned Idx, const Twine &NameStr);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
template<typename InputIterator>
|
2008-06-06 21:06:32 +00:00
|
|
|
void init(InputIterator IdxBegin, InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
// This argument ensures that we have an iterator we can
|
|
|
|
// do arithmetic on in constant time
|
|
|
|
std::random_access_iterator_tag) {
|
|
|
|
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-31 00:58:22 +00:00
|
|
|
// There's no fundamental reason why we require at least one index
|
|
|
|
// (other than weirdness with &*IdxBegin being invalid; see
|
|
|
|
// getelementptr's init routine for example). But there's no
|
|
|
|
// present need to support it.
|
|
|
|
assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
|
|
|
|
|
|
|
|
// This requires that the iterator points to contiguous memory.
|
2008-07-24 00:08:56 +00:00
|
|
|
init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
|
2008-06-04 14:40:55 +00:00
|
|
|
// we have to build an array here
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getIndexedType - Returns the type of the element that would be extracted
|
|
|
|
/// with an extractvalue instruction with the specified parameters.
|
|
|
|
///
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Null is returned if the indices are invalid for the specified
|
2008-05-15 19:50:34 +00:00
|
|
|
/// pointer type.
|
|
|
|
///
|
|
|
|
static const Type *getIndexedType(const Type *Agg,
|
2008-05-31 00:58:22 +00:00
|
|
|
const unsigned *Idx, unsigned NumIdx);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
static const Type *getIndexedType(const Type *Ptr,
|
2009-02-09 17:11:05 +00:00
|
|
|
InputIterator IdxBegin,
|
2008-05-15 19:50:34 +00:00
|
|
|
InputIterator IdxEnd,
|
|
|
|
// This argument ensures that we
|
|
|
|
// have an iterator we can do
|
|
|
|
// arithmetic on in constant time
|
|
|
|
std::random_access_iterator_tag) {
|
|
|
|
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
|
|
|
|
|
|
|
|
if (NumIdx > 0)
|
|
|
|
// This requires that the iterator points to contiguous memory.
|
2008-06-23 16:38:10 +00:00
|
|
|
return getIndexedType(Ptr, &*IdxBegin, NumIdx);
|
2008-05-15 19:50:34 +00:00
|
|
|
else
|
2008-05-31 00:58:22 +00:00
|
|
|
return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Constructors - Create a extractvalue instruction with a base aggregate
|
|
|
|
/// value and a list of indices. The first ctor can optionally insert before
|
|
|
|
/// an existing instruction, the second appends the new instruction to the
|
|
|
|
/// specified BasicBlock.
|
2008-05-15 19:50:34 +00:00
|
|
|
template<typename InputIterator>
|
2009-02-09 17:11:05 +00:00
|
|
|
inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
|
2008-05-15 19:50:34 +00:00
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
Instruction *InsertBefore);
|
|
|
|
template<typename InputIterator>
|
|
|
|
inline ExtractValueInst(Value *Agg,
|
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
2008-05-31 19:09:47 +00:00
|
|
|
// allocate space for exactly one operand
|
2008-05-31 00:58:22 +00:00
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 1);
|
|
|
|
}
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual ExtractValueInst *clone_impl() const;
|
2008-05-31 00:58:22 +00:00
|
|
|
|
2008-06-06 20:28:12 +00:00
|
|
|
public:
|
2008-05-15 19:50:34 +00:00
|
|
|
template<typename InputIterator>
|
2009-02-09 17:11:05 +00:00
|
|
|
static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
|
2008-05-15 19:50:34 +00:00
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-15 19:50:34 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-05-31 00:58:22 +00:00
|
|
|
return new
|
2008-07-24 00:08:56 +00:00
|
|
|
ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
|
|
|
static ExtractValueInst *Create(Value *Agg,
|
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Constructors - These two creators are convenience methods because one
|
|
|
|
/// index extractvalue instructions are much more common than those with
|
|
|
|
/// more than one.
|
2008-05-31 00:58:22 +00:00
|
|
|
static ExtractValueInst *Create(Value *Agg, unsigned Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-15 19:50:34 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-06-23 16:48:17 +00:00
|
|
|
unsigned Idxs[1] = { Idx };
|
2008-07-24 00:08:56 +00:00
|
|
|
return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
2008-05-31 00:58:22 +00:00
|
|
|
static ExtractValueInst *Create(Value *Agg, unsigned Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-06-23 16:48:17 +00:00
|
|
|
unsigned Idxs[1] = { Idx };
|
2008-07-24 00:08:56 +00:00
|
|
|
return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getIndexedType - Returns the type of the element that would be extracted
|
|
|
|
/// with an extractvalue instruction with the specified parameters.
|
|
|
|
///
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Null is returned if the indices are invalid for the specified
|
2008-05-15 19:50:34 +00:00
|
|
|
/// pointer type.
|
|
|
|
///
|
|
|
|
template<typename InputIterator>
|
|
|
|
static const Type *getIndexedType(const Type *Ptr,
|
|
|
|
InputIterator IdxBegin,
|
|
|
|
InputIterator IdxEnd) {
|
|
|
|
return getIndexedType(Ptr, IdxBegin, IdxEnd,
|
|
|
|
typename std::iterator_traits<InputIterator>::
|
|
|
|
iterator_category());
|
2009-02-09 17:11:05 +00:00
|
|
|
}
|
2008-05-31 00:58:22 +00:00
|
|
|
static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
2008-06-19 17:15:57 +00:00
|
|
|
typedef const unsigned* idx_iterator;
|
|
|
|
inline idx_iterator idx_begin() const { return Indices.begin(); }
|
|
|
|
inline idx_iterator idx_end() const { return Indices.end(); }
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
Value *getAggregateOperand() {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
const Value *getAggregateOperand() const {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
static unsigned getAggregateOperandIndex() {
|
|
|
|
return 0U; // get index for modifying correct operand
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumIndices() const { // Note: always non-negative
|
2008-06-05 07:35:27 +00:00
|
|
|
return (unsigned)Indices.size();
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasIndices() const {
|
2008-05-31 19:09:08 +00:00
|
|
|
return true;
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const ExtractValueInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::ExtractValue;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-23 00:36:11 +00:00
|
|
|
template<typename InputIterator>
|
|
|
|
ExtractValueInst::ExtractValueInst(Value *Agg,
|
2009-02-09 17:11:05 +00:00
|
|
|
InputIterator IdxBegin,
|
2008-05-23 00:36:11 +00:00
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
Instruction *InsertBefore)
|
2008-06-06 20:28:12 +00:00
|
|
|
: UnaryInstruction(checkType(getIndexedType(Agg->getType(),
|
2008-07-22 07:14:12 +00:00
|
|
|
IdxBegin, IdxEnd)),
|
|
|
|
ExtractValue, Agg, InsertBefore) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(IdxBegin, IdxEnd, NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
|
|
|
ExtractValueInst::ExtractValueInst(Value *Agg,
|
|
|
|
InputIterator IdxBegin,
|
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2008-06-06 20:28:12 +00:00
|
|
|
: UnaryInstruction(checkType(getIndexedType(Agg->getType(),
|
2008-07-22 07:14:12 +00:00
|
|
|
IdxBegin, IdxEnd)),
|
|
|
|
ExtractValue, Agg, InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(IdxBegin, IdxEnd, NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InsertValueInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-05-15 23:35:32 +00:00
|
|
|
/// InsertValueInst - This instruction inserts a struct field of array element
|
|
|
|
/// value into an aggregate value.
|
2008-05-15 19:50:34 +00:00
|
|
|
///
|
|
|
|
class InsertValueInst : public Instruction {
|
2008-05-31 00:58:22 +00:00
|
|
|
SmallVector<unsigned, 4> Indices;
|
|
|
|
|
|
|
|
void *operator new(size_t, unsigned); // Do not implement
|
2008-05-15 19:50:34 +00:00
|
|
|
InsertValueInst(const InsertValueInst &IVI);
|
2008-06-05 07:26:15 +00:00
|
|
|
void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr);
|
|
|
|
void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
void init(Value *Agg, Value *Val,
|
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
// This argument ensures that we have an iterator we can
|
|
|
|
// do arithmetic on in constant time
|
|
|
|
std::random_access_iterator_tag) {
|
|
|
|
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-31 00:58:22 +00:00
|
|
|
// There's no fundamental reason why we require at least one index
|
|
|
|
// (other than weirdness with &*IdxBegin being invalid; see
|
|
|
|
// getelementptr's init routine for example). But there's no
|
|
|
|
// present need to support it.
|
|
|
|
assert(NumIdx > 0 && "InsertValueInst must have at least one index");
|
|
|
|
|
|
|
|
// This requires that the iterator points to contiguous memory.
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
|
2008-06-04 14:40:55 +00:00
|
|
|
// we have to build an array here
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Constructors - Create a insertvalue instruction with a base aggregate
|
|
|
|
/// value, a value to insert, and a list of indices. The first ctor can
|
|
|
|
/// optionally insert before an existing instruction, the second appends
|
|
|
|
/// the new instruction to the specified BasicBlock.
|
2008-05-15 19:50:34 +00:00
|
|
|
template<typename InputIterator>
|
2009-02-09 17:11:05 +00:00
|
|
|
inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
|
2008-05-15 23:35:32 +00:00
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 23:35:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2008-05-15 19:50:34 +00:00
|
|
|
template<typename InputIterator>
|
|
|
|
inline InsertValueInst(Value *Agg, Value *Val,
|
2008-05-15 23:35:32 +00:00
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
/// Constructors - These two constructors are convenience methods because one
|
|
|
|
/// and two index insertvalue instructions are so common.
|
|
|
|
InsertValueInst(Value *Agg, Value *Val,
|
2009-07-25 04:41:11 +00:00
|
|
|
unsigned Idx, const Twine &NameStr = "",
|
2008-05-15 19:50:34 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2008-05-31 00:58:22 +00:00
|
|
|
InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual InsertValueInst *clone_impl() const;
|
2008-05-15 19:50:34 +00:00
|
|
|
public:
|
2008-05-31 00:58:22 +00:00
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
template<typename InputIterator>
|
2008-06-05 07:26:15 +00:00
|
|
|
static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
|
2008-05-15 19:50:34 +00:00
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-15 19:50:34 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-05-31 00:58:22 +00:00
|
|
|
return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
|
2008-07-24 00:08:56 +00:00
|
|
|
NameStr, InsertBefore);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
|
|
|
static InsertValueInst *Create(Value *Agg, Value *Val,
|
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-05-31 00:58:22 +00:00
|
|
|
return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
|
2008-07-24 00:08:56 +00:00
|
|
|
NameStr, InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Constructors - These two creators are convenience methods because one
|
|
|
|
/// index insertvalue instructions are much more common than those with
|
|
|
|
/// more than one.
|
2008-05-31 00:58:22 +00:00
|
|
|
static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-15 19:50:34 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
2008-05-31 00:58:22 +00:00
|
|
|
static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2008-06-19 17:15:57 +00:00
|
|
|
typedef const unsigned* idx_iterator;
|
|
|
|
inline idx_iterator idx_begin() const { return Indices.begin(); }
|
|
|
|
inline idx_iterator idx_end() const { return Indices.end(); }
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
Value *getAggregateOperand() {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
const Value *getAggregateOperand() const {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
static unsigned getAggregateOperandIndex() {
|
|
|
|
return 0U; // get index for modifying correct operand
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *getInsertedValueOperand() {
|
|
|
|
return getOperand(1);
|
|
|
|
}
|
|
|
|
const Value *getInsertedValueOperand() const {
|
|
|
|
return getOperand(1);
|
|
|
|
}
|
|
|
|
static unsigned getInsertedValueOperandIndex() {
|
|
|
|
return 1U; // get index for modifying correct operand
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumIndices() const { // Note: always non-negative
|
2008-06-05 07:35:27 +00:00
|
|
|
return (unsigned)Indices.size();
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasIndices() const {
|
2008-05-31 19:09:08 +00:00
|
|
|
return true;
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const InsertValueInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::InsertValue;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
|
2008-05-15 19:50:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-23 00:36:11 +00:00
|
|
|
template<typename InputIterator>
|
|
|
|
InsertValueInst::InsertValueInst(Value *Agg,
|
|
|
|
Value *Val,
|
2009-02-09 17:11:05 +00:00
|
|
|
InputIterator IdxBegin,
|
2008-05-23 00:36:11 +00:00
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
Instruction *InsertBefore)
|
2008-05-31 00:58:22 +00:00
|
|
|
: Instruction(Agg->getType(), InsertValue,
|
|
|
|
OperandTraits<InsertValueInst>::op_begin(this),
|
|
|
|
2, InsertBefore) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Agg, Val, IdxBegin, IdxEnd, NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
|
|
|
InsertValueInst::InsertValueInst(Value *Agg,
|
|
|
|
Value *Val,
|
|
|
|
InputIterator IdxBegin,
|
|
|
|
InputIterator IdxEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2008-05-31 00:58:22 +00:00
|
|
|
: Instruction(Agg->getType(), InsertValue,
|
|
|
|
OperandTraits<InsertValueInst>::op_begin(this),
|
|
|
|
2, InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Agg, Val, IdxBegin, IdxEnd, NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PHINode Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// PHINode - The PHINode class is used to represent the magical mystical PHI
|
|
|
|
// node, that can not exist in nature, but can be synthesized in a computer
|
|
|
|
// scientist's overactive imagination.
|
|
|
|
//
|
|
|
|
class PHINode : public Instruction {
|
2008-04-06 20:25:17 +00:00
|
|
|
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
2005-01-29 00:31:36 +00:00
|
|
|
/// ReservedSpace - The number of operands actually allocated. NumOperands is
|
|
|
|
/// the number actually in use.
|
|
|
|
unsigned ReservedSpace;
|
2004-07-29 12:17:34 +00:00
|
|
|
PHINode(const PHINode &PN);
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
explicit PHINode(const Type *Ty, const Twine &NameStr = "",
|
2006-10-03 17:09:12 +00:00
|
|
|
Instruction *InsertBefore = 0)
|
2007-02-24 00:55:48 +00:00
|
|
|
: Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
|
2005-01-29 00:31:36 +00:00
|
|
|
ReservedSpace(0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:41:11 +00:00
|
|
|
PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
|
2007-02-24 00:55:48 +00:00
|
|
|
: Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
|
2005-01-29 00:31:36 +00:00
|
|
|
ReservedSpace(0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2005-01-29 00:31:36 +00:00
|
|
|
}
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual PHINode *clone_impl() const;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2009-07-25 04:41:11 +00:00
|
|
|
static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
|
2008-04-06 20:25:17 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new PHINode(Ty, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
static PHINode *Create(const Type *Ty, const Twine &NameStr,
|
2008-05-05 17:41:03 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new PHINode(Ty, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2007-12-10 02:14:30 +00:00
|
|
|
~PHINode();
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
/// reserveOperandSpace - This method can be used to avoid repeated
|
|
|
|
/// reallocation of PHI operand lists by reserving space for the correct
|
|
|
|
/// number of operands before adding them. Unlike normal vector reserves,
|
|
|
|
/// this method can also be used to trim the operand space.
|
|
|
|
void reserveOperandSpace(unsigned NumValues) {
|
|
|
|
resizeOperands(NumValues*2);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// getNumIncomingValues - Return the number of incoming edges
|
|
|
|
///
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumIncomingValues() const { return getNumOperands()/2; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2006-05-19 19:07:54 +00:00
|
|
|
/// getIncomingValue - Return incoming value number x
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
|
|
|
Value *getIncomingValue(unsigned i) const {
|
2005-01-29 00:31:36 +00:00
|
|
|
assert(i*2 < getNumOperands() && "Invalid value number!");
|
|
|
|
return getOperand(i*2);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
void setIncomingValue(unsigned i, Value *V) {
|
2005-01-29 00:31:36 +00:00
|
|
|
assert(i*2 < getNumOperands() && "Invalid value number!");
|
|
|
|
setOperand(i*2, V);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-03-23 15:48:29 +00:00
|
|
|
static unsigned getOperandNumForIncomingValue(unsigned i) {
|
2004-07-29 12:17:34 +00:00
|
|
|
return i*2;
|
|
|
|
}
|
2009-03-23 15:48:29 +00:00
|
|
|
static unsigned getIncomingValueNumForOperand(unsigned i) {
|
|
|
|
assert(i % 2 == 0 && "Invalid incoming-value operand index!");
|
|
|
|
return i/2;
|
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// getIncomingBlock - Return incoming basic block number @p i.
|
2009-10-10 07:42:42 +00:00
|
|
|
///
|
|
|
|
BasicBlock *getIncomingBlock(unsigned i) const {
|
2009-10-10 08:01:27 +00:00
|
|
|
return cast<BasicBlock>(getOperand(i*2+1));
|
2009-10-10 07:42:42 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 19:40:15 +00:00
|
|
|
/// getIncomingBlock - Return incoming basic block corresponding
|
2009-10-10 07:42:42 +00:00
|
|
|
/// to an operand of the PHI.
|
2009-01-23 19:40:15 +00:00
|
|
|
///
|
2009-10-10 07:42:42 +00:00
|
|
|
BasicBlock *getIncomingBlock(const Use &U) const {
|
|
|
|
assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
|
2009-10-10 08:01:27 +00:00
|
|
|
return cast<BasicBlock>((&U + 1)->get());
|
2009-01-23 19:40:15 +00:00
|
|
|
}
|
2009-10-10 07:42:42 +00:00
|
|
|
|
|
|
|
/// getIncomingBlock - Return incoming basic block corresponding
|
|
|
|
/// to value use iterator.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2009-10-10 07:42:42 +00:00
|
|
|
template <typename U>
|
|
|
|
BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
|
|
|
|
return getIncomingBlock(I.getUse());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-10-10 07:42:42 +00:00
|
|
|
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
void setIncomingBlock(unsigned i, BasicBlock *BB) {
|
2009-10-27 16:49:53 +00:00
|
|
|
setOperand(i*2+1, (Value*)BB);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-03-23 15:48:29 +00:00
|
|
|
static unsigned getOperandNumForIncomingBlock(unsigned i) {
|
2004-07-29 12:17:34 +00:00
|
|
|
return i*2+1;
|
|
|
|
}
|
2009-03-23 15:48:29 +00:00
|
|
|
static unsigned getIncomingBlockNumForOperand(unsigned i) {
|
|
|
|
assert(i % 2 == 1 && "Invalid incoming-block operand index!");
|
|
|
|
return i/2;
|
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
/// addIncoming - Add an incoming value to the end of the PHI list
|
|
|
|
///
|
|
|
|
void addIncoming(Value *V, BasicBlock *BB) {
|
2008-02-27 22:37:28 +00:00
|
|
|
assert(V && "PHI node got a null value!");
|
|
|
|
assert(BB && "PHI node got a null basic block!");
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(getType() == V->getType() &&
|
|
|
|
"All operands to PHI node must be the same type as the PHI node!");
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned OpNo = NumOperands;
|
|
|
|
if (OpNo+2 > ReservedSpace)
|
|
|
|
resizeOperands(0); // Get more space!
|
|
|
|
// Initialize some new operands.
|
|
|
|
NumOperands = OpNo+2;
|
2008-05-26 21:33:52 +00:00
|
|
|
OperandList[OpNo] = V;
|
2009-10-27 16:49:53 +00:00
|
|
|
OperandList[OpNo+1] = (Value*)BB;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// removeIncomingValue - Remove an incoming value. This is useful if a
|
|
|
|
/// predecessor basic block is deleted. The value removed is returned.
|
|
|
|
///
|
|
|
|
/// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
|
|
|
|
/// is true), the PHI node is destroyed and any uses of it are replaced with
|
|
|
|
/// dummy values. The only time there should be zero incoming values to a PHI
|
|
|
|
/// node is when the block is dead, so this strategy is sound.
|
|
|
|
///
|
|
|
|
Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
|
2004-07-29 12:17:34 +00:00
|
|
|
int Idx = getBasicBlockIndex(BB);
|
|
|
|
assert(Idx >= 0 && "Invalid basic block argument to remove!");
|
|
|
|
return removeIncomingValue(Idx, DeletePHIIfEmpty);
|
|
|
|
}
|
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
/// getBasicBlockIndex - Return the first index of the specified basic
|
2004-07-29 12:17:34 +00:00
|
|
|
/// block in the value list for this PHI. Returns -1 if no instance.
|
|
|
|
///
|
|
|
|
int getBasicBlockIndex(const BasicBlock *BB) const {
|
2005-01-29 00:31:36 +00:00
|
|
|
Use *OL = OperandList;
|
2005-04-21 20:19:05 +00:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
|
2009-10-27 16:49:53 +00:00
|
|
|
if (OL[i+1].get() == (const Value*)BB) return i/2;
|
2004-07-29 12:17:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *getIncomingValueForBlock(const BasicBlock *BB) const {
|
|
|
|
return getIncomingValue(getBasicBlockIndex(BB));
|
|
|
|
}
|
|
|
|
|
2006-10-03 17:09:12 +00:00
|
|
|
/// hasConstantValue - If the specified PHI node always merges together the
|
2005-08-04 23:24:19 +00:00
|
|
|
/// same value, return the value, otherwise return null.
|
|
|
|
///
|
2009-09-03 15:34:35 +00:00
|
|
|
/// If the PHI has undef operands, but all the rest of the operands are
|
|
|
|
/// some unique value, return that value if it can be proved that the
|
|
|
|
/// value dominates the PHI. If DT is null, use a conservative check,
|
|
|
|
/// otherwise use DT to test for dominance.
|
|
|
|
///
|
|
|
|
Value *hasConstantValue(DominatorTree *DT = 0) const;
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const PHINode *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2005-04-21 20:19:05 +00:00
|
|
|
return I->getOpcode() == Instruction::PHI;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
|
|
|
void resizeOperands(unsigned NumOperands);
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
|
2008-05-10 08:32:32 +00:00
|
|
|
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ReturnInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// ReturnInst - Return a value (possibly void), from a function. Execution
|
|
|
|
/// does not continue in this function any longer.
|
|
|
|
///
|
|
|
|
class ReturnInst : public TerminatorInst {
|
2007-02-24 00:55:48 +00:00
|
|
|
ReturnInst(const ReturnInst &RI);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-04-06 20:25:17 +00:00
|
|
|
private:
|
2004-07-29 12:17:34 +00:00
|
|
|
// ReturnInst constructors:
|
|
|
|
// ReturnInst() - 'ret void' instruction
|
2004-11-17 21:02:25 +00:00
|
|
|
// ReturnInst( null) - 'ret void' instruction
|
2004-07-29 12:17:34 +00:00
|
|
|
// ReturnInst(Value* X) - 'ret X' instruction
|
2008-05-10 08:32:32 +00:00
|
|
|
// ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
|
2004-07-29 12:17:34 +00:00
|
|
|
// ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
|
2008-05-10 08:32:32 +00:00
|
|
|
// ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
|
|
|
|
// ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
|
2004-11-17 21:02:25 +00:00
|
|
|
//
|
|
|
|
// NOTE: If the Value* passed is of type void then the constructor behaves as
|
|
|
|
// if it was passed NULL.
|
2009-08-13 21:58:54 +00:00
|
|
|
explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
|
|
|
|
Instruction *InsertBefore = 0);
|
|
|
|
ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
|
|
|
|
explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual ReturnInst *clone_impl() const;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2009-08-13 21:58:54 +00:00
|
|
|
static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
|
|
|
|
Instruction *InsertBefore = 0) {
|
|
|
|
return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-08-13 21:58:54 +00:00
|
|
|
static ReturnInst* Create(LLVMContext &C, Value *retVal,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-08-13 21:58:54 +00:00
|
|
|
static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
|
|
|
|
return new(0) ReturnInst(C, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-02-23 00:35:18 +00:00
|
|
|
virtual ~ReturnInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2008-02-26 17:56:20 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Convenience accessor
|
2008-03-11 17:35:03 +00:00
|
|
|
Value *getReturnValue(unsigned n = 0) const {
|
2008-05-10 08:32:32 +00:00
|
|
|
return n < getNumOperands()
|
|
|
|
? getOperand(n)
|
|
|
|
: 0;
|
2008-03-11 17:35:03 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 0; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const ReturnInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Ret);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
|
|
|
virtual BasicBlock *getSuccessorV(unsigned idx) const;
|
|
|
|
virtual unsigned getNumSuccessorsV() const;
|
|
|
|
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2010-03-16 10:59:48 +00:00
|
|
|
struct OperandTraits<ReturnInst> : public VariadicOperandTraits<> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BranchInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// BranchInst - Conditional or Unconditional Branch instruction.
|
|
|
|
///
|
|
|
|
class BranchInst : public TerminatorInst {
|
2005-01-29 00:31:36 +00:00
|
|
|
/// Ops list - Branches are strange. The operands are ordered:
|
2009-03-12 18:34:49 +00:00
|
|
|
/// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
|
|
|
|
/// they don't have to check for cond/uncond branchness. These are mostly
|
|
|
|
/// accessed relative from op_end().
|
2004-07-29 12:17:34 +00:00
|
|
|
BranchInst(const BranchInst &BI);
|
2005-01-29 00:31:36 +00:00
|
|
|
void AssertOK();
|
2004-07-29 12:17:34 +00:00
|
|
|
// BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
|
|
|
|
// BranchInst(BB *B) - 'br B'
|
|
|
|
// BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
|
|
|
|
// BranchInst(BB* B, Inst *I) - 'br B' insert before I
|
|
|
|
// BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
|
|
|
|
// BranchInst(BB* B, BB *I) - 'br B' insert at end
|
|
|
|
// BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
|
2007-02-24 00:55:48 +00:00
|
|
|
explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
|
2004-07-29 12:17:34 +00:00
|
|
|
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
|
2007-02-24 00:55:48 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
|
|
|
BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
|
2004-07-29 12:17:34 +00:00
|
|
|
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
|
2007-02-24 00:55:48 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual BranchInst *clone_impl() const;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
|
2009-03-12 18:34:49 +00:00
|
|
|
return new(1, true) BranchInst(IfTrue, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
|
|
|
|
Value *Cond, Instruction *InsertBefore = 0) {
|
2008-04-06 20:25:17 +00:00
|
|
|
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
|
|
|
|
}
|
|
|
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
|
2009-03-12 18:34:49 +00:00
|
|
|
return new(1, true) BranchInst(IfTrue, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
|
|
|
|
Value *Cond, BasicBlock *InsertAtEnd) {
|
2008-04-06 20:25:17 +00:00
|
|
|
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
|
2009-03-12 18:34:49 +00:00
|
|
|
~BranchInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
bool isUnconditional() const { return getNumOperands() == 1; }
|
|
|
|
bool isConditional() const { return getNumOperands() == 3; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
Value *getCondition() const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(isConditional() && "Cannot get condition of an uncond branch!");
|
2009-03-12 18:34:49 +00:00
|
|
|
return Op<-3>();
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setCondition(Value *V) {
|
|
|
|
assert(isConditional() && "Cannot set condition of unconditional branch!");
|
2009-03-12 18:34:49 +00:00
|
|
|
Op<-3>() = V;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setUnconditionalDest - Change the current branch to an unconditional branch
|
|
|
|
// targeting the specified block.
|
2005-01-29 00:31:36 +00:00
|
|
|
// FIXME: Eliminate this ugly method.
|
2004-07-29 12:17:34 +00:00
|
|
|
void setUnconditionalDest(BasicBlock *Dest) {
|
2009-10-27 16:49:53 +00:00
|
|
|
Op<-1>() = (Value*)Dest;
|
2005-01-29 00:31:36 +00:00
|
|
|
if (isConditional()) { // Convert this to an uncond branch.
|
2009-03-12 18:34:49 +00:00
|
|
|
Op<-2>() = 0;
|
|
|
|
Op<-3>() = 0;
|
2005-01-29 00:31:36 +00:00
|
|
|
NumOperands = 1;
|
2009-03-12 18:34:49 +00:00
|
|
|
OperandList = op_begin();
|
2005-01-29 00:31:36 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 1+isConditional(); }
|
|
|
|
|
|
|
|
BasicBlock *getSuccessor(unsigned i) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
|
2009-03-12 18:34:49 +00:00
|
|
|
return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
|
2009-10-27 16:49:53 +00:00
|
|
|
*(&Op<-1>() - idx) = (Value*)NewSucc;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const BranchInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Br);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
|
|
|
virtual BasicBlock *getSuccessorV(unsigned idx) const;
|
|
|
|
virtual unsigned getNumSuccessorsV() const;
|
|
|
|
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
|
2008-05-10 08:32:32 +00:00
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SwitchInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// SwitchInst - Multiway switch
|
|
|
|
///
|
|
|
|
class SwitchInst : public TerminatorInst {
|
2008-05-10 08:32:32 +00:00
|
|
|
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned ReservedSpace;
|
2004-07-29 12:17:34 +00:00
|
|
|
// Operand[0] = Value to switch on
|
|
|
|
// Operand[1] = Default basic block destination
|
|
|
|
// Operand[2n ] = Value to match
|
|
|
|
// Operand[2n+1] = BasicBlock to go to on match
|
2009-10-27 19:13:16 +00:00
|
|
|
SwitchInst(const SwitchInst &SI);
|
2005-01-29 00:31:36 +00:00
|
|
|
void init(Value *Value, BasicBlock *Default, unsigned NumCases);
|
|
|
|
void resizeOperands(unsigned No);
|
2008-05-10 08:32:32 +00:00
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
/// SwitchInst ctor - Create a new switch instruction, specifying a value to
|
|
|
|
/// switch on and a default destination. The number of additional cases can
|
|
|
|
/// be specified here to make memory allocation more efficient. This
|
|
|
|
/// constructor can also autoinsert before another instruction.
|
|
|
|
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
|
2009-10-27 19:13:16 +00:00
|
|
|
Instruction *InsertBefore);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
/// SwitchInst ctor - Create a new switch instruction, specifying a value to
|
|
|
|
/// switch on and a default destination. The number of additional cases can
|
|
|
|
/// be specified here to make memory allocation more efficient. This
|
|
|
|
/// constructor also autoinserts at the end of the specified BasicBlock.
|
|
|
|
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
|
2007-02-24 00:55:48 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual SwitchInst *clone_impl() const;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2008-05-10 08:32:32 +00:00
|
|
|
static SwitchInst *Create(Value *Value, BasicBlock *Default,
|
|
|
|
unsigned NumCases, Instruction *InsertBefore = 0) {
|
|
|
|
return new SwitchInst(Value, Default, NumCases, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
static SwitchInst *Create(Value *Value, BasicBlock *Default,
|
|
|
|
unsigned NumCases, BasicBlock *InsertAtEnd) {
|
|
|
|
return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2007-12-10 02:14:30 +00:00
|
|
|
~SwitchInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Accessor Methods for Switch stmt
|
2008-02-23 01:11:02 +00:00
|
|
|
Value *getCondition() const { return getOperand(0); }
|
2005-01-29 00:31:36 +00:00
|
|
|
void setCondition(Value *V) { setOperand(0, V); }
|
2004-12-10 20:35:47 +00:00
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
BasicBlock *getDefaultDest() const {
|
2005-01-29 00:31:36 +00:00
|
|
|
return cast<BasicBlock>(getOperand(1));
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getNumCases - return the number of 'cases' in this switch instruction.
|
|
|
|
/// Note that case #0 is always the default case.
|
|
|
|
unsigned getNumCases() const {
|
2005-01-29 00:31:36 +00:00
|
|
|
return getNumOperands()/2;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getCaseValue - Return the specified case value. Note that case #0, the
|
|
|
|
/// default destination, does not have a case value.
|
2005-02-24 05:32:09 +00:00
|
|
|
ConstantInt *getCaseValue(unsigned i) {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(i && i < getNumCases() && "Illegal case value to get!");
|
|
|
|
return getSuccessorValue(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getCaseValue - Return the specified case value. Note that case #0, the
|
|
|
|
/// default destination, does not have a case value.
|
2005-02-24 05:32:09 +00:00
|
|
|
const ConstantInt *getCaseValue(unsigned i) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(i && i < getNumCases() && "Illegal case value to get!");
|
|
|
|
return getSuccessorValue(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// findCaseValue - Search all of the case values for the specified constant.
|
|
|
|
/// If it is explicitly handled, return the case number of it, otherwise
|
|
|
|
/// return 0 to indicate that it is handled by the default handler.
|
2005-02-24 05:32:09 +00:00
|
|
|
unsigned findCaseValue(const ConstantInt *C) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
for (unsigned i = 1, e = getNumCases(); i != e; ++i)
|
|
|
|
if (getCaseValue(i) == C)
|
|
|
|
return i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-18 19:03:59 +00:00
|
|
|
/// findCaseDest - Finds the unique case value for a given successor. Returns
|
|
|
|
/// null if the successor is not found, not unique, or is the default case.
|
|
|
|
ConstantInt *findCaseDest(BasicBlock *BB) {
|
2006-09-18 20:44:37 +00:00
|
|
|
if (BB == getDefaultDest()) return NULL;
|
|
|
|
|
2006-09-18 19:03:59 +00:00
|
|
|
ConstantInt *CI = NULL;
|
|
|
|
for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
|
|
|
|
if (getSuccessor(i) == BB) {
|
|
|
|
if (CI) return NULL; // Multiple cases lead to BB.
|
|
|
|
else CI = getCaseValue(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// addCase - Add an entry to the switch instruction...
|
|
|
|
///
|
2005-02-24 05:32:09 +00:00
|
|
|
void addCase(ConstantInt *OnVal, BasicBlock *Dest);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
/// removeCase - This method removes the specified successor from the switch
|
|
|
|
/// instruction. Note that this cannot be used to remove the default
|
|
|
|
/// destination (successor #0).
|
|
|
|
///
|
|
|
|
void removeCase(unsigned idx);
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return getNumOperands()/2; }
|
|
|
|
BasicBlock *getSuccessor(unsigned idx) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
|
2005-01-29 00:31:36 +00:00
|
|
|
return cast<BasicBlock>(getOperand(idx*2+1));
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
|
2009-10-27 16:49:53 +00:00
|
|
|
setOperand(idx*2+1, (Value*)NewSucc);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getSuccessorValue - Return the value associated with the specified
|
|
|
|
// successor.
|
2008-02-23 01:11:02 +00:00
|
|
|
ConstantInt *getSuccessorValue(unsigned idx) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range!");
|
2005-05-15 16:13:11 +00:00
|
|
|
return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SwitchInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2005-02-24 05:32:09 +00:00
|
|
|
return I->getOpcode() == Instruction::Switch;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
|
|
|
virtual BasicBlock *getSuccessorV(unsigned idx) const;
|
|
|
|
virtual unsigned getNumSuccessorsV() const;
|
|
|
|
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
|
2008-05-10 08:32:32 +00:00
|
|
|
|
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-28 00:19:10 +00:00
|
|
|
// IndirectBrInst Class
|
2009-10-27 19:13:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
2009-10-28 00:19:10 +00:00
|
|
|
/// IndirectBrInst - Indirect Branch Instruction.
|
2009-10-27 19:13:16 +00:00
|
|
|
///
|
2009-10-28 00:19:10 +00:00
|
|
|
class IndirectBrInst : public TerminatorInst {
|
2009-10-27 19:13:16 +00:00
|
|
|
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
|
|
|
unsigned ReservedSpace;
|
|
|
|
// Operand[0] = Value to switch on
|
|
|
|
// Operand[1] = Default basic block destination
|
|
|
|
// Operand[2n ] = Value to match
|
|
|
|
// Operand[2n+1] = BasicBlock to go to on match
|
2009-10-28 00:19:10 +00:00
|
|
|
IndirectBrInst(const IndirectBrInst &IBI);
|
2009-10-27 19:13:16 +00:00
|
|
|
void init(Value *Address, unsigned NumDests);
|
|
|
|
void resizeOperands(unsigned No);
|
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2009-10-28 00:19:10 +00:00
|
|
|
/// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
|
|
|
|
/// Address to jump to. The number of expected destinations can be specified
|
|
|
|
/// here to make memory allocation more efficient. This constructor can also
|
2009-10-27 19:13:16 +00:00
|
|
|
/// autoinsert before another instruction.
|
2009-10-28 00:19:10 +00:00
|
|
|
IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
|
2009-10-27 19:13:16 +00:00
|
|
|
|
2009-10-28 00:19:10 +00:00
|
|
|
/// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
|
|
|
|
/// Address to jump to. The number of expected destinations can be specified
|
|
|
|
/// here to make memory allocation more efficient. This constructor also
|
|
|
|
/// autoinserts at the end of the specified BasicBlock.
|
|
|
|
IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2009-10-28 00:19:10 +00:00
|
|
|
virtual IndirectBrInst *clone_impl() const;
|
2009-10-27 19:13:16 +00:00
|
|
|
public:
|
2009-10-28 00:19:10 +00:00
|
|
|
static IndirectBrInst *Create(Value *Address, unsigned NumDests,
|
|
|
|
Instruction *InsertBefore = 0) {
|
|
|
|
return new IndirectBrInst(Address, NumDests, InsertBefore);
|
2009-10-27 19:13:16 +00:00
|
|
|
}
|
2009-10-28 00:19:10 +00:00
|
|
|
static IndirectBrInst *Create(Value *Address, unsigned NumDests,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return new IndirectBrInst(Address, NumDests, InsertAtEnd);
|
2009-10-27 19:13:16 +00:00
|
|
|
}
|
2009-10-28 00:19:10 +00:00
|
|
|
~IndirectBrInst();
|
2009-10-27 19:13:16 +00:00
|
|
|
|
|
|
|
/// Provide fast operand accessors.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2009-10-28 00:19:10 +00:00
|
|
|
// Accessor Methods for IndirectBrInst instruction.
|
2009-10-27 19:13:16 +00:00
|
|
|
Value *getAddress() { return getOperand(0); }
|
|
|
|
const Value *getAddress() const { return getOperand(0); }
|
|
|
|
void setAddress(Value *V) { setOperand(0, V); }
|
|
|
|
|
|
|
|
|
|
|
|
/// getNumDestinations - return the number of possible destinations in this
|
2009-10-28 00:19:10 +00:00
|
|
|
/// indirectbr instruction.
|
2009-10-27 19:13:16 +00:00
|
|
|
unsigned getNumDestinations() const { return getNumOperands()-1; }
|
|
|
|
|
|
|
|
/// getDestination - Return the specified destination.
|
|
|
|
BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
|
|
|
|
const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
|
|
|
|
|
|
|
|
/// addDestination - Add a destination.
|
|
|
|
///
|
|
|
|
void addDestination(BasicBlock *Dest);
|
|
|
|
|
|
|
|
/// removeDestination - This method removes the specified successor from the
|
2009-10-28 00:19:10 +00:00
|
|
|
/// indirectbr instruction.
|
2009-10-27 19:13:16 +00:00
|
|
|
void removeDestination(unsigned i);
|
|
|
|
|
|
|
|
unsigned getNumSuccessors() const { return getNumOperands()-1; }
|
|
|
|
BasicBlock *getSuccessor(unsigned i) const {
|
|
|
|
return cast<BasicBlock>(getOperand(i+1));
|
|
|
|
}
|
|
|
|
void setSuccessor(unsigned i, BasicBlock *NewSucc) {
|
|
|
|
setOperand(i+1, (Value*)NewSucc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-10-28 00:19:10 +00:00
|
|
|
static inline bool classof(const IndirectBrInst *) { return true; }
|
2009-10-27 19:13:16 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
2009-10-28 00:19:10 +00:00
|
|
|
return I->getOpcode() == Instruction::IndirectBr;
|
2009-10-27 19:13:16 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
virtual BasicBlock *getSuccessorV(unsigned idx) const;
|
|
|
|
virtual unsigned getNumSuccessorsV() const;
|
|
|
|
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2009-10-28 00:19:10 +00:00
|
|
|
struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
|
2009-10-27 19:13:16 +00:00
|
|
|
};
|
|
|
|
|
2009-10-28 00:19:10 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
|
2009-10-27 19:13:16 +00:00
|
|
|
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InvokeInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
|
|
|
|
/// calling convention of the call.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
|
|
|
class InvokeInst : public TerminatorInst {
|
2008-09-25 21:00:45 +00:00
|
|
|
AttrListPtr AttributeList;
|
2004-07-29 12:17:34 +00:00
|
|
|
InvokeInst(const InvokeInst &BI);
|
|
|
|
void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
|
2007-02-13 01:04:01 +00:00
|
|
|
Value* const *Args, unsigned NumArgs);
|
2007-08-27 19:04:21 +00:00
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
|
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2007-08-27 19:04:21 +00:00
|
|
|
// This argument ensures that we have an iterator we can
|
|
|
|
// do arithmetic on in constant time
|
|
|
|
std::random_access_iterator_tag) {
|
2007-08-29 16:32:50 +00:00
|
|
|
unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-08-29 16:32:50 +00:00
|
|
|
// This requires that the iterator points to contiguous memory.
|
|
|
|
init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2007-08-27 19:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Construct an InvokeInst given a range of arguments.
|
|
|
|
/// InputIterator must be a random-access iterator pointing to
|
|
|
|
/// contiguous storage (e.g. a std::vector<>::iterator). Checks are
|
|
|
|
/// made for random-accessness but not for contiguous storage as
|
|
|
|
/// that would incur runtime overhead.
|
|
|
|
///
|
|
|
|
/// @brief Construct an InvokeInst from a range of arguments
|
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
|
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, Instruction *InsertBefore);
|
2007-08-27 19:04:21 +00:00
|
|
|
|
|
|
|
/// Construct an InvokeInst given a range of arguments.
|
|
|
|
/// InputIterator must be a random-access iterator pointing to
|
|
|
|
/// contiguous storage (e.g. a std::vector<>::iterator). Checks are
|
|
|
|
/// made for random-accessness but not for contiguous storage as
|
|
|
|
/// that would incur runtime overhead.
|
|
|
|
///
|
|
|
|
/// @brief Construct an InvokeInst from a range of arguments
|
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
|
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual InvokeInst *clone_impl() const;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
static InvokeInst *Create(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
2008-04-06 20:25:17 +00:00
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2008-05-05 17:41:03 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-05-10 08:32:32 +00:00
|
|
|
unsigned Values(ArgEnd - ArgBegin + 3);
|
|
|
|
return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
|
2008-07-24 00:08:56 +00:00
|
|
|
Values, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
2008-05-10 08:32:32 +00:00
|
|
|
static InvokeInst *Create(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
2008-04-06 20:25:17 +00:00
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-07-24 00:08:56 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-05-10 08:32:32 +00:00
|
|
|
unsigned Values(ArgEnd - ArgBegin + 3);
|
|
|
|
return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
|
2008-07-24 00:08:56 +00:00
|
|
|
Values, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2007-08-27 19:04:21 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2010-06-07 19:05:06 +00:00
|
|
|
unsigned getNumArgOperands() const { return getNumOperands() - 3; }
|
|
|
|
Value *getArgOperand(unsigned i) const { return getOperand(i); }
|
2010-06-28 12:23:36 +00:00
|
|
|
void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
|
2010-06-07 19:05:06 +00:00
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
/// getCallingConv/setCallingConv - Get or set the calling convention of this
|
|
|
|
/// function call.
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID getCallingConv() const {
|
2009-12-29 02:46:09 +00:00
|
|
|
return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
|
2009-09-02 08:44:58 +00:00
|
|
|
}
|
|
|
|
void setCallingConv(CallingConv::ID CC) {
|
2009-12-29 02:46:09 +00:00
|
|
|
setInstructionSubclassData(static_cast<unsigned>(CC));
|
2005-05-06 20:26:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// getAttributes - Return the parameter attributes for this invoke.
|
2008-03-12 17:45:29 +00:00
|
|
|
///
|
2008-09-25 21:00:45 +00:00
|
|
|
const AttrListPtr &getAttributes() const { return AttributeList; }
|
2007-04-09 18:00:57 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// setAttributes - Set the parameter attributes for this invoke.
|
2008-03-12 17:45:29 +00:00
|
|
|
///
|
2008-09-25 21:00:45 +00:00
|
|
|
void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
|
2007-11-27 13:23:08 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// addAttribute - adds the attribute to the list of attributes.
|
|
|
|
void addAttribute(unsigned i, Attributes attr);
|
2007-11-28 17:07:01 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// removeAttribute - removes the attribute from the list of attributes.
|
|
|
|
void removeAttribute(unsigned i, Attributes attr);
|
2008-07-08 08:38:44 +00:00
|
|
|
|
2008-09-26 21:38:45 +00:00
|
|
|
/// @brief Determine whether the call or the callee has the given attribute.
|
|
|
|
bool paramHasAttr(unsigned i, Attributes attr) const;
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-02-22 17:49:45 +00:00
|
|
|
/// @brief Extract the alignment for a call or parameter (0=unknown).
|
2008-03-13 05:00:21 +00:00
|
|
|
unsigned getParamAlignment(unsigned i) const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttributeList.getParamAlignment(i);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-02-22 17:49:45 +00:00
|
|
|
|
2010-03-25 04:49:10 +00:00
|
|
|
/// @brief Return true if the call should not be inlined.
|
|
|
|
bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
|
2010-07-06 03:53:22 +00:00
|
|
|
void setIsNoInline(bool Value = true) {
|
2010-03-25 04:49:10 +00:00
|
|
|
if (Value) addAttribute(~0, Attribute::NoInline);
|
|
|
|
else removeAttribute(~0, Attribute::NoInline);
|
|
|
|
}
|
2010-07-06 03:53:22 +00:00
|
|
|
|
2007-12-03 20:06:50 +00:00
|
|
|
/// @brief Determine if the call does not access memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotAccessMemory() const {
|
2009-07-17 16:12:36 +00:00
|
|
|
return paramHasAttr(~0, Attribute::ReadNone);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
void setDoesNotAccessMemory(bool NotAccessMemory = true) {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
|
|
|
|
else removeAttribute(~0, Attribute::ReadNone);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
|
|
|
/// @brief Determine if the call does not access or only reads memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool onlyReadsMemory() const {
|
2008-09-26 22:53:05 +00:00
|
|
|
return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
|
|
|
|
else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2007-12-10 19:09:40 +00:00
|
|
|
/// @brief Determine if the call cannot return.
|
2010-07-06 03:53:22 +00:00
|
|
|
bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
|
2008-07-24 00:08:56 +00:00
|
|
|
void setDoesNotReturn(bool DoesNotReturn = true) {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
|
|
|
|
else removeAttribute(~0, Attribute::NoReturn);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-10 19:09:40 +00:00
|
|
|
|
2007-12-03 20:06:50 +00:00
|
|
|
/// @brief Determine if the call cannot unwind.
|
2010-07-06 03:53:22 +00:00
|
|
|
bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
|
2008-07-24 00:08:56 +00:00
|
|
|
void setDoesNotThrow(bool DoesNotThrow = true) {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
|
|
|
|
else removeAttribute(~0, Attribute::NoUnwind);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @brief Determine if the call returns a structure through first
|
2008-03-03 21:46:28 +00:00
|
|
|
/// pointer argument.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool hasStructRetAttr() const {
|
|
|
|
// Be friendly and also check the callee.
|
2008-09-25 21:00:45 +00:00
|
|
|
return paramHasAttr(1, Attribute::StructRet);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2007-04-09 18:00:57 +00:00
|
|
|
|
2008-09-26 21:38:45 +00:00
|
|
|
/// @brief Determine if any call argument is an aggregate passed by value.
|
|
|
|
bool hasByValArgument() const {
|
|
|
|
return AttributeList.hasAttrSomewhere(Attribute::ByVal);
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// getCalledFunction - Return the function called, or null if this is an
|
2004-11-18 17:46:57 +00:00
|
|
|
/// indirect function invocation.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2004-11-18 17:46:57 +00:00
|
|
|
Function *getCalledFunction() const {
|
2010-03-24 13:21:49 +00:00
|
|
|
return dyn_cast<Function>(Op<-3>());
|
2004-11-18 17:46:57 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// getCalledValue - Get a pointer to the function that is invoked by this
|
2008-09-26 21:38:45 +00:00
|
|
|
/// instruction
|
2010-03-24 13:21:49 +00:00
|
|
|
const Value *getCalledValue() const { return Op<-3>(); }
|
|
|
|
Value *getCalledValue() { return Op<-3>(); }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2010-03-20 21:00:25 +00:00
|
|
|
/// setCalledFunction - Set the function called.
|
|
|
|
void setCalledFunction(Value* Fn) {
|
2010-03-24 13:21:49 +00:00
|
|
|
Op<-3>() = Fn;
|
2010-03-20 21:00:25 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// get*Dest - Return the destination basic blocks...
|
2005-01-29 00:31:36 +00:00
|
|
|
BasicBlock *getNormalDest() const {
|
2010-03-24 13:21:49 +00:00
|
|
|
return cast<BasicBlock>(Op<-2>());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
BasicBlock *getUnwindDest() const {
|
2010-03-24 13:21:49 +00:00
|
|
|
return cast<BasicBlock>(Op<-1>());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
void setNormalDest(BasicBlock *B) {
|
2010-03-24 13:21:49 +00:00
|
|
|
Op<-2>() = reinterpret_cast<Value*>(B);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
void setUnwindDest(BasicBlock *B) {
|
2010-03-24 13:21:49 +00:00
|
|
|
Op<-1>() = reinterpret_cast<Value*>(B);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
BasicBlock *getSuccessor(unsigned i) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(i < 2 && "Successor # out of range for invoke!");
|
|
|
|
return i == 0 ? getNormalDest() : getUnwindDest();
|
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < 2 && "Successor # out of range for invoke!");
|
2010-03-24 13:21:49 +00:00
|
|
|
*(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 2; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const InvokeInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Invoke);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2010-03-24 13:21:49 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
|
|
|
virtual BasicBlock *getSuccessorV(unsigned idx) const;
|
|
|
|
virtual unsigned getNumSuccessorsV() const;
|
|
|
|
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
|
2009-12-29 02:14:09 +00:00
|
|
|
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
InvokeInst::InvokeInst(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, Instruction *InsertBefore)
|
2008-05-10 08:32:32 +00:00
|
|
|
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Invoke,
|
|
|
|
OperandTraits<InvokeInst>::op_end(this) - Values,
|
|
|
|
Values, InsertBefore) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
|
|
|
InvokeInst::InvokeInst(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd)
|
2008-05-10 08:32:32 +00:00
|
|
|
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Invoke,
|
|
|
|
OperandTraits<InvokeInst>::op_end(this) - Values,
|
|
|
|
Values, InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::iterator_category());
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UnwindInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// UnwindInst - Immediately exit the current function, unwinding the stack
|
|
|
|
/// until an invoke instruction is found.
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class UnwindInst : public TerminatorInst {
|
2008-04-06 20:25:17 +00:00
|
|
|
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual UnwindInst *clone_impl() const;
|
2004-10-27 16:14:51 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2009-08-13 21:58:54 +00:00
|
|
|
explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
|
|
|
|
explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 0; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const UnwindInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Unwind;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
|
|
|
virtual BasicBlock *getSuccessorV(unsigned idx) const;
|
|
|
|
virtual unsigned getNumSuccessorsV() const;
|
|
|
|
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2004-10-16 18:05:54 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UnreachableInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// UnreachableInst - This function has undefined behavior. In particular, the
|
|
|
|
/// presence of this instruction indicates some higher level knowledge that the
|
|
|
|
/// end of the block cannot be reached.
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class UnreachableInst : public TerminatorInst {
|
2008-04-06 20:25:17 +00:00
|
|
|
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
virtual UnreachableInst *clone_impl() const;
|
|
|
|
|
2004-10-27 16:14:51 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2009-08-13 21:58:54 +00:00
|
|
|
explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
|
|
|
|
explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
|
2004-10-16 18:05:54 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 0; }
|
2004-10-16 18:05:54 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const UnreachableInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Unreachable;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
|
|
|
virtual BasicBlock *getSuccessorV(unsigned idx) const;
|
|
|
|
virtual unsigned getNumSuccessorsV() const;
|
|
|
|
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
|
2004-10-16 18:05:54 +00:00
|
|
|
};
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TruncInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a truncation of integer types.
|
|
|
|
class TruncInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical TruncInst
|
|
|
|
virtual TruncInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
TruncInst(
|
|
|
|
Value *S, ///< The value to be truncated
|
|
|
|
const Type *Ty, ///< The (smaller) type to truncate to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
TruncInst(
|
|
|
|
Value *S, ///< The value to be truncated
|
|
|
|
const Type *Ty, ///< The (smaller) type to truncate to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const TruncInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Trunc;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ZExtInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents zero extension of integer types.
|
|
|
|
class ZExtInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical ZExtInst
|
|
|
|
virtual ZExtInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
ZExtInst(
|
|
|
|
Value *S, ///< The value to be zero extended
|
|
|
|
const Type *Ty, ///< The type to zero extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end semantics.
|
|
|
|
ZExtInst(
|
|
|
|
Value *S, ///< The value to be zero extended
|
|
|
|
const Type *Ty, ///< The type to zero extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const ZExtInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == ZExt;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SExtInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a sign extension of integer types.
|
|
|
|
class SExtInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical SExtInst
|
|
|
|
virtual SExtInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
SExtInst(
|
|
|
|
Value *S, ///< The value to be sign extended
|
|
|
|
const Type *Ty, ///< The type to sign extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
SExtInst(
|
|
|
|
Value *S, ///< The value to be sign extended
|
|
|
|
const Type *Ty, ///< The type to sign extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SExtInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == SExt;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPTruncInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a truncation of floating point types.
|
|
|
|
class FPTruncInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical FPTruncInst
|
|
|
|
virtual FPTruncInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPTruncInst(
|
|
|
|
Value *S, ///< The value to be truncated
|
|
|
|
const Type *Ty, ///< The type to truncate to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPTruncInst(
|
|
|
|
Value *S, ///< The value to be truncated
|
|
|
|
const Type *Ty, ///< The type to truncate to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const FPTruncInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == FPTrunc;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPExtInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents an extension of floating point types.
|
|
|
|
class FPExtInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical FPExtInst
|
|
|
|
virtual FPExtInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPExtInst(
|
|
|
|
Value *S, ///< The value to be extended
|
|
|
|
const Type *Ty, ///< The type to extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
FPExtInst(
|
|
|
|
Value *S, ///< The value to be extended
|
|
|
|
const Type *Ty, ///< The type to extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const FPExtInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == FPExt;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UIToFPInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a cast unsigned integer to floating point.
|
|
|
|
class UIToFPInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical UIToFPInst
|
|
|
|
virtual UIToFPInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
UIToFPInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
UIToFPInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const UIToFPInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == UIToFP;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SIToFPInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a cast from signed integer to floating point.
|
|
|
|
class SIToFPInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical SIToFPInst
|
|
|
|
virtual SIToFPInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
SIToFPInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
SIToFPInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SIToFPInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == SIToFP;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPToUIInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a cast from floating point to unsigned integer
|
|
|
|
class FPToUIInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical FPToUIInst
|
|
|
|
virtual FPToUIInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPToUIInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
FPToUIInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const FPToUIInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == FPToUI;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPToSIInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a cast from floating point to signed integer.
|
|
|
|
class FPToSIInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical FPToSIInst
|
|
|
|
virtual FPToSIInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPToSIInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
FPToSIInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const FPToSIInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == FPToSI;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IntToPtrInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a cast from an integer to a pointer.
|
|
|
|
class IntToPtrInst : public CastInst {
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
IntToPtrInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
IntToPtrInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Clone an identical IntToPtrInst
|
2009-10-27 22:16:29 +00:00
|
|
|
virtual IntToPtrInst *clone_impl() const;
|
2006-11-27 01:05:10 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const IntToPtrInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == IntToPtr;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PtrToIntInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a cast from a pointer to an integer
|
|
|
|
class PtrToIntInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical PtrToIntInst
|
|
|
|
virtual PtrToIntInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
PtrToIntInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
PtrToIntInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const PtrToIntInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == PtrToInt;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BitCastInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// @brief This class represents a no-op cast from one type to another.
|
|
|
|
class BitCastInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
|
|
|
/// @brief Clone an identical BitCastInst
|
|
|
|
virtual BitCastInst *clone_impl() const;
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
BitCastInst(
|
|
|
|
Value *S, ///< The value to be casted
|
|
|
|
const Type *Ty, ///< The type to casted to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr = "", ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-end-of-block semantics
|
|
|
|
BitCastInst(
|
|
|
|
Value *S, ///< The value to be casted
|
|
|
|
const Type *Ty, ///< The type to casted to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const BitCastInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == BitCast;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
} // End llvm namespace
|
2003-01-27 22:08:52 +00:00
|
|
|
|
|
|
|
#endif
|