From 779e4d82dea2d0ecb094252dcc679f8f7d256ca0 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 1 Jul 2020 11:54:18 -0700 Subject: [PATCH] [IR] Add classof methods to ConstantExpr subclasses. I didn't notice these were missing when I wrote 1544019. --- llvm/lib/IR/ConstantsContext.h | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/llvm/lib/IR/ConstantsContext.h b/llvm/lib/IR/ConstantsContext.h index fadbc2169816..95c5ab6d0ee4 100644 --- a/llvm/lib/IR/ConstantsContext.h +++ b/llvm/lib/IR/ConstantsContext.h @@ -56,6 +56,14 @@ public: } DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return Instruction::isCast(CE->getOpcode()) || + Instruction::isUnaryOp(CE->getOpcode()); + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; /// BinaryConstantExpr - This class is private to Constants.cpp, and is used @@ -77,6 +85,13 @@ public: /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return Instruction::isBinaryOp(CE->getOpcode()); + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; /// SelectConstantExpr - This class is private to Constants.cpp, and is used @@ -97,6 +112,13 @@ public: /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::Select; + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; /// ExtractElementConstantExpr - This class is private to @@ -118,6 +140,13 @@ public: /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::ExtractElement; + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; /// InsertElementConstantExpr - This class is private to @@ -140,6 +169,13 @@ public: /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::InsertElement; + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; /// ShuffleVectorConstantExpr - This class is private to @@ -168,6 +204,13 @@ public: /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); + + static bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::ShuffleVector; + } + static bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } }; /// ExtractValueConstantExpr - This class is private to