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

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

Removed string based CC lookup in CC Compiler.

File size: 4.6 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/codegenstate.h>
17#include <pablo/pe_pabloe.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;
76using namespace pablo;
77
78struct LLVM_Gen_RetVal
79{
80    int carry_q_size;
81    void *process_block_fptr;
82};
83
84struct SumWithOverflowPack {
85  Value *sum;
86  Value *obit;
87};
88
89class LLVM_Generator {
90public:
91    LLVM_Generator(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits);
92    ~LLVM_Generator();
93    LLVM_Gen_RetVal Generate_LLVMIR(const CodeGenState &cg_state);
94private:
95    void MakeLLVMModule();
96    void DefineTypes();
97    void DeclareFunctions();
98    void DeclareCallFunctions(ExpressionList stmts);
99    void DeclareCallFunctions_PabloS(PabloE* stmt);
100    void DeclareCallFunctions_PabloE(PabloE* expr);
101    void StoreBitBlockMarkerPtr(std::string name, int index);
102    void LoadBitBlocksFromStaticExtern();
103    void SetReturnMarker(std::string marker, int output_idx);
104    Value* GetMarker(std::string name);
105    std::string Generate_PabloStatements(ExpressionList stmts);
106    std::string Generate_PabloS(PabloE* stmt);
107    Value* Generate_PabloE(PabloE* expr);
108    Value* genMatchStar(Value* marker_expr, Value* cc_expr);
109    Value* genScanThru(Value* marker_expr, Value* cc_expr);
110    Value* genCarryInLoad(Value* ptr_carry_q, int carryq_idx);
111    Value* genCarryOutStore(Value* carryout, Value* ptr_carry_q, int carryq_idx);
112    Value* genAddWithCarry(Value* e1, Value* e2);
113    Value* genAdvanceWithCarry(Value* e1);
114    Value* genBitBlockAny(Value* e);
115    Value* genShiftHighbitToLow(Value* e, const Twine &namehint = "");
116    Value* genShiftLeft64(Value* e, const Twine &namehint = "") ;
117    Value* genNot(Value* e, const Twine &namehint = "");
118
119    SumWithOverflowPack callUaddOverflow(Value *e1, Value *e2);
120
121    int         mBits;
122    std::map<std::string, std::string> m_name_map;
123    std::string mBasis_Pattern;
124
125    Module*          mMod;
126    BasicBlock*      mBasicBlock;
127
128    ExecutionEngine* mExecutionEngine;
129
130    VectorType*  mXi64Vect;
131    PointerType* mXi64Vect_Ptr1;
132
133    VectorType* mXi128Vect;
134
135    PointerType* mStruct_Basis_Bits_Ptr1;
136    PointerType* mStruct_Output_Ptr1;
137
138    std::map<std::string, Value*> mMarkerMap;
139
140    int         mCarryQueueIdx;
141    Value*      mptr_carry_q;
142
143    int         mCarryQueueSize;
144
145    ConstantInt*           mConst_int64_neg1;
146    ConstantAggregateZero* mConst_Aggregate_Xi64_0;
147    Constant*              mConst_Aggregate_Xi64_neg1;
148
149    FunctionType* mFuncTy_0;
150    Function*     mFunc_process_block;
151    Function*     mFunc_llvm_uadd_with_overflow;
152
153    Constant*     mFunc_print_register;
154    Constant*     mFunc_test_getCategory;
155    Constant*     mFunc_get_unicode_category;
156    Value*     mFunc_get_unicode_category_Nd;
157
158    AllocaInst*  mPtr_basis_bits_addr;
159    AllocaInst*  mPtr_carry_q_addr;
160    AllocaInst*  mPtr_output_addr;
161};
162
163
164#endif // LLVM_GENERATOR_H
Note: See TracBrowser for help on using the repository browser.