File tree Expand file tree Collapse file tree 3 files changed +12
-45
lines changed
cpp/ql/src/semmle/code/cpp/ir/implementation Expand file tree Collapse file tree 3 files changed +12
-45
lines changed Original file line number Diff line number Diff line change @@ -159,24 +159,13 @@ private cached module Cached {
159159 not startsBasicBlock ( i2 )
160160 }
161161
162- /** Gets the index of `i` in its `IRBlock`. */
163- private int getMemberIndex ( Instruction i ) {
164- startsBasicBlock ( i ) and
165- result = 0
166- or
167- exists ( Instruction iPrev |
168- adjacentInBlock ( iPrev , i ) and
169- result = getMemberIndex ( iPrev ) + 1
170- )
171- }
162+ /** Holds if `i` is the `index`th instruction the block starting with `first`. */
163+ private Instruction getInstructionFromFirst ( Instruction first , int index ) =
164+ shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
172165
173166 /** Holds if `i` is the `index`th instruction in `block`. */
174167 cached Instruction getInstruction ( TIRBlock block , int index ) {
175- exists ( Instruction first |
176- block = MkIRBlock ( first ) and
177- index = getMemberIndex ( result ) and
178- adjacentInBlock * ( first , result )
179- )
168+ result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
180169 }
181170
182171 cached int getInstructionCount ( TIRBlock block ) {
Original file line number Diff line number Diff line change @@ -159,24 +159,13 @@ private cached module Cached {
159159 not startsBasicBlock ( i2 )
160160 }
161161
162- /** Gets the index of `i` in its `IRBlock`. */
163- private int getMemberIndex ( Instruction i ) {
164- startsBasicBlock ( i ) and
165- result = 0
166- or
167- exists ( Instruction iPrev |
168- adjacentInBlock ( iPrev , i ) and
169- result = getMemberIndex ( iPrev ) + 1
170- )
171- }
162+ /** Holds if `i` is the `index`th instruction the block starting with `first`. */
163+ private Instruction getInstructionFromFirst ( Instruction first , int index ) =
164+ shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
172165
173166 /** Holds if `i` is the `index`th instruction in `block`. */
174167 cached Instruction getInstruction ( TIRBlock block , int index ) {
175- exists ( Instruction first |
176- block = MkIRBlock ( first ) and
177- index = getMemberIndex ( result ) and
178- adjacentInBlock * ( first , result )
179- )
168+ result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
180169 }
181170
182171 cached int getInstructionCount ( TIRBlock block ) {
Original file line number Diff line number Diff line change @@ -159,24 +159,13 @@ private cached module Cached {
159159 not startsBasicBlock ( i2 )
160160 }
161161
162- /** Gets the index of `i` in its `IRBlock`. */
163- private int getMemberIndex ( Instruction i ) {
164- startsBasicBlock ( i ) and
165- result = 0
166- or
167- exists ( Instruction iPrev |
168- adjacentInBlock ( iPrev , i ) and
169- result = getMemberIndex ( iPrev ) + 1
170- )
171- }
162+ /** Holds if `i` is the `index`th instruction the block starting with `first`. */
163+ private Instruction getInstructionFromFirst ( Instruction first , int index ) =
164+ shortestDistances( startsBasicBlock / 1 , adjacentInBlock / 2 ) ( first , result , index )
172165
173166 /** Holds if `i` is the `index`th instruction in `block`. */
174167 cached Instruction getInstruction ( TIRBlock block , int index ) {
175- exists ( Instruction first |
176- block = MkIRBlock ( first ) and
177- index = getMemberIndex ( result ) and
178- adjacentInBlock * ( first , result )
179- )
168+ result = getInstructionFromFirst ( getFirstInstruction ( block ) , index )
180169 }
181170
182171 cached int getInstructionCount ( TIRBlock block ) {
You can’t perform that action at this time.
0 commit comments