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

C++/C#: Remove Instruction::getResultType() and friends #2217

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dave-bartolomeo
Copy link
Contributor

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.

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.
Copy link
Contributor

@jbj jbj left a 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
Copy link
Contributor

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.

@jbj
Copy link
Contributor

jbj commented Oct 29, 2019

The qlformat test is failing.

i.getResultType() instanceof IntegralType or
i.getResultType() instanceof PointerType
i.getResultIRType() instanceof IRIntegerType or
i.getResultIRType() instanceof IRAddressType
Copy link
Contributor

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 Bounds. @rdmarsh2, what do you think about these changes to the range analysis library? @dave-bartolomeo, please check how performance and size of boundedInstruction change.

Copy link
Contributor

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.

Copy link
Contributor

@calumgrant calumgrant left a 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 }
Copy link
Contributor

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.

@jbj
Copy link
Contributor

jbj commented Dec 13, 2019

@dbartol A friendly reminder that this PR is needed by @Cornelius-Riemenschneider for his project of extending the range analysis to be interprocedural.

@criemen
Copy link
Collaborator

criemen commented Jan 9, 2020

Any update on this?

@adityasharad adityasharad changed the base branch from master to main August 14, 2020 18:35
@adityasharad adityasharad requested review from a team as code owners August 14, 2020 18:35
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.

6 participants