Skip to content

Commit 21b1e16

Browse files
author
Artem Gindinson
committed
[SYCL] Improve the error mechanism of llvm-no-spir-kernel
This patch improves the tool's diagnostic upon finding a SPIR kernel within an LLVM module. Despite that the tool's only current use is within the SYCL FPGA flow, it's important to make the message target-agnostic, so that the tool is not tied to a particular device BE. A related commit to the Clang driver has extended these diagnostics with SYCL FPGA specifics without affecting the tool itself. This patch also introduces testing for the return code value. For example, this should allow the Clang driver users/developers to differentiate between the two possible causes of llvm-no-spir-kernel failure. Signed-off-by: Artem Gindinson <[email protected]>
1 parent 360b25b commit 21b1e16

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
; RUN: not llvm-no-spir-kernel %s
1+
; RUN: not llvm-no-spir-kernel %s 2>&1 | FileCheck %s
22

33
; expected failure
4+
; CHECK: error: Unexpected SPIR kernel occurrence: foo
45
define spir_kernel void @foo() {
56
bb:
67
ret void
78
}
89

9-
10+
; Check the return code
11+
; RUN: llvm-no-spir-kernel %s; \
12+
; RUN: if [ $? = 1 ]; then exit 0; else exit 1; fi
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
; RUN: not llvm-no-spir-kernel %s
2-
; expected failure
1+
; RUN: not llvm-no-spir-kernel %s 2>&1 | FileCheck %s
32

3+
; expected no failures
44
define void @foo() {
55
bb:
66
ret void
77
}
88

99
; expected failure
10+
; CHECK: error: Unexpected SPIR kernel occurrence:
11+
; CHECK-SAME: foo2
1012
define spir_kernel void @foo2() {
1113
bb:
1214
ret void
1315
}
1416

17+
; Check the return code
18+
; RUN: llvm-no-spir-kernel %s; \
19+
; RUN: if [ $? = 1 ]; then exit 0; else exit 1; fi
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
; RUN: echo garbage > garbage.ll
2+
; RUN: not llvm-no-spir-kernel garbage.ll

llvm/tools/llvm-no-spir-kernel/llvm-no-spir-kernel.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This utility checks if the input module contains functions that is a spir
10-
// kernel. Return 0 if no, return 1 if yes. Use of an output file is not
11-
// required for a successful check. It is used to allow for proper input and
12-
// output flow within the driver toolchain.
9+
// This utility checks if the input module contains functions that are a SPIR
10+
// kernel.
11+
//
12+
// - Return 0 if the LLVM module is "clean" from SPIR kernels
13+
// - Return 1 upon the first SPIR kernel occurence
14+
//
15+
// Use of an output file is not required for a successful check. It is used
16+
// to allow for proper input and output flow within the driver toolchain.
1317
//
1418
// Usage: llvm-no-spir-kernel input.bc/input.ll -o output.bc/output.ll
1519
//
1620
//===----------------------------------------------------------------------===//
1721

22+
#include "llvm/Demangle/Demangle.h"
1823
#include "llvm/IR/LLVMContext.h"
1924
#include "llvm/IR/Module.h"
2025
#include "llvm/IRReader/IRReader.h"
@@ -44,15 +49,21 @@ int main(int argc, char **argv) {
4449

4550
// Use lazy loading, since we only care about function calling convention
4651
SMDiagnostic Err;
52+
const char *ProgramName = llvm::sys::path::filename(argv[0]).data();
4753
std::unique_ptr<Module> M = getLazyIRFileModule(InputFilename, Err, Context);
4854

4955
if (!M.get()) {
50-
Err.print(argv[0], errs());
56+
Err.print(ProgramName, errs());
5157
return 1;
5258
}
5359

5460
for (auto &F : *M) {
5561
if (F.getCallingConv() == CallingConv::SPIR_KERNEL) {
62+
std::string SPIRKernelMsg =
63+
"Unexpected SPIR kernel occurrence: " + demangle(F.getName().str());
64+
SMDiagnostic SPIRKernelDiag(InputFilename, SourceMgr::DiagKind::DK_Error,
65+
SPIRKernelMsg);
66+
SPIRKernelDiag.print(ProgramName, errs());
5667
return 1;
5768
}
5869
}

0 commit comments

Comments
 (0)