Skip to content

Commit 588a179

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 0f56ea5 + 6467d0e commit 588a179

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

include/swift/AST/ClangModuleLoader.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace swift {
3333

3434
class Decl;
3535
class DeclContext;
36+
class EffectiveClangContext;
37+
class SwiftLookupTable;
3638
class VisibleDeclConsumer;
3739

3840
/// Represents the different namespaces for types in C.
@@ -177,6 +179,9 @@ class ClangModuleLoader : public ModuleLoader {
177179
StringRef relatedEntityKind,
178180
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
179181

182+
/// Imports a clang decl directly, rather than looking up its name.
183+
virtual Decl *importDeclDirectly(const clang::NamedDecl *decl) = 0;
184+
180185
/// Instantiate and import class template using given arguments.
181186
///
182187
/// This method will find the clang::ClassTemplateSpecialization decl if
@@ -241,6 +246,21 @@ class ClangModuleLoader : public ModuleLoader {
241246

242247
virtual Type importFunctionReturnType(const clang::FunctionDecl *clangDecl,
243248
DeclContext *dc) = 0;
249+
250+
/// Find the lookup table that corresponds to the given Clang module.
251+
///
252+
/// \param clangModule The module, or null to indicate that we're talking
253+
/// about the directly-parsed headers.
254+
virtual SwiftLookupTable *
255+
findLookupTable(const clang::Module *clangModule) = 0;
256+
257+
virtual DeclName
258+
importName(const clang::NamedDecl *D,
259+
clang::DeclarationName givenName = clang::DeclarationName()) = 0;
260+
261+
/// Determine the effective Clang context for the given Swift nominal type.
262+
EffectiveClangContext virtual getEffectiveClangContext(
263+
const NominalTypeDecl *nominal) = 0;
244264
};
245265

246266
/// Describes a C++ template instantiation error.

include/swift/ClangImporter/ClangImporter.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ class ClangModuleUnit;
6262
class ClangNode;
6363
class Decl;
6464
class DeclContext;
65+
class EffectiveClangContext;
6566
class EnumDecl;
6667
class ImportDecl;
6768
class IRGenOptions;
6869
class ModuleDecl;
6970
class NominalTypeDecl;
7071
class StructDecl;
72+
class SwiftLookupTable;
7173
class TypeDecl;
7274
class VisibleDeclConsumer;
7375
enum class SelectorSplitKind;
@@ -457,11 +459,12 @@ class ClangImporter final : public ClangModuleLoader {
457459
/// Given a Clang module, decide whether this module is imported already.
458460
static bool isModuleImported(const clang::Module *M);
459461

460-
DeclName importName(const clang::NamedDecl *D,
461-
clang::DeclarationName givenName);
462+
DeclName importName(
463+
const clang::NamedDecl *D,
464+
clang::DeclarationName givenName = clang::DeclarationName()) override;
462465

463466
Type importFunctionReturnType(const clang::FunctionDecl *clangDecl,
464-
DeclContext *dc) override;
467+
DeclContext *dc) override;
465468

466469
Optional<std::string>
467470
getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
@@ -493,6 +496,19 @@ class ClangImporter final : public ClangModuleLoader {
493496
SubstitutionMap subst) override;
494497

495498
bool isCXXMethodMutating(const clang::CXXMethodDecl *method) override;
499+
500+
/// Find the lookup table that corresponds to the given Clang module.
501+
///
502+
/// \param clangModule The module, or null to indicate that we're talking
503+
/// about the directly-parsed headers.
504+
SwiftLookupTable *findLookupTable(const clang::Module *clangModule) override;
505+
506+
/// Determine the effective Clang context for the given Swift nominal type.
507+
EffectiveClangContext
508+
getEffectiveClangContext(const NominalTypeDecl *nominal) override;
509+
510+
/// Imports a clang decl directly, rather than looking up it's name.
511+
Decl *importDeclDirectly(const clang::NamedDecl *decl) override;
496512
};
497513

498514
ImportDecl *createImportDecl(ASTContext &Ctx, DeclContext *DC, ClangNode ClangN,

lib/ClangImporter/ClangImporter.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,12 @@ importer::addCommonInvocationArguments(
781781
invocationArgStrs.push_back("-march=z13");
782782
}
783783

784+
if (triple.getArch() == llvm::Triple::x86_64) {
785+
// Enable double wide atomic intrinsics on every x86_64 target.
786+
// (This is the default on Darwin, but not so on other platforms.)
787+
invocationArgStrs.push_back("-mcx16");
788+
}
789+
784790
if (!importerOpts.Optimization.empty()) {
785791
invocationArgStrs.push_back(importerOpts.Optimization);
786792
}
@@ -4340,3 +4346,18 @@ bool ClangImporter::isCXXMethodMutating(const clang::CXXMethodDecl *method) {
43404346
return isa<clang::CXXConstructorDecl>(method) || !method->isConst() ||
43414347
method->getParent()->hasMutableFields();
43424348
}
4349+
4350+
SwiftLookupTable *
4351+
ClangImporter::findLookupTable(const clang::Module *clangModule) {
4352+
return Impl.findLookupTable(clangModule);
4353+
}
4354+
4355+
/// Determine the effective Clang context for the given Swift nominal type.
4356+
EffectiveClangContext
4357+
ClangImporter::getEffectiveClangContext(const NominalTypeDecl *nominal) {
4358+
return Impl.getEffectiveClangContext(nominal);
4359+
}
4360+
4361+
Decl *ClangImporter::importDeclDirectly(const clang::NamedDecl *decl) {
4362+
return Impl.importDecl(decl, Impl.CurrentVersion);
4363+
}

test/IRGen/cx16.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -target x86_64-unknown-linux-gnu -disable-legacy-type-info -parse-stdlib -disable-objc-interop %s -module-name main -emit-ir -o - | %FileCheck %s
2+
// RUN: %target-swift-frontend -target x86_64-unknown-windows-msvc -disable-legacy-type-info -parse-stdlib -disable-objc-interop %s -module-name main -emit-ir -o - | %FileCheck %s
3+
// RUN: %target-swift-frontend -target x86_64-unknown-freebsd -disable-legacy-type-info -parse-stdlib -disable-objc-interop %s -module-name main -emit-ir -o - | %FileCheck %s
4+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -disable-legacy-type-info -parse-stdlib -module-name main %s -emit-ir -o - | %FileCheck %s
5+
6+
// REQUIRES: CODEGENERATOR=X86
7+
8+
public func test() {
9+
}
10+
11+
// We expect double-wide atomic intrinsics to always be available on x86_64.
12+
// CHECK: "target-features"="{{.*}}+cx16,

0 commit comments

Comments
 (0)