llvm / llvm/circt

[CfToHandshake] `hlstool` crashes with unused `memref`

Open
#9,807 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

Consider these two functions:

func.func @bad(%arg0: memref<1024xi32>, %arg1: memref<1024xi32>) {
    %c1_i32 = arith.constant 1 : i32
    affine.store %c1_i32, %arg1[0] : memref<1024xi32>
    return
}

func.func @good(%arg0: memref<1024xi32>, %arg1: memref<1024xi32>) {
    %c1_i32 = arith.constant 1 : i32
    affine.store %c1_i32, %arg0[0] : memref<1024xi32>
    return
}

On the latest commit of CIRCT, hlstool crashes on the first function with the following assertion error

$ hlstool --ir --output-level=core --dynamic-hw <bad.mlir>

Assertion failed: (use_empty() && "Cannot destroy a value that still has uses!"), function ~IRObjectWithUseList, file UseDefLists.h, line 198.
PLEASE submit a bug report to https://github.com/llvm/circt and include the crash backtrace.
Stack dump:
0.      Program arguments: hlstool bad.mlir --ir --output-level=core --dynamic-hw
 #0 0x0000000100ace810 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (hlstool+0x100072810)
 #1 0x0000000100acc904 llvm::sys::RunSignalHandlers() (hlstool+0x100070904)
 #2 0x0000000100acf2a0 SignalHandler(int, __siginfo*, void*) (hlstool+0x1000732a0)
 #3 0x000000019748f744 (/usr/lib/system/libsystem_platform.dylib+0x1804e3744)
 #4 0x0000000197485888 (/usr/lib/system/libsystem_pthread.dylib+0x1804d9888)
 #5 0x000000019738a850 (/usr/lib/system/libsystem_c.dylib+0x1803de850)
 #6 0x0000000197389a84 (/usr/lib/system/libsystem_c.dylib+0x1803dda84)
 #7 0x0000000101186264 mlir::Block::getTerminator() (.cold.1) (hlstool+0x10072a264)
 #8 0x00000001011858bc mlir::Block::getTerminator() (hlstool+0x1007298bc)
 #9 0x0000000101185784 mlir::Block::eraseArguments(llvm::BitVector const&) (hlstool+0x100729784)
#10 0x00000001017cd1ac mlir::function_interface_impl::eraseFunctionArguments(mlir::FunctionOpInterface, llvm::BitVector const&, mlir::Type) (hlstool+0x100d711ac)
#11 0x0000000100cf0c6c mlir::detail::FunctionOpInterfaceTrait<circt::handshake::FuncOp>::eraseArgument(unsigned int) (hlstool+0x100294c6c)
#12 0x0000000100ceee14 (anonymous namespace)::HandshakeLowerExtmemToHWPass::lowerExtmemToHW(circt::handshake::FuncOp) (hlstool+0x100292e14)
#13 0x0000000100ced184 (anonymous namespace)::HandshakeLowerExtmemToHWPass::runOnOperation() (hlstool+0x100291184)
#14 0x0000000101672240 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (hlstool+0x100c16240)
#15 0x0000000101672d54 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (hlstool+0x100c16d54)
#16 0x0000000101678584 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (hlstool+0x100c1c584)
#17 0x0000000101677d1c mlir::PassManager::run(mlir::Operation*) (hlstool+0x100c1bd1c)
#18 0x0000000100a61854 processBuffer(mlir::MLIRContext&, mlir::TimingScope&, llvm::SourceMgr&, std::__1::optional<std::__1::unique_ptr<llvm::ToolOutputFile, std::__1::default_delete<llvm::ToolOutputFile>>>&) (hlstool+0x100005854)
#19 0x0000000100a60848 processInputSplit(mlir::MLIRContext&, mlir::TimingScope&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, std::__1::optional<std::__1::unique_ptr<llvm::ToolOutputFile, std::__1::default_delete<llvm::ToolOutputFile>>>&) (hlstool+0x100004848)
#20 0x0000000100a5ea0c executeHlstool(mlir::MLIRContext&) (hlstool+0x100002a0c)
#21 0x0000000100a5e128 main (hlstool+0x100002128)
#22 0x00000001970bdd54

The second function @good works fine though.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at HandshakeLowerExtmemToHWPass::lowerExtmemToHW, identified in the stack trace, and reproduce the failure with the two MLIR functions using the shown hlstool command. Compare argument handling for @bad and @good; done means the unused memref case no longer triggers the use-list assertion while the working case remains successful.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.