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++: Remove some IndirectOperand and IndirectInstruction nodes #11218

Open
wants to merge 6 commits into
base: mathiasvp/replace-ast-with-ir-use-usedataflow
Choose a base branch
from

Conversation

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Nov 10, 2022

Consider the IR for this simple function:

void test() {
  int x = source();
  sink(x);
}

this has the following IR:

4| void test()
4|   Block 0
4|     v4_1(void)           = EnterFunction           :
4|     m4_2(unknown)        = AliasedDefinition       :
4|     m4_3(unknown)        = InitializeNonLocal      :
4|     m4_4(unknown)        = Chi                     : total:m4_2, partial:m4_3
5|     r5_1(glval<int>)     = VariableAddress[x]      :
5|     r5_2(glval<unknown>) = FunctionAddress[source] :
5|     r5_3(int)            = Call[source]            : func:r5_2
5|     m5_4(unknown)        = ^CallSideEffect         : ~m4_4
5|     m5_5(unknown)        = Chi                     : total:m4_4, partial:m5_4
5|     m5_6(int)            = Store[x]                : &:r5_1, r5_3
6|     r6_1(glval<unknown>) = FunctionAddress[sink]   :
6|     r6_2(glval<int>)     = VariableAddress[x]      :
6|     r6_3(int)            = Load[x]                 : &:r6_2, m5_6
6|     v6_4(void)           = Call[sink]              : func:r6_1, 0:r6_3
6|     m6_5(unknown)        = ^CallSideEffect         : ~m5_5
6|     m6_6(unknown)        = Chi                     : total:m5_5, partial:m6_5
7|     v7_1(void)           = NoOp                    :
4|     v4_5(void)           = ReturnVoid              :
4|     v4_6(void)           = AliasedUse              : ~m6_6
4|     v4_7(void)           = ExitFunction            :

Currently, we generate an SSA write to the IndirectOperand of &:r5_1, and SSA then flows from that node to the IndirectOperand for &:r6_2. Flow then continues from that node, through the LoadInstruction and into the IR operand 0:r6_3.

That's kinda unnecessary. Instead of flowing to these IndirectOperand, we might as well just reuse the IR operands (and instructions) where appropriate. This is what this PR does. For the above example, that means that IndirectOperand(&:r6_2) is represented by the 0:r6_3 operand node.

Note that we still need the IndirectOperands for things like:

void test() {
  int x = source();
  int* px = &x;
  sink(*px);
}

which require some non-trivial flow through indirect dataflow nodes in order to reach *px.

A nice side-effect of this (which is really why the real goal of this PR) is that our existing InstructionBarrierGuard barrier now works as expected on the feature branch (since the nodes you want to select are now backed by instructions and operands in most cases). This makes our existing barrier guard tests pass again 🎉

Commit-by-commit review recommended!

I've checked the query result changes. They're all either:

  • Fixing of FPs (because we now correctly identify some barriers that we didn't identify before)
  • New TPs (🎉)
  • Result duplication (😭)

@MathiasVP MathiasVP requested a review from a team as a code owner Nov 10, 2022
@github-actions github-actions bot added the C++ label Nov 10, 2022
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Nov 10, 2022
MathiasVP added 6 commits Nov 11, 2022
…d 'IndirectOperand' when the semantically identical value already exists in the IR.
…truction before we should pick the operand as the 'sink' in the call-target resolution recursion.
…he qualifier of a call (and not just when it's an argument of a call).
@MathiasVP MathiasVP force-pushed the merge-some-indirect-and-instruction-nodes branch from 282cf2f to 0c7f57e Compare Nov 11, 2022
@MathiasVP MathiasVP requested a review from rdmarsh2 Nov 11, 2022
@MathiasVP
Copy link
Contributor Author

MathiasVP commented Nov 11, 2022

I've looked through the result changes on DCA: the Samate ones are all TPs, and the lost results on cpp/uncontrolled-allocation-size query are because we're now correctly using the sanitizers in the query 🎉.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant