Skip to content

Commit 211f95a

Browse files
authored
Merge pull request #3788 from swiftwasm/main
2 parents cecd6af + 50b44f0 commit 211f95a

19 files changed

+286
-51
lines changed

cmake/caches/Windows-arm64.cmake

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
set(LLVM_ENABLE_PROJECTS
2+
clang
3+
clang-tools-extra
4+
lld
5+
lldb
6+
CACHE STRING "")
7+
8+
set(LLVM_EXTERNAL_PROJECTS
9+
cmark
10+
swift
11+
CACHE STRING "")
12+
13+
set(LLVM_ENABLE_RUNTIMES
14+
compiler-rt
15+
CACHE STRING "")
16+
17+
# NOTE(compnerd) always enable assertions, the toolchain will not provide enough
18+
# context to resolve issues otherwise and may silently generate invalid output.
19+
set(LLVM_ENABLE_ASSERTIONS YES CACHE BOOL "")
20+
21+
set(ENABLE_X86_RELAX_RELOCATIONS YES CACHE BOOL "")
22+
23+
# NOTE(compnerd) we can hardcode the default target triple since the cache files
24+
# are target dependent.
25+
set(LLVM_DEFAULT_TARGET_TRIPLE aarch64-unknown-windows-msvc CACHE STRING "")
26+
27+
set(LLVM_APPEND_VC_REV NO CACHE BOOL "")
28+
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR YES CACHE BOOL "")
29+
set(LLVM_ENABLE_PYTHON YES CACHE BOOL "")
30+
set(LLVM_RUNTIME_TARGETS
31+
aarch64-unknown-windows-msvc
32+
CACHE STRING "")
33+
foreach(target ${LLVM_RUNTIME_TARGETS})
34+
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
35+
compiler-rt
36+
CACHE STRING "")
37+
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
38+
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
39+
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
40+
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
41+
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")
42+
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE YES CACHE BOOL "")
43+
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS NO CACHE BOOL "")
44+
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY NO CACHE BOOL "")
45+
endforeach()
46+
47+
set(LLVM_TARGETS_TO_BUILD AArch64 ARM WebAssembly X86 CACHE STRING "")
48+
49+
# Disable certain targets to reduce the configure time or to avoid configuration
50+
# differences (and in some cases weird build errors on a complete build).
51+
set(LLVM_BUILD_LLVM_DYLIB NO CACHE BOOL "")
52+
set(LLVM_BUILD_LLVM_C_DYLIB NO CACHE BOOL "")
53+
set(LLVM_ENABLE_LIBEDIT NO CACHE BOOL "")
54+
set(LLVM_ENABLE_LIBXML2 NO CACHE BOOL "")
55+
set(LLVM_ENABLE_OCAMLDOC NO CACHE BOOL "")
56+
set(LLVM_ENABLE_TERMINFO NO CACHE BOOL "")
57+
set(LLVM_ENABLE_Z3_SOLVER NO CACHE BOOL "")
58+
set(LLVM_ENABLE_ZLIB NO CACHE BOOL "")
59+
set(LLVM_INCLUDE_BENCHMARKS NO CACHE BOOL "")
60+
set(LLVM_INCLUDE_DOCS NO CACHE BOOL "")
61+
set(LLVM_INCLUDE_EXAMPLES NO CACHE BOOL "")
62+
set(LLVM_INCLUDE_GO_TESTS NO CACHE BOOL "")
63+
set(LLVM_TOOL_GOLD_BUILD NO CACHE BOOL "")
64+
set(LLVM_TOOL_LLVM_SHLIB_BUILD NO CACHE BOOL "")
65+
66+
# Avoid swig dependency for lldb
67+
set(LLDB_ALLOW_STATIC_BINDINGS YES CACHE BOOL "")
68+
set(LLDB_USE_STATIC_BINDINGS YES CACHE BOOL "")
69+
70+
# This requires perl which may not be available on Windows
71+
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")
72+
set(SWIFT_BUILD_ENABLE_PARSER_LIB YES CACHE BOOL "")
73+
# static linking is not supported on Windows yet
74+
set(SWIFT_BUILD_STATIC_STDLIB NO CACHE BOOL "")
75+
set(SWIFT_BUILD_STATIC_SDK_OVERLAY NO CACHE BOOL "")
76+
77+
set(LLVM_INSTALL_BINUTILS_SYMLINKS YES CACHE BOOL "")
78+
set(LLVM_INSTALL_TOOLCHAIN_ONLY YES CACHE BOOL "")
79+
set(LLVM_TOOLCHAIN_TOOLS
80+
addr2line
81+
ar
82+
c++filt
83+
dsymutil
84+
dwp
85+
# lipo
86+
llvm-ar
87+
llvm-cov
88+
llvm-cvtres
89+
llvm-cxxfilt
90+
llvm-dlltool
91+
llvm-dwarfdump
92+
llvm-dwp
93+
llvm-lib
94+
llvm-lipo
95+
llvm-mt
96+
llvm-nm
97+
llvm-objcopy
98+
llvm-objdump
99+
llvm-pdbutil
100+
llvm-profdata
101+
llvm-ranlib
102+
llvm-rc
103+
llvm-readelf
104+
llvm-readobj
105+
llvm-size
106+
llvm-strings
107+
llvm-strip
108+
llvm-symbolizer
109+
llvm-undname
110+
nm
111+
objcopy
112+
objdump
113+
ranlib
114+
readelf
115+
size
116+
strings
117+
CACHE STRING "")
118+
119+
set(CLANG_TOOLS
120+
clang
121+
clangd
122+
clang-format
123+
clang-resource-headers
124+
clang-tidy
125+
CACHE STRING "")
126+
127+
set(LLD_TOOLS
128+
lld
129+
CACHE STRING "")
130+
131+
set(LLDB_TOOLS
132+
liblldb
133+
lldb
134+
lldb-argdumper
135+
lldb-python-scripts
136+
lldb-server
137+
lldb-vscode
138+
repl_swift
139+
CACHE STRING "")
140+
141+
set(SWIFT_INSTALL_COMPONENTS
142+
autolink-driver
143+
compiler
144+
clang-builtin-headers
145+
editor-integration
146+
tools
147+
sourcekit-inproc
148+
swift-remote-mirror
149+
swift-remote-mirror-headers
150+
parser-lib
151+
CACHE STRING "")
152+
153+
set(LLVM_DISTRIBUTION_COMPONENTS
154+
IndexStore
155+
libclang
156+
libclang-headers
157+
LTO
158+
runtimes
159+
${LLVM_TOOLCHAIN_TOOLS}
160+
${CLANG_TOOLS}
161+
${LLD_TOOLS}
162+
${LLDB_TOOLS}
163+
${SWIFT_INSTALL_COMPONENTS}
164+
CACHE STRING "")

lib/IRGen/GenMeta.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,29 +334,56 @@ void IRGenModule::emitNonoverriddenMethodDescriptor(const SILVTable *VTable,
334334
getAddrOfLLVMVariable(entity, init, DebugTypeInfo());
335335
}
336336

337+
void IRGenModule::setVCallVisibility(llvm::GlobalVariable *var,
338+
llvm::GlobalObject::VCallVisibility vis,
339+
std::pair<uint64_t, uint64_t> range) {
340+
// Insert attachment of !vcall_visibility !{ vis, range.first, range.second }
341+
var->addMetadata(
342+
llvm::LLVMContext::MD_vcall_visibility,
343+
*llvm::MDNode::get(getLLVMContext(),
344+
{
345+
llvm::ConstantAsMetadata::get(
346+
llvm::ConstantInt::get(Int64Ty, vis)),
347+
llvm::ConstantAsMetadata::get(
348+
llvm::ConstantInt::get(Int64Ty, range.first)),
349+
llvm::ConstantAsMetadata::get(
350+
llvm::ConstantInt::get(Int64Ty, range.second)),
351+
}));
352+
// Insert attachment of !typed_global_not_for_cfi !{}
353+
var->addMetadata("typed_global_not_for_cfi",
354+
*llvm::MDNode::get(getLLVMContext(), {}));
355+
}
356+
337357
void IRGenModule::addVTableTypeMetadata(
338358
ClassDecl *decl, llvm::GlobalVariable *var,
339359
SmallVector<std::pair<Size, SILDeclRef>, 8> vtableEntries) {
360+
if (vtableEntries.empty())
361+
return;
362+
363+
uint64_t minOffset = UINT64_MAX;
364+
uint64_t maxOffset = 0;
340365
for (auto ventry : vtableEntries) {
341366
auto method = ventry.second;
342367
auto offset = ventry.first.getValue();
343368
var->addTypeMetadata(offset, typeIdForMethod(*this, method));
369+
minOffset = std::min(minOffset, offset);
370+
maxOffset = std::max(maxOffset, offset);
344371
}
345372

373+
using VCallVisibility = llvm::GlobalObject::VCallVisibility;
374+
VCallVisibility vis = VCallVisibility::VCallVisibilityPublic;
346375
auto AS = decl->getFormalAccessScope();
347376
if (AS.isFileScope()) {
348-
var->setVCallVisibilityMetadata(
349-
llvm::GlobalObject::VCallVisibility::VCallVisibilityTranslationUnit);
377+
vis = VCallVisibility::VCallVisibilityTranslationUnit;
350378
} else if (AS.isPrivate() || AS.isInternal()) {
351-
var->setVCallVisibilityMetadata(
352-
llvm::GlobalObject::VCallVisibility::VCallVisibilityLinkageUnit);
379+
vis = VCallVisibility::VCallVisibilityLinkageUnit;
353380
} else if (getOptions().InternalizeAtLink) {
354-
var->setVCallVisibilityMetadata(
355-
llvm::GlobalObject::VCallVisibility::VCallVisibilityLinkageUnit);
356-
} else {
357-
var->setVCallVisibilityMetadata(
358-
llvm::GlobalObject::VCallVisibility::VCallVisibilityPublic);
381+
vis = VCallVisibility::VCallVisibilityLinkageUnit;
359382
}
383+
384+
auto relptrSize = DataLayout.getTypeAllocSize(Int32Ty).getValue();
385+
setVCallVisibility(var, vis,
386+
std::make_pair(minOffset, maxOffset + relptrSize));
360387
}
361388

362389
namespace {

lib/IRGen/GenProto.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,9 @@ static void addWTableTypeMetadata(IRGenModule &IGM,
21672167
llvm::GlobalVariable *global,
21682168
SILWitnessTable *wt) {
21692169
auto conf = wt->getConformance();
2170+
2171+
uint64_t minOffset = UINT64_MAX;
2172+
uint64_t maxOffset = 0;
21702173
for (auto entry : wt->getEntries()) {
21712174
if (entry.getKind() != SILWitnessTable::WitnessKind::Method)
21722175
continue;
@@ -2178,30 +2181,36 @@ static void addWTableTypeMetadata(IRGenModule &IGM,
21782181
auto index = fnProtoInfo.getFunctionIndex(member).forProtocolWitnessTable();
21792182
auto offset = index.getValue() * IGM.getPointerSize().getValue();
21802183
global->addTypeMetadata(offset, typeIdForMethod(IGM, member));
2184+
2185+
minOffset = std::min(minOffset, offset);
2186+
maxOffset = std::max(maxOffset, offset);
21812187
}
21822188

2189+
if (minOffset == UINT64_MAX)
2190+
return;
2191+
2192+
using VCallVisibility = llvm::GlobalObject::VCallVisibility;
2193+
VCallVisibility vis = VCallVisibility::VCallVisibilityPublic;
21832194
auto linkage = stripExternalFromLinkage(wt->getLinkage());
21842195
switch (linkage) {
21852196
case SILLinkage::Private:
2186-
global->setVCallVisibilityMetadata(
2187-
llvm::GlobalObject::VCallVisibility::VCallVisibilityTranslationUnit);
2197+
vis = VCallVisibility::VCallVisibilityTranslationUnit;
21882198
break;
21892199
case SILLinkage::Hidden:
21902200
case SILLinkage::Shared:
2191-
global->setVCallVisibilityMetadata(
2192-
llvm::GlobalObject::VCallVisibility::VCallVisibilityLinkageUnit);
2201+
vis = VCallVisibility::VCallVisibilityLinkageUnit;
21932202
break;
21942203
case SILLinkage::Public:
21952204
default:
21962205
if (IGM.getOptions().InternalizeAtLink) {
2197-
global->setVCallVisibilityMetadata(
2198-
llvm::GlobalObject::VCallVisibility::VCallVisibilityLinkageUnit);
2199-
} else {
2200-
global->setVCallVisibilityMetadata(
2201-
llvm::GlobalObject::VCallVisibility::VCallVisibilityPublic);
2206+
vis = VCallVisibility::VCallVisibilityLinkageUnit;
22022207
}
22032208
break;
22042209
}
2210+
2211+
auto relptrSize = IGM.DataLayout.getTypeAllocSize(IGM.Int32Ty).getValue();
2212+
IGM.setVCallVisibility(global, vis,
2213+
std::make_pair(minOffset, maxOffset + relptrSize));
22052214
}
22062215

22072216
void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {

lib/IRGen/IRGenModule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,11 @@ private: \
14511451
bool isDestroyer,
14521452
bool isForeign,
14531453
ForDefinition_t forDefinition);
1454+
1455+
void setVCallVisibility(llvm::GlobalVariable *var,
1456+
llvm::GlobalObject::VCallVisibility visibility,
1457+
std::pair<uint64_t, uint64_t> range);
1458+
14541459
void addVTableTypeMetadata(
14551460
ClassDecl *decl, llvm::GlobalVariable *var,
14561461
SmallVector<std::pair<Size, SILDeclRef>, 8> vtableEntries);

test/IRGen/conditional-dead-strip-exec.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
// REQUIRES: executable_test
1414

15-
// Test disabled until LLVM GlobalDCE supports conditional references.
16-
// REQUIRES: rdar81868900
15+
// FIXME(mracek): More work needed to get this to work on non-Apple platforms.
16+
// REQUIRES: VENDOR=apple
1717

1818
// (1) used
1919
@inline(never) func func1_used() { print("func1_used") }

test/IRGen/virtual-function-elimination-exec.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
// REQUIRES: executable_test
1313

14-
// Test disabled until LLVM GlobalDCE supports Swift vtables.
15-
// REQUIRES: rdar81868930
14+
// FIXME(mracek): More work needed to get this to work on non-Apple platforms.
15+
// REQUIRES: VENDOR=apple
1616

1717
class MyClass {
1818
func foo() { print("MyClass.foo") }

test/IRGen/virtual-function-elimination-ir-thunks.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: %target-build-swift -Xfrontend -disable-objc-interop -Xfrontend -enable-llvm-vfe -parse-as-library %s -DLIBRARY -module-name Library -emit-module -o %t/Library.swiftmodule
66
// RUN: %target-build-swift -Xfrontend -disable-objc-interop -Xfrontend -enable-llvm-vfe -parse-as-library %s -DCLIENT -module-name Main -I%t -emit-ir -o - | %FileCheck %s
77

8+
// UNSUPPORTED: OS=windows-msvc
9+
810
#if LIBRARY
911

1012
public class MyLibraryClass {

test/IRGen/virtual-function-elimination-ir.swift

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ class MyDerivedClass: MyClass {
1818

1919
// Has vfunc slots at offsets 56, 64, 72 (in swift.method_descriptor structs).
2020
// CHECK: @"$s4main7MyClassCMn" =
21-
// CHECK-SAME: align 4, !type !0, !type !1, !type !2, !vcall_visibility !3
21+
// CHECK-SAME: align 4, !type !0, !type !1, !type !2, !vcall_visibility !3, !typed_global_not_for_cfi !4
2222

2323
// Has vfunc slots at offsets 72, 80, 88 (on 64-bit) / 48, 52, 56 (on 32-bit).
2424
// CHECK: @"$s4main7MyClassCMf" =
25-
// CHECK-64-SAME: align 8, !type !4, !type !5, !type !6, !vcall_visibility !3
26-
// CHECK-32-SAME: align 4, !type !4, !type !5, !type !6, !vcall_visibility !3
25+
// CHECK-64-SAME: align 8, !type !5, !type !6, !type !7, !vcall_visibility !8, !typed_global_not_for_cfi !4
26+
// CHECK-32-SAME: align 4, !type !5, !type !6, !type !7, !vcall_visibility !8, !typed_global_not_for_cfi !4
2727

2828
// Has vfunc slots at offsets 56, 68, 80 (in swift.method_override_descriptor structs).
2929
// CHECK: @"$s4main14MyDerivedClassCMn" =
30-
// CHECK-SAME: align 4, !type !0, !type !7, !type !8, !vcall_visibility !3
30+
// CHECK-SAME: align 4, !type !0, !type !9, !type !10, !vcall_visibility !11, !typed_global_not_for_cfi !4
3131

3232
// Has vfunc slots at offsets 72, 80, 88 (on 64-bit) / 48, 52, 56 (on 32-bit)
3333
// CHECK: @"$s4main14MyDerivedClassCMf" =
34-
// CHECK-64-SAME: align 8, !type !4, !type !5, !type !6, !vcall_visibility !3
35-
// CHECK-32-SAME: align 4, !type !4, !type !5, !type !6, !vcall_visibility !3
34+
// CHECK-64-SAME: align 8, !type !5, !type !6, !type !7, !vcall_visibility !8, !typed_global_not_for_cfi !4
35+
// CHECK-32-SAME: align 4, !type !5, !type !6, !type !7, !vcall_visibility !8, !typed_global_not_for_cfi !4
3636

3737

3838
func func1() {
@@ -56,19 +56,25 @@ func func2() {
5656
// CHECK-64: !0 = !{i64 56, !"$s4main7MyClassC3fooyyFTq"}
5757
// CHECK-64: !1 = !{i64 64, !"$s4main7MyClassC3baryyFTq"}
5858
// CHECK-64: !2 = !{i64 72, !"$s4main7MyClassCACycfCTq"}
59-
// CHECK-64: !3 = !{i64 1}
60-
// CHECK-64: !4 = !{i64 72, !"$s4main7MyClassC3fooyyFTq"}
61-
// CHECK-64: !5 = !{i64 80, !"$s4main7MyClassC3baryyFTq"}
62-
// CHECK-64: !6 = !{i64 88, !"$s4main7MyClassCACycfCTq"}
63-
// CHECK-64: !7 = !{i64 68, !"$s4main7MyClassC3baryyFTq"}
64-
// CHECK-64: !8 = !{i64 80, !"$s4main7MyClassCACycfCTq"}
59+
// CHECK-64: !3 = !{i64 1, i64 56, i64 76}
60+
// CHECK-64: !4 = !{}
61+
// CHECK-64: !5 = !{i64 72, !"$s4main7MyClassC3fooyyFTq"}
62+
// CHECK-64: !6 = !{i64 80, !"$s4main7MyClassC3baryyFTq"}
63+
// CHECK-64: !7 = !{i64 88, !"$s4main7MyClassCACycfCTq"}
64+
// CHECK-64: !8 = !{i64 1, i64 72, i64 92}
65+
// CHECK-64: !9 = !{i64 68, !"$s4main7MyClassC3baryyFTq"}
66+
// CHECK-64: !10 = !{i64 80, !"$s4main7MyClassCACycfCTq"}
67+
// CHECK-64: !11 = !{i64 1, i64 56, i64 84}
6568

6669
// CHECK-32: !0 = !{i64 56, !"$s4main7MyClassC3fooyyFTq"}
6770
// CHECK-32: !1 = !{i64 64, !"$s4main7MyClassC3baryyFTq"}
6871
// CHECK-32: !2 = !{i64 72, !"$s4main7MyClassCACycfCTq"}
69-
// CHECK-32: !3 = !{i64 1}
70-
// CHECK-32: !4 = !{i64 48, !"$s4main7MyClassC3fooyyFTq"}
71-
// CHECK-32: !5 = !{i64 52, !"$s4main7MyClassC3baryyFTq"}
72-
// CHECK-32: !6 = !{i64 56, !"$s4main7MyClassCACycfCTq"}
73-
// CHECK-32: !7 = !{i64 68, !"$s4main7MyClassC3baryyFTq"}
74-
// CHECK-32: !8 = !{i64 80, !"$s4main7MyClassCACycfCTq"}
72+
// CHECK-32: !3 = !{i64 1, i64 56, i64 76}
73+
// CHECK-32: !4 = !{}
74+
// CHECK-32: !5 = !{i64 48, !"$s4main7MyClassC3fooyyFTq"}
75+
// CHECK-32: !6 = !{i64 52, !"$s4main7MyClassC3baryyFTq"}
76+
// CHECK-32: !7 = !{i64 56, !"$s4main7MyClassCACycfCTq"}
77+
// CHECK-32: !8 = !{i64 1, i64 48, i64 60}
78+
// CHECK-32: !9 = !{i64 68, !"$s4main7MyClassC3baryyFTq"}
79+
// CHECK-32: !10 = !{i64 80, !"$s4main7MyClassCACycfCTq"}
80+
// CHECK-32: !11 = !{i64 1, i64 56, i64 84}

0 commit comments

Comments
 (0)