Skip to content

Conversation

@zhengyao-lin
Copy link

Fixes #9538: hlstool crashes on this handshake function

handshake.func @top(%a: i32, %b: none, %c: none) -> (i32, i32) {
  %d, %e = sync %a, %b : i32, none
  %f, %g, %h = sync %a, %b, %c : i32, none, none
  return %d, %f : i32, i32
}

when running with

hlstool --dynamic-hw \
  --buffering-strategy=all \
  --verilog \
  --lowering-options=disallowLocalVariables
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 believe this is caused by a module naming issue in this function:

auto [inTypes, outTypes] = getHandshakeDiscriminatingTypes(oldOp);

where getHandshakeDiscriminatingTypes filters out none inputs/outputs when generating a unique module name for the operator.
Therefore, the two sync operators with different input types get mapped to the same module name handshake_sync_in_ui32_out_ui32, causing the assertion failure.

This PR removes the none type filtering behavior. However, I'm not sure why this is done in the first place, so please let me know if this might break something else.

Thank you!

Copy link
Contributor

@Dinistro Dinistro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sync construct was added later on. It might be that the naming logic was built with assuming that none can only ever show up once.
I wouldn't be aware that this can break anything, so I'm accepting this. Consider to give @mortbopet a day or two to intervene.

@zhengyao-lin
Copy link
Author

Thank you! I fixed all the unit tests and added one more test for the crashing handshake function above. Could you please help me restart the CI tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hlstool crashes on handshake input

2 participants