mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
Refactor common initialization code in private init() functions.
This is a first step in supplying append to basic block constructors for all instruction types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13793 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -32,9 +32,13 @@ protected:
|
|||||||
TerminatorInst(Instruction::TermOps iType, Instruction *InsertBefore = 0);
|
TerminatorInst(Instruction::TermOps iType, Instruction *InsertBefore = 0);
|
||||||
TerminatorInst(const Type *Ty, Instruction::TermOps iType,
|
TerminatorInst(const Type *Ty, Instruction::TermOps iType,
|
||||||
const std::string &Name = "", Instruction *InsertBefore = 0)
|
const std::string &Name = "", Instruction *InsertBefore = 0)
|
||||||
: Instruction(Ty, iType, Name, InsertBefore) {
|
: Instruction(Ty, iType, Name, InsertBefore) {}
|
||||||
}
|
|
||||||
TerminatorInst(Instruction::TermOps iType, BasicBlock *InsertAtEnd);
|
TerminatorInst(Instruction::TermOps iType, BasicBlock *InsertAtEnd);
|
||||||
|
TerminatorInst(const Type *Ty, Instruction::TermOps iType,
|
||||||
|
const std::string &Name, BasicBlock *InsertAtEnd)
|
||||||
|
: Instruction(Ty, iType, Name, InsertAtEnd) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Terminators must implement the methods required by Instruction...
|
/// Terminators must implement the methods required by Instruction...
|
||||||
|
@@ -36,11 +36,15 @@ class Instruction : public User, public Annotable {
|
|||||||
friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
|
friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
|
||||||
ilist_traits<Instruction> >;
|
ilist_traits<Instruction> >;
|
||||||
void setParent(BasicBlock *P);
|
void setParent(BasicBlock *P);
|
||||||
|
void init();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned iType; // InstructionType: The opcode of the instruction
|
unsigned iType; // InstructionType: The opcode of the instruction
|
||||||
|
|
||||||
Instruction(const Type *Ty, unsigned iType, const std::string &Name = "",
|
Instruction(const Type *Ty, unsigned iType, const std::string &Name = "",
|
||||||
Instruction *InsertBefore = 0);
|
Instruction *InsertBefore = 0);
|
||||||
|
Instruction(const Type *Ty, unsigned iType, const std::string &Name,
|
||||||
|
BasicBlock *InsertAtEnd);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
~Instruction() {
|
~Instruction() {
|
||||||
|
@@ -163,6 +163,10 @@ class LoadInst : public Instruction {
|
|||||||
Operands.push_back(Use(LI.Operands[0], this));
|
Operands.push_back(Use(LI.Operands[0], this));
|
||||||
}
|
}
|
||||||
bool Volatile; // True if this is a volatile load
|
bool Volatile; // True if this is a volatile load
|
||||||
|
void init(Value *Ptr) {
|
||||||
|
Operands.reserve(1);
|
||||||
|
Operands.push_back(Use(Ptr, this));
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
|
LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
|
||||||
LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false,
|
LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false,
|
||||||
@@ -210,6 +214,11 @@ class StoreInst : public Instruction {
|
|||||||
Operands.push_back(Use(SI.Operands[1], this));
|
Operands.push_back(Use(SI.Operands[1], this));
|
||||||
}
|
}
|
||||||
bool Volatile; // True if this is a volatile store
|
bool Volatile; // True if this is a volatile store
|
||||||
|
void init(Value *Val, Value *Ptr) {
|
||||||
|
Operands.reserve(2);
|
||||||
|
Operands.push_back(Use(Val, this));
|
||||||
|
Operands.push_back(Use(Ptr, this));
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
|
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
|
||||||
StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
|
||||||
@@ -258,6 +267,8 @@ class GetElementPtrInst : public Instruction {
|
|||||||
for (unsigned i = 0, E = EPI.Operands.size(); i != E; ++i)
|
for (unsigned i = 0, E = EPI.Operands.size(); i != E; ++i)
|
||||||
Operands.push_back(Use(EPI.Operands[i], this));
|
Operands.push_back(Use(EPI.Operands[i], this));
|
||||||
}
|
}
|
||||||
|
void init(Value *Ptr, const std::vector<Value*> &Idx);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
|
GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
|
||||||
const std::string &Name = "", Instruction *InsertBefore =0);
|
const std::string &Name = "", Instruction *InsertBefore =0);
|
||||||
|
@@ -32,6 +32,14 @@ class ReturnInst : public TerminatorInst {
|
|||||||
Operands.push_back(Use(RI.Operands[0], this));
|
Operands.push_back(Use(RI.Operands[0], this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init(Value *RetVal) {
|
||||||
|
if (RetVal) {
|
||||||
|
Operands.reserve(1);
|
||||||
|
Operands.push_back(Use(RetVal, this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// ReturnInst constructors:
|
// ReturnInst constructors:
|
||||||
// ReturnInst() - 'ret void' instruction
|
// ReturnInst() - 'ret void' instruction
|
||||||
@@ -42,17 +50,11 @@ public:
|
|||||||
// ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
|
// ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
|
||||||
ReturnInst(Value *RetVal = 0, Instruction *InsertBefore = 0)
|
ReturnInst(Value *RetVal = 0, Instruction *InsertBefore = 0)
|
||||||
: TerminatorInst(Instruction::Ret, InsertBefore) {
|
: TerminatorInst(Instruction::Ret, InsertBefore) {
|
||||||
if (RetVal) {
|
init(RetVal);
|
||||||
Operands.reserve(1);
|
|
||||||
Operands.push_back(Use(RetVal, this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ReturnInst(Value *RetVal, BasicBlock *InsertAtEnd)
|
ReturnInst(Value *RetVal, BasicBlock *InsertAtEnd)
|
||||||
: TerminatorInst(Instruction::Ret, InsertAtEnd) {
|
: TerminatorInst(Instruction::Ret, InsertAtEnd) {
|
||||||
if (RetVal) {
|
init(RetVal);
|
||||||
Operands.reserve(1);
|
|
||||||
Operands.push_back(Use(RetVal, this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Instruction *clone() const { return new ReturnInst(*this); }
|
virtual Instruction *clone() const { return new ReturnInst(*this); }
|
||||||
@@ -87,6 +89,8 @@ public:
|
|||||||
///
|
///
|
||||||
class BranchInst : public TerminatorInst {
|
class BranchInst : public TerminatorInst {
|
||||||
BranchInst(const BranchInst &BI);
|
BranchInst(const BranchInst &BI);
|
||||||
|
void init(BasicBlock *IfTrue);
|
||||||
|
void init(BasicBlock *True, BasicBlock *False, Value *Cond);
|
||||||
public:
|
public:
|
||||||
// BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
|
// BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
|
||||||
// BranchInst(BB *B) - 'br B'
|
// BranchInst(BB *B) - 'br B'
|
||||||
@@ -161,6 +165,8 @@ class SwitchInst : public TerminatorInst {
|
|||||||
// Operand[2n ] = Value to match
|
// Operand[2n ] = Value to match
|
||||||
// Operand[2n+1] = BasicBlock to go to on match
|
// Operand[2n+1] = BasicBlock to go to on match
|
||||||
SwitchInst(const SwitchInst &RI);
|
SwitchInst(const SwitchInst &RI);
|
||||||
|
void init(Value *Value, BasicBlock *Default);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SwitchInst(Value *Value, BasicBlock *Default, Instruction *InsertBefore = 0);
|
SwitchInst(Value *Value, BasicBlock *Default, Instruction *InsertBefore = 0);
|
||||||
SwitchInst(Value *Value, BasicBlock *Default, BasicBlock *InsertAtEnd);
|
SwitchInst(Value *Value, BasicBlock *Default, BasicBlock *InsertAtEnd);
|
||||||
@@ -259,6 +265,8 @@ public:
|
|||||||
///
|
///
|
||||||
class InvokeInst : public TerminatorInst {
|
class InvokeInst : public TerminatorInst {
|
||||||
InvokeInst(const InvokeInst &BI);
|
InvokeInst(const InvokeInst &BI);
|
||||||
|
void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
|
||||||
|
const std::vector<Value*> &Params);
|
||||||
public:
|
public:
|
||||||
InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
|
InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
|
||||||
const std::vector<Value*> &Params, const std::string &Name = "",
|
const std::vector<Value*> &Params, const std::string &Name = "",
|
||||||
|
@@ -29,8 +29,7 @@ TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
|
TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
|
||||||
: Instruction(Type::VoidTy, iType) {
|
: Instruction(Type::VoidTy, iType, "", IAE) {
|
||||||
if (IAE) IAE->getInstList().push_back(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -17,14 +17,18 @@
|
|||||||
#include "Support/LeakDetector.h"
|
#include "Support/LeakDetector.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name,
|
void Instruction::init()
|
||||||
Instruction *InsertBefore)
|
{
|
||||||
: User(ty, Value::InstructionVal, Name) {
|
|
||||||
Parent = 0;
|
|
||||||
iType = it;
|
|
||||||
|
|
||||||
// Make sure that we get added to a basicblock
|
// Make sure that we get added to a basicblock
|
||||||
LeakDetector::addGarbageObject(this);
|
LeakDetector::addGarbageObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name,
|
||||||
|
Instruction *InsertBefore)
|
||||||
|
: User(ty, Value::InstructionVal, Name),
|
||||||
|
Parent(0),
|
||||||
|
iType(it) {
|
||||||
|
init();
|
||||||
|
|
||||||
// If requested, insert this instruction into a basic block...
|
// If requested, insert this instruction into a basic block...
|
||||||
if (InsertBefore) {
|
if (InsertBefore) {
|
||||||
@@ -34,6 +38,18 @@ Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name,
|
||||||
|
BasicBlock *InsertAtEnd)
|
||||||
|
: User(ty, Value::InstructionVal, Name),
|
||||||
|
Parent(0),
|
||||||
|
iType(it) {
|
||||||
|
init();
|
||||||
|
|
||||||
|
// append this instruction into the basic block
|
||||||
|
assert(InsertAtEnd && "Basic block to append to may not be NULL!");
|
||||||
|
InsertAtEnd->getInstList().push_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
void Instruction::setParent(BasicBlock *P) {
|
void Instruction::setParent(BasicBlock *P) {
|
||||||
if (getParent()) {
|
if (getParent()) {
|
||||||
if (!P) LeakDetector::addGarbageObject(this);
|
if (!P) LeakDetector::addGarbageObject(this);
|
||||||
|
@@ -28,52 +28,45 @@ void UnwindInst::setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
|||||||
assert(0 && "UnwindInst has no successors!");
|
assert(0 && "UnwindInst has no successors!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BranchInst::init(BasicBlock *IfTrue)
|
||||||
|
{
|
||||||
|
assert(IfTrue != 0 && "Branch destination may not be null!");
|
||||||
|
Operands.reserve(1);
|
||||||
|
Operands.push_back(Use(IfTrue, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BranchInst::init(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond)
|
||||||
|
{
|
||||||
|
assert(IfTrue && IfFalse && Cond &&
|
||||||
|
"Branch destinations and condition may not be null!");
|
||||||
|
assert(Cond && Cond->getType() == Type::BoolTy &&
|
||||||
|
"May only branch on boolean predicates!");
|
||||||
|
Operands.reserve(3);
|
||||||
|
Operands.push_back(Use(IfTrue, this));
|
||||||
|
Operands.push_back(Use(IfFalse, this));
|
||||||
|
Operands.push_back(Use(Cond, this));
|
||||||
|
}
|
||||||
|
|
||||||
BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
|
BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
|
||||||
Instruction *InsertBefore)
|
Instruction *InsertBefore)
|
||||||
: TerminatorInst(Instruction::Br, InsertBefore) {
|
: TerminatorInst(Instruction::Br, InsertBefore) {
|
||||||
assert(True != 0 && "True branch destination may not be null!!!");
|
init(True, False, Cond);
|
||||||
Operands.reserve(False ? 3 : 1);
|
|
||||||
Operands.push_back(Use(True, this));
|
|
||||||
if (False) {
|
|
||||||
Operands.push_back(Use(False, this));
|
|
||||||
Operands.push_back(Use(Cond, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(!!False == !!Cond &&
|
|
||||||
"Either both cond and false or neither can be specified!");
|
|
||||||
assert((Cond == 0 || Cond->getType() == Type::BoolTy) &&
|
|
||||||
"May only branch on boolean predicates!!!!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
|
BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
|
||||||
BasicBlock *InsertAtEnd)
|
BasicBlock *InsertAtEnd)
|
||||||
: TerminatorInst(Instruction::Br, InsertAtEnd) {
|
: TerminatorInst(Instruction::Br, InsertAtEnd) {
|
||||||
assert(True != 0 && "True branch destination may not be null!!!");
|
init(True, False, Cond);
|
||||||
Operands.reserve(False ? 3 : 1);
|
|
||||||
Operands.push_back(Use(True, this));
|
|
||||||
if (False) {
|
|
||||||
Operands.push_back(Use(False, this));
|
|
||||||
Operands.push_back(Use(Cond, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(!!False == !!Cond &&
|
|
||||||
"Either both cond and false or neither can be specified!");
|
|
||||||
assert((Cond == 0 || Cond->getType() == Type::BoolTy) &&
|
|
||||||
"May only branch on boolean predicates!!!!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore)
|
BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore)
|
||||||
: TerminatorInst(Instruction::Br, InsertBefore) {
|
: TerminatorInst(Instruction::Br, InsertBefore) {
|
||||||
assert(True != 0 && "True branch destination may not be null!!!");
|
init(True);
|
||||||
Operands.reserve(1);
|
|
||||||
Operands.push_back(Use(True, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BranchInst::BranchInst(BasicBlock *True, BasicBlock *InsertAtEnd)
|
BranchInst::BranchInst(BasicBlock *True, BasicBlock *InsertAtEnd)
|
||||||
: TerminatorInst(Instruction::Br, InsertAtEnd) {
|
: TerminatorInst(Instruction::Br, InsertAtEnd) {
|
||||||
assert(True != 0 && "True branch destination may not be null!!!");
|
init(True);
|
||||||
Operands.reserve(1);
|
|
||||||
Operands.push_back(Use(True, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
|
BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
|
||||||
|
@@ -99,51 +99,42 @@ Function *CallInst::getCalledFunction() {
|
|||||||
// InvokeInst Implementation
|
// InvokeInst Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
|
void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
|
||||||
BasicBlock *IfException,
|
const std::vector<Value*> &Params)
|
||||||
const std::vector<Value*> ¶ms,
|
{
|
||||||
const std::string &Name, Instruction *InsertBefore)
|
Operands.reserve(3+Params.size());
|
||||||
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
|
Operands.push_back(Use(Fn, this));
|
||||||
->getElementType())->getReturnType(),
|
|
||||||
Instruction::Invoke, Name, InsertBefore) {
|
|
||||||
Operands.reserve(3+params.size());
|
|
||||||
Operands.push_back(Use(Func, this));
|
|
||||||
Operands.push_back(Use((Value*)IfNormal, this));
|
Operands.push_back(Use((Value*)IfNormal, this));
|
||||||
Operands.push_back(Use((Value*)IfException, this));
|
Operands.push_back(Use((Value*)IfException, this));
|
||||||
const FunctionType *MTy =
|
const FunctionType *MTy =
|
||||||
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
|
||||||
|
|
||||||
assert((params.size() == MTy->getNumParams()) ||
|
assert((Params.size() == MTy->getNumParams()) ||
|
||||||
(MTy->isVarArg() && params.size() > MTy->getNumParams()) &&
|
(MTy->isVarArg() && Params.size() > MTy->getNumParams()) &&
|
||||||
"Calling a function with bad signature");
|
"Calling a function with bad signature");
|
||||||
|
|
||||||
for (unsigned i = 0; i < params.size(); i++)
|
for (unsigned i = 0; i < Params.size(); i++)
|
||||||
Operands.push_back(Use(params[i], this));
|
Operands.push_back(Use(Params[i], this));
|
||||||
}
|
}
|
||||||
|
|
||||||
InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
|
InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
|
||||||
BasicBlock *IfException,
|
BasicBlock *IfException,
|
||||||
const std::vector<Value*> ¶ms,
|
const std::vector<Value*> &Params,
|
||||||
const std::string &Name, BasicBlock *InsertAtEnd)
|
const std::string &Name, Instruction *InsertBefore)
|
||||||
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
|
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
|
||||||
->getElementType())->getReturnType(),
|
->getElementType())->getReturnType(),
|
||||||
Instruction::Invoke, Name) {
|
Instruction::Invoke, Name, InsertBefore) {
|
||||||
Operands.reserve(3+params.size());
|
init(Fn, IfNormal, IfException, Params);
|
||||||
Operands.push_back(Use(Func, this));
|
}
|
||||||
Operands.push_back(Use((Value*)IfNormal, this));
|
|
||||||
Operands.push_back(Use((Value*)IfException, this));
|
|
||||||
const FunctionType *MTy =
|
|
||||||
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
|
|
||||||
|
|
||||||
assert((params.size() == MTy->getNumParams()) ||
|
|
||||||
(MTy->isVarArg() && params.size() > MTy->getNumParams()) &&
|
|
||||||
"Calling a function with bad signature");
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < params.size(); i++)
|
|
||||||
Operands.push_back(Use(params[i], this));
|
|
||||||
|
|
||||||
if (InsertAtEnd)
|
InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
|
||||||
InsertAtEnd->getInstList().push_back(this);
|
BasicBlock *IfException,
|
||||||
|
const std::vector<Value*> &Params,
|
||||||
|
const std::string &Name, BasicBlock *InsertAtEnd)
|
||||||
|
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
|
||||||
|
->getElementType())->getReturnType(),
|
||||||
|
Instruction::Invoke, Name, InsertAtEnd) {
|
||||||
|
init(Fn, IfNormal, IfException, Params);
|
||||||
}
|
}
|
||||||
|
|
||||||
InvokeInst::InvokeInst(const InvokeInst &CI)
|
InvokeInst::InvokeInst(const InvokeInst &CI)
|
||||||
|
@@ -67,16 +67,14 @@ FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore)
|
|||||||
LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef)
|
LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef)
|
||||||
: Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
|
: Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
|
||||||
Load, Name, InsertBef), Volatile(false) {
|
Load, Name, InsertBef), Volatile(false) {
|
||||||
Operands.reserve(1);
|
init(Ptr);
|
||||||
Operands.push_back(Use(Ptr, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
|
LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
|
||||||
Instruction *InsertBef)
|
Instruction *InsertBef)
|
||||||
: Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
|
: Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
|
||||||
Load, Name, InsertBef), Volatile(isVolatile) {
|
Load, Name, InsertBef), Volatile(isVolatile) {
|
||||||
Operands.reserve(1);
|
init(Ptr);
|
||||||
Operands.push_back(Use(Ptr, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@@ -85,19 +83,13 @@ LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
|
|||||||
|
|
||||||
StoreInst::StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore)
|
StoreInst::StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore)
|
||||||
: Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(false) {
|
: Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(false) {
|
||||||
|
init(Val, Ptr);
|
||||||
Operands.reserve(2);
|
|
||||||
Operands.push_back(Use(Val, this));
|
|
||||||
Operands.push_back(Use(Ptr, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile,
|
StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile,
|
||||||
Instruction *InsertBefore)
|
Instruction *InsertBefore)
|
||||||
: Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(isVolatile) {
|
: Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(isVolatile) {
|
||||||
|
init(Val, Ptr);
|
||||||
Operands.reserve(2);
|
|
||||||
Operands.push_back(Use(Val, this));
|
|
||||||
Operands.push_back(Use(Ptr, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -113,11 +105,8 @@ static inline const Type *checkType(const Type *Ty) {
|
|||||||
return Ty;
|
return Ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
|
void GetElementPtrInst::init(Value *Ptr, const std::vector<Value*> &Idx)
|
||||||
const std::string &Name, Instruction *InBe)
|
{
|
||||||
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
|
|
||||||
Idx, true))),
|
|
||||||
GetElementPtr, Name, InBe) {
|
|
||||||
Operands.reserve(1+Idx.size());
|
Operands.reserve(1+Idx.size());
|
||||||
Operands.push_back(Use(Ptr, this));
|
Operands.push_back(Use(Ptr, this));
|
||||||
|
|
||||||
@@ -125,6 +114,14 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
|
|||||||
Operands.push_back(Use(Idx[i], this));
|
Operands.push_back(Use(Idx[i], this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
|
||||||
|
const std::string &Name, Instruction *InBe)
|
||||||
|
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
|
||||||
|
Idx, true))),
|
||||||
|
GetElementPtr, Name, InBe) {
|
||||||
|
init(Ptr, Idx);
|
||||||
|
}
|
||||||
|
|
||||||
// getIndexedType - Returns the type of the element that would be loaded with
|
// getIndexedType - Returns the type of the element that would be loaded with
|
||||||
// a load instruction with the specified parameters.
|
// a load instruction with the specified parameters.
|
||||||
//
|
//
|
||||||
|
@@ -15,20 +15,22 @@
|
|||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
|
void SwitchInst::init(Value *Value, BasicBlock *Default)
|
||||||
Instruction *InsertBefore)
|
{
|
||||||
: TerminatorInst(Instruction::Switch, InsertBefore) {
|
assert(Value && Default);
|
||||||
assert(V && DefaultDest);
|
Operands.push_back(Use(Value, this));
|
||||||
Operands.push_back(Use(V, this));
|
Operands.push_back(Use(Default, this));
|
||||||
Operands.push_back(Use(DefaultDest, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
|
SwitchInst::SwitchInst(Value *V, BasicBlock *D,
|
||||||
BasicBlock *InsertAtEnd)
|
Instruction *InsertBefore)
|
||||||
|
: TerminatorInst(Instruction::Switch, InsertBefore) {
|
||||||
|
init(V, D);
|
||||||
|
}
|
||||||
|
|
||||||
|
SwitchInst::SwitchInst(Value *V, BasicBlock *D, BasicBlock *InsertAtEnd)
|
||||||
: TerminatorInst(Instruction::Switch, InsertAtEnd) {
|
: TerminatorInst(Instruction::Switch, InsertAtEnd) {
|
||||||
assert(V && DefaultDest);
|
init(V, D);
|
||||||
Operands.push_back(Use(V, this));
|
|
||||||
Operands.push_back(Use(DefaultDest, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchInst::SwitchInst(const SwitchInst &SI)
|
SwitchInst::SwitchInst(const SwitchInst &SI)
|
||||||
|
Reference in New Issue
Block a user