Skip to content

[SYCL] Improve the error mechanism of llvm-no-spir-kernel #1068

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

Merged
merged 3 commits into from
Feb 19, 2020
Merged
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
11 changes: 11 additions & 0 deletions llvm/test/tools/llvm-no-spir-kernel/error-code.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; UNSUPPORTED: system-windows

; Check the return code
; RUN: llvm-no-spir-kernel %s; \
; RUN: if [ $? = 1 ]; then exit 0; else exit 1; fi

; expected failure
define spir_kernel void @foo() {
bb:
ret void
}
14 changes: 10 additions & 4 deletions llvm/test/tools/llvm-no-spir-kernel/has-spir-kernel.ll
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
; RUN: not llvm-no-spir-kernel %s
; RUN: not llvm-no-spir-kernel %s 2>&1 | FileCheck %s

; expected failure
define spir_kernel void @foo() {
; expected no failures
define void @foo() {
bb:
ret void
}


; expected failure
; CHECK: error: Unexpected SPIR kernel occurrence:
; CHECK-SAME: foo2
define spir_kernel void @foo2() {
bb:
ret void
}
14 changes: 0 additions & 14 deletions llvm/test/tools/llvm-no-spir-kernel/has-spir-kernel2.ll

This file was deleted.

2 changes: 2 additions & 0 deletions llvm/test/tools/llvm-no-spir-kernel/invalid-input.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; RUN: echo garbage > garbage.ll
; RUN: not llvm-no-spir-kernel garbage.ll
21 changes: 16 additions & 5 deletions llvm/tools/llvm-no-spir-kernel/llvm-no-spir-kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
//
//===----------------------------------------------------------------------===//
//
// This utility checks if the input module contains functions that is a spir
// kernel. Return 0 if no, return 1 if yes. Use of an output file is not
// required for a successful check. It is used to allow for proper input and
// output flow within the driver toolchain.
// This utility checks if the input module contains functions that are a SPIR
// kernel.
//
// - Return 0 if the LLVM module is "clean" from SPIR kernels
// - Return 1 upon the first SPIR kernel occurence
//
// Use of an output file is not required for a successful check. It is used
// to allow for proper input and output flow within the driver toolchain.
//
// Usage: llvm-no-spir-kernel input.bc/input.ll -o output.bc/output.ll
//
//===----------------------------------------------------------------------===//

#include "llvm/Demangle/Demangle.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
Expand Down Expand Up @@ -44,15 +49,21 @@ int main(int argc, char **argv) {

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

if (!M.get()) {
Err.print(argv[0], errs());
Err.print(ProgramName, errs());
return 1;
}

for (auto &F : *M) {
if (F.getCallingConv() == CallingConv::SPIR_KERNEL) {
std::string SPIRKernelMsg =
"Unexpected SPIR kernel occurrence: " + demangle(F.getName().str());
SMDiagnostic SPIRKernelDiag(InputFilename, SourceMgr::DiagKind::DK_Error,
SPIRKernelMsg);
SPIRKernelDiag.print(ProgramName, errs());
return 1;
}
}
Expand Down