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

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

Refactoring work + correction for getRawItemPointer

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