Skip to content

Commit d1fac9d

Browse files
committed
feat(compiler): expose source locations in IR dumps
1 parent 03c0393 commit d1fac9d

5 files changed

Lines changed: 23 additions & 4 deletions

File tree

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ configure_file(
66

77
add_custom_target(check-warpforth
88
COMMAND ${LIT_COMMAND} ${CMAKE_CURRENT_BINARY_DIR} -v
9-
DEPENDS warpforth-translate warpforth-opt
9+
DEPENDS warpforth-translate warpforth-opt warpforthc
1010
COMMENT "Running WarpForth lit tests"
1111
)

test/Conversion/ForthToGPU/invalid-intrinsic.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// RUN: %FileCheck %s < %t.err
33
// RUN: test ! -s %t.out
44

5-
// CHECK: failed to legalize operation 'forth.intrinsic'
5+
// CHECK: invalid-intrinsic.forth:12:7: error: failed to legalize operation 'forth.intrinsic'
66

77
module {
88
func.func private @main() attributes {forth.kernel} {
9-
%0 = forth.intrinsic "unknown" : index
9+
%0 = forth.intrinsic "unknown" : index loc("invalid-intrinsic.forth":12:7)
1010
return
1111
}
1212
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
\ RUN: %warpforth-translate --forth-to-mlir --mlir-print-debuginfo %s | %FileCheck %s --check-prefix=FORTH
2+
\ RUN: %warpforthc --mlir-print-ir-after=convert-forth-to-memref --mlir-print-debuginfo --mlir-disable-threading %s -o %t.ptx 2>&1 | %FileCheck %s --check-prefix=LOWERED
3+
4+
\! kernel main
5+
42
6+
7+
\ FORTH: forth.constant %{{.*}}(42 : i64) {{.*}} loc([[FORTH_LOC:#loc[0-9]+]])
8+
\ FORTH: [[FORTH_LOC]] = loc("{{.*}}source-locations.forth":5:1)
9+
10+
\ LOWERED: IR Dump After ConvertForthToMemRef (convert-forth-to-memref)
11+
\ LOWERED: arith.constant 42 : i64 loc([[LOWERED_LOC:#loc[0-9]+]])
12+
\ LOWERED: [[LOWERED_LOC]] = loc("{{.*}}source-locations.forth":5:1)

test/lit.cfg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
config.substitutions.append(
1414
("%warpforth-opt", os.path.join(config.warpforth_bin_root, "bin", "warpforth-opt"))
1515
)
16+
config.substitutions.append(
17+
("%warpforthc", os.path.join(config.warpforth_bin_root, "bin", "warpforthc"))
18+
)
1619
config.substitutions.append(
1720
("%FileCheck", config.filecheck_path)
1821
)

tools/warpforthc/warpforthc.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
1313
#include "mlir/Dialect/Func/IR/FuncOps.h"
1414
#include "mlir/Dialect/MemRef/IR/MemRef.h"
15+
#include "mlir/IR/AsmState.h"
1516
#include "mlir/IR/BuiltinOps.h"
1617
#include "mlir/IR/Diagnostics.h"
1718
#include "mlir/IR/MLIRContext.h"
@@ -44,7 +45,9 @@ static llvm::cl::opt<std::string>
4445

4546
int main(int argc, char **argv) {
4647
llvm::InitLLVM y(argc, argv);
48+
warpforth::registerConversionPasses();
4749
registerMLIRContextCLOptions();
50+
registerAsmPrinterCLOptions();
4851
registerPassManagerCLOptions();
4952
llvm::cl::ParseCommandLineOptions(argc, argv,
5053
"WarpForth compiler: Forth to PTX\n");
@@ -88,7 +91,8 @@ int main(int argc, char **argv) {
8891

8992
// Run the compilation pipeline
9093
PassManager pm(&context);
91-
(void)applyPassManagerCLOptions(pm);
94+
if (failed(applyPassManagerCLOptions(pm)))
95+
return 1;
9296
warpforth::buildWarpForthPipeline(pm);
9397
if (failed(pm.run(*module))) {
9498
llvm::errs() << "error: compilation pipeline failed\n";

0 commit comments

Comments
 (0)