source: icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h @ 4237

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

Moved llvm_gen.* into pablo/pablo_compiler.* and updated CMakeLists.txt

File size: 4.5 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 PABLO_COMPILER_H
8#define PABLO_COMPILER_H
9
10//define this indicates that we use llvm.uadd.with.overflow for genAddWithCarry
11//#define USE_UADD_OVERFLOW
12
13//Pablo Expressions
14#include <pablo/codegenstate.h>
15#include <pablo/pe_pabloe.h>
16#include "unicode_categories.h"
17//#include "unicode_categories-flat.h"
18//#include "unicode_categories-simple.h"
19#include <iostream>
20#include <string>
21#include <list>
22#include <map>
23#include <algorithm>
24
25#include <llvm/Support/raw_ostream.h>
26
27#ifdef USE_LLVM_3_4
28#include <llvm/Analysis/Verifier.h>
29#include <llvm/Assembly/PrintModulePass.h>
30#include <llvm/Linker.h>
31#endif
32
33#ifdef USE_LLVM_3_5
34#include <llvm/IR/Verifier.h>
35#endif
36
37#include <llvm/Pass.h>
38#include <llvm/PassManager.h>
39#include <llvm/ADT/SmallVector.h>
40#include <llvm/Analysis/Passes.h>
41#include <llvm/IR/BasicBlock.h>
42#include <llvm/IR/CallingConv.h>
43#include <llvm/IR/Constants.h>
44#include <llvm/IR/DataLayout.h>
45#include <llvm/IR/DerivedTypes.h>
46#include <llvm/IR/Function.h>
47#include <llvm/IR/GlobalVariable.h>
48#include <llvm/IR/InlineAsm.h>
49#include <llvm/IR/Instructions.h>
50#include <llvm/IR/LLVMContext.h>
51#include <llvm/IR/Module.h>
52#include <llvm/Support/FormattedStream.h>
53#include <llvm/Support/MathExtras.h>
54#include <llvm/Support/Casting.h>
55#include <llvm/Support/Debug.h>
56
57#include <llvm/Support/TargetSelect.h>
58#include <llvm/Transforms/Scalar.h>
59
60#include <llvm/ExecutionEngine/ExecutionEngine.h>
61#include <llvm/ExecutionEngine/MCJIT.h>
62
63#include <llvm/IRReader/IRReader.h>
64#include <llvm/Bitcode/ReaderWriter.h>
65#include <llvm/Support/MemoryBuffer.h>
66
67#include <llvm/IR/IRBuilder.h>
68
69#include "include/simd-lib/bitblock.hpp"
70
71using namespace llvm;
72
73namespace pablo {
74
75struct LLVM_Gen_RetVal
76{
77    int carry_q_size;
78    void *process_block_fptr;
79};
80
81struct SumWithOverflowPack {
82  Value *sum;
83  Value *obit;
84};
85
86class PabloCompiler {
87public:
88    PabloCompiler(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits);
89    ~PabloCompiler();
90
91
92    LLVM_Gen_RetVal compile(const PabloBlock & cg_state);
93private:
94    Module * MakeLLVMModule();
95    void DefineTypes();
96    void DeclareFunctions();
97    void DeclareCallFunctions(const ExpressionList & stmts);
98    void DeclareCallFunctions(const PabloE * expr);
99    void LoadBitBlocksFromStaticExtern();
100    void SetReturnMarker(Value * marker, const unsigned output_idx);
101
102    Value * GetMarker(const std::string & name);
103
104    Value * compileStatements(const ExpressionList & stmts);
105    Value * compileStatement(PabloE *stmt);
106
107    Value* compileExpression(PabloE * expr);
108    Value* genCarryInLoad(Value* ptr_carry_q, int carryq_idx);
109    Value* genCarryOutStore(Value* carryout, Value* ptr_carry_q, int carryq_idx);
110    Value* genAddWithCarry(Value* e1, Value* e2);
111    Value* genAdvanceWithCarry(Value* e1);
112    Value* genBitBlockAny(Value* e);
113    Value* genShiftHighbitToLow(Value* e, const Twine &namehint = "");
114    Value* genShiftLeft64(Value* e, const Twine &namehint = "") ;
115    Value* genNot(Value* e, const Twine &namehint = "");
116
117    SumWithOverflowPack callUaddOverflow(Value *e1, Value *e2);
118
119    std::map<std::string, Value*>       mCalleeMap;
120    std::map<std::string, Value*>       mMarkerMap;
121
122
123    int                                 mBits;
124    std::map<std::string, std::string>  m_name_map;
125    std::string                         mBasisBitPattern;
126
127
128
129    Module*                             mMod;
130    BasicBlock*                         mBasicBlock;
131    ExecutionEngine*                    mExecutionEngine;
132
133    VectorType*                         mXi64Vect;
134
135    VectorType*                         mXi128Vect;
136
137    PointerType*                        mBasisBitsInputPtr;
138    PointerType*                        mOutputPtr;
139
140    int                                 mCarryQueueIdx;
141    Value*                              mptr_carry_q;
142
143    int                                 mCarryQueueSize;
144
145    ConstantInt*                        mConst_int64_neg1;
146    ConstantAggregateZero*              mZeroInitializer;
147    Constant*                           mAllOneInitializer;
148
149    FunctionType*                       mFuncTy_0;
150    Function*                           mFunc_process_block;
151
152
153    AllocaInst*                         mBasisBitsAddr;
154    AllocaInst*                         mPtr_carry_q_addr;
155    AllocaInst*                         mPtr_output_addr;
156};
157
158}
159
160#endif // LLVM_GENERATOR_H
Note: See TracBrowser for help on using the repository browser.