1 | /* |
---|
2 | * Copyright (c) 2014 International Characters. |
---|
3 | * This software is licensed to the public under the Open Software License 3.0. |
---|
4 | * icgrep is a trademark of International Characters. |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef LLVM_GENERATOR_H |
---|
8 | #define LLVM_GENERATOR_H |
---|
9 | |
---|
10 | //Regular Expressions |
---|
11 | #include "re_re.h" |
---|
12 | #include "re_cc.h" |
---|
13 | #include "re_name.h" |
---|
14 | #include "re_start.h" |
---|
15 | #include "re_end.h" |
---|
16 | #include "re_seq.h" |
---|
17 | #include "re_alt.h" |
---|
18 | #include "re_rep.h" |
---|
19 | |
---|
20 | //Pablo Expressions |
---|
21 | #include "pe_pabloe.h" |
---|
22 | #include "pe_sel.h" |
---|
23 | #include "pe_advance.h" |
---|
24 | #include "pe_all.h" |
---|
25 | #include "pe_and.h" |
---|
26 | #include "pe_charclass.h" |
---|
27 | #include "pe_matchstar.h" |
---|
28 | #include "pe_not.h" |
---|
29 | #include "pe_or.h" |
---|
30 | #include "pe_call.h" |
---|
31 | #include "pe_var.h" |
---|
32 | #include "pe_xor.h" |
---|
33 | |
---|
34 | //Pablo Statements |
---|
35 | #include "ps_pablos.h" |
---|
36 | #include "ps_assign.h" |
---|
37 | #include "ps_if.h" |
---|
38 | #include "ps_while.h" |
---|
39 | |
---|
40 | #include "cc_codegenobject.h" |
---|
41 | |
---|
42 | #include "pbix_compiler.h" |
---|
43 | |
---|
44 | #include "llvm_gen_helper.h" |
---|
45 | |
---|
46 | //#include "unicode_categories.h" |
---|
47 | //#include "unicode_categories-flat.h" |
---|
48 | #include "unicode_categories-simple.h" |
---|
49 | |
---|
50 | #include <iostream> |
---|
51 | #include <string> |
---|
52 | #include <sstream> |
---|
53 | #include <list> |
---|
54 | #include <map> |
---|
55 | #include <algorithm> |
---|
56 | |
---|
57 | #include <llvm/Support/raw_ostream.h> |
---|
58 | |
---|
59 | #include <llvm/Pass.h> |
---|
60 | #include <llvm/PassManager.h> |
---|
61 | #include <llvm/ADT/SmallVector.h> |
---|
62 | #include <llvm/Analysis/Verifier.h> |
---|
63 | #include "llvm/Analysis/Passes.h" |
---|
64 | #include <llvm/Assembly/PrintModulePass.h> |
---|
65 | #include <llvm/IR/BasicBlock.h> |
---|
66 | #include <llvm/IR/CallingConv.h> |
---|
67 | #include <llvm/IR/Constants.h> |
---|
68 | #include "llvm/IR/DataLayout.h" |
---|
69 | #include "llvm/IR/DerivedTypes.h" |
---|
70 | #include <llvm/IR/Function.h> |
---|
71 | #include <llvm/IR/GlobalVariable.h> |
---|
72 | #include <llvm/IR/InlineAsm.h> |
---|
73 | #include <llvm/IR/Instructions.h> |
---|
74 | #include <llvm/IR/LLVMContext.h> |
---|
75 | #include <llvm/IR/Module.h> |
---|
76 | #include <llvm/Support/FormattedStream.h> |
---|
77 | #include <llvm/Support/MathExtras.h> |
---|
78 | #include <llvm/Support/Casting.h> |
---|
79 | |
---|
80 | #include "llvm/Support/TargetSelect.h" |
---|
81 | #include "llvm/Transforms/Scalar.h" |
---|
82 | |
---|
83 | #include <llvm/ExecutionEngine/ExecutionEngine.h> |
---|
84 | #include <llvm/ExecutionEngine/MCJIT.h> |
---|
85 | |
---|
86 | #include <llvm/Linker.h> |
---|
87 | #include <llvm/IRReader/IRReader.h> |
---|
88 | #include <llvm/Bitcode/ReaderWriter.h> |
---|
89 | #include <llvm/Support/MemoryBuffer.h> |
---|
90 | |
---|
91 | #include <llvm/IR/IRBuilder.h> |
---|
92 | |
---|
93 | #include <simd-lib/bitblock.hpp> |
---|
94 | |
---|
95 | using namespace llvm; |
---|
96 | |
---|
97 | struct LLVM_Gen_RetVal |
---|
98 | { |
---|
99 | int carry_q_size; |
---|
100 | void *process_block_fptr; |
---|
101 | }; |
---|
102 | |
---|
103 | class LLVM_Generator |
---|
104 | { |
---|
105 | public: |
---|
106 | LLVM_Generator(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits); |
---|
107 | ~LLVM_Generator(); |
---|
108 | LLVM_Gen_RetVal Generate_LLVMIR(CodeGenState cg_state, |
---|
109 | CodeGenState subexpression_cg_state, |
---|
110 | std::list<PabloS*> cc_cgo); |
---|
111 | private: |
---|
112 | void MakeLLVMModule(); |
---|
113 | void DefineTypes(); |
---|
114 | void DeclareFunctions(); |
---|
115 | void DeclareCallFunctions(std::list<PabloS*> stmts); |
---|
116 | void DeclareCallFunctions_PabloS(PabloS* stmt); |
---|
117 | void DeclareCallFunctions_PabloE(PabloE* expr); |
---|
118 | void StoreBitBlockMarkerPtr(std::string name, int index); |
---|
119 | void LoadBitBlocksFromStaticExtern(); |
---|
120 | void SetReturnMarker(std::string marker, int output_idx); |
---|
121 | Value* GetMarker(std::string name); |
---|
122 | std::string Generate_PabloStatements(std::list<PabloS*> stmts); |
---|
123 | std::string Generate_PabloS(PabloS* stmt); |
---|
124 | Value* Generate_PabloE(PabloE* expr); |
---|
125 | Value* genMatchStar(Value* marker_expr, Value* cc_expr); |
---|
126 | Value* genScanThru(Value* marker_expr, Value* cc_expr); |
---|
127 | Value* genAddWithCarry(Value* e1, Value* e2); |
---|
128 | Value* genShiftRight127(Value* e, const Twine &namehint = ""); |
---|
129 | Value* genShiftLeft64(Value* e, const Twine &namehint = "") ; |
---|
130 | Value* genNot(Value* e, const Twine &namehint = ""); |
---|
131 | |
---|
132 | int mBits; |
---|
133 | std::map<std::string, std::string> m_name_map; |
---|
134 | std::string mBasis_Pattern; |
---|
135 | |
---|
136 | Module* mMod; |
---|
137 | BasicBlock* mBasicBlock; |
---|
138 | |
---|
139 | ExecutionEngine* mExecutionEngine; |
---|
140 | |
---|
141 | VectorType* m64x2Vect; |
---|
142 | PointerType* m64x2Vect_Ptr1; |
---|
143 | |
---|
144 | VectorType* m128x1Vect; |
---|
145 | |
---|
146 | PointerType* mStruct_Basis_Bits_Ptr1; |
---|
147 | PointerType* mStruct_Output_Ptr1; |
---|
148 | |
---|
149 | std::map<std::string, Value*> mMarkerMap; |
---|
150 | |
---|
151 | int mCarryQueueIdx; |
---|
152 | Value* mptr_carry_q; |
---|
153 | |
---|
154 | int mCarryQueueSize; |
---|
155 | |
---|
156 | ConstantInt* mConst_int64_neg1; |
---|
157 | ConstantAggregateZero* mConst_Aggregate_64x2_0; |
---|
158 | Constant* mConst_Aggregate_64x2_neg1; |
---|
159 | |
---|
160 | FunctionType* mFuncTy_0; |
---|
161 | Function* mFunc_process_block; |
---|
162 | |
---|
163 | Constant* mFunc_print_register; |
---|
164 | Constant* mFunc_test_getCategory; |
---|
165 | Constant* mFunc_get_unicode_category; |
---|
166 | Value* mFunc_get_unicode_category_Nd; |
---|
167 | |
---|
168 | AllocaInst* mPtr_basis_bits_addr; |
---|
169 | AllocaInst* mPtr_carry_q_addr; |
---|
170 | AllocaInst* mPtr_output_addr; |
---|
171 | }; |
---|
172 | |
---|
173 | |
---|
174 | #endif // LLVM_GENERATOR_H |
---|