Skip to content

Commit 352106f

Browse files
committed
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
1 parent cd6ffd6 commit 352106f

File tree

2 files changed

+63
-65
lines changed

2 files changed

+63
-65
lines changed

include/llvm/IR/InstrTypes.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,69 @@ struct OperandTraits<UnaryInstruction> :
9595

9696
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
9797

98+
//===----------------------------------------------------------------------===//
99+
// UnaryOperator Class
100+
//===----------------------------------------------------------------------===//
101+
102+
class UnaryOperator : public UnaryInstruction {
103+
void AssertOK();
104+
105+
protected:
106+
UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
107+
const Twine &Name, Instruction *InsertBefore);
108+
UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
109+
const Twine &Name, BasicBlock *InsertAtEnd);
110+
111+
// Note: Instruction needs to be a friend here to call cloneImpl.
112+
friend class Instruction;
113+
114+
UnaryOperator *cloneImpl() const;
115+
116+
public:
117+
118+
/// Construct a unary instruction, given the opcode and an operand.
119+
/// Optionally (if InstBefore is specified) insert the instruction
120+
/// into a BasicBlock right before the specified instruction. The specified
121+
/// Instruction is allowed to be a dereferenced end iterator.
122+
///
123+
static UnaryOperator *Create(UnaryOps Op, Value *S,
124+
const Twine &Name = Twine(),
125+
Instruction *InsertBefore = nullptr);
126+
127+
/// Construct a unary instruction, given the opcode and an operand.
128+
/// Also automatically insert this instruction to the end of the
129+
/// BasicBlock specified.
130+
///
131+
static UnaryOperator *Create(UnaryOps Op, Value *S,
132+
const Twine &Name,
133+
BasicBlock *InsertAtEnd);
134+
135+
/// These methods just forward to Create, and are useful when you
136+
/// statically know what type of instruction you're going to create. These
137+
/// helpers just save some typing.
138+
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
139+
static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") {\
140+
return Create(Instruction::OPC, V, Name);\
141+
}
142+
#include "llvm/IR/Instruction.def"
143+
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
144+
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
145+
BasicBlock *BB) {\
146+
return Create(Instruction::OPC, V, Name, BB);\
147+
}
148+
#include "llvm/IR/Instruction.def"
149+
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
150+
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
151+
Instruction *I) {\
152+
return Create(Instruction::OPC, V, Name, I);\
153+
}
154+
#include "llvm/IR/Instruction.def"
155+
156+
UnaryOps getOpcode() const {
157+
return static_cast<UnaryOps>(Instruction::getOpcode());
158+
}
159+
};
160+
98161
//===----------------------------------------------------------------------===//
99162
// BinaryOperator Class
100163
//===----------------------------------------------------------------------===//

include/llvm/IR/Instructions.h

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,71 +1133,6 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
11331133

11341134
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
11351135

1136-
//===----------------------------------------------------------------------===//
1137-
// UnaryOperator Class
1138-
//===----------------------------------------------------------------------===//
1139-
1140-
/// a unary instruction
1141-
class UnaryOperator : public UnaryInstruction {
1142-
void AssertOK();
1143-
1144-
protected:
1145-
UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
1146-
const Twine &Name, Instruction *InsertBefore);
1147-
UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
1148-
const Twine &Name, BasicBlock *InsertAtEnd);
1149-
1150-
// Note: Instruction needs to be a friend here to call cloneImpl.
1151-
friend class Instruction;
1152-
1153-
UnaryOperator *cloneImpl() const;
1154-
1155-
public:
1156-
1157-
/// Construct a unary instruction, given the opcode and an operand.
1158-
/// Optionally (if InstBefore is specified) insert the instruction
1159-
/// into a BasicBlock right before the specified instruction. The specified
1160-
/// Instruction is allowed to be a dereferenced end iterator.
1161-
///
1162-
static UnaryOperator *Create(UnaryOps Op, Value *S,
1163-
const Twine &Name = Twine(),
1164-
Instruction *InsertBefore = nullptr);
1165-
1166-
/// Construct a unary instruction, given the opcode and an operand.
1167-
/// Also automatically insert this instruction to the end of the
1168-
/// BasicBlock specified.
1169-
///
1170-
static UnaryOperator *Create(UnaryOps Op, Value *S,
1171-
const Twine &Name,
1172-
BasicBlock *InsertAtEnd);
1173-
1174-
/// These methods just forward to Create, and are useful when you
1175-
/// statically know what type of instruction you're going to create. These
1176-
/// helpers just save some typing.
1177-
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
1178-
static UnaryInstruction *Create##OPC(Value *V, \
1179-
const Twine &Name = "") {\
1180-
return Create(Instruction::OPC, V, Name);\
1181-
}
1182-
#include "llvm/IR/Instruction.def"
1183-
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
1184-
static UnaryInstruction *Create##OPC(Value *V, \
1185-
const Twine &Name, BasicBlock *BB) {\
1186-
return Create(Instruction::OPC, V, Name, BB);\
1187-
}
1188-
#include "llvm/IR/Instruction.def"
1189-
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
1190-
static UnaryInstruction *Create##OPC(Value *V, \
1191-
const Twine &Name, Instruction *I) {\
1192-
return Create(Instruction::OPC, V, Name, I);\
1193-
}
1194-
#include "llvm/IR/Instruction.def"
1195-
1196-
UnaryOps getOpcode() const {
1197-
return static_cast<UnaryOps>(Instruction::getOpcode());
1198-
}
1199-
};
1200-
12011136
//===----------------------------------------------------------------------===//
12021137
// ICmpInst Class
12031138
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)