Skip to content

[WIP][SYCL] Make sycl-post-link process split modules sequentially, simplify. #5001

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions llvm/include/llvm/Support/SimpleTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class SimpleTable {

public:
SimpleTable() = default;
SimpleTable(ArrayRef<StringRef> ColNames);
static Expected<UPtrTy> create(ArrayRef<StringRef> ColNames);
static Expected<UPtrTy> create(int NColumns);
int getNumColumns() const { return static_cast<int>(ColumnNames.size()); }
Expand Down
26 changes: 15 additions & 11 deletions llvm/lib/SYCLLowerIR/LowerESIMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace id = itanium_demangle;

namespace {
SmallPtrSet<Type *, 4> collectGenXVolatileTypes(Module &);
void generateKernelMetadata(Module &);
bool generateKernelMetadata(Module &);

class SYCLLowerESIMDLegacyPass : public ModulePass {
public:
Expand Down Expand Up @@ -85,6 +85,7 @@ static constexpr char ESIMD_INTRIN_PREF1[] = "__esimd_";
static constexpr char SPIRV_INTRIN_PREF[] = "__spirv_BuiltIn";

static constexpr char GENX_KERNEL_METADATA[] = "genx.kernels";
constexpr char ESIMD_MARKER_MD[] = "sycl_explicit_simd";

struct ESIMDIntrinDesc {
// Denotes argument translation rule kind.
Expand Down Expand Up @@ -1275,9 +1276,9 @@ static std::string getMDString(MDNode *N, unsigned I) {
return "";
}

void generateKernelMetadata(Module &M) {
bool generateKernelMetadata(Module &M) {
if (M.getNamedMetadata(GENX_KERNEL_METADATA))
return;
return false;

auto Kernels = M.getOrInsertNamedMetadata(GENX_KERNEL_METADATA);
assert(Kernels->getNumOperands() == 0 && "metadata out of sync");
Expand All @@ -1293,12 +1294,14 @@ void generateKernelMetadata(Module &M) {

enum { AK_NORMAL, AK_SAMPLER, AK_SURFACE, AK_VME };
enum { IK_NORMAL, IK_INPUT, IK_OUTPUT, IK_INPUT_OUTPUT };
bool Modified = false;

for (auto &F : M.functions()) {
// Skip non-SIMD kernels.
if (F.getCallingConv() != CallingConv::SPIR_KERNEL ||
F.getMetadata("sycl_explicit_simd") == nullptr)
F.getMetadata(ESIMD_MARKER_MD) == nullptr)
continue;
Modified = true;

// Metadata node containing N i32s, where N is the number of kernel
// arguments, and each i32 is the kind of argument, one of:
Expand Down Expand Up @@ -1379,6 +1382,7 @@ void generateKernelMetadata(Module &M) {
F.addFnAttr("oclrt", "1");
F.addFnAttr("CMGenxMain");
}
return Modified;
}

// collect all the vector-types that are used by genx-volatiles
Expand Down Expand Up @@ -1415,17 +1419,17 @@ SmallPtrSet<Type *, 4> collectGenXVolatileTypes(Module &M) {
} // namespace

PreservedAnalyses SYCLLowerESIMDPass::run(Module &M, ModuleAnalysisManager &) {
generateKernelMetadata(M);
bool Modified = generateKernelMetadata(M);
SmallPtrSet<Type *, 4> GVTS = collectGenXVolatileTypes(M);

size_t AmountOfESIMDIntrCalls = 0;
size_t NChanges = 0;
for (auto &F : M.functions()) {
AmountOfESIMDIntrCalls += this->runOnFunction(F, GVTS);
NChanges += this->runOnFunction(F, GVTS);
}

Modified |= NChanges > 0;
// TODO FIXME ESIMD figure out less conservative result
return AmountOfESIMDIntrCalls > 0 ? PreservedAnalyses::none()
: PreservedAnalyses::all();
return Modified ? PreservedAnalyses::none()
: PreservedAnalyses::all();
}

size_t SYCLLowerESIMDPass::runOnFunction(Function &F,
Expand Down Expand Up @@ -1565,5 +1569,5 @@ size_t SYCLLowerESIMDPass::runOnFunction(Function &F,
CI->eraseFromParent();
}

return ESIMDIntrCalls.size();
return ToErase.size();
}
9 changes: 9 additions & 0 deletions llvm/lib/Support/SimpleTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ StringRef SimpleTable::Row::getCell(StringRef ColName,
return (I >= 0) ? Cells[I] : DefaultVal;
}

SimpleTable::SimpleTable(ArrayRef<StringRef> ColNames) {
for (auto N : ColNames)
if (Error Err = addColumnName(N)) {
constexpr char Msg[] = "SimpleTable::SimpleTable internal error";
assert(false && Msg);
throw Msg;
}
}

Expected<SimpleTable::UPtrTy>
SimpleTable::create(ArrayRef<StringRef> ColNames) {
auto Res = std::make_unique<SimpleTable>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ define dso_local spir_kernel void @KERNEL_CCC() {
; CHECK-PROP1: SpecConst=2|
; CHECK-PROP1-NOT: SpecConst2
;
; CHECK-PROP2: [SYCL/specialization constants]
; CHECK-PROP2: [SYCL/specialization constants default values]
; There are no specialization constants in module 2 (created for KERNEL_CCC):
; CHECK-PROP2-NOT: [SYCL/specialization constants]
; CHECK-PROP2-NOT: [SYCL/specialization constants default values]
Comment on lines +59 to +60
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
; CHECK-PROP2-NOT: [SYCL/specialization constants]
; CHECK-PROP2-NOT: [SYCL/specialization constants default values]
; CHECK-PROP2-NOT: [SYCL/specialization constants

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
; RUN: sycl-post-link -split-esimd -split=kernel -S %s -o %t.table
; RUN: FileCheck %s -input-file=%t.table
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-SYCL-IR-0
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-SYCL-IR-1
; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-ESIMD-IR-0
; RUN: FileCheck %s -input-file=%t_esimd_1.ll --check-prefixes CHECK-ESIMD-IR-1
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefixes CHECK-SYCL-IR-0
; RUN: FileCheck %s -input-file=%t_3.ll --check-prefixes CHECK-SYCL-IR-1

; This test checks that after we split SYCL and ESIMD kernels into
; separate modules, we split those two modules further according to
Expand Down Expand Up @@ -52,10 +52,10 @@ attributes #1 = { "sycl-module-id"="a.cpp" }
!3 = !{}

; CHECK: [Code|Properties]
; CHECK: {{.*}}_0.ll|{{.*}}_0.prop
; CHECK: {{.*}}_1.ll|{{.*}}_1.prop
; CHECK: {{.*}}_esimd_0.ll|{{.*}}_esimd_0.prop
; CHECK: {{.*}}_esimd_1.ll|{{.*}}_esimd_1.prop
; CHECK: {{.*}}_2.ll|{{.*}}_2.prop
; CHECK: {{.*}}_3.ll|{{.*}}_3.prop

; CHECK-SYCL-IR-0-DAG: define dso_local spir_kernel void @SYCL_kernel1()
; CHECK-SYCL-IR-0-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
Expand Down
Loading