Skip to content
Open
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
6 changes: 6 additions & 0 deletions include/warpforth/Conversion/ForthToMemRef/ForthToMemRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
namespace mlir {
namespace warpforth {

/// Discardable attribute recording the data-stack depth before an op.
inline constexpr const char kForthKnownDepthAttr[] = "known_depth";

/// Tags Forth ops whose data-stack depth is known at compile time.
std::unique_ptr<Pass> createTagForthStackDepthPass();

/// Creates a pass that converts Forth dialect operations to MemRef dialect.
/// This pass lowers the abstract Forth stack type to a concrete memref<256xi64>
/// representation with an explicit stack pointer (index type) threaded through
Expand Down
23 changes: 18 additions & 5 deletions include/warpforth/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@

include "mlir/Pass/PassBase.td"

def ConvertForthToMemRef
: Pass<"convert-forth-to-memref", "mlir::ModuleOp"> {
def TagForthStackDepth : Pass<"tag-forth-stack-depth", "mlir::ModuleOp"> {
let summary = "Tag Forth ops with a known stack depth";
let description = [{
Records the compile-time data-stack depth before each Forth op as a
`known_depth` attribute. A function whose depth cannot be tracked is left
unchanged. The attribute is an analysis result and does not change operands.
}];

let constructor = "mlir::warpforth::createTagForthStackDepthPass()";

let dependentDialects = ["mlir::func::FuncDialect",
"mlir::cf::ControlFlowDialect"];
}

def ConvertForthToMemRef : Pass<"convert-forth-to-memref", "mlir::ModuleOp"> {
let summary = "Convert Forth dialect to MemRef dialect";
let description = [{
This pass converts Forth dialect operations to MemRef dialect operations.
Expand All @@ -20,7 +33,8 @@ def ConvertForthToMemRef
- Stack pointer: `index` type (current top of stack position)

Forth operations are converted to corresponding memref load/store operations
with explicit stack pointer arithmetic.
with explicit stack pointer arithmetic. An op tagged with `known_depth` is
lowered to SSA values instead of the memref stack.

`forth.shuffle` becomes a `gpu.shuffle` of the whole i64 cell at width 32.
}];
Expand All @@ -31,8 +45,7 @@ def ConvertForthToMemRef
"mlir::arith::ArithDialect",
"mlir::LLVM::LLVMDialect",
"mlir::cf::ControlFlowDialect",
"mlir::math::MathDialect",
"mlir::gpu::GPUDialect"];
"mlir::math::MathDialect", "mlir::gpu::GPUDialect"];
}

def ConvertForthToGPU : Pass<"convert-forth-to-gpu", "mlir::ModuleOp"> {
Expand Down
1 change: 1 addition & 0 deletions lib/Conversion/ForthToMemRef/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_mlir_conversion_library(MLIRForthToMemRefConversion
ForthToMemRef.cpp
TagForthStackDepth.cpp

DEPENDS
MLIRConversionPassIncGen
Expand Down
Loading
Loading