-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C++/C#: Remove Instruction::getResultType()
and friends
#2217
base: main
Are you sure you want to change the base?
Conversation
Now that the language-neutral IR type system is in place, this PR gets rid of the language-specific IR type APIs that caused the original problem. I've fixed up a fair bit of code to avoid these, including range analysis and sign analysis. These last two are almost shareable between C# and C++ now that they depend on `IRType`, but I haven't done the actual work to officially share them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -799,11 +758,13 @@ class ConstantInstruction extends ConstantValueInstruction { | |||
} | |||
|
|||
class IntegerConstantInstruction extends ConstantInstruction { | |||
IntegerConstantInstruction() { getResultType() instanceof Language::IntegralType } | |||
IntegerConstantInstruction() { | |||
getResultIRType() instanceof IRIntegerType or getResultIRType() instanceof IRBooleanType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A line break would make this clearer.
The qlformat test is failing. |
i.getResultType() instanceof IntegralType or | ||
i.getResultType() instanceof PointerType | ||
i.getResultIRType() instanceof IRIntegerType or | ||
i.getResultIRType() instanceof IRAddressType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to use the range analysis library to validate an index into a stack-allocated array, and I found that it didn't work. After a long debugging session, I figured out that it was because this predicate and SafeCastInstruction
didn't treat a glvalue as a pointer, so a local variable subjected to array-to-pointer decay would not become a Bound
. After I'd fixed that, I remembered this PR and came back here to discover that this innocent-looking change also has exactly that effect! So that's good.
The question is now what it means for performance that all variable addresses are now Bound
s. @rdmarsh2, what do you think about these changes to the range analysis library? @dave-bartolomeo, please check how performance and size of boundedInstruction
change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For local variables with an array type or a struct type with an array member, that should be an improvement. I'm a bit nervous about the performance implications of all variable addresses being bounds. It should have a bigger impact on the size of boundedInstruction
than on the time to compute the stage, but that means the performance hit will come from users of the library rather than the library itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No concerns from the C# side.
} | ||
|
||
class FloatConstantInstruction extends ConstantInstruction { | ||
FloatConstantInstruction() { getResultType() instanceof Language::FloatingPointType } | ||
FloatConstantInstruction() { getResultIRType() instanceof IRFloatingPointType } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would tend to prefer this.getResultIRType()
here and elsewhere.
@dbartol A friendly reminder that this PR is needed by @Cornelius-Riemenschneider for his project of extending the range analysis to be interprocedural. |
Any update on this? |
Now that the language-neutral IR type system is in place, this PR gets rid of the language-specific IR type APIs that caused the original problem. I've fixed up a fair bit of code to avoid these, including range analysis and sign analysis. These last two are almost shareable between C# and C++ now that they depend on
IRType
, but I haven't done the actual work to officially share them.