Skip to content

Commit b4d5638

Browse files
author
Davide Italiano
committed
[SILInstruction] Introduce isDebugInstruction().
This is a property of an instruction and should be a member function of `SILInstruction` and not a free function in `DebugUtils`. Discussed with Adrian.
1 parent b36a551 commit b4d5638

File tree

9 files changed

+27
-26
lines changed

9 files changed

+27
-26
lines changed

include/swift/SIL/DebugUtils.h

+3-9
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,12 @@ namespace swift {
4343

4444
class SILInstruction;
4545

46-
/// Returns true if the instruction \p Inst is an instruction which is only
47-
/// relevant for debug information and has no other impact on program semantics.
48-
inline bool isDebugInst(SILInstruction *Inst) {
49-
return isa<DebugValueInst>(Inst) || isa<DebugValueAddrInst>(Inst);
50-
}
51-
5246
/// Deletes all of the debug instructions that use \p Inst.
5347
inline void deleteAllDebugUses(ValueBase *Inst) {
5448
for (auto UI = Inst->use_begin(), E = Inst->use_end(); UI != E;) {
5549
auto *Inst = UI->getUser();
5650
UI++;
57-
if (isDebugInst(Inst))
51+
if (Inst->isDebugInstruction())
5852
Inst->eraseFromParent();
5953
}
6054
}
@@ -76,7 +70,7 @@ template <bool nonDebugInsts> class DebugUseIterator
7670
return;
7771

7872
SILInstruction *User = BaseIterator->getUser();
79-
if (isDebugInst(User) != nonDebugInsts)
73+
if (User->isDebugInstruction() != nonDebugInsts)
8074
return;
8175

8276
BaseIterator++;
@@ -188,7 +182,7 @@ inline void eraseFromParentWithDebugInsts(SILInstruction *I,
188182
while (!result->use_empty()) {
189183
foundAny = true;
190184
auto *User = result->use_begin()->getUser();
191-
assert(isDebugInst(User));
185+
assert(User->isDebugInstruction());
192186
if (InstIter != SILBasicBlock::iterator() &&
193187
InstIter != I->getParent()->end() &&
194188
&*InstIter == User) {

include/swift/SIL/SILInstruction.h

+7
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,13 @@ class SILInstruction
597597
/// you perform such optimizations like e.g. jump-threading.
598598
bool isTriviallyDuplicatable() const;
599599

600+
/// Returns true if the instruction is only relevant for debug
601+
/// informations and has no other impact on program semantics.
602+
bool isDebugInstruction() const {
603+
return getKind() == SILInstructionKind::DebugValueInst ||
604+
getKind() == SILInstructionKind::DebugValueAddrInst;
605+
}
606+
600607
/// Returns true if the instruction is a meta instruction which is
601608
/// relevant for debug information and does not get lowered to a real
602609
/// instruction.

lib/SIL/InstructionUtils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ bool swift::isEndOfScopeMarker(SILInstruction *user) {
275275
}
276276

277277
bool swift::isIncidentalUse(SILInstruction *user) {
278-
return isEndOfScopeMarker(user) || isDebugInst(user)
279-
|| isa<FixLifetimeInst>(user);
278+
return isEndOfScopeMarker(user) || user->isDebugInstruction() ||
279+
isa<FixLifetimeInst>(user);
280280
}
281281

282282
bool swift::onlyAffectsRefCount(SILInstruction *user) {

lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ bool COWArrayOpt::checkSafeArrayAddressUses(UserList &AddressUsers) {
579579

580580
for (auto *UseInst : AddressUsers) {
581581

582-
if (isDebugInst(UseInst))
582+
if (UseInst->isDebugInstruction())
583583
continue;
584584

585585
if (auto *AI = dyn_cast<ApplyInst>(UseInst)) {
@@ -698,7 +698,7 @@ bool COWArrayOpt::checkSafeArrayValueUses(UserList &ArrayValueUsers) {
698698
if (isa<MarkDependenceInst>(UseInst))
699699
continue;
700700

701-
if (isDebugInst(UseInst))
701+
if (UseInst->isDebugInstruction())
702702
continue;
703703

704704
// Found an unsafe or unknown user. The Array may escape here.
@@ -761,7 +761,7 @@ bool COWArrayOpt::checkSafeArrayElementUse(SILInstruction *UseInst,
761761
if (isa<MarkDependenceInst>(UseInst))
762762
return true;
763763

764-
if (isDebugInst(UseInst))
764+
if (UseInst->isDebugInstruction())
765765
return true;
766766

767767
// If this is an instruction which is a safe array element use if and only if
@@ -1764,7 +1764,7 @@ class ArrayPropertiesAnalysis {
17641764
bool checkSafeArrayAddressUses(UserList &AddressUsers) {
17651765
for (auto *UseInst : AddressUsers) {
17661766

1767-
if (isDebugInst(UseInst))
1767+
if (UseInst->isDebugInstruction())
17681768
continue;
17691769

17701770
if (isa<DeallocStackInst>(UseInst)) {

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,10 @@ static bool isAddressInitializedAtCall(SILValue addr, SILInstruction *AI,
934934
if (!DT->properlyDominates(AI, user))
935935
return false;
936936
} else {
937-
assert(isa<CopyAddrInst>(user) || isa<InitExistentialAddrInst>(user)
938-
|| isa<OpenExistentialAddrInst>(user)
939-
|| isa<DeallocStackInst>(user)
940-
|| isDebugInst(user) && "Unexpected instruction");
937+
assert(isa<CopyAddrInst>(user) || isa<InitExistentialAddrInst>(user) ||
938+
isa<OpenExistentialAddrInst>(user) ||
939+
isa<DeallocStackInst>(user) ||
940+
user->isDebugInstruction() && "Unexpected instruction");
941941
}
942942
}
943943
return true;

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
415415
if (auto *OEAI = dyn_cast<OpenExistentialAddrInst>(Op->getUser())) {
416416
for (auto *Op : OEAI->getUses()) {
417417
assert(isa<DestroyAddrInst>(Op->getUser()) ||
418-
isDebugInst(Op->getUser()) && "Unexpected instruction");
418+
Op->getUser()->isDebugInstruction() && "Unexpected instruction");
419419
ToDelete.insert(Op->getUser());
420420
}
421421
}
@@ -425,7 +425,7 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
425425
isa<DestroyAddrInst>(Op->getUser()) ||
426426
isa<DeallocStackInst>(Op->getUser()) ||
427427
isa<DeinitExistentialAddrInst>(Op->getUser()) ||
428-
isDebugInst(Op->getUser()) && "Unexpected instruction");
428+
Op->getUser()->isDebugInstruction() && "Unexpected instruction");
429429
ToDelete.insert(Op->getUser());
430430
}
431431

@@ -920,7 +920,7 @@ SILCombiner::visitInjectEnumAddrInst(InjectEnumAddrInst *IEAI) {
920920
// we don't care about the dealloc stack instructions
921921
continue;
922922
}
923-
if (isDebugInst(CurrUser) || isa<LoadInst>(CurrUser)) {
923+
if (CurrUser->isDebugInstruction() || isa<LoadInst>(CurrUser)) {
924924
// These Instructions are a non-risky use we can ignore
925925
continue;
926926
}

lib/SILOptimizer/Transforms/ConditionForwarding.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) {
160160
if (ArgUser == SEI)
161161
continue;
162162

163-
if (isDebugInst(ArgUser))
163+
if (ArgUser->isDebugInstruction())
164164
continue;
165165

166166
if (ArgUser->getParent()->getSinglePredecessorBlock() == SEI->getParent()) {
@@ -227,7 +227,7 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) {
227227
while (!Arg->use_empty()) {
228228
Operand *ArgUse = *Arg->use_begin();
229229
SILInstruction *ArgUser = ArgUse->getUser();
230-
if (isDebugInst(ArgUser)) {
230+
if (ArgUser->isDebugInstruction()) {
231231
// Don't care about debug instructions. Just remove them.
232232
ArgUser->eraseFromParent();
233233
continue;

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ static bool onlyHasTerminatorAndDebugInsts(SILBasicBlock *BB) {
11271127
TermInst *Terminator = BB->getTerminator();
11281128
SILBasicBlock::iterator Iter = BB->begin();
11291129
while (&*Iter != Terminator) {
1130-
if (!isDebugInst(&*Iter))
1130+
if (!(&*Iter)->isDebugInstruction())
11311131
return false;
11321132
Iter++;
11331133
}

lib/SILOptimizer/Utils/Generics.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ void swift::trySpecializeApplyOfGeneric(
23402340
SILInstruction *User = Use->getUser();
23412341
if (isa<RefCountingInst>(User))
23422342
continue;
2343-
if (isDebugInst(User))
2343+
if (User->isDebugInstruction())
23442344
continue;
23452345

23462346
auto FAS = FullApplySite::isa(User);

0 commit comments

Comments
 (0)