From 6b538cfc5c758edc8e05070ab8794bd6c3e8ffb9 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Thu, 7 Dec 2006 04:18:31 +0000 Subject: [PATCH] Provide a getOpcode() method on CmpInst to ensure the opcode is returned as the right type. Use this to shorten some code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32300 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/InstrTypes.h | 5 +++++ lib/VMCore/Constants.cpp | 3 +-- lib/VMCore/Instructions.cpp | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 0577db3efc4..eaf56a301cd 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -521,6 +521,11 @@ public: /// @brief Implement superclass method. virtual CmpInst *clone() const; + /// @brief Get the opcode casted to the right type + OtherOps getOpcode() const { + return static_cast(Instruction::getOpcode()); + } + /// The predicate for CmpInst is defined by the subclasses but stored in /// the SubclassData field (see Value.h). We allow it to be fetched here /// as the predicate but there is no enum type for it, just the raw unsigned diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index f9271178a4d..5f1aaea9094 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -378,8 +378,7 @@ struct VISIBILITY_HIDDEN CompareConstantExpr : public ConstantExpr { Use Ops[2]; CompareConstantExpr(Instruction::OtherOps opc, unsigned short pred, Constant* LHS, Constant* RHS) - : ConstantExpr(Type::BoolTy, Instruction::OtherOps(opc), Ops, 2), - predicate(pred) { + : ConstantExpr(Type::BoolTy, opc, Ops, 2), predicate(pred) { OperandList[0].init(LHS, this); OperandList[1].init(RHS, this); } diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 1cc04334cdb..57dd5a56b8a 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -2252,8 +2252,7 @@ BinaryOperator *BinaryOperator::clone() const { } CmpInst* CmpInst::clone() const { - return create(Instruction::OtherOps(getOpcode()), getPredicate(), - Ops[0], Ops[1]); + return create(getOpcode(), getPredicate(), Ops[0], Ops[1]); } MallocInst *MallocInst::clone() const { return new MallocInst(*this); }