Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
20 changes: 20 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4684,6 +4684,14 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {

for (const KernelDesc &K : KernelDescs) {
const size_t N = K.Params.size();
PresumedLoc PLoc = S.Context.getSourceManager().getPresumedLoc(
S.Context.getSourceManager()
.getExpansionRange(K.KernelLocation)
.getEnd());
std::string FileName = PLoc.getFilename();
Comment thread
schittir marked this conversation as resolved.
Outdated
unsigned LineNumber = PLoc.getLine();
unsigned ColumnNumber = PLoc.getColumn();
std::string KernelName = K.NameType->getAsCXXRecordDecl()->getName().str();
if (K.IsUnnamedKernel) {
O << "template <> struct KernelInfoData<";
OutputStableNameInChars(O, K.StableName);
Expand All @@ -4707,6 +4715,18 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
O << " __SYCL_DLL_LOCAL\n";
O << " static constexpr bool isESIMD() { return " << K.IsESIMDKernel
<< "; }\n";
O << " __SYCL_DLL_LOCAL\n";
O << " static constexpr const char* getFileName() { return " << FileName
<< "; }\n";
O << " __SYCL_DLL_LOCAL\n";
O << " static constexpr const char* getFunctionName() { return "
<< KernelName << "; }\n";
O << " __SYCL_DLL_LOCAL\n";
O << " static constexpr unsigned getLineNumber() { return " << LineNumber
<< "; }\n";
O << " __SYCL_DLL_LOCAL\n";
O << " static constexpr unsigned getColumnNumber() { return "
<< ColumnNumber << "; }\n";
O << "};\n";
CurStart += N;
}
Expand Down
24 changes: 24 additions & 0 deletions clang/test/CodeGenSYCL/code_location.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem -sycl-std=2020 -fsycl-int-header=%t.h %s -o %t.out
// RUN: FileCheck -input-file=%t.h %s

Comment thread
schittir marked this conversation as resolved.
#include "Inputs/sycl.hpp"

int main() {
cl::sycl::queue q;
q.submit([&](cl::sycl::handler &h) { h.single_task([] {}); });
q.submit([&](cl::sycl::handler &h) { h.single_task<class KernelName>([]() {}); });
Comment thread
schittir marked this conversation as resolved.
return 0;
}

// CHECK: template <> struct KernelInfoData<'_', 'Z', 'T', 'S', 'Z', 'Z', '4', 'm', 'a', 'i', 'n', 'E', 'N', 'K', 'U', 'l', 'R', 'N', '2', 'c', 'l', '4', 's', 'y', 'c', 'l', '7', 'h', 'a', 'n', 'd', 'l', 'e', 'r', 'E', 'E', '_', 'c', 'l', 'E', 'S', '2', '_', 'E', 'U', 'l', 'v', 'E', '_'> {
// CHECK: static constexpr const char* getFileName() { return {{.*}}/clang/test/CodeGenSYCL/code_location.cpp; }
Comment thread
schittir marked this conversation as resolved.
Outdated
// CHECK: static constexpr const char* getFunctionName() { return ; }
Comment thread
schittir marked this conversation as resolved.
Outdated
// CHECK: static constexpr unsigned getLineNumber() { return 8; }
// CHECK: static constexpr unsigned getColumnNumber() { return 54; }
//};
// CHECK: template <> struct KernelInfo<KernelName> {
// CHECK: static constexpr const char* getFileName() { return {{.*}}/clang/test/CodeGenSYCL/code_location.cpp; }
// CHECK: static constexpr const char* getFunctionName() { return KernelName; }
Comment thread
schittir marked this conversation as resolved.
Outdated
// CHECK: static constexpr unsigned getLineNumber() { return 9; }
// CHECK: static constexpr unsigned getColumnNumber() { return 72; }
//};
18 changes: 18 additions & 0 deletions sycl/include/CL/sycl/detail/kernel_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ template <class KernelNameType> struct KernelInfo {
}
static constexpr const char *getName() { return ""; }
static constexpr bool isESIMD() { return 0; }
#ifndef NDEBUG
static constexpr const char *getFileName() { return ""; }
static constexpr const char *getFunctionName() { return ""; }
static constexpr unsigned getLineNumber() { return 0; }
static constexpr unsigned getColumnNumber() { return 0; }
#endif
};
#else
template <char...> struct KernelInfoData {
Expand All @@ -85,6 +91,12 @@ template <char...> struct KernelInfoData {
}
static constexpr const char *getName() { return ""; }
static constexpr bool isESIMD() { return 0; }
#ifndef NDEBUG
static constexpr const char *getFileName() { return ""; }
static constexpr const char *getFunctionName() { return ""; }
static constexpr unsigned getLineNumber() { return 0; }
static constexpr unsigned getColumnNumber() { return 0; }
#endif
};

// C++14 like index_sequence and make_index_sequence
Expand Down Expand Up @@ -123,6 +135,12 @@ template <class KernelNameType> struct KernelInfo {
}
static constexpr const char *getName() { return SubKernelInfo::getName(); }
static constexpr bool isESIMD() { return SubKernelInfo::isESIMD(); }
#ifndef NDEBUG
static constexpr const char *getFileName() { return ""; }
static constexpr const char *getFunctionName() { return ""; }
static constexpr unsigned getLineNumber() { return 0; }
static constexpr unsigned getColumnNumber() { return 0; }
#endif
};
#endif //__SYCL_UNNAMED_LAMBDA__

Expand Down