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

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

Changes towards separate compilation

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/idisa_builder.h>
11#include <IR_Gen/FunctionTypeBuilder.h>
12#include <kernels/kernel.h>
13#include <kernels/streamset.h>
14
15namespace llvm { class ExecutionEngine; }
16namespace llvm { class Module; }
17namespace llvm { class TargetMachine; }
18namespace llvm { class formatted_raw_ostream; }
19namespace llvm { namespace cl { class OptionCategory; } }
20namespace IDISA { class IDISA_Builder; }
21namespace kernel { class KernelBuilder; }
22
23class ParabixObjectCache;
24
25namespace codegen {
26const llvm::cl::OptionCategory * codegen_flags();
27
28// Command Parameters
29enum DebugFlags {
30    ShowIR,
31#ifndef USE_LLVM_3_6
32    ShowASM,
33#endif
34    SerializeThreads
35};
36
37bool DebugOptionIsSet(DebugFlags flag);
38
39
40extern char OptLevel;  // set from command line
41extern int BlockSize;  // set from command line
42extern int SegmentSize;  // set from command line
43extern int BufferSegments;
44extern int ThreadNum;
45extern bool EnableAsserts;
46extern bool EnableCycleCounter;
47#ifdef CUDA_ENABLED
48extern bool NVPTX;
49extern int GroupNum;
50#endif
51}
52
53#ifdef CUDA_ENABLED
54void setNVPTXOption();
55void Compile2PTX (llvm::Module * m, std::string IRFilename, std::string PTXFilename);
56#endif
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    IDISA::IDISA_Builder * getIDISA_Builder() { return iBuilder.get(); }
70   
71    parabix::ExternalFileBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalFileBuffer> b, llvm::Value * externalBuf);
72   
73    parabix::StreamSetBuffer * addBuffer(std::unique_ptr<parabix::StreamSetBuffer> b);
74   
75    kernel::KernelBuilder * addKernelInstance(std::unique_ptr<kernel::KernelBuilder> kb);
76   
77    void addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
78
79    void makeKernelCall(kernel::KernelBuilder * 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::KernelBuilder & 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<IDISA::IDISA_Builder>   iBuilder;
98    llvm::TargetMachine *                   mTarget;
99    llvm::ExecutionEngine *                 mEngine;
100    ParabixObjectCache *                    mCache;
101
102    std::vector<kernel::KernelBuilder *>    mPipeline;
103    // Owned kernels and buffers that will persist with this ParabixDriver instance.
104    std::vector<std::unique_ptr<kernel::KernelBuilder>> mOwnedKernels;
105    std::vector<std::unique_ptr<parabix::StreamSetBuffer>> mOwnedBuffers;
106};
107
108template <typename ExternalFunctionType>
109llvm::Function * ParabixDriver::LinkFunction(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
110    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(iBuilder->getContext());
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.