source: icGREP/icgrep-devel/icgrep/toolchain/toolchain.h @ 5456

Last change on this file since 5456 was 5454, checked in by nmedfort, 2 years ago

Bug fix check in for DumpTrace?, compilation of DoBlock? / DoFinalBlock? functions. Pablo CodeMotionPass? optimized and enabled by default.

File size: 3.8 KB
Line 
1/*
2 *  Copyright (c) 2017 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 TOOLCHAIN_H
8#define TOOLCHAIN_H
9#include <string>
10#include <IR_Gen/FunctionTypeBuilder.h>
11#include <kernels/kernel.h>
12#include <kernels/streamset.h>
13
14namespace llvm { class ExecutionEngine; }
15namespace llvm { class Function; }
16namespace llvm { class Module; }
17namespace llvm { class TargetMachine; }
18namespace llvm { class formatted_raw_ostream; }
19namespace llvm { namespace cl { class OptionCategory; } }
20namespace kernel { class Kernel; }
21namespace kernel { class KernelBuilder; }
22namespace IDISA { class IDISA_Builder; }
23
24class ParabixObjectCache;
25
26namespace codegen {
27const llvm::cl::OptionCategory * codegen_flags();
28
29// Command Parameters
30enum DebugFlags {
31    ShowUnoptimizedIR,
32    ShowIR,
33    VerifyIR,
34#ifndef USE_LLVM_3_6
35    ShowASM,
36#endif
37    SerializeThreads
38};
39
40bool DebugOptionIsSet(DebugFlags flag);
41
42
43extern char OptLevel;  // set from command line
44extern int BlockSize;  // set from command line
45extern int SegmentSize;  // set from command line
46extern int BufferSegments;
47extern int ThreadNum;
48extern bool EnableAsserts;
49extern bool EnableCycleCounter;
50#ifdef CUDA_ENABLED
51extern bool NVPTX;
52extern int GroupNum;
53#endif
54}
55
56#ifdef CUDA_ENABLED
57void setNVPTXOption();
58void Compile2PTX (llvm::Module * m, std::string IRFilename, std::string PTXFilename);
59#endif
60
61void AddParabixVersionPrinter();
62
63bool AVX2_available();
64
65class ParabixDriver {
66    friend class CBuilder;
67public:
68    ParabixDriver(std::string && moduleName);
69
70    ~ParabixDriver();
71   
72    const std::unique_ptr<kernel::KernelBuilder> & getBuilder();
73   
74    parabix::ExternalBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalBuffer> b);
75   
76    parabix::StreamSetBuffer * addBuffer(std::unique_ptr<parabix::StreamSetBuffer> b);
77   
78    kernel::Kernel * addKernelInstance(std::unique_ptr<kernel::Kernel> kb);
79   
80    void addKernelCall(kernel::Kernel & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
81
82    void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
83   
84    void generatePipelineIR();
85   
86    template <typename ExternalFunctionType>
87    llvm::Function * LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
88
89    void linkAndFinalize();
90   
91    void * getPointerToMain();
92
93protected:
94
95    llvm::Function * LinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const;
96
97private:
98    std::unique_ptr<llvm::LLVMContext>                      mContext;
99    llvm::Module * const                                    mMainModule;
100    std::unique_ptr<kernel::KernelBuilder>                  iBuilder;
101    llvm::TargetMachine *                                   mTarget;
102    llvm::ExecutionEngine *                                 mEngine;
103    ParabixObjectCache *                                    mCache;
104
105    std::vector<kernel::Kernel *>                           mPipeline;
106    // Owned kernels and buffers that will persist with this ParabixDriver instance.
107    std::vector<std::unique_ptr<kernel::Kernel>>            mOwnedKernels;
108    std::vector<std::unique_ptr<parabix::StreamSetBuffer>>  mOwnedBuffers;
109};
110
111template <typename ExternalFunctionType>
112llvm::Function * ParabixDriver::LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
113    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(*mContext.get());
114    assert ("FunctionTypeBuilder did not resolve a function type." && type);
115    return LinkFunction(kb.getModule(), name, type, reinterpret_cast<void *>(functionPtr));
116}
117
118#endif
Note: See TracBrowser for help on using the repository browser.