summaryrefslogtreecommitdiff
path: root/willow/lib/IR/Instruction.cpp
blob: a6e0c9bcc31b8419430b3c67c80010563465acdc (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
#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;
  }
}

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