diff options
author | Chris Lattner <sabre@nondot.org> | 2003-11-20 17:45:12 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-11-20 17:45:12 +0000 |
commit | 4b74c8333495c609fa81421df32e46db616672e1 (patch) | |
tree | 1f238f6a4b006f1543946172c52a29e721ad58a4 /lib/VMCore | |
parent | dd56927846f8092cbca6084de584cdc18117b0aa (diff) | |
download | external_llvm-4b74c8333495c609fa81421df32e46db616672e1.zip external_llvm-4b74c8333495c609fa81421df32e46db616672e1.tar.gz external_llvm-4b74c8333495c609fa81421df32e46db616672e1.tar.bz2 |
* 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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/InstrTypes.cpp | 12 | ||||
-rw-r--r-- | lib/VMCore/Instruction.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/iBranch.cpp | 35 | ||||
-rw-r--r-- | lib/VMCore/iCall.cpp | 38 | ||||
-rw-r--r-- | lib/VMCore/iOperators.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/iSwitch.cpp | 13 |
6 files changed, 79 insertions, 29 deletions
diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp index 17e16fa..b10f9cc 100644 --- a/lib/VMCore/InstrTypes.cpp +++ b/lib/VMCore/InstrTypes.cpp @@ -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 @@ TerminatorInst::TerminatorInst(Instruction::TermOps iType, Instruction *IB) : 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 @@ Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) { } return Removed; } - -} // End llvm namespace diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 9ca2fed..2e22bc3 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -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 @@ bool Instruction::isTrapping(unsigned op) { return false; } } - -} // End llvm namespace diff --git a/lib/VMCore/iBranch.cpp b/lib/VMCore/iBranch.cpp index 59dc303..1a169c6 100644 --- a/lib/VMCore/iBranch.cpp +++ b/lib/VMCore/iBranch.cpp @@ -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 @@ BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond, "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 @@ BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore) 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 @@ BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) { Operands.push_back(Use(BI.Operands[2], this)); } } - -} // End llvm namespace diff --git a/lib/VMCore/iCall.cpp b/lib/VMCore/iCall.cpp index c385afc..2d41dcd 100644 --- a/lib/VMCore/iCall.cpp +++ b/lib/VMCore/iCall.cpp @@ -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 @@ InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal, 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 @@ Function *InvokeInst::getCalledFunction() { 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 @@ Function *CallSite::getCalledFunction() const { return cast<Function>(CPR->getValue()); return 0; } - -} // End llvm namespace diff --git a/lib/VMCore/iOperators.cpp b/lib/VMCore/iOperators.cpp index 79fac33..9cd7612 100644 --- a/lib/VMCore/iOperators.cpp +++ b/lib/VMCore/iOperators.cpp @@ -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 @@ Instruction::BinaryOps SetCondInst::getSwappedCondition(BinaryOps Opcode) { case SetLE: return SetGE; } } - -} // End llvm namespace diff --git a/lib/VMCore/iSwitch.cpp b/lib/VMCore/iSwitch.cpp index 4386b7b..c4cffc2 100644 --- a/lib/VMCore/iSwitch.cpp +++ b/lib/VMCore/iSwitch.cpp @@ -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 @@ SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest, 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 @@ void SwitchInst::removeCase(unsigned idx) { assert(idx*2 < Operands.size() && "Successor index out of range!!!"); Operands.erase(Operands.begin()+idx*2, Operands.begin()+(idx+1)*2); } - -} // End llvm namespace |