source: icGREP/icgrep-devel/icgrep/llvm_gen.h @ 4132

Last change on this file since 4132 was 4132, checked in by cameron, 5 years ago

Restructure - collapse cc_codegenobject into cc_compiler

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