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

Last change on this file since 5458 was 5458, checked in by lindanl, 2 years ago

Add NVPTX driver.

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