Caffe2 - C++ API
A deep learning, cross platform ML framework
Compiler.h
1 #ifndef NOM_REPRESENTATIONS_COMPILER_H
2 #define NOM_REPRESENTATIONS_COMPILER_H
3 
4 #include "nomnigraph/Graph/Graph.h"
5 #include "nomnigraph/Support/Casting.h"
6 
7 namespace nom {
8 namespace repr {
9 
10 class Value {
11 public:
12  enum class ValueKind { Value, Instruction, Data };
13  Value(ValueKind K) : Kind(K) {}
14  Value() : Kind(ValueKind::Value) {}
15  ValueKind getKind() const { return Kind; }
16  virtual ~Value() = default;
17 
18 private:
19  const ValueKind Kind;
20 };
21 
22 class Data : public Value {
23 public:
24  Data() : Value(ValueKind::Data) {}
25  static bool classof(const Value *V) {
26  return V->getKind() == ValueKind::Data;
27  }
28  virtual ~Data() = default;
29  size_t getVersion() const { return Version; }
30 
31  void setVersion(size_t version) { Version = version; }
32 
33 private:
34  size_t Version = 0;
35 };
36 
37 class Instruction : public Value {
38 public:
40  enum class Opcode {
41  Generic, // Handles basic instructions.
42  TerminatorStart, // LLVM style range of operations.
43  Branch,
44  Return,
45  TerminatorEnd,
46  Phi
47  };
48  Instruction() : Value(ValueKind::Instruction), Op(Opcode::Generic) {}
49  Instruction(Opcode op) : Value(ValueKind::Instruction), Op(op) {}
50  static bool classof(const Value *V) {
51  return V->getKind() == ValueKind::Instruction;
52  }
53  virtual ~Instruction() = default;
54  Opcode getOpcode() const { return Op; }
55 
56 private:
57  Opcode Op;
58 };
59 
60 class Terminator : public Instruction {
61 public:
63 
64 private:
65  static bool classof(const Value *V) {
66  return isa<Instruction>(V) &&
67  isTerminator(cast<Instruction>(V)->getOpcode());
68  }
69  static bool isTerminator(const Opcode &op) {
70  return op >= Opcode::TerminatorStart && op <= Opcode::TerminatorEnd;
71  }
72 };
73 
74 class Branch : public Terminator {
75 public:
76  Branch() : Terminator(Instruction::Opcode::Branch) {}
77 };
78 
79 class Return : public Terminator {
80 public:
81  Return() : Terminator(Instruction::Opcode::Return) {}
82 };
83 
84 class Phi : public Instruction {
85 public:
86  Phi() : Instruction(Instruction::Opcode::Phi) {}
87 };
88 
89 } // namespace repr
90 } // namespace nom
91 
92 #endif // NOM_REPRESENTATIONS_COMPILER_H
Definition: Caffe2.cc:16
Opcode
All the different types of execution.
Definition: Compiler.h:40