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

llvm: Refactor override matching #1197

Merged
merged 5 commits into from
Apr 25, 2024

Conversation

langston-barrett
Copy link
Contributor

Figuring out whether a given override should apply to a given define
or declare in an LLVM module is not as easy as seeing if their names
match. For some C++ overrides, for example, checking if the override
should apply requires demangling the function name, which is an
expensive proposition.

For this reason, override matching happens in two "phases" in
Crucible-LLVM: first, there is an initial, fast, string-based
TemplateMatcher that is used to filter out overrides that definitely
don't apply. Then, if any remain, there is a second phase that
inspects the declaration in more detail to see if the override matches.

Previously, this second phase consisted of a RegOverrideM (i.e.,
OverrideSim) action that would actually perform the registration.
This is unnecessarily flexible. The second phase is only really supposed
to perform the inspection of the declaration, construct an override, and
register it. Therefore, it's been replaced by a pure function that
returns a Maybe (SomeLLVMOverride ...), which can then be registered
by client code, if desired.

This more restrictive type should help clarify the intent of the
override matching code, and reduce the potential for superfluous use
of OverrideSim effects.

For clarity and separate compilation.
Figuring out whether a given override should apply to a given `define`
or `declare` in an LLVM module is not as easy as seeing if their names
match. For some C++ overrides, for example, checking if the override
should apply requires demangling the function name, which is an
expensive proposition.

For this reason, override matching happens in two "phases" in
Crucible-LLVM: first, there is an initial, fast, string-based
`TemplateMatcher` that is used to filter out overrides that definitely
*don't* apply. Then, if any remain, there is a second phase that
inspects the declaration in more detail to see if the override matches.

Previously, this second phase consisted of a `RegOverrideM` (i.e.,
`OverrideSim`) action that would actually perform the registration.
This is unnecessarily flexible. The second phase is only really supposed
to perform the inspection of the declaration, construct an override, and
register it. Therefore, it's been replaced by a pure function that
returns a `Maybe (SomeLLVMOverride ...)`, which can then be registered
by client code, if desired.

This more restrictive type should help clarify the intent of the
override matching code, and reduce the potential for superfluous use
of `OverrideSim` effects.
Copy link
Contributor

@RyanGlScott RyanGlScott left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this. The override registration matching code has always made my head spin a bit, and this is a nice simplification.

Of course, do make sure to mention the API changes in the crucible-llvm changelog.

crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics.hs Outdated Show resolved Hide resolved
crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/Common.hs Outdated Show resolved Hide resolved
crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/Common.hs Outdated Show resolved Hide resolved
crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/Common.hs Outdated Show resolved Hide resolved
crucible-llvm/src/Lang/Crucible/LLVM/SymIO.hs Outdated Show resolved Hide resolved
@langston-barrett langston-barrett marked this pull request as ready for review April 25, 2024 18:11
@langston-barrett langston-barrett merged commit de3610e into GaloisInc:master Apr 25, 2024
32 checks passed
@langston-barrett langston-barrett deleted the lb/ov-matching branch April 25, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants