Ignore:
Timestamp:
May 22, 2017, 12:14:19 PM (2 years ago)
Author:
nmedfort
Message:

Restructuring work for the Driver classes. Start of work to eliminate the memory leaks with the ExecutionEngine?. Replaced custom AlignedMalloc? with backend call to std::aligned_malloc. Salvaged some work on DistributionPass? for reevaluation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.h

    r5458 r5464  
    77#ifndef TOOLCHAIN_H
    88#define TOOLCHAIN_H
    9 #include <string>
    10 #include <IR_Gen/FunctionTypeBuilder.h>
    11 #include <kernels/kernel.h>
    12 #include <kernels/streamset.h>
    139
    14 #include <toolchain/NVPTXDriver.h>
    15 namespace llvm { class ExecutionEngine; }
    16 namespace llvm { class Function; }
    17 namespace llvm { class Module; }
    18 namespace llvm { class TargetMachine; }
    19 namespace llvm { class formatted_raw_ostream; }
     10#include <llvm/ADT/StringRef.h>
     11#include <llvm/Support/CodeGen.h>
     12#include <llvm/Target/TargetOptions.h>
     13#include <llvm/Target/TargetMachine.h>
     14
     15// FIXME: llvm/CodeGen/CommandFlags.h can only be included once or the various cl::opt causes multiple definition
     16// errors. To bypass for now, the relevant options and functions are accessible from here. Re-evaluate with later
     17// versions of LLVM.
     18
    2019namespace llvm { namespace cl { class OptionCategory; } }
    21 namespace kernel { class Kernel; }
    22 namespace kernel { class KernelBuilder; }
    23 namespace IDISA { class IDISA_Builder; }
    24 
    25 class ParabixObjectCache;
    2620
    2721namespace codegen {
     22
    2823const llvm::cl::OptionCategory * codegen_flags();
    2924
     
    3934};
    4035
    41 bool DebugOptionIsSet(DebugFlags flag);
     36bool DebugOptionIsSet(const DebugFlags flag);
    4237
    43 
    44 extern char OptLevel;  // set from command line
     38extern bool pipelineParallel;
     39extern bool segmentPipelineParallel;
     40#ifndef USE_LLVM_3_6
     41extern const std::string ASMOutputFilename;
     42#endif
     43extern const std::string IROutputFilename;
     44extern const std::string ObjectCacheDir;
     45extern const llvm::CodeGenOpt::Level OptLevel;  // set from command line
    4546extern int BlockSize;  // set from command line
    4647extern int SegmentSize;  // set from command line
    4748extern int BufferSegments;
    4849extern int ThreadNum;
     50extern const bool EnableObjectCache;
    4951extern bool EnableAsserts;
    5052extern bool EnableCycleCounter;
    5153extern bool NVPTX;
    5254extern int GroupNum;
     55extern const llvm::TargetOptions Options;
     56extern const llvm::Reloc::Model RelocModel;
     57extern const llvm::CodeModel::Model CMModel;
     58extern const std::string MArch;
     59extern const std::string RunPass;
     60extern const llvm::TargetMachine::CodeGenFileType FileType;
     61extern const std::string StopAfter;
     62extern const std::string StartAfter;
     63
     64std::string getCPUStr();
     65std::string getFeaturesStr();
     66void setFunctionAttributes(llvm::StringRef CPU, llvm::StringRef Features, llvm::Module &M);
     67
    5368}
    5469
     
    6075bool AVX2_available();
    6176
    62 class ParabixDriver {
    63     friend class CBuilder;
    64 public:
    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 
    90 protected:
    91 
    92     llvm::Function * LinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const;
    93 
    94 private:
    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 
    108 template <typename ExternalFunctionType>
    109 llvm::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 
    11577#endif
Note: See TracChangeset for help on using the changeset viewer.