blob: 517b6f97b6fb416e47e160a2ad044472c40137ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <willow/IR/Instruction.h>
#include <willow/IR/Instructions.h>
namespace willow {
bool Instruction::isTerminatorOp(Opcode op) {
using enum Opcode;
switch (op) {
case Jmp:
case Br:
case Call:
case Ret:
return true;
case Add:
case Mul:
case Sub:
case Div:
case Mod:
case Shl:
case Shr:
case Ashl:
case Ashr:
case Eq:
case Lt:
case Gt:
case Le:
case Ge:
case And:
case Or:
case Not:
case Phi:
case Alloca:
return false;
}
}
void Instruction::setOperand(std::size_t index, Value *operand) {
assert(index < operands.size() && "Operand index out of bounds");
assert(operand && "Operand cannot be null");
Value *old = operands[index];
if (old == operand)
return;
old->delUse(this);
operands[index] = operand;
operand->addUse(this);
}
Successors Instruction::succs() {
using enum Opcode;
switch (op) {
case Jmp: {
auto inst = static_cast<JmpInst *>(this);
return Successors{inst->getTarget()};
}
case Br: {
auto inst = static_cast<BrInst *>(this);
return Successors{inst->getTrueTarget(), inst->getFalseTarget()};
}
default:
return Successors{};
}
}
}; // namespace willow
|