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

Last change on this file since 4900 was 4900, checked in by cameron, 3 years ago

Dynamic generation of s2p code

File size: 2.8 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//#define USE_LONG_INTEGER_SHIFT
13//#define USE_TWO_UADD_OVERFLOW
14
15#if defined(USE_TWO_UADD_OVERFLOW) && !defined(USE_UADD_OVERFLOW)
16static_assert(false, "Need to turn on them together.");
17#endif
18
19//Pablo Expressions
20#include <string>
21#include <list>
22#include <vector>
23#include <map>
24#include <algorithm>
25#include <unordered_map>
26#include <pablo/pe_string.h>
27#include <pablo/carry_manager.h>
28#include <llvm/ADT/Twine.h>
29#include <llvm/IR/IRBuilder.h>
30#include <IDISA/idisa_builder.h>
31
32namespace llvm {
33    class Value;
34    class Module;
35    class ExecutionEngine;
36    class VectorType;
37    class PointerType;
38    class ConstantAggregateZero;
39    class Constant;
40    class FunctionType;
41    class Function;
42    class BasicBlock;
43}
44
45namespace pablo {
46
47using namespace llvm;
48
49class PabloAST;
50class PabloBlock;
51class PabloFunction;
52class String;
53class Var;
54class Statement;
55class StatementList;
56class If;
57class While;
58
59#if (BLOCK_SIZE==256)
60#define USE_UADD_OVERFLOW
61#define USE_TWO_UADD_OVERFLOW
62#endif
63
64class PabloCompiler {
65    #ifdef USE_UADD_OVERFLOW
66    struct SumWithOverflowPack {
67        Value * sum;
68        Value * obit;
69    };
70    #endif
71
72    typedef std::unordered_map<const pablo::PabloAST *, Value *>   ASTToValueMap;
73
74public:
75    PabloCompiler(Module * m, IDISA::IDISA_Builder * b);
76    ~PabloCompiler();
77    Function * compile(pablo::PabloFunction * function);
78private:
79    void GenerateFunction(PabloFunction & function);
80    void Examine(PabloFunction & function);
81    void Examine(PabloBlock * block);
82
83    void SetOutputValue(Value * marker, const unsigned index);
84
85    void compileBlock(PabloBlock * block);
86    void compileStatement(const Statement * stmt);
87    void compileIf(const If * ifStmt);
88    void compileWhile(const While * whileStmt);
89    Value* compileExpression(const PabloAST * expr);
90
91    ASTToValueMap                       mMarkerMap;
92
93    Module *                            mMod;
94    IDISA::IDISA_Builder *              iBuilder;
95    Type* const                         mBitBlockType;
96
97    CarryManager *                      mCarryManager;
98
99    PointerType*                        mInputType;
100
101    PabloBlock *                        mPabloBlock;
102   
103    unsigned                            mWhileDepth;
104    unsigned                            mIfDepth;
105
106    Function *                          mFunction;
107    Value *                             mInputAddressPtr;
108    Value *                             mOutputAddressPtr;
109
110    unsigned                            mMaxWhileDepth;
111
112};
113
114}
115
116#endif // LLVM_GENERATOR_H
Note: See TracBrowser for help on using the repository browser.