#include "llvm/Constant.h"
#include "llvm/Type.h"
#include <algorithm> // find
-
-namespace llvm {
+using namespace llvm;
//===----------------------------------------------------------------------===//
// TerminatorInst Class
: 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
//===----------------------------------------------------------------------===//
}
return Removed;
}
-
-} // End llvm namespace
#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)
return false;
}
}
-
-} // End llvm namespace
#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)
"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!!!");
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));
Operands.push_back(Use(BI.Operands[2], this));
}
}
-
-} // End llvm namespace
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
-
-namespace llvm {
+#include "llvm/Support/CallSite.h"
+using namespace llvm;
//===----------------------------------------------------------------------===//
// CallInst Implementation
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());
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))
return cast<Function>(CPR->getValue());
return 0;
}
-
-} // End llvm namespace
#include "llvm/Type.h"
#include "llvm/Constants.h"
#include "llvm/BasicBlock.h"
-
-namespace llvm {
+using namespace llvm;
//===----------------------------------------------------------------------===//
// BinaryOperator Class
case SetLE: return SetGE;
}
}
-
-} // End llvm namespace
#include "llvm/iTerminators.h"
#include "llvm/BasicBlock.h"
-
-namespace llvm {
+using namespace llvm;
SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
Instruction *InsertBefore)
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());
assert(idx*2 < Operands.size() && "Successor index out of range!!!");
Operands.erase(Operands.begin()+idx*2, Operands.begin()+(idx+1)*2);
}
-
-} // End llvm namespace