llvm.org GIT mirror llvm / 352106f
Refactor UnaryOperator class The UnaryOperator class was originally placed in llvm/IR/Instructions.h, with the other UnaryInstructions. However, I'm now thinking that it makes more sense for it to live in llvm/IR/InstrTypes.h, with BinaryOperator. It is more similar to BinaryOperator than any of the other UnaryInstructions. NFCI Differential Revision: https://reviews.llvm.org/D61614 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360103 91177308-0d34-0410-b5e6-96231b3b80d8 Cameron McInally 5 months ago
2 changed file(s) with 63 addition(s) and 65 deletion(s). Raw diff Collapse all Expand all
9393 };
9494
9595 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
96
97 //===----------------------------------------------------------------------===//
98 // UnaryOperator Class
99 //===----------------------------------------------------------------------===//
100
101 class UnaryOperator : public UnaryInstruction {
102 void AssertOK();
103
104 protected:
105 UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
106 const Twine &Name, Instruction *InsertBefore);
107 UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
108 const Twine &Name, BasicBlock *InsertAtEnd);
109
110 // Note: Instruction needs to be a friend here to call cloneImpl.
111 friend class Instruction;
112
113 UnaryOperator *cloneImpl() const;
114
115 public:
116
117 /// Construct a unary instruction, given the opcode and an operand.
118 /// Optionally (if InstBefore is specified) insert the instruction
119 /// into a BasicBlock right before the specified instruction. The specified
120 /// Instruction is allowed to be a dereferenced end iterator.
121 ///
122 static UnaryOperator *Create(UnaryOps Op, Value *S,
123 const Twine &Name = Twine(),
124 Instruction *InsertBefore = nullptr);
125
126 /// Construct a unary instruction, given the opcode and an operand.
127 /// Also automatically insert this instruction to the end of the
128 /// BasicBlock specified.
129 ///
130 static UnaryOperator *Create(UnaryOps Op, Value *S,
131 const Twine &Name,
132 BasicBlock *InsertAtEnd);
133
134 /// These methods just forward to Create, and are useful when you
135 /// statically know what type of instruction you're going to create. These
136 /// helpers just save some typing.
137 #define HANDLE_UNARY_INST(N, OPC, CLASS) \
138 static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") {\
139 return Create(Instruction::OPC, V, Name);\
140 }
141 #include "llvm/IR/Instruction.def"
142 #define HANDLE_UNARY_INST(N, OPC, CLASS) \
143 static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
144 BasicBlock *BB) {\
145 return Create(Instruction::OPC, V, Name, BB);\
146 }
147 #include "llvm/IR/Instruction.def"
148 #define HANDLE_UNARY_INST(N, OPC, CLASS) \
149 static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
150 Instruction *I) {\
151 return Create(Instruction::OPC, V, Name, I);\
152 }
153 #include "llvm/IR/Instruction.def"
154
155 UnaryOps getOpcode() const {
156 return static_cast(Instruction::getOpcode());
157 }
158 };
96159
97160 //===----------------------------------------------------------------------===//
98161 // BinaryOperator Class
11311131 }
11321132
11331133 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
1134
1135 //===----------------------------------------------------------------------===//
1136 // UnaryOperator Class
1137 //===----------------------------------------------------------------------===//
1138
1139 /// a unary instruction
1140 class UnaryOperator : public UnaryInstruction {
1141 void AssertOK();
1142
1143 protected:
1144 UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
1145 const Twine &Name, Instruction *InsertBefore);
1146 UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
1147 const Twine &Name, BasicBlock *InsertAtEnd);
1148
1149 // Note: Instruction needs to be a friend here to call cloneImpl.
1150 friend class Instruction;
1151
1152 UnaryOperator *cloneImpl() const;
1153
1154 public:
1155
1156 /// Construct a unary instruction, given the opcode and an operand.
1157 /// Optionally (if InstBefore is specified) insert the instruction
1158 /// into a BasicBlock right before the specified instruction. The specified
1159 /// Instruction is allowed to be a dereferenced end iterator.
1160 ///
1161 static UnaryOperator *Create(UnaryOps Op, Value *S,
1162 const Twine &Name = Twine(),
1163 Instruction *InsertBefore = nullptr);
1164
1165 /// Construct a unary instruction, given the opcode and an operand.
1166 /// Also automatically insert this instruction to the end of the
1167 /// BasicBlock specified.
1168 ///
1169 static UnaryOperator *Create(UnaryOps Op, Value *S,
1170 const Twine &Name,
1171 BasicBlock *InsertAtEnd);
1172
1173 /// These methods just forward to Create, and are useful when you
1174 /// statically know what type of instruction you're going to create. These
1175 /// helpers just save some typing.
1176 #define HANDLE_UNARY_INST(N, OPC, CLASS) \
1177 static UnaryInstruction *Create##OPC(Value *V, \
1178 const Twine &Name = "") {\
1179 return Create(Instruction::OPC, V, Name);\
1180 }
1181 #include "llvm/IR/Instruction.def"
1182 #define HANDLE_UNARY_INST(N, OPC, CLASS) \
1183 static UnaryInstruction *Create##OPC(Value *V, \
1184 const Twine &Name, BasicBlock *BB) {\
1185 return Create(Instruction::OPC, V, Name, BB);\
1186 }
1187 #include "llvm/IR/Instruction.def"
1188 #define HANDLE_UNARY_INST(N, OPC, CLASS) \
1189 static UnaryInstruction *Create##OPC(Value *V, \
1190 const Twine &Name, Instruction *I) {\
1191 return Create(Instruction::OPC, V, Name, I);\
1192 }
1193 #include "llvm/IR/Instruction.def"
1194
1195 UnaryOps getOpcode() const {
1196 return static_cast(Instruction::getOpcode());
1197 }
1198 };
11991134
12001135 //===----------------------------------------------------------------------===//
12011136 // ICmpInst Class