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

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

Set default version as 3.4; eliminate baked platform dependencies

File size: 4.9 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 USE_LLVM_3_4
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_codegenobject.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#endif
64
65#ifdef USE_LLVM_3_5
66#include "llvm/IR/Verifier.h"
67#endif
68
69#include "llvm/Pass.h"
70#include "llvm/PassManager.h"
71#include "llvm/ADT/SmallVector.h"
72#include "llvm/Analysis/Passes.h"
73#include "llvm/Assembly/PrintModulePass.h"
74#include "llvm/IR/BasicBlock.h"
75#include "llvm/IR/CallingConv.h"
76#include "llvm/IR/Constants.h"
77#include "llvm/IR/DataLayout.h"
78#include "llvm/IR/DerivedTypes.h"
79#include "llvm/IR/Function.h"
80#include "llvm/IR/GlobalVariable.h"
81#include "llvm/IR/InlineAsm.h"
82#include "llvm/IR/Instructions.h"
83#include "llvm/IR/LLVMContext.h"
84#include "llvm/IR/Module.h"
85#include "llvm/Support/FormattedStream.h"
86#include "llvm/Support/MathExtras.h"
87#include "llvm/Support/Casting.h"
88#include "llvm/Support/Debug.h"
89
90#include "llvm/Support/TargetSelect.h"
91#include "llvm/Transforms/Scalar.h"
92
93#include "llvm/ExecutionEngine/ExecutionEngine.h"
94#include "llvm/ExecutionEngine/MCJIT.h"
95
96#include "llvm/Linker.h"
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
113class LLVM_Generator
114{
115public:
116    LLVM_Generator(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits);
117    ~LLVM_Generator();
118    LLVM_Gen_RetVal Generate_LLVMIR(CodeGenState cg_state,
119                                    CodeGenState subexpression_cg_state,
120                                    std::list<PabloS*> cc_cgo);
121private:
122    void MakeLLVMModule();
123    void DefineTypes();
124    void DeclareFunctions();
125    void DeclareCallFunctions(std::list<PabloS*> stmts);
126    void DeclareCallFunctions_PabloS(PabloS* stmt);
127    void DeclareCallFunctions_PabloE(PabloE* expr);
128    void StoreBitBlockMarkerPtr(std::string name, int index);
129    void LoadBitBlocksFromStaticExtern();
130    void SetReturnMarker(std::string marker, int output_idx);
131    Value* GetMarker(std::string name);
132    std::string Generate_PabloStatements(std::list<PabloS*> stmts);
133    std::string Generate_PabloS(PabloS* stmt);
134    Value* Generate_PabloE(PabloE* expr);
135    Value* genMatchStar(Value* marker_expr, Value* cc_expr);
136    Value* genScanThru(Value* marker_expr, Value* cc_expr);
137    Value* genCarryInLoad(Value* ptr_carry_q, int carryq_idx);
138    Value* genCarryOutStore(Value* carryout, Value* ptr_carry_q, int carryq_idx);
139    Value* genAddWithCarry(Value* e1, Value* e2);
140    Value* genBitBlockAny(Value* e);
141    Value* genShiftRight127(Value* e, const Twine &namehint = "");
142    Value* genShiftLeft64(Value* e, const Twine &namehint = "") ;
143    Value* genNot(Value* e, const Twine &namehint = "");
144
145    int         mBits;
146    std::map<std::string, std::string> m_name_map;
147    std::string mBasis_Pattern;
148
149    Module*          mMod;
150    BasicBlock*      mBasicBlock;
151
152    ExecutionEngine* mExecutionEngine;
153
154    VectorType*  m64x2Vect;
155    PointerType* m64x2Vect_Ptr1;
156
157    VectorType* m128x1Vect;
158
159    PointerType* mStruct_Basis_Bits_Ptr1;
160    PointerType* mStruct_Output_Ptr1;
161
162    std::map<std::string, Value*> mMarkerMap;
163
164    int         mCarryQueueIdx;
165    Value*      mptr_carry_q;
166
167    int         mCarryQueueSize;
168
169    ConstantInt*           mConst_int64_neg1;
170    ConstantAggregateZero* mConst_Aggregate_64x2_0;
171    Constant*              mConst_Aggregate_64x2_neg1;
172
173    FunctionType* mFuncTy_0;
174    Function*     mFunc_process_block;
175
176    Constant*     mFunc_print_register;
177    Constant*     mFunc_test_getCategory;
178    Constant*     mFunc_get_unicode_category;
179    Value*     mFunc_get_unicode_category_Nd;
180
181    AllocaInst*  mPtr_basis_bits_addr;
182    AllocaInst*  mPtr_carry_q_addr;
183    AllocaInst*  mPtr_output_addr;
184};
185
186
187#endif // LLVM_GENERATOR_H
Note: See TracBrowser for help on using the repository browser.