Skip to content

hlstool crashes on handshake input #9538

@zhengyao-lin

Description

@zhengyao-lin

Running

hlstool --dynamic-hw --buffering-strategy=all --verilog --lowering-options=disallowLocalVariables --verbose-pass-executions

crashes on the following handshake function

handshake.func @top(%v0: i32, %v1: i32, %mem.src.load0.data: i32, %mem.src.load0.done: none, %mem.dst.store0.done: none) -> (none, index, i32, index) attributes {argNames = ["in0", "in1", "mem.src.load0.data", "mem.src.load0.done", "mem.dst.store0.done"], resNames = ["out0", "mem.src.load0.addr", "mem.dst.store0.data", "mem.dst.store0.addr"]} {
  %v4 = handshake.constant %v3 {value = 1 : i32} : i32
  %v6 = handshake.constant %v5 {value = 1 : i32} : i32
  %v8 = handshake.constant %v7 {value = 511 : i32} : i32
  %v10 = handshake.constant %v9 {value = 256 : i32} : i32
  %v12, %v13 = handshake.fork [2] %v11 : i32
  %v15, %v16 = handshake.fork [2] %v14 : i32
  %v18, %v19, %v20, %v21, %v22, %v23, %v24, %v25, %v26, %v27, %v28, %v29, %v30, %v31 = handshake.fork [14] %v17 : i1
  %v32, %_0 = handshake.cond_br %v21, %v16 : i32
  %v33, %v34 = handshake.fork [2] %v32 : i32
  %v36, %v37 = handshake.fork [2] %v35 : i32
  %v38, %_1 = handshake.cond_br %v20, %v37 : i32
  %v39, %v40 = handshake.fork [2] %v38 : i32
  %v42, %v43 = handshake.fork [2] %v41 : i32
  %v45, %v46 = handshake.fork [2] %v44 : i32
  %v48, %v49, %v50, %v51, %v52, %v53, %v54, %v55, %v56, %v57, %v58, %v59 = handshake.fork [12] %v47 : i1
  %v60, %_2 = handshake.cond_br %v49, %v46 : i32
  %v61, %v62 = handshake.fork [2] %v60 : i32
  %v64, %v65, %v66, %v67, %v68, %v69, %v70, %v71, %v72, %v73 = handshake.fork [10] %v63 : i1
  %v76 = handshake.join %v74, %v75 : none, none
  %v77, %_3 = handshake.cond_br %v71, %v76 : none
  %v79, %v75, %v80 = handshake.fork [3] %v78 : none
  %_4, %v81 = handshake.cond_br %v73, %v80 : none
  %v83, %v84, %v85, %v74, %v86 = handshake.fork [5] %v82 : none
  %v88, %v89, %v90 = handshake.fork [3] %v87 : none
  %_5, %v87 = handshake.cond_br %v72, %v86 : none
  %v92 = handshake.join %v85, %v91 : none, none
  %v93, %_6 = handshake.cond_br %v69, %v92 : none
  %v95, %v91, %v96 = handshake.fork [3] %v94 : none
  %_7, %v97 = handshake.cond_br %v70, %v96 : none
  %v100 = arith.select %v67, %v98, %v99 : i32
  %v105 = handshake.join %v101, %v102, %v103, %v104 : none, none, none, none
  %v2 = handshake.br %v105 : none
  %v107, %v108 = handshake.fork [2] %v106 : i32
  %_8, %v110 = handshake.cond_br %v29, %v109 : none
  %v112, %v113, %v99 = handshake.fork [3] %v111 : i32
  %v114, %v115 = handshake.fork [2] %v8 : i32
  %v116 = handshake.constant %v90 {value = 0 : i32} : i32
  %v118 = handshake.constant %v117 {value = 0 : i32} : i32
  %v120 = handshake.constant %v119 {value = 0 : i32} : i32
  %v122, %v123 = handshake.fork [2] %v121 : i32
  %v125 = handshake.constant %v124 {value = 0 : i32} : i32
  %v127, %v128 = handshake.fork [2] %v126 : none
  %v129, %_9 = handshake.cond_br %v58, %v127 : none
  %_10, %v101 = handshake.cond_br %v59, %v128 : none
  %v131, %v132 = handshake.fork [2] %v130 : none
  %v133, %_11 = handshake.cond_br %v56, %v131 : none
  %_12, %v103 = handshake.cond_br %v57, %v132 : none
  %v135, %v136 = handshake.fork [2] %v134 : none
  %v78, %_13 = handshake.cond_br %v30, %v135 : none
  %_14, %v137 = handshake.cond_br %v31, %v136 : none
  %v139, %v109 = handshake.fork [2] %v138 : none
  %v140, %_15 = handshake.cond_br %v28, %v139 : none
  %v119, %v117, %v141, %v3, %v142, %v143 = handshake.fork [6] %v129 : none
  %_16 = arith.index_cast %v13 : i32 to index
  %mem.dst.store0.addr = handshake.buffer [1] seq %_18 : index
  %mem.dst.store0.data = handshake.buffer [1] seq %_19 : i32
  %_20 = handshake.buffer [1] seq %mem.dst.store0.done : none
  %_21, %_22 = handshake.fork [2] %_16 : index
  %_23, %_24 = handshake.fork [2] %v144 : i32
  %_17 = handshake.join %_21, %_23 : index, i32
  %_19, %_18 = handshake.store [%_22] %_24, %_17 : index, i32
  %v145 = handshake.br %mem.dst.store0.done : none
  %v82 = handshake.join %v146, %v147 : none, i32
  %v148, %v9, %v7, %v5, %v146 = handshake.fork [5] %v140 : none
  %v150 = join %v149 : i32
  %v124, %v152, %v102 = handshake.fork [3] %v151 : none
  %v151 = join %v153 : i32
  %v154, %v104 = handshake.fork [2] %v150 : none
  %_25 = handshake.buffer [1] seq %v53 {initValues = [0]} : i1
  %v155 = handshake.mux %_25 [%v1, %v123] : i1, i32
  %v156, %v153, %v149 = handshake.fork [3] %v0 : i32
  %v121, %_26 = handshake.cond_br %v48, %v155 : i32
  %v157, %v158 = handshake.fork [2] %v133 : none
  %v160, %_27 = handshake.cond_br %v19, %v159 : i32
  %v106, %_28 = handshake.cond_br %v18, %v161 : i32
  %v163, %v164 = handshake.fork [2] %v162 : i1
  %v166 = handshake.mux %v66 [%v165, %v77] : i1, none
  %v94 = handshake.join %v79, %v164 : none, i1
  %v165 = handshake.join %v88, %v81 : none, none
  %v167, %_29 = handshake.cond_br %v64, %v115 : i32
  %v144, %_30, %_31 = handshake.sync %v168, %v163, %v83 : i32, i1, none
  %v162 = handshake.constant %v166 {value = 0 : i1} : i1
  %v170, %v171 = handshake.fork [2] %v169 : i1
  %v98 = arith.subi %v113, %v114 : i32
  %v173 = handshake.mux %v68 [%v172, %v93] : i1, none
  %v174 = handshake.join %v84, %v171, %v145 : none, i1, none
  %v172 = handshake.join %v89, %v97 : none, none
  %v175, %_32 = handshake.sync %v100, %v170 : i32, i1
  %v169 = handshake.constant %v173 {value = 0 : i1} : i1
  %v177 = handshake.join %v95, %v176 : none, none
  %v178 = handshake.join %v158, %v143, %v110, %v137 : none, none, none, none
  %v179, %v176 = handshake.fork [2] %v174 : none
  %v180 = arith.addi %v39, %v6 : i32
  %v181, %_33 = handshake.cond_br %v50, %v43 : i32
  %v182 = arith.addi %v61, %v4 : i32
  %v168 = handshake.mux %v65 [%v116, %v167] : i1, i32
  %_34 = handshake.buffer [1] seq %v22 {initValues = [0]} : i1
  %v35 = handshake.mux %_34 [%v118, %v180] : i1, i32
  %_35 = handshake.buffer [1] seq %v23 {initValues = [0]} : i1
  %v161 = handshake.mux %_35 [%v62, %v108] : i1, i32
  %_36 = handshake.buffer [1] seq %v24 {initValues = [0]} : i1
  %v159 = handshake.mux %_36 [%v120, %v175] : i1, i32
  %_37 = handshake.buffer [1] seq %v25 {initValues = [0]} : i1
  %v14 = handshake.mux %_37 [%v122, %v34] : i1, i32
  %_38 = handshake.buffer [1] seq %v26 {initValues = [0]} : i1
  %v138 = handshake.mux %_38 [%v141, %v179] : i1, none
  %_39 = handshake.buffer [1] seq %v27 {initValues = [0]} : i1
  %v134 = handshake.mux %_39 [%v157, %v177] : i1, none
  %_40 = handshake.buffer [1] seq %v51 {initValues = [0]} : i1
  %v44 = handshake.mux %_40 [%v125, %v182] : i1, i32
  %_41 = handshake.buffer [1] seq %v52 {initValues = [0]} : i1
  %v41 = handshake.mux %_41 [%v156, %v181] : i1, i32
  %_42 = handshake.buffer [1] seq %v54 {initValues = [0]} : i1
  %v126 = handshake.mux %_42 [%v152, %v142] : i1, none
  %_43 = handshake.buffer [1] seq %v55 {initValues = [0]} : i1
  %v130 = handshake.mux %_43 [%v154, %v178] : i1, none
  %v47 = arith.cmpi ult, %v45, %v42 : i32
  %v17 = arith.cmpi ult, %v36, %v15 : i32
  %v183 = arith.muli %v107, %v33 : i32
  %v11 = arith.addi %v183, %v40 : i32
  %v184, %_44 = handshake.sync %v12, %v148 : i32, none
  %v186, %v147 = handshake.fork [2] %v185 : i32
  %_45 = arith.index_cast %v184 : i32 to index
  %mem.src.load0.addr = handshake.buffer [1] seq %_47 : index
  %_48 = handshake.buffer [1] seq %mem.src.load0.data : i32
  %_49, %_50 = handshake.fork [2] %_45 : index
  %_46 = handshake.join %_49 : index
  %v185, %_47 = handshake.load [%_50] %_48, %_46 : index, i32
  %v111 = arith.addi %v186, %v160 : i32
  %v63 = arith.cmpi slt, %v10, %v112 : i32
  return %v2, %mem.src.load0.addr, %mem.dst.store0.data, %mem.dst.store0.addr : none, index, i32, index
}

Assertion failure and stack trace:

Assertion failed: (op->getNumResults() == newValues.size() && "incorrect # of replacement values"), function replaceOp, file DialectConversion.cpp, line 2159.
PLEASE submit a bug report to https://github.com/llvm/circt and include the crash backtrace.
Stack dump:
0.      Program arguments: build/bin/hlstool tests/dither/test.handshake.mlir --dynamic-hw --buffering-strategy=cycles --verilog --lowering-options=disallowLocalVariables --verbose-pass-executions
 #0 0x0000000102a3e810 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100072810)
 #1 0x0000000102a3c904 llvm::sys::RunSignalHandlers() (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100070904)
 #2 0x0000000102a3f2a0 SignalHandler(int, __siginfo*, void*) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x1000732a0)
 #3 0x0000000183a996a4 (/usr/lib/system/libsystem_platform.dylib+0x1804ad6a4)
 #4 0x0000000183a5f848 (/usr/lib/system/libsystem_pthread.dylib+0x180473848)
 #5 0x00000001839689e4 (/usr/lib/system/libsystem_c.dylib+0x18037c9e4)
 #6 0x0000000183967c18 (/usr/lib/system/libsystem_c.dylib+0x18037bc18)
 #7 0x0000000103564eec mlir::ConversionPatternRewriter::applySignatureConversion(mlir::Block*, mlir::TypeConverter::SignatureConversion&, mlir::TypeConverter const*) (.cold.1) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b98eec)
 #8 0x00000001035508d8 mlir::ConversionPatternRewriter::replaceOp(mlir::Operation*, mlir::ValueRange) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b848d8)
 #9 0x00000001035506c4 mlir::ConversionPatternRewriter::replaceOp(mlir::Operation*, mlir::Operation*) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b846c4)
#10 0x0000000102c24d78 (anonymous namespace)::HandshakeConversionPattern<circt::handshake::SyncOp>::matchAndRewrite(circt::handshake::SyncOp, circt::handshake::SyncOpAdaptor, mlir::ConversionPatternRewriter&) const (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100258d78)
#11 0x0000000102c0f8bc llvm::LogicalResult mlir::ConversionPattern::dispatchTo1To1<mlir::OpConversionPattern<circt::handshake::SyncOp>, circt::handshake::SyncOp>(mlir::OpConversionPattern<circt::handshake::SyncOp> const&, circt::handshake::SyncOp, circt::handshake::SyncOp::GenericAdaptor<llvm::ArrayRef<mlir::ValueRange> >, mlir::ConversionPatternRewriter&) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x1002438bc)
#12 0x0000000102c0f7d8 mlir::OpConversionPattern<circt::handshake::SyncOp>::matchAndRewrite(circt::handshake::SyncOp, circt::handshake::SyncOpGenericAdaptor<llvm::ArrayRef<mlir::ValueRange> >, mlir::ConversionPatternRewriter&) const (/Users/zhengyao/work/stuff/build/bin/hlstool+0x1002437d8)
#13 0x0000000102c0f43c mlir::OpConversionPattern<circt::handshake::SyncOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::ValueRange>, mlir::ConversionPatternRewriter&) const (/Users/zhengyao/work/stuff/build/bin/hlstool+0x10024343c)
#14 0x0000000103551d38 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b85d38)
#15 0x0000000103589218 void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>)::$_0>(long) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100bbd218)
#16 0x00000001035863bc mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100bba3bc)
#17 0x000000010355282c (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b8682c)
#18 0x0000000103551e40 mlir::OperationConverter::convert(mlir::Operation*, bool) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b85e40)
#19 0x0000000103552bd8 mlir::OperationConverter::applyConversion(llvm::ArrayRef<mlir::Operation*>) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b86bd8)
#20 0x000000010355d050 void llvm::function_ref<void ()>::callback_fn<applyConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::$_0>(long) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b91050)
#21 0x0000000103555ce8 applyConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b89ce8)
#22 0x0000000103555da0 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100b89da0)
#23 0x0000000102c18f50 (anonymous namespace)::HandshakeToHWPass::runOnOperation() (/Users/zhengyao/work/stuff/build/bin/hlstool+0x10024cf50)
#24 0x00000001035e2448 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100c16448)
#25 0x00000001035e2f5c mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100c16f5c)
#26 0x00000001035e878c mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100c1c78c)
#27 0x00000001035e7f24 mlir::PassManager::run(mlir::Operation*) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100c1bf24)
#28 0x00000001029d1854 processBuffer(mlir::MLIRContext&, mlir::TimingScope&, llvm::SourceMgr&, std::__1::optional<std::__1::unique_ptr<llvm::ToolOutputFile, std::__1::default_delete<llvm::ToolOutputFile> > >&) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100005854)
#29 0x00000001029d0848 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> > >&) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100004848)
#30 0x00000001029cea0c executeHlstool(mlir::MLIRContext&) (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100002a0c)
#31 0x00000001029ce128 main (/Users/zhengyao/work/stuff/build/bin/hlstool+0x100002128)
#32 0x00000001836beb98

I'm new to CIRCT and the handshake dialect, so please let me know if there's a good way to minimize the code above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions