From f28cf0d94a8199d20b791afa0b31feaf49995d46 Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Sat, 24 Oct 2026 20:55:59 +1100 Subject: [PATCH] fix(warpforthc): register the func inliner extension warpforthc builds its own dialect registry, and since 8f2b838 it no longer pulls in the func dialect's inliner extension. Without it the inliner pass inlines nothing, so every user word reached PTX as a .visible .func. warpforth-opt was unaffected because it registers all extensions. i64-memory-alignment.forth checked loads and stores inside the SUM3 function, which no longer exists once words are inlined. Its kernel checks still cover 64-bit global accesses. --- test/Pipeline/i64-memory-alignment.forth | 8 ++------ test/Pipeline/inlined-words.forth | 13 +++++++++++++ tools/warpforthc/CMakeLists.txt | 1 + tools/warpforthc/warpforthc.cpp | 6 ++++-- 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 test/Pipeline/inlined-words.forth diff --git a/test/Pipeline/i64-memory-alignment.forth b/test/Pipeline/i64-memory-alignment.forth index e36113e..ab95703 100644 --- a/test/Pipeline/i64-memory-alignment.forth +++ b/test/Pipeline/i64-memory-alignment.forth @@ -1,8 +1,8 @@ \ RUN: %warpforthc %s -o %t.ptx \ RUN: %FileCheck %s --implicit-check-not='{{(ld|st)[.a-z]*\.[bsuf]32}}' < %t.ptx -\ i64 global accesses and the stack slots in word functions are naturally -\ aligned, so each is a single 64-bit memory operation. +\ i64 global accesses are naturally aligned, so each is a single 64-bit memory +\ operation. \! kernel main \! param A i64[256] @@ -18,7 +18,3 @@ GLOBAL-ID CELLS A + ! \ CHECK: ld{{(\.global)?}}.{{[bsuf]}}64 {{%[a-z]+[0-9]+}}, [ \ CHECK: ld{{(\.global)?}}.{{[bsuf]}}64 {{%[a-z]+[0-9]+}}, [ \ CHECK: st{{(\.global)?}}.{{[bsuf]}}64 [ - -\ CHECK-LABEL: .func {{.*}}SUM3( -\ CHECK: ld{{(\.global)?}}.{{[bsuf]}}64 {{%[a-z]+[0-9]+}}, [ -\ CHECK: st{{(\.global)?}}.{{[bsuf]}}64 [ diff --git a/test/Pipeline/inlined-words.forth b/test/Pipeline/inlined-words.forth new file mode 100644 index 0000000..239bfe1 --- /dev/null +++ b/test/Pipeline/inlined-words.forth @@ -0,0 +1,13 @@ +\ RUN: %warpforthc %s -o %t.ptx +\ RUN: %FileCheck %s < %t.ptx + +\ Words inlined into the kernel must not survive as device functions. +\ CHECK-NOT: .func +\ CHECK: .entry k( +\ CHECK-NOT: .func + +\! kernel k +\! param a i64[256] +: sq DUP * ; +: sumsq 0 SWAP 0 DO I sq + LOOP ; +GLOBAL-ID sumsq GLOBAL-ID CELLS a + ! diff --git a/tools/warpforthc/CMakeLists.txt b/tools/warpforthc/CMakeLists.txt index 9b8c8fc..08a225a 100644 --- a/tools/warpforthc/CMakeLists.txt +++ b/tools/warpforthc/CMakeLists.txt @@ -12,6 +12,7 @@ target_link_libraries(warpforthc MLIRArithToLLVM MLIRBuiltinToLLVMIRTranslation MLIRControlFlowToLLVM + MLIRFuncInlinerExtension MLIRFuncToLLVM MLIRGPUToLLVMIRTranslation MLIRLLVMToLLVMIRTranslation diff --git a/tools/warpforthc/warpforthc.cpp b/tools/warpforthc/warpforthc.cpp index 0815d67..bd13536 100644 --- a/tools/warpforthc/warpforthc.cpp +++ b/tools/warpforthc/warpforthc.cpp @@ -9,8 +9,9 @@ #include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h" #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlow.h" // IWYU pragma: keep -#include "mlir/Dialect/Func/IR/FuncOps.h" // IWYU pragma: keep -#include "mlir/Dialect/MemRef/IR/MemRef.h" // IWYU pragma: keep +#include "mlir/Dialect/Func/Extensions/InlinerExtension.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" // IWYU pragma: keep +#include "mlir/Dialect/MemRef/IR/MemRef.h" // IWYU pragma: keep #include "mlir/IR/AsmState.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Diagnostics.h" @@ -75,6 +76,7 @@ int main(int argc, char **argv) { cf::registerConvertControlFlowToLLVMInterface(registry); registerConvertFuncToLLVMInterface(registry); registerConvertMemRefToLLVMInterface(registry); + func::registerInlinerExtension(registry); registerBuiltinDialectTranslation(registry); registerGPUDialectTranslation(registry);