C++/C#: Move irFunc out of various TInstruction branches

This commit is contained in:
Dave Bartolomeo
2020-06-12 17:26:45 -04:00
parent 07c1520b4d
commit 978275cbd4
6 changed files with 106 additions and 115 deletions

View File

@@ -18,19 +18,17 @@ cached
private module Cached {
cached
predicate hasPhiInstructionCached(
IRFunction irFunc, OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
) {
exists(OldBlock oldBlock |
definitionHasPhiNode(defLocation, oldBlock) and
irFunc = oldBlock.getEnclosingIRFunction() and
blockStartInstr = oldBlock.getFirstInstruction()
)
}
cached
predicate hasChiInstructionCached(IRFunctionBase irFunc, OldInstruction primaryInstruction) {
hasChiNode(_, primaryInstruction) and
irFunc = primaryInstruction.getEnclosingIRFunction()
predicate hasChiInstructionCached(OldInstruction primaryInstruction) {
hasChiNode(_, primaryInstruction)
}
cached
@@ -44,11 +42,6 @@ private module Cached {
class TStageInstruction =
TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction;
private TRawInstruction rawInstruction(IRFunctionBase irFunc, Opcode opcode) {
result = TRawInstruction(irFunc, opcode, _, _) and
result instanceof OldInstruction
}
cached
predicate hasInstruction(TStageInstruction instr) {
instr instanceof TRawInstruction and instr instanceof OldInstruction
@@ -268,12 +261,12 @@ private module Cached {
result = getOldInstruction(instr).getAST()
or
exists(RawIR::Instruction blockStartInstr |
instr = phiInstruction(_, blockStartInstr, _) and
instr = phiInstruction(blockStartInstr, _) and
result = blockStartInstr.getAST()
)
or
exists(RawIR::Instruction primaryInstr |
instr = chiInstruction(_, primaryInstr) and
instr = chiInstruction(primaryInstr) and
result = primaryInstr.getAST()
)
or
@@ -287,12 +280,12 @@ private module Cached {
result = instr.(RawIR::Instruction).getResultLanguageType()
or
exists(Alias::MemoryLocation defLocation |
instr = phiInstruction(_, _, defLocation) and
instr = phiInstruction(_, defLocation) and
result = defLocation.getType()
)
or
exists(Instruction primaryInstr, Alias::VirtualVariable vvar |
instr = chiInstruction(_, primaryInstr) and
instr = chiInstruction(primaryInstr) and
hasChiNode(vvar, primaryInstr) and
result = vvar.getType()
)
@@ -302,22 +295,27 @@ private module Cached {
cached
Opcode getInstructionOpcode(Instruction instr) {
instr = rawInstruction(_, result)
result = getOldInstruction(instr).getOpcode()
or
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
or
instr = chiInstruction(_, _) and result instanceof Opcode::Chi
instr = chiInstruction(_) and result instanceof Opcode::Chi
or
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
}
cached
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
instr = rawInstruction(result, _)
result = getOldInstruction(instr).getEnclosingIRFunction()
or
instr = phiInstruction(result, _, _)
exists(OldInstruction blockStartInstr |
instr = phiInstruction(blockStartInstr, _) and
result = blockStartInstr.getEnclosingIRFunction()
)
or
instr = chiInstruction(result, _)
exists(OldInstruction primaryInstr |
instr = chiInstruction(primaryInstr) and result = primaryInstr.getEnclosingIRFunction()
)
or
instr = unreachedInstruction(result)
}
@@ -341,11 +339,11 @@ private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(
private OldInstruction getOldInstruction(Instruction instr) { instr = result }
private ChiInstruction getChi(OldInstruction primaryInstr) {
result = chiInstruction(_, primaryInstr)
result = chiInstruction(primaryInstr)
}
private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) {
result = phiInstruction(_, defBlock.getFirstInstruction(), defLocation)
result = phiInstruction(defBlock.getFirstInstruction(), defLocation)
}
/**
@@ -910,9 +908,9 @@ module SSAConsistency {
module SSA {
class MemoryLocation = Alias::MemoryLocation;
predicate hasPhiInstruction = Cached::hasPhiInstructionCached/3;
predicate hasPhiInstruction = Cached::hasPhiInstructionCached/2;
predicate hasChiInstruction = Cached::hasChiInstructionCached/2;
predicate hasChiInstruction = Cached::hasChiInstructionCached/1;
predicate hasUnreachedInstruction = Cached::hasUnreachedInstructionCached/1;
}

View File

@@ -15,29 +15,29 @@ private import Imports::Opcode
cached
newtype TInstruction =
TRawInstruction(
IRFunctionBase irFunc, Opcode opcode, IRConstruction::Raw::InstructionTag1 tag1,
Opcode opcode, IRConstruction::Raw::InstructionTag1 tag1,
IRConstruction::Raw::InstructionTag2 tag2
) {
IRConstruction::Raw::hasInstruction(irFunc.getFunction(), opcode, tag1, tag2)
IRConstruction::Raw::hasInstruction(opcode, tag1, tag2)
} or
TUnaliasedSSAPhiInstruction(
IRFunctionBase irFunc, TRawInstruction blockStartInstr,
TRawInstruction blockStartInstr,
UnaliasedSSA::SSA::MemoryLocation memoryLocation
) {
UnaliasedSSA::SSA::hasPhiInstruction(irFunc, blockStartInstr, memoryLocation)
UnaliasedSSA::SSA::hasPhiInstruction(blockStartInstr, memoryLocation)
} or
TUnaliasedSSAChiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) { none() } or
TUnaliasedSSAChiInstruction(TRawInstruction primaryInstruction) { none() } or
TUnaliasedSSAUnreachedInstruction(IRFunctionBase irFunc) {
UnaliasedSSA::SSA::hasUnreachedInstruction(irFunc)
} or
TAliasedSSAPhiInstruction(
IRFunctionBase irFunc, TRawInstruction blockStartInstr,
TRawInstruction blockStartInstr,
AliasedSSA::SSA::MemoryLocation memoryLocation
) {
AliasedSSA::SSA::hasPhiInstruction(irFunc, blockStartInstr, memoryLocation)
AliasedSSA::SSA::hasPhiInstruction(blockStartInstr, memoryLocation)
} or
TAliasedSSAChiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
AliasedSSA::SSA::hasChiInstruction(irFunc, primaryInstruction)
TAliasedSSAChiInstruction(TRawInstruction primaryInstruction) {
AliasedSSA::SSA::hasChiInstruction(primaryInstruction)
} or
TAliasedSSAUnreachedInstruction(IRFunctionBase irFunc) {
AliasedSSA::SSA::hasUnreachedInstruction(irFunc)
@@ -53,16 +53,16 @@ module UnaliasedSSAInstructions {
class TPhiInstruction = TUnaliasedSSAPhiInstruction;
TPhiInstruction phiInstruction(
IRFunctionBase irFunc, TRawInstruction blockStartInstr,
TRawInstruction blockStartInstr,
UnaliasedSSA::SSA::MemoryLocation memoryLocation
) {
result = TUnaliasedSSAPhiInstruction(irFunc, blockStartInstr, memoryLocation)
result = TUnaliasedSSAPhiInstruction(blockStartInstr, memoryLocation)
}
class TChiInstruction = TUnaliasedSSAChiInstruction;
TChiInstruction chiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
result = TUnaliasedSSAChiInstruction(irFunc, primaryInstruction)
TChiInstruction chiInstruction(TRawInstruction primaryInstruction) {
result = TUnaliasedSSAChiInstruction(primaryInstruction)
}
class TUnreachedInstruction = TUnaliasedSSAUnreachedInstruction;
@@ -82,16 +82,16 @@ module AliasedSSAInstructions {
class TPhiInstruction = TAliasedSSAPhiInstruction;
TPhiInstruction phiInstruction(
IRFunctionBase irFunc, TRawInstruction blockStartInstr,
TRawInstruction blockStartInstr,
AliasedSSA::SSA::MemoryLocation memoryLocation
) {
result = TAliasedSSAPhiInstruction(irFunc, blockStartInstr, memoryLocation)
result = TAliasedSSAPhiInstruction(blockStartInstr, memoryLocation)
}
class TChiInstruction = TAliasedSSAChiInstruction;
TChiInstruction chiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
result = TAliasedSSAChiInstruction(irFunc, primaryInstruction)
TChiInstruction chiInstruction(TRawInstruction primaryInstruction) {
result = TAliasedSSAChiInstruction(primaryInstruction)
}
class TUnreachedInstruction = TAliasedSSAUnreachedInstruction;

View File

@@ -15,11 +15,11 @@ private import TranslatedStmt
private import TranslatedFunction
TranslatedElement getInstructionTranslatedElement(Instruction instruction) {
instruction = TRawInstruction(_, _, result, _)
instruction = TRawInstruction(_, result, _)
}
InstructionTag getInstructionTag(Instruction instruction) {
instruction = TRawInstruction(_, _, _, result)
instruction = TRawInstruction(_, _, result)
}
pragma[noinline]
@@ -44,11 +44,8 @@ module Raw {
predicate functionHasIR(Function func) { exists(getTranslatedFunction(func)) }
cached
predicate hasInstruction(
Function func, Opcode opcode, TranslatedElement element, InstructionTag tag
) {
element.hasInstruction(opcode, tag, _) and
func = element.getFunction()
predicate hasInstruction(Opcode opcode, TranslatedElement element, InstructionTag tag) {
element.hasInstruction(opcode, tag, _)
}
cached
@@ -382,12 +379,12 @@ private module Cached {
cached
Opcode getInstructionOpcode(TStageInstruction instr) {
instr = TRawInstruction(_, result, _, _)
instr = TRawInstruction(result, _, _)
}
cached
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
instr = TRawInstruction(result, _, _, _)
result.getFunction() = getInstructionTranslatedElement(instr).getFunction()
}
cached

View File

@@ -18,19 +18,17 @@ cached
private module Cached {
cached
predicate hasPhiInstructionCached(
IRFunction irFunc, OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
) {
exists(OldBlock oldBlock |
definitionHasPhiNode(defLocation, oldBlock) and
irFunc = oldBlock.getEnclosingIRFunction() and
blockStartInstr = oldBlock.getFirstInstruction()
)
}
cached
predicate hasChiInstructionCached(IRFunctionBase irFunc, OldInstruction primaryInstruction) {
hasChiNode(_, primaryInstruction) and
irFunc = primaryInstruction.getEnclosingIRFunction()
predicate hasChiInstructionCached(OldInstruction primaryInstruction) {
hasChiNode(_, primaryInstruction)
}
cached
@@ -44,11 +42,6 @@ private module Cached {
class TStageInstruction =
TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction;
private TRawInstruction rawInstruction(IRFunctionBase irFunc, Opcode opcode) {
result = TRawInstruction(irFunc, opcode, _, _) and
result instanceof OldInstruction
}
cached
predicate hasInstruction(TStageInstruction instr) {
instr instanceof TRawInstruction and instr instanceof OldInstruction
@@ -268,12 +261,12 @@ private module Cached {
result = getOldInstruction(instr).getAST()
or
exists(RawIR::Instruction blockStartInstr |
instr = phiInstruction(_, blockStartInstr, _) and
instr = phiInstruction(blockStartInstr, _) and
result = blockStartInstr.getAST()
)
or
exists(RawIR::Instruction primaryInstr |
instr = chiInstruction(_, primaryInstr) and
instr = chiInstruction(primaryInstr) and
result = primaryInstr.getAST()
)
or
@@ -287,12 +280,12 @@ private module Cached {
result = instr.(RawIR::Instruction).getResultLanguageType()
or
exists(Alias::MemoryLocation defLocation |
instr = phiInstruction(_, _, defLocation) and
instr = phiInstruction(_, defLocation) and
result = defLocation.getType()
)
or
exists(Instruction primaryInstr, Alias::VirtualVariable vvar |
instr = chiInstruction(_, primaryInstr) and
instr = chiInstruction(primaryInstr) and
hasChiNode(vvar, primaryInstr) and
result = vvar.getType()
)
@@ -302,22 +295,27 @@ private module Cached {
cached
Opcode getInstructionOpcode(Instruction instr) {
instr = rawInstruction(_, result)
result = getOldInstruction(instr).getOpcode()
or
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
or
instr = chiInstruction(_, _) and result instanceof Opcode::Chi
instr = chiInstruction(_) and result instanceof Opcode::Chi
or
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
}
cached
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
instr = rawInstruction(result, _)
result = getOldInstruction(instr).getEnclosingIRFunction()
or
instr = phiInstruction(result, _, _)
exists(OldInstruction blockStartInstr |
instr = phiInstruction(blockStartInstr, _) and
result = blockStartInstr.getEnclosingIRFunction()
)
or
instr = chiInstruction(result, _)
exists(OldInstruction primaryInstr |
instr = chiInstruction(primaryInstr) and result = primaryInstr.getEnclosingIRFunction()
)
or
instr = unreachedInstruction(result)
}
@@ -341,11 +339,11 @@ private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(
private OldInstruction getOldInstruction(Instruction instr) { instr = result }
private ChiInstruction getChi(OldInstruction primaryInstr) {
result = chiInstruction(_, primaryInstr)
result = chiInstruction(primaryInstr)
}
private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) {
result = phiInstruction(_, defBlock.getFirstInstruction(), defLocation)
result = phiInstruction(defBlock.getFirstInstruction(), defLocation)
}
/**
@@ -910,9 +908,9 @@ module SSAConsistency {
module SSA {
class MemoryLocation = Alias::MemoryLocation;
predicate hasPhiInstruction = Cached::hasPhiInstructionCached/3;
predicate hasPhiInstruction = Cached::hasPhiInstructionCached/2;
predicate hasChiInstruction = Cached::hasChiInstructionCached/2;
predicate hasChiInstruction = Cached::hasChiInstructionCached/1;
predicate hasUnreachedInstruction = Cached::hasUnreachedInstructionCached/1;
}

View File

@@ -15,29 +15,29 @@ private import Imports::Opcode
cached
newtype TInstruction =
TRawInstruction(
IRFunctionBase irFunc, Opcode opcode, IRConstruction::Raw::InstructionTag1 tag1,
Opcode opcode, IRConstruction::Raw::InstructionTag1 tag1,
IRConstruction::Raw::InstructionTag2 tag2
) {
IRConstruction::Raw::hasInstruction(irFunc.getFunction(), opcode, tag1, tag2)
IRConstruction::Raw::hasInstruction(opcode, tag1, tag2)
} or
TUnaliasedSSAPhiInstruction(
IRFunctionBase irFunc, TRawInstruction blockStartInstr,
TRawInstruction blockStartInstr,
UnaliasedSSA::SSA::MemoryLocation memoryLocation
) {
UnaliasedSSA::SSA::hasPhiInstruction(irFunc, blockStartInstr, memoryLocation)
UnaliasedSSA::SSA::hasPhiInstruction(blockStartInstr, memoryLocation)
} or
TUnaliasedSSAChiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) { none() } or
TUnaliasedSSAChiInstruction(TRawInstruction primaryInstruction) { none() } or
TUnaliasedSSAUnreachedInstruction(IRFunctionBase irFunc) {
UnaliasedSSA::SSA::hasUnreachedInstruction(irFunc)
} or
TAliasedSSAPhiInstruction(
IRFunctionBase irFunc, TRawInstruction blockStartInstr,
TRawInstruction blockStartInstr,
AliasedSSA::SSA::MemoryLocation memoryLocation
) {
AliasedSSA::SSA::hasPhiInstruction(irFunc, blockStartInstr, memoryLocation)
AliasedSSA::SSA::hasPhiInstruction(blockStartInstr, memoryLocation)
} or
TAliasedSSAChiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
AliasedSSA::SSA::hasChiInstruction(irFunc, primaryInstruction)
TAliasedSSAChiInstruction(TRawInstruction primaryInstruction) {
AliasedSSA::SSA::hasChiInstruction(primaryInstruction)
} or
TAliasedSSAUnreachedInstruction(IRFunctionBase irFunc) {
AliasedSSA::SSA::hasUnreachedInstruction(irFunc)
@@ -53,16 +53,16 @@ module UnaliasedSSAInstructions {
class TPhiInstruction = TUnaliasedSSAPhiInstruction;
TPhiInstruction phiInstruction(
IRFunctionBase irFunc, TRawInstruction blockStartInstr,
TRawInstruction blockStartInstr,
UnaliasedSSA::SSA::MemoryLocation memoryLocation
) {
result = TUnaliasedSSAPhiInstruction(irFunc, blockStartInstr, memoryLocation)
result = TUnaliasedSSAPhiInstruction(blockStartInstr, memoryLocation)
}
class TChiInstruction = TUnaliasedSSAChiInstruction;
TChiInstruction chiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
result = TUnaliasedSSAChiInstruction(irFunc, primaryInstruction)
TChiInstruction chiInstruction(TRawInstruction primaryInstruction) {
result = TUnaliasedSSAChiInstruction(primaryInstruction)
}
class TUnreachedInstruction = TUnaliasedSSAUnreachedInstruction;
@@ -82,16 +82,16 @@ module AliasedSSAInstructions {
class TPhiInstruction = TAliasedSSAPhiInstruction;
TPhiInstruction phiInstruction(
IRFunctionBase irFunc, TRawInstruction blockStartInstr,
TRawInstruction blockStartInstr,
AliasedSSA::SSA::MemoryLocation memoryLocation
) {
result = TAliasedSSAPhiInstruction(irFunc, blockStartInstr, memoryLocation)
result = TAliasedSSAPhiInstruction(blockStartInstr, memoryLocation)
}
class TChiInstruction = TAliasedSSAChiInstruction;
TChiInstruction chiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
result = TAliasedSSAChiInstruction(irFunc, primaryInstruction)
TChiInstruction chiInstruction(TRawInstruction primaryInstruction) {
result = TAliasedSSAChiInstruction(primaryInstruction)
}
class TUnreachedInstruction = TAliasedSSAUnreachedInstruction;

View File

@@ -18,19 +18,17 @@ cached
private module Cached {
cached
predicate hasPhiInstructionCached(
IRFunction irFunc, OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
) {
exists(OldBlock oldBlock |
definitionHasPhiNode(defLocation, oldBlock) and
irFunc = oldBlock.getEnclosingIRFunction() and
blockStartInstr = oldBlock.getFirstInstruction()
)
}
cached
predicate hasChiInstructionCached(IRFunctionBase irFunc, OldInstruction primaryInstruction) {
hasChiNode(_, primaryInstruction) and
irFunc = primaryInstruction.getEnclosingIRFunction()
predicate hasChiInstructionCached(OldInstruction primaryInstruction) {
hasChiNode(_, primaryInstruction)
}
cached
@@ -44,11 +42,6 @@ private module Cached {
class TStageInstruction =
TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction;
private TRawInstruction rawInstruction(IRFunctionBase irFunc, Opcode opcode) {
result = TRawInstruction(irFunc, opcode, _, _) and
result instanceof OldInstruction
}
cached
predicate hasInstruction(TStageInstruction instr) {
instr instanceof TRawInstruction and instr instanceof OldInstruction
@@ -268,12 +261,12 @@ private module Cached {
result = getOldInstruction(instr).getAST()
or
exists(RawIR::Instruction blockStartInstr |
instr = phiInstruction(_, blockStartInstr, _) and
instr = phiInstruction(blockStartInstr, _) and
result = blockStartInstr.getAST()
)
or
exists(RawIR::Instruction primaryInstr |
instr = chiInstruction(_, primaryInstr) and
instr = chiInstruction(primaryInstr) and
result = primaryInstr.getAST()
)
or
@@ -287,12 +280,12 @@ private module Cached {
result = instr.(RawIR::Instruction).getResultLanguageType()
or
exists(Alias::MemoryLocation defLocation |
instr = phiInstruction(_, _, defLocation) and
instr = phiInstruction(_, defLocation) and
result = defLocation.getType()
)
or
exists(Instruction primaryInstr, Alias::VirtualVariable vvar |
instr = chiInstruction(_, primaryInstr) and
instr = chiInstruction(primaryInstr) and
hasChiNode(vvar, primaryInstr) and
result = vvar.getType()
)
@@ -302,22 +295,27 @@ private module Cached {
cached
Opcode getInstructionOpcode(Instruction instr) {
instr = rawInstruction(_, result)
result = getOldInstruction(instr).getOpcode()
or
instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
instr = phiInstruction(_, _) and result instanceof Opcode::Phi
or
instr = chiInstruction(_, _) and result instanceof Opcode::Chi
instr = chiInstruction(_) and result instanceof Opcode::Chi
or
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
}
cached
IRFunctionBase getInstructionEnclosingIRFunction(Instruction instr) {
instr = rawInstruction(result, _)
result = getOldInstruction(instr).getEnclosingIRFunction()
or
instr = phiInstruction(result, _, _)
exists(OldInstruction blockStartInstr |
instr = phiInstruction(blockStartInstr, _) and
result = blockStartInstr.getEnclosingIRFunction()
)
or
instr = chiInstruction(result, _)
exists(OldInstruction primaryInstr |
instr = chiInstruction(primaryInstr) and result = primaryInstr.getEnclosingIRFunction()
)
or
instr = unreachedInstruction(result)
}
@@ -341,11 +339,11 @@ private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(
private OldInstruction getOldInstruction(Instruction instr) { instr = result }
private ChiInstruction getChi(OldInstruction primaryInstr) {
result = chiInstruction(_, primaryInstr)
result = chiInstruction(primaryInstr)
}
private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) {
result = phiInstruction(_, defBlock.getFirstInstruction(), defLocation)
result = phiInstruction(defBlock.getFirstInstruction(), defLocation)
}
/**
@@ -910,9 +908,9 @@ module SSAConsistency {
module SSA {
class MemoryLocation = Alias::MemoryLocation;
predicate hasPhiInstruction = Cached::hasPhiInstructionCached/3;
predicate hasPhiInstruction = Cached::hasPhiInstructionCached/2;
predicate hasChiInstruction = Cached::hasChiInstructionCached/2;
predicate hasChiInstruction = Cached::hasChiInstructionCached/1;
predicate hasUnreachedInstruction = Cached::hasUnreachedInstructionCached/1;
}