Skip to content

Commit

Permalink
[SYCL] Add newPM support for passes in LLVMSYCL
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauthier Harnisch committed Jun 2, 2022
1 parent d04250e commit 3fa9b01
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 80 deletions.
8 changes: 4 additions & 4 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,10 @@ void initializeWinEHPreparePass(PassRegistry&);
void initializeWriteBitcodePassPass(PassRegistry&);
void initializeWriteThinLTOBitcodePass(PassRegistry&);
void initializeXRayInstrumentationPass(PassRegistry&);
void initializeInSPIRationPass(PassRegistry&);
void initializeKernelPropGenPass(PassRegistry&);
void initializeVXXIRDowngraderPass(PassRegistry&);
void initializePrepareSYCLOptPass(PassRegistry&);
void initializeInSPIRationLegacyPass(PassRegistry&);
void initializeKernelPropGenLegacyPass(PassRegistry&);
void initializeVXXIRDowngraderLegacyPass(PassRegistry&);
void initializePrepareSYCLOptLegacyPass(PassRegistry&);
void initializeLowerSYCLMetaDataPass(PassRegistry&);

} // end namespace llvm
Expand Down
8 changes: 5 additions & 3 deletions llvm/include/llvm/SYCL/InSPIRation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
#ifndef LLVM_SYCL_INSPIRATION_H
#define LLVM_SYCL_INSPIRATION_H

#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include "llvm/Support/SHA1.h"

namespace llvm {

struct InSPIRationPass : PassInfoMixin<InSPIRationPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

ModulePass *createInSPIRationPass();
ModulePass *createInSPIRationLegacyPass();

}

Expand Down
9 changes: 7 additions & 2 deletions llvm/include/llvm/SYCL/KernelPropGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
#ifndef LLVM_SYCL_KERNEL_PROP_GEN_H
#define LLVM_SYCL_KERNEL_PROP_GEN_H

#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"

namespace llvm {

ModulePass *createKernelPropGenPass();
class KernelPropGenPass : public PassInfoMixin<KernelPropGenPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

ModulePass *createKernelPropGenLegacyPass();

}

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/SYCL/LowerSYCLMetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
//
// ===---------------------------------------------------------------------===//

#ifndef LLVM_PREPARE_SYCL_OPT_H
#define LLVM_PREPARE_SYCL_OPT_H
#ifndef LLVM_SYCL_LOWER_SYCL_METADATA_H
#define LLVM_SYCL_LOWER_SYCL_METADATA_H

#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
Expand Down
13 changes: 9 additions & 4 deletions llvm/include/llvm/SYCL/PrepareSYCLOpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
//
// ===---------------------------------------------------------------------===//

#ifndef LLVM_PREPARE_SYCL_OPT_H
#define LLVM_PREPARE_SYCL_OPT_H
#ifndef LLVM_SYCL_PREPARE_SYCL_OPT_H
#define LLVM_SYCL_PREPARE_SYCL_OPT_H

#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"

namespace llvm {

ModulePass *createPrepareSYCLOptPass();
class PrepareSYCLOptPass : public PassInfoMixin<PrepareSYCLOptPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

ModulePass *createPrepareSYCLOptLegacyPass();

}

Expand Down
8 changes: 7 additions & 1 deletion llvm/include/llvm/SYCL/VXXIRDowngrader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
#define LLVM_SYCL_VXX_IR_DOWNGRADER_H

#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"

namespace llvm {

ModulePass *createVXXIRDowngraderPass();
class VXXIRDowngraderPass : public PassInfoMixin<VXXIRDowngraderPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

ModulePass *createVXXIRDowngraderLegacyPass();

}

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_llvm_component_library(LLVMPasses
ObjCARC
Scalar
Support
SYCL
SYCLLowerIR
Target
TransformUtils
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
#include "llvm/IR/PrintPasses.h"
#include "llvm/IR/SafepointIRVerifier.h"
#include "llvm/IR/Verifier.h"
#include "llvm/SYCL/InSPIRation.h"
#include "llvm/SYCL/KernelPropGen.h"
#include "llvm/SYCL/LowerSYCLMetaData.h"
#include "llvm/SYCL/PrepareSYCLOpt.h"
#include "llvm/SYCL/VXXIRDowngrader.h"
#include "llvm/SYCLLowerIR/ESIMD/ESIMDVerifier.h"
#include "llvm/SYCLLowerIR/ESIMD/LowerESIMD.h"
#include "llvm/SYCLLowerIR/LowerInvokeSimd.h"
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ MODULE_PASS("partial-inliner", PartialInlinerPass())
MODULE_PASS("pgo-icall-prom", PGOIndirectCallPromotion())
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
MODULE_PASS("pgo-instr-use", PGOInstrumentationUse())
MODULE_PASS("preparesycl", PrepareSYCLOptPass())
MODULE_PASS("inSPIRation", InSPIRationPass())
MODULE_PASS("lower-sycl-metadata", LowerSYCLMetaDataPass())
MODULE_PASS("kernelPropGen", KernelPropGenPass())
MODULE_PASS("vxxIRDowngrader", VXXIRDowngraderPass())
MODULE_PASS("print-profile-summary", ProfileSummaryPrinterPass(dbgs()))
MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
MODULE_PASS("print", PrintModulePass(dbgs()))
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/SYCL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ add_llvm_component_library(LLVMSYCL
${LLVM_MAIN_INCLUDE_DIR}/llvm/SYCL

LINK_COMPONENTS
Passes Core Support TransformUtils Demangle Analysis
Core Support TransformUtils Demangle Analysis
)
51 changes: 27 additions & 24 deletions llvm/lib/SYCL/InSPIRation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ static const std::regex matchReqdWorkGroupSize{
static const std::regex matchSomeNaturalInteger{R"(\d+)"};

/// Transform the SYCL kernel functions into v++ SPIR-compatible kernels
struct InSPIRation : public ModulePass {

static char ID; // Pass identification, replacement for typeid

InSPIRation() : ModulePass(ID) {}

struct InSPIRationState {
/// This function currently works by checking for certain prefixes, and
/// removing them from the mangled name, this currently is used for
/// get_global_id etc. (as we forcefully prefix it with __spir_ocl_), and
Expand Down Expand Up @@ -124,19 +119,6 @@ struct InSPIRation : public ModulePass {
F->getName().drop_front(Elem.first.size()));
}

bool doInitialization(Module &M) override {
// LLVM_DEBUG(dbgs() << "Enter: " << M.getModuleIdentifier() << "\n\n");

// Do not change the code
return false;
}

bool doFinalization(Module &M) override {
// LLVM_DEBUG(dbgs() << "Exit: " << M.getModuleIdentifier() << "\n\n");
// Do not change the code
return false;
}

/// Do transforms on a SPIR function called by a SPIR kernel
void kernelCallFuncSPIRify(Function &F) {
// no op at the moment
Expand Down Expand Up @@ -286,7 +268,7 @@ struct InSPIRation : public ModulePass {
/// However, it should be run prior to KernelPropGen as that
/// pass relies on the kernel names generated here for now to fuel the driver
/// script.
bool runOnModule(Module &M) override {
bool runOnModule(Module &M) {
// funcCount is for naming new name for each function called in kernel
int FuncCount = 0;

Expand Down Expand Up @@ -391,15 +373,36 @@ struct InSPIRation : public ModulePass {
}
};

void runInSPIRation(Module &M) {
InSPIRationState S;
S.runOnModule(M);
}

} // namespace

PreservedAnalyses InSPIRationPass::run(Module &M, ModuleAnalysisManager &AM) {
runInSPIRation(M);
return PreservedAnalyses::none();
}

struct InSPIRationLegacy : public ModulePass {

static char ID; // Pass identification, replacement for typeid

InSPIRationLegacy() : ModulePass(ID) {}
bool runOnModule(Module &M) override {
runInSPIRation(M);
return true;
}
};

namespace llvm {
void initializeInSPIRationPass(PassRegistry &Registry);
void initializeInSPIRationLegacyPass(PassRegistry & Registry);
}

INITIALIZE_PASS(InSPIRation, "inSPIRation",
INITIALIZE_PASS(InSPIRationLegacy, "inSPIRation",
"pass to make functions and kernels SPIR-compatible", false,
false)
ModulePass *llvm::createInSPIRationPass() { return new InSPIRation(); }
ModulePass *llvm::createInSPIRationLegacyPass() { return new InSPIRationLegacy(); }

char InSPIRation::ID = 0;
char InSPIRationLegacy::ID = 0;
37 changes: 27 additions & 10 deletions llvm/lib/SYCL/KernelPropGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ enum SPIRAddressSpace {

/// Retrieve the names and properties for all kernels in the module and place
/// them into a file. Generates the vitis HLS IR for kernel interface control.
struct KernelPropGen : public ModulePass {

static char ID; // Pass identification, replacement for typeid

KernelPropGen() : ModulePass(ID) {}
struct KernelPropGenState {

int getWriteStreamId(StringRef Path) {
int FileFD = 0;
Expand Down Expand Up @@ -196,7 +192,7 @@ struct KernelPropGen : public ModulePass {
}

/// Visit all the functions of the module
bool runOnModule(Module &M) override {
bool runOnModule(Module &M) {
llvm::raw_fd_ostream O(getWriteStreamId(KernelPropGenOutput),
true /*close in destructor*/);

Expand All @@ -209,15 +205,36 @@ struct KernelPropGen : public ModulePass {
}
};

void runKernelPropGen(Module &M) {
KernelPropGenState S;
S.runOnModule(M);
}

} // namespace

PreservedAnalyses KernelPropGenPass::run(Module &M, ModuleAnalysisManager &AM) {
runKernelPropGen(M);
return PreservedAnalyses::none();
}

namespace llvm {
void initializeKernelPropGenPass(PassRegistry &Registry);
void initializeKernelPropGenLegacyPass(PassRegistry &Registry);
} // namespace llvm

INITIALIZE_PASS(KernelPropGen, "kernelPropGen",
struct KernelPropGenLegacy : public ModulePass {

static char ID; // Pass identification, replacement for typeid

KernelPropGenLegacy() : ModulePass(ID) {}
bool runOnModule(Module &M) override {
runKernelPropGen(M);
return true;
}
};

INITIALIZE_PASS(KernelPropGenLegacy, "kernelPropGen",
"pass that finds kernel names and places them into a text file",
false, false)
ModulePass *llvm::createKernelPropGenPass() { return new KernelPropGen(); }
ModulePass *llvm::createKernelPropGenLegacyPass() { return new KernelPropGenLegacy(); }

char KernelPropGen::ID = 0;
char KernelPropGenLegacy::ID = 0;
37 changes: 27 additions & 10 deletions llvm/lib/SYCL/PrepareSYCLOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ namespace {

cl::opt<bool> AfterO3("sycl-prepare-after-O3", cl::Hidden, cl::init(false));

struct PrepareSYCLOpt : public ModulePass {

static char ID; // Pass identification, replacement for typeid

PrepareSYCLOpt() : ModulePass(ID) {}
struct PrepareSYCLOptState {

inline bool isKernel(Function &F) {
// Kernel are first detected with the SPIR_KERNEL CC.
Expand Down Expand Up @@ -237,7 +233,7 @@ struct PrepareSYCLOpt : public ModulePass {
}
}

bool runOnModule(Module &M) override {
bool runOnModule(Module &M) {
// When using the HLS flow instead of SPIR default
bool SyclHLSFlow = Triple(M.getTargetTriple()).isXilinxHLS();
unwrapFPGAProperties(M);
Expand All @@ -258,14 +254,35 @@ struct PrepareSYCLOpt : public ModulePass {
return true;
}
};

void runPrepareSYCLOpt(Module &M) {
PrepareSYCLOptState State;
State.runOnModule(M);
}

} // namespace

PreservedAnalyses PrepareSYCLOptPass::run(Module &M,
ModuleAnalysisManager &AM) {
runPrepareSYCLOpt(M);
return PreservedAnalyses::none();
}

struct PrepareSYCLOptLegacy : public ModulePass {
static char ID; // Pass identification, replacement for typeid
PrepareSYCLOptLegacy() : ModulePass(ID) {}
bool runOnModule(Module &M) override {
runPrepareSYCLOpt(M);
return true;
}
};

namespace llvm {
void initializePrepareSYCLOptPass(PassRegistry &Registry);
void initializePrepareSYCLOptLegacyPass(PassRegistry &Registry);
}

INITIALIZE_PASS(PrepareSYCLOpt, "preparesycl",
INITIALIZE_PASS(PrepareSYCLOptLegacy, "preparesycl",
"prepare SYCL device code to optimizations", false, false)
ModulePass *llvm::createPrepareSYCLOptPass() { return new PrepareSYCLOpt(); }
ModulePass *llvm::createPrepareSYCLOptLegacyPass() { return new PrepareSYCLOptLegacy(); }

char PrepareSYCLOpt::ID = 0;
char PrepareSYCLOptLegacy::ID = 0;
Loading

0 comments on commit 3fa9b01

Please sign in to comment.