Skip to content

Port Local Accessor and Global Offset passes to the new PM #5987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions llvm/include/llvm/SYCLLowerIR/GlobalOffset.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,51 @@
#ifndef LLVM_SYCL_GLOBALOFFSET_H
#define LLVM_SYCL_GLOBALOFFSET_H

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

namespace llvm {

ModulePass *createGlobalOffsetPass();
class ModulePass;
class PassRegistry;

class GlobalOffsetPass : public PassInfoMixin<GlobalOffsetPass> {
private:
using KernelPayload = TargetHelpers::KernelPayload;
using ArchType = TargetHelpers::ArchType;

public:
explicit GlobalOffsetPass() {}

PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
static StringRef getPassName() { return "Add implicit SYCL global offset"; }

private:
void processKernelEntryPoint(Module &M, Function *Func);
void addImplicitParameterToCallers(Module &M, Value *Callee,
Function *CalleeWithImplicitParam);
std::pair<Function *, Value *>
addOffsetArgumentToFunction(Module &M, Function *Func,
Type *ImplicitArgumentType = nullptr,
bool KeepOriginal = false);
DenseMap<Function *, MDNode *>
validateKernels(Module &M, SmallVectorImpl<KernelPayload> &KernelPayloads);

private:
// Keep track of which functions have been processed to avoid processing twice
llvm::DenseMap<Function *, Value *> ProcessedFunctions;
// Keep a map of all entry point functions with metadata
llvm::DenseMap<Function *, MDNode *> EntryPointMetadata;
llvm::Type *KernelImplicitArgumentType;
llvm::Type *ImplicitOffsetPtrType;

ArchType AT;
unsigned TargetAS = 0;
};

ModulePass *createGlobalOffsetPassLegacy();
void initializeGlobalOffsetLegacyPass(PassRegistry &);

} // end namespace llvm

Expand Down
34 changes: 32 additions & 2 deletions llvm/include/llvm/SYCLLowerIR/LocalAccessorToSharedMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,41 @@
#define LLVM_SYCL_LOCALACCESSORTOSHAREDMEMORY_H

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

namespace llvm {

ModulePass *createLocalAccessorToSharedMemoryPass();
class ModulePass;
class PassRegistry;

class LocalAccessorToSharedMemoryPass
: public PassInfoMixin<LocalAccessorToSharedMemoryPass> {
private:
using KernelPayload = TargetHelpers::KernelPayload;
using ArchType = TargetHelpers::ArchType;

public:
explicit LocalAccessorToSharedMemoryPass() {}

PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
static StringRef getPassName() {
return "SYCL Local Accessor to Shared Memory";
}

private:
Function *processKernel(Module &M, Function *F);
void postProcessKernels(
SmallVectorImpl<std::pair<Function *, KernelPayload>> &NewToOldKernels);

private:
// The value for NVVM's ADDRESS_SPACE_SHARED and AMD's LOCAL_ADDRESS happen to
// be 3.
const unsigned SharedASValue = 3;
};

ModulePass *createLocalAccessorToSharedMemoryPassLegacy();
void initializeLocalAccessorToSharedMemoryLegacyPass(PassRegistry &);

} // end namespace llvm

Expand Down
Loading