mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
CPP: Improve performance of IR debugging
This commit is contained in:
@@ -8,6 +8,22 @@ private import internal.IRBlockImports as Imports
|
|||||||
import Imports::EdgeKind
|
import Imports::EdgeKind
|
||||||
private import Cached
|
private import Cached
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds if `block` is a block in `func` and `sortOverride`, `sortKey1`, and `sortKey2` are the
|
||||||
|
* sort keys of the block (derived from its first instruction)
|
||||||
|
*/
|
||||||
|
pragma[nomagic]
|
||||||
|
private predicate blockSortKeys(
|
||||||
|
IRFunction func, IRBlockBase block, int sortOverride, int sortKey1, int sortKey2
|
||||||
|
) {
|
||||||
|
block.getEnclosingIRFunction() = func and
|
||||||
|
block.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
||||||
|
// Ensure that the block containing `EnterFunction` always comes first.
|
||||||
|
if block.getFirstInstruction() instanceof EnterFunctionInstruction
|
||||||
|
then sortOverride = 0
|
||||||
|
else sortOverride = 1
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
||||||
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
||||||
@@ -37,17 +53,14 @@ class IRBlockBase extends TIRBlock {
|
|||||||
exists(IRConfiguration::IRConfiguration config |
|
exists(IRConfiguration::IRConfiguration config |
|
||||||
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
||||||
) and
|
) and
|
||||||
|
exists(IRFunction func |
|
||||||
this =
|
this =
|
||||||
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
||||||
funcBlock.getEnclosingFunction() = this.getEnclosingFunction() and
|
blockSortKeys(func, funcBlock, sortOverride, sortKey1, sortKey2)
|
||||||
funcBlock.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
|
||||||
// Ensure that the block containing `EnterFunction` always comes first.
|
|
||||||
if funcBlock.getFirstInstruction() instanceof EnterFunctionInstruction
|
|
||||||
then sortOverride = 0
|
|
||||||
else sortOverride = 1
|
|
||||||
|
|
|
|
||||||
funcBlock order by sortOverride, sortKey1, sortKey2
|
funcBlock order by sortOverride, sortKey1, sortKey2
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -116,14 +116,14 @@ class Instruction extends Construction::TStageInstruction {
|
|||||||
|
|
||||||
private int getLineRank() {
|
private int getLineRank() {
|
||||||
this.shouldGenerateDumpStrings() and
|
this.shouldGenerateDumpStrings() and
|
||||||
|
exists(IRFunction enclosing, Language::File file, int line |
|
||||||
this =
|
this =
|
||||||
rank[result](Instruction instr |
|
rank[result](Instruction instr |
|
||||||
instr =
|
instr = getAnInstructionAtLine(enclosing, file, line)
|
||||||
getAnInstructionAtLine(this.getEnclosingIRFunction(), this.getLocation().getFile(),
|
|
||||||
this.getLocation().getStartLine())
|
|
||||||
|
|
|
|
||||||
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ private import internal.IRBlockImports as Imports
|
|||||||
import Imports::EdgeKind
|
import Imports::EdgeKind
|
||||||
private import Cached
|
private import Cached
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds if `block` is a block in `func` and `sortOverride`, `sortKey1`, and `sortKey2` are the
|
||||||
|
* sort keys of the block (derived from its first instruction)
|
||||||
|
*/
|
||||||
|
pragma[nomagic]
|
||||||
|
private predicate blockSortKeys(
|
||||||
|
IRFunction func, IRBlockBase block, int sortOverride, int sortKey1, int sortKey2
|
||||||
|
) {
|
||||||
|
block.getEnclosingIRFunction() = func and
|
||||||
|
block.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
||||||
|
// Ensure that the block containing `EnterFunction` always comes first.
|
||||||
|
if block.getFirstInstruction() instanceof EnterFunctionInstruction
|
||||||
|
then sortOverride = 0
|
||||||
|
else sortOverride = 1
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
||||||
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
||||||
@@ -37,17 +53,14 @@ class IRBlockBase extends TIRBlock {
|
|||||||
exists(IRConfiguration::IRConfiguration config |
|
exists(IRConfiguration::IRConfiguration config |
|
||||||
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
||||||
) and
|
) and
|
||||||
|
exists(IRFunction func |
|
||||||
this =
|
this =
|
||||||
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
||||||
funcBlock.getEnclosingFunction() = this.getEnclosingFunction() and
|
blockSortKeys(func, funcBlock, sortOverride, sortKey1, sortKey2)
|
||||||
funcBlock.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
|
||||||
// Ensure that the block containing `EnterFunction` always comes first.
|
|
||||||
if funcBlock.getFirstInstruction() instanceof EnterFunctionInstruction
|
|
||||||
then sortOverride = 0
|
|
||||||
else sortOverride = 1
|
|
||||||
|
|
|
|
||||||
funcBlock order by sortOverride, sortKey1, sortKey2
|
funcBlock order by sortOverride, sortKey1, sortKey2
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -116,14 +116,14 @@ class Instruction extends Construction::TStageInstruction {
|
|||||||
|
|
||||||
private int getLineRank() {
|
private int getLineRank() {
|
||||||
this.shouldGenerateDumpStrings() and
|
this.shouldGenerateDumpStrings() and
|
||||||
|
exists(IRFunction enclosing, Language::File file, int line |
|
||||||
this =
|
this =
|
||||||
rank[result](Instruction instr |
|
rank[result](Instruction instr |
|
||||||
instr =
|
instr = getAnInstructionAtLine(enclosing, file, line)
|
||||||
getAnInstructionAtLine(this.getEnclosingIRFunction(), this.getLocation().getFile(),
|
|
||||||
this.getLocation().getStartLine())
|
|
||||||
|
|
|
|
||||||
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -423,7 +423,12 @@ private module CachedForDebugging {
|
|||||||
cached
|
cached
|
||||||
predicate instructionHasSortKeys(Instruction instruction, int key1, int key2) {
|
predicate instructionHasSortKeys(Instruction instruction, int key1, int key2) {
|
||||||
key1 = getInstructionTranslatedElement(instruction).getId() and
|
key1 = getInstructionTranslatedElement(instruction).getId() and
|
||||||
getInstructionTag(instruction) =
|
getInstructionTag(instruction) = tagByRank(key2)
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma[nomagic]
|
||||||
|
private InstructionTag tagByRank(int key2) {
|
||||||
|
result =
|
||||||
rank[key2](InstructionTag tag, string tagId |
|
rank[key2](InstructionTag tag, string tagId |
|
||||||
tagId = getInstructionTagId(tag)
|
tagId = getInstructionTagId(tag)
|
||||||
|
|
|
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ private import internal.IRBlockImports as Imports
|
|||||||
import Imports::EdgeKind
|
import Imports::EdgeKind
|
||||||
private import Cached
|
private import Cached
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds if `block` is a block in `func` and `sortOverride`, `sortKey1`, and `sortKey2` are the
|
||||||
|
* sort keys of the block (derived from its first instruction)
|
||||||
|
*/
|
||||||
|
pragma[nomagic]
|
||||||
|
private predicate blockSortKeys(
|
||||||
|
IRFunction func, IRBlockBase block, int sortOverride, int sortKey1, int sortKey2
|
||||||
|
) {
|
||||||
|
block.getEnclosingIRFunction() = func and
|
||||||
|
block.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
||||||
|
// Ensure that the block containing `EnterFunction` always comes first.
|
||||||
|
if block.getFirstInstruction() instanceof EnterFunctionInstruction
|
||||||
|
then sortOverride = 0
|
||||||
|
else sortOverride = 1
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
||||||
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
||||||
@@ -37,17 +53,14 @@ class IRBlockBase extends TIRBlock {
|
|||||||
exists(IRConfiguration::IRConfiguration config |
|
exists(IRConfiguration::IRConfiguration config |
|
||||||
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
||||||
) and
|
) and
|
||||||
|
exists(IRFunction func |
|
||||||
this =
|
this =
|
||||||
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
||||||
funcBlock.getEnclosingFunction() = this.getEnclosingFunction() and
|
blockSortKeys(func, funcBlock, sortOverride, sortKey1, sortKey2)
|
||||||
funcBlock.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
|
||||||
// Ensure that the block containing `EnterFunction` always comes first.
|
|
||||||
if funcBlock.getFirstInstruction() instanceof EnterFunctionInstruction
|
|
||||||
then sortOverride = 0
|
|
||||||
else sortOverride = 1
|
|
||||||
|
|
|
|
||||||
funcBlock order by sortOverride, sortKey1, sortKey2
|
funcBlock order by sortOverride, sortKey1, sortKey2
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -116,14 +116,14 @@ class Instruction extends Construction::TStageInstruction {
|
|||||||
|
|
||||||
private int getLineRank() {
|
private int getLineRank() {
|
||||||
this.shouldGenerateDumpStrings() and
|
this.shouldGenerateDumpStrings() and
|
||||||
|
exists(IRFunction enclosing, Language::File file, int line |
|
||||||
this =
|
this =
|
||||||
rank[result](Instruction instr |
|
rank[result](Instruction instr |
|
||||||
instr =
|
instr = getAnInstructionAtLine(enclosing, file, line)
|
||||||
getAnInstructionAtLine(this.getEnclosingIRFunction(), this.getLocation().getFile(),
|
|
||||||
this.getLocation().getStartLine())
|
|
||||||
|
|
|
|
||||||
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ private import internal.IRBlockImports as Imports
|
|||||||
import Imports::EdgeKind
|
import Imports::EdgeKind
|
||||||
private import Cached
|
private import Cached
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds if `block` is a block in `func` and `sortOverride`, `sortKey1`, and `sortKey2` are the
|
||||||
|
* sort keys of the block (derived from its first instruction)
|
||||||
|
*/
|
||||||
|
pragma[nomagic]
|
||||||
|
private predicate blockSortKeys(
|
||||||
|
IRFunction func, IRBlockBase block, int sortOverride, int sortKey1, int sortKey2
|
||||||
|
) {
|
||||||
|
block.getEnclosingIRFunction() = func and
|
||||||
|
block.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
||||||
|
// Ensure that the block containing `EnterFunction` always comes first.
|
||||||
|
if block.getFirstInstruction() instanceof EnterFunctionInstruction
|
||||||
|
then sortOverride = 0
|
||||||
|
else sortOverride = 1
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
||||||
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
||||||
@@ -37,17 +53,14 @@ class IRBlockBase extends TIRBlock {
|
|||||||
exists(IRConfiguration::IRConfiguration config |
|
exists(IRConfiguration::IRConfiguration config |
|
||||||
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
||||||
) and
|
) and
|
||||||
|
exists(IRFunction func |
|
||||||
this =
|
this =
|
||||||
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
||||||
funcBlock.getEnclosingFunction() = this.getEnclosingFunction() and
|
blockSortKeys(func, funcBlock, sortOverride, sortKey1, sortKey2)
|
||||||
funcBlock.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
|
||||||
// Ensure that the block containing `EnterFunction` always comes first.
|
|
||||||
if funcBlock.getFirstInstruction() instanceof EnterFunctionInstruction
|
|
||||||
then sortOverride = 0
|
|
||||||
else sortOverride = 1
|
|
||||||
|
|
|
|
||||||
funcBlock order by sortOverride, sortKey1, sortKey2
|
funcBlock order by sortOverride, sortKey1, sortKey2
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -116,14 +116,14 @@ class Instruction extends Construction::TStageInstruction {
|
|||||||
|
|
||||||
private int getLineRank() {
|
private int getLineRank() {
|
||||||
this.shouldGenerateDumpStrings() and
|
this.shouldGenerateDumpStrings() and
|
||||||
|
exists(IRFunction enclosing, Language::File file, int line |
|
||||||
this =
|
this =
|
||||||
rank[result](Instruction instr |
|
rank[result](Instruction instr |
|
||||||
instr =
|
instr = getAnInstructionAtLine(enclosing, file, line)
|
||||||
getAnInstructionAtLine(this.getEnclosingIRFunction(), this.getLocation().getFile(),
|
|
||||||
this.getLocation().getStartLine())
|
|
||||||
|
|
|
|
||||||
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ private import internal.IRBlockImports as Imports
|
|||||||
import Imports::EdgeKind
|
import Imports::EdgeKind
|
||||||
private import Cached
|
private import Cached
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds if `block` is a block in `func` and `sortOverride`, `sortKey1`, and `sortKey2` are the
|
||||||
|
* sort keys of the block (derived from its first instruction)
|
||||||
|
*/
|
||||||
|
pragma[nomagic]
|
||||||
|
private predicate blockSortKeys(
|
||||||
|
IRFunction func, IRBlockBase block, int sortOverride, int sortKey1, int sortKey2
|
||||||
|
) {
|
||||||
|
block.getEnclosingIRFunction() = func and
|
||||||
|
block.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
||||||
|
// Ensure that the block containing `EnterFunction` always comes first.
|
||||||
|
if block.getFirstInstruction() instanceof EnterFunctionInstruction
|
||||||
|
then sortOverride = 0
|
||||||
|
else sortOverride = 1
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
|
||||||
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
|
||||||
@@ -37,17 +53,14 @@ class IRBlockBase extends TIRBlock {
|
|||||||
exists(IRConfiguration::IRConfiguration config |
|
exists(IRConfiguration::IRConfiguration config |
|
||||||
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
|
||||||
) and
|
) and
|
||||||
|
exists(IRFunction func |
|
||||||
this =
|
this =
|
||||||
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
|
||||||
funcBlock.getEnclosingFunction() = this.getEnclosingFunction() and
|
blockSortKeys(func, funcBlock, sortOverride, sortKey1, sortKey2)
|
||||||
funcBlock.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
|
|
||||||
// Ensure that the block containing `EnterFunction` always comes first.
|
|
||||||
if funcBlock.getFirstInstruction() instanceof EnterFunctionInstruction
|
|
||||||
then sortOverride = 0
|
|
||||||
else sortOverride = 1
|
|
||||||
|
|
|
|
||||||
funcBlock order by sortOverride, sortKey1, sortKey2
|
funcBlock order by sortOverride, sortKey1, sortKey2
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -116,14 +116,14 @@ class Instruction extends Construction::TStageInstruction {
|
|||||||
|
|
||||||
private int getLineRank() {
|
private int getLineRank() {
|
||||||
this.shouldGenerateDumpStrings() and
|
this.shouldGenerateDumpStrings() and
|
||||||
|
exists(IRFunction enclosing, Language::File file, int line |
|
||||||
this =
|
this =
|
||||||
rank[result](Instruction instr |
|
rank[result](Instruction instr |
|
||||||
instr =
|
instr = getAnInstructionAtLine(enclosing, file, line)
|
||||||
getAnInstructionAtLine(this.getEnclosingIRFunction(), this.getLocation().getFile(),
|
|
||||||
this.getLocation().getStartLine())
|
|
||||||
|
|
|
|
||||||
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
|
||||||
)
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user