Skip to content

Commit 34aba08

Browse files
ravikandhadaiDougGregor
authored andcommitted
[SILOpt][OSLog] Skip constant folding StaticString in the
OSLogOptimization pass The OSLogOptimization pass constant evaluates and folds SIL instructions that are inlined from the construction of the string interpolations passed to the log calls, which enables replacing the dynamic format string construction with a static format string. In addition to folding constant strings, it also folds constant integers and arrays whose elements are constants. This change makes it skip folding static strings, since they are already efficiently represented. rdar://146028438 (cherry picked from commit cbf804e)
1 parent 493744d commit 34aba08

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/SILOptimizer/Mandatory/OSLogOptimization.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,16 @@ static void substituteConstants(FoldState &foldState) {
938938
for (SILValue constantSILValue : foldState.getConstantSILValues()) {
939939
SymbolicValue constantSymbolicVal =
940940
evaluator.lookupConstValue(constantSILValue).value();
941+
CanType instType = constantSILValue->getType().getASTType();
942+
943+
// If the SymbolicValue is a string but the instruction that is folded is
944+
// not String typed, we are tracking a StaticString which is represented as
945+
// a raw pointer. Skip folding StaticString as they are already efficiently
946+
// represented.
947+
if (constantSymbolicVal.getKind() == SymbolicValue::String &&
948+
!instType->isString())
949+
continue;
950+
941951
// Make sure that the symbolic value tracked in the foldState is a constant.
942952
// In the case of ArraySymbolicValue, the array storage could be a non-constant
943953
// if some instruction in the array initialization sequence was not evaluated
@@ -976,7 +986,6 @@ static void substituteConstants(FoldState &foldState) {
976986

977987
SILBuilderWithScope builder(insertionPoint);
978988
SILLocation loc = insertionPoint->getLoc();
979-
CanType instType = constantSILValue->getType().getASTType();
980989
SILValue foldedSILVal = emitCodeForSymbolicValue(
981990
constantSymbolicVal, instType, builder, loc, foldState.stringInfo);
982991

0 commit comments

Comments
 (0)