llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
inline_helper.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 <llvm/ADT/PostOrderIterator.h>
8 
9 #include "core/block.h"
10 #include "core/cast.h"
11 #include "core/clone.h"
12 #include "core/func.h"
13 #include "core/cfg.h"
14 
15 class TrampolineGraph;
16 
17 
18 
22 class InlineHelper final : public CloneVisitor {
23 public:
31  InlineHelper(CallSite *call, Func *callee, TrampolineGraph &graph);
32 
34  void Inline();
35 
36 private:
38  Inst *Duplicate(Block *block, Inst *inst);
40  Ref<Inst> Duplicate(Block *block, ArgInst *arg);
41 
43  Block *Map(Block *block) override { return blocks_[block]; }
45  Ref<Inst> Map(Ref<Inst> inst) override { return insts_[inst]; }
46 
48  AnnotSet Annot(const Inst *inst) override;
49 
51  Inst *Convert(
52  Type argType,
53  Type valType,
54  Ref<Inst> valInst,
55  AnnotSet &&annot
56  );
57 
59  void DuplicateBlocks();
61  void SplitEntry();
62 
63 private:
65  const bool isTailCall_;
67  const std::vector<Type> types_;
69  CallSite *call_;
71  const AnnotSet callAnnot_;
73  Block *entry_;
75  Func *callee_;
77  Func *caller_;
79  llvm::DenseMap<unsigned, unsigned> frameIndices_;
81  Block *exit_;
83  Block *throw_;
85  Block *throwSplit_;
87  std::vector<Ref<PhiInst>> raisePhis_;
89  std::vector<Ref<PhiInst>> landPhis_;
91  std::vector<Ref<PhiInst>> phis_;
93  unsigned numExits_;
95  llvm::SmallVector<Ref<Inst>, 8> args_;
97  llvm::DenseMap<Block *, Block *> blocks_;
99  std::unordered_map<Ref<Inst>, Ref<Inst>> insts_;
101  llvm::ReversePostOrderTraversal<Func *> rpot_;
103  TrampolineGraph &graph_;
104 };
105 
Inst
Definition: inst.h:53
Func
Definition: func.h:30
InlineHelper
Definition: inline_helper.h:22
TrampolineGraph
Definition: trampoline_graph.h:19
AnnotSet
Definition: annot.h:69
CloneVisitor
Definition: clone.h:22
Ref
Definition: ref.h:63
InlineHelper::InlineHelper
InlineHelper(CallSite *call, Func *callee, TrampolineGraph &graph)
Definition: inline_helper.cpp:13
InlineHelper::Inline
void Inline()
Inlines the function.
Definition: inline_helper.cpp:76
Block
Definition: block.h:29
Annot
Definition: annot.h:15