Skip to content

Commit 88219da

Browse files
committed
PerformanceDiagnostics: don't issue a metatype diagnostics when using MemoryLayout
The metatype is not code-gend for the memory layout builtins. Also fix the wrong help test for the -experimental-performance-annotations option.
1 parent cddb08a commit 88219da

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ def CrossModuleOptimization : Flag<["-"], "cross-module-optimization">,
812812

813813
def ExperimentalPerformanceAnnotations : Flag<["-"], "experimental-performance-annotations">,
814814
Flags<[HelpHidden, FrontendOption]>,
815-
HelpText<"Perform cross-module optimization">;
815+
HelpText<"Enable experimental performance annotations">;
816816

817817
def RemoveRuntimeAsserts : Flag<["-"], "remove-runtime-asserts">,
818818
Flags<[FrontendOption]>,

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,9 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
667667
if (auto selfType = instTy->getAs<DynamicSelfType>())
668668
instTy = selfType->getSelfType();
669669
auto *cl = instTy->getClassOrBoundGenericClass();
670-
bool isForeign =
671-
cl->getObjectModel() == ReferenceCounting::ObjC ||
672-
cl->isForeign();
673-
if ((cl && isForeign) || instTy->isAnyObject())
670+
bool isForeign = cl && (cl->getObjectModel() == ReferenceCounting::ObjC ||
671+
cl->isForeign());
672+
if (isForeign || instTy->isAnyObject())
674673
return RuntimeEffect::MetaData | RuntimeEffect::ObjectiveC;
675674
return RuntimeEffect::MetaData;
676675
}

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ bool PerformanceDiagnostics::visitCallee(FullApplySite as,
154154
return false;
155155
}
156156

157+
static bool metatypeUsesAreNotRelevant(MetatypeInst *mt) {
158+
for (Operand *use : mt->getUses()) {
159+
if (auto *bi = dyn_cast<BuiltinInst>(use->getUser())) {
160+
switch (bi->getBuiltinInfo().ID) {
161+
case BuiltinValueKind::Sizeof:
162+
case BuiltinValueKind::Strideof:
163+
case BuiltinValueKind::Alignof:
164+
case BuiltinValueKind::IsPOD:
165+
case BuiltinValueKind::IsConcrete:
166+
case BuiltinValueKind::IsBitwiseTakable:
167+
continue;
168+
default:
169+
break;
170+
}
171+
}
172+
return false;
173+
}
174+
return true;
175+
}
176+
157177
bool PerformanceDiagnostics::visitInst(SILInstruction *inst,
158178
PerformanceConstraints perfConstr,
159179
LocWithParent *parentLoc) {
@@ -191,6 +211,10 @@ bool PerformanceDiagnostics::visitInst(SILInstruction *inst,
191211
diagnose(loc, diag::performance_metadata, "generic function calls");
192212
break;
193213
}
214+
case SILInstructionKind::MetatypeInst:
215+
if (metatypeUsesAreNotRelevant(cast<MetatypeInst>(inst)))
216+
break;
217+
LLVM_FALLTHROUGH;
194218
default:
195219
// We didn't recognize the instruction, so try to give an error message
196220
// based on the involved type.

test/SILOptimizer/performance-annotations.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func testUnsafePerformance(_ idx: Int) -> [Int] {
8585
return _unsafePerformance { [10, 20, 30, 40] }
8686
}
8787

88+
@_noAllocation
89+
func testMemoryLayout() -> Int {
90+
return MemoryLayout<Int>.size + MemoryLayout<Int>.stride + MemoryLayout<Int>.alignment
91+
}
92+
8893
class MyError : Error {}
8994

9095
@_noLocks

0 commit comments

Comments
 (0)