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

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

Intergrated Meng's uadd with overflow patch; untested for now. Minor misc changes to Pablo Compiler.

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