Skip to content

[FIRRTLToHW] Remove the SYNTHESIS guard in printf/flush lowering path#10526

Open
nanjo712 wants to merge 7 commits into
llvm:mainfrom
nanjo712:feat/remove-sysnthesis-guard
Open

[FIRRTLToHW] Remove the SYNTHESIS guard in printf/flush lowering path#10526
nanjo712 wants to merge 7 commits into
llvm:mainfrom
nanjo712:feat/remove-sysnthesis-guard

Conversation

@nanjo712
Copy link
Copy Markdown
Contributor

As discussed in #10489, for operations like printing, SYNTHESIS guard may no longer be necessary because Chisel will send these operations to the verification layer.

@nanjo712
Copy link
Copy Markdown
Contributor Author

Hi @seldridge, since you mentioned that you could try running this through internal builds/flows to see whether anything breaks, would you mind taking a look when you get a chance? I’d like to confirm whether removing this guard causes any downstream impact.

@nanjo712 nanjo712 force-pushed the feat/remove-sysnthesis-guard branch from 92397fb to 19dc84e Compare May 22, 2026 15:28
@circt-bot
Copy link
Copy Markdown

circt-bot Bot commented May 22, 2026

Results of circt-tests run for 19dc84e compared to results for 61d7eca: no change to test results.

Comment thread lib/Conversion/Utils/SVLoweringUtils.cpp
Comment thread test/Conversion/FIRRTLToHW/lower-to-hw.mlir Outdated
Copy link
Copy Markdown
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for doing this.

@nanjo712: yes, I can take a look at this. I'm currently working on a 1.148.0 release and will hold off on testing this. We've got a number of outstanding bugs and one bug fix that needs to get released soon. Once I have something clean on our internal builds, I can take a look at this.

@nanjo712
Copy link
Copy Markdown
Contributor Author

Thanks for taking a look!

@circt-bot
Copy link
Copy Markdown

circt-bot Bot commented May 23, 2026

Results of circt-tests run for 933001f compared to results for 61d7eca: no change to test results.

@seldridge
Copy link
Copy Markdown
Member

This passed some light internal testing. I also inspected the Verilog for one sample and the result looks fine. We have everything already guarded by layers, so there is no real need for the double-guarding. I'm good to proceed with this.

Copy link
Copy Markdown
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

Generally LGTM. Internal testing looked fine. (I'm not saying I won't have to revert it later when I realize this is problematic, though!)

Question about how this is finding the macro.

Comment thread lib/Conversion/Utils/SVLoweringUtils.cpp Outdated
@nanjo712 nanjo712 force-pushed the feat/remove-sysnthesis-guard branch from 933001f to 4367640 Compare May 29, 2026 05:53
@nanjo712
Copy link
Copy Markdown
Contributor Author

Well, I don't really understand what's happening in CI process. It failed in the stage Configure CIRCT in Windows Test.

It looks like a environment problem.

@nanjo712
Copy link
Copy Markdown
Contributor Author

The issue disappeared after I re-triggered the CI. I tried moving the previously mentioned helper to a more reusable location and adjusted my previous logic. It should now be ready for further review. 🚀

@nanjo712 nanjo712 requested a review from seldridge May 29, 2026 06:43
@circt-bot
Copy link
Copy Markdown

circt-bot Bot commented May 29, 2026

Results of circt-tests run for f587125 compared to results for e217d99: no change to test results.

Copy link
Copy Markdown
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

This is looking great. One comment about the function signature and what is passed around.

Comment thread lib/Conversion/Utils/SVLoweringUtils.cpp Outdated
Comment thread include/circt/Dialect/SV/SVOps.h Outdated
Comment on lines +51 to +52
StringAttr resolveMacroSymName(Operation *symbolTableOp, StringRef verilogName,
bool &created);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: naming this getOrCreate may be clearer:

Suggested change
StringAttr resolveMacroSymName(Operation *symbolTableOp, StringRef verilogName,
bool &created);
StringAttr getOrcreate(Operation *symbolTableOp, StringRef verilogName,
bool &created);

Copy link
Copy Markdown
Contributor Author

@nanjo712 nanjo712 May 30, 2026

Choose a reason for hiding this comment

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

This function doesn't actually create anything; it just checks if a symbol already exists or generates a usable symbol name. Perhaps it could be replaced with lookupOrGenerateMacroSymName?

Comment thread lib/Dialect/SV/SVOps.cpp Outdated
@seldridge
Copy link
Copy Markdown
Member

@nanjo712 wrote:

Well, I don't really understand what's happening in CI process. It failed in the stage Configure CIRCT in Windows Test.

I've seen this happen before. It appears to be intermittent. LLMs seem to think that PowerShell Gallery is just flaky. 🫠 Maybe we could change the script to do a few retries before it finally fails.

@nanjo712 nanjo712 requested a review from seldridge May 30, 2026 07:13
@circt-bot
Copy link
Copy Markdown

circt-bot Bot commented May 30, 2026

Results of circt-tests run for 92cd9c2 compared to results for e217d99: no change to test results.

Comment thread lib/Dialect/SV/SVOps.cpp
Comment on lines +70 to +82
Namespace ns;
auto symbolNameId =
StringAttr::get(symbolTableBlock->getParentOp()->getContext(),
SymbolTable::getSymbolAttrName());
for (auto &op : *symbolTableBlock) {
if (auto symbol = op.getAttrOfType<StringAttr>(symbolNameId))
ns.add(symbol.getValue());
}

created = true;
return StringAttr::get(symbolTableBlock->getParentOp()->getContext(),
ns.newName(verilogName));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand it existed before, but could you consider using SymbolTable::insert instead (as SymbolTable is MLIR proper)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I may have misunderstood. I think SymbolTable::insert is not quite appropriate here because this helper simply selects a symbol name and intentionally postpones the creation of the decl opeartion.

auto fragment = emit::FragmentOp::create(builder, fragmentSymName, [&] {
emitGuard("SYNTHESIS", [&]() {
emitGuard(kFileDescriptorMacroName, [&]() {
emitGuard(synthesisSymName, [&]() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't we remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would be more cautious about removing this. We could simply remove the synthesis guard for print operations, mainly because Chisel places these operations in a separate layer, which are then output to separate files. These separate files themselves have macro guard, and also it's easy to disable it by not including these separate files in the synthesis.

As far as I know, there doesn't seem to be a similar mechanism for this part; it outputs separately to each file used, unlike print operations which are separated from the design code.

We might be able to improve it further, but I think this might require another evaluation.

@nanjo712 nanjo712 requested a review from uenoku June 1, 2026 11:10
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.

3 participants