* Finegrainify namespacification
authorChris Lattner <sabre@nondot.org>
Thu, 20 Nov 2003 17:45:12 +0000 (17:45 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 20 Nov 2003 17:45:12 +0000 (17:45 +0000)
* 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

lib/VMCore/InstrTypes.cpp
lib/VMCore/Instruction.cpp
lib/VMCore/iBranch.cpp
lib/VMCore/iCall.cpp
lib/VMCore/iOperators.cpp
lib/VMCore/iSwitch.cpp

index 17e16fa733fd675cca42b7e1de0211678a429bbf..b10f9cc31cf3031fecc967e4a4f8851a45a25790 100644 (file)
@@ -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
index 9ca2fedbf4f83afecbb21af0ace6d1820231a42c..2e22bc3641aea224cfedd4a2ccddbde73703062e 100644 (file)
@@ -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
index 59dc303d70103856fe85b1764db47cd029b2f10c..1a169c6d0ef27dbfa4ee9248ab5922f721883306 100644 (file)
 #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
index c385afc778bc4625a5493ead712331c7fa98cbed..2d41dcd274349a54c283b08016ce34ad08afd02f 100644 (file)
@@ -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*> &params,
+                      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
index 79fac335fe54635f53ea9c9033f6d99aef7b153d..9cd7612fcb244498e7986f52e696e260ccb13634 100644 (file)
@@ -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
index 4386b7b837ce02eaec7a842855f2c3128cb8f418..c4cffc22d7d111d967f849bd316dfcaa02374091 100644 (file)
@@ -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