Skip to content

Commit 21b4a94

Browse files
committed
Review comments
1 parent e45aad4 commit 21b4a94

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include "llvm/Passes/PassPlugin.h"
4848
#include "llvm/Passes/StandardInstrumentations.h"
4949
#include "llvm/ProfileData/InstrProfCorrelator.h"
50-
#include "llvm/SYCLLowerIR/CheckNDRangeSYCLNativeCPU.h"
5150
#include "llvm/SYCLLowerIR/CleanupSYCLMetadata.h"
5251
#include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h"
5352
#include "llvm/SYCLLowerIR/ESIMD/ESIMDVerifier.h"
@@ -1166,11 +1165,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
11661165
if (LangOpts.EnableDAEInSpirKernels)
11671166
MPM.addPass(DeadArgumentEliminationSYCLPass());
11681167

1169-
// We have to schedule the pass here because the native cpu pipeline
1170-
// is ran as part of a separate clang invocation, but we want the information
1171-
// in sycl-post-link.
11721168
if (LangOpts.SYCLIsNativeCPU)
1173-
MPM.addPass(CheckNDRangeSYCLNativeCPUPass());
1169+
llvm::sycl::utils::addSYCLNativeCPUEarlyPasses(MPM);
11741170
// Rerun aspect propagation without warning diagnostics.
11751171
MPM.addPass(
11761172
SYCLPropagateAspectsUsagePass(/*FP64ConvEmu=*/CodeGenOpts.FP64ConvEmu,

clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ class BinaryWrapper {
713713
"__sycl_native_cpu_decls");
714714
auto *EntriesBegin = ConstantExpr::getGetElementPtr(GVar->getValueType(), GVar,
715715
getSizetConstPair(0u, 0u));
716+
717+
// Add Native CPU specific properties to the nativecpu_program struct
716718
Constant *PropValue = NullPtr;
717719
if (NativeCPUProps.has_value()) {
718720
auto PropsOrErr = addSYCLPropertySetToModule(*NativeCPUProps);
@@ -724,6 +726,11 @@ class BinaryWrapper {
724726
auto T = addStructArrayToModule({S}, getSyclPropSetTy());
725727
PropValue = T.first;
726728
}
729+
730+
// Create the nativecpu_program struct.
731+
// We add it to a ConstantArray of length 1 because the SYCL runtime expects a
732+
// non-zero sized binary image, and this allows it to point the end of the binary
733+
// image to the end of the array.
727734
auto *Program = ConstantStruct::get(NCPUProgramT, {EntriesBegin, PropValue});
728735
ArrayType *ProgramATy = ArrayType::get(NCPUProgramT, 1);
729736
Constant *CPA = ConstantArray::get(ProgramATy, {Program});

llvm/include/llvm/SYCLLowerIR/UtilsSYCLNativeCPU.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111
//===----------------------------------------------------------------------===//
1212
#pragma once
1313
#include "llvm/ADT/Twine.h"
14+
#include "llvm/IR/Module.h"
1415
#include "llvm/IR/PassManager.h"
1516
#include "llvm/Passes/OptimizationLevel.h"
1617

1718
namespace llvm {
1819
namespace sycl {
1920
namespace utils {
2021

22+
23+
// Used to schedule passes in the device compiler cc1 invocation for
24+
// Native CPU.
25+
void addSYCLNativeCPUEarlyPasses(ModulePassManager &MPM);
26+
2127
void addSYCLNativeCPUBackendPasses(ModulePassManager &MPM,
2228
ModuleAnalysisManager &MAM,
2329
OptimizationLevel OptLevel);

llvm/lib/SYCLNativeCPUUtils/CheckNDRangeSYCLNativeCPU.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===------ PrepareSYCLNativeCPU.cpp - SYCL Native CPU Preparation Pass ---===//
1+
//- CheckNDRangeSYCLNativeCPU.cpp - Check if a kernel uses nd_range features -//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -23,10 +23,19 @@
2323

2424
using namespace llvm;
2525

26-
// TODO: add other bts
27-
static std::array<const char *, 5> ndFunctions{
28-
"_Z23__spirv_WorkgroupSize_xv", "_Z23__spirv_NumWorkgroups_xv",
29-
"_Z21__spirv_WorkgroupId_xv", "_Z27__spirv_LocalInvocationId_xv",
26+
static std::array<const char *, 13> NdFunctions{
27+
"_Z23__spirv_WorkgroupSize_xv",
28+
"_Z23__spirv_WorkgroupSize_yv",
29+
"_Z23__spirv_WorkgroupSize_zv",
30+
"_Z23__spirv_NumWorkgroups_xv",
31+
"_Z23__spirv_NumWorkgroups_yv",
32+
"_Z23__spirv_NumWorkgroups_zv",
33+
"_Z21__spirv_WorkgroupId_xv",
34+
"_Z21__spirv_WorkgroupId_yv",
35+
"_Z21__spirv_WorkgroupId_zv",
36+
"_Z27__spirv_LocalInvocationId_xv",
37+
"_Z27__spirv_LocalInvocationId_yv",
38+
"_Z27__spirv_LocalInvocationId_zv",
3039
"_Z22__spirv_ControlBarrierjjj"};
3140

3241
static void addNDRangeMetadata(Function &F, bool Value) {
@@ -56,8 +65,8 @@ CheckNDRangeSYCLNativeCPUPass::run(Module &M, ModuleAnalysisManager &MAM) {
5665
for (auto &I : BB) {
5766
if (auto CI = dyn_cast<CallInst>(&I)) {
5867
auto CalleeName = CI->getCalledFunction()->getName();
59-
if (std::find(ndFunctions.begin(), ndFunctions.end(), CalleeName) !=
60-
ndFunctions.end()) {
68+
if (std::find(NdFunctions.begin(), NdFunctions.end(), CalleeName) !=
69+
NdFunctions.end()) {
6170
IsNDRange = true;
6271
break;
6372
}

llvm/lib/SYCLNativeCPUUtils/PipelineSYCLNativeCPU.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,7 @@ void llvm::sycl::utils::addSYCLNativeCPUBackendPasses(
131131
MPM.addPass(DumpIR());
132132
}
133133
}
134+
135+
void llvm::sycl::utils::addSYCLNativeCPUEarlyPasses(ModulePassManager &MPM) {
136+
MPM.addPass(CheckNDRangeSYCLNativeCPUPass());
137+
}

0 commit comments

Comments
 (0)