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

Last change on this file since 4272 was 4270, checked in by nmedfort, 4 years ago

Minor changes.

File size: 4.2 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/pabloAST.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
84
85    typedef std::unordered_map<const pablo::String *, Value*>   StringToValueMap;
86    typedef std::vector<Value*>                                 CarryQueueVector;
87
88public:
89    PabloCompiler(const std::vector<Var *> & basisBitVars);
90    ~PabloCompiler();
91    LLVM_Gen_RetVal compile(PabloBlock & pb);
92private:
93    void DefineTypes();
94    void DeclareFunctions();
95    void DeclareCallFunctions(const StatementList & stmts);
96    void DeclareCallFunctions(const PabloAST * expr);
97    void SetOutputValue(Value * marker, const unsigned index);
98
99    Value* compileStatements(const StatementList & stmts);
100    Value* compileStatement(const PabloAST * stmt);
101    Value* compileExpression(const PabloAST * expr);
102    Value* genCarryInLoad(const unsigned index);
103    void   genCarryOutStore(Value* carryOut, const unsigned index);
104    Value* genAddWithCarry(Value* e1, Value* e2);
105    Value* genAdvanceWithCarry(Value* e1, int shift_amount);
106    Value* genBitBlockAny(Value* test);
107    Value* genShiftHighbitToLow(Value* e, const Twine & namehint = "");
108    Value* genShiftLeft64(Value* e, const Twine & namehint = "") ;
109    Value* genNot(Value* expr);
110
111    #ifdef USE_UADD_OVERFLOW
112    SumWithOverflowPack callUaddOverflow(Value *e1, Value *e2, Value *cin);
113    #endif
114
115    StringToValueMap                    mMarkerMap;
116    CarryQueueVector                    mCarryQueueVector;
117
118    const std::vector<Var *> &          mBasisBits;
119
120    Module* const                       mMod;
121    BasicBlock*                         mBasicBlock;
122    ExecutionEngine*                    mExecutionEngine;
123
124    VectorType* const                   mBitBlockType;
125    PointerType*                        mBasisBitsInputPtr;
126
127    unsigned                            mCarryQueueIdx;
128    Value*                              mCarryQueuePtr;
129    unsigned                            mNestingDepth;
130    unsigned                            mCarryQueueSize;
131
132    ConstantAggregateZero* const        mZeroInitializer;
133    Constant* const                     mOneInitializer;
134
135    FunctionType*                       mFunctionType;
136    Function*                           mFunc_process_block;
137
138
139    Value*                              mBasisBitsAddr;
140    Value*                              mOutputAddrPtr;
141
142    StringToValueMap                    mCalleeMap;
143};
144
145}
146
147#endif // LLVM_GENERATOR_H
Note: See TracBrowser for help on using the repository browser.