[llvm-commits] CVS: llvm/lib/VMCore/iSwitch.cpp iMemory.cpp iCall.cpp iBranch.cpp Instruction.cpp InstrTypes.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Wed May 26 16:44:01 PDT 2004
Changes in directory llvm/lib/VMCore:
iSwitch.cpp updated: 1.11 -> 1.12
iMemory.cpp updated: 1.38 -> 1.39
iCall.cpp updated: 1.23 -> 1.24
iBranch.cpp updated: 1.12 -> 1.13
Instruction.cpp updated: 1.35 -> 1.36
InstrTypes.cpp updated: 1.24 -> 1.25
---
Log message:
Refactor common initialization code in private init() functions.
This is a first step in supplying append to basic block constructors
for all instruction types.
---
Diffs of the changes: (+96 -98)
Index: llvm/lib/VMCore/iSwitch.cpp
diff -u llvm/lib/VMCore/iSwitch.cpp:1.11 llvm/lib/VMCore/iSwitch.cpp:1.12
--- llvm/lib/VMCore/iSwitch.cpp:1.11 Thu Nov 20 11:45:12 2003
+++ llvm/lib/VMCore/iSwitch.cpp Wed May 26 16:41:09 2004
@@ -15,20 +15,22 @@
#include "llvm/BasicBlock.h"
using namespace llvm;
-SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
+void SwitchInst::init(Value *Value, BasicBlock *Default)
+{
+ assert(Value && Default);
+ Operands.push_back(Use(Value, this));
+ Operands.push_back(Use(Default, this));
+}
+
+SwitchInst::SwitchInst(Value *V, BasicBlock *D,
Instruction *InsertBefore)
: TerminatorInst(Instruction::Switch, InsertBefore) {
- assert(V && DefaultDest);
- Operands.push_back(Use(V, this));
- Operands.push_back(Use(DefaultDest, this));
+ init(V, D);
}
-SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
- BasicBlock *InsertAtEnd)
+SwitchInst::SwitchInst(Value *V, BasicBlock *D, BasicBlock *InsertAtEnd)
: TerminatorInst(Instruction::Switch, InsertAtEnd) {
- assert(V && DefaultDest);
- Operands.push_back(Use(V, this));
- Operands.push_back(Use(DefaultDest, this));
+ init(V, D);
}
SwitchInst::SwitchInst(const SwitchInst &SI)
Index: llvm/lib/VMCore/iMemory.cpp
diff -u llvm/lib/VMCore/iMemory.cpp:1.38 llvm/lib/VMCore/iMemory.cpp:1.39
--- llvm/lib/VMCore/iMemory.cpp:1.38 Thu May 6 17:15:47 2004
+++ llvm/lib/VMCore/iMemory.cpp Wed May 26 16:41:09 2004
@@ -67,16 +67,14 @@
LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef)
: Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
Load, Name, InsertBef), Volatile(false) {
- Operands.reserve(1);
- Operands.push_back(Use(Ptr, this));
+ init(Ptr);
}
LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
Instruction *InsertBef)
: Instruction(cast<PointerType>(Ptr->getType())->getElementType(),
Load, Name, InsertBef), Volatile(isVolatile) {
- Operands.reserve(1);
- Operands.push_back(Use(Ptr, this));
+ init(Ptr);
}
//===----------------------------------------------------------------------===//
@@ -85,19 +83,13 @@
StoreInst::StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore)
: Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(false) {
-
- Operands.reserve(2);
- Operands.push_back(Use(Val, this));
- Operands.push_back(Use(Ptr, this));
+ init(Val, Ptr);
}
StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile,
Instruction *InsertBefore)
: Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(isVolatile) {
-
- Operands.reserve(2);
- Operands.push_back(Use(Val, this));
- Operands.push_back(Use(Ptr, this));
+ init(Val, Ptr);
}
@@ -113,16 +105,21 @@
return Ty;
}
-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) {
+void GetElementPtrInst::init(Value *Ptr, const std::vector<Value*> &Idx)
+{
Operands.reserve(1+Idx.size());
Operands.push_back(Use(Ptr, this));
for (unsigned i = 0, E = Idx.size(); i != E; ++i)
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
Index: llvm/lib/VMCore/iCall.cpp
diff -u llvm/lib/VMCore/iCall.cpp:1.23 llvm/lib/VMCore/iCall.cpp:1.24
--- llvm/lib/VMCore/iCall.cpp:1.23 Sun Feb 8 22:14:01 2004
+++ llvm/lib/VMCore/iCall.cpp Wed May 26 16:41:09 2004
@@ -99,51 +99,42 @@
// InvokeInst Implementation
//===----------------------------------------------------------------------===//
-InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException,
- const std::vector<Value*> ¶ms,
- const std::string &Name, Instruction *InsertBefore)
- : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
- ->getElementType())->getReturnType(),
- Instruction::Invoke, Name, InsertBefore) {
- Operands.reserve(3+params.size());
- Operands.push_back(Use(Func, this));
+void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
+ const std::vector<Value*> &Params)
+{
+ Operands.reserve(3+Params.size());
+ Operands.push_back(Use(Fn, 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());
+ cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
- assert((params.size() == MTy->getNumParams()) ||
- (MTy->isVarArg() && params.size() > MTy->getNumParams()) &&
+ 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));
+ for (unsigned i = 0; i < Params.size(); i++)
+ Operands.push_back(Use(Params[i], this));
}
-InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
+InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
BasicBlock *IfException,
- const std::vector<Value*> ¶ms,
- const std::string &Name, BasicBlock *InsertAtEnd)
- : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
+ const std::vector<Value*> &Params,
+ const std::string &Name, Instruction *InsertBefore)
+ : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
->getElementType())->getReturnType(),
- Instruction::Invoke, Name) {
- Operands.reserve(3+params.size());
- 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));
+ Instruction::Invoke, Name, InsertBefore) {
+ init(Fn, IfNormal, IfException, Params);
+}
- if (InsertAtEnd)
- InsertAtEnd->getInstList().push_back(this);
+InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
+ 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)
Index: llvm/lib/VMCore/iBranch.cpp
diff -u llvm/lib/VMCore/iBranch.cpp:1.12 llvm/lib/VMCore/iBranch.cpp:1.13
--- llvm/lib/VMCore/iBranch.cpp:1.12 Thu Nov 20 12:11:56 2003
+++ llvm/lib/VMCore/iBranch.cpp Wed May 26 16:41:09 2004
@@ -28,52 +28,45 @@
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,
Instruction *InsertBefore)
: TerminatorInst(Instruction::Br, InsertBefore) {
- assert(True != 0 && "True branch destination may not be null!!!");
- 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!!!!");
+ init(True, False, Cond);
}
BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
BasicBlock *InsertAtEnd)
: TerminatorInst(Instruction::Br, InsertAtEnd) {
- assert(True != 0 && "True branch destination may not be null!!!");
- 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!!!!");
+ init(True, False, Cond);
}
BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore)
: TerminatorInst(Instruction::Br, InsertBefore) {
- assert(True != 0 && "True branch destination may not be null!!!");
- Operands.reserve(1);
- Operands.push_back(Use(True, this));
+ init(True);
}
BranchInst::BranchInst(BasicBlock *True, BasicBlock *InsertAtEnd)
: TerminatorInst(Instruction::Br, InsertAtEnd) {
- assert(True != 0 && "True branch destination may not be null!!!");
- Operands.reserve(1);
- Operands.push_back(Use(True, this));
+ init(True);
}
BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.35 llvm/lib/VMCore/Instruction.cpp:1.36
--- llvm/lib/VMCore/Instruction.cpp:1.35 Thu Mar 11 23:54:20 2004
+++ llvm/lib/VMCore/Instruction.cpp Wed May 26 16:41:09 2004
@@ -17,14 +17,18 @@
#include "Support/LeakDetector.h"
using namespace llvm;
-Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name,
- Instruction *InsertBefore)
- : User(ty, Value::InstructionVal, Name) {
- Parent = 0;
- iType = it;
-
+void Instruction::init()
+{
// Make sure that we get added to a basicblock
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 (InsertBefore) {
@@ -32,6 +36,18 @@
"Instruction to insert before is not in a basic block!");
InsertBefore->getParent()->getInstList().insert(InsertBefore, this);
}
+}
+
+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) {
Index: llvm/lib/VMCore/InstrTypes.cpp
diff -u llvm/lib/VMCore/InstrTypes.cpp:1.24 llvm/lib/VMCore/InstrTypes.cpp:1.25
--- llvm/lib/VMCore/InstrTypes.cpp:1.24 Thu Nov 20 11:45:12 2003
+++ llvm/lib/VMCore/InstrTypes.cpp Wed May 26 16:41:09 2004
@@ -29,8 +29,7 @@
}
TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
- : Instruction(Type::VoidTy, iType) {
- if (IAE) IAE->getInstList().push_back(this);
+ : Instruction(Type::VoidTy, iType, "", IAE) {
}
More information about the llvm-commits
mailing list