[llvm-commits] [PATCH] ExtractValueInst < UnaryInstruction

Gabor Greif gabor at mac.com
Fri Jun 6 11:13:43 PDT 2008


This patch makes a slight change to the inheritance
graph, by deriving ExtractValueInst from UnaryInstruction.

Dan, Mathiijs, OK to commit?

The only thing that could be improved on this is
the elimination of the name argument to init().

Cheers,

	Gabor



Index: include/llvm/Instructions.h
===================================================================
--- include/llvm/Instructions.h (Revision 52051)
+++ include/llvm/Instructions.h (Arbeitskopie)
@@ -1453,7 +1453,7 @@
  /// ExtractValueInst - This instruction extracts a struct member or  
array
  /// element value from an aggregate value.
  ///
-class ExtractValueInst : public Instruction {
+class ExtractValueInst : public UnaryInstruction {
    SmallVector<unsigned, 4> Indices;

    ExtractValueInst(const ExtractValueInst &EVI);
@@ -1526,12 +1526,13 @@
                      Instruction *InsertBefore = 0);
    ExtractValueInst(Value *Agg, unsigned Idx,
                      const std::string &Name, BasicBlock *InsertAtEnd);
-public:
+
    // allocate space for exactly one operand
    void *operator new(size_t s) {
      return User::operator new(s, 1);
    }

+public:
    template<typename InputIterator>
    static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
                                    InputIterator IdxEnd,
@@ -1629,10 +1630,9 @@
                                     InputIterator IdxEnd,
                                     const std::string &Name,
                                     Instruction *InsertBefore)
-  : Instruction(checkType(getIndexedType(Agg->getType(), IdxBegin,  
IdxEnd)),
-                ExtractValue,
-                OperandTraits<ExtractValueInst>::op_begin(this),
-                1, InsertBefore) {
+  : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
+                                             IdxBegin, IdxEnd)),
+                    ExtractValue, Agg, InsertBefore) {
    init(Agg, IdxBegin, IdxEnd, Name,
         typename  
std::iterator_traits<InputIterator>::iterator_category());
  }
@@ -1642,10 +1642,9 @@
                                     InputIterator IdxEnd,
                                     const std::string &Name,
                                     BasicBlock *InsertAtEnd)
-  : Instruction(checkType(getIndexedType(Agg->getType(), IdxBegin,  
IdxEnd)),
-                ExtractValue,
-                OperandTraits<ExtractValueInst>::op_begin(this),
-                1, InsertAtEnd) {
+  : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
+                                             IdxBegin, IdxEnd)),
+                    ExtractValue, Agg, InsertAtEnd) {
    init(Agg, IdxBegin, IdxEnd, Name,
         typename  
std::iterator_traits<InputIterator>::iterator_category());
  }
Index: lib/VMCore/Instructions.cpp
===================================================================
--- lib/VMCore/Instructions.cpp (Revision 52051)
+++ lib/VMCore/Instructions.cpp (Arbeitskopie)
@@ -999,7 +999,8 @@
    return cast<PointerType>(Val->getType())->getAddressSpace();
  }

-void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned  
NumIdx, const std::string &Name) {
+void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned  
NumIdx,
+                            const std::string &Name) {
    assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
    Use *OL = OperandList;
    OL[0] = Ptr;
@@ -1411,7 +1412,8 @@
  //                             ExtractValueInst Class
  // 
===--------------------------------------------------------------------- 
-===//

-void ExtractValueInst::init(Value *Agg, const unsigned *Idx,  
unsigned NumIdx, const std::string &Name) {
+void ExtractValueInst::init(Value *Agg, const unsigned *Idx,  
unsigned NumIdx,
+                           const std::string &Name) {
    assert(NumOperands == 1 && "NumOperands not initialized?");
    Op<0>() = Agg;

@@ -1428,8 +1430,7 @@
  }

  ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
-  : Instruction(reinterpret_cast<const Type*>(EVI.getType()),  
ExtractValue,
-                OperandTraits<ExtractValueInst>::op_begin(this), 1),
+  : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)),
      Indices(EVI.Indices) {
  }

@@ -1464,10 +1465,8 @@
                                     unsigned Idx,
                                     const std::string &Name,
                                     BasicBlock *InsertAtEnd)
-  : Instruction(checkType(getIndexedType(Agg->getType(), &Idx, 1)),
-                ExtractValue,
-                OperandTraits<ExtractValueInst>::op_begin(this),
-                1, InsertAtEnd) {
+  : UnaryInstruction(checkType(getIndexedType(Agg->getType(), &Idx,  
1)),
+                    ExtractValue, Agg, InsertAtEnd) {
    init(Agg, Idx, Name);
  }

@@ -1475,10 +1474,8 @@
                                     unsigned Idx,
                                     const std::string &Name,
                                     Instruction *InsertBefore)
-  : Instruction(checkType(getIndexedType(Agg->getType(), &Idx, 1)),
-                ExtractValue,
-                OperandTraits<ExtractValueInst>::op_begin(this),
-                1, InsertBefore) {
+  : UnaryInstruction(checkType(getIndexedType(Agg->getType(), &Idx,  
1)),
+                    ExtractValue, Agg, InsertBefore) {
    init(Agg, Idx, Name);
  }





More information about the llvm-commits mailing list