llvm.org GIT mirror llvm / 5814008
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 Vikram S. Adve 17 years ago
7 changed file(s) with 4 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
2626
2727 // Terminators must implement the methods required by Instruction...
2828 virtual Instruction *clone() const = 0;
29 virtual const char *getOpcodeName() const = 0;
3029
3130 // Additionally, they must provide a method to get at the successors of this
3231 // terminator instruction. 'idx' may not be >= the number of successors
7978 return create(getOpcode(), Operands[0]);
8079 }
8180
82 virtual const char *getOpcodeName() const = 0;
83
8481 // Methods for support type inquiry through isa, cast, and dyn_cast:
8582 static inline bool classof(const UnaryOperator *) { return true; }
8683 static inline bool classof(const Instruction *I) {
125122 return create(getOpcode(), Operands[0], Operands[1]);
126123 }
127124
128 virtual const char *getOpcodeName() const = 0;
129
130125 // swapOperands - Exchange the two operands to this instruction.
131126 // This instruction is safe to use on any binary instruction and
132127 // does not modify the semantics of the instruction. If the
5858 // Subclass classification... getOpcode() returns a member of
5959 // one of the enums that is coming soon (down below)...
6060 //
61 virtual const char *getOpcodeName() const = 0;
6261 unsigned getOpcode() const { return iType; }
62 virtual const char *getOpcodeName() const {
63 return getOpcodeName(getOpcode());
64 }
65 static const char* getOpcodeName(unsigned OpCode);
6366
6467 inline bool isTerminator() const { // Instance of TerminatorInst?
6568 return iType >= FirstTermOp && iType < NumTermOps;
7070 return new MallocInst((Type*)getType(), (Value*)Operands[0].get());
7171 }
7272
73 virtual const char *getOpcodeName() const { return "malloc"; }
74
7573 // Methods for support type inquiry through isa, cast, and dyn_cast:
7674 static inline bool classof(const MallocInst *) { return true; }
7775 static inline bool classof(const Instruction *I) {
9593 return new AllocaInst((Type*)getType(), (Value*)Operands[0].get());
9694 }
9795
98 virtual const char *getOpcodeName() const { return "alloca"; }
99
10096 // Methods for support type inquiry through isa, cast, and dyn_cast:
10197 static inline bool classof(const AllocaInst *) { return true; }
10298 static inline bool classof(const Instruction *I) {
116112 FreeInst(Value *Ptr);
117113
118114 virtual Instruction *clone() const { return new FreeInst(Operands[0]); }
119
120 virtual const char *getOpcodeName() const { return "free"; }
121115
122116 virtual bool hasSideEffects() const { return true; }
123117
209203 LoadInst(Value *Ptr, const std::string &Name = "");
210204
211205 virtual Instruction *clone() const { return new LoadInst(*this); }
212 virtual const char *getOpcodeName() const { return "load"; }
213206
214207 virtual unsigned getFirstIndexOperandNumber() const { return 1; }
215208
239232 StoreInst(Value *Val, Value *Ptr);
240233 virtual Instruction *clone() const { return new StoreInst(*this); }
241234
242 virtual const char *getOpcodeName() const { return "store"; }
243
244235 virtual bool hasSideEffects() const { return true; }
245236 virtual unsigned getFirstIndexOperandNumber() const { return 2; }
246237
270261 GetElementPtrInst(Value *Ptr, const std::vector &Idx,
271262 const std::string &Name = "");
272263 virtual Instruction *clone() const { return new GetElementPtrInst(*this); }
273 virtual const char *getOpcodeName() const { return "getelementptr"; }
274264 virtual unsigned getFirstIndexOperandNumber() const { return 1; }
275265
276266 // getType - Overload to return most specific pointer type...
1717 GenericUnaryInst(UnaryOps Opcode, Value *S1, const std::string &Name = "")
1818 : UnaryOperator(S1, Opcode, Name) {
1919 }
20
21 virtual const char *getOpcodeName() const;
2220 };
2321
2422 //===----------------------------------------------------------------------===//
3432 const std::string &Name = "")
3533 : BinaryOperator(Opcode, S1, S2, Name) {
3634 }
37
38 virtual const char *getOpcodeName() const;
3935 };
4036
4137 class SetCondInst : public BinaryOperator {
4339 public:
4440 SetCondInst(BinaryOps opType, Value *S1, Value *S2,
4541 const std::string &Name = "");
46
47 virtual const char *getOpcodeName() const;
4842 };
4943
5044 #endif
2929 }
3030
3131 virtual Instruction *clone() const { return new CastInst(*this); }
32 virtual const char *getOpcodeName() const { return "cast"; }
3332
3433 // Methods for support type inquiry through isa, cast, and dyn_cast:
3534 static inline bool classof(const CastInst *) { return true; }
5049 CallInst(const CallInst &CI);
5150 public:
5251 CallInst(Value *M, const std::vector &Par, const std::string & = "");
53
54 virtual const char *getOpcodeName() const { return "call"; }
5552
5653 virtual Instruction *clone() const { return new CallInst(*this); }
5754 bool hasSideEffects() const { return true; }
10299 OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
103100
104101 virtual Instruction *clone() const { return new ShiftInst(*this); }
105 virtual const char *getOpcodeName() const {
106 return getOpcode() == Shl ? "shl" : "shr";
107 }
108102
109103 // Methods for support type inquiry through isa, cast, and dyn_cast:
110104 static inline bool classof(const ShiftInst *) { return true; }
2323 PHINode(const Type *Ty, const std::string &Name = "");
2424
2525 virtual Instruction *clone() const { return new PHINode(*this); }
26 virtual const char *getOpcodeName() const { return "phi"; }
2726
2827 // getNumIncomingValues - Return the number of incoming edges the PHI node has
2928 inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
3838
3939 virtual Instruction *clone() const { return new ReturnInst(*this); }
4040
41 virtual const char *getOpcodeName() const { return "ret"; }
42
4341 inline const Value *getReturnValue() const {
4442 return Operands.size() ? Operands[0].get() : 0;
4543 }
8785 inline Value *getCondition() {
8886 return isUnconditional() ? 0 : Operands[2].get();
8987 }
90
91 virtual const char *getOpcodeName() const { return "br"; }
9288
9389 // setUnconditionalDest - Change the current branch to an unconditional branch
9490 // targeting the specified block.
152148
153149 void dest_push_back(Constant *OnVal, BasicBlock *Dest);
154150
155 virtual const char *getOpcodeName() const { return "switch"; }
156
157151 virtual const BasicBlock *getSuccessor(unsigned idx) const {
158152 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
159153 return cast(Operands[idx*2+1].get());
240234 Operands[2] = (Value*)B;
241235 }
242236
243 virtual const char *getOpcodeName() const { return "invoke"; }
244
245237 virtual const BasicBlock *getSuccessor(unsigned i) const {
246238 assert(i < 2 && "Successor # out of range for invoke!");
247239 return i == 0 ? getNormalDest() : getExceptionalDest();