From 07e8f8869589124603ea6b678e4540cb840f781d Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 15 Dec 2015 06:11:36 +0000 Subject: [PATCH] [IR] Add classof for GetElementPtrConstantExpr, CompareConstantExpr, InsertValueConstantExpr, and ExtractValueConstantExpr. All but CompareConstantExpr were being used in casts that were erroneously using ConstantExpr::classof due to inheritance. While there use cast to simplify code slightly. I believe in one place we were always casting to ExtractValueConstantExpr when we were trying to choose between ExtractValueConstantExpr and InsertValueConstantExpr because of this. But since they have identical layouts this didn't cause any observable problems. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255624 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Constants.cpp | 3 +-- lib/IR/ConstantsContext.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index ac80eae8e94..0898bf64538 100644 --- a/lib/IR/Constants.cpp +++ b/lib/IR/Constants.cpp @@ -1154,8 +1154,7 @@ ArrayRef ConstantExpr::getIndices() const { } unsigned ConstantExpr::getPredicate() const { - assert(isCompare()); - return ((const CompareConstantExpr*)this)->predicate; + return cast(this)->predicate; } /// getWithOperandReplaced - Return a constant expression identical to this diff --git a/lib/IR/ConstantsContext.h b/lib/IR/ConstantsContext.h index 33e89515b26..13fcbd2ece1 100644 --- a/lib/IR/ConstantsContext.h +++ b/lib/IR/ConstantsContext.h @@ -179,6 +179,13 @@ public: /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::ExtractValue; + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; /// InsertValueConstantExpr - This class is private to @@ -205,6 +212,13 @@ public: /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::InsertValue; + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; /// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is @@ -235,6 +249,13 @@ public: Type *getSourceElementType() const; /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::GetElementPtr; + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; // CompareConstantExpr - This class is private to Constants.cpp, and is used @@ -257,6 +278,14 @@ public: } /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::ICmp || + CE->getOpcode() == Instruction::FCmp; + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; template <> -- 2.34.1