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

Last change on this file since 3911 was 3850, checked in by cameron, 5 years ago

icgrep-0.8 distribution

File size: 3.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 LLVM_GENERATOR_H
8#define LLVM_GENERATOR_H
9
10//Regular Expressions
11#include "re_re.h"
12#include "re_cc.h"
13#include "re_start.h"
14#include "re_end.h"
15#include "re_seq.h"
16#include "re_alt.h"
17#include "re_rep.h"
18
19#include "rl_replimit.h"
20#include "rl_unbounded.h"
21#include "rl_upperbound.h"
22
23//Pablo Expressions
24#include "pe_pabloe.h"
25#include "pe_sel.h"
26#include "pe_advance.h"
27#include "pe_all.h"
28#include "pe_and.h"
29#include "pe_charclass.h"
30#include "pe_matchstar.h"
31#include "pe_not.h"
32#include "pe_or.h"
33#include "pe_var.h"
34#include "pe_xor.h"
35
36//Pablo Statements
37#include "ps_pablos.h"
38#include "ps_assign.h"
39#include "ps_if.h"
40#include "ps_while.h"
41
42#include "cc_codegenobject.h"
43#include "pbix_compiler.h"
44
45#include "llvm_gen_helper.h"
46
47#include <iostream>
48#include <string>
49#include <sstream>
50#include <list>
51#include <map>
52#include <algorithm>
53
54#include <llvm/Support/raw_ostream.h>
55
56#include <llvm/Pass.h>
57#include <llvm/PassManager.h>
58#include <llvm/ADT/SmallVector.h>
59#include <llvm/Analysis/Verifier.h>
60#include "llvm/Analysis/Passes.h"
61#include <llvm/Assembly/PrintModulePass.h>
62#include <llvm/IR/BasicBlock.h>
63#include <llvm/IR/CallingConv.h>
64#include <llvm/IR/Constants.h>
65#include "llvm/IR/DataLayout.h"
66#include "llvm/IR/DerivedTypes.h"
67#include <llvm/IR/Function.h>
68#include <llvm/IR/GlobalVariable.h>
69#include <llvm/IR/InlineAsm.h>
70#include <llvm/IR/Instructions.h>
71#include <llvm/IR/LLVMContext.h>
72#include <llvm/IR/Module.h>
73#include <llvm/Support/FormattedStream.h>
74#include <llvm/Support/MathExtras.h>
75#include <llvm/Support/Casting.h>
76
77#include "llvm/Support/TargetSelect.h"
78#include "llvm/Transforms/Scalar.h"
79
80#include <llvm/ExecutionEngine/ExecutionEngine.h>
81#include <llvm/ExecutionEngine/MCJIT.h>
82
83#include <llvm/Linker.h>
84#include <llvm/IRReader/IRReader.h>
85#include <llvm/Bitcode/ReaderWriter.h>
86#include <llvm/Support/MemoryBuffer.h>
87
88#include <llvm/IR/IRBuilder.h>
89
90#include <simd-lib/bitblock.hpp>
91
92using namespace llvm;
93
94struct LLVM_Gen_RetVal
95{
96    int carry_q_size;
97    void *process_block_fptr;
98};
99
100class LLVM_Generator
101{
102public:
103    LLVM_Generator(std::string basis_pattern, int bits);
104    ~LLVM_Generator();
105    LLVM_Gen_RetVal Generate_LLVMIR(CodeGenState cg_state, std::list<PabloS*> cc_cgo);
106    void Print_Register(char* name, BitBlock bit_block);
107private:
108    void MakeLLVMModule();
109    void DefineTypes();
110    void DeclareFunctions();
111    void StoreBitBlockMarkerPtr(std::string name, int index);
112    void SetReturnMarker(std::string marker, int output_idx);
113    Value* GetMarker(std::string name);
114    std::string Generate_PabloStatements(std::list<PabloS*> stmts);
115    std::string Generate_PabloS(PabloS* stmt);
116    Value* Generate_PabloE(PabloE* expr);
117
118    int         mBits;
119    std::string mBasis_Pattern;
120
121    Module*          mMod;
122    BasicBlock*      mBasicBlock;
123    BasicBlock*      mWhileCondBlock;
124    BasicBlock*      mWhileBodyBlock;
125    BasicBlock*      mWhileEndBlock;
126    ExecutionEngine* mExecutionEngine;
127
128    VectorType*  m64x2Vect;
129    PointerType* m64x2Vect_Ptr1;
130
131    PointerType* mStruct_Basis_Bits_Ptr1;
132    PointerType* mStruct_Output_Ptr1;
133
134    std::map<std::string, Value*> mMarkerMap;
135
136    bool        mInWhile;
137
138    int         mCarryQueueIdx;
139    Value*      mptr_carry_q;
140
141    ConstantInt*           mConst_int64_neg1;
142    ConstantAggregateZero* mConst_Aggregate_64x2_0;
143    Constant*              mConst_Aggregate_64x2_neg1;
144
145    FunctionType* mFuncTy_0;
146    Function*     mFunc_process_block;
147
148    Constant*     mFunc_print_register;
149
150    AllocaInst*  mPtr_basis_bits_addr;
151    AllocaInst*  mPtr_carry_q_addr;
152    AllocaInst*  mPtr_output_addr;
153};
154
155
156#endif // LLVM_GENERATOR_H
Note: See TracBrowser for help on using the repository browser.