[llvm-commits] [llvm] r49482 - in /llvm/branches/ggreif/use-diet: include/llvm/Instructions.h lib/VMCore/Instructions.cpp

Gabor Greif ggreif at gmail.com
Thu Apr 10 07:09:31 PDT 2008


Author: ggreif
Date: Thu Apr 10 09:09:30 2008
New Revision: 49482

URL: http://llvm.org/viewvc/llvm-project?rev=49482&view=rev
Log:
convert CallInst to VariadicOperandTraits

Modified:
    llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
    llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp

Modified: llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Instructions.h?rev=49482&r1=49481&r2=49482&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Instructions.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Instructions.h Thu Apr 10 09:09:30 2008
@@ -364,6 +364,24 @@
 
 
 //===----------------------------------------------------------------------===//
+//                          VariadicOperand Trait Class
+//===----------------------------------------------------------------------===//
+
+template <unsigned MINARITY = 0>
+struct VariadicOperandTraits {
+  static Use *op_begin(User* U) {
+    return reinterpret_cast<Use*>(U) - U->getNumOperands();
+  }
+  static Use *op_end(User* U) {
+    return reinterpret_cast<Use*>(U);
+  }
+  static unsigned operands(const User*U) {
+    return U->getNumOperands();
+  }
+  static inline void *allocate(unsigned); // FIXME
+};
+
+//===----------------------------------------------------------------------===//
 //                             GetElementPtrInst Class
 //===----------------------------------------------------------------------===//
 
@@ -901,13 +919,13 @@
   /// @brief Construct a CallInst from a range of arguments
   template<typename InputIterator>
   CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
-           const std::string &Name = "", Instruction *InsertBefore = 0)
+           const std::string &Name = "", Instruction *InsertBefore = 0);/*
       : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
                                        ->getElementType())->getReturnType(),
                     Instruction::Call, 0, 0, InsertBefore) {
     init(Func, ArgBegin, ArgEnd, Name, 
          typename std::iterator_traits<InputIterator>::iterator_category());
-  }
+  }*/
 
   /// Construct a CallInst given a range of arguments.  InputIterator
   /// must be a random-access iterator pointing to contiguous storage
@@ -916,14 +934,15 @@
   /// incur runtime overhead.
   /// @brief Construct a CallInst from a range of arguments
   template<typename InputIterator>
-  CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
-           const std::string &Name, BasicBlock *InsertAtEnd)
+  inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+                  const std::string &Name, BasicBlock *InsertAtEnd);
+    /*
       : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
                                        ->getElementType())->getReturnType(),
                     Instruction::Call, 0, 0, InsertAtEnd) {
     init(Func, ArgBegin, ArgEnd, Name,
          typename std::iterator_traits<InputIterator>::iterator_category());
-  }
+  }*/
 
   CallInst(Value *F, Value *Actual, const std::string& Name = "",
            Instruction *InsertBefore = 0);
@@ -962,6 +981,9 @@
   ~CallInst();
 
   virtual CallInst *clone() const;
+
+  /// Provide fast operand accessors
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
   
   bool isTailCall() const           { return SubclassData & 1; }
   void setTailCall(bool isTailCall = true) {
@@ -1045,6 +1067,39 @@
   }
 };
 
+template <>
+struct OperandTraits<CallInst> : VariadicOperandTraits<1> {
+};
+
+template<typename InputIterator>
+CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+                   const std::string &Name, BasicBlock *InsertAtEnd)
+  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+                                   ->getElementType())->getReturnType(),
+                Instruction::Call,
+                OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
+                ArgEnd - ArgBegin + 1, InsertAtEnd) {
+  init(Func, ArgBegin, ArgEnd, Name,
+       typename std::iterator_traits<InputIterator>::iterator_category());
+}
+
+template<typename InputIterator>
+CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+                   const std::string &Name, Instruction *InsertBefore)
+  : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+                                   ->getElementType())->getReturnType(),
+                Instruction::Call,
+                OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
+                ArgEnd - ArgBegin + 1, InsertBefore) {
+  init(Func, ArgBegin, ArgEnd, Name, 
+       typename std::iterator_traits<InputIterator>::iterator_category());
+}
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
+//void CallInst::operator delete(void *it) {
+//  OperandTraits<CallInst>::op_begin(static_cast<CallInst*>(it));
+//}
+
 //===----------------------------------------------------------------------===//
 //                               SelectInst Class
 //===----------------------------------------------------------------------===//
@@ -1483,24 +1538,6 @@
 };
 
 //===----------------------------------------------------------------------===//
-//                          VariadicOperand Trait Class
-//===----------------------------------------------------------------------===//
-
-template <unsigned MINARITY = 0>
-struct VariadicOperandTraits {
-  static Use *op_begin(User* U) {
-    return reinterpret_cast<Use*>(U) - U->getNumOperands();
-  }
-  static Use *op_end(User* U) {
-    return reinterpret_cast<Use*>(U);
-  }
-  static unsigned operands(const User*U) {
-    return U->getNumOperands();
-  }
-  static inline void *allocate(unsigned); // FIXME
-};
-
-//===----------------------------------------------------------------------===//
 //                               ReturnInst Class
 //===----------------------------------------------------------------------===//
 

Modified: llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp?rev=49482&r1=49481&r2=49482&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp Thu Apr 10 09:09:30 2008
@@ -244,12 +244,11 @@
 //===----------------------------------------------------------------------===//
 
 CallInst::~CallInst() {
-//  delete [] OperandList;
 }
 
 void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
   NumOperands = NumParams+1;
-  Use *OL = OperandList = allocHangoffUses(NumParams+1);
+  Use *OL = OperandList;
   OL[0].init(Func, this);
 
   const FunctionType *FTy =
@@ -269,7 +268,7 @@
 
 void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
   NumOperands = 3;
-  Use *OL = OperandList = allocHangoffUses(3);
+  Use *OL = OperandList;
   OL[0].init(Func, this);
   OL[1].init(Actual1, this);
   OL[2].init(Actual2, this);
@@ -291,7 +290,7 @@
 
 void CallInst::init(Value *Func, Value *Actual) {
   NumOperands = 2;
-  Use *OL = OperandList = allocHangoffUses(2);
+  Use *OL = OperandList;
   OL[0].init(Func, this);
   OL[1].init(Actual, this);
 
@@ -309,7 +308,7 @@
 
 void CallInst::init(Value *Func) {
   NumOperands = 1;
-  Use *OL = OperandList = allocHangoffUses(1);
+  Use *OL = OperandList;
   OL[0].init(Func, this);
 
   const FunctionType *FTy =
@@ -323,7 +322,9 @@
                    Instruction *InsertBefore)
   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
                                    ->getElementType())->getReturnType(),
-                Instruction::Call, 0, 0, InsertBefore) {
+                Instruction::Call,
+                OperandTraits<CallInst>::op_end(this) - 2,
+                2, InsertBefore) {
   init(Func, Actual);
   setName(Name);
 }
@@ -332,7 +333,9 @@
                    BasicBlock  *InsertAtEnd)
   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
                                    ->getElementType())->getReturnType(),
-                Instruction::Call, 0, 0, InsertAtEnd) {
+                Instruction::Call,
+                OperandTraits<CallInst>::op_end(this) - 2,
+                2, InsertAtEnd) {
   init(Func, Actual);
   setName(Name);
 }
@@ -340,7 +343,9 @@
                    Instruction *InsertBefore)
   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
                                    ->getElementType())->getReturnType(),
-                Instruction::Call, 0, 0, InsertBefore) {
+                Instruction::Call,
+                OperandTraits<CallInst>::op_end(this) - 1,
+                1, InsertBefore) {
   init(Func);
   setName(Name);
 }
@@ -349,13 +354,16 @@
                    BasicBlock *InsertAtEnd)
   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
                                    ->getElementType())->getReturnType(),
-                Instruction::Call, 0, 0, InsertAtEnd) {
+                Instruction::Call,
+                OperandTraits<CallInst>::op_end(this) - 1,
+                1, InsertAtEnd) {
   init(Func);
   setName(Name);
 }
 
 CallInst::CallInst(const CallInst &CI)
-  : Instruction(CI.getType(), Instruction::Call, allocHangoffUses(CI.getNumOperands()),
+  : Instruction(CI.getType(), Instruction::Call,
+                OperandTraits<CallInst>::op_end(this) - CI.getNumOperands(),
                 CI.getNumOperands()) {
   setParamAttrs(CI.getParamAttrs());
   SubclassData = CI.SubclassData;





More information about the llvm-commits mailing list