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

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

auto detect LLVM version in CMakeList.txt; add #ifdef blocks

File size: 5.1 KB
RevLine 
[3850]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
[4117]10//#define DUMP_GENERATED_IR
[4088]11
[3850]12//Regular Expressions
13#include "re_re.h"
14#include "re_cc.h"
[3914]15#include "re_name.h"
[3850]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"
[3940]32#include "pe_call.h"
[3850]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"
[3969]43
[3850]44#include "pbix_compiler.h"
45
46#include "llvm_gen_helper.h"
47
[4070]48#include "unicode_categories.h"
[3991]49//#include "unicode_categories-flat.h"
[4070]50//#include "unicode_categories-simple.h"
[3940]51
[3850]52#include <iostream>
53#include <string>
54#include <sstream>
55#include <list>
56#include <map>
57#include <algorithm>
58
[4088]59#include "llvm/Support/raw_ostream.h"
[3850]60
[4088]61#ifdef USE_LLVM_3_4
62#include "llvm/Analysis/Verifier.h"
[4090]63#include "llvm/Assembly/PrintModulePass.h"
[4091]64#include "llvm/Linker.h"
[4088]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"
[3850]74#include "llvm/Analysis/Passes.h"
[4088]75#include "llvm/IR/BasicBlock.h"
76#include "llvm/IR/CallingConv.h"
77#include "llvm/IR/Constants.h"
[3850]78#include "llvm/IR/DataLayout.h"
79#include "llvm/IR/DerivedTypes.h"
[4088]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"
[3850]90
91#include "llvm/Support/TargetSelect.h"
92#include "llvm/Transforms/Scalar.h"
93
[4088]94#include "llvm/ExecutionEngine/ExecutionEngine.h"
95#include "llvm/ExecutionEngine/MCJIT.h"
[3850]96
[4088]97#include "llvm/IRReader/IRReader.h"
98#include "llvm/Bitcode/ReaderWriter.h"
99#include "llvm/Support/MemoryBuffer.h"
[3850]100
[4088]101#include "llvm/IR/IRBuilder.h"
[3850]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
[4096]113struct SumWithOverflowPack {
114  Value *sum;
115  Value *obit;
116};
117
[3850]118class LLVM_Generator
119{
120public:
[3955]121    LLVM_Generator(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits);
[3850]122    ~LLVM_Generator();
[3914]123    LLVM_Gen_RetVal Generate_LLVMIR(CodeGenState cg_state,
[3955]124                                    CodeGenState subexpression_cg_state,
[3914]125                                    std::list<PabloS*> cc_cgo);
[3850]126private:
127    void MakeLLVMModule();
128    void DefineTypes();
129    void DeclareFunctions();
[3982]130    void DeclareCallFunctions(std::list<PabloS*> stmts);
131    void DeclareCallFunctions_PabloS(PabloS* stmt);
132    void DeclareCallFunctions_PabloE(PabloE* expr);
[3850]133    void StoreBitBlockMarkerPtr(std::string name, int index);
[3940]134    void LoadBitBlocksFromStaticExtern();
[3850]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);
[3999]140    Value* genMatchStar(Value* marker_expr, Value* cc_expr);
141    Value* genScanThru(Value* marker_expr, Value* cc_expr);
[4085]142    Value* genCarryInLoad(Value* ptr_carry_q, int carryq_idx);
143    Value* genCarryOutStore(Value* carryout, Value* ptr_carry_q, int carryq_idx);
[3999]144    Value* genAddWithCarry(Value* e1, Value* e2);
[4085]145    Value* genBitBlockAny(Value* e);
[3999]146    Value* genShiftRight127(Value* e, const Twine &namehint = "");
147    Value* genShiftLeft64(Value* e, const Twine &namehint = "") ;
148    Value* genNot(Value* e, const Twine &namehint = "");
[3850]149
[4096]150    SumWithOverflowPack genUaddOverflow(Value *e1, Value *e2);
151
[3850]152    int         mBits;
[3955]153    std::map<std::string, std::string> m_name_map;
[3850]154    std::string mBasis_Pattern;
155
156    Module*          mMod;
157    BasicBlock*      mBasicBlock;
[3914]158
[3850]159    ExecutionEngine* mExecutionEngine;
160
161    VectorType*  m64x2Vect;
162    PointerType* m64x2Vect_Ptr1;
163
[3940]164    VectorType* m128x1Vect;
165
[3850]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
[3914]174    int         mCarryQueueSize;
175
[3850]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;
[4096]182    Function*     mFunc_llvm_uadd_with_overflow_i128;
[3850]183
184    Constant*     mFunc_print_register;
[3940]185    Constant*     mFunc_test_getCategory;
186    Constant*     mFunc_get_unicode_category;
[3982]187    Value*     mFunc_get_unicode_category_Nd;
[3850]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.