Skip to content

[local] Change some for-loops in analyzeStaticInitializer to use llvm… #15494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions lib/SILOptimizer/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,62 +1364,52 @@ bool swift::isSimpleType(SILType SILTy, SILModule& Module) {
/// Check if the value of V is computed by means of a simple initialization.
/// Store the actual SILValue into Val and the reversed list of instructions
/// initializing it in Insns.
/// The check is performed by recursively walking the computation of the
/// SIL value being analyzed.
/// TODO: Move into utils.
///
/// The check is performed by recursively walking the computation of the SIL
/// value being analyzed.
bool
swift::analyzeStaticInitializer(SILValue V,
SmallVectorImpl<SILInstruction *> &Insns) {
SmallVectorImpl<SILInstruction *> &Insts) {
// Save every instruction we see.
// TODO: MultiValueInstruction?
if (auto I = dyn_cast<SingleValueInstruction>(V))
Insns.push_back(I);
if (auto *I = dyn_cast<SingleValueInstruction>(V))
Insts.push_back(I);

if (auto *SI = dyn_cast<StructInst>(V)) {
// If it is not a struct which is a simple type, bail.
if (!isSimpleType(SI->getType(), SI->getModule()))
return false;
for (auto &Op: SI->getAllOperands()) {
// If one of the struct instruction operands is not
// a simple initializer, bail.
if (!analyzeStaticInitializer(Op.get(), Insns))
return false;
}
return true;
return llvm::none_of(SI->getAllOperands(),
[&](Operand &Op) -> bool {
return !analyzeStaticInitializer(Op.get(), Insts);
});
}

if (auto *TI = dyn_cast<TupleInst>(V)) {
// If it is not a tuple which is a simple type, bail.
if (!isSimpleType(TI->getType(), TI->getModule()))
return false;
for (auto &Op: TI->getAllOperands()) {
// If one of the struct instruction operands is not
// a simple initializer, bail.
if (!analyzeStaticInitializer(Op.get(), Insns))
return false;
}
return true;
return llvm::none_of(TI->getAllOperands(),
[&](Operand &Op) -> bool {
return !analyzeStaticInitializer(Op.get(), Insts);
});
}

if (auto *bi = dyn_cast<BuiltinInst>(V)) {
switch (bi->getBuiltinInfo().ID) {
case BuiltinValueKind::FPTrunc:
if (auto *LI = dyn_cast<LiteralInst>(bi->getArguments()[0])) {
return analyzeStaticInitializer(LI, Insns);
return analyzeStaticInitializer(LI, Insts);
}
return false;
default:
return false;
}
}

if (isa<IntegerLiteralInst>(V)
|| isa<FloatLiteralInst>(V)
|| isa<StringLiteralInst>(V)) {
return true;
}

return false;
return isa<IntegerLiteralInst>(V)
|| isa<FloatLiteralInst>(V)
|| isa<StringLiteralInst>(V);
}

/// Replace load sequence which may contain
Expand Down