Skip to content

[LLHD] Add llhd.sig.extract support to Mem2Reg #8542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fabianschuiki
Copy link
Contributor

Extend LLHD's Mem2Reg pass to support llhd.sig.extract projections. To implement the extraction and injection of bit ranges at dynamic offsets, add a few helper functions to CombOps.h that assemble the necessary operations. We may want to add a comb.inject op in the future to simplify this.

Extend LLHD's Mem2Reg pass to support `llhd.sig.extract` projections. To
implement the extraction and injection of bit ranges at dynamic offsets,
add a few helper functions to `CombOps.h` that assemble the necessary
operations. We may want to add a `comb.inject` op in the future to
simplify this.
@fabianschuiki fabianschuiki added LLHD Comb Involving the `comb` dialect labels Jun 5, 2025
#include "mlir/IR/PatternMatch.h"
#include "llvm/Support/FormatVariadic.h"

using namespace circt;
using namespace comb;

Value comb::createZExt(OpBuilder &builder, Location loc, Value value,
unsigned targetWidth) {
assert(value.getType().isInteger());
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could also use isSignlessInteger() as comb only uses signless

return builder.createOrFold<comb::OrOp>(loc, value, replacement, twoState);
}

Value comb::createInject(OpBuilder &builder, Location loc, Value value,
Copy link
Member

Choose a reason for hiding this comment

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

This function doesn't have a test or am I missing something?

if (end < largeWidth)
fragments.push_back(
builder.create<comb::ExtractOp>(loc, value, end, largeWidth - end));
fragments.push_back(replacement);
Copy link
Member

Choose a reason for hiding this comment

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

What if end > largeWidth? Should we extract from replacement and ignore the non-overlapping part?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Comb Involving the `comb` dialect LLHD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants