Skip to content

Commit 5d5dbd9

Browse files
Merge pull request #66077 from aschwaighofer/wip_enable_opaque_pointers
Enable usage of LLVM's opaque pointer
2 parents 19ad0c5 + 0d4dec1 commit 5d5dbd9

File tree

597 files changed

+1595
-844
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

597 files changed

+1595
-844
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ importer::addCommonInvocationArguments(
845845
invocationArgStrs.push_back("-fansi-escape-codes");
846846

847847
invocationArgStrs.push_back("-Xclang");
848-
invocationArgStrs.push_back("-no-opaque-pointers");
848+
invocationArgStrs.push_back("-opaque-pointers");
849849

850850
if (importerOpts.ValidateModulesOnce) {
851851
invocationArgStrs.push_back("-fmodules-validate-once-per-build-session");

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5190,7 +5190,8 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
51905190
}
51915191

51925192
if (auto *GV = dyn_cast<llvm::GlobalVariable>(addr.getValue()))
5193-
GV->setComdat(nullptr);
5193+
if (GV->isDeclaration())
5194+
GV->setComdat(nullptr);
51945195

51955196
// FIXME: MC breaks when emitting alias references on some platforms
51965197
// (rdar://problem/22450593 ). Work around this by referring to the aliasee

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,6 +2817,7 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
28172817
llvm::DIExpression *Expr, unsigned Line, unsigned Col,
28182818
llvm::DILocalScope *Scope, const SILDebugScope *DS, bool InCoroContext,
28192819
AddrDbgInstrKind AddrDInstKind) {
2820+
Storage = Storage->stripPointerCasts();
28202821
// Set the location/scope of the intrinsic.
28212822
auto *InlinedAt = createInlinedAt(DS);
28222823
auto DL =

lib/IRGen/IRGenSIL.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -981,17 +981,24 @@ class IRGenSILFunction :
981981
&& !isAnonymous;
982982
}
983983

984-
bool shouldShadowStorage(llvm::Value *Storage) {
985-
return !isa<llvm::AllocaInst>(Storage)
986-
&& !isa<llvm::UndefValue>(Storage)
987-
&& needsShadowCopy(Storage);
984+
bool shouldShadowStorage(llvm::Value *Storage,
985+
llvm::Type *StorageType) {
986+
Storage = Storage->stripPointerCasts();
987+
if (isa<llvm::UndefValue>(Storage))
988+
return false;
989+
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(Storage);
990+
Alloca && Alloca->isStaticAlloca() &&
991+
Alloca->getAllocatedType() == StorageType)
992+
return false;
993+
return needsShadowCopy(Storage);
988994
}
989995

990996
/// At -Onone, emit a shadow copy of an Address in an alloca, so the
991997
/// register allocator doesn't elide the dbg.value intrinsic when
992998
/// register pressure is high. There is a trade-off to this: With
993999
/// shadow copies, we lose the precise lifetime.
9941000
llvm::Value *emitShadowCopyIfNeeded(llvm::Value *Storage,
1001+
llvm::Type *StorageType,
9951002
const SILDebugScope *Scope,
9961003
SILDebugVariable VarInfo,
9971004
bool IsAnonymous, bool WasMoved,
@@ -1011,7 +1018,7 @@ class IRGenSILFunction :
10111018
// This condition must be consistent with emitPoisonDebugValueInst to avoid
10121019
// generating extra shadow copies for debug_value [poison].
10131020
if (!shouldShadowVariable(VarInfo, IsAnonymous)
1014-
|| !shouldShadowStorage(Storage)) {
1021+
|| !shouldShadowStorage(Storage, StorageType)) {
10151022
return Storage;
10161023
}
10171024

@@ -1034,11 +1041,12 @@ class IRGenSILFunction :
10341041
/// Like \c emitShadowCopyIfNeeded() but takes an \c Address instead of an
10351042
/// \c llvm::Value.
10361043
llvm::Value *emitShadowCopyIfNeeded(Address Storage,
1044+
llvm::Type *StorageType,
10371045
const SILDebugScope *Scope,
10381046
SILDebugVariable VarInfo,
10391047
bool IsAnonymous, bool WasMoved) {
1040-
return emitShadowCopyIfNeeded(Storage.getAddress(), Scope, VarInfo,
1041-
IsAnonymous, WasMoved,
1048+
return emitShadowCopyIfNeeded(Storage.getAddress(), StorageType, Scope,
1049+
VarInfo, IsAnonymous, WasMoved,
10421050
Storage.getAlignment());
10431051
}
10441052

@@ -1072,7 +1080,9 @@ class IRGenSILFunction :
10721080
return;
10731081

10741082
if (e.size() == 1) {
1075-
copy.push_back(emitShadowCopyIfNeeded(e.claimNext(), Scope, VarInfo,
1083+
auto &ti = getTypeInfo(SILVal->getType());
1084+
copy.push_back(emitShadowCopyIfNeeded(e.claimNext(), ti.getStorageType(),
1085+
Scope, VarInfo,
10761086
IsAnonymous, WasMoved));
10771087
return;
10781088
}
@@ -1116,7 +1126,7 @@ class IRGenSILFunction :
11161126
llvm::raw_svector_ostream(Buf) << "$pack_count_" << Position;
11171127
auto Name = IGM.Context.getIdentifier(Buf.str());
11181128
SILDebugVariable Var(Name.str(), true, 0);
1119-
Shape = emitShadowCopyIfNeeded(Shape, getDebugScope(), Var, false,
1129+
Shape = emitShadowCopyIfNeeded(Shape, nullptr, getDebugScope(), Var, false,
11201130
false /*was move*/);
11211131
if (IGM.DebugInfo)
11221132
IGM.DebugInfo->emitPackCountParameter(*this, Shape, Var);
@@ -5061,7 +5071,7 @@ void IRGenSILFunction::emitErrorResultVar(CanSILFunctionType FnTy,
50615071
auto Var = DbgValue->getVarInfo();
50625072
assert(Var && "error result without debug info");
50635073
auto Storage =
5064-
emitShadowCopyIfNeeded(ErrorResultSlot.getAddress(), getDebugScope(),
5074+
emitShadowCopyIfNeeded(ErrorResultSlot.getAddress(), nullptr, getDebugScope(),
50655075
*Var, false, false /*was move*/);
50665076
if (!IGM.DebugInfo)
50675077
return;
@@ -5108,7 +5118,7 @@ void IRGenSILFunction::emitPoisonDebugValueInst(DebugValueInst *i) {
51085118
// copy--poison should never affect program behavior. Also filter everything
51095119
// not handled by emitShadowCopyIfNeeded to avoid extra shadow copies.
51105120
if (!shouldShadowVariable(*varInfo, isAnonymous)
5111-
|| !shouldShadowStorage(storage)) {
5121+
|| !shouldShadowStorage(storage, nullptr)) {
51125122
return;
51135123
}
51145124

@@ -5255,13 +5265,15 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
52555265

52565266
// Put the value into a shadow-copy stack slot at -Onone.
52575267
llvm::SmallVector<llvm::Value *, 8> Copy;
5258-
if (IsAddrVal)
5268+
if (IsAddrVal) {
5269+
auto &ti = getTypeInfo(SILVal->getType());
52595270
Copy.emplace_back(emitShadowCopyIfNeeded(
5260-
getLoweredAddress(SILVal).getAddress(), i->getDebugScope(), *VarInfo,
5271+
getLoweredAddress(SILVal).getAddress(), ti.getStorageType(), i->getDebugScope(), *VarInfo,
52615272
IsAnonymous, i->getUsesMoveableValueDebugInfo()));
5262-
else
5273+
} else {
52635274
emitShadowCopyIfNeeded(SILVal, i->getDebugScope(), *VarInfo, IsAnonymous,
52645275
i->getUsesMoveableValueDebugInfo(), Copy);
5276+
}
52655277

52665278
bindArchetypes(DbgTy.getType());
52675279
if (!IGM.DebugInfo)
@@ -5882,9 +5894,10 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
58825894
auto VarInfo = i->getVarInfo();
58835895
if (!VarInfo)
58845896
return;
5885-
5897+
auto &ti = getTypeInfo(SILTy);
58865898
auto Storage =
5887-
emitShadowCopyIfNeeded(boxWithAddr.getAddress(), i->getDebugScope(),
5899+
emitShadowCopyIfNeeded(boxWithAddr.getAddress(), ti.getStorageType(),
5900+
i->getDebugScope(),
58885901
*VarInfo, IsAnonymous, false /*was moved*/);
58895902

58905903
if (!IGM.DebugInfo)

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ function(_add_target_variant_c_compile_link_flags)
138138
if (_lto_flag_out)
139139
list(APPEND result "${_lto_flag_out}")
140140
# Disable opaque pointers in lto mode.
141-
list(APPEND result "-Xclang")
142-
list(APPEND result "-no-opaque-pointers")
141+
#list(APPEND result "-Xclang")
142+
#list(APPEND result "-no-opaque-pointers")
143143
endif()
144144

145145
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)

test/AutoDiff/IRGen/differentiable_function.sil

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
1+
// RUN: %target-swift-frontend %use_no_opaque_pointers -emit-ir %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-ir %s
23

34
sil_stage raw
45

test/AutoDiff/IRGen/runtime.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-frontend -parse-stdlib %s -emit-ir | %FileCheck %s
1+
// RUN: %target-swift-frontend %use_no_opaque_pointers -parse-stdlib %s -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend -parse-stdlib %s -emit-ir
23

34
import Swift
45
import _Differentiation

test/AutoDiff/IRGen/witness_table_differentiable_requirements.sil

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-frontend -parse-sil %s -emit-ir | %FileCheck %s
1+
// RUN: %target-swift-frontend %use_no_opaque_pointers -parse-sil %s -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend -parse-sil %s -emit-ir
23
// REQUIRES: CPU=x86_64
34

45
sil_stage canonical

test/AutoDiff/SIL/differentiability_witness_function_inst.sil

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
// IRGen test.
1717

18-
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=Simplification -emit-ir %s | %FileCheck %s --check-prefix=IRGEN --check-prefix %target-cpu
18+
// RUN: %target-swift-frontend %use_no_opaque_pointers -Xllvm -sil-disable-pass=Simplification -emit-ir %s | %FileCheck %s --check-prefix=IRGEN --check-prefix %target-cpu
19+
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=Simplification -emit-ir %s
1920
// NOTE: `%target-cpu`-specific FileCheck lines exist because lowered function types in LLVM IR differ between architectures.
2021

2122
// `shell` is required only to run `sed` as a

test/AutoDiff/SIL/differentiable_function_inst.sil

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
// IRGen test.
1717

18-
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=CHECK-IRGEN
18+
// RUN: %target-swift-frontend %use_no_opaque_pointers -emit-ir %s | %FileCheck %s --check-prefix=CHECK-IRGEN
19+
// RUN: %target-swift-frontend -emit-ir %s
1920

2021
// `shell` is required only to run `sed` as a
2122
// https://github.com/apple/swift/issues/54526 workaround.

0 commit comments

Comments
 (0)