Derive GetResultInst from UnaryInstruction, this simplifies code and removes a FIXME.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51023 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Gabor Greif
2008-05-13 07:09:08 +00:00
parent 6ddba2b933
commit d6a2218586
3 changed files with 13 additions and 30 deletions

View File

@ -86,6 +86,7 @@ public:
class UnaryInstruction : public Instruction { class UnaryInstruction : public Instruction {
void *operator new(size_t, unsigned); // Do not implement void *operator new(size_t, unsigned); // Do not implement
UnaryInstruction(const UnaryInstruction&); // Do not implement
protected: protected:
UnaryInstruction(const Type *Ty, unsigned iType, Value *V, Instruction *IB = 0) UnaryInstruction(const Type *Ty, unsigned iType, Value *V, Instruction *IB = 0)
@ -116,6 +117,7 @@ public:
I->getOpcode() == Instruction::Free || I->getOpcode() == Instruction::Free ||
I->getOpcode() == Instruction::Load || I->getOpcode() == Instruction::Load ||
I->getOpcode() == Instruction::VAArg || I->getOpcode() == Instruction::VAArg ||
I->getOpcode() == Instruction::GetResult ||
(I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd); (I->getOpcode() >= CastOpsBegin && I->getOpcode() < CastOpsEnd);
} }
static inline bool classof(const Value *V) { static inline bool classof(const Value *V) {

View File

@ -2761,20 +2761,14 @@ public:
/// GetResultInst - This instruction extracts individual result value from /// GetResultInst - This instruction extracts individual result value from
/// aggregate value, where aggregate value is returned by CallInst. /// aggregate value, where aggregate value is returned by CallInst.
/// ///
class GetResultInst : public /*FIXME: Unary*/Instruction { class GetResultInst : public UnaryInstruction {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
unsigned Idx; unsigned Idx;
GetResultInst(const GetResultInst &GRI) : GetResultInst(const GetResultInst &GRI) :
Instruction(GRI.getType(), Instruction::GetResult, &Op<0>(), 1) { UnaryInstruction(GRI.getType(), Instruction::GetResult, GRI.getOperand(0)),
Op<0>().init(GRI.Op<0>(), this); Idx(GRI.Idx) {
Idx = GRI.Idx;
} }
public: public:
// allocate space for exactly one operand
void *operator new(size_t s) {
return User::operator new(s, 1);
}
GetResultInst(Value *Aggr, unsigned index, GetResultInst(Value *Aggr, unsigned index,
const std::string &Name = "", const std::string &Name = "",
Instruction *InsertBefore = 0); Instruction *InsertBefore = 0);
@ -2797,9 +2791,6 @@ public:
return Idx; return Idx;
} }
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
// Methods for support type inquiry through isa, cast, and dyn_cast: // Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GetResultInst *) { return true; } static inline bool classof(const GetResultInst *) { return true; }
static inline bool classof(const Instruction *I) { static inline bool classof(const Instruction *I) {
@ -2810,14 +2801,6 @@ public:
} }
}; };
// FIXME: these are redundant if GetResultInst < UnaryInstruction
template <>
struct OperandTraits<GetResultInst> : FixedNumOperandTraits<1> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetResultInst, Value)
} // End llvm namespace } // End llvm namespace
#endif #endif

View File

@ -2734,14 +2734,12 @@ void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
GetResultInst::GetResultInst(Value *Aggregate, unsigned Index, GetResultInst::GetResultInst(Value *Aggregate, unsigned Index,
const std::string &Name, const std::string &Name,
Instruction *InsertBef) Instruction *InsertBef)
: Instruction(cast<StructType>(Aggregate->getType())->getElementType(Index), : UnaryInstruction(cast<StructType>(Aggregate->getType())
GetResult, ->getElementType(Index),
OperandTraits<GetResultInst>::op_begin(this), GetResult, Aggregate, InsertBef),
OperandTraits<GetResultInst>::operands(this), Idx(Index) {
InsertBef) { assert(isValidOperands(Aggregate, Index)
assert(isValidOperands(Aggregate, Index) && "Invalid GetResultInst operands!"); && "Invalid GetResultInst operands!");
Op<0>().init(Aggregate, this);
Idx = Index;
setName(Name); setName(Name);
} }