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"
|
2008-05-10 08:32:32 +00:00
|
|
|
#include "llvm/BasicBlock.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;
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AllocationInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// AllocationInst - This class is the common base class of MallocInst and
|
|
|
|
/// AllocaInst.
|
|
|
|
///
|
2005-01-29 00:31:36 +00:00
|
|
|
class AllocationInst : public UnaryInstruction {
|
2004-07-29 12:17:34 +00:00
|
|
|
protected:
|
2005-11-05 09:21:28 +00:00
|
|
|
AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
|
2005-03-16 03:46:55 +00:00
|
|
|
const std::string &Name = "", Instruction *InsertBefore = 0);
|
2005-11-05 09:21:28 +00:00
|
|
|
AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
|
2005-03-16 03:46:55 +00:00
|
|
|
const std::string &Name, BasicBlock *InsertAtEnd);
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// Out of line virtual method, so the vtable, etc. has a home.
|
2007-12-10 02:14:30 +00:00
|
|
|
virtual ~AllocationInst();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/// getArraySize - Get the number of element allocated, for a simple
|
|
|
|
/// 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.
|
|
|
|
///
|
2008-03-24 16:55:58 +00:00
|
|
|
unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
|
|
|
|
void setAlignment(unsigned Align);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
virtual Instruction *clone() const = 0;
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const AllocationInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Alloca ||
|
|
|
|
I->getOpcode() == Instruction::Malloc;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MallocInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// MallocInst - an instruction to allocated memory on the heap
|
|
|
|
///
|
|
|
|
class MallocInst : public AllocationInst {
|
|
|
|
MallocInst(const MallocInst &MI);
|
|
|
|
public:
|
|
|
|
explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "",
|
2004-07-29 12:17:34 +00:00
|
|
|
Instruction *InsertBefore = 0)
|
2008-07-24 00:08:56 +00:00
|
|
|
: AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertBefore) {}
|
|
|
|
MallocInst(const Type *Ty, Value *ArraySize, const std::string &NameStr,
|
2004-07-29 12:17:34 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2008-07-24 00:08:56 +00:00
|
|
|
: AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2008-07-24 00:08:56 +00:00
|
|
|
MallocInst(const Type *Ty, const std::string &NameStr,
|
2006-10-03 17:09:12 +00:00
|
|
|
Instruction *InsertBefore = 0)
|
2008-07-24 00:08:56 +00:00
|
|
|
: AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertBefore) {}
|
2009-02-15 11:32:31 +00:00
|
|
|
MallocInst(const Type *Ty, const std::string &NameStr,
|
|
|
|
BasicBlock *InsertAtEnd)
|
2008-07-24 00:08:56 +00:00
|
|
|
: AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
|
|
|
MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd)
|
|
|
|
: AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertAtEnd) {}
|
2006-05-10 04:38:35 +00:00
|
|
|
MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "",
|
2005-11-05 09:21:28 +00:00
|
|
|
Instruction *InsertBefore = 0)
|
2008-07-24 00:08:56 +00:00
|
|
|
: AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertBefore) {}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual MallocInst *clone() const;
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MallocInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Malloc);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AllocaInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// AllocaInst - an instruction to allocate memory on the stack
|
|
|
|
///
|
|
|
|
class AllocaInst : public AllocationInst {
|
|
|
|
AllocaInst(const AllocaInst &);
|
|
|
|
public:
|
|
|
|
explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "",
|
2004-07-29 12:17:34 +00:00
|
|
|
Instruction *InsertBefore = 0)
|
2008-07-24 00:08:56 +00:00
|
|
|
: AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertBefore) {}
|
|
|
|
AllocaInst(const Type *Ty, Value *ArraySize, const std::string &NameStr,
|
2004-07-29 12:17:34 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2008-07-24 00:08:56 +00:00
|
|
|
: AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {}
|
2006-05-10 04:38:35 +00:00
|
|
|
|
2008-07-24 00:08:56 +00:00
|
|
|
AllocaInst(const Type *Ty, const std::string &NameStr,
|
2006-05-10 04:38:35 +00:00
|
|
|
Instruction *InsertBefore = 0)
|
2008-07-24 00:08:56 +00:00
|
|
|
: AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertBefore) {}
|
|
|
|
AllocaInst(const Type *Ty, const std::string &NameStr,
|
|
|
|
BasicBlock *InsertAtEnd)
|
|
|
|
: AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-05-10 04:38:35 +00:00
|
|
|
AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "", Instruction *InsertBefore = 0)
|
|
|
|
: AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertBefore) {}
|
2005-11-05 09:21:28 +00:00
|
|
|
AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd)
|
|
|
|
: AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertAtEnd) {}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual AllocaInst *clone() const;
|
2009-02-09 17:11:05 +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;
|
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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FreeInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// FreeInst - an instruction to deallocate memory
|
|
|
|
///
|
2005-01-29 00:31:36 +00:00
|
|
|
class FreeInst : public UnaryInstruction {
|
|
|
|
void AssertOK();
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
|
|
|
explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
|
|
|
|
FreeInst(Value *Ptr, BasicBlock *InsertAfter);
|
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual FreeInst *clone() const;
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-07-06 23:13:31 +00:00
|
|
|
// Accessor methods for consistency with other memory operations
|
|
|
|
Value *getPointerOperand() { return getOperand(0); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(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 FreeInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Free);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// 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 {
|
2007-04-22 19:24:39 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
LoadInst(const LoadInst &LI)
|
2005-02-05 01:44:18 +00:00
|
|
|
: UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
|
|
|
|
setVolatile(LI.isVolatile());
|
2007-04-22 19:24:39 +00:00
|
|
|
setAlignment(LI.getAlignment());
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
AssertOK();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void AssertOK();
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2008-07-24 00:08:56 +00:00
|
|
|
LoadInst(Value *Ptr, const std::string &NameStr, Instruction *InsertBefore);
|
|
|
|
LoadInst(Value *Ptr, const std::string &NameStr, BasicBlock *InsertAtEnd);
|
2009-02-09 17:11:05 +00:00
|
|
|
LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile = false,
|
2007-02-13 07:54:42 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2008-07-24 00:08:56 +00:00
|
|
|
LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile,
|
|
|
|
unsigned Align, Instruction *InsertBefore = 0);
|
|
|
|
LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile,
|
2007-07-18 20:51:11 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2008-07-24 00:08:56 +00:00
|
|
|
LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile,
|
|
|
|
unsigned Align, BasicBlock *InsertAtEnd);
|
|
|
|
|
|
|
|
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,
|
2007-02-13 07:54:42 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// isVolatile - Return true if this is a load from a volatile memory
|
|
|
|
/// location.
|
|
|
|
///
|
2007-04-22 19:24:39 +00:00
|
|
|
bool isVolatile() const { return SubclassData & 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) {
|
|
|
|
SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual LoadInst *clone() const;
|
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 {
|
2007-04-22 22:22:02 +00:00
|
|
|
return (1 << (SubclassData>>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; }
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// 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
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store,
|
|
|
|
&Op<0>(), 2) {
|
2008-05-26 21:33:52 +00:00
|
|
|
Op<0>() = SI.Op<0>();
|
|
|
|
Op<1>() = SI.Op<1>();
|
2005-02-05 01:44:18 +00:00
|
|
|
setVolatile(SI.isVolatile());
|
2007-04-22 19:24:39 +00:00
|
|
|
setAlignment(SI.getAlignment());
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
AssertOK();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void AssertOK();
|
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.
|
|
|
|
///
|
2007-04-22 19:24:39 +00:00
|
|
|
bool isVolatile() const { return SubclassData & 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) {
|
|
|
|
SubclassData = (SubclassData & ~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 {
|
2007-04-22 22:22:02 +00:00
|
|
|
return (1 << (SubclassData>>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
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual StoreInst *clone() const;
|
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; }
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
|
|
|
struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> {
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr);
|
|
|
|
void init(Value *Ptr, Value *Idx, const std::string &NameStr);
|
2007-09-04 15:46:09 +00:00
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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.
|
2008-07-24 00:08:56 +00:00
|
|
|
GetElementPtrInst(Value *Ptr, Value *Idx, const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd);
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual GetElementPtrInst *clone() const;
|
2005-04-21 20:19:05 +00:00
|
|
|
|
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-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
|
|
|
|
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 <>
|
|
|
|
struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 {
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics.
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "", ///< Name of the instruction
|
2006-11-20 01:22:35 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert
|
2008-09-09 01:02:47 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
|
|
|
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
|
2009-02-09 17:11:05 +00:00
|
|
|
assert((getOperand(0)->getType()->isIntOrIntVector() ||
|
2008-05-14 20:28:31 +00:00
|
|
|
isa<PointerType>(getOperand(0)->getType())) &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Invalid operand types for ICmp instruction");
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-block-end semantics.
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, ///< Name of the instruction
|
2006-11-20 01:22:35 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< Block to insert into.
|
2008-09-09 01:02:47 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
|
|
|
Instruction::ICmp, pred, LHS, RHS, NameStr,
|
2008-05-12 19:01:56 +00:00
|
|
|
InsertAtEnd) {
|
|
|
|
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
|
2009-02-09 17:11:05 +00:00
|
|
|
assert((getOperand(0)->getType()->isIntOrIntVector() ||
|
2008-05-14 20:28:31 +00:00
|
|
|
isa<PointerType>(getOperand(0)->getType())) &&
|
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
|
|
|
|
2006-12-23 06:05:41 +00:00
|
|
|
/// @returns true if the predicate of this ICmpInst is signed, false otherwise
|
|
|
|
/// @brief Determine if this instruction's predicate is signed.
|
2007-09-15 06:51:03 +00:00
|
|
|
bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
|
2006-12-23 06:05:41 +00:00
|
|
|
|
|
|
|
/// @returns true if the predicate provided is signed, false otherwise
|
|
|
|
/// @brief Determine if the predicate is signed.
|
|
|
|
static bool isSignedPredicate(Predicate pred);
|
|
|
|
|
2008-05-17 07:33:39 +00:00
|
|
|
/// @returns true if the specified compare predicate is
|
|
|
|
/// true when both operands are equal...
|
|
|
|
/// @brief Determine if the icmp is true when both operands are equal
|
|
|
|
static bool isTrueWhenEqual(ICmpInst::Predicate pred) {
|
|
|
|
return pred == ICmpInst::ICMP_EQ || pred == ICmpInst::ICMP_UGE ||
|
|
|
|
pred == ICmpInst::ICMP_SGE || pred == ICmpInst::ICMP_ULE ||
|
|
|
|
pred == ICmpInst::ICMP_SLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @returns true if the specified compare instruction is
|
|
|
|
/// true when both operands are equal...
|
|
|
|
/// @brief Determine if the ICmpInst returns true when both operands are equal
|
|
|
|
bool isTrueWhenEqual() {
|
|
|
|
return isTrueWhenEqual(getPredicate());
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
SubclassData = getSwappedPredicate();
|
2008-05-13 22:51:52 +00:00
|
|
|
Op<0>().swap(Op<1>());
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 20:48:18 +00:00
|
|
|
virtual ICmpInst *clone() const;
|
|
|
|
|
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 {
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics.
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "", ///< Name of the instruction
|
2006-11-20 01:22:35 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert
|
2008-09-09 01:02:47 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
|
|
|
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
|
2008-09-09 01:02:47 +00:00
|
|
|
assert(getOperand(0)->getType()->isFPOrFPVector() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Invalid operand types for FCmp instruction");
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-block-end semantics.
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, ///< Name of the instruction
|
2006-11-20 01:22:35 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< Block to insert into.
|
2008-09-09 01:02:47 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
|
|
|
Instruction::FCmp, pred, LHS, RHS, NameStr,
|
2008-05-12 19:01:56 +00:00
|
|
|
InsertAtEnd) {
|
|
|
|
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
|
2008-09-09 01:02:47 +00:00
|
|
|
assert(getOperand(0)->getType()->isFPOrFPVector() &&
|
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 {
|
|
|
|
return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
|
|
|
|
SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
|
|
|
|
}
|
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() ||
|
|
|
|
SubclassData == FCMP_FALSE ||
|
|
|
|
SubclassData == FCMP_TRUE ||
|
|
|
|
SubclassData == FCMP_ORD ||
|
|
|
|
SubclassData == FCMP_UNO;
|
|
|
|
}
|
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() {
|
|
|
|
SubclassData = getSwappedPredicate();
|
2008-05-13 22:51:52 +00:00
|
|
|
Op<0>().swap(Op<1>());
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 20:48:18 +00:00
|
|
|
virtual FCmpInst *clone() const;
|
|
|
|
|
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));
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
};
|
|
|
|
|
2008-05-12 19:01:56 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VICmpInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// This instruction compares its operands according to the predicate given
|
|
|
|
/// to the constructor. It only operates on vectors of integers.
|
|
|
|
/// The operands must be identical types.
|
|
|
|
/// @brief Represents a vector integer comparison operator.
|
|
|
|
class VICmpInst: public CmpInst {
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics.
|
|
|
|
VICmpInst(
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "", ///< Name of the instruction
|
2008-05-12 19:01:56 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert
|
2008-07-24 00:08:56 +00:00
|
|
|
) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, NameStr,
|
2008-05-12 19:01:56 +00:00
|
|
|
InsertBefore) {
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
|
|
|
|
pred <= CmpInst::LAST_ICMP_PREDICATE &&
|
|
|
|
"Invalid VICmp predicate value");
|
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
|
|
|
"Both operands to VICmp instruction are not of the same type!");
|
2008-05-12 19:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-block-end semantics.
|
|
|
|
VICmpInst(
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, ///< Name of the instruction
|
2008-05-12 19:01:56 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< Block to insert into.
|
2008-07-24 00:08:56 +00:00
|
|
|
) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, NameStr,
|
2008-05-12 19:01:56 +00:00
|
|
|
InsertAtEnd) {
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
|
|
|
|
pred <= CmpInst::LAST_ICMP_PREDICATE &&
|
|
|
|
"Invalid VICmp predicate value");
|
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
|
|
|
"Both operands to VICmp instruction are not of the same type!");
|
2008-05-12 19:01:56 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-12 19:01:56 +00:00
|
|
|
/// @brief Return the predicate for this instruction.
|
|
|
|
Predicate getPredicate() const { return Predicate(SubclassData); }
|
|
|
|
|
|
|
|
virtual VICmpInst *clone() const;
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const VICmpInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::VICmp;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VFCmpInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// This instruction compares its operands according to the predicate given
|
|
|
|
/// to the constructor. It only operates on vectors of floating point values.
|
|
|
|
/// The operands must be identical types.
|
|
|
|
/// @brief Represents a vector floating point comparison operator.
|
|
|
|
class VFCmpInst: public CmpInst {
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics.
|
|
|
|
VFCmpInst(
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "", ///< Name of the instruction
|
2008-05-12 19:01:56 +00:00
|
|
|
Instruction *InsertBefore = 0 ///< Where to insert
|
|
|
|
) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
|
2008-07-24 00:08:56 +00:00
|
|
|
Instruction::VFCmp, pred, LHS, RHS, NameStr, InsertBefore) {
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
|
|
|
|
"Invalid VFCmp predicate value");
|
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
|
|
|
"Both operands to VFCmp instruction are not of the same type!");
|
2008-05-12 19:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Constructor with insert-at-block-end semantics.
|
|
|
|
VFCmpInst(
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, ///< Name of the instruction
|
2008-05-12 19:01:56 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< Block to insert into.
|
|
|
|
) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
|
2008-07-24 00:08:56 +00:00
|
|
|
Instruction::VFCmp, pred, LHS, RHS, NameStr, InsertAtEnd) {
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
|
|
|
|
"Invalid VFCmp predicate value");
|
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
|
|
|
"Both operands to VFCmp instruction are not of the same type!");
|
2008-05-12 19:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Return the predicate for this instruction.
|
|
|
|
Predicate getPredicate() const { return Predicate(SubclassData); }
|
|
|
|
|
|
|
|
virtual VFCmpInst *clone() const;
|
|
|
|
|
|
|
|
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const VFCmpInst *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::VFCmp;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CallInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// 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
|
|
|
///
|
2007-08-01 03:43:44 +00:00
|
|
|
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd);
|
2007-08-01 03:43:44 +00:00
|
|
|
|
2008-07-24 00:08:56 +00:00
|
|
|
CallInst(Value *F, Value *Actual, const std::string& NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2008-07-24 00:08:56 +00:00
|
|
|
CallInst(Value *F, Value *Actual, const std::string& NameStr,
|
2004-07-29 12:17:34 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2008-07-24 00:08:56 +00:00
|
|
|
explicit CallInst(Value *F, const std::string &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2008-07-24 00:08:56 +00:00
|
|
|
CallInst(Value *F, const std::string &NameStr, BasicBlock *InsertAtEnd);
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "",
|
2008-05-05 17:41:03 +00:00
|
|
|
Instruction *InsertBefore = 0) {
|
2008-05-10 19:59:59 +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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd) {
|
2008-05-10 19:59:59 +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,
|
|
|
|
const std::string& 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
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
static CallInst *Create(Value *F, Value *Actual, const std::string& 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
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
static CallInst *Create(Value *F, const std::string &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
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
static CallInst *Create(Value *F, const std::string &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
|
|
|
}
|
|
|
|
|
2007-12-10 02:14:30 +00:00
|
|
|
~CallInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
bool isTailCall() const { return SubclassData & 1; }
|
2008-07-24 00:08:56 +00:00
|
|
|
void setTailCall(bool isTC = true) {
|
|
|
|
SubclassData = (SubclassData & ~1) | unsigned(isTC);
|
2005-05-06 20:26:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-26 21:38:45 +00:00
|
|
|
virtual CallInst *clone() const;
|
|
|
|
|
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
/// getCallingConv/setCallingConv - Get or set the calling convention of this
|
|
|
|
/// function call.
|
|
|
|
unsigned getCallingConv() const { return SubclassData >> 1; }
|
|
|
|
void setCallingConv(unsigned CC) {
|
|
|
|
SubclassData = (SubclassData & 1) | (CC << 1);
|
|
|
|
}
|
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
|
|
|
}
|
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.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotReturn() const {
|
2008-09-26 22:53:05 +00:00
|
|
|
return paramHasAttr(~0, Attribute::NoReturn);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
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.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotThrow() const {
|
2008-09-26 22:53:05 +00:00
|
|
|
return paramHasAttr(~0, Attribute::NoUnwind);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
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 {
|
2007-09-24 15:46:02 +00:00
|
|
|
return dyn_cast<Function>(getOperand(0));
|
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
|
2006-12-29 04:10:59 +00:00
|
|
|
/// instruction
|
2008-02-23 01:11:02 +00:00
|
|
|
const Value *getCalledValue() const { return getOperand(0); }
|
|
|
|
Value *getCalledValue() { return getOperand(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 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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
|
|
|
struct OperandTraits<CallInst> : VariadicOperandTraits<1> {
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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),
|
2008-05-10 11:26:52 +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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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),
|
2008-05-10 11:26:52 +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());
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
SelectInst(const SelectInst &SI)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) {
|
|
|
|
init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>());
|
2005-01-29 00:31:36 +00:00
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
SelectInst(Value *C, Value *S1, Value *S2, const std::string &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
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
SelectInst(Value *C, Value *S1, Value *S2, const std::string &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
|
|
|
}
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr,
|
|
|
|
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
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
Value *getCondition() const { return Op<0>(); }
|
|
|
|
Value *getTrueValue() const { return Op<1>(); }
|
|
|
|
Value *getFalseValue() const { return Op<2>(); }
|
2009-02-09 17:11:05 +00:00
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual SelectInst *clone() const;
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
// 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 <>
|
|
|
|
struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> {
|
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2004-07-29 12:17:34 +00:00
|
|
|
VAArgInst(const VAArgInst &VAA)
|
2005-01-29 00:31:36 +00:00
|
|
|
: UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2008-07-24 00:08:56 +00:00
|
|
|
VAArgInst(Value *List, const Type *Ty, const std::string &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
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
VAArgInst(Value *List, const Type *Ty, const std::string &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
|
|
|
}
|
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual VAArgInst *clone() const;
|
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 {
|
2006-10-03 17:09:12 +00:00
|
|
|
ExtractElementInst(const ExtractElementInst &EE) :
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) {
|
2008-05-26 21:33:52 +00:00
|
|
|
Op<0>() = EE.Op<0>();
|
|
|
|
Op<1>() = EE.Op<1>();
|
2006-01-10 19:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
2008-05-10 08:32:32 +00:00
|
|
|
return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor?
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr = "",
|
2006-04-08 01:15:18 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2008-07-24 00:08:56 +00:00
|
|
|
ExtractElementInst(Value *Vec, unsigned Idx, const std::string &NameStr = "",
|
2006-10-05 06:24:58 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
2008-07-24 00:08:56 +00:00
|
|
|
ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr,
|
2006-04-08 01:15:18 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2008-07-24 00:08:56 +00:00
|
|
|
ExtractElementInst(Value *Vec, unsigned Idx, const std::string &NameStr,
|
2006-10-05 06:24:58 +00:00
|
|
|
BasicBlock *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
|
|
|
|
2006-01-10 19:04:13 +00:00
|
|
|
virtual ExtractElementInst *clone() const;
|
|
|
|
|
|
|
|
/// 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 <>
|
|
|
|
struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> {
|
|
|
|
};
|
|
|
|
|
|
|
|
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-14 22:20:07 +00:00
|
|
|
InsertElementInst(const InsertElementInst &IE);
|
2006-04-08 01:15:18 +00:00
|
|
|
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
|
2009-02-09 17:11:05 +00:00
|
|
|
const std::string &NameStr = "",
|
|
|
|
Instruction *InsertBefore = 0);
|
2006-10-05 06:24:58 +00:00
|
|
|
InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
|
2009-02-09 17:11:05 +00:00
|
|
|
const std::string &NameStr = "",
|
|
|
|
Instruction *InsertBefore = 0);
|
2006-04-08 01:15:18 +00:00
|
|
|
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd);
|
2006-10-05 06:24:58 +00:00
|
|
|
InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
static InsertElementInst *Create(const InsertElementInst &IE) {
|
|
|
|
return new(IE.getNumOperands()) InsertElementInst(IE);
|
|
|
|
}
|
|
|
|
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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, unsigned Idx,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "",
|
2008-05-05 17:41:03 +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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
|
|
}
|
|
|
|
static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
|
|
|
2006-01-17 20:05:59 +00:00
|
|
|
virtual InsertElementInst *clone() const;
|
|
|
|
|
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 <>
|
|
|
|
struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> {
|
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2006-10-03 17:09:12 +00:00
|
|
|
ShuffleVectorInst(const ShuffleVectorInst &IE);
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr = "",
|
|
|
|
Instruction *InsertBefor = 0);
|
2006-04-08 01:15:18 +00:00
|
|
|
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
virtual ShuffleVectorInst *clone() const;
|
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 <>
|
|
|
|
struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> {
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr);
|
|
|
|
void init(unsigned Idx, const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
Instruction *InsertBefore);
|
|
|
|
template<typename InputIterator>
|
|
|
|
inline ExtractValueInst(Value *Agg,
|
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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);
|
|
|
|
}
|
|
|
|
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
|
|
}
|
|
|
|
|
|
|
|
virtual ExtractValueInst *clone() const;
|
|
|
|
|
|
|
|
// getType - Overload to return most specific pointer type...
|
|
|
|
const PointerType *getType() const {
|
|
|
|
return reinterpret_cast<const PointerType*>(Instruction::getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr);
|
|
|
|
void init(Value *Agg, Value *Val, unsigned Idx, const std::string &NameStr);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
void init(Value *Agg, Value *Val,
|
|
|
|
InputIterator IdxBegin, InputIterator IdxEnd,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
unsigned Idx, const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd);
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
|
|
}
|
|
|
|
|
|
|
|
virtual InsertValueInst *clone() const;
|
|
|
|
|
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
|
|
|
// getType - Overload to return most specific pointer type...
|
|
|
|
const PointerType *getType() const {
|
|
|
|
return reinterpret_cast<const PointerType*>(Instruction::getType());
|
|
|
|
}
|
|
|
|
|
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 <>
|
2008-05-31 00:58:22 +00:00
|
|
|
struct OperandTraits<InsertValueInst> : 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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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);
|
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
explicit PHINode(const Type *Ty, const std::string &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
|
|
|
}
|
|
|
|
|
2008-07-24 00:08:56 +00:00
|
|
|
PHINode(const Type *Ty, const std::string &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
|
|
|
}
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2008-07-24 00:08:56 +00:00
|
|
|
static PHINode *Create(const Type *Ty, const std::string &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
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
static PHINode *Create(const Type *Ty, const std::string &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
|
|
|
}
|
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual PHINode *clone() const;
|
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
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getOperandNumForIncomingValue(unsigned i) {
|
2004-07-29 12:17:34 +00:00
|
|
|
return i*2;
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:40:15 +00:00
|
|
|
/// getIncomingBlock - Return incoming basic block corresponding
|
|
|
|
/// to value use iterator
|
|
|
|
///
|
|
|
|
template <typename U>
|
|
|
|
BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
|
|
|
|
assert(this == *I && "Iterator doesn't point to PHI's Uses?");
|
|
|
|
return static_cast<BasicBlock*>((&I.getUse() + 1)->get());
|
|
|
|
}
|
2006-05-19 19:07:54 +00:00
|
|
|
/// getIncomingBlock - Return incoming basic block number x
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2005-04-21 20:19:05 +00:00
|
|
|
BasicBlock *getIncomingBlock(unsigned i) const {
|
2008-05-10 08:32:32 +00:00
|
|
|
return static_cast<BasicBlock*>(getOperand(i*2+1));
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
void setIncomingBlock(unsigned i, BasicBlock *BB) {
|
2008-05-10 08:32:32 +00:00
|
|
|
setOperand(i*2+1, BB);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
unsigned getOperandNumForIncomingBlock(unsigned i) {
|
|
|
|
return i*2+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
OperandList[OpNo+1] = 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)
|
2008-05-10 08:32:32 +00:00
|
|
|
if (OL[i+1].get() == 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.
|
|
|
|
///
|
2005-08-05 00:49:06 +00:00
|
|
|
Value *hasConstantValue(bool AllowNonDominatingInstruction = false) 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 <>
|
|
|
|
struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
|
|
|
|
};
|
|
|
|
|
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.
|
2007-02-24 00:55:48 +00:00
|
|
|
explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
|
|
|
|
ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
|
|
|
|
explicit ReturnInst(BasicBlock *InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
|
|
|
|
return new(!!retVal) ReturnInst(retVal, InsertBefore);
|
|
|
|
}
|
|
|
|
static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
|
|
|
|
return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
|
|
|
|
}
|
|
|
|
static ReturnInst* Create(BasicBlock *InsertAtEnd) {
|
|
|
|
return new(0) ReturnInst(InsertAtEnd);
|
|
|
|
}
|
2008-02-23 00:35:18 +00:00
|
|
|
virtual ~ReturnInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual ReturnInst *clone() const;
|
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 <>
|
2008-07-23 00:34:11 +00:00
|
|
|
struct OperandTraits<ReturnInst> : OptionalOperandTraits<> {
|
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:
|
|
|
|
/// TrueDest, FalseDest, Cond. This makes some accessors faster because
|
|
|
|
/// they don't have to check for cond/uncond branchness.
|
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);
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
|
|
|
|
return new(1) BranchInst(IfTrue, InsertBefore);
|
|
|
|
}
|
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) {
|
|
|
|
return new(1) BranchInst(IfTrue, InsertAtEnd);
|
|
|
|
}
|
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
|
|
|
|
2008-05-10 10:58:07 +00:00
|
|
|
~BranchInst() {
|
2008-05-10 08:32:32 +00:00
|
|
|
if (NumOperands == 1)
|
2008-05-10 19:59:59 +00:00
|
|
|
NumOperands = (unsigned)((Use*)this - OperandList);
|
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);
|
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual BranchInst *clone() const;
|
2004-07-29 12:17:34 +00:00
|
|
|
|
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!");
|
2005-01-29 00:31:36 +00:00
|
|
|
return getOperand(2);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setCondition(Value *V) {
|
|
|
|
assert(isConditional() && "Cannot set condition of unconditional branch!");
|
|
|
|
setOperand(2, V);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2008-05-10 08:32:32 +00:00
|
|
|
Op<0>() = Dest;
|
2005-01-29 00:31:36 +00:00
|
|
|
if (isConditional()) { // Convert this to an uncond branch.
|
2008-05-10 08:32:32 +00:00
|
|
|
Op<1>().set(0);
|
|
|
|
Op<2>().set(0);
|
2005-01-29 00:31:36 +00:00
|
|
|
NumOperands = 1;
|
|
|
|
}
|
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-02-09 20:27:45 +00:00
|
|
|
return cast_or_null<BasicBlock>(getOperand(i));
|
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!");
|
2008-05-10 08:32:32 +00:00
|
|
|
setOperand(idx, 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 <>
|
|
|
|
struct OperandTraits<BranchInst> : HungoffOperandTraits<> {
|
|
|
|
// we need to access operands via OperandList, since
|
|
|
|
// the NumOperands may change from 3 to 1
|
|
|
|
static inline void *allocate(unsigned); // FIXME
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
SwitchInst(const SwitchInst &RI);
|
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,
|
2007-02-24 00:55:48 +00:00
|
|
|
Instruction *InsertBefore = 0);
|
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);
|
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
|
|
|
virtual SwitchInst *clone() const;
|
|
|
|
|
|
|
|
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!");
|
2008-05-10 08:32:32 +00:00
|
|
|
setOperand(idx*2+1, 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 <>
|
|
|
|
struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
|
|
|
|
};
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
|
2008-05-10 08:32:32 +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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, BasicBlock *InsertAtEnd);
|
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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr,
|
|
|
|
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
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual InvokeInst *clone() const;
|
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);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
/// getCallingConv/setCallingConv - Get or set the calling convention of this
|
|
|
|
/// function call.
|
|
|
|
unsigned getCallingConv() const { return SubclassData; }
|
|
|
|
void setCallingConv(unsigned CC) {
|
|
|
|
SubclassData = CC;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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-25 21:00:45 +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.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotReturn() const {
|
2008-09-26 22:53:05 +00:00
|
|
|
return paramHasAttr(~0, Attribute::NoReturn);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
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.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotThrow() const {
|
2008-09-26 22:53:05 +00:00
|
|
|
return paramHasAttr(~0, Attribute::NoUnwind);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
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 {
|
2005-01-29 00:31:36 +00:00
|
|
|
return dyn_cast<Function>(getOperand(0));
|
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
|
|
|
|
const Value *getCalledValue() const { return getOperand(0); }
|
|
|
|
Value *getCalledValue() { return getOperand(0); }
|
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 {
|
|
|
|
return cast<BasicBlock>(getOperand(1));
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
BasicBlock *getUnwindDest() const {
|
|
|
|
return cast<BasicBlock>(getOperand(2));
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
void setNormalDest(BasicBlock *B) {
|
2008-05-10 08:32:32 +00:00
|
|
|
setOperand(1, B);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
void setUnwindDest(BasicBlock *B) {
|
2008-05-10 08:32:32 +00:00
|
|
|
setOperand(2, 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!");
|
2008-05-10 08:32:32 +00:00
|
|
|
setOperand(idx+1, 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));
|
|
|
|
}
|
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 <>
|
|
|
|
struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> {
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
InvokeInst::InvokeInst(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
|
|
|
InputIterator ArgBegin, InputIterator ArgEnd,
|
|
|
|
unsigned Values,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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,
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
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);
|
|
|
|
}
|
2007-02-24 00:55:48 +00:00
|
|
|
explicit UnwindInst(Instruction *InsertBefore = 0);
|
|
|
|
explicit UnwindInst(BasicBlock *InsertAtEnd);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2004-10-15 23:52:05 +00:00
|
|
|
virtual UnwindInst *clone() const;
|
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
|
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);
|
|
|
|
}
|
2007-02-24 00:55:48 +00:00
|
|
|
explicit UnreachableInst(Instruction *InsertBefore = 0);
|
|
|
|
explicit UnreachableInst(BasicBlock *InsertAtEnd);
|
2004-10-16 18:05:54 +00:00
|
|
|
|
|
|
|
virtual UnreachableInst *clone() const;
|
|
|
|
|
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 {
|
|
|
|
/// Private copy constructor
|
|
|
|
TruncInst(const TruncInst &CI)
|
|
|
|
: CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 TruncInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
/// @brief Private copy constructor
|
|
|
|
ZExtInst(const ZExtInst &CI)
|
|
|
|
: CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 ZExtInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
/// @brief Private copy constructor
|
|
|
|
SExtInst(const SExtInst &CI)
|
|
|
|
: CastInst(CI.getType(), SExt, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 SExtInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
FPTruncInst(const FPTruncInst &CI)
|
|
|
|
: CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPTruncInst(
|
|
|
|
Value *S, ///< The value to be truncated
|
|
|
|
const Type *Ty, ///< The type to truncate to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 FPTruncInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
FPExtInst(const FPExtInst &CI)
|
|
|
|
: CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPExtInst(
|
|
|
|
Value *S, ///< The value to be extended
|
|
|
|
const Type *Ty, ///< The type to extend to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 FPExtInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
UIToFPInst(const UIToFPInst &CI)
|
|
|
|
: CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
UIToFPInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 UIToFPInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
SIToFPInst(const SIToFPInst &CI)
|
|
|
|
: CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
SIToFPInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 SIToFPInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
FPToUIInst(const FPToUIInst &CI)
|
|
|
|
: CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPToUIInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
|
|
|
/// @brief Clone an identical FPToUIInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
FPToSIInst(const FPToSIInst &CI)
|
|
|
|
: CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
FPToSIInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 FPToSIInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
IntToPtrInst(const IntToPtrInst &CI)
|
|
|
|
: CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
IntToPtrInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
PtrToIntInst(const PtrToIntInst &CI)
|
|
|
|
: CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
PtrToIntInst(
|
|
|
|
Value *S, ///< The value to be converted
|
|
|
|
const Type *Ty, ///< The type to convert to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 PtrToIntInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
BitCastInst(const BitCastInst &CI)
|
|
|
|
: CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
/// @brief Constructor with insert-before-instruction semantics
|
|
|
|
BitCastInst(
|
|
|
|
Value *S, ///< The value to be casted
|
|
|
|
const Type *Ty, ///< The type to casted to
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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
|
2008-07-24 00:08:56 +00:00
|
|
|
const std::string &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 BitCastInst
|
|
|
|
virtual CastInst *clone() const;
|
|
|
|
|
|
|
|
// 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
|