@@ -115,7 +115,7 @@ static bool isTemporary(const core::GlobalState &gs, const core::LocalVariable &
115
115
n == Names::unconditional ();
116
116
}
117
117
118
- struct LocalOccurrence {
118
+ struct OwnedLocal {
119
119
// / Parent method.
120
120
const core::SymbolRef owner;
121
121
// / Counter corresponding to the local's definition, unique within a method.
@@ -272,7 +272,7 @@ class SCIPState {
272
272
}
273
273
274
274
public:
275
- absl::Status saveDefinition (const core::GlobalState &gs, core::FileRef file, LocalOccurrence occ) {
275
+ absl::Status saveDefinition (const core::GlobalState &gs, core::FileRef file, OwnedLocal occ) {
276
276
return this ->saveDefinitionImpl (gs, file, occ.toString (gs, file), core::Loc (file, occ.offsets ));
277
277
}
278
278
@@ -296,8 +296,7 @@ class SCIPState {
296
296
return this ->saveDefinitionImpl (gs, file, symbolString, occLocStatus.value ());
297
297
}
298
298
299
- absl::Status saveReference (const core::GlobalState &gs, core::FileRef file, LocalOccurrence occ,
300
- int32_t symbol_roles) {
299
+ absl::Status saveReference (const core::GlobalState &gs, core::FileRef file, OwnedLocal occ, int32_t symbol_roles) {
301
300
return this ->saveReferenceImpl (gs, file, occ.toString (gs, file), occ.offsets , symbol_roles);
302
301
}
303
302
@@ -361,6 +360,7 @@ class CFGTraversal final {
361
360
UnorderedMap<const cfg::BasicBlock *, UnorderedMap<cfg::LocalRef, core::Loc>> blockLocals;
362
361
UnorderedMap<cfg::LocalRef, uint32_t > functionLocals;
363
362
363
+ // Local variable counter that is reset for every function.
364
364
uint32_t counter = 0 ;
365
365
SCIPState &scipState;
366
366
core::Context ctx;
@@ -387,6 +387,9 @@ class CFGTraversal final {
387
387
RValue,
388
388
};
389
389
390
+ // Emit an occurrence for a local variable if applicable.
391
+ //
392
+ // Returns true if an occurrence was emitted.
390
393
bool emitLocalOccurrence (const cfg::CFG &cfg, const cfg::BasicBlock *bb, cfg::LocalOccurrence local,
391
394
ValueCategory category) {
392
395
auto localRef = local.variable ;
@@ -436,10 +439,10 @@ class CFGTraversal final {
436
439
absl::Status status;
437
440
if (isDefinition) {
438
441
status = this ->scipState .saveDefinition (this ->ctx .state , this ->ctx .file ,
439
- LocalOccurrence {this ->ctx .owner , localId, local.loc });
442
+ OwnedLocal {this ->ctx .owner , localId, local.loc });
440
443
} else {
441
444
status = this ->scipState .saveReference (this ->ctx .state , this ->ctx .file ,
442
- LocalOccurrence {this ->ctx .owner , localId, local.loc }, referenceRole);
445
+ OwnedLocal {this ->ctx .owner , localId, local.loc }, referenceRole);
443
446
}
444
447
ENFORCE_NO_TIMER (status.ok ());
445
448
return true ;
@@ -550,7 +553,7 @@ class CFGTraversal final {
550
553
// Emit references for arguments
551
554
for (auto &arg : send->args ) {
552
555
// NOTE: For constructs like a += b, the instruction sequence ends up being:
553
- // $tmp = $b
556
+ // $tmp = $a
554
557
// $a = $tmp.+($b)
555
558
// The location for $tmp will point to $a in the source. However, the second one is a read,
556
559
// and the first one is a write. Instead of emitting two occurrences, it'd be nice to emit
0 commit comments