Skip to content

[SYCL] Add SYCLPropagateAspectUsage Pass #5348

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 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a94f4e3
[SYCL] Add SYCLPropagateAspectUsage Pass
maksimsab Jan 20, 2022
58479f6
remove trash output.ll
maksimsab Jan 20, 2022
59c12ed
add support for double
maksimsab Jan 20, 2022
bfadc0b
add warning support
maksimsab Jan 21, 2022
40eb790
move PropagateAspectUsage Pass in SYCLLowerIR component
maksimsab Jan 21, 2022
471814e
refactor code
maksimsab Jan 21, 2022
1973f1b
support complex types graphs. add more tests
maksimsab Jan 26, 2022
02ff770
apply clang-format
maksimsab Jan 26, 2022
427c18d
refactor code
maksimsab Jan 27, 2022
be7e7f2
reformat code
maksimsab Jan 28, 2022
1daf094
reformat code
maksimsab Jan 28, 2022
8163a0e
fix bug and commit corresponding test
maksimsab Jan 28, 2022
5c14699
reformat code
maksimsab Jan 28, 2022
da7d34a
add consts
maksimsab Jan 28, 2022
79147ac
edit tests
maksimsab Jan 31, 2022
83e3e5b
make tests more reliable
maksimsab Jan 31, 2022
931bb7b
add test for unnamed struct
maksimsab Jan 31, 2022
fe05491
fix tests
maksimsab Jan 31, 2022
cd81ba9
add test
maksimsab Feb 1, 2022
8998d89
add comment for fp64 aspect
maksimsab Feb 1, 2022
6214a10
reformat code
maksimsab Feb 1, 2022
65b7d80
add PropagateAspectUsage pass in clang
maksimsab Feb 2, 2022
5f274b8
add PropagateAspectUsagePass for new pass manager
maksimsab Feb 3, 2022
824f9df
reformat code
maksimsab Feb 3, 2022
5ad3b08
add support of call chains and debug information. add corresponding
maksimsab Feb 8, 2022
b6e9526
fix remarks
maksimsab Feb 8, 2022
b6eafb1
fix bug of extensions/inline_asm.cpp
maksimsab Feb 8, 2022
eef814a
Make warnings work with clang FE.
maksimsab Feb 10, 2022
76f6864
fix remarks
maksimsab Feb 11, 2022
e7b7728
remove warning tests from llvm tests. replace require with device_has
maksimsab Feb 11, 2022
d122167
add test cases for arrays and vectors
maksimsab Feb 11, 2022
e4fa2cc
fix aspect_usage.cpp test
maksimsab Feb 11, 2022
d6b1c3f
add aspect id demangling
maksimsab Feb 18, 2022
483ed82
fix failing tests
maksimsab Feb 18, 2022
c11e71d
fix remarks
maksimsab Feb 21, 2022
02225b3
add test for composite types with vectors. fix aspect_usage.cpp test
maksimsab Feb 21, 2022
cdf83fe
fix compile error
maksimsab Feb 21, 2022
3bbc3c2
Merge branch 'sycl' of https://github.com/intel/llvm into new_pass
maksimsab Feb 21, 2022
495e006
fix compile error
maksimsab Feb 21, 2022
4495e00
fix aspect_usage.cpp test
maksimsab Feb 22, 2022
a3c4d28
add demangling for function name
maksimsab Feb 22, 2022
9ffe87a
unify pass names from both PMs
maksimsab Feb 22, 2022
e3fda46
Fix clang-format
AlexeySachkov Mar 16, 2022
7f125d5
Improve diagnostic message
AlexeySachkov Mar 18, 2022
28a3753
Outline aspects enum into separate file to increase readability
AlexeySachkov Mar 18, 2022
8ed6c15
Propagate aspects up to SYCL_EXTERNAL functions also
AlexeySachkov Mar 18, 2022
a4c5443
Apply comments
AlexeySachkov Mar 21, 2022
a963dac
Add Frontend test
AlexeySachkov Mar 21, 2022
ab6eeb2
Merge branch 'sycl' of https://github.com/intel/llvm into HEAD
maksimsab Mar 21, 2022
70bf013
add test checking ESIMD metadata presence
maksimsab Mar 22, 2022
9be4c55
fix linter remark
maksimsab Mar 22, 2022
e9f03d7
allign aspect_usage.cpp test
maksimsab Mar 23, 2022
842247d
fix type
maksimsab Mar 24, 2022
13745b9
fix Frontend/sycl-aspects-usage.cpp test
maksimsab Mar 25, 2022
e28f61a
add considering of opaque pointers
maksimsab Mar 25, 2022
307fe3d
add comment to sycl/include/CL/sycl/aspects.hpp
maksimsab Mar 29, 2022
38d2041
add few cases in sycl-aspects-usage test
maksimsab Mar 30, 2022
c5fa2de
add check with several aspects in sycl-aspects-usage test
maksimsab Mar 30, 2022
b491190
clafiry sycl-aspects-usage test
maksimsab Mar 30, 2022
cf668e9
fix checkSeveralAspects test
maksimsab Apr 4, 2022
bf7134a
add checkEmptyDeviceHas2 test in sycl-aspects-usage test
maksimsab Apr 5, 2022
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
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/DiagnosticFrontendKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,11 @@ def warn_profile_data_unprofiled : Warning<
InGroup<ProfileInstrUnprofiled>;
} // end of instrumentation issue category

def warn_sycl_wrong_aspect_usage : Warning<
"function '%0' uses aspect '%1' not listed in 'sycl::device_has()'">,
InGroup<DiagGroup<"sycl-aspect-usage">>;
def note_sycl_wrong_aspect_usage : Note<
"%select{the actual use is in|which is called by}0 "
"%1%select{|, compile with '-g' to get source location}2">;

}
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "llvm/SYCLLowerIR/ESIMD/ESIMDVerifier.h"
#include "llvm/SYCLLowerIR/LowerWGLocalMemory.h"
#include "llvm/SYCLLowerIR/MutatePrintfAddrspace.h"
#include "llvm/SYCLLowerIR/PropagateAspectUsage.h"
#include "llvm/Support/BuryPointer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MemoryBuffer.h"
Expand Down Expand Up @@ -1024,6 +1025,9 @@ void EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager(
PerFunctionPasses.add(
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));

if (LangOpts.SYCLIsDevice)
PerModulePasses.add(createPropagateAspectUsagePass());

CreatePasses(PerModulePasses, PerFunctionPasses);

// Add a verifier pass if requested. We don't have to do this if the action
Expand Down Expand Up @@ -1382,6 +1386,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(

ModulePassManager MPM;

if (CodeGenOpts.DisableLLVMPasses && LangOpts.SYCLIsDevice)
MPM.addPass(PropagateAspectUsagePass());

if (!CodeGenOpts.DisableLLVMPasses) {
// Map our optimization levels into one of the distinct levels used to
// configure the pipeline.
Expand All @@ -1391,6 +1398,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
PB.registerPipelineStartEPCallback(
[](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(ESIMDVerifierPass());
MPM.addPass(PropagateAspectUsagePass());
});

bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
Expand Down
25 changes: 25 additions & 0 deletions clang/lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ namespace clang {
void OptimizationFailureHandler(
const llvm::DiagnosticInfoOptimizationFailure &D);
void DontCallDiagHandler(const DiagnosticInfoDontCall &D);
void SYCLWarningDiagHandler(const DiagnosticInfoSYCLUnspecAspect &D);
};

void BackendConsumer::anchor() {}
Expand Down Expand Up @@ -825,6 +826,27 @@ void BackendConsumer::DontCallDiagHandler(const DiagnosticInfoDontCall &D) {
<< llvm::demangle(D.getFunctionName().str()) << D.getNote();
}

void BackendConsumer::SYCLWarningDiagHandler(
const DiagnosticInfoSYCLUnspecAspect &D) {
// FIXME: instead of querying source location from debug info, we should
// re-use existing mechanism with srcloc metadata, see D106030, D110364.
SourceLocation Loc;
Diags.Report(Loc, diag::warn_sycl_wrong_aspect_usage)
Comment on lines +833 to +834
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it uses invalid source location, so the warning won't point to real code. Maybe we can try to construct valid source info at least when we have debug info? Seems like DontCallDiagHandler defined above at least tries something like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good idea and it seems like that is a better approach than we have right now. However, DontCallDiagHandler relies on source location emitted into LLVM IR by FE in form of srcloc metadata: D106030, D110364.

Amount of the changes in this PR is already huge, would it be acceptable to postpone this diagnostic improvement till the next PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Amount of the changes in this PR is already huge, would it be acceptable to postpone this diagnostic improvement till the next PR?

I think it is ok to postpone. Please file a tracker if you're not going to work on it ASAP.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm less certain it's okay to postpone as this means all diagnostics will show up in very wrong places (if at all) within an IDE, for example. I don't think the user experience is all that great when the diagnostic is a warning that's divorced from their code.

Note: losing source location information and providing a poor user experience with diagnostics is why very few diagnostics ever come from the backend. It's too easy to lose the source locations, especially when optimizer passes get involved. That's why the majority of backend diagnostics are in the form of remarks instead of warnings (let alone errors). We should be very careful about the user experience here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm less certain it's okay to postpone as this means all diagnostics will show up in very wrong places (if at all) within an IDE, for example. I don't think the user experience is all that great when the diagnostic is a warning that's divorced from their code.

Note that we are in the very beginning of our optional kernel features implementation journey and even if user properly sets all the attributes, the code won't work as expected, because we are missing a lot of changes in other components. Therefore, I think that it should be ok not to complicate this PR even more, but still refactor diagnostics before we mark the whole feature as completed.

Note: losing source location information and providing a poor user experience with diagnostics is why very few diagnostics ever come from the backend. It's too easy to lose the source locations, especially when optimizer passes get involved. That's why the majority of backend diagnostics are in the form of remarks instead of warnings (let alone errors). We should be very careful about the user experience here.

That pass is supposed to be launched before all other passes or otherwise not only source locations will be lost, but also some semantics, i.e. we can lose information about declared aspects due to inlining.

Copy link
Contributor

Choose a reason for hiding this comment

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

Therefore, I think that it should be ok not to complicate this PR even more, but still refactor diagnostics before we mark the whole feature as completed.

I'm ok with this approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've created #5877 to track this further improvement

<< D.getFunctionName() << D.getAspect();

if (!D.getCallChain().empty()) {
Diags.Report(Loc, diag::note_sycl_wrong_aspect_usage)
<< /* the actual use */ 0 << D.getCallChain().back()
<< !D.isFullDebugMode();

for (auto I = ++D.getCallChain().rbegin(), E = D.getCallChain().rend();
I != E; ++I) {
Diags.Report(Loc, diag::note_sycl_wrong_aspect_usage)
Comment on lines +838 to +844
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't both of these notes be on a location from the call chain instead of using the invalid source location?

Copy link
Contributor

Choose a reason for hiding this comment

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

So, do I understand it correctly that this will also be applied in the next PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, properly dealing with source location requires more changes and I would prefer not to overcomplicate this PR anymore, I've submitted #5877 to track this further improvement

<< /* called by */ 1 << *I << !D.isFullDebugMode();
}
}
}

/// This function is invoked when the backend needs
/// to report something to the user.
void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
Expand Down Expand Up @@ -899,6 +921,9 @@ void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
case llvm::DK_DontCall:
DontCallDiagHandler(cast<DiagnosticInfoDontCall>(DI));
return;
case llvm::DK_SYCLWarning:
SYCLWarningDiagHandler(cast<DiagnosticInfoSYCLUnspecAspect>(DI));
return;
default:
// Plugin IDs are not bound to any value as they are set dynamically.
ComputeDiagRemarkID(Severity, backend_plugin, DiagID);
Expand Down
20 changes: 20 additions & 0 deletions clang/test/CodeGenSYCL/aspect_usage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Checks that Propagate aspect usage Pass is run for SYCL device target.
//
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown %s -flegacy-pass-manager -mllvm -debug-pass=Structure -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-SYCL1
// CHECK-SYCL1: Propagate aspect usage
//
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown %s -flegacy-pass-manager -fno-sycl-early-optimizations -mllvm -debug-pass=Structure -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-SYCL2
// CHECK-SYCL2: Propagate aspect usage
//
// RUN: %clang_cc1 %s -flegacy-pass-manager -mllvm -debug-pass=Structure -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SYCL1
// CHECK-NOT-SYCL1-NOT: Propagate aspect usage
//
//
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown %s -fno-legacy-pass-manager -mdebug-pass Structure -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-NEWPM-SYCL1
// CHECK-NEWPM-SYCL1: PropagateAspectUsagePass
//
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown %s -fno-legacy-pass-manager -fno-sycl-early-optimizations -mdebug-pass Structure -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-NEWPM-SYCL2
// CHECK-NEWPM-SYCL2: PropagateAspectUsagePass
//
// RUN: %clang_cc1 %s -fno-legacy-pass-manager -mdebug-pass Structure -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-NEWPM-NOT-SYCL
// CHECK-NEWPM-NOT-SYCL-NOT: PropagateAspectUsagePass
17 changes: 9 additions & 8 deletions clang/test/CodeGenSYCL/uses_aspects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ template <cl::sycl::aspect Aspect>
void func5() {}

[[__sycl_detail__::__uses_aspects__(cl::sycl::aspect::cpu)]] void func6();
// CHECK: define dso_local spir_func void @{{.*}}func6{{.*}} !intel_used_aspects ![[ASPECTS1]] {
// CHECK: define dso_local spir_func void @{{.*}}func6{{.*}} !intel_used_aspects ![[ASPECTS4:[0-9]+]] {
void func6() {
Type1WithAspect TestObj1;
Type2WithAspect TestObj2;
Expand Down Expand Up @@ -57,10 +57,11 @@ void foo() {
h.single_task<class kernel_name_1>(f1);
});
}
// CHECK: !intel_types_that_use_aspects = !{![[TYPE1:[0-9]+]], ![[TYPE2:[0-9]+]]}
// CHECK: [[TYPE1]] = !{!"class.Type1WithAspect", i32 1}
// CHECK: [[TYPE2]] = !{!"class.Type2WithAspect", i32 5, i32 1}
// CHECK: [[EMPTYASPECTS]] = !{}
// CHECK: [[ASPECTS1]] = !{i32 1}
// CHECK: [[ASPECTS2]] = !{i32 5, i32 2}
// CHECK: [[ASPECTS3]] = !{i32 0}
// CHECK-DAG: !intel_types_that_use_aspects = !{![[TYPE1:[0-9]+]], ![[TYPE2:[0-9]+]]}
// CHECK-DAG: [[TYPE1]] = !{!"class.Type1WithAspect", i32 1}
// CHECK-DAG: [[TYPE2]] = !{!"class.Type2WithAspect", i32 5, i32 1}
// CHECK-DAG: [[EMPTYASPECTS]] = !{}
// CHECK-DAG: [[ASPECTS1]] = !{i32 1}
// CHECK-DAG: [[ASPECTS2]] = !{i32 5, i32 2}
// CHECK-DAG: [[ASPECTS3]] = !{i32 0}
// CHECK-DAG: [[ASPECTS4]] = !{i32 1, i32 5}
68 changes: 68 additions & 0 deletions clang/test/Frontend/Inputs/sycl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once

#define ATTR_SYCL_KERNEL __attribute__((sycl_kernel))

inline namespace cl {
namespace sycl {

// Dummy aspect enum with limited enumerators
enum class aspect {
host = 0,
cpu = 1,
gpu = 2,
accelerator = 3,
custom = 4,
fp16 = 5,
fp64 = 6,
};

class kernel {};
class context {};
class device {};
class event {};

class queue {
public:
template <typename T>
event submit(T cgf) { return event{}; }

void wait() {}
void wait_and_throw() {}
void throw_asynchronous() {}
};

class auto_name {};
template <typename Name, typename Type>
struct get_kernel_name_t {
using name = Name;
};
template <typename Type>
struct get_kernel_name_t<auto_name, Type> {
using name = Type;
};

class kernel_handler {
void __init_specialization_constants_buffer(char *specialization_constants_buffer) {}
};

#define ATTR_SYCL_KERNEL __attribute__((sycl_kernel))
template <typename KernelName, typename KernelType>
ATTR_SYCL_KERNEL void kernel_single_task(const KernelType &kernelFunc) { // #KernelSingleTask
kernelFunc();
}

class handler {
public:
template <typename KernelName = auto_name, typename KernelType>
void single_task(const KernelType &kernelFunc) {
using NameT = typename get_kernel_name_t<KernelName, KernelType>::name;
#ifdef __SYCL_DEVICE_ONLY__
kernel_single_task<NameT>(kernelFunc);
#else
kernelFunc();
#endif
}
};

} // namespace sycl
} // namespace cl
107 changes: 107 additions & 0 deletions clang/test/Frontend/sycl-aspects-usage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Test checks Propagate Aspect Usage pass.

// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-WARNINGS

// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown %s -debug-info-kind=constructor -dwarf-version=5 -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-WARNINGS-DBG -DPATH=%s

// CHECK-WARNINGS: warning: function 'checkStructUsesAspect(int)' uses aspect 'fp16' not listed in 'sycl::device_has()'
// CHECK-WARNINGS-NEXT: note: the actual use is in funcWithStruct(int), compile with '-g' to get source location
// CHECK-WARNINGS-NEXT: note: which is called by checkStructUsesAspect(int), compile with '-g' to get source location
//
// CHECK-WARNINGS-DBG: warning: function 'checkStructUsesAspect(int)' uses aspect 'fp16' not listed in 'sycl::device_has()'
// CHECK-WARNINGS-DBG-NEXT: note: the actual use is in funcWithStruct(int) at [[PATH]]:27:5
// CHECK-WARNINGS-DBG-NEXT: note: which is called by checkStructUsesAspect(int) at [[PATH]]:32:10

#include "Inputs/sycl.hpp"

using namespace cl::sycl;

class KernelName;

struct [[__sycl_detail__::__uses_aspects__(aspect::fp16)]] Struct {
int a = 0;
};

int funcWithStruct(int) {
Struct s;
s.a = 1;
return s.a;
}

[[sycl::device_has(aspect::fp64)]] int checkStructUsesAspect(int) {
return funcWithStruct(1);
}

// Check that empty device_has() emits a warning.
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-EMPTY
// CHECK-EMPTY: warning: function 'checkEmptyDeviceHas()' uses aspect 'fp16' not listed in 'sycl::device_has()'
[[sycl::device_has()]] int checkEmptyDeviceHas() {
return funcWithStruct(1);
}

[[sycl::device_has(aspect::fp16)]] int func2() {
return funcWithStruct(1);
}

// Check that empty device_has() emits a warning despite the fact
// that invoked function's device_has() attribute is conformant
// with actual usage.
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-EMPTY2
// CHECK-EMPTY2: warning: function 'checkEmptyDeviceHas()' uses aspect 'fp16' not listed in 'sycl::device_has()'
[[sycl::device_has()]] int checkEmptyDeviceHas2() {
return func2();
}

// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-DOUBLE
// CHECK-DOUBLE: warning: function 'checkDouble()' uses aspect 'fp64' not listed in 'sycl::device_has()'
// CHECK-DOUBLE-NEXT: note: the actual use is in checkDouble(), compile with '-g' to get source location

[[sycl::device_has(aspect::fp16)]] int checkDouble() {
double d = 123;
// Strange calculations just to prevent AST optimizations
for (int i = 0; i < 10; ++i)
d += d * d;

return d;
}

struct [[__sycl_detail__::__uses_aspects__(aspect::cpu)]] StructWithCpu {
int a = 0;
};

int funcWithSeveralAspects() {
Struct s1;
StructWithCpu s2;
return static_cast<double>(s1.a);
}

// Check that a warning diagnostic works in a case
// when there are several aspects present which conflict
// with declared in device_has().

// Check for fp64 aspect
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-SEVERAL-FP64
// CHECK-SEVERAL-FP64: warning: function 'checkSeveralAspects()' uses aspect 'fp64' not listed in 'sycl::device_has()'
// CHECK-SEVERAL-FP64-NEXT: note: the actual use is in funcWithSeveralAspects(), compile with '-g' to get source location
// CHECK-SEVERAL-FP64-NEXT: note: which is called by checkSeveralAspects(), compile with '-g' to get source location
//
// Check for cpu aspect
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-SEVERAL-CPU
// CHECK-SEVERAL-CPU: warning: function 'checkSeveralAspects()' uses aspect 'cpu' not listed in 'sycl::device_has()'
// CHECK-SEVERAL-CPU-NEXT: note: the actual use is in funcWithSeveralAspects(), compile with '-g' to get source location
// CHECK-SEVERAL-CPU-NEXT: note: which is called by checkSeveralAspects(), compile with '-g' to get source location
[[sycl::device_has(aspect::fp16)]] int checkSeveralAspects() {
return funcWithSeveralAspects();
}

int main() {
queue Q;
Q.submit([&](handler &h) {
h.single_task<KernelName>([=]() {
checkStructUsesAspect(1);
checkEmptyDeviceHas();
checkDouble();
checkSeveralAspects();
});
});
}
32 changes: 32 additions & 0 deletions llvm/include/llvm/IR/DiagnosticInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm-c/Types.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
Expand Down Expand Up @@ -85,6 +86,7 @@ enum DiagnosticKind {
DK_Unsupported,
DK_SrcMgr,
DK_DontCall,
DK_SYCLWarning,
DK_FirstPluginKind // Must be last value to work with
// getNextAvailablePluginDiagnosticKind
};
Expand Down Expand Up @@ -1098,6 +1100,36 @@ class DiagnosticInfoDontCall : public DiagnosticInfo {
}
};

/// Class for emiting warning messages from SYCL PropagateAspectUsage pass
/// about unspecified aspect.
class DiagnosticInfoSYCLUnspecAspect : public DiagnosticInfo {
SmallString<16> FunctionName;
SmallString<5> AspectStr;
SmallVector<std::string, 8> CallChain;
bool IsFullDebugMode = false;

public:
DiagnosticInfoSYCLUnspecAspect(StringRef FunctionName, StringRef AspectStr,
const SmallVector<std::string, 8> &CallChain,
bool IsFullDebugMode)
: DiagnosticInfo(DK_SYCLWarning, DiagnosticSeverity::DS_Warning),
FunctionName(FunctionName), AspectStr(AspectStr),
CallChain(std::move(CallChain)), IsFullDebugMode(IsFullDebugMode) {}

StringRef getFunctionName() const { return FunctionName; }

StringRef getAspect() const { return AspectStr; }

const SmallVector<std::string, 8> &getCallChain() const { return CallChain; }

int isFullDebugMode() const { return IsFullDebugMode; }

void print(DiagnosticPrinter &DP) const override;
static bool classof(const DiagnosticInfo *DI) {
return DI->getKind() == DK_SYCLWarning;
}
};

} // end namespace llvm

#endif // LLVM_IR_DIAGNOSTICINFO_H
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ void initializeESIMDLowerLoadStorePass(PassRegistry &);
void initializeESIMDLowerVecArgLegacyPassPass(PassRegistry &);
void initializeESIMDVerifierPass(PassRegistry &);
void initializeSYCLLowerWGLocalMemoryLegacyPass(PassRegistry &);
void initializeSYCLPropagateAspectUsageLegacyPassPass(PassRegistry &);
void initializeTailCallElimPass(PassRegistry&);
void initializeTailDuplicatePass(PassRegistry&);
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry&);
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/LinkAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/SYCLLowerIR/ESIMD/ESIMDVerifier.h"
#include "llvm/SYCLLowerIR/MutatePrintfAddrspace.h"
#include "llvm/SYCLLowerIR/PropagateAspectUsage.h"
#include "llvm/Support/Valgrind.h"
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
#include "llvm/Transforms/IPO.h"
Expand Down Expand Up @@ -209,6 +210,7 @@ namespace {
(void) llvm::createExpandMemCmpPass();
(void) llvm::createExpandVectorPredicationPass();
(void)llvm::createESIMDVerifierPass();
(void)llvm::createPropagateAspectUsagePass();
std::string buf;
llvm::raw_string_ostream os(buf);
(void) llvm::createPrintModulePass(os);
Expand Down
Loading