|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 | //
|
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. |
13 | 17 | //
|
14 | 18 | // Usage: llvm-no-spir-kernel input.bc/input.ll -o output.bc/output.ll
|
15 | 19 | //
|
16 | 20 | //===----------------------------------------------------------------------===//
|
17 | 21 |
|
| 22 | +#include "llvm/Demangle/Demangle.h" |
18 | 23 | #include "llvm/IR/LLVMContext.h"
|
19 | 24 | #include "llvm/IR/Module.h"
|
20 | 25 | #include "llvm/IRReader/IRReader.h"
|
@@ -44,15 +49,21 @@ int main(int argc, char **argv) {
|
44 | 49 |
|
45 | 50 | // Use lazy loading, since we only care about function calling convention
|
46 | 51 | SMDiagnostic Err;
|
| 52 | + const char *ProgramName = llvm::sys::path::filename(argv[0]).data(); |
47 | 53 | std::unique_ptr<Module> M = getLazyIRFileModule(InputFilename, Err, Context);
|
48 | 54 |
|
49 | 55 | if (!M.get()) {
|
50 |
| - Err.print(argv[0], errs()); |
| 56 | + Err.print(ProgramName, errs()); |
51 | 57 | return 1;
|
52 | 58 | }
|
53 | 59 |
|
54 | 60 | for (auto &F : *M) {
|
55 | 61 | 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()); |
56 | 67 | return 1;
|
57 | 68 | }
|
58 | 69 | }
|
|
0 commit comments