@@ -29,7 +29,13 @@ private Instruction getAnInstructionAtLine(IRFunction irFunc, Language::File fil
2929/**
3030 * Represents a single operation in the IR.
3131 */
32- class Instruction extends Construction:: TInstruction {
32+ class Instruction extends Construction:: TStageInstruction {
33+ Instruction ( ) {
34+ // The base `TStageInstruction` type is a superset of the actual instructions appearing in this
35+ // stage. This call lets the stage filter out the ones that are not reused from raw IR.
36+ Construction:: hasInstruction ( this )
37+ }
38+
3339 final string toString ( ) { result = getOpcode ( ) .toString ( ) + ": " + getAST ( ) .toString ( ) }
3440
3541 /**
@@ -194,14 +200,14 @@ class Instruction extends Construction::TInstruction {
194200 * conversion.
195201 */
196202 final Language:: Expr getConvertedResultExpression ( ) {
197- result = Construction :: getInstructionConvertedResultExpression ( this )
203+ result = Raw :: getInstructionConvertedResultExpression ( this )
198204 }
199205
200206 /**
201207 * Gets the unconverted form of the `Expr` whose result is computed by this instruction, if any.
202208 */
203209 final Language:: Expr getUnconvertedResultExpression ( ) {
204- result = Construction :: getInstructionUnconvertedResultExpression ( this )
210+ result = Raw :: getInstructionUnconvertedResultExpression ( this )
205211 }
206212
207213 final Language:: LanguageType getResultLanguageType ( ) {
@@ -212,6 +218,7 @@ class Instruction extends Construction::TInstruction {
212218 * Gets the type of the result produced by this instruction. If the instruction does not produce
213219 * a result, its result type will be `IRVoidType`.
214220 */
221+ cached
215222 final IRType getResultIRType ( ) { result = getResultLanguageType ( ) .getIRType ( ) }
216223
217224 /**
@@ -250,7 +257,7 @@ class Instruction extends Construction::TInstruction {
250257 * result of the `Load` instruction is a prvalue of type `int`, representing
251258 * the integer value loaded from variable `x`.
252259 */
253- final predicate isGLValue ( ) { Construction :: getInstructionResultType ( this ) .hasType ( _, true ) }
260+ final predicate isGLValue ( ) { getResultLanguageType ( ) .hasType ( _, true ) }
254261
255262 /**
256263 * Gets the size of the result produced by this instruction, in bytes. If the
@@ -259,7 +266,7 @@ class Instruction extends Construction::TInstruction {
259266 * If `this.isGLValue()` holds for this instruction, the value of
260267 * `getResultSize()` will always be the size of a pointer.
261268 */
262- final int getResultSize ( ) { result = Construction :: getInstructionResultType ( this ) .getByteSize ( ) }
269+ final int getResultSize ( ) { result = getResultLanguageType ( ) .getByteSize ( ) }
263270
264271 /**
265272 * Gets the opcode that specifies the operation performed by this instruction.
@@ -395,7 +402,7 @@ class Instruction extends Construction::TInstruction {
395402class VariableInstruction extends Instruction {
396403 IRVariable var ;
397404
398- VariableInstruction ( ) { var = Construction :: getInstructionVariable ( this ) }
405+ VariableInstruction ( ) { var = Raw :: getInstructionVariable ( this ) }
399406
400407 override string getImmediateString ( ) { result = var .toString ( ) }
401408
@@ -410,7 +417,7 @@ class VariableInstruction extends Instruction {
410417class FieldInstruction extends Instruction {
411418 Language:: Field field ;
412419
413- FieldInstruction ( ) { field = Construction :: getInstructionField ( this ) }
420+ FieldInstruction ( ) { field = Raw :: getInstructionField ( this ) }
414421
415422 final override string getImmediateString ( ) { result = field .toString ( ) }
416423
@@ -420,7 +427,7 @@ class FieldInstruction extends Instruction {
420427class FunctionInstruction extends Instruction {
421428 Language:: Function funcSymbol ;
422429
423- FunctionInstruction ( ) { funcSymbol = Construction :: getInstructionFunction ( this ) }
430+ FunctionInstruction ( ) { funcSymbol = Raw :: getInstructionFunction ( this ) }
424431
425432 final override string getImmediateString ( ) { result = funcSymbol .toString ( ) }
426433
@@ -430,7 +437,7 @@ class FunctionInstruction extends Instruction {
430437class ConstantValueInstruction extends Instruction {
431438 string value ;
432439
433- ConstantValueInstruction ( ) { value = Construction :: getInstructionConstantValue ( this ) }
440+ ConstantValueInstruction ( ) { value = Raw :: getInstructionConstantValue ( this ) }
434441
435442 final override string getImmediateString ( ) { result = value }
436443
@@ -440,7 +447,7 @@ class ConstantValueInstruction extends Instruction {
440447class IndexedInstruction extends Instruction {
441448 int index ;
442449
443- IndexedInstruction ( ) { index = Construction :: getInstructionIndex ( this ) }
450+ IndexedInstruction ( ) { index = Raw :: getInstructionIndex ( this ) }
444451
445452 final override string getImmediateString ( ) { result = index .toString ( ) }
446453
@@ -603,11 +610,16 @@ class ConstantInstruction extends ConstantValueInstruction {
603610}
604611
605612class IntegerConstantInstruction extends ConstantInstruction {
606- IntegerConstantInstruction ( ) { getResultType ( ) instanceof Language:: IntegralType }
613+ IntegerConstantInstruction ( ) {
614+ exists ( IRType resultType |
615+ resultType = getResultIRType ( ) and
616+ ( resultType instanceof IRIntegerType or resultType instanceof IRBooleanType )
617+ )
618+ }
607619}
608620
609621class FloatConstantInstruction extends ConstantInstruction {
610- FloatConstantInstruction ( ) { getResultType ( ) instanceof Language :: FloatingPointType }
622+ FloatConstantInstruction ( ) { getResultIRType ( ) instanceof IRFloatingPointType }
611623}
612624
613625class StringConstantInstruction extends VariableInstruction {
@@ -704,7 +716,7 @@ class PointerArithmeticInstruction extends BinaryInstruction {
704716
705717 PointerArithmeticInstruction ( ) {
706718 getOpcode ( ) instanceof PointerArithmeticOpcode and
707- elementSize = Construction :: getInstructionElementSize ( this )
719+ elementSize = Raw :: getInstructionElementSize ( this )
708720 }
709721
710722 final override string getImmediateString ( ) { result = elementSize .toString ( ) }
@@ -753,7 +765,7 @@ class InheritanceConversionInstruction extends UnaryInstruction {
753765 Language:: Class derivedClass ;
754766
755767 InheritanceConversionInstruction ( ) {
756- Construction :: getInstructionInheritance ( this , baseClass , derivedClass )
768+ Raw :: getInstructionInheritance ( this , baseClass , derivedClass )
757769 }
758770
759771 final override string getImmediateString ( ) {
@@ -1216,7 +1228,7 @@ class CatchByTypeInstruction extends CatchInstruction {
12161228
12171229 CatchByTypeInstruction ( ) {
12181230 getOpcode ( ) instanceof Opcode:: CatchByType and
1219- exceptionType = Construction :: getInstructionExceptionType ( this )
1231+ exceptionType = Raw :: getInstructionExceptionType ( this )
12201232 }
12211233
12221234 final override string getImmediateString ( ) { result = exceptionType .toString ( ) }
@@ -1362,7 +1374,7 @@ class BuiltInOperationInstruction extends Instruction {
13621374
13631375 BuiltInOperationInstruction ( ) {
13641376 getOpcode ( ) instanceof BuiltInOperationOpcode and
1365- operation = Construction :: getInstructionBuiltInOperation ( this )
1377+ operation = Raw :: getInstructionBuiltInOperation ( this )
13661378 }
13671379
13681380 final Language:: BuiltInOperation getBuiltInOperation ( ) { result = operation }
0 commit comments