summaryrefslogtreecommitdiff
path: root/willow/lib/IR/Instructions.cpp
blob: 15e678611d8b0b0800812025c23eeaf462ee994e (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/Instructions.h>

namespace willow {

UnaryInst::UnaryInst(Opcode op, Type type, Value *value,
                     std::optional<Location> loc)
    : Instruction(op, type, loc) {
  addOperand(value);
}

BinaryInst::BinaryInst(Opcode op, Type type, Value *lhs, Value *rhs,
                       std::optional<Location> loc)
    : Instruction(op, type, loc) {
  addOperand(lhs);
  addOperand(rhs);
}

BrInst::BrInst(Type type, Value *condition, BasicBlock *true_target,
               BasicBlock *false_target, std::optional<Location> loc)
    : Instruction(Opcode::Br, type, loc) {
  addOperand(condition);
  addOperand(true_target);
  addOperand(false_target);
}

Value *BrInst::getCondition() { return getOperand(0); }

const Value *BrInst::getCondition() const { return getOperand(0); }

BasicBlock *BrInst::getTrueTarget() {
  return static_cast<BasicBlock *>(getOperand(1));
}

const BasicBlock *BrInst::getTrueTarget() const {
  return static_cast<const BasicBlock *>(getOperand(1));
}

BasicBlock *BrInst::getFalseTarget() {
  return static_cast<BasicBlock *>(getOperand(2));
}

const BasicBlock *BrInst::getFalseTarget() const {
  return static_cast<const BasicBlock *>(getOperand(2));
}

RetInst::RetInst(Type voidty, std::optional<Location> loc)
    : Instruction(Opcode::Ret, voidty, loc) {}

RetInst::RetInst(Type voidty, Value *val, std::optional<Location> loc)
    : Instruction(Opcode::Ret, voidty, loc) {
  addOperand(val);
}

PhiInst::PhiInst(Type type,
                 std::initializer_list<std::pair<BasicBlock *, Value *>> args,
                 std::optional<Location> loc)
    : Instruction(Opcode::Phi, type, loc) {
  for (auto [bb, v] : args) {
    addOperand(static_cast<Value *>(bb));
    addOperand(v);
  }
}

} // namespace willow