Skip to content

[pull] swiftwasm from main #3788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions cmake/caches/Windows-arm64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
set(LLVM_ENABLE_PROJECTS
clang
clang-tools-extra
lld
lldb
CACHE STRING "")

set(LLVM_EXTERNAL_PROJECTS
cmark
swift
CACHE STRING "")

set(LLVM_ENABLE_RUNTIMES
compiler-rt
CACHE STRING "")

# NOTE(compnerd) always enable assertions, the toolchain will not provide enough
# context to resolve issues otherwise and may silently generate invalid output.
set(LLVM_ENABLE_ASSERTIONS YES CACHE BOOL "")

set(ENABLE_X86_RELAX_RELOCATIONS YES CACHE BOOL "")

# NOTE(compnerd) we can hardcode the default target triple since the cache files
# are target dependent.
set(LLVM_DEFAULT_TARGET_TRIPLE aarch64-unknown-windows-msvc CACHE STRING "")

set(LLVM_APPEND_VC_REV NO CACHE BOOL "")
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR YES CACHE BOOL "")
set(LLVM_ENABLE_PYTHON YES CACHE BOOL "")
set(LLVM_RUNTIME_TARGETS
aarch64-unknown-windows-msvc
CACHE STRING "")
foreach(target ${LLVM_RUNTIME_TARGETS})
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
compiler-rt
CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE YES CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY NO CACHE BOOL "")
endforeach()

set(LLVM_TARGETS_TO_BUILD AArch64 ARM WebAssembly X86 CACHE STRING "")

# Disable certain targets to reduce the configure time or to avoid configuration
# differences (and in some cases weird build errors on a complete build).
set(LLVM_BUILD_LLVM_DYLIB NO CACHE BOOL "")
set(LLVM_BUILD_LLVM_C_DYLIB NO CACHE BOOL "")
set(LLVM_ENABLE_LIBEDIT NO CACHE BOOL "")
set(LLVM_ENABLE_LIBXML2 NO CACHE BOOL "")
set(LLVM_ENABLE_OCAMLDOC NO CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO NO CACHE BOOL "")
set(LLVM_ENABLE_Z3_SOLVER NO CACHE BOOL "")
set(LLVM_ENABLE_ZLIB NO CACHE BOOL "")
set(LLVM_INCLUDE_BENCHMARKS NO CACHE BOOL "")
set(LLVM_INCLUDE_DOCS NO CACHE BOOL "")
set(LLVM_INCLUDE_EXAMPLES NO CACHE BOOL "")
set(LLVM_INCLUDE_GO_TESTS NO CACHE BOOL "")
set(LLVM_TOOL_GOLD_BUILD NO CACHE BOOL "")
set(LLVM_TOOL_LLVM_SHLIB_BUILD NO CACHE BOOL "")

# Avoid swig dependency for lldb
set(LLDB_ALLOW_STATIC_BINDINGS YES CACHE BOOL "")
set(LLDB_USE_STATIC_BINDINGS YES CACHE BOOL "")

# This requires perl which may not be available on Windows
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")
set(SWIFT_BUILD_ENABLE_PARSER_LIB YES CACHE BOOL "")
# static linking is not supported on Windows yet
set(SWIFT_BUILD_STATIC_STDLIB NO CACHE BOOL "")
set(SWIFT_BUILD_STATIC_SDK_OVERLAY NO CACHE BOOL "")

set(LLVM_INSTALL_BINUTILS_SYMLINKS YES CACHE BOOL "")
set(LLVM_INSTALL_TOOLCHAIN_ONLY YES CACHE BOOL "")
set(LLVM_TOOLCHAIN_TOOLS
addr2line
ar
c++filt
dsymutil
dwp
# lipo
llvm-ar
llvm-cov
llvm-cvtres
llvm-cxxfilt
llvm-dlltool
llvm-dwarfdump
llvm-dwp
llvm-lib
llvm-lipo
llvm-mt
llvm-nm
llvm-objcopy
llvm-objdump
llvm-pdbutil
llvm-profdata
llvm-ranlib
llvm-rc
llvm-readelf
llvm-readobj
llvm-size
llvm-strings
llvm-strip
llvm-symbolizer
llvm-undname
nm
objcopy
objdump
ranlib
readelf
size
strings
CACHE STRING "")

set(CLANG_TOOLS
clang
clangd
clang-format
clang-resource-headers
clang-tidy
CACHE STRING "")

set(LLD_TOOLS
lld
CACHE STRING "")

set(LLDB_TOOLS
liblldb
lldb
lldb-argdumper
lldb-python-scripts
lldb-server
lldb-vscode
repl_swift
CACHE STRING "")

set(SWIFT_INSTALL_COMPONENTS
autolink-driver
compiler
clang-builtin-headers
editor-integration
tools
sourcekit-inproc
swift-remote-mirror
swift-remote-mirror-headers
parser-lib
CACHE STRING "")

set(LLVM_DISTRIBUTION_COMPONENTS
IndexStore
libclang
libclang-headers
LTO
runtimes
${LLVM_TOOLCHAIN_TOOLS}
${CLANG_TOOLS}
${LLD_TOOLS}
${LLDB_TOOLS}
${SWIFT_INSTALL_COMPONENTS}
CACHE STRING "")
45 changes: 36 additions & 9 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,29 +334,56 @@ void IRGenModule::emitNonoverriddenMethodDescriptor(const SILVTable *VTable,
getAddrOfLLVMVariable(entity, init, DebugTypeInfo());
}

void IRGenModule::setVCallVisibility(llvm::GlobalVariable *var,
llvm::GlobalObject::VCallVisibility vis,
std::pair<uint64_t, uint64_t> range) {
// Insert attachment of !vcall_visibility !{ vis, range.first, range.second }
var->addMetadata(
llvm::LLVMContext::MD_vcall_visibility,
*llvm::MDNode::get(getLLVMContext(),
{
llvm::ConstantAsMetadata::get(
llvm::ConstantInt::get(Int64Ty, vis)),
llvm::ConstantAsMetadata::get(
llvm::ConstantInt::get(Int64Ty, range.first)),
llvm::ConstantAsMetadata::get(
llvm::ConstantInt::get(Int64Ty, range.second)),
}));
// Insert attachment of !typed_global_not_for_cfi !{}
var->addMetadata("typed_global_not_for_cfi",
*llvm::MDNode::get(getLLVMContext(), {}));
}

void IRGenModule::addVTableTypeMetadata(
ClassDecl *decl, llvm::GlobalVariable *var,
SmallVector<std::pair<Size, SILDeclRef>, 8> vtableEntries) {
if (vtableEntries.empty())
return;

uint64_t minOffset = UINT64_MAX;
uint64_t maxOffset = 0;
for (auto ventry : vtableEntries) {
auto method = ventry.second;
auto offset = ventry.first.getValue();
var->addTypeMetadata(offset, typeIdForMethod(*this, method));
minOffset = std::min(minOffset, offset);
maxOffset = std::max(maxOffset, offset);
}

using VCallVisibility = llvm::GlobalObject::VCallVisibility;
VCallVisibility vis = VCallVisibility::VCallVisibilityPublic;
auto AS = decl->getFormalAccessScope();
if (AS.isFileScope()) {
var->setVCallVisibilityMetadata(
llvm::GlobalObject::VCallVisibility::VCallVisibilityTranslationUnit);
vis = VCallVisibility::VCallVisibilityTranslationUnit;
} else if (AS.isPrivate() || AS.isInternal()) {
var->setVCallVisibilityMetadata(
llvm::GlobalObject::VCallVisibility::VCallVisibilityLinkageUnit);
vis = VCallVisibility::VCallVisibilityLinkageUnit;
} else if (getOptions().InternalizeAtLink) {
var->setVCallVisibilityMetadata(
llvm::GlobalObject::VCallVisibility::VCallVisibilityLinkageUnit);
} else {
var->setVCallVisibilityMetadata(
llvm::GlobalObject::VCallVisibility::VCallVisibilityPublic);
vis = VCallVisibility::VCallVisibilityLinkageUnit;
}

auto relptrSize = DataLayout.getTypeAllocSize(Int32Ty).getValue();
setVCallVisibility(var, vis,
std::make_pair(minOffset, maxOffset + relptrSize));
}

namespace {
Expand Down
27 changes: 18 additions & 9 deletions lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,9 @@ static void addWTableTypeMetadata(IRGenModule &IGM,
llvm::GlobalVariable *global,
SILWitnessTable *wt) {
auto conf = wt->getConformance();

uint64_t minOffset = UINT64_MAX;
uint64_t maxOffset = 0;
for (auto entry : wt->getEntries()) {
if (entry.getKind() != SILWitnessTable::WitnessKind::Method)
continue;
Expand All @@ -2178,30 +2181,36 @@ static void addWTableTypeMetadata(IRGenModule &IGM,
auto index = fnProtoInfo.getFunctionIndex(member).forProtocolWitnessTable();
auto offset = index.getValue() * IGM.getPointerSize().getValue();
global->addTypeMetadata(offset, typeIdForMethod(IGM, member));

minOffset = std::min(minOffset, offset);
maxOffset = std::max(maxOffset, offset);
}

if (minOffset == UINT64_MAX)
return;

using VCallVisibility = llvm::GlobalObject::VCallVisibility;
VCallVisibility vis = VCallVisibility::VCallVisibilityPublic;
auto linkage = stripExternalFromLinkage(wt->getLinkage());
switch (linkage) {
case SILLinkage::Private:
global->setVCallVisibilityMetadata(
llvm::GlobalObject::VCallVisibility::VCallVisibilityTranslationUnit);
vis = VCallVisibility::VCallVisibilityTranslationUnit;
break;
case SILLinkage::Hidden:
case SILLinkage::Shared:
global->setVCallVisibilityMetadata(
llvm::GlobalObject::VCallVisibility::VCallVisibilityLinkageUnit);
vis = VCallVisibility::VCallVisibilityLinkageUnit;
break;
case SILLinkage::Public:
default:
if (IGM.getOptions().InternalizeAtLink) {
global->setVCallVisibilityMetadata(
llvm::GlobalObject::VCallVisibility::VCallVisibilityLinkageUnit);
} else {
global->setVCallVisibilityMetadata(
llvm::GlobalObject::VCallVisibility::VCallVisibilityPublic);
vis = VCallVisibility::VCallVisibilityLinkageUnit;
}
break;
}

auto relptrSize = IGM.DataLayout.getTypeAllocSize(IGM.Int32Ty).getValue();
IGM.setVCallVisibility(global, vis,
std::make_pair(minOffset, maxOffset + relptrSize));
}

void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
Expand Down
5 changes: 5 additions & 0 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,11 @@ private: \
bool isDestroyer,
bool isForeign,
ForDefinition_t forDefinition);

void setVCallVisibility(llvm::GlobalVariable *var,
llvm::GlobalObject::VCallVisibility visibility,
std::pair<uint64_t, uint64_t> range);

void addVTableTypeMetadata(
ClassDecl *decl, llvm::GlobalVariable *var,
SmallVector<std::pair<Size, SILDeclRef>, 8> vtableEntries);
Expand Down
4 changes: 2 additions & 2 deletions test/IRGen/conditional-dead-strip-exec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

// REQUIRES: executable_test

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

// (1) used
@inline(never) func func1_used() { print("func1_used") }
Expand Down
4 changes: 2 additions & 2 deletions test/IRGen/virtual-function-elimination-exec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

// REQUIRES: executable_test

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

class MyClass {
func foo() { print("MyClass.foo") }
Expand Down
2 changes: 2 additions & 0 deletions test/IRGen/virtual-function-elimination-ir-thunks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// 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
// 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

// UNSUPPORTED: OS=windows-msvc

#if LIBRARY

public class MyLibraryClass {
Expand Down
42 changes: 24 additions & 18 deletions test/IRGen/virtual-function-elimination-ir.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ class MyDerivedClass: MyClass {

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

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

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

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


func func1() {
Expand All @@ -56,19 +56,25 @@ func func2() {
// CHECK-64: !0 = !{i64 56, !"$s4main7MyClassC3fooyyFTq"}
// CHECK-64: !1 = !{i64 64, !"$s4main7MyClassC3baryyFTq"}
// CHECK-64: !2 = !{i64 72, !"$s4main7MyClassCACycfCTq"}
// CHECK-64: !3 = !{i64 1}
// CHECK-64: !4 = !{i64 72, !"$s4main7MyClassC3fooyyFTq"}
// CHECK-64: !5 = !{i64 80, !"$s4main7MyClassC3baryyFTq"}
// CHECK-64: !6 = !{i64 88, !"$s4main7MyClassCACycfCTq"}
// CHECK-64: !7 = !{i64 68, !"$s4main7MyClassC3baryyFTq"}
// CHECK-64: !8 = !{i64 80, !"$s4main7MyClassCACycfCTq"}
// CHECK-64: !3 = !{i64 1, i64 56, i64 76}
// CHECK-64: !4 = !{}
// CHECK-64: !5 = !{i64 72, !"$s4main7MyClassC3fooyyFTq"}
// CHECK-64: !6 = !{i64 80, !"$s4main7MyClassC3baryyFTq"}
// CHECK-64: !7 = !{i64 88, !"$s4main7MyClassCACycfCTq"}
// CHECK-64: !8 = !{i64 1, i64 72, i64 92}
// CHECK-64: !9 = !{i64 68, !"$s4main7MyClassC3baryyFTq"}
// CHECK-64: !10 = !{i64 80, !"$s4main7MyClassCACycfCTq"}
// CHECK-64: !11 = !{i64 1, i64 56, i64 84}

// CHECK-32: !0 = !{i64 56, !"$s4main7MyClassC3fooyyFTq"}
// CHECK-32: !1 = !{i64 64, !"$s4main7MyClassC3baryyFTq"}
// CHECK-32: !2 = !{i64 72, !"$s4main7MyClassCACycfCTq"}
// CHECK-32: !3 = !{i64 1}
// CHECK-32: !4 = !{i64 48, !"$s4main7MyClassC3fooyyFTq"}
// CHECK-32: !5 = !{i64 52, !"$s4main7MyClassC3baryyFTq"}
// CHECK-32: !6 = !{i64 56, !"$s4main7MyClassCACycfCTq"}
// CHECK-32: !7 = !{i64 68, !"$s4main7MyClassC3baryyFTq"}
// CHECK-32: !8 = !{i64 80, !"$s4main7MyClassCACycfCTq"}
// CHECK-32: !3 = !{i64 1, i64 56, i64 76}
// CHECK-32: !4 = !{}
// CHECK-32: !5 = !{i64 48, !"$s4main7MyClassC3fooyyFTq"}
// CHECK-32: !6 = !{i64 52, !"$s4main7MyClassC3baryyFTq"}
// CHECK-32: !7 = !{i64 56, !"$s4main7MyClassCACycfCTq"}
// CHECK-32: !8 = !{i64 1, i64 48, i64 60}
// CHECK-32: !9 = !{i64 68, !"$s4main7MyClassC3baryyFTq"}
// CHECK-32: !10 = !{i64 80, !"$s4main7MyClassCACycfCTq"}
// CHECK-32: !11 = !{i64 1, i64 56, i64 84}
Loading