Skip to content

[SYCL] Add barrier optimization pass #19353

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

Open
wants to merge 8 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "llvm/SYCLLowerIR/SYCLAddOptLevelAttribute.h"
#include "llvm/SYCLLowerIR/SYCLConditionalCallOnDevice.h"
#include "llvm/SYCLLowerIR/SYCLCreateNVVMAnnotations.h"
#include "llvm/SYCLLowerIR/SYCLOptimizeBarriers.h"
#include "llvm/SYCLLowerIR/SYCLPropagateAspectsUsage.h"
#include "llvm/SYCLLowerIR/SYCLPropagateJointMatrixUsage.h"
#include "llvm/SYCLLowerIR/SYCLVirtualFunctionsAnalysis.h"
Expand Down Expand Up @@ -1096,6 +1097,16 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
});
}

// Add SYCLOptimizeBarriers pass for SYCL device code.
if (LangOpts.SYCLIsDevice) {
PB.registerOptimizerLastEPCallback(
[](ModulePassManager &MPM, OptimizationLevel Level,
ThinOrFullLTOPhase) {
MPM.addPass(
createModuleToFunctionPassAdaptor(SYCLOptimizeBarriersPass()));
});
}

const bool PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
const bool PrepareForLTO = CodeGenOpts.PrepareForLTO;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
//==- SYCLOptimizeBackToBackBarrier.h - SYCLOptimizeBackToBackBarrier Pass -==//
//==- SYCLOptimizeBarriers.h - SYCLOptimizeBarriers Pass -==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This pass cleans up back-to-back ControlBarrier calls.
// This pass cleans up ControlBarrier and MemoryBarrier calls.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_SYCL_OPTIMIZE_BACK_TO_BACK_BARRIER_H
#define LLVM_SYCL_OPTIMIZE_BACK_TO_BACK_BARRIER_H
#ifndef LLVM_SYCL_OPTIMIZE_BARRIERS_H
#define LLVM_SYCL_OPTIMIZE_BARRIERS_H

#include "llvm/IR/PassManager.h"

namespace llvm {

class SYCLOptimizeBackToBackBarrierPass
: public PassInfoMixin<SYCLOptimizeBackToBackBarrierPass> {
class SYCLOptimizeBarriersPass
: public PassInfoMixin<SYCLOptimizeBarriersPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
PreservedAnalyses run(Function &F, FunctionAnalysisManager &);

static bool isRequired() { return true; }
};

} // namespace llvm

#endif // LLVM_SYCL_OPTIMIZE_BACK_TO_BACK_BARRIER_H
#endif // LLVM_SYCL_OPTIMIZE_BARRIERS_H
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
#include "llvm/SYCLLowerIR/SYCLConditionalCallOnDevice.h"
#include "llvm/SYCLLowerIR/SYCLCreateNVVMAnnotations.h"
#include "llvm/SYCLLowerIR/SYCLJointMatrixTransform.h"
#include "llvm/SYCLLowerIR/SYCLOptimizeBackToBackBarrier.h"
#include "llvm/SYCLLowerIR/SYCLOptimizeBarriers.h"
#include "llvm/SYCLLowerIR/SYCLPropagateAspectsUsage.h"
#include "llvm/SYCLLowerIR/SYCLPropagateJointMatrixUsage.h"
#include "llvm/SYCLLowerIR/SYCLVirtualFunctionsAnalysis.h"
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
#include "llvm/Transforms/Vectorize/SLPVectorizer.h"
#include "llvm/Transforms/Vectorize/VectorCombine.h"

// TODO: move it elsewhere
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we should do before merging this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm thinking of just Transforms

#include "llvm/SYCLLowerIR/SYCLOptimizeBarriers.h"

using namespace llvm;

static cl::opt<InliningAdvisorMode> UseInlineAdvisor(
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ MODULE_PASS("esimd-remove-host-code", ESIMDRemoveHostCodePass());
MODULE_PASS("esimd-remove-optnone-noinline", ESIMDRemoveOptnoneNoinlinePass());
MODULE_PASS("sycl-conditional-call-on-device", SYCLConditionalCallOnDevicePass())
MODULE_PASS("sycl-joint-matrix-transform", SYCLJointMatrixTransformPass())
MODULE_PASS("sycl-optimize-back-to-back-barrier", SYCLOptimizeBackToBackBarrierPass())
MODULE_PASS("sycl-propagate-aspects-usage", SYCLPropagateAspectsUsagePass())
MODULE_PASS("sycl-propagate-joint-matrix-usage", SYCLPropagateJointMatrixUsagePass())
MODULE_PASS("sycl-add-opt-level-attribute", SYCLAddOptLevelAttributePass())
Expand Down Expand Up @@ -507,6 +506,7 @@ FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
FUNCTION_PASS("slsr", StraightLineStrengthReducePass())
FUNCTION_PASS("stack-protector", StackProtectorPass(TM))
FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
FUNCTION_PASS("sycl-optimize-barriers", SYCLOptimizeBarriersPass())
FUNCTION_PASS("tailcallelim", TailCallElimPass())
FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
FUNCTION_PASS("trigger-crash-function", TriggerCrashFunctionPass())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/SYCLLowerIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ add_llvm_component_library(LLVMSYCLLowerIR
SYCLDeviceRequirements.cpp
SYCLKernelParamOptInfo.cpp
SYCLJointMatrixTransform.cpp
SYCLOptimizeBackToBackBarrier.cpp
SYCLOptimizeBarriers.cpp
SYCLPropagateAspectsUsage.cpp
SYCLPropagateJointMatrixUsage.cpp
SYCLVirtualFunctionsAnalysis.cpp
Expand Down
160 changes: 0 additions & 160 deletions llvm/lib/SYCLLowerIR/SYCLOptimizeBackToBackBarrier.cpp

This file was deleted.

Loading
Loading