Skip to content
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

dialects: Add LLVM InlineAsm op #2203

Merged
merged 5 commits into from
Feb 22, 2024
Merged

dialects: Add LLVM InlineAsm op #2203

merged 5 commits into from
Feb 22, 2024

Conversation

JosseVanDelm
Copy link
Collaborator

This PR attempts to add the LLVM InlineAsm op, which allows to bake in inline assembly from within MLIR.

Some things I noted while making this:

  • The docs mention this:

    The InlineAsmOp mirrors the underlying LLVM semantics with a notable exception: the embedded asm_string is not allowed to define or reference any symbol or any global variable: only the operands of the op may be read, written, or referenced. Attempting to define or reference any symbol or any global behavior is considered undefined behavior at this time.

    I'm assuming this means that this constraint is never actually checked/verified 😅 ?

  • There's an additional attribute to select the inline assembly dialect (not dialect in context of MLIR, choices are AT&T or Intel). I just implemented this as an IntegerAttr, is that okay? It looked like Linkage (prior to this PR) was/is implemented differently from upstream in a similar way?

Currently I have only implemented round-trip tests.

Happy to add any other tests if required.

CC @jorendumoulin

@JosseVanDelm JosseVanDelm added enhancement New feature or request dialects Changes on the dialects labels Feb 21, 2024
@JosseVanDelm JosseVanDelm self-assigned this Feb 21, 2024
@superlopuh
Copy link
Member

Can you please add a test for the roundtrip with MLIR?

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (91a79f2) 89.44% compared to head (c8344e5) 89.45%.
Report is 6 commits behind head on main.

Files Patch % Lines
xdsl/dialects/llvm.py 64.70% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2203      +/-   ##
==========================================
+ Coverage   89.44%   89.45%   +0.01%     
==========================================
  Files         319      322       +3     
  Lines       38709    38770      +61     
  Branches     5736     5742       +6     
==========================================
+ Hits        34623    34683      +60     
- Misses       3282     3289       +7     
+ Partials      804      798       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding this!

@JosseVanDelm
Copy link
Collaborator Author

Added @superlopuh !

Comment on lines +756 to +762
"asm_dialect": IntegerAttr.from_int_and_width(asm_dialect, 64),
}
if has_side_effects:
props["has_side_effects"] = UnitAttr()
if is_align_stack:
props["is_align_stack"] = UnitAttr()

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"asm_dialect": IntegerAttr.from_int_and_width(asm_dialect, 64),
}
if has_side_effects:
props["has_side_effects"] = UnitAttr()
if is_align_stack:
props["is_align_stack"] = UnitAttr()
"asm_dialect": IntegerAttr.from_int_and_width(asm_dialect, 64),
"has_side_effects": UnitAttr() if has_side_effects else None,
"is_align_stack": UnitAttr() if is_align_stack else None,
}

Copy link
Member

Choose a reason for hiding this comment

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

can then probably move the dict literal into the super init call

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pyright throws an error if I do that, cause props is not allowed to have a None as value in the dictionary.
I've seen some other shorthands here, but just like the poster here I prefer the original code:
https://stackoverflow.com/questions/14263872/only-add-to-a-dict-if-a-condition-is-met

Copy link
Member

Choose a reason for hiding this comment

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

Wait a second, properties can't be missing, can you please check that in MLIR these are properties and not attributes by printing the generic syntax?

xdsl/dialects/llvm.py Outdated Show resolved Hide resolved
@JosseVanDelm JosseVanDelm merged commit 0be2ab3 into main Feb 22, 2024
10 checks passed
@JosseVanDelm JosseVanDelm deleted the Josse/add-inline-asm branch February 22, 2024 09:12
JosseVanDelm added a commit that referenced this pull request Feb 22, 2024
@superlopuh pointed out that #2203 contains an erroneous implementation
of a UnitAttr being implemented as properties. This is incorrect, since
upstream prints the UnitAttrs as attributes and properties.
It was a bit confusing because some other ops in the LLVM dialect have
the same mistake right now.
This happens under the radar because in testing, properties are printed
as attributes.
This PR fixes the inline_asm operation.
superlopuh pushed a commit that referenced this pull request Feb 22, 2024
This PR adds the LLVM InlineAsm op, which allows to bake in
inline assembly from within MLIR.

There's an additional attribute to select the inline assembly dialect
(not dialect in context of MLIR, choices are AT&T or Intel). I just
implemented this as an `IntegerAttr`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants