llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
phi.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include "core/inst.h"
8 
9 
10 
14 class PhiInst final : public Inst {
15 public:
17  static constexpr Inst::Kind kInstKind = Inst::Kind::PHI;
18 
19 public:
20  PhiInst(Type type, AnnotSet &&annot = {});
21  PhiInst(Type type, const AnnotSet &annot);
22 
24  unsigned GetNumRets() const override;
26  Type GetType(unsigned i) const override;
27 
29  void Add(Block *block, Ref<Inst> value);
30 
32  unsigned GetNumIncoming() const;
33 
35  void SetBlock(unsigned i, Block *block);
37  const Block *GetBlock(unsigned i) const;
39  Block *GetBlock(unsigned i);
40 
42  void SetValue(unsigned i, Ref<Inst> value);
44  ConstRef<Inst> GetValue(unsigned i) const;
46  Ref<Inst> GetValue(unsigned i);
48  Ref<Inst> GetValue(const Block *block);
50  inline ConstRef<Inst> GetValue(const Block *block) const
51  {
52  return const_cast<PhiInst *>(this)->GetValue(block);
53  }
54 
56  void Remove(const Block *block);
58  bool HasValue(const Block *block) const;
59 
61  Type GetType() const { return type_; }
62 
64  bool HasSideEffects() const override { return false; }
66  bool IsConstant() const override { return false; }
68  bool IsReturn() const override { return false; }
69 
70 private:
72  Type type_;
73 };
PhiInst::GetNumRets
unsigned GetNumRets() const override
Returns the number of return values.
Definition: phi.cpp:25
Inst
Definition: inst.h:53
PhiInst::SetValue
void SetValue(unsigned i, Ref< Inst > value)
Sets the value attached to a block.
Definition: phi.cpp:93
PhiInst::Add
void Add(Block *block, Ref< Inst > value)
Adds an incoming value.
Definition: phi.cpp:38
Inst::Kind
Kind
Definition: inst.h:65
ConstRef< Inst >
PhiInst::HasValue
bool HasValue(const Block *block) const
Checks if the PHI has a value for a block.
Definition: phi.cpp:122
PhiInst::IsConstant
bool IsConstant() const override
Instruction is not constant.
Definition: phi.h:66
PhiInst::GetType
Type GetType() const
Returns the immediate type.
Definition: phi.h:61
PhiInst::SetBlock
void SetBlock(unsigned i, Block *block)
Updates the nth block.
Definition: phi.cpp:75
PhiInst::GetNumIncoming
unsigned GetNumIncoming() const
Returns the number of predecessors.
Definition: phi.cpp:52
AnnotSet
Definition: annot.h:69
PhiInst::GetValue
ConstRef< Inst > GetValue(const Block *block) const
Returns an operand for a block.
Definition: phi.h:50
PhiInst::Remove
void Remove(const Block *block)
Removes an incoming value.
Definition: phi.cpp:59
PhiInst::HasSideEffects
bool HasSideEffects() const override
This instruction has no side effects.
Definition: phi.h:64
Ref
Definition: ref.h:63
PhiInst::GetValue
ConstRef< Inst > GetValue(unsigned i) const
Returns the nth value.
Definition: phi.cpp:99
PhiInst::GetBlock
const Block * GetBlock(unsigned i) const
Returns the nth block.
Definition: phi.cpp:81
Block
Definition: block.h:29
PhiInst::IsReturn
bool IsReturn() const override
Instruction does not return.
Definition: phi.h:68
PhiInst::kInstKind
static constexpr Inst::Kind kInstKind
Kind of the instruction.
Definition: phi.h:17
PhiInst
Definition: phi.h:14