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

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

#ifdefs for experimental options

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