Skip to content

Commit 2295308

Browse files
author
Artem Gindinson
authored
[SYCL] Improve the error mechanism of llvm-no-spir-kernel (#1068)
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 <artem.gindinson@intel.com>
1 parent febf832 commit 2295308

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; UNSUPPORTED: system-windows
2+
3+
; Check the return code
4+
; RUN: llvm-no-spir-kernel %s; \
5+
; RUN: if [ $? = 1 ]; then exit 0; else exit 1; fi
6+
7+
; expected failure
8+
define spir_kernel void @foo() {
9+
bb:
10+
ret void
11+
}
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
; RUN: not llvm-no-spir-kernel %s
1+
; RUN: not llvm-no-spir-kernel %s 2>&1 | FileCheck %s
22

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

9-
9+
; expected failure
10+
; CHECK: error: Unexpected SPIR kernel occurrence:
11+
; CHECK-SAME: foo2
12+
define spir_kernel void @foo2() {
13+
bb:
14+
ret void
15+
}

llvm/test/tools/llvm-no-spir-kernel/has-spir-kernel2.ll

Lines changed: 0 additions & 14 deletions
This file was deleted.
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)