chigraph  master
Systems programming language written for beginners in LLVM
NodeCompiler.hpp
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #ifndef CHI_NODE_COMPILER_HPP
6 #define CHI_NODE_COMPILER_HPP
7 
8 #include "chi/Fwd.hpp"
9 
10 #include <cassert>
11 #include <unordered_set>
12 #include <vector>
13 
14 #include <boost/dynamic_bitset.hpp>
15 
16 namespace chi {
17 
24 struct NodeCompiler {
28  NodeCompiler(FunctionCompiler& functionCompiler, NodeInstance& inst);
29 
30  NodeCompiler(const NodeCompiler&) = delete;
31 
33  NodeCompiler(NodeCompiler&&) = default;
34 
35  NodeCompiler& operator=(const NodeCompiler&) = delete;
36 
38  NodeCompiler& operator=(NodeCompiler&&) = default;
39 
42  FunctionCompiler& funcCompiler() const { return *mCompiler; }
43 
46  NodeInstance& node() const { return *mNode; }
47 
50  bool pure() const;
51 
56  void compile_stage1(size_t inputExecID);
57 
67  Result compile_stage2(std::vector<llvm::BasicBlock*> trailingBlocks, size_t inputExecID);
68 
73  bool compiled(size_t inputExecID) const;
74 
82  llvm::BasicBlock& firstBlock(size_t inputExecID) const;
83 
89  llvm::BasicBlock& codeBlock(size_t inputExecID) const;
90 
92  llvm::Module& llvmModule() const;
93 
95  Context& context() const;
96 
101  size_t inputExecs() const;
102 
105  std::vector<llvm::Value*> returnValues() const { return mReturnValues; }
106 
110  llvm::IndirectBrInst& jumpBackInst() const {
111  assert(pure() && "Cannot get jump back inst for a nonpure node");
112  return *mJumpBackInst;
113  }
114 
115 private:
116  FunctionCompiler* mCompiler;
117  NodeInstance* mNode;
118 
119  std::vector<std::vector<llvm::BasicBlock*>> mPureBlocks;
120  std::vector<llvm::BasicBlock*> mCodeBlocks;
121 
122  std::vector<llvm::Value*> mReturnValues;
123 
124  boost::dynamic_bitset<> mCompiledInputs;
125 
126  llvm::IndirectBrInst* mJumpBackInst = nullptr;
127 };
128 
138 std::vector<NodeInstance*> dependentPuresRecursive(const NodeInstance& inst);
139 
140 } // namespace chi
141 
142 #endif // CHI_NODE_COMPILER_HPP
Result compile_stage2(std::vector< llvm::BasicBlock *> trailingBlocks, size_t inputExecID)
Fill the codegen block If compile_stage1 hasn&#39;t been called for this inputExecID, then it will be cal...
llvm::BasicBlock & codeBlock(size_t inputExecID) const
Get the code block for a given inputExecID Requires that compile_stage1 has been called for this ID...
llvm::Module & llvmModule() const
Get the module being generated.
bool pure() const
node().type().pure()
Forward declares all the chigraph data types.
FunctionCompiler & funcCompiler() const
Get the function compiler.
An instance of a node.
std::vector< NodeInstance * > dependentPuresRecursive(const NodeInstance &inst)
Get the pures a NodeInstance relies on These are all the dependent pures (it&#39;s fetched recursively) T...
Helper to compile nodes.
size_t inputExecs() const
The number of input execs that we can compile If it&#39;s pure or an entry node, this is 1...
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
NodeInstance & node() const
The node we&#39;re compiling.
void compile_stage1(size_t inputExecID)
Add the basic blocks and fill the pure blocks, but don&#39;t fill the code block nop if its already been ...
Class for compiling GraphFunctions into llvm::Functions.
std::vector< llvm::Value * > returnValues() const
Get return values.
Context & context() const
Just node().context()
bool compiled(size_t inputExecID) const
Get if compile_stage2 has been called for a given inputExecID.
NodeCompiler(FunctionCompiler &functionCompiler, NodeInstance &inst)
Constructor.
The namespace where chigraph lives.
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72
llvm::BasicBlock & firstBlock(size_t inputExecID) const
Get the first block to jump to for the node If there are dependent pures, it&#39;s the first pure block O...
llvm::IndirectBrInst & jumpBackInst() const
Get the IndirectBrInst* for the pure.