From: Gabor Greif Date: Fri, 6 Jun 2008 20:28:12 +0000 (+0000) Subject: make ExtractValueInst derived from UnaryInstruction X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=d4f268bdd47db4db384483db63c3b09f67e9da6a;p=oota-llvm.git make ExtractValueInst derived from UnaryInstruction git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52061 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 386c00118fa..0a3fbed804f 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -118,6 +118,7 @@ public: I->getOpcode() == Instruction::Load || I->getOpcode() == Instruction::VAArg || I->getOpcode() == Instruction::GetResult || + I->getOpcode() == Instruction::ExtractValue || (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd); } static inline bool classof(const Value *V) { diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 5bd029644be..6a599d3fceb 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -1453,7 +1453,7 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) /// ExtractValueInst - This instruction extracts a struct member or array /// element value from an aggregate value. /// -class ExtractValueInst : public Instruction { +class ExtractValueInst : public UnaryInstruction { SmallVector Indices; ExtractValueInst(const ExtractValueInst &EVI); @@ -1526,12 +1526,13 @@ class ExtractValueInst : public Instruction { 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 static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, InputIterator IdxEnd, @@ -1564,9 +1565,6 @@ public: virtual ExtractValueInst *clone() const; - /// Transparently provide more efficient getOperand methods. - DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); - // getType - Overload to return most specific pointer type... const PointerType *getType() const { return reinterpret_cast(Instruction::getType()); @@ -1619,20 +1617,15 @@ public: } }; -template <> -struct OperandTraits : FixedNumOperandTraits<1> { -}; - template ExtractValueInst::ExtractValueInst(Value *Agg, InputIterator IdxBegin, InputIterator IdxEnd, const std::string &Name, Instruction *InsertBefore) - : Instruction(checkType(getIndexedType(Agg->getType(), IdxBegin, IdxEnd)), - ExtractValue, - OperandTraits::op_begin(this), - 1, InsertBefore) { + : UnaryInstruction(checkType(getIndexedType(Agg->getType(), + IdxBegin, IdxEnd)), + ExtractValue, Agg, InsertBefore) { init(Agg, IdxBegin, IdxEnd, Name, typename std::iterator_traits::iterator_category()); } @@ -1642,16 +1635,13 @@ ExtractValueInst::ExtractValueInst(Value *Agg, InputIterator IdxEnd, const std::string &Name, BasicBlock *InsertAtEnd) - : Instruction(checkType(getIndexedType(Agg->getType(), IdxBegin, IdxEnd)), - ExtractValue, - OperandTraits::op_begin(this), - 1, InsertAtEnd) { + : UnaryInstruction(checkType(getIndexedType(Agg->getType(), + IdxBegin, IdxEnd)), + ExtractValue, Agg, InsertAtEnd) { init(Agg, IdxBegin, IdxEnd, Name, typename std::iterator_traits::iterator_category()); } -DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractValueInst, Value) - //===----------------------------------------------------------------------===// // InsertValueInst Class diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index f66076d24e8..4a297b3345b 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -999,7 +999,8 @@ static unsigned retrieveAddrSpace(const Value *Val) { return cast(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 @@ InsertValueInst::InsertValueInst(Value *Agg, // 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 @@ void ExtractValueInst::init(Value *Agg, unsigned Idx, const std::string &Name) { } ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI) - : Instruction(reinterpret_cast(EVI.getType()), ExtractValue, - OperandTraits::op_begin(this), 1), + : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)), Indices(EVI.Indices) { } @@ -1464,10 +1465,8 @@ ExtractValueInst::ExtractValueInst(Value *Agg, unsigned Idx, const std::string &Name, BasicBlock *InsertAtEnd) - : Instruction(checkType(getIndexedType(Agg->getType(), &Idx, 1)), - ExtractValue, - OperandTraits::op_begin(this), - 1, InsertAtEnd) { + : UnaryInstruction(checkType(getIndexedType(Agg->getType(), &Idx, 1)), + ExtractValue, Agg, InsertAtEnd) { init(Agg, Idx, Name); } @@ -1475,10 +1474,8 @@ ExtractValueInst::ExtractValueInst(Value *Agg, unsigned Idx, const std::string &Name, Instruction *InsertBefore) - : Instruction(checkType(getIndexedType(Agg->getType(), &Idx, 1)), - ExtractValue, - OperandTraits::op_begin(this), - 1, InsertBefore) { + : UnaryInstruction(checkType(getIndexedType(Agg->getType(), &Idx, 1)), + ExtractValue, Agg, InsertBefore) { init(Agg, Idx, Name); }