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

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

Continued refactoring work. PabloKernel? now abstract base type with a 'generatePabloMethod' hook to generate Pablo code.

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