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

Last change on this file since 4096 was 4096, checked in by linmengl, 5 years ago

generate llvm.uadd.with.overflow. add 'make check' target to run greptest.py.

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 USE_LLVM_3_5
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
114struct SumWithOverflowPack {
115  Value *sum;
116  Value *obit;
117};
118
119class LLVM_Generator
120{
121public:
122    LLVM_Generator(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits);
123    ~LLVM_Generator();
124    LLVM_Gen_RetVal Generate_LLVMIR(CodeGenState cg_state,
125                                    CodeGenState subexpression_cg_state,
126                                    std::list<PabloS*> cc_cgo);
127private:
128    void MakeLLVMModule();
129    void DefineTypes();
130    void DeclareFunctions();
131    void DeclareCallFunctions(std::list<PabloS*> stmts);
132    void DeclareCallFunctions_PabloS(PabloS* stmt);
133    void DeclareCallFunctions_PabloE(PabloE* expr);
134    void StoreBitBlockMarkerPtr(std::string name, int index);
135    void LoadBitBlocksFromStaticExtern();
136    void SetReturnMarker(std::string marker, int output_idx);
137    Value* GetMarker(std::string name);
138    std::string Generate_PabloStatements(std::list<PabloS*> stmts);
139    std::string Generate_PabloS(PabloS* stmt);
140    Value* Generate_PabloE(PabloE* expr);
141    Value* genMatchStar(Value* marker_expr, Value* cc_expr);
142    Value* genScanThru(Value* marker_expr, Value* cc_expr);
143    Value* genCarryInLoad(Value* ptr_carry_q, int carryq_idx);
144    Value* genCarryOutStore(Value* carryout, Value* ptr_carry_q, int carryq_idx);
145    Value* genAddWithCarry(Value* e1, Value* e2);
146    Value* genBitBlockAny(Value* e);
147    Value* genShiftRight127(Value* e, const Twine &namehint = "");
148    Value* genShiftLeft64(Value* e, const Twine &namehint = "") ;
149    Value* genNot(Value* e, const Twine &namehint = "");
150
151    SumWithOverflowPack genUaddOverflow(Value *e1, Value *e2);
152
153    int         mBits;
154    std::map<std::string, std::string> m_name_map;
155    std::string mBasis_Pattern;
156
157    Module*          mMod;
158    BasicBlock*      mBasicBlock;
159
160    ExecutionEngine* mExecutionEngine;
161
162    VectorType*  m64x2Vect;
163    PointerType* m64x2Vect_Ptr1;
164
165    VectorType* m128x1Vect;
166
167    PointerType* mStruct_Basis_Bits_Ptr1;
168    PointerType* mStruct_Output_Ptr1;
169
170    std::map<std::string, Value*> mMarkerMap;
171
172    int         mCarryQueueIdx;
173    Value*      mptr_carry_q;
174
175    int         mCarryQueueSize;
176
177    ConstantInt*           mConst_int64_neg1;
178    ConstantAggregateZero* mConst_Aggregate_64x2_0;
179    Constant*              mConst_Aggregate_64x2_neg1;
180
181    FunctionType* mFuncTy_0;
182    Function*     mFunc_process_block;
183    Function*     mFunc_llvm_uadd_with_overflow_i128;
184
185    Constant*     mFunc_print_register;
186    Constant*     mFunc_test_getCategory;
187    Constant*     mFunc_get_unicode_category;
188    Value*     mFunc_get_unicode_category_Nd;
189
190    AllocaInst*  mPtr_basis_bits_addr;
191    AllocaInst*  mPtr_carry_q_addr;
192    AllocaInst*  mPtr_output_addr;
193};
194
195
196#endif // LLVM_GENERATOR_H
Note: See TracBrowser for help on using the repository browser.