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

Last change on this file since 4197 was 4197, checked in by nmedfort, 5 years ago

More refactoring of the RE system; moved the original re/RE_Compiler to compiler.cpp and the PBIX_Compiler to the re/RE_Compiler.

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