Skip to content

Commit 97854b9

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 4d2318d + 28a2826 commit 97854b9

17 files changed

+172
-268
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,21 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQU
633633
set(SWIFT_COMPILER_IS_MSVC_LIKE TRUE)
634634
endif()
635635

636+
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
637+
# CMake's default for CMAKE_CXX_FLAGS_RELEASE is "-O3 -DNDEBUG". Let's avoid "-O3" for consistency
638+
# between Release and RelWithDebInfo. And let's not set -DNDEBUG because we're setting that manually
639+
# based on LLVM_ENABLE_ASSERTIONS.
640+
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
641+
642+
_compute_lto_flag("${SWIFT_TOOLS_ENABLE_LTO}" _lto_flag_out)
643+
if(_lto_flag_out)
644+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE} -gline-tables-only")
645+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -gline-tables-only")
646+
endif()
647+
else()
648+
649+
endif()
650+
636651
#
637652
# Configure SDKs.
638653
#

cmake/modules/AddSwift.cmake

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,18 @@ function(_add_host_variant_c_compile_flags target)
130130
_add_host_variant_c_compile_link_flags(${target})
131131

132132
is_build_type_optimized("${CMAKE_BUILD_TYPE}" optimized)
133-
if(optimized)
134-
if("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
135-
target_compile_options(${target} PRIVATE -Os)
136-
else()
137-
target_compile_options(${target} PRIVATE -O2)
138-
endif()
133+
is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" debuginfo)
134+
135+
# Add -O0/-O2/-O3/-Os/-g/-momit-leaf-frame-pointer/... based on CMAKE_BUILD_TYPE.
136+
target_compile_options(${target} PRIVATE "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}")
139137

138+
if(optimized)
140139
# Omit leaf frame pointers on x86 production builds (optimized, no debug
141140
# info, and no asserts).
142-
is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" debug)
143-
if(NOT debug AND NOT LLVM_ENABLE_ASSERTIONS)
141+
if(NOT debuginfo AND NOT LLVM_ENABLE_ASSERTIONS)
142+
# Unfortunately, this cannot be folded into the standard
143+
# CMAKE_CXX_FLAGS_... because Apple multi-SDK builds use different
144+
# architectures for different SDKs.
144145
if(SWIFT_HOST_VARIANT_ARCH MATCHES "i?86")
145146
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
146147
target_compile_options(${target} PRIVATE -momit-leaf-frame-pointer)
@@ -149,27 +150,6 @@ function(_add_host_variant_c_compile_flags target)
149150
endif()
150151
endif()
151152
endif()
152-
else()
153-
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
154-
target_compile_options(${target} PRIVATE -O0)
155-
else()
156-
target_compile_options(${target} PRIVATE /Od)
157-
endif()
158-
endif()
159-
160-
# CMake automatically adds the flags for debug info if we use MSVC/clang-cl.
161-
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
162-
is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" debuginfo)
163-
if(debuginfo)
164-
_compute_lto_flag("${SWIFT_TOOLS_ENABLE_LTO}" _lto_flag_out)
165-
if(_lto_flag_out)
166-
target_compile_options(${target} PRIVATE -gline-tables-only)
167-
else()
168-
target_compile_options(${target} PRIVATE -g)
169-
endif()
170-
else()
171-
target_compile_options(${target} PRIVATE -g0)
172-
endif()
173153
endif()
174154

175155
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ static CanSILFunctionType getAutoDiffDifferentialType(
407407
// result's convention is indirect.
408408
if (tl.isAddressOnly() && !isIndirectFormalResult(origResConv)) {
409409
switch (origResConv) {
410+
case ResultConvention::Unowned:
410411
case ResultConvention::Owned:
411412
return ResultConvention::Indirect;
412413
default:

lib/SILOptimizer/ARC/ARCMatchingSet.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ ARCMatchingSetBuilder::matchIncrementsToDecrements() {
6868
continue;
6969
}
7070

71-
// We need to be known safe over all increments/decrements we are matching
72-
// up to ignore insertion points.
7371
bool BUIsKnownSafe = (*BURefCountState)->second.isKnownSafe();
7472
LLVM_DEBUG(llvm::dbgs() << " BOTTOM UP KNOWNSAFE: "
7573
<< (BUIsKnownSafe ? "true" : "false") << "\n");
@@ -152,8 +150,6 @@ ARCMatchingSetBuilder::matchDecrementsToIncrements() {
152150
continue;
153151
}
154152

155-
// We need to be known safe over all increments/decrements we are matching
156-
// up to ignore insertion points.
157153
bool TDIsKnownSafe = (*TDRefCountState)->second.isKnownSafe();
158154
LLVM_DEBUG(llvm::dbgs() << " TOP DOWN KNOWNSAFE: "
159155
<< (TDIsKnownSafe ? "true" : "false") << "\n");
@@ -223,7 +219,7 @@ bool ARCMatchingSetBuilder::matchUpIncDecSetsForPtr() {
223219
LLVM_DEBUG(llvm::dbgs() << "Attempting to match up increments -> "
224220
"decrements:\n");
225221
// For each increment in our list of new increments, attempt to match them
226-
// up with decrements and gather the insertion points of the decrements.
222+
// up with decrements.
227223
auto Result = matchIncrementsToDecrements();
228224
if (!Result) {
229225
LLVM_DEBUG(llvm::dbgs() << " FAILED TO MATCH INCREMENTS -> "
@@ -287,8 +283,6 @@ bool ARCMatchingSetBuilder::matchUpIncDecSetsForPtr() {
287283
assert(MatchSet.Increments.empty() == MatchSet.Decrements.empty() &&
288284
"Match set without increments or decrements");
289285

290-
// If we do not have any insertion points but we do have increments, we must
291-
// be eliminating pairs.
292286
if (!MatchSet.Increments.empty())
293287
MatchedPair = true;
294288

lib/SILOptimizer/ARC/ARCRegionState.cpp

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#define DEBUG_TYPE "arc-sequence-opts"
1414
#include "ARCRegionState.h"
15+
#include "ARCSequenceOptUtils.h"
1516
#include "RCStateTransitionVisitors.h"
1617
#include "swift/Basic/Range.h"
1718
#include "swift/SILOptimizer/Analysis/LoopRegionAnalysis.h"
@@ -155,77 +156,6 @@ void ARCRegionState::mergePredTopDown(ARCRegionState &PredRegionState) {
155156
// Bottom Up Dataflow
156157
//
157158

158-
static bool isARCSignificantTerminator(TermInst *TI) {
159-
switch (TI->getTermKind()) {
160-
case TermKind::UnreachableInst:
161-
// br is a forwarding use for its arguments. It cannot in of itself extend
162-
// the lifetime of an object (just like a phi-node) cannot.
163-
case TermKind::BranchInst:
164-
// A cond_br is a forwarding use for its non-operand arguments in a similar
165-
// way to br. Its operand must be an i1 that has a different lifetime from any
166-
// ref counted object.
167-
case TermKind::CondBranchInst:
168-
return false;
169-
// Be conservative for now. These actually perform some sort of operation
170-
// against the operand or can use the value in some way.
171-
case TermKind::ThrowInst:
172-
case TermKind::ReturnInst:
173-
case TermKind::UnwindInst:
174-
case TermKind::YieldInst:
175-
case TermKind::TryApplyInst:
176-
case TermKind::SwitchValueInst:
177-
case TermKind::SwitchEnumInst:
178-
case TermKind::SwitchEnumAddrInst:
179-
case TermKind::DynamicMethodBranchInst:
180-
case TermKind::CheckedCastBranchInst:
181-
case TermKind::CheckedCastValueBranchInst:
182-
case TermKind::CheckedCastAddrBranchInst:
183-
return true;
184-
}
185-
186-
llvm_unreachable("Unhandled TermKind in switch.");
187-
}
188-
189-
// Visit each one of our predecessor regions and see if any are blocks that can
190-
// use reference counted values. If any of them do, we advance the sequence for
191-
// the pointer and create an insertion point here. This state will be propagated
192-
// into all of our predecessors, allowing us to be conservatively correct in all
193-
// cases.
194-
//
195-
// The key thing to notice is that in general this cannot happen due to
196-
// critical edge splitting. To trigger this, one would need a terminator that
197-
// uses a reference counted value and only has one successor due to critical
198-
// edge splitting. This is just to be conservative when faced with the unknown
199-
// of future changes.
200-
//
201-
// We do not need to worry about loops here, since a loop exit block can only
202-
// have predecessors in the loop itself implying that loop exit blocks at the
203-
// loop region level always have only one predecessor, the loop itself.
204-
void ARCRegionState::processBlockBottomUpPredTerminators(
205-
const LoopRegion *R, AliasAnalysis *AA, LoopRegionFunctionInfo *LRFI,
206-
ImmutablePointerSetFactory<SILInstruction> &SetFactory) {
207-
llvm::TinyPtrVector<SILInstruction *> PredTerminators;
208-
for (unsigned PredID : R->getPreds()) {
209-
auto *PredRegion = LRFI->getRegion(PredID);
210-
if (!PredRegion->isBlock())
211-
continue;
212-
213-
auto *TermInst = PredRegion->getBlock()->getTerminator();
214-
if (!isARCSignificantTerminator(TermInst))
215-
continue;
216-
PredTerminators.push_back(TermInst);
217-
}
218-
219-
for (auto &OtherState : getBottomupStates()) {
220-
// If the other state's value is blotted, skip it.
221-
if (!OtherState.hasValue())
222-
continue;
223-
224-
OtherState->second.updateForPredTerminators(PredTerminators,
225-
SetFactory, AA);
226-
}
227-
}
228-
229159
static bool processBlockBottomUpInsts(
230160
ARCRegionState &State, SILBasicBlock &BB,
231161
BottomUpDataflowRCStateVisitor<ARCRegionState> &DataflowVisitor,
@@ -239,9 +169,9 @@ static bool processBlockBottomUpInsts(
239169
if (II == IE)
240170
return false;
241171

242-
// If II is the terminator, skip it since our terminator was already processed
243-
// in our successors.
244-
if (*II == BB.getTerminator())
172+
// If II is not an arc significant terminator, skip it.
173+
if (*II == BB.getTerminator() &&
174+
!isARCSignificantTerminator(cast<TermInst>(*II)))
245175
++II;
246176

247177
bool NestingDetected = false;
@@ -298,18 +228,10 @@ bool ARCRegionState::processBlockBottomUp(
298228
RCIA, EAFI, *this, FreezeOwnedArgEpilogueReleases, IncToDecStateMap,
299229
SetFactory);
300230

301-
// Visit each non-terminator arc relevant instruction I in BB visited in
302-
// reverse...
231+
// Visit each arc relevant instruction I in BB visited in reverse...
303232
bool NestingDetected =
304233
processBlockBottomUpInsts(*this, BB, DataflowVisitor, AA, SetFactory);
305234

306-
// Now visit each one of our predecessor regions and see if any are blocks
307-
// that can use reference counted values. If any of them do, we advance the
308-
// sequence for the pointer and create an insertion point here. This state
309-
// will be propagated into all of our predecessors, allowing us to be
310-
// conservatively correct in all cases.
311-
processBlockBottomUpPredTerminators(R, AA, LRFI, SetFactory);
312-
313235
return NestingDetected;
314236
}
315237

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===--- ARCSequenceOptUtils.cpp - ARCSequenceOpt utilities ------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "ARCSequenceOptUtils.h"
14+
15+
using namespace swift;
16+
namespace swift {
17+
bool isARCSignificantTerminator(TermInst *TI) {
18+
switch (TI->getTermKind()) {
19+
case TermKind::UnreachableInst:
20+
// br is a forwarding use for its arguments. It cannot in of itself extend
21+
// the lifetime of an object (just like a phi-node) cannot.
22+
case TermKind::BranchInst:
23+
// A cond_br is a forwarding use for its non-operand arguments in a similar
24+
// way to br. Its operand must be an i1 that has a different lifetime from any
25+
// ref counted object.
26+
case TermKind::CondBranchInst:
27+
return false;
28+
// Be conservative for now. These actually perform some sort of operation
29+
// against the operand or can use the value in some way.
30+
case TermKind::ThrowInst:
31+
case TermKind::ReturnInst:
32+
case TermKind::UnwindInst:
33+
case TermKind::YieldInst:
34+
case TermKind::TryApplyInst:
35+
case TermKind::SwitchValueInst:
36+
case TermKind::SwitchEnumInst:
37+
case TermKind::SwitchEnumAddrInst:
38+
case TermKind::DynamicMethodBranchInst:
39+
case TermKind::CheckedCastBranchInst:
40+
case TermKind::CheckedCastValueBranchInst:
41+
case TermKind::CheckedCastAddrBranchInst:
42+
return true;
43+
}
44+
45+
llvm_unreachable("Unhandled TermKind in switch.");
46+
}
47+
48+
} // end namespace 'swift'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===--- ARCSequenceOptUtils.h - ARCSequenceOpts utilities ----*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
///
13+
/// Utilities used by the ARCSequenceOpts for analyzing and transforming
14+
/// SILInstructions.
15+
///
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_SILOPTIMIZER_ARC_ARCSEQUENCEOPTUTILS_H
19+
#define SWIFT_SILOPTIMIZER_ARC_ARCSEQUENCEOPTUTILS_H
20+
21+
#include "swift/SIL/SILInstruction.h"
22+
23+
namespace swift {
24+
bool isARCSignificantTerminator(TermInst *TI);
25+
} // end namespace swift
26+
27+
#endif

lib/SILOptimizer/ARC/ARCSequenceOpts.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ llvm::cl::opt<bool> EnableLoopARC("enable-loop-arc", llvm::cl::init(false));
4545
// Code Motion
4646
//===----------------------------------------------------------------------===//
4747

48-
// This routine takes in the ARCMatchingSet \p MatchSet and inserts new
49-
// increments, decrements at the insertion points and adds the old increment,
50-
// decrements to the delete list. Sets changed to true if anything was moved or
51-
// deleted.
48+
// This routine takes in the ARCMatchingSet \p MatchSet and adds the increments
49+
// and decrements to the delete list.
5250
void ARCPairingContext::optimizeMatchingSet(
5351
ARCMatchingSet &MatchSet, llvm::SmallVectorImpl<SILInstruction *> &NewInsts,
5452
llvm::SmallVectorImpl<SILInstruction *> &DeadInsts) {
@@ -99,9 +97,6 @@ bool ARCPairingContext::performMatching(
9997
for (auto *I : Set.Decrements)
10098
DecToIncStateMap.erase(I);
10199

102-
// Add the Set to the callback. *NOTE* No instruction destruction can
103-
// happen here since we may remove instructions that are insertion points
104-
// for other instructions.
105100
optimizeMatchingSet(Set, NewInsts, DeadInsts);
106101
}
107102
}

lib/SILOptimizer/ARC/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target_sources(swiftSILOptimizer PRIVATE
44
ARCMatchingSet.cpp
55
ARCRegionState.cpp
66
ARCSequenceOpts.cpp
7+
ARCSequenceOptUtils.cpp
78
GlobalARCSequenceDataflow.cpp
89
GlobalLoopARCSequenceDataflow.cpp
910
RCStateTransition.cpp

0 commit comments

Comments
 (0)