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

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

First stage of refactoring PabloE classes.

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