[llvm-commits] CVS: llvm/lib/VMCore/InstrTypes.cpp Instruction.cpp iBranch.cpp iCall.cpp iOperators.cpp iSwitch.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Nov 20 11:46:05 PST 2003
Changes in directory llvm/lib/VMCore:
InstrTypes.cpp updated: 1.23 -> 1.24
Instruction.cpp updated: 1.31 -> 1.32
iBranch.cpp updated: 1.10 -> 1.11
iCall.cpp updated: 1.21 -> 1.22
iOperators.cpp updated: 1.24 -> 1.25
iSwitch.cpp updated: 1.10 -> 1.11
---
Log message:
* Finegrainify namespacification
* Add new constructors to allow insertion of terminator instructions at the
end of basic blocks.
* Move a ReturnInst method out-of-line, so that the vtable and type info don't
need to be emitted to every translation unit that uses the class.
---
Diffs of the changes: (+79 -29)
Index: llvm/lib/VMCore/InstrTypes.cpp
diff -u llvm/lib/VMCore/InstrTypes.cpp:1.23 llvm/lib/VMCore/InstrTypes.cpp:1.24
--- llvm/lib/VMCore/InstrTypes.cpp:1.23 Tue Nov 11 16:41:34 2003
+++ llvm/lib/VMCore/InstrTypes.cpp Thu Nov 20 11:45:12 2003
@@ -18,8 +18,7 @@
#include "llvm/Constant.h"
#include "llvm/Type.h"
#include <algorithm> // find
-
-namespace llvm {
+using namespace llvm;
//===----------------------------------------------------------------------===//
// TerminatorInst Class
@@ -29,6 +28,13 @@
: Instruction(Type::VoidTy, iType, "", IB) {
}
+TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE)
+ : Instruction(Type::VoidTy, iType) {
+ if (IAE) IAE->getInstList().push_back(this);
+}
+
+
+
//===----------------------------------------------------------------------===//
// PHINode Class
//===----------------------------------------------------------------------===//
@@ -58,5 +64,3 @@
}
return Removed;
}
-
-} // End llvm namespace
Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.31 llvm/lib/VMCore/Instruction.cpp:1.32
--- llvm/lib/VMCore/Instruction.cpp:1.31 Tue Nov 11 16:41:34 2003
+++ llvm/lib/VMCore/Instruction.cpp Thu Nov 20 11:45:12 2003
@@ -15,8 +15,7 @@
#include "llvm/SymbolTable.h"
#include "llvm/Type.h"
#include "Support/LeakDetector.h"
-
-namespace llvm {
+using namespace llvm;
Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name,
Instruction *InsertBefore)
@@ -165,5 +164,3 @@
return false;
}
}
-
-} // End llvm namespace
Index: llvm/lib/VMCore/iBranch.cpp
diff -u llvm/lib/VMCore/iBranch.cpp:1.10 llvm/lib/VMCore/iBranch.cpp:1.11
--- llvm/lib/VMCore/iBranch.cpp:1.10 Tue Nov 11 16:41:34 2003
+++ llvm/lib/VMCore/iBranch.cpp Thu Nov 20 11:45:12 2003
@@ -15,8 +15,15 @@
#include "llvm/iTerminators.h"
#include "llvm/BasicBlock.h"
#include "llvm/Type.h"
+using namespace llvm;
+
+// Out-of-line ReturnInst method, put here so the C++ compiler can choose to
+// emit the vtable for the class in this translation unit.
+void ReturnInst::setSuccessor(unsigned idx, BasicBlock *NewSucc) {
+ assert(0 && "ReturnInst has no successors!");
+}
+
-namespace llvm {
BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
Instruction *InsertBefore)
@@ -35,6 +42,23 @@
"May only branch on boolean predicates!!!!");
}
+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!!!!");
+}
+
BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore)
: TerminatorInst(Instruction::Br, InsertBefore) {
assert(True != 0 && "True branch destination may not be null!!!");
@@ -42,6 +66,13 @@
Operands.push_back(Use(True, this));
}
+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));
+}
+
BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
Operands.reserve(BI.Operands.size());
Operands.push_back(Use(BI.Operands[0], this));
@@ -51,5 +82,3 @@
Operands.push_back(Use(BI.Operands[2], this));
}
}
-
-} // End llvm namespace
Index: llvm/lib/VMCore/iCall.cpp
diff -u llvm/lib/VMCore/iCall.cpp:1.21 llvm/lib/VMCore/iCall.cpp:1.22
--- llvm/lib/VMCore/iCall.cpp:1.21 Tue Nov 11 16:41:34 2003
+++ llvm/lib/VMCore/iCall.cpp Thu Nov 20 11:45:12 2003
@@ -16,8 +16,8 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
-
-namespace llvm {
+#include "llvm/Support/CallSite.h"
+using namespace llvm;
//===----------------------------------------------------------------------===//
// CallInst Implementation
@@ -124,6 +124,32 @@
Operands.push_back(Use(params[i], this));
}
+InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException,
+ const std::vector<Value*> ¶ms,
+ const std::string &Name, BasicBlock *InsertAtEnd)
+ : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->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());
+
+ const FunctionType::ParamTypes &PL = MTy->getParamTypes();
+ assert((params.size() == PL.size()) ||
+ (MTy->isVarArg() && params.size() > PL.size()) &&
+ "Calling a function with bad signature");
+
+ for (unsigned i = 0; i < params.size(); i++)
+ Operands.push_back(Use(params[i], this));
+
+ if (InsertAtEnd)
+ InsertAtEnd->getInstList().push_back(this);
+}
+
InvokeInst::InvokeInst(const InvokeInst &CI)
: TerminatorInst(CI.getType(), Instruction::Invoke) {
Operands.reserve(CI.Operands.size());
@@ -146,12 +172,6 @@
return 0;
}
-} // End llvm namespace
-
-#include "llvm/Support/CallSite.h"
-
-namespace llvm {
-
Function *CallSite::getCalledFunction() const {
Value *Callee = getCalledValue();
if (Function *F = dyn_cast<Function>(Callee))
@@ -160,5 +180,3 @@
return cast<Function>(CPR->getValue());
return 0;
}
-
-} // End llvm namespace
Index: llvm/lib/VMCore/iOperators.cpp
diff -u llvm/lib/VMCore/iOperators.cpp:1.24 llvm/lib/VMCore/iOperators.cpp:1.25
--- llvm/lib/VMCore/iOperators.cpp:1.24 Tue Nov 11 16:41:34 2003
+++ llvm/lib/VMCore/iOperators.cpp Thu Nov 20 11:45:12 2003
@@ -15,8 +15,7 @@
#include "llvm/Type.h"
#include "llvm/Constants.h"
#include "llvm/BasicBlock.h"
-
-namespace llvm {
+using namespace llvm;
//===----------------------------------------------------------------------===//
// BinaryOperator Class
@@ -196,5 +195,3 @@
case SetLE: return SetGE;
}
}
-
-} // End llvm namespace
Index: llvm/lib/VMCore/iSwitch.cpp
diff -u llvm/lib/VMCore/iSwitch.cpp:1.10 llvm/lib/VMCore/iSwitch.cpp:1.11
--- llvm/lib/VMCore/iSwitch.cpp:1.10 Tue Nov 11 16:41:34 2003
+++ llvm/lib/VMCore/iSwitch.cpp Thu Nov 20 11:45:12 2003
@@ -13,8 +13,7 @@
#include "llvm/iTerminators.h"
#include "llvm/BasicBlock.h"
-
-namespace llvm {
+using namespace llvm;
SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
Instruction *InsertBefore)
@@ -24,6 +23,14 @@
Operands.push_back(Use(DefaultDest, this));
}
+SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
+ BasicBlock *InsertAtEnd)
+ : TerminatorInst(Instruction::Switch, InsertAtEnd) {
+ assert(V && DefaultDest);
+ Operands.push_back(Use(V, this));
+ Operands.push_back(Use(DefaultDest, this));
+}
+
SwitchInst::SwitchInst(const SwitchInst &SI)
: TerminatorInst(Instruction::Switch) {
Operands.reserve(SI.Operands.size());
@@ -50,5 +57,3 @@
assert(idx*2 < Operands.size() && "Successor index out of range!!!");
Operands.erase(Operands.begin()+idx*2, Operands.begin()+(idx+1)*2);
}
-
-} // End llvm namespace
More information about the llvm-commits
mailing list