Skip to content

Commit 4e7569e

Browse files
authored
Merge pull request #31786 from eeckstein/opt-improvements
SILOptimizer: a bit refactoring and a small bug fix
2 parents 265b272 + 9958b47 commit 4e7569e

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

include/swift/SILOptimizer/Utils/LoadStoreOptUtils.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,16 @@ class LSBase {
169169
}
170170

171171
/// Print the LSBase.
172-
virtual void print(llvm::raw_ostream &os, SILModule *Mod,
173-
TypeExpansionContext context) {
172+
virtual void print(llvm::raw_ostream &os) {
174173
os << Base;
175-
Path.getValue().print(os, *Mod, context);
174+
SILFunction *F = Base->getFunction();
175+
if (F) {
176+
Path.getValue().print(os, F->getModule(), TypeExpansionContext(*F));
177+
}
176178
}
177179

178-
virtual void dump(SILModule *Mod, TypeExpansionContext context) {
179-
print(llvm::dbgs(), Mod, context);
180+
virtual void dump() {
181+
print(llvm::dbgs());
180182
}
181183
};
182184

@@ -260,13 +262,12 @@ class LSValue : public LSBase {
260262
return Path.getValue().createExtract(Base, Inst, true);
261263
}
262264

263-
void print(llvm::raw_ostream &os, SILModule *Mod,
264-
TypeExpansionContext context) {
265+
void print(llvm::raw_ostream &os) {
265266
if (CoveringValue) {
266267
os << "Covering Value";
267268
return;
268269
}
269-
LSBase::print(os, Mod, context);
270+
LSBase::print(os);
270271
}
271272

272273
/// Expand this SILValue to all individual fields it contains.

lib/SIL/IR/SILBasicBlock.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ SILPhiArgument *SILBasicBlock::replacePhiArgumentAndReplaceAllUses(
226226
// any uses.
227227
SmallVector<Operand *, 16> operands;
228228
SILValue undef = SILUndef::get(ty, *getParent());
229-
for (auto *use : getArgument(i)->getUses()) {
229+
SILArgument *arg = getArgument(i);
230+
while (!arg->use_empty()) {
231+
Operand *use = *arg->use_begin();
230232
use->set(undef);
231233
operands.push_back(use);
232234
}

lib/SIL/IR/SILPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,9 @@ ID SILPrintContext::getID(const SILNode *node) {
35323532
return {ID::SILUndef, 0};
35333533

35343534
SILBasicBlock *BB = node->getParentBlock();
3535+
if (!BB) {
3536+
return { ID::Null, 0 };
3537+
}
35353538
if (SILFunction *F = BB->getParent()) {
35363539
setContext(F);
35373540
// Lazily initialize the instruction -> ID mapping.

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,7 @@ static bool getDeadInstsAfterInitializerRemoved(
835835
bool DeadObjectElimination::processAllocApply(ApplyInst *AI,
836836
DeadEndBlocks &DEBlocks) {
837837
// Currently only handle array.uninitialized
838-
if (ArraySemanticsCall(AI).getKind() != ArrayCallKind::kArrayUninitialized &&
839-
ArraySemanticsCall(AI).getKind() !=
840-
ArrayCallKind::kArrayUninitializedIntrinsic)
838+
if (!isAllocatingApply(AI))
841839
return false;
842840

843841
llvm::SmallVector<SILInstruction *, 8> instsDeadAfterInitializerRemoved;

lib/SILOptimizer/Transforms/RedundantLoadElimination.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,8 +1585,7 @@ bool RLEContext::run() {
15851585

15861586
LLVM_DEBUG(for (unsigned i = 0; i < LocationVault.size(); ++i) {
15871587
llvm::dbgs() << "LSLocation #" << i;
1588-
getLocation(i).print(llvm::dbgs(), &Fn->getModule(),
1589-
TypeExpansionContext(*Fn));
1588+
getLocation(i).print(llvm::dbgs());
15901589
});
15911590

15921591
if (Optimistic)

lib/SILOptimizer/UtilityPasses/LSLocationPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class LSLocationPrinter : public SILModuleTransform {
171171

172172
llvm::outs() << "#" << Counter++ << II;
173173
for (auto &Loc : Locs) {
174-
Loc.print(llvm::outs(), &Fn.getModule(), TypeExpansionContext(Fn));
174+
Loc.print(llvm::outs());
175175
}
176176
Locs.clear();
177177
}
@@ -227,7 +227,7 @@ class LSLocationPrinter : public SILModuleTransform {
227227
LSLocation::reduce(L, &Fn.getModule(), TypeExpansionContext(Fn), SLocs);
228228
llvm::outs() << "#" << Counter++ << II;
229229
for (auto &Loc : SLocs) {
230-
Loc.print(llvm::outs(), &Fn.getModule(), TypeExpansionContext(Fn));
230+
Loc.print(llvm::outs());
231231
}
232232
L.reset();
233233
Locs.clear();

0 commit comments

Comments
 (0)