| 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
chi::NodeCompiler::compile_stage2
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...
Definition: NodeCompiler.cpp:151
chi::NodeCompiler::codeBlock
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...
Definition: NodeCompiler.cpp:221
chi::NodeCompiler::llvmModule
llvm::Module & llvmModule() const
Get the module being generated.
Definition: NodeCompiler.cpp:226
chi::NodeCompiler::pure
bool pure() const
node().type().pure()
Definition: NodeCompiler.cpp:89
Fwd.hpp
Forward declares all the chigraph data types.
chi::NodeCompiler::funcCompiler
FunctionCompiler & funcCompiler() const
Get the function compiler.
Definition: NodeCompiler.hpp:42
chi::NodeInstance
An instance of a node.
Definition: NodeInstance.hpp:19
chi::dependentPuresRecursive
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...
Definition: NodeCompiler.cpp:244
chi::NodeCompiler
Helper to compile nodes.
Definition: NodeCompiler.hpp:24
chi::NodeCompiler::inputExecs
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...
Definition: NodeCompiler.cpp:235
chi::Context
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
chi::NodeCompiler::node
NodeInstance & node() const
The node we&#39;re compiling.
Definition: NodeCompiler.hpp:46
chi::NodeCompiler::compile_stage1
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 ...
Definition: NodeCompiler.cpp:91
chi::FunctionCompiler
Class for compiling GraphFunctions into llvm::Functions.
Definition: FunctionCompiler.hpp:24
chi::NodeCompiler::returnValues
std::vector< llvm::Value * > returnValues() const
Get return values.
Definition: NodeCompiler.hpp:105
chi::NodeCompiler::context
Context & context() const
Just node().context()
Definition: NodeCompiler.cpp:233
chi::NodeCompiler::compiled
bool compiled(size_t inputExecID) const
Get if compile_stage2 has been called for a given inputExecID.
Definition: NodeCompiler.cpp:228
chi::NodeCompiler::NodeCompiler
NodeCompiler(FunctionCompiler &functionCompiler, NodeInstance &inst)
Constructor.
Definition: NodeCompiler.cpp:22
chi
The namespace where chigraph lives.
Definition: BitcodeParser.hpp:12
chi::Result
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72
chi::NodeCompiler::firstBlock
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...
Definition: NodeCompiler.cpp:214
chi::NodeCompiler::jumpBackInst
llvm::IndirectBrInst & jumpBackInst() const
Get the IndirectBrInst* for the pure.
Definition: NodeCompiler.hpp:110