Skip to content

C#: Refactor SSA liveness logic - #449

Merged
semmle-qlci merged 2 commits into
github:masterfrom
hvitved:csharp/ssa/live-at-rank
Nov 20, 2018
Merged

C#: Refactor SSA liveness logic#449
semmle-qlci merged 2 commits into
github:masterfrom
hvitved:csharp/ssa/live-at-rank

Conversation

@hvitved

@hvitved hvitved commented Nov 12, 2018

Copy link
Copy Markdown
Contributor

Simplify liveness analysis by avoiding the two extra copies of liveAtRank() (and other auxiliary predicates) for fields/captured variables analysis.

In addition to simplifying the logic, this also has a positive performance impact, for example:

Before:

	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::liveAtRank#ffff ........................... 5m16s (executed 13561 times)
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::updateCandidate#ffff ...................... 1m20s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::liveAfterUpdateCandidate#ff ............... 35.5s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::refRankExt#ffff#join_rhs .................. 32.1s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::refRankExt#ffff ........................... 28.7s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::refExt#fff ................................ 25s
	SsaDef.ql-13:project#SSA::Ssa::FieldOrPropsImpl::refRankExt#ffff ................... 16.5s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::refRankExt#ffff_0231#join_rhs ............. 12.4s
	SsaDef.ql-13:project#SSA::Ssa::FieldOrPropsImpl::updateCandidate#ffff .............. 12.1s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::refExt#fff_0211#rank_term ................. 11.6s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::refExt#fff_021#rank_range ................. 10.6s
	SsaDef.ql-13:project#SSA::Ssa::FieldOrPropsImpl::refRankExt#ffff_0122#max_term ..... 6s
	SsaDef.ql-13:project#SSA::Ssa::FieldOrPropsImpl::updateCandidate#ffff#2 ............ 5.6s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::liveAfterUpdateCandidate#ff_10#join_rhs ... 5.1s
	SsaDef.ql-13:SSA::Ssa::SourceVariableImpl::liveAtRank#fffff ........................ 4.6s (executed 151 times)

After:

	SsaDef.ql-13:project#SSA::Ssa::FieldOrPropsImpl::updateCandidate#ffff ....................................................................... 18.9s
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::updateCandidate#ffff ............................................................................... 6.4s
	SsaDef.ql-13:SSA::Ssa::SourceVariableImpl::liveAtRank#fffff ................................................................................. 3.6s (executed 17 times)
	SsaDef.ql-13:SSA::Ssa::FieldOrPropsImpl::updateCandidate#ffff_2301#join_rhs ................................................................. 2.8s
	SsaDef.ql-13:SSA::Ssa::SourceVariableImpl::liveAtEntry#fff .................................................................................. 2.1s (executed 310 times)

@calumgrant

Simplify liveness analysis by avoiding the two extra copies of `liveAtRank()`
(and other auxiliary predicates) for fields/captured variables analysis.
@hvitved hvitved added the C# label Nov 12, 2018
@hvitved
hvitved requested a review from calumgrant November 12, 2018 09:45
@hvitved
hvitved requested a review from a team as a code owner November 12, 2018 09:45

@calumgrant calumgrant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some minor questions, but otherwise LGTM.

/**
* Same as `ref()`, but extended to include implicit call definitions
* for fields and properties.
* Holds if source varible `v` is likely to be live at any node inside basic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Document that this is an overestimate. Perhaps liveCandidate, possiblyLive or liveInBB or something?

bb.getNode(i) = call.getAControlFlowNode() and
call.getEnclosingCallable() = fp.getEnclosingCallable() and
relevantDefinition(_, fp.getAssignable(), _)
getARuntimeTarget(call).hasBody()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is hasBody signifying?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It just makes the computation faster, as we only care about calls to methods that either call other methods or perform an update.

@semmle-qlci
semmle-qlci merged commit 4b5f24d into github:master Nov 20, 2018
@hvitved
hvitved deleted the csharp/ssa/live-at-rank branch November 20, 2018 13:01
cklin pushed a commit that referenced this pull request May 23, 2022
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