C++: Remove resultType from the IPA constructors for TInstruction

Making these part of the IPA object identity changes the failure mode for cases where we assign multiple result types to an instruction. Previously, we would just have one instruction with two result types, but now we'd have two instructions, which breaks things worse. This change goes back to how things were before, to avoid any new surprises on real-world code with invalid ASTs or IR.
This commit is contained in:
Dave Bartolomeo
2020-06-03 10:11:27 -04:00
parent 53d4a8e3b2
commit f93c2e4e64
6 changed files with 112 additions and 128 deletions

View File

@@ -19,10 +19,8 @@ private module Cached {
class TStageInstruction = class TStageInstruction =
TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction; TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction;
private TRawInstruction rawInstruction( private TRawInstruction rawInstruction(IRFunctionBase irFunc, Opcode opcode, Language::AST ast) {
IRFunctionBase irFunc, Opcode opcode, Language::AST ast, Language::LanguageType resultType result = TRawInstruction(irFunc, opcode, ast, _, _) and
) {
result = TRawInstruction(irFunc, opcode, ast, resultType, _, _) and
result instanceof OldInstruction result instanceof OldInstruction
} }
@@ -246,15 +244,15 @@ private module Cached {
cached cached
Language::AST getInstructionAST(TStageInstruction instr) { Language::AST getInstructionAST(TStageInstruction instr) {
instr = rawInstruction(_, _, result, _) instr = rawInstruction(_, _, result)
or or
exists(RawIR::Instruction blockStartInstr | exists(RawIR::Instruction blockStartInstr |
instr = phiInstruction(_, _, blockStartInstr, _) and instr = phiInstruction(_, blockStartInstr, _) and
result = blockStartInstr.getAST() result = blockStartInstr.getAST()
) )
or or
exists(RawIR::Instruction primaryInstr | exists(RawIR::Instruction primaryInstr |
instr = chiInstruction(_, _, primaryInstr) and instr = chiInstruction(_, primaryInstr) and
result = primaryInstr.getAST() result = primaryInstr.getAST()
) )
or or
@@ -265,33 +263,40 @@ private module Cached {
cached cached
Language::LanguageType getInstructionResultType(TStageInstruction instr) { Language::LanguageType getInstructionResultType(TStageInstruction instr) {
instr = rawInstruction(_, _, _, result) result = instr.(RawIR::Instruction).getResultLanguageType()
or or
instr = phiInstruction(_, result, _, _) exists(Alias::MemoryLocation defLocation |
instr = phiInstruction(_, _, defLocation) and
result = defLocation.getType()
)
or or
instr = chiInstruction(_, result, _) exists(Instruction primaryInstr, Alias::VirtualVariable vvar |
instr = chiInstruction(_, primaryInstr) and
hasChiNode(vvar, primaryInstr) and
result = vvar.getType()
)
or or
instr = unreachedInstruction(_) and result = Language::getVoidType() instr = unreachedInstruction(_) and result = Language::getVoidType()
} }
cached cached
Opcode getInstructionOpcode(TStageInstruction instr) { Opcode getInstructionOpcode(TStageInstruction instr) {
instr = rawInstruction(_, result, _, _) instr = rawInstruction(_, result, _)
or or
instr = phiInstruction(_, _, _, _) and result instanceof Opcode::Phi instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
or or
instr = chiInstruction(_, _, _) and result instanceof Opcode::Chi instr = chiInstruction(_, _) and result instanceof Opcode::Chi
or or
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
} }
cached cached
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) { IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
instr = rawInstruction(result, _, _, _) instr = rawInstruction(result, _, _)
or or
instr = phiInstruction(result, _, _, _) instr = phiInstruction(result, _, _)
or or
instr = chiInstruction(result, _, _) instr = chiInstruction(result, _)
or or
instr = unreachedInstruction(result) instr = unreachedInstruction(result)
} }
@@ -313,11 +318,11 @@ private module Cached {
private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(result) = instr } private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(result) = instr }
private ChiInstruction getChi(OldInstruction primaryInstr) { private ChiInstruction getChi(OldInstruction primaryInstr) {
result = chiInstruction(_, _, primaryInstr) result = chiInstruction(_, primaryInstr)
} }
private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) { private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) {
result = phiInstruction(_, _, defBlock.getFirstInstruction(), defLocation) result = phiInstruction(_, defBlock.getFirstInstruction(), defLocation)
} }
/** /**
@@ -883,26 +888,19 @@ module SSA {
cached cached
predicate hasPhiInstruction( predicate hasPhiInstruction(
IRFunction irFunc, Language::LanguageType resultType, OldInstruction blockStartInstr, IRFunction irFunc, OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
Alias::MemoryLocation defLocation
) { ) {
exists(OldBlock oldBlock | exists(OldBlock oldBlock |
definitionHasPhiNode(defLocation, oldBlock) and definitionHasPhiNode(defLocation, oldBlock) and
irFunc = oldBlock.getEnclosingIRFunction() and irFunc = oldBlock.getEnclosingIRFunction() and
blockStartInstr = oldBlock.getFirstInstruction() and blockStartInstr = oldBlock.getFirstInstruction()
resultType = defLocation.getType()
) )
} }
cached cached
predicate hasChiInstruction( predicate hasChiInstruction(IRFunctionBase irFunc, OldInstruction primaryInstruction) {
IRFunctionBase irFunc, Language::LanguageType resultType, OldInstruction primaryInstruction hasChiNode(_, primaryInstruction) and
) { irFunc = primaryInstruction.getEnclosingIRFunction()
exists(Alias::VirtualVariable vvar |
hasChiNode(vvar, primaryInstruction) and
irFunc = primaryInstruction.getEnclosingIRFunction() and
resultType = vvar.getType()
)
} }
cached cached

View File

@@ -14,35 +14,29 @@ private import Imports::Opcode
*/ */
newtype TInstruction = newtype TInstruction =
TRawInstruction( TRawInstruction(
IRFunctionBase irFunc, Opcode opcode, Language::AST ast, Language::LanguageType resultType, IRFunctionBase irFunc, Opcode opcode, Language::AST ast,
IRConstruction::Raw::InstructionTag1 tag1, IRConstruction::Raw::InstructionTag2 tag2 IRConstruction::Raw::InstructionTag1 tag1, IRConstruction::Raw::InstructionTag2 tag2
) { ) {
IRConstruction::Raw::hasInstruction(irFunc.getFunction(), opcode, ast, resultType, tag1, tag2) IRConstruction::Raw::hasInstruction(irFunc.getFunction(), opcode, ast, tag1, tag2)
} or } or
TUnaliasedSSAPhiInstruction( TUnaliasedSSAPhiInstruction(
IRFunctionBase irFunc, Language::LanguageType resultType, TRawInstruction blockStartInstr, IRFunctionBase irFunc, TRawInstruction blockStartInstr,
UnaliasedSSA::SSA::MemoryLocation memoryLocation UnaliasedSSA::SSA::MemoryLocation memoryLocation
) { ) {
UnaliasedSSA::SSA::hasPhiInstruction(irFunc, resultType, blockStartInstr, memoryLocation) UnaliasedSSA::SSA::hasPhiInstruction(irFunc, blockStartInstr, memoryLocation)
} or
TUnaliasedSSAChiInstruction(
IRFunctionBase irFunc, Language::LanguageType resultType, TRawInstruction primaryInstruction
) {
none()
} or } or
TUnaliasedSSAChiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) { none() } or
TUnaliasedSSAUnreachedInstruction(IRFunctionBase irFunc) { TUnaliasedSSAUnreachedInstruction(IRFunctionBase irFunc) {
UnaliasedSSA::SSA::hasUnreachedInstruction(irFunc) UnaliasedSSA::SSA::hasUnreachedInstruction(irFunc)
} or } or
TAliasedSSAPhiInstruction( TAliasedSSAPhiInstruction(
IRFunctionBase irFunc, Language::LanguageType resultType, TRawInstruction blockStartInstr, IRFunctionBase irFunc, TRawInstruction blockStartInstr,
AliasedSSA::SSA::MemoryLocation memoryLocation AliasedSSA::SSA::MemoryLocation memoryLocation
) { ) {
AliasedSSA::SSA::hasPhiInstruction(irFunc, resultType, blockStartInstr, memoryLocation) AliasedSSA::SSA::hasPhiInstruction(irFunc, blockStartInstr, memoryLocation)
} or } or
TAliasedSSAChiInstruction( TAliasedSSAChiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
IRFunctionBase irFunc, Language::LanguageType resultType, TRawInstruction primaryInstruction AliasedSSA::SSA::hasChiInstruction(irFunc, primaryInstruction)
) {
AliasedSSA::SSA::hasChiInstruction(irFunc, resultType, primaryInstruction)
} or } or
TAliasedSSAUnreachedInstruction(IRFunctionBase irFunc) { TAliasedSSAUnreachedInstruction(IRFunctionBase irFunc) {
AliasedSSA::SSA::hasUnreachedInstruction(irFunc) AliasedSSA::SSA::hasUnreachedInstruction(irFunc)
@@ -58,18 +52,16 @@ module UnaliasedSSAInstructions {
class TPhiInstruction = TUnaliasedSSAPhiInstruction; class TPhiInstruction = TUnaliasedSSAPhiInstruction;
TPhiInstruction phiInstruction( TPhiInstruction phiInstruction(
IRFunctionBase irFunc, Language::LanguageType resultType, TRawInstruction blockStartInstr, IRFunctionBase irFunc, TRawInstruction blockStartInstr,
UnaliasedSSA::SSA::MemoryLocation memoryLocation UnaliasedSSA::SSA::MemoryLocation memoryLocation
) { ) {
result = TUnaliasedSSAPhiInstruction(irFunc, resultType, blockStartInstr, memoryLocation) result = TUnaliasedSSAPhiInstruction(irFunc, blockStartInstr, memoryLocation)
} }
class TChiInstruction = TUnaliasedSSAChiInstruction; class TChiInstruction = TUnaliasedSSAChiInstruction;
TChiInstruction chiInstruction( TChiInstruction chiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
IRFunctionBase irFunc, Language::LanguageType resultType, TRawInstruction primaryInstruction result = TUnaliasedSSAChiInstruction(irFunc, primaryInstruction)
) {
result = TUnaliasedSSAChiInstruction(irFunc, resultType, primaryInstruction)
} }
class TUnreachedInstruction = TUnaliasedSSAUnreachedInstruction; class TUnreachedInstruction = TUnaliasedSSAUnreachedInstruction;
@@ -89,18 +81,16 @@ module AliasedSSAInstructions {
class TPhiInstruction = TAliasedSSAPhiInstruction; class TPhiInstruction = TAliasedSSAPhiInstruction;
TPhiInstruction phiInstruction( TPhiInstruction phiInstruction(
IRFunctionBase irFunc, Language::LanguageType resultType, TRawInstruction blockStartInstr, IRFunctionBase irFunc, TRawInstruction blockStartInstr,
AliasedSSA::SSA::MemoryLocation memoryLocation AliasedSSA::SSA::MemoryLocation memoryLocation
) { ) {
result = TAliasedSSAPhiInstruction(irFunc, resultType, blockStartInstr, memoryLocation) result = TAliasedSSAPhiInstruction(irFunc, blockStartInstr, memoryLocation)
} }
class TChiInstruction = TAliasedSSAChiInstruction; class TChiInstruction = TAliasedSSAChiInstruction;
TChiInstruction chiInstruction( TChiInstruction chiInstruction(IRFunctionBase irFunc, TRawInstruction primaryInstruction) {
IRFunctionBase irFunc, Language::LanguageType resultType, TRawInstruction primaryInstruction result = TAliasedSSAChiInstruction(irFunc, primaryInstruction)
) {
result = TAliasedSSAChiInstruction(irFunc, resultType, primaryInstruction)
} }
class TUnreachedInstruction = TAliasedSSAUnreachedInstruction; class TUnreachedInstruction = TAliasedSSAUnreachedInstruction;

View File

@@ -15,11 +15,11 @@ private import TranslatedStmt
private import TranslatedFunction private import TranslatedFunction
TranslatedElement getInstructionTranslatedElement(Instruction instruction) { TranslatedElement getInstructionTranslatedElement(Instruction instruction) {
instruction = TRawInstruction(_, _, _, _, result, _) instruction = TRawInstruction(_, _, _, result, _)
} }
InstructionTag getInstructionTag(Instruction instruction) { InstructionTag getInstructionTag(Instruction instruction) {
instruction = TRawInstruction(_, _, _, _, _, result) instruction = TRawInstruction(_, _, _, _, result)
} }
pragma[noinline] pragma[noinline]
@@ -45,10 +45,9 @@ module Raw {
cached cached
predicate hasInstruction( predicate hasInstruction(
Function func, Opcode opcode, Element ast, CppType resultType, TranslatedElement element, Function func, Opcode opcode, Element ast, TranslatedElement element, InstructionTag tag
InstructionTag tag
) { ) {
element.hasInstruction(opcode, tag, resultType) and element.hasInstruction(opcode, tag, _) and
ast = element.getAST() and ast = element.getAST() and
func = element.getFunction() func = element.getFunction()
} }
@@ -371,22 +370,25 @@ private module Cached {
cached cached
Locatable getInstructionAST(TStageInstruction instr) { Locatable getInstructionAST(TStageInstruction instr) {
instr = TRawInstruction(_, _, result, _, _, _) instr = TRawInstruction(_, _, result, _, _)
} }
cached cached
CppType getInstructionResultType(TStageInstruction instr) { CppType getInstructionResultType(TStageInstruction instr) {
instr = TRawInstruction(_, _, _, result, _, _) exists(TranslatedElement element, InstructionTag tag |
instructionOrigin(instr, element, tag) and
element.hasInstruction(_, tag, result)
)
} }
cached cached
Opcode getInstructionOpcode(TStageInstruction instr) { Opcode getInstructionOpcode(TStageInstruction instr) {
instr = TRawInstruction(_, result, _, _, _, _) instr = TRawInstruction(_, result, _, _, _)
} }
cached cached
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) { IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
instr = TRawInstruction(result, _, _, _, _, _) instr = TRawInstruction(result, _, _, _, _)
} }
cached cached

View File

@@ -19,10 +19,8 @@ private module Cached {
class TStageInstruction = class TStageInstruction =
TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction; TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction;
private TRawInstruction rawInstruction( private TRawInstruction rawInstruction(IRFunctionBase irFunc, Opcode opcode, Language::AST ast) {
IRFunctionBase irFunc, Opcode opcode, Language::AST ast, Language::LanguageType resultType result = TRawInstruction(irFunc, opcode, ast, _, _) and
) {
result = TRawInstruction(irFunc, opcode, ast, resultType, _, _) and
result instanceof OldInstruction result instanceof OldInstruction
} }
@@ -246,15 +244,15 @@ private module Cached {
cached cached
Language::AST getInstructionAST(TStageInstruction instr) { Language::AST getInstructionAST(TStageInstruction instr) {
instr = rawInstruction(_, _, result, _) instr = rawInstruction(_, _, result)
or or
exists(RawIR::Instruction blockStartInstr | exists(RawIR::Instruction blockStartInstr |
instr = phiInstruction(_, _, blockStartInstr, _) and instr = phiInstruction(_, blockStartInstr, _) and
result = blockStartInstr.getAST() result = blockStartInstr.getAST()
) )
or or
exists(RawIR::Instruction primaryInstr | exists(RawIR::Instruction primaryInstr |
instr = chiInstruction(_, _, primaryInstr) and instr = chiInstruction(_, primaryInstr) and
result = primaryInstr.getAST() result = primaryInstr.getAST()
) )
or or
@@ -265,33 +263,40 @@ private module Cached {
cached cached
Language::LanguageType getInstructionResultType(TStageInstruction instr) { Language::LanguageType getInstructionResultType(TStageInstruction instr) {
instr = rawInstruction(_, _, _, result) result = instr.(RawIR::Instruction).getResultLanguageType()
or or
instr = phiInstruction(_, result, _, _) exists(Alias::MemoryLocation defLocation |
instr = phiInstruction(_, _, defLocation) and
result = defLocation.getType()
)
or or
instr = chiInstruction(_, result, _) exists(Instruction primaryInstr, Alias::VirtualVariable vvar |
instr = chiInstruction(_, primaryInstr) and
hasChiNode(vvar, primaryInstr) and
result = vvar.getType()
)
or or
instr = unreachedInstruction(_) and result = Language::getVoidType() instr = unreachedInstruction(_) and result = Language::getVoidType()
} }
cached cached
Opcode getInstructionOpcode(TStageInstruction instr) { Opcode getInstructionOpcode(TStageInstruction instr) {
instr = rawInstruction(_, result, _, _) instr = rawInstruction(_, result, _)
or or
instr = phiInstruction(_, _, _, _) and result instanceof Opcode::Phi instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
or or
instr = chiInstruction(_, _, _) and result instanceof Opcode::Chi instr = chiInstruction(_, _) and result instanceof Opcode::Chi
or or
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
} }
cached cached
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) { IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
instr = rawInstruction(result, _, _, _) instr = rawInstruction(result, _, _)
or or
instr = phiInstruction(result, _, _, _) instr = phiInstruction(result, _, _)
or or
instr = chiInstruction(result, _, _) instr = chiInstruction(result, _)
or or
instr = unreachedInstruction(result) instr = unreachedInstruction(result)
} }
@@ -313,11 +318,11 @@ private module Cached {
private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(result) = instr } private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(result) = instr }
private ChiInstruction getChi(OldInstruction primaryInstr) { private ChiInstruction getChi(OldInstruction primaryInstr) {
result = chiInstruction(_, _, primaryInstr) result = chiInstruction(_, primaryInstr)
} }
private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) { private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) {
result = phiInstruction(_, _, defBlock.getFirstInstruction(), defLocation) result = phiInstruction(_, defBlock.getFirstInstruction(), defLocation)
} }
/** /**
@@ -883,26 +888,19 @@ module SSA {
cached cached
predicate hasPhiInstruction( predicate hasPhiInstruction(
IRFunction irFunc, Language::LanguageType resultType, OldInstruction blockStartInstr, IRFunction irFunc, OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
Alias::MemoryLocation defLocation
) { ) {
exists(OldBlock oldBlock | exists(OldBlock oldBlock |
definitionHasPhiNode(defLocation, oldBlock) and definitionHasPhiNode(defLocation, oldBlock) and
irFunc = oldBlock.getEnclosingIRFunction() and irFunc = oldBlock.getEnclosingIRFunction() and
blockStartInstr = oldBlock.getFirstInstruction() and blockStartInstr = oldBlock.getFirstInstruction()
resultType = defLocation.getType()
) )
} }
cached cached
predicate hasChiInstruction( predicate hasChiInstruction(IRFunctionBase irFunc, OldInstruction primaryInstruction) {
IRFunctionBase irFunc, Language::LanguageType resultType, OldInstruction primaryInstruction hasChiNode(_, primaryInstruction) and
) { irFunc = primaryInstruction.getEnclosingIRFunction()
exists(Alias::VirtualVariable vvar |
hasChiNode(vvar, primaryInstruction) and
irFunc = primaryInstruction.getEnclosingIRFunction() and
resultType = vvar.getType()
)
} }
cached cached

View File

@@ -42,7 +42,6 @@ missingOperandType
duplicateChiOperand duplicateChiOperand
sideEffectWithoutPrimary sideEffectWithoutPrimary
instructionWithoutSuccessor instructionWithoutSuccessor
| CPP-309.cpp:7:5:7:20 | InitializeDynamicAllocation: new[] |
| VacuousDestructorCall.cpp:2:29:2:29 | InitializeIndirection: y | | VacuousDestructorCall.cpp:2:29:2:29 | InitializeIndirection: y |
| VacuousDestructorCall.cpp:3:3:3:3 | VariableAddress: x | | VacuousDestructorCall.cpp:3:3:3:3 | VariableAddress: x |
| VacuousDestructorCall.cpp:4:3:4:3 | Load: y | | VacuousDestructorCall.cpp:4:3:4:3 | Load: y |
@@ -51,7 +50,6 @@ instructionWithoutSuccessor
| condition_decls.cpp:26:23:26:24 | IndirectMayWriteSideEffect: call to BoxedInt | | condition_decls.cpp:26:23:26:24 | IndirectMayWriteSideEffect: call to BoxedInt |
| condition_decls.cpp:41:22:41:23 | IndirectMayWriteSideEffect: call to BoxedInt | | condition_decls.cpp:41:22:41:23 | IndirectMayWriteSideEffect: call to BoxedInt |
| condition_decls.cpp:48:52:48:53 | IndirectMayWriteSideEffect: call to BoxedInt | | condition_decls.cpp:48:52:48:53 | IndirectMayWriteSideEffect: call to BoxedInt |
| cpp17.cpp:15:5:15:45 | InitializeDynamicAllocation: new |
| enum.c:6:9:6:9 | Constant: (int)... | | enum.c:6:9:6:9 | Constant: (int)... |
| file://:0:0:0:0 | CompareNE: (bool)... | | file://:0:0:0:0 | CompareNE: (bool)... |
| file://:0:0:0:0 | CompareNE: (bool)... | | file://:0:0:0:0 | CompareNE: (bool)... |

View File

@@ -19,10 +19,8 @@ private module Cached {
class TStageInstruction = class TStageInstruction =
TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction; TRawInstruction or TPhiInstruction or TChiInstruction or TUnreachedInstruction;
private TRawInstruction rawInstruction( private TRawInstruction rawInstruction(IRFunctionBase irFunc, Opcode opcode, Language::AST ast) {
IRFunctionBase irFunc, Opcode opcode, Language::AST ast, Language::LanguageType resultType result = TRawInstruction(irFunc, opcode, ast, _, _) and
) {
result = TRawInstruction(irFunc, opcode, ast, resultType, _, _) and
result instanceof OldInstruction result instanceof OldInstruction
} }
@@ -246,15 +244,15 @@ private module Cached {
cached cached
Language::AST getInstructionAST(TStageInstruction instr) { Language::AST getInstructionAST(TStageInstruction instr) {
instr = rawInstruction(_, _, result, _) instr = rawInstruction(_, _, result)
or or
exists(RawIR::Instruction blockStartInstr | exists(RawIR::Instruction blockStartInstr |
instr = phiInstruction(_, _, blockStartInstr, _) and instr = phiInstruction(_, blockStartInstr, _) and
result = blockStartInstr.getAST() result = blockStartInstr.getAST()
) )
or or
exists(RawIR::Instruction primaryInstr | exists(RawIR::Instruction primaryInstr |
instr = chiInstruction(_, _, primaryInstr) and instr = chiInstruction(_, primaryInstr) and
result = primaryInstr.getAST() result = primaryInstr.getAST()
) )
or or
@@ -265,33 +263,40 @@ private module Cached {
cached cached
Language::LanguageType getInstructionResultType(TStageInstruction instr) { Language::LanguageType getInstructionResultType(TStageInstruction instr) {
instr = rawInstruction(_, _, _, result) result = instr.(RawIR::Instruction).getResultLanguageType()
or or
instr = phiInstruction(_, result, _, _) exists(Alias::MemoryLocation defLocation |
instr = phiInstruction(_, _, defLocation) and
result = defLocation.getType()
)
or or
instr = chiInstruction(_, result, _) exists(Instruction primaryInstr, Alias::VirtualVariable vvar |
instr = chiInstruction(_, primaryInstr) and
hasChiNode(vvar, primaryInstr) and
result = vvar.getType()
)
or or
instr = unreachedInstruction(_) and result = Language::getVoidType() instr = unreachedInstruction(_) and result = Language::getVoidType()
} }
cached cached
Opcode getInstructionOpcode(TStageInstruction instr) { Opcode getInstructionOpcode(TStageInstruction instr) {
instr = rawInstruction(_, result, _, _) instr = rawInstruction(_, result, _)
or or
instr = phiInstruction(_, _, _, _) and result instanceof Opcode::Phi instr = phiInstruction(_, _, _) and result instanceof Opcode::Phi
or or
instr = chiInstruction(_, _, _) and result instanceof Opcode::Chi instr = chiInstruction(_, _) and result instanceof Opcode::Chi
or or
instr = unreachedInstruction(_) and result instanceof Opcode::Unreached instr = unreachedInstruction(_) and result instanceof Opcode::Unreached
} }
cached cached
IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) { IRFunctionBase getInstructionEnclosingIRFunction(TStageInstruction instr) {
instr = rawInstruction(result, _, _, _) instr = rawInstruction(result, _, _)
or or
instr = phiInstruction(result, _, _, _) instr = phiInstruction(result, _, _)
or or
instr = chiInstruction(result, _, _) instr = chiInstruction(result, _)
or or
instr = unreachedInstruction(result) instr = unreachedInstruction(result)
} }
@@ -313,11 +318,11 @@ private module Cached {
private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(result) = instr } private Instruction getNewInstruction(OldInstruction instr) { getOldInstruction(result) = instr }
private ChiInstruction getChi(OldInstruction primaryInstr) { private ChiInstruction getChi(OldInstruction primaryInstr) {
result = chiInstruction(_, _, primaryInstr) result = chiInstruction(_, primaryInstr)
} }
private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) { private PhiInstruction getPhi(OldBlock defBlock, Alias::MemoryLocation defLocation) {
result = phiInstruction(_, _, defBlock.getFirstInstruction(), defLocation) result = phiInstruction(_, defBlock.getFirstInstruction(), defLocation)
} }
/** /**
@@ -883,26 +888,19 @@ module SSA {
cached cached
predicate hasPhiInstruction( predicate hasPhiInstruction(
IRFunction irFunc, Language::LanguageType resultType, OldInstruction blockStartInstr, IRFunction irFunc, OldInstruction blockStartInstr, Alias::MemoryLocation defLocation
Alias::MemoryLocation defLocation
) { ) {
exists(OldBlock oldBlock | exists(OldBlock oldBlock |
definitionHasPhiNode(defLocation, oldBlock) and definitionHasPhiNode(defLocation, oldBlock) and
irFunc = oldBlock.getEnclosingIRFunction() and irFunc = oldBlock.getEnclosingIRFunction() and
blockStartInstr = oldBlock.getFirstInstruction() and blockStartInstr = oldBlock.getFirstInstruction()
resultType = defLocation.getType()
) )
} }
cached cached
predicate hasChiInstruction( predicate hasChiInstruction(IRFunctionBase irFunc, OldInstruction primaryInstruction) {
IRFunctionBase irFunc, Language::LanguageType resultType, OldInstruction primaryInstruction hasChiNode(_, primaryInstruction) and
) { irFunc = primaryInstruction.getEnclosingIRFunction()
exists(Alias::VirtualVariable vvar |
hasChiNode(vvar, primaryInstruction) and
irFunc = primaryInstruction.getEnclosingIRFunction() and
resultType = vvar.getType()
)
} }
cached cached