[SCFToCalyx] Cannot lower to Calyx with memref.global
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 524
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 46
Description
The --lower-scf-to-calyx pass fails with a seg fault:
module {
memref.global "private" @conv_weight : memref<600xf32> = dense<"0x3644523B0CAFE0BDA86574BD3333103D1468EBBDD6E89E3DC229C7BDAF39CFBC1146CF3CC6D9B23DFE12353C3F87783CC2B5E83D1BEC9B3D2210B23D339B893D7E49BDBDE2F31CBD5240E4BCCAA142BDC5E594BD98CBD5BC2BE7DA3DA7B0DFBD3074493D27DA01BCA0AFDD3DBD5E21BD192F95BD1DBE223C52739FBD2946033DB1AAE6BBE6B5D53D6D23BE3D7817A5BDF976903DD9C6CA3DDFC404BD6C1BE8BDE01887BD54B1713DFAE7D83DAD7808BC3FD2B2BDAFD986BDC76CCDBDDF7298BD13F2E8BDA632953DEE3CC83D7A2B6F3C83EEA6BD6607F7BC2400083D999E11BDBA63503DE29B753D095E39BD581F983C66AB343DA22FB53D654296BCEB4AA2BD54E4A93D483C283D47E535BD8E70BB3DD13FDA3DF0E620BC47C1D8BD88DB40BD3A11723D97C7EABD5DF75C3D081EBF3DC0E9953DDC0492BD89E113BD45A23CBB264B72BD417BB43D5A86A13DF727A0BD1E2C45BAE3CFAABD59DFC8BD4AFD463D647E6CBDDC621ABC18BF94BD722BD6BD28E6C2BDE82E7ABCFB73CB3D024C8C3CFF89BABCDA0312BC90D50CBD369E783D5FF328BD8185BEBDFC278D3D29698D3C7CE9B23DEFCE52BD0FB8E5BD309D19BDD67CC3BBB9B6D5BC7F18BD3D06A8A73D97B6C43DB5B0E7BDAF87193D8E8DB7BC3A6C863DEDCE8ABD2BB99C3D61A7EB3D78F4C4BDA5BF273D9D0E8F3D0B225E3DC291C8BD94E67EBD0E152BBDCB79ABBDFF1290BDA98DB8BD20AD893CBDED86BDE667C83D36C7D8BD2CAE293D4B7D6CBC731E843C50E0C13DEA2C753DDB0EA6BD7D806ABD43B0763D81C6C33BC7D8943D56C8083D2926A13D63789D3D4E1B7BBD3B440BBDF9924FBCF41354BD9E3C44BD9A6FE6BC3E3B273D3FE8723D7A92A9BC2462E4BD31DDE0BD82756ABDBDFAC4BD2DE482BDBEE4713B41B2663C706EA3BDF069DD3A9690463DB5E48D3D5F19673CC88CB63D4B00A0BD57CFFEBA1D27CABD898DDCBCBEF1CFBDF36CEEBCADB6BDBCDEA6E8BD05C3DFBCFC666A3DDA7F2BBD1DE37A3D547616BD76011ABCDF39E1BDFBC7E0BC4B0813BD648191BD21CFC9BDE3E3D43D704FDB3D447C63BD7E4F8CBDCBCF6E3C2ECFCBBDA8FCC03DD27C8C3CE631CABDC6B6523D189626BB5E62BDBD2246613CD1FE3DBCE1C885BA6853CFBC0B2EA53D18ABA1BC23873B3C8D2562BD1852DB3DCB192A3D1483BC3D6CF61CBDB893EEBC8DAFB43DAC80BD3D2321163DD64550BD7738B83D6736E03CDD4E9EBD61CF8E3C6827E7BDC2E3CFBD635E2DBD6BE34C3DE8C55E3D855481BDFDB1C5BDAA08CD3DF8A4CABD77E7AABDA3F04E3D108EE63DC322C0BD648382BDD18C6F3DA31426BDAD164C3C8E6534BA2E6896BB6CD0AFBDC02913BD02A23CBDE4AD77BDA2B664BD5AFFC6BD4AC827BD9821BE3DA69103BD2805283DAC51AF3D3F67E53D2FDE7DBD08467F3D1073B4BC264C813D6EC3353D0236C1BD4274BABD29C2483CAFBAAB3A0A848CBCDA923DBCF7C4A1BD9F35E83DBB7FB9BDD7CDAA3DCF0ECA3DD52ADC3D150598BDFB7B7B3CB3FED3BD81C1BEBD996B763BD5BF863D7F4072BD542DB6BD1A5E8E3CAB06DC3D68D63BBC0EB225BDC425A43DEEC880BD5FE2D43D4834BFBD34DCDDBD88CFDF3D80C4AABC03D098BCA4EF43BD64BC473DF83BAB3DBF0F253CB79DA13DA178133DEC1FE2BDB8C1AE3B0D5A7A3DCF30FB3B7E0E6FBDB01893BD4E01D93D70386F3DAAA8E83D1F0E91BD04E2913C5DC583BCB419E7BDB47CD3BC3457403DE76C3E3D2BF5DA3DC73BB43D2DBC60BD5BB991BDA095D0BC3A2BE1BCF2F559BDC027E6BB568AA6BD915066BD2062A0BD050DC3BD569EB4BC34E0A3BD472BC1BDEF6DB63D617011BD078B653D5FE8013D918B683CCC13B83D2D78513CE2CDC03D15B8CA3D2804C23D87D0DABDCDDCC03C0FBD1EBD13F6B83D921DA4BD5D68043D6A9686BAB9A52BBC7C0A3BBC72E8B2BDFD04C23D39BFBFBD1CA7A4BD876F4D396F9C11BDF971B7BDE2A746BD0BFE22BDED79993D2EEFCA3DE8D9C33D7520E03D8323823DB5E797BDD172DDBD6C4C9F3DD6B6CB3CAB38103D764CD23D9ADA06BC52CB9DBC1E288FBB2AB509BD8CEB8D3D0FB598BD7A9BB53D7C93E5BC6CE0A8BD9745B93D327A6B3DE2648CBD409D88BD3E65B23C03BDABBD530FE2BD46CB5ABD03611ABD30A0D6BD1785493DF02577BDAB68B5BC70029BBDF205A8BDB05D613BC5CEA2BD920B303D79E5E43CD658CBBD23914A3B4B2D87BDDA548A3DE678473CB5E6A33D7D3ECD3DFD4A64BD809BA5BD16EB0ABD892B2DBD37638C3D6379B4BD9A23A2BD3C4DE0BD293E2B3D9D25E83D9F6267BD9CCC6C3D5802E43D6128CF3D74EF7ABCFB8944BDCD9BE23DCBC7C9BD212D88BD621DD13D04BAC03D28CCC63B0D1B95BC7FA2B5BDAAF788BC7AB7C23DCC8B0ABDF4D6BB3D27915EBD01EC253CC88B64BD76F87ABC8300873DE379AC3D7CA856BCD715B5BDABC2B6BD1F8925BD45A946BD4C4A59BD72B2AE3C1C35B43D7F9BD33D5658333DE3D0B5BD73144D3D4486D0BA9194A23DF3D72CBDB1BC87BC7FC1C9BCA7088ABD05F3913CED0BB53D9D5F83BD40E906BD17573A3DC61E51BD2A60DEBD3DFDA33D0B853BBD825A763BC8CB2C3D89E3B13DBAEA00BC8FEE6BBD9889613DACD186BDCFF1C2BDA7D64A3C90BB71BDCF9467BDE8997EBD5EB0B3BDBD4935BDC350B73DA313A4BD86B5DA3CCDFFCD3DC081FD3BA10AA5BD250A66BD9F0D903D711691BDCDCE5EBDFFB81BBDBEF39DBDAED3FB3C6F09D9BD3860A8BCCCECE73C1F79CABA2E16A63D1BCF17BDD367D83D116A6DBCD9AE0D3DC7ACEDBC98BC153CD6BB92BD4071E53CCCA91B3D58A25E3D3A3085BBCB1BDDBDDAD4ADBD016791BD9579C03DD07BCD3DA86462BD757B85BD90A5E5BD7449D7BC981905BCC96713BCE8E259BCA25CE43D99709B3B2103C1BDC305383D64B1603DBBFE37BD673951BDB12CB53D0D169C3D22E6C4BDC45FBCBD18A5AE3D53898BBCB690823D979EE83C122B1F3C5425D03D907B1C3C9819A3BD6E09DC3D73BDA8BD486F123DD5E7C8BCE37C323B96E8163A39F6213D2E99CE3D17A3BABD2A001EBD73B9BF3DF142DA3D88ED0E3D23BDDD3C735354BD67C2B13B25B4D8BD3153353D4A5399BD11B3A9BBD5C8D33D034110BD9ED8923DF6E4A5BC5E0651BD75B0053D3B71A33D42A2B33DE25B663C9B15DC3D3FF2CEBDD1B182BD07EAF03C4E55E5BD538EC2BD96E594BC9EB0193D910E053C531E43BC9CFA8F3DDA42973DD4BEB83CB982A13DAD43D33D84FD8EBD8685393BEB339A3CE1B5D6BDBE42D13C10ECD7BD49D2AEBCE405893D9692E63DD1DCE23B7BC69C3D86046E3DED7D8AB991648FBD38384DBD24E81A3D14B85ABD0FD9193DB5B4883DDB99C5BD8C481F3D">
func.func @test() -> i32{
%0 = arith.constant 1 : i32
%1 = memref.get_global @conv_weight : memref<600xf32>
%2 = arith.sitofp %0 : i32 to f32
%3 = arith.index_cast %0 : i32 to index
memref.store %2, %1[%3] : memref<600xf32>
%4 = arith.addf %2, %2 : f32
%5 = arith.fptosi %4 : f32 to i32
return %0 : i32
}
}
The stack dump:
0. Program arguments: /opt/compiler-explorer/circt-trunk/bin/circt-opt -o /app/example.out.mlir --pass-pipeline=builtin.module(lower-scf-to-calyx{top-level-function=test}) <source>
#0 0x0000000001414b58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x1414b58)
#1 0x0000000001411835 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x00007f518a842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x0000000002ed482b mlir::DenseElementsAttr::getNumElements() const (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x2ed482b)
#4 0x0000000002cd36a8 llvm::LogicalResult circt::scftocalyx::buildAllocOp<mlir::memref::GetGlobalOp>(circt::scftocalyx::ComponentLoweringState&, mlir::PatternRewriter&, mlir::memref::GetGlobalOp) SCFToCalyx.cpp:0:0
#5 0x0000000002cd472d circt::scftocalyx::BuildOpGroups::partiallyLowerFuncToComp(mlir::func::FuncOp, mlir::PatternRewriter&) const::'lambda'(mlir::Operation*)::operator()(mlir::Operation*) const (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x2cd472d)
#6 0x0000000002cd5840 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.5) SCFToCalyx.cpp:0:0
#7 0x0000000002cd5814 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.5) SCFToCalyx.cpp:0:0
#8 0x0000000002cd58e3 circt::scftocalyx::BuildOpGroups::partiallyLowerFuncToComp(mlir::func::FuncOp, mlir::PatternRewriter&) const (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x2cd58e3)
#9 0x0000000002c1f283 circt::calyx::PartialLoweringPattern<mlir::func::FuncOp, mlir::OpRewritePattern>::matchAndRewrite(mlir::func::FuncOp, mlir::PatternRewriter&) const (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x2c1f283)
#10 0x0000000003b35192 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&)>)::'lambda'()::operator()() const PatternApplicator.cpp:0:0
#11 0x0000000003b3653a 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&)>) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x3b3653a)
#12 0x0000000003b03cb3 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#13 0x0000000003b084b3 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x3b084b3)
#14 0x0000000002cded27 circt::(anonymous namespace)::SCFToCalyxPass::runOnOperation() SCFToCalyx.cpp:0:0
#15 0x0000000003c45fa1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x3c45fa1)
#16 0x0000000003c462d7 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x3c462d7)
#17 0x0000000003c480ba mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x3c480ba)
#18 0x0000000003c48f31 mlir::PassManager::run(mlir::Operation*) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x3c48f31)
#19 0x000000000344a637 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x000000000344b047 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#21 0x000000000347eafe mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x347eafe)
#22 0x0000000003446a89 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#23 0x000000000344b7a4 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x344b7a4)
#24 0x000000000344b9ed mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x344b9ed)
#25 0x000000000137819d main (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x137819d)
#26 0x00007f518a829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x00007f518a829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x000000000137c445 _start (/opt/compiler-explorer/circt-trunk/bin/circt-opt+0x137c445)
The issue is likely not checking for null before trying to call getValues()
auto cstAttr = llvm::dyn_cast_or_null<DenseElementsAttr>(
globalOp.getConstantInitValue());
int sizeCount = 0;
for (auto attr : cstAttr.template getValues<Attribute>()) {
assert((isa<mlir::FloatAttr, mlir::IntegerAttr>(attr)) &&
"memory attributes must be float or int");
if (auto fltAttr = dyn_cast<mlir::FloatAttr>(attr)) {
flattenedVals[sizeCount++] =
bit_cast<uint64_t>(fltAttr.getValueAsDouble());
} else {
auto intAttr = dyn_cast<mlir::IntegerAttr>(attr);
APInt value = intAttr.getValue();
flattenedVals[sizeCount++] = *value.getRawData();
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in SCFToCalyx.cpp at buildAllocOp and inspect how memref.get_global handles globalOp.getConstantInitValue(). Reproduce the crash with the supplied MLIR and the lower-scf-to-calyx{top-level-function=test} pipeline. Done means the pass no longer segfaults on this input and its behavior for the missing constant initializer is handled safely.
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