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

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

Changes for parabix-LLVM (3.5 based); reset default to 3.4

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