From 5814008f4b77774c8563578e1562c9c24a6750c2 Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Sun, 14 Jul 2002 22:48:20 +0000 Subject: [PATCH] Create a static version of Instruction::getOpcodeName(opCode) that can be invoked with only an opcode (i.e., without an instruction). Move all opCode->opCodeName translations there. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2892 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/InstrTypes.h | 5 ----- include/llvm/Instruction.h | 5 ++++- include/llvm/iMemory.h | 10 ---------- include/llvm/iOperators.h | 6 ------ include/llvm/iOther.h | 6 ------ include/llvm/iPHINode.h | 1 - include/llvm/iTerminators.h | 8 -------- 7 files changed, 4 insertions(+), 37 deletions(-) diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index e990db76976..9a28d64fb9c 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -27,7 +27,6 @@ public: // Terminators must implement the methods required by Instruction... virtual Instruction *clone() const = 0; - virtual const char *getOpcodeName() const = 0; // Additionally, they must provide a method to get at the successors of this // terminator instruction. 'idx' may not be >= the number of successors @@ -80,8 +79,6 @@ public: return create(getOpcode(), Operands[0]); } - virtual const char *getOpcodeName() const = 0; - // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const UnaryOperator *) { return true; } static inline bool classof(const Instruction *I) { @@ -126,8 +123,6 @@ public: return create(getOpcode(), Operands[0], Operands[1]); } - virtual const char *getOpcodeName() const = 0; - // swapOperands - Exchange the two operands to this instruction. // This instruction is safe to use on any binary instruction and // does not modify the semantics of the instruction. If the diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 7cdee5d2c1d..e13d1b747b7 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -59,8 +59,11 @@ public: // Subclass classification... getOpcode() returns a member of // one of the enums that is coming soon (down below)... // - virtual const char *getOpcodeName() const = 0; unsigned getOpcode() const { return iType; } + virtual const char *getOpcodeName() const { + return getOpcodeName(getOpcode()); + } + static const char* getOpcodeName(unsigned OpCode); inline bool isTerminator() const { // Instance of TerminatorInst? return iType >= FirstTermOp && iType < NumTermOps; diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h index 8a88c321810..1820e3c6b21 100644 --- a/include/llvm/iMemory.h +++ b/include/llvm/iMemory.h @@ -71,8 +71,6 @@ struct MallocInst : public AllocationInst { return new MallocInst((Type*)getType(), (Value*)Operands[0].get()); } - virtual const char *getOpcodeName() const { return "malloc"; } - // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const MallocInst *) { return true; } static inline bool classof(const Instruction *I) { @@ -96,8 +94,6 @@ struct AllocaInst : public AllocationInst { return new AllocaInst((Type*)getType(), (Value*)Operands[0].get()); } - virtual const char *getOpcodeName() const { return "alloca"; } - // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const AllocaInst *) { return true; } static inline bool classof(const Instruction *I) { @@ -118,8 +114,6 @@ struct FreeInst : public Instruction { virtual Instruction *clone() const { return new FreeInst(Operands[0]); } - virtual const char *getOpcodeName() const { return "free"; } - virtual bool hasSideEffects() const { return true; } // Methods for support type inquiry through isa, cast, and dyn_cast: @@ -210,7 +204,6 @@ public: LoadInst(Value *Ptr, const std::string &Name = ""); virtual Instruction *clone() const { return new LoadInst(*this); } - virtual const char *getOpcodeName() const { return "load"; } virtual unsigned getFirstIndexOperandNumber() const { return 1; } @@ -240,8 +233,6 @@ public: StoreInst(Value *Val, Value *Ptr); virtual Instruction *clone() const { return new StoreInst(*this); } - virtual const char *getOpcodeName() const { return "store"; } - virtual bool hasSideEffects() const { return true; } virtual unsigned getFirstIndexOperandNumber() const { return 2; } @@ -271,7 +262,6 @@ public: GetElementPtrInst(Value *Ptr, const std::vector &Idx, const std::string &Name = ""); virtual Instruction *clone() const { return new GetElementPtrInst(*this); } - virtual const char *getOpcodeName() const { return "getelementptr"; } virtual unsigned getFirstIndexOperandNumber() const { return 1; } // getType - Overload to return most specific pointer type... diff --git a/include/llvm/iOperators.h b/include/llvm/iOperators.h index f9cba9f68ca..f9fc88ac41a 100644 --- a/include/llvm/iOperators.h +++ b/include/llvm/iOperators.h @@ -18,8 +18,6 @@ public: GenericUnaryInst(UnaryOps Opcode, Value *S1, const std::string &Name = "") : UnaryOperator(S1, Opcode, Name) { } - - virtual const char *getOpcodeName() const; }; //===----------------------------------------------------------------------===// @@ -35,8 +33,6 @@ public: const std::string &Name = "") : BinaryOperator(Opcode, S1, S2, Name) { } - - virtual const char *getOpcodeName() const; }; class SetCondInst : public BinaryOperator { @@ -44,8 +40,6 @@ class SetCondInst : public BinaryOperator { public: SetCondInst(BinaryOps opType, Value *S1, Value *S2, const std::string &Name = ""); - - virtual const char *getOpcodeName() const; }; #endif diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h index 96d2c7e1b19..31c50fe32ee 100644 --- a/include/llvm/iOther.h +++ b/include/llvm/iOther.h @@ -30,7 +30,6 @@ public: } virtual Instruction *clone() const { return new CastInst(*this); } - virtual const char *getOpcodeName() const { return "cast"; } // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const CastInst *) { return true; } @@ -52,8 +51,6 @@ class CallInst : public Instruction { public: CallInst(Value *M, const std::vector &Par, const std::string & = ""); - virtual const char *getOpcodeName() const { return "call"; } - virtual Instruction *clone() const { return new CallInst(*this); } bool hasSideEffects() const { return true; } @@ -103,9 +100,6 @@ public: OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); } virtual Instruction *clone() const { return new ShiftInst(*this); } - virtual const char *getOpcodeName() const { - return getOpcode() == Shl ? "shl" : "shr"; - } // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const ShiftInst *) { return true; } diff --git a/include/llvm/iPHINode.h b/include/llvm/iPHINode.h index 0ac0d44c669..081c57a7d44 100644 --- a/include/llvm/iPHINode.h +++ b/include/llvm/iPHINode.h @@ -24,7 +24,6 @@ public: PHINode(const Type *Ty, const std::string &Name = ""); virtual Instruction *clone() const { return new PHINode(*this); } - virtual const char *getOpcodeName() const { return "phi"; } // getNumIncomingValues - Return the number of incoming edges the PHI node has inline unsigned getNumIncomingValues() const { return Operands.size()/2; } diff --git a/include/llvm/iTerminators.h b/include/llvm/iTerminators.h index b17029be750..9a421527b51 100644 --- a/include/llvm/iTerminators.h +++ b/include/llvm/iTerminators.h @@ -39,8 +39,6 @@ public: virtual Instruction *clone() const { return new ReturnInst(*this); } - virtual const char *getOpcodeName() const { return "ret"; } - inline const Value *getReturnValue() const { return Operands.size() ? Operands[0].get() : 0; } @@ -89,8 +87,6 @@ public: return isUnconditional() ? 0 : Operands[2].get(); } - virtual const char *getOpcodeName() const { return "br"; } - // setUnconditionalDest - Change the current branch to an unconditional branch // targeting the specified block. // @@ -153,8 +149,6 @@ public: void dest_push_back(Constant *OnVal, BasicBlock *Dest); - virtual const char *getOpcodeName() const { return "switch"; } - virtual const BasicBlock *getSuccessor(unsigned idx) const { assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); return cast(Operands[idx*2+1].get()); @@ -241,8 +235,6 @@ public: Operands[2] = (Value*)B; } - virtual const char *getOpcodeName() const { return "invoke"; } - virtual const BasicBlock *getSuccessor(unsigned i) const { assert(i < 2 && "Successor # out of range for invoke!"); return i == 0 ? getNormalDest() : getExceptionalDest(); -- 2.34.1