CodeQL library for C/C++
codeql/cpp-all 2.0.1-dev (changelog, source)
Search

Module PhiInsertion

Module to handle insertion of Phi instructions at the correct blocks. We insert a Phi instruction at the beginning of a block for a given location when that block is on the dominance frontier of a definition of the location and there is a use of that location reachable from that block without an intervening definition of the location. Within the approach outlined above, we treat a location slightly differently depending on whether or not it is a virtual variable. For a virtual variable, we will insert a Phi instruction on the dominance frontier if there is a use of any member location of that virtual variable that is reachable from the Phi instruction. For a location that is not a virtual variable, we insert a Phi instruction only if there is an exactly-overlapping use of the location reachable from the Phi instruction. This ensures that we insert a Phi instruction for a non-virtual variable only if doing so would allow dataflow analysis to get a more precise result than if we just used a Phi instruction for the virtual variable as a whole.

Import path

import semmle.code.cpp.ir.implementation.aliased_ssa.internal.SSAConstruction

Predicates

definitionHasPhiNode

Holds if a Phi instruction needs to be inserted for location defLocation at the beginning of block phiBlock.

definitionLiveOnEntryToBlock

Holds if the definition defLocation is live on entry to block block. The definition is live if there is at least one use of that definition before any intervening instruction that redefines the definition location.

definitionLiveOnExitFromBlock

Holds if the definition defLocation is live on exit from block block. The definition is live on exit if it is live on entry to any of the successors of block.