Skip to content

C++/C#: generate IR for funcs excluded in PrintIR #2975

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

Merged
merged 7 commits into from
Mar 25, 2020

Conversation

rdmarsh2
Copy link
Contributor

@rdmarsh2 rdmarsh2 commented Mar 3, 2020

Previously, functions excluded from PrintIR would not have IR
generated. This sometimes affected escape analysis of functions that
were printed.

Previously, functions excluded from PrintIR would not have IR
generated. This sometimes affected escacpe analysis of functions that
were printed.
@rdmarsh2 rdmarsh2 added the C++ label Mar 3, 2020
@rdmarsh2 rdmarsh2 requested review from a team as code owners March 3, 2020 22:52
@jbj
Copy link
Contributor

jbj commented Mar 4, 2020

We could still have the exclusion in place for raw, right?

@dbartol
Copy link

dbartol commented Mar 4, 2020

@jbj We could, but I'm not sure it's worth making the PrintIR queries diverge depending on the IR flavor.

dbartol
dbartol previously approved these changes Mar 4, 2020
Copy link

@dbartol dbartol left a comment

Choose a reason for hiding this comment

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

LGTM
I'll wait to merge until later today to allow for further discussion.

Copy link

@dbartol dbartol left a comment

Choose a reason for hiding this comment

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

Wait a minute. @rdmarsh2, can you compare PrintIR performance before and after on Wireshark, printing a single function? One of the original motivations for skipping IR construction was to reduce the cost of computing toString() for every instruction, opera day, etc.

@rdmarsh2
Copy link
Contributor Author

rdmarsh2 commented Mar 4, 2020

I can. I'm sure it will be much slower, but my personal preference would be to speed it up explicitly rather than have implicit differences between the printed IR and the IR that queries are using.

@rdmarsh2
Copy link
Contributor Author

rdmarsh2 commented Mar 4, 2020

Looks like it still tries to generate strings for everything... I let it run for 2 hours and it stalled out in a toString predicate.

@dbartol
Copy link

dbartol commented Mar 10, 2020

@rdmarsh2 Maybe some manual magic on the relevant string predicates would help? We really only need those strings for the IR that we're actually printing.

I'm certainly willing to pay the price of constructing all of the IR itself, even if that's significant.

@rdmarsh2
Copy link
Contributor Author

I'd hoped to get buy-in for evaluating the whole IR during yesterday's meeting but we didn't get to it. I'll go ahead and experiment with manual magic.

@rdmarsh2
Copy link
Contributor Author

Timings on Wireshark to dump IR for a single function with the new changes, after IR evaluation:

[2020-03-11 11:32:59] (201s) Query done
[2020-03-11 11:32:59] (201s) Total timings for execution:
[2020-03-11 11:32:59] (201s) 	- Extensionals: 0ms
[2020-03-11 11:32:59] (201s) 	- Intensionals: 7min47.586s ... of which ...
[2020-03-11 11:32:59] (201s) 		- Nonrecursive intensionals: 6min42.709s
[2020-03-11 11:32:59] (201s) 		- Recursive intensionals: 1min4.876s ... of which ...
[2020-03-11 11:32:59] (201s) 			- Taking deltas: 58.928s
[2020-03-11 11:32:59] (201s) 			- Committing results: 5.948s
[2020-03-11 11:32:59] (201s) 	- Building results: 0ms
[2020-03-11 11:32:59] (201s) Clause timing report:
[2020-03-11 11:32:59] (201s) 
[2020-03-11 11:32:59] 
	PrintIRRestricted.ql-18:Instruction::Instruction::toString_dispred#ff ............................................. 1m8s
	PrintIRRestricted.ql-18:project#IRBlock::Cached::getInstruction#3#2 ............................................... 37.3s
	PrintIRRestricted.ql-18:Type::internalSpecString#bff .............................................................. 36.4s (executed 47 times)
	PrintIRRestricted.ql-18:Operand::Operand::getDefinitionOverlap_dispred#3#ff ....................................... 32.3s
	PrintIRRestricted.ql-18:Instruction::Instruction::getResultId_dispred#ff .......................................... 27.5s
	PrintIRRestricted.ql-18:Operand::NonPhiOperand#3#ffff_30#join_rhs ................................................. 26s
	PrintIRRestricted.ql-18:IRVariable::IRGeneratedVariable::getLocationString_dispred#3#ff ........................... 24.3s
	PrintIRRestricted.ql-18:project#IRBlock::Cached::getInstruction#3 ................................................. 20.8s
	PrintIRRestricted.ql-18:Instruction::Instruction::getImmediateString_dispred#ff ................................... 15.7s
	PrintIRRestricted.ql-18:Operand::Operand::isDefinitionInexact_dispred#f#antijoin_rhs .............................. 14.3s
	PrintIRRestricted.ql-18:Instruction::Instruction::isResultModeled_dispred#f ....................................... 14.3s
	PrintIRRestricted.ql-18:Operand::Operand::getAnyDef_dispred#3#ff .................................................. 12.6s
	PrintIRRestricted.ql-18:Print::DumpFunction::getDeclaratorSuffixBeforeQualifiers_dispred#bf ....................... 11.7s (executed 38 times)
	PrintIRRestricted.ql-18:Operand::Operand::getDumpString_dispred#ff ................................................ 11.2s
	PrintIRRestricted.ql-18:Instruction::Instruction::toString_dispred#ff#shared ...................................... 11.1s
	PrintIRRestricted.ql-18:project#Operand::Operand::getDumpSortOrder_dispred#ff ..................................... 9.8s
	PrintIRRestricted.ql-18:Operand::Operand::getInexactSpecifier_dispred#ff .......................................... 9.2s
	PrintIRRestricted.ql-18:Operand::Operand::getDumpLabel_dispred#ff ................................................. 9s
	PrintIRRestricted.ql-18:Instruction::Instruction::getDisplayIndexInBlock_dispred#ff ............................... 7.8s
	PrintIRRestricted.ql-18:IRBlock::IRBlockBase::getAnInstruction_dispred#3#ff ....................................... 5.2s
	PrintIRRestricted.ql-18:Operand::Operand::isDefinitionInexact_dispred#f ........................................... 4.7s
	PrintIRRestricted.ql-18:IRVariable::IRVariable::toString_dispred#ff ............................................... 4.2s
	PrintIRRestricted.ql-18:Operand::TRegisterOperand#3#ffff_3#join_rhs ............................................... 4s
	PrintIRRestricted.ql-18:IRFunction::IRFunction::toString_dispred#ff ............................................... 3.4s
	PrintIRRestricted.ql-18:Print::DumpType::getDeclaratorPrefix_dispred#ff ........................................... 3.4s (executed 38 times)
	PrintIRRestricted.ql-18:Print::DumpFunction::getIdentityString_dispred#bf ......................................... 3s (executed 37 times)
	PrintIRRestricted.ql-18:Print::DumpType::getDeclaratorSuffixBeforeQualifiers_dispred#ff ........................... 2.8s (executed 39 times)
	PrintIRRestricted.ql-18:project#Instruction::Instruction::getImmediateString_dispred#ff ........................... 2.8s
	PrintIRRestricted.ql-18:dom#EdgeKind::TCaseEdge#ff ................................................................ 2.7s
	PrintIRRestricted.ql-18:Type::internalSpecString#bff_021#join_rhs ................................................. 2.7s
	PrintIRRestricted.ql-18:IRCppLanguage::getStringLiteralText#ff .................................................... 2.4s
	PrintIRRestricted.ql-18:Print::DumpType::getTypeIdentityString_dispred#ff ......................................... 2.3s (executed 38 times)
	PrintIRRestricted.ql-18:CppType::CppType::toString_dispred#ff ..................................................... 2.1s
	PrintIRRestricted.ql-18:CppType::CppType::getDumpString_dispred#ff ................................................ 2s
	PrintIRRestricted.ql-18:Print::UserDumpType::getIdentityString_dispred#ff ......................................... 1.6s (executed 34 times)
	PrintIRRestricted.ql-18:project#Expr::Expr::getValueTextFollowingConversions#bf ................................... 1.6s
	PrintIRRestricted.ql-18:PrintIR::getSuccessorIndex#fff ............................................................ 1.5s
	PrintIRRestricted.ql-18:Print::getScopePrefix#bf .................................................................. 1.3s (executed 35 times)
	PrintIRRestricted.ql-18:UserType::UserType::getSimpleName_dispred#ff .............................................. 1.1s
	PrintIRRestricted.ql-18:Print::DumpFunction::getDeclaratorSuffixBeforeQualifiers_dispred#bf#loop_invariant_prefix . 960ms
	PrintIRRestricted.ql-18:IRBlock::Cached::blockSuccessor#6#fff_102#join_rhs ........................................ 960ms
	PrintIRRestricted.ql-18:PrintIR::getSuccessorIndex#fff#rank_range ................................................. 794ms
	PrintIRRestricted.ql-18:PrintIR::getSuccessorIndex#fff#rank_term .................................................. 779ms
	PrintIRRestricted.ql-18:Print::DumpFunction::getDeclaratorSuffixBeforeQualifiers_dispred#bf#join_rhs .............. 765ms
	PrintIRRestricted.ql-18:Instruction::PointerArithmeticInstruction#class#3#ff ...................................... 729ms
	PrintIRRestricted.ql-18:Print::DumpFunction::getDeclaratorSuffix_dispred#bf ....................................... 674ms (executed 36 times)
	PrintIRRestricted.ql-18:Instruction::SideEffectInstruction#class#3#f .............................................. 597ms
	PrintIRRestricted.ql-18:Print::DumpType::getDeclaratorSuffix_dispred#ff ........................................... 582ms (executed 36 times)
	PrintIRRestricted.ql-18:Instruction::Instruction::getResultIRType_dispred#3#fb_0#antijoin_rhs ..................... 572ms
	PrintIRRestricted.ql-18:Expr::Expr::getValueText_dispred#bf ....................................................... 567ms

Copy link

@dbartol dbartol left a comment

Choose a reason for hiding this comment

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

LGTM

I fixed the formatting failure, and everything else looks good, including the perf numbers.

@@ -307,13 +310,20 @@ class Instruction extends Construction::TInstruction {
result = getResultString() + " = " + getOperationString() + " " + getOperandsString()
}

predicate shouldGenerateDumpStrings() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
predicate shouldGenerateDumpStrings() {
private predicate shouldGenerateDumpStrings() {

Copy link

Choose a reason for hiding this comment

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

Oops, missed this before I merged. I'll fix in another PR immediately.

@dbartol dbartol merged commit 3767794 into github:master Mar 25, 2020
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.

3 participants