Skip to content

Commit a48235e

Browse files
authored
Merge pull request github#4730 from MathiasVP/definitionHasPhiNode-join-order-fix
C++: Fix join order in definitionHasPhiNode
2 parents edb57c2 + 5f4ad3a commit a48235e

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,28 @@ private import PhiInsertion
404404
*/
405405
private module PhiInsertion {
406406
/**
407-
* Holds if a `Phi` instruction needs to be inserted for ___location `defLocation` at the beginning of block `phiBlock`.
407+
* Holds if `phiBlock` is a block in the dominance frontier of a block that has a definition of the
408+
* memory ___location `defLocation`.
408409
*/
409-
predicate definitionHasPhiNode(Alias::MemoryLocation defLocation, OldBlock phiBlock) {
410+
pragma[noinline]
411+
private predicate dominanceFrontierOfDefinition(
412+
Alias::MemoryLocation defLocation, OldBlock phiBlock
413+
) {
410414
exists(OldBlock defBlock |
411415
phiBlock = Dominance::getDominanceFrontier(defBlock) and
412-
definitionHasDefinitionInBlock(defLocation, defBlock) and
413-
/* We can also eliminate those nodes where the definition is not live on any incoming edge */
414-
definitionLiveOnEntryToBlock(defLocation, phiBlock)
416+
definitionHasDefinitionInBlock(defLocation, defBlock)
415417
)
416418
}
417419

420+
/**
421+
* Holds if a `Phi` instruction needs to be inserted for ___location `defLocation` at the beginning of block `phiBlock`.
422+
*/
423+
predicate definitionHasPhiNode(Alias::MemoryLocation defLocation, OldBlock phiBlock) {
424+
dominanceFrontierOfDefinition(defLocation, phiBlock) and
425+
/* We can also eliminate those nodes where the definition is not live on any incoming edge */
426+
definitionLiveOnEntryToBlock(defLocation, phiBlock)
427+
}
428+
418429
/**
419430
* Holds if the memory ___location `defLocation` has a definition in block `block`, either because of an existing
420431
* instruction, a `Phi` node, or a `Chi` node.

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,28 @@ private import PhiInsertion
404404
*/
405405
private module PhiInsertion {
406406
/**
407-
* Holds if a `Phi` instruction needs to be inserted for ___location `defLocation` at the beginning of block `phiBlock`.
407+
* Holds if `phiBlock` is a block in the dominance frontier of a block that has a definition of the
408+
* memory ___location `defLocation`.
408409
*/
409-
predicate definitionHasPhiNode(Alias::MemoryLocation defLocation, OldBlock phiBlock) {
410+
pragma[noinline]
411+
private predicate dominanceFrontierOfDefinition(
412+
Alias::MemoryLocation defLocation, OldBlock phiBlock
413+
) {
410414
exists(OldBlock defBlock |
411415
phiBlock = Dominance::getDominanceFrontier(defBlock) and
412-
definitionHasDefinitionInBlock(defLocation, defBlock) and
413-
/* We can also eliminate those nodes where the definition is not live on any incoming edge */
414-
definitionLiveOnEntryToBlock(defLocation, phiBlock)
416+
definitionHasDefinitionInBlock(defLocation, defBlock)
415417
)
416418
}
417419

420+
/**
421+
* Holds if a `Phi` instruction needs to be inserted for ___location `defLocation` at the beginning of block `phiBlock`.
422+
*/
423+
predicate definitionHasPhiNode(Alias::MemoryLocation defLocation, OldBlock phiBlock) {
424+
dominanceFrontierOfDefinition(defLocation, phiBlock) and
425+
/* We can also eliminate those nodes where the definition is not live on any incoming edge */
426+
definitionLiveOnEntryToBlock(defLocation, phiBlock)
427+
}
428+
418429
/**
419430
* Holds if the memory ___location `defLocation` has a definition in block `block`, either because of an existing
420431
* instruction, a `Phi` node, or a `Chi` node.

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,28 @@ private import PhiInsertion
404404
*/
405405
private module PhiInsertion {
406406
/**
407-
* Holds if a `Phi` instruction needs to be inserted for ___location `defLocation` at the beginning of block `phiBlock`.
407+
* Holds if `phiBlock` is a block in the dominance frontier of a block that has a definition of the
408+
* memory ___location `defLocation`.
408409
*/
409-
predicate definitionHasPhiNode(Alias::MemoryLocation defLocation, OldBlock phiBlock) {
410+
pragma[noinline]
411+
private predicate dominanceFrontierOfDefinition(
412+
Alias::MemoryLocation defLocation, OldBlock phiBlock
413+
) {
410414
exists(OldBlock defBlock |
411415
phiBlock = Dominance::getDominanceFrontier(defBlock) and
412-
definitionHasDefinitionInBlock(defLocation, defBlock) and
413-
/* We can also eliminate those nodes where the definition is not live on any incoming edge */
414-
definitionLiveOnEntryToBlock(defLocation, phiBlock)
416+
definitionHasDefinitionInBlock(defLocation, defBlock)
415417
)
416418
}
417419

420+
/**
421+
* Holds if a `Phi` instruction needs to be inserted for ___location `defLocation` at the beginning of block `phiBlock`.
422+
*/
423+
predicate definitionHasPhiNode(Alias::MemoryLocation defLocation, OldBlock phiBlock) {
424+
dominanceFrontierOfDefinition(defLocation, phiBlock) and
425+
/* We can also eliminate those nodes where the definition is not live on any incoming edge */
426+
definitionLiveOnEntryToBlock(defLocation, phiBlock)
427+
}
428+
418429
/**
419430
* Holds if the memory ___location `defLocation` has a definition in block `block`, either because of an existing
420431
* instruction, a `Phi` node, or a `Chi` node.

0 commit comments

Comments
 (0)