[PATCH] D137512: [clang] Add Swift support for MIPS

2022-11-08 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer added a comment.

This looks good to me. Can you rebase your patch so that it applies on top of 
github.com:apple/llvm-project.git main?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137512/new/

https://reviews.llvm.org/D137512

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109451: Summary: Introduce a new frontend flag `-fswift-async-fp={auto|always|never}` that controls how code generation sets the Swift extended async frame info bit. There are three possibili

2021-09-16 Thread Arnold Schwaighofer via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf670c5aeeef0: Add a new frontend flag 
`-fswift-async-fp={auto|always|never}` (authored by aschwaighofer).

Changed prior to commit:
  https://reviews.llvm.org/D109451?vs=371383=372966#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109451/new/

https://reviews.llvm.org/D109451

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/swift-async-extended-fp.c

Index: clang/test/CodeGen/swift-async-extended-fp.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-extended-fp.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+// RUN: %clang_cc1 -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=NEVER-X86
+// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=NEVER-X86
+// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=AUTO-X86
+// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+
+// RUN: %clang_cc1 -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
+// RUN: %clang_cc1 -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
+// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=AUTO-ARM64
+// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
+// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=NEVER-ARM64
+// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=NEVER-ARM64
+// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
+// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
+
+// REQUIRES: aarch64-registered-target,x86-registered-target
+
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+SWIFTASYNCCALL void async_context_1(ASYNC_CONTEXT void *ctx) {}
+
+// AUTO-X86: _async_context_1:
+// AUTO-X86:	_swift_async_extendedFramePointerFlags
+
+// ALWAYS-X86: _async_context_1:
+// ALWAYS-X86: btsq	$60
+
+// NEVER-X86: _async_context_1:
+// NEVER-X86-NOT:	_swift_async_extendedFramePointerFlags
+// NEVER-X86-NOT: btsq	$60
+
+// AUTO-ARM64: _async_context_1
+// AUTO-ARM64: _swift_async_extendedFramePointerFlags
+
+// ALWAYS-ARM64: _async_context_1
+// ALWAYS-ARM64: orr x29, x29, #0x1000
+
+// NEVER-ARM64: _async_context_1:
+// NEVER-ARM64-NOT:	_swift_async_extendedFramePointerFlags
+// NEVER-ARM64-NOT: orr x29, x29, #0x1000
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5912,6 +5912,8 @@
   RenderSCPOptions(TC, Args, CmdArgs);
   RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
 
+  Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
+
   // Translate -mstackrealign
   if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
false))
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ 

[PATCH] D109451: Summary: Introduce a new frontend flag `-fswift-async-fp={auto|always|never}` that controls how code generation sets the Swift extended async frame info bit. There are three possibili

2021-09-08 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer created this revision.
aschwaighofer added reviewers: doug.gregor, t.p.northover.
Herald added subscribers: ormris, dexonsmith, dang.
aschwaighofer requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- `auto`: the default, which determines how to set the bit based on

deployment target, either statically or dynamically via
`swift_async_extendedFramePointerFlags`.

- `always`: always set the bit statically, regardless of deployment

target.

- `never`: never set the bit, regardless of deployment target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109451

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/swift-async-extended-fp.c

Index: clang/test/CodeGen/swift-async-extended-fp.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-extended-fp.c
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=AUTO-X86
+// RUN: %clang_cc1 -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=NEVER-X86
+// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=NEVER-X86
+// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=AUTO-X86
+// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
+
+// RUN: %clang_cc1 -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=AUTO-ARM64
+// RUN: %clang_cc1 -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
+// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=NEVER-ARM64
+// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=NEVER-ARM64
+
+// REQUIRES: aarch64-registered-target,x86-registered-target
+
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+SWIFTASYNCCALL void async_context_1(ASYNC_CONTEXT void *ctx) {}
+
+// AUTO-X86: _async_context_1:
+// AUTO-X86:	_swift_async_extendedFramePointerFlags
+
+// ALWAYS-X86: _async_context_1:
+// ALWAYS-X86: btsq	$60
+
+// NEVER-X86: _async_context_1:
+// NEVER-X86-NOT:	_swift_async_extendedFramePointerFlags
+// NEVER-X86-NOT: btsq	$60
+
+// AUTO-ARM64: _async_context_1
+// AUTO-ARM64: _swift_async_extendedFramePointerFlags
+
+// ALWAYS-ARM64: _async_context_1
+// ALWAYS-ARM64: orr x29, x29, #0x1000
+
+// NEVER-ARM64: _async_context_1:
+// NEVER-ARM64-NOT:	_swift_async_extendedFramePointerFlags
+// NEVER-ARM64-NOT: orr x29, x29, #0x1000
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5909,6 +5909,8 @@
   RenderSCPOptions(TC, Args, CmdArgs);
   RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
 
+  Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
+
   // Translate -mstackrealign
   if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
false))
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -582,6 +582,21 @@
   Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex;
   Options.LoopAlignment = CodeGenOpts.LoopAlignment;
 
+  switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
+  case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
+Options.SwiftAsyncFramePointer =
+SwiftAsyncFramePointerMode::DeploymentBased;
+break;
+
+  case CodeGenOptions::SwiftAsyncFramePointerKind::Always:
+Options.SwiftAsyncFramePointer = 

[PATCH] D107841: CodeGen: No need to check for isExternC if HasStrictReturn is already false

2021-08-11 Thread Arnold Schwaighofer via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9eb99d2e73b5: CodeGen: No need to check for isExternC if 
HasStrictReturn is already false (authored by aschwaighofer).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107841/new/

https://reviews.llvm.org/D107841

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2241,7 +2241,7 @@
   // C++ explicitly makes returning undefined values UB. C's rule only applies
   // to used values, so we never mark them noundef for now.
   bool HasStrictReturn = getLangOpts().CPlusPlus;
-  if (TargetDecl) {
+  if (TargetDecl && HasStrictReturn) {
 if (const FunctionDecl *FDecl = dyn_cast(TargetDecl))
   HasStrictReturn &= !FDecl->isExternC();
 else if (const VarDecl *VDecl = dyn_cast(TargetDecl))


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2241,7 +2241,7 @@
   // C++ explicitly makes returning undefined values UB. C's rule only applies
   // to used values, so we never mark them noundef for now.
   bool HasStrictReturn = getLangOpts().CPlusPlus;
-  if (TargetDecl) {
+  if (TargetDecl && HasStrictReturn) {
 if (const FunctionDecl *FDecl = dyn_cast(TargetDecl))
   HasStrictReturn &= !FDecl->isExternC();
 else if (const VarDecl *VDecl = dyn_cast(TargetDecl))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107841: CodeGen: No need to check for isExternC if HasStrictReturn is already false

2021-08-10 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer created this revision.
aschwaighofer added a reviewer: rjmccall.
aschwaighofer requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

NFC intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107841

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2241,7 +2241,7 @@
   // C++ explicitly makes returning undefined values UB. C's rule only applies
   // to used values, so we never mark them noundef for now.
   bool HasStrictReturn = getLangOpts().CPlusPlus;
-  if (TargetDecl) {
+  if (TargetDecl && HasStrictReturn) {
 if (const FunctionDecl *FDecl = dyn_cast(TargetDecl))
   HasStrictReturn &= !FDecl->isExternC();
 else if (const VarDecl *VDecl = dyn_cast(TargetDecl))


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2241,7 +2241,7 @@
   // C++ explicitly makes returning undefined values UB. C's rule only applies
   // to used values, so we never mark them noundef for now.
   bool HasStrictReturn = getLangOpts().CPlusPlus;
-  if (TargetDecl) {
+  if (TargetDecl && HasStrictReturn) {
 if (const FunctionDecl *FDecl = dyn_cast(TargetDecl))
   HasStrictReturn &= !FDecl->isExternC();
 else if (const VarDecl *VDecl = dyn_cast(TargetDecl))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96802: [Clang] Add proper target checks for SwiftAsync convention.

2021-02-16 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer accepted this revision.
aschwaighofer added a comment.
This revision is now accepted and ready to land.

Looks good to me


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96802/new/

https://reviews.llvm.org/D96802

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95814: [NFC] Simplify test to use multiple FileCheck prefixes.

2021-02-15 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer accepted this revision.
aschwaighofer added a comment.
This revision is now accepted and ready to land.

LGTM

Thank you!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95814/new/

https://reviews.llvm.org/D95814

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86218: Teach the swift calling convention about _Atomic types

2020-08-31 Thread Arnold Schwaighofer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41634497d4fd: Teach the swift calling convention about 
_Atomic types (authored by aschwaighofer).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86218/new/

https://reviews.llvm.org/D86218

Files:
  clang/lib/CodeGen/SwiftCallingConv.cpp
  clang/test/CodeGen/64bit-swiftcall.c


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -10,6 +10,9 @@
 #define ERROR __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
 
+// CHECK-DAG: %struct.atomic_padded = type { { %struct.packed, [7 x i8] } }
+// CHECK-DAG: %struct.packed = type <{ i64, i8 }>
+//
 // CHECK: [[STRUCT2_RESULT:@.*]] = private {{.*}} constant 
[[STRUCT2_TYPE:%.*]] { i32 0, i8 0, i8 undef, i8 0, i32 0, i32 0 }
 
 /*/
@@ -1042,3 +1045,27 @@
   // CHECK-NOT: call void @llvm.lifetime.
   take_int5(return_int5());
 }
+
+typedef struct {
+  unsigned long long a;
+  unsigned long long b;
+} double_word;
+
+typedef struct {
+  _Atomic(double_word) a;
+} atomic_double_word;
+
+// CHECK-LABEL: use_atomic(i64 %0, i64 %1)
+SWIFTCALL void use_atomic(atomic_double_word a) {}
+
+typedef struct {
+  unsigned long long a;
+  unsigned char b;
+} __attribute__((packed)) packed;
+
+typedef struct {
+  _Atomic(packed) a;
+} atomic_padded;
+
+// CHECK-LABEL: use_atomic_padded(i64 %0, i64 %1)
+SWIFTCALL void use_atomic_padded(atomic_padded a) {}
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -93,11 +93,24 @@
 // Just add it all as opaque.
 addOpaqueData(begin, begin + CGM.getContext().getTypeSizeInChars(type));
 
-  // Everything else is scalar and should not convert as an LLVM aggregate.
+// Atomic types.
+  } else if (const auto *atomicType = type->getAs()) {
+auto valueType = atomicType->getValueType();
+auto atomicSize = CGM.getContext().getTypeSizeInChars(atomicType);
+auto valueSize = CGM.getContext().getTypeSizeInChars(valueType);
+
+addTypedData(atomicType->getValueType(), begin);
+
+// Add atomic padding.
+auto atomicPadding = atomicSize - valueSize;
+if (atomicPadding > CharUnits::Zero())
+  addOpaqueData(begin + valueSize, begin + atomicSize);
+
+// Everything else is scalar and should not convert as an LLVM aggregate.
   } else {
 // We intentionally convert as !ForMem because we want to preserve
 // that a type was an i1.
-auto llvmType = CGM.getTypes().ConvertType(type);
+auto *llvmType = CGM.getTypes().ConvertType(type);
 addTypedData(llvmType, begin);
   }
 }


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -10,6 +10,9 @@
 #define ERROR __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
 
+// CHECK-DAG: %struct.atomic_padded = type { { %struct.packed, [7 x i8] } }
+// CHECK-DAG: %struct.packed = type <{ i64, i8 }>
+//
 // CHECK: [[STRUCT2_RESULT:@.*]] = private {{.*}} constant [[STRUCT2_TYPE:%.*]] { i32 0, i8 0, i8 undef, i8 0, i32 0, i32 0 }
 
 /*/
@@ -1042,3 +1045,27 @@
   // CHECK-NOT: call void @llvm.lifetime.
   take_int5(return_int5());
 }
+
+typedef struct {
+  unsigned long long a;
+  unsigned long long b;
+} double_word;
+
+typedef struct {
+  _Atomic(double_word) a;
+} atomic_double_word;
+
+// CHECK-LABEL: use_atomic(i64 %0, i64 %1)
+SWIFTCALL void use_atomic(atomic_double_word a) {}
+
+typedef struct {
+  unsigned long long a;
+  unsigned char b;
+} __attribute__((packed)) packed;
+
+typedef struct {
+  _Atomic(packed) a;
+} atomic_padded;
+
+// CHECK-LABEL: use_atomic_padded(i64 %0, i64 %1)
+SWIFTCALL void use_atomic_padded(atomic_padded a) {}
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -93,11 +93,24 @@
 // Just add it all as opaque.
 addOpaqueData(begin, begin + CGM.getContext().getTypeSizeInChars(type));
 
-  // Everything else is scalar and should not convert as an LLVM aggregate.
+// Atomic types.
+  } else if (const auto *atomicType = type->getAs()) {
+auto valueType = atomicType->getValueType();
+auto atomicSize = CGM.getContext().getTypeSizeInChars(atomicType);
+auto valueSize = CGM.getContext().getTypeSizeInChars(valueType);
+
+addTypedData(atomicType->getValueType(), begin);
+
+// Add 

[PATCH] D86218: Teach the swift calling convention about _Atomic types

2020-08-21 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer updated this revision to Diff 287055.
aschwaighofer added a comment.

Respect atomic padding.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86218/new/

https://reviews.llvm.org/D86218

Files:
  clang/lib/CodeGen/SwiftCallingConv.cpp
  clang/test/CodeGen/64bit-swiftcall.c


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -10,6 +10,9 @@
 #define ERROR __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
 
+// CHECK-DAG: %struct.atomic_padded = type { { %struct.packed, [7 x i8] } }
+// CHECK-DAG: %struct.packed = type <{ i64, i8 }>
+//
 // CHECK: [[STRUCT2_RESULT:@.*]] = private {{.*}} constant 
[[STRUCT2_TYPE:%.*]] { i32 0, i8 0, i8 undef, i8 0, i32 0, i32 0 }
 
 /*/
@@ -1042,3 +1045,27 @@
   // CHECK-NOT: call void @llvm.lifetime.
   take_int5(return_int5());
 }
+
+typedef struct {
+  unsigned long long a;
+  unsigned long long b;
+} double_word;
+
+typedef struct {
+  _Atomic(double_word) a;
+} atomic_double_word;
+
+// CHECK-LABEL: use_atomic(i64 %0, i64 %1)
+SWIFTCALL void use_atomic(atomic_double_word a) {}
+
+typedef struct {
+  unsigned long long a;
+  unsigned char b;
+} __attribute__((packed)) packed;
+
+typedef struct {
+  _Atomic(packed) a;
+} atomic_padded;
+
+// CHECK-LABEL: use_atomic_padded(i64 %0, i64 %1)
+SWIFTCALL void use_atomic_padded(atomic_padded a) {}
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -93,11 +93,24 @@
 // Just add it all as opaque.
 addOpaqueData(begin, begin + CGM.getContext().getTypeSizeInChars(type));
 
-  // Everything else is scalar and should not convert as an LLVM aggregate.
+// Atomic types.
+  } else if (const auto *atomicType = type->getAs()) {
+auto valueType = atomicType->getValueType();
+auto atomicSize = CGM.getContext().getTypeSizeInChars(atomicType);
+auto valueSize = CGM.getContext().getTypeSizeInChars(valueType);
+
+addTypedData(atomicType->getValueType(), begin);
+
+// Add atomic padding.
+auto atomicPadding = atomicSize - valueSize;
+if (atomicPadding > CharUnits::Zero())
+  addOpaqueData(begin + valueSize, begin + atomicSize);
+
+// Everything else is scalar and should not convert as an LLVM aggregate.
   } else {
 // We intentionally convert as !ForMem because we want to preserve
 // that a type was an i1.
-auto llvmType = CGM.getTypes().ConvertType(type);
+auto *llvmType = CGM.getTypes().ConvertType(type);
 addTypedData(llvmType, begin);
   }
 }


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -10,6 +10,9 @@
 #define ERROR __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
 
+// CHECK-DAG: %struct.atomic_padded = type { { %struct.packed, [7 x i8] } }
+// CHECK-DAG: %struct.packed = type <{ i64, i8 }>
+//
 // CHECK: [[STRUCT2_RESULT:@.*]] = private {{.*}} constant [[STRUCT2_TYPE:%.*]] { i32 0, i8 0, i8 undef, i8 0, i32 0, i32 0 }
 
 /*/
@@ -1042,3 +1045,27 @@
   // CHECK-NOT: call void @llvm.lifetime.
   take_int5(return_int5());
 }
+
+typedef struct {
+  unsigned long long a;
+  unsigned long long b;
+} double_word;
+
+typedef struct {
+  _Atomic(double_word) a;
+} atomic_double_word;
+
+// CHECK-LABEL: use_atomic(i64 %0, i64 %1)
+SWIFTCALL void use_atomic(atomic_double_word a) {}
+
+typedef struct {
+  unsigned long long a;
+  unsigned char b;
+} __attribute__((packed)) packed;
+
+typedef struct {
+  _Atomic(packed) a;
+} atomic_padded;
+
+// CHECK-LABEL: use_atomic_padded(i64 %0, i64 %1)
+SWIFTCALL void use_atomic_padded(atomic_padded a) {}
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -93,11 +93,24 @@
 // Just add it all as opaque.
 addOpaqueData(begin, begin + CGM.getContext().getTypeSizeInChars(type));
 
-  // Everything else is scalar and should not convert as an LLVM aggregate.
+// Atomic types.
+  } else if (const auto *atomicType = type->getAs()) {
+auto valueType = atomicType->getValueType();
+auto atomicSize = CGM.getContext().getTypeSizeInChars(atomicType);
+auto valueSize = CGM.getContext().getTypeSizeInChars(valueType);
+
+addTypedData(atomicType->getValueType(), begin);
+
+// Add atomic padding.
+auto atomicPadding = atomicSize - valueSize;
+if 

[PATCH] D86218: Teach the swift calling convention about _Atomic types

2020-08-19 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer updated this revision to Diff 286575.
aschwaighofer added a comment.

Try to sooth clang-tidy


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86218/new/

https://reviews.llvm.org/D86218

Files:
  clang/lib/CodeGen/SwiftCallingConv.cpp
  clang/test/CodeGen/64bit-swiftcall.c


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -1042,3 +1042,15 @@
   // CHECK-NOT: call void @llvm.lifetime.
   take_int5(return_int5());
 }
+
+typedef struct {
+  unsigned long long a;
+  unsigned long long b;
+} double_word;
+
+typedef struct {
+  _Atomic(double_word) a;
+} atomic_double_word;
+
+// CHECK-LABEL: use_atomic(i64 %0, i64 %1)
+SWIFTCALL void use_atomic(atomic_double_word a) {}
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -62,9 +62,12 @@
 
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
+  // Atomic types.
+  if (const auto *atomicType = type->getAs()) {
+addTypedData(atomicType->getValueType(), begin);
 
-  // Record types.
-  if (auto recType = type->getAs()) {
+// Record types.
+  } else if (const auto *recType = type->getAs()) {
 addTypedData(recType->getDecl(), begin);
 
   // Array types.


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -1042,3 +1042,15 @@
   // CHECK-NOT: call void @llvm.lifetime.
   take_int5(return_int5());
 }
+
+typedef struct {
+  unsigned long long a;
+  unsigned long long b;
+} double_word;
+
+typedef struct {
+  _Atomic(double_word) a;
+} atomic_double_word;
+
+// CHECK-LABEL: use_atomic(i64 %0, i64 %1)
+SWIFTCALL void use_atomic(atomic_double_word a) {}
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -62,9 +62,12 @@
 
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
+  // Atomic types.
+  if (const auto *atomicType = type->getAs()) {
+addTypedData(atomicType->getValueType(), begin);
 
-  // Record types.
-  if (auto recType = type->getAs()) {
+// Record types.
+  } else if (const auto *recType = type->getAs()) {
 addTypedData(recType->getDecl(), begin);
 
   // Array types.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86218: Teach the swift calling convention about _Atomic types

2020-08-19 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer created this revision.
aschwaighofer added a reviewer: rjmccall.
Herald added subscribers: cfe-commits, jfb.
Herald added a project: clang.
aschwaighofer requested review of this revision.

rdar://67351073


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86218

Files:
  clang/lib/CodeGen/SwiftCallingConv.cpp
  clang/test/CodeGen/64bit-swiftcall.c


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -1042,3 +1042,15 @@
   // CHECK-NOT: call void @llvm.lifetime.
   take_int5(return_int5());
 }
+
+typedef struct {
+  unsigned long long a;
+  unsigned long long b;
+} double_word;
+
+typedef struct {
+  _Atomic(double_word) a;
+} atomic_double_word;
+
+// CHECK-LABEL: use_atomic(i64 %0, i64 %1)
+SWIFTCALL void use_atomic(atomic_double_word a) {}
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -62,9 +62,12 @@
 
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
+  // Atomic types.
+  if (auto atomicType = type->getAs()) {
+addTypedData(atomicType->getValueType(), begin);
 
-  // Record types.
-  if (auto recType = type->getAs()) {
+// Record types.
+  } else if (auto recType = type->getAs()) {
 addTypedData(recType->getDecl(), begin);
 
   // Array types.


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -1042,3 +1042,15 @@
   // CHECK-NOT: call void @llvm.lifetime.
   take_int5(return_int5());
 }
+
+typedef struct {
+  unsigned long long a;
+  unsigned long long b;
+} double_word;
+
+typedef struct {
+  _Atomic(double_word) a;
+} atomic_double_word;
+
+// CHECK-LABEL: use_atomic(i64 %0, i64 %1)
+SWIFTCALL void use_atomic(atomic_double_word a) {}
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -62,9 +62,12 @@
 
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
+  // Atomic types.
+  if (auto atomicType = type->getAs()) {
+addTypedData(atomicType->getValueType(), begin);
 
-  // Record types.
-  if (auto recType = type->getAs()) {
+// Record types.
+  } else if (auto recType = type->getAs()) {
 addTypedData(recType->getDecl(), begin);
 
   // Array types.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81857: Fix ConstantAggregateBuilderBase::getRelativeOffset

2020-06-15 Thread Arnold Schwaighofer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4a8120ca9fb9: Fix 
ConstantAggregateBuilderBase::getRelativeOffset (authored by aschwaighofer).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81857/new/

https://reviews.llvm.org/D81857

Files:
  clang/lib/CodeGen/ConstantInitBuilder.cpp


Index: clang/lib/CodeGen/ConstantInitBuilder.cpp
===
--- clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -129,7 +129,7 @@
 ConstantAggregateBuilderBase::getRelativeOffset(llvm::IntegerType *offsetType,
 llvm::Constant *target) {
   return getRelativeOffsetToPosition(offsetType, target,
- Builder.SelfReferences.size());
+ Builder.Buffer.size() - Begin);
 }
 
 llvm::Constant *ConstantAggregateBuilderBase::getRelativeOffsetToPosition(


Index: clang/lib/CodeGen/ConstantInitBuilder.cpp
===
--- clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -129,7 +129,7 @@
 ConstantAggregateBuilderBase::getRelativeOffset(llvm::IntegerType *offsetType,
 llvm::Constant *target) {
   return getRelativeOffsetToPosition(offsetType, target,
- Builder.SelfReferences.size());
+ Builder.Buffer.size() - Begin);
 }
 
 llvm::Constant *ConstantAggregateBuilderBase::getRelativeOffsetToPosition(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81857: Fix ConstantAggregateBuilderBase::getRelativeOffset

2020-06-15 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
aschwaighofer added a reviewer: rjmccall.

If a record has a mix of relative pointers and other fields they
wouldn't necessarily be the same.

Fallout from D77592 .

rdar://64309883


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81857

Files:
  clang/lib/CodeGen/ConstantInitBuilder.cpp


Index: clang/lib/CodeGen/ConstantInitBuilder.cpp
===
--- clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -129,7 +129,7 @@
 ConstantAggregateBuilderBase::getRelativeOffset(llvm::IntegerType *offsetType,
 llvm::Constant *target) {
   return getRelativeOffsetToPosition(offsetType, target,
- Builder.SelfReferences.size());
+ Builder.Buffer.size() - Begin);
 }
 
 llvm::Constant *ConstantAggregateBuilderBase::getRelativeOffsetToPosition(


Index: clang/lib/CodeGen/ConstantInitBuilder.cpp
===
--- clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -129,7 +129,7 @@
 ConstantAggregateBuilderBase::getRelativeOffset(llvm::IntegerType *offsetType,
 llvm::Constant *target) {
   return getRelativeOffsetToPosition(offsetType, target,
- Builder.SelfReferences.size());
+ Builder.Buffer.size() - Begin);
 }
 
 llvm::Constant *ConstantAggregateBuilderBase::getRelativeOffsetToPosition(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-04-01 Thread Arnold Schwaighofer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG153dadf3a3ca: [clang] CodeGen: Make getOrEmitProtocol public 
for Swift (authored by aschwaighofer).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/CGObjCRuntime.h

Index: clang/lib/CodeGen/CGObjCRuntime.h
===
--- clang/lib/CodeGen/CGObjCRuntime.h
+++ clang/lib/CodeGen/CGObjCRuntime.h
@@ -211,6 +211,11 @@
   /// implementations.
   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
 
+  /// GetOrEmitProtocol - Get the protocol object for the given
+  /// declaration, emitting it if necessary. The return value has type
+  /// ProtocolPtrTy.
+  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) = 0;
+
   /// Generate a function preamble for a method with the specified
   /// types.
 
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -13,14 +13,15 @@
 //===--===//
 
 #include "CGObjCRuntime.h"
-#include "CGCleanup.h"
 #include "CGCXXABI.h"
+#include "CGCleanup.h"
 #include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/Support/SaveAndRestore.h"
 
 using namespace clang;
@@ -383,3 +384,9 @@
 CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
   return MessageSendInfo(argsInfo, signatureType);
 }
+
+llvm::Constant *
+clang::CodeGen::emitObjCProtocolObject(CodeGenModule ,
+   const ObjCProtocolDecl *protocol) {
+  return CGM.getObjCRuntime().GetOrEmitProtocol(protocol);
+}
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1107,11 +1107,6 @@
 
   void GenerateProtocol(const ObjCProtocolDecl *PD) override;
 
-  /// GetOrEmitProtocol - Get the protocol object for the given
-  /// declaration, emitting it if necessary. The return value has type
-  /// ProtocolPtrTy.
-  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD)=0;
-
   /// GetOrEmitProtocolRef - Get a forward reference to the protocol
   /// object for the given declaration, emitting it if needed. These
   /// forward references will be filled in with empty bodies if no
Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -617,6 +617,13 @@
   llvm::Value *GenerateProtocolRef(CodeGenFunction ,
const ObjCProtocolDecl *PD) override;
   void GenerateProtocol(const ObjCProtocolDecl *PD) override;
+
+  virtual llvm::Constant *GenerateProtocolRef(const ObjCProtocolDecl *PD);
+
+  llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) override {
+return GenerateProtocolRef(PD);
+  }
+
   llvm::Function *ModuleInitFunction() override;
   llvm::FunctionCallee GetPropertyGetFunction() override;
   llvm::FunctionCallee GetPropertySetFunction() override;
@@ -1348,7 +1355,7 @@
   void GenerateProtocol(const ObjCProtocolDecl *PD) override {
 // Do nothing - we only emit referenced protocols.
   }
-  llvm::Constant *GenerateProtocolRef(const ObjCProtocolDecl *PD) {
+  llvm::Constant *GenerateProtocolRef(const ObjCProtocolDecl *PD) override {
 std::string ProtocolName = PD->getNameAsString();
 auto * = ExistingProtocols[ProtocolName];
 if (Protocol)
@@ -3039,13 +3046,18 @@
 
 llvm::Value *CGObjCGNU::GenerateProtocolRef(CodeGenFunction ,
 const ObjCProtocolDecl *PD) {
+  auto protocol = GenerateProtocolRef(PD);
+  llvm::Type *T =
+  CGM.getTypes().ConvertType(CGM.getContext().getObjCProtoType());
+  return CGF.Builder.CreateBitCast(protocol, llvm::PointerType::getUnqual(T));
+}
+
+llvm::Constant *CGObjCGNU::GenerateProtocolRef(const ObjCProtocolDecl *PD) {
   llvm::Constant * = ExistingProtocols[PD->getNameAsString()];
   if (!protocol)
 GenerateProtocol(PD);
   assert(protocol && "Unknown protocol");
-  llvm::Type *T =
-CGM.getTypes().ConvertType(CGM.getContext().getObjCProtoType());
-  return CGF.Builder.CreateBitCast(protocol, llvm::PointerType::getUnqual(T));
+  return protocol;
 }
 
 llvm::Constant *
Index: clang/include/clang/CodeGen/CodeGenABITypes.h

[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-04-01 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer marked an inline comment as done.
aschwaighofer added inline comments.



Comment at: clang/lib/CodeGen/CGObjCRuntime.h:217
+  /// ProtocolPtrTy.
+  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) = 0;
+

rjmccall wrote:
> aschwaighofer wrote:
> > aschwaighofer wrote:
> > > rjmccall wrote:
> > > > Can this name more closely parallel the "external" name, like 
> > > > `getOrEmitProtocolObject`?
> > > > 
> > > > Also, I think we're incrementally lowercasing new method names.
> > > This is an already existing method. I just moved it higher in the class 
> > > hierarchy to CGObjCRuntime from CGObjCMac so that it is callable from 
> > > getOrEmitProtocolObject.
> > s/getOrEmitProtocolObject/emitObjCProtocolObject
> I see.  Well, in that case, I won't ask you to rename it, but please do 
> implement it for the GNU runtime as I mentioned.
Done. I introduced 
`CGObjCGNU::GenerateProtocolRef(const ObjCProtocolDecl *PD)` because it only 
existed in the `CGObjCGNUstep2` subclass.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-04-01 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer updated this revision to Diff 254171.
aschwaighofer added a comment.

- Implement for the GNU runtimes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/CGObjCRuntime.h

Index: clang/lib/CodeGen/CGObjCRuntime.h
===
--- clang/lib/CodeGen/CGObjCRuntime.h
+++ clang/lib/CodeGen/CGObjCRuntime.h
@@ -211,6 +211,11 @@
   /// implementations.
   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
 
+  /// GetOrEmitProtocol - Get the protocol object for the given
+  /// declaration, emitting it if necessary. The return value has type
+  /// ProtocolPtrTy.
+  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) = 0;
+
   /// Generate a function preamble for a method with the specified
   /// types.
 
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -13,14 +13,15 @@
 //===--===//
 
 #include "CGObjCRuntime.h"
-#include "CGCleanup.h"
 #include "CGCXXABI.h"
+#include "CGCleanup.h"
 #include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/Support/SaveAndRestore.h"
 
 using namespace clang;
@@ -383,3 +384,9 @@
 CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
   return MessageSendInfo(argsInfo, signatureType);
 }
+
+llvm::Constant *
+clang::CodeGen::emitObjCProtocolObject(CodeGenModule ,
+   const ObjCProtocolDecl *protocol) {
+  return CGM.getObjCRuntime().GetOrEmitProtocol(protocol);
+}
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1107,11 +1107,6 @@
 
   void GenerateProtocol(const ObjCProtocolDecl *PD) override;
 
-  /// GetOrEmitProtocol - Get the protocol object for the given
-  /// declaration, emitting it if necessary. The return value has type
-  /// ProtocolPtrTy.
-  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD)=0;
-
   /// GetOrEmitProtocolRef - Get a forward reference to the protocol
   /// object for the given declaration, emitting it if needed. These
   /// forward references will be filled in with empty bodies if no
Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -617,6 +617,13 @@
   llvm::Value *GenerateProtocolRef(CodeGenFunction ,
const ObjCProtocolDecl *PD) override;
   void GenerateProtocol(const ObjCProtocolDecl *PD) override;
+
+  virtual llvm::Constant *GenerateProtocolRef(const ObjCProtocolDecl *PD);
+
+  llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) override {
+return GenerateProtocolRef(PD);
+  }
+
   llvm::Function *ModuleInitFunction() override;
   llvm::FunctionCallee GetPropertyGetFunction() override;
   llvm::FunctionCallee GetPropertySetFunction() override;
@@ -1348,7 +1355,7 @@
   void GenerateProtocol(const ObjCProtocolDecl *PD) override {
 // Do nothing - we only emit referenced protocols.
   }
-  llvm::Constant *GenerateProtocolRef(const ObjCProtocolDecl *PD) {
+  llvm::Constant *GenerateProtocolRef(const ObjCProtocolDecl *PD) override {
 std::string ProtocolName = PD->getNameAsString();
 auto * = ExistingProtocols[ProtocolName];
 if (Protocol)
@@ -3039,13 +3046,18 @@
 
 llvm::Value *CGObjCGNU::GenerateProtocolRef(CodeGenFunction ,
 const ObjCProtocolDecl *PD) {
+  auto protocol = GenerateProtocolRef(PD);
+  llvm::Type *T =
+  CGM.getTypes().ConvertType(CGM.getContext().getObjCProtoType());
+  return CGF.Builder.CreateBitCast(protocol, llvm::PointerType::getUnqual(T));
+}
+
+llvm::Constant *CGObjCGNU::GenerateProtocolRef(const ObjCProtocolDecl *PD) {
   llvm::Constant * = ExistingProtocols[PD->getNameAsString()];
   if (!protocol)
 GenerateProtocol(PD);
   assert(protocol && "Unknown protocol");
-  llvm::Type *T =
-CGM.getTypes().ConvertType(CGM.getContext().getObjCProtoType());
-  return CGF.Builder.CreateBitCast(protocol, llvm::PointerType::getUnqual(T));
+  return protocol;
 }
 
 llvm::Constant *
Index: clang/include/clang/CodeGen/CodeGenABITypes.h
===
--- 

[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-31 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer marked an inline comment as done.
aschwaighofer added inline comments.



Comment at: clang/lib/CodeGen/CGObjCRuntime.h:217
+  /// ProtocolPtrTy.
+  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) = 0;
+

aschwaighofer wrote:
> rjmccall wrote:
> > Can this name more closely parallel the "external" name, like 
> > `getOrEmitProtocolObject`?
> > 
> > Also, I think we're incrementally lowercasing new method names.
> This is an already existing method. I just moved it higher in the class 
> hierarchy to CGObjCRuntime from CGObjCMac so that it is callable from 
> getOrEmitProtocolObject.
s/getOrEmitProtocolObject/emitObjCProtocolObject


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-31 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer marked an inline comment as done.
aschwaighofer added inline comments.



Comment at: clang/lib/CodeGen/CGObjCRuntime.h:217
+  /// ProtocolPtrTy.
+  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) = 0;
+

rjmccall wrote:
> Can this name more closely parallel the "external" name, like 
> `getOrEmitProtocolObject`?
> 
> Also, I think we're incrementally lowercasing new method names.
This is an already existing method. I just moved it higher in the class 
hierarchy to CGObjCRuntime from CGObjCMac so that it is callable from 
getOrEmitProtocolObject.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-31 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer marked an inline comment as done.
aschwaighofer added inline comments.



Comment at: clang/include/clang/CodeGen/CodeGenABITypes.h:148
+ llvm::function_ref
+ createProtocolReference);
 }  // end namespace CodeGen

rjmccall wrote:
> aschwaighofer wrote:
> > rjmccall wrote:
> > > I would call this `emitObjCProtocolObject` or something, and maybe say in 
> > > the comment:
> > > 
> > > > Get a pointer to a protocol object for the given declaration, emitting 
> > > > it if it hasn't already been emitted in this translation unit.  Note 
> > > > that the ABI for emitting a protocol reference in code (e.g. for a 
> > > > `@protocol` expression) in most runtimes is not as simple as just 
> > > > materializing a pointer to this object.
> > > 
> > > Can you explain the need for the callback?   Are you expecting to use 
> > > this for Swift-declared protocols by synthesizing an ObjC protocol 
> > > declaration for them?  I can see why you'd need a callback in that case.
> > > Can you explain the need for the callback? Are you expecting to use this 
> > > for Swift-declared protocols by synthesizing an ObjC protocol declaration 
> > > for them? I can see why you'd need a callback in that case.
> > 
> > The objective C protocol references other protocols in its inherited list. 
> > Swift has an internal list that keeps track of those protocols references 
> > and makes sure to initialized them for the debugger and also makes sure 
> > that the underlying protocol structure is emitted. The call back is to keep 
> > this list in sync.
> The problem is that this is really, really intertwined with the ABI logic.  
> This callback basically has to know exactly how the caller is calling it and 
> and what it's expected to build in response.
> 
> Swift code can use arbitrary inline Objective-C functions and therefore emit 
> arbitrary Objective-C code.  Is there an approach that handles that while 
> also being less invasive for Clang IRGen?  Can we, e.g., inspect the built 
> llvm::Module to figure out retroactively what protocol refs we need to update 
> dynamically instead of trying to track them during the build?
Yes. I think you are right. Swift can inspect the generated IR and update it.

https://github.com/aschwaighofer/swift/commit/d29daf41ec3a51405df31591dad6fea97dbc58e0

I have removed the callback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-31 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer updated this revision to Diff 253938.
aschwaighofer added a comment.

- Remove callback. Swift can inspect the generated IR and update it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/CGObjCRuntime.h

Index: clang/lib/CodeGen/CGObjCRuntime.h
===
--- clang/lib/CodeGen/CGObjCRuntime.h
+++ clang/lib/CodeGen/CGObjCRuntime.h
@@ -211,6 +211,11 @@
   /// implementations.
   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
 
+  /// GetOrEmitProtocol - Get the protocol object for the given
+  /// declaration, emitting it if necessary. The return value has type
+  /// ProtocolPtrTy.
+  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) = 0;
+
   /// Generate a function preamble for a method with the specified
   /// types.
 
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -13,14 +13,15 @@
 //===--===//
 
 #include "CGObjCRuntime.h"
-#include "CGCleanup.h"
 #include "CGCXXABI.h"
+#include "CGCleanup.h"
 #include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/Support/SaveAndRestore.h"
 
 using namespace clang;
@@ -383,3 +384,9 @@
 CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
   return MessageSendInfo(argsInfo, signatureType);
 }
+
+llvm::Constant *
+clang::CodeGen::emitObjCProtocolObject(CodeGenModule ,
+   const ObjCProtocolDecl *protocol) {
+  return CGM.getObjCRuntime().GetOrEmitProtocol(protocol);
+}
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1107,11 +1107,6 @@
 
   void GenerateProtocol(const ObjCProtocolDecl *PD) override;
 
-  /// GetOrEmitProtocol - Get the protocol object for the given
-  /// declaration, emitting it if necessary. The return value has type
-  /// ProtocolPtrTy.
-  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD)=0;
-
   /// GetOrEmitProtocolRef - Get a forward reference to the protocol
   /// object for the given declaration, emitting it if needed. These
   /// forward references will be filled in with empty bodies if no
Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -617,6 +617,11 @@
   llvm::Value *GenerateProtocolRef(CodeGenFunction ,
const ObjCProtocolDecl *PD) override;
   void GenerateProtocol(const ObjCProtocolDecl *PD) override;
+
+  llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) override {
+llvm_unreachable("not implemented");
+  }
+
   llvm::Function *ModuleInitFunction() override;
   llvm::FunctionCallee GetPropertyGetFunction() override;
   llvm::FunctionCallee GetPropertySetFunction() override;
Index: clang/include/clang/CodeGen/CodeGenABITypes.h
===
--- clang/include/clang/CodeGen/CodeGenABITypes.h
+++ clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -28,11 +28,12 @@
 #include "clang/CodeGen/CGFunctionInfo.h"
 
 namespace llvm {
-  class DataLayout;
-  class Module;
-  class Function;
-  class FunctionType;
-  class Type;
+class Constant;
+class DataLayout;
+class Module;
+class Function;
+class FunctionType;
+class Type;
 }
 
 namespace clang {
@@ -44,6 +45,7 @@
 class DiagnosticsEngine;
 class HeaderSearchOptions;
 class ObjCMethodDecl;
+class ObjCProtocolDecl;
 class PreprocessorOptions;
 
 namespace CodeGen {
@@ -137,6 +139,13 @@
CharUnits DstAlignment,
bool IsVolatile, QualType QT);
 
+/// Get a pointer to a protocol object for the given declaration, emitting it if
+/// it hasn't already been emitted in this translation unit. Note that the ABI
+/// for emitting a protocol reference in code (e.g. for a protocol expression)
+/// in most runtimes is not as simple as just materializing a pointer to this
+/// object.
+llvm::Constant *emitObjCProtocolObject(CodeGenModule ,
+   const ObjCProtocolDecl *p);
 }  // end namespace CodeGen
 }  // end namespace clang
 

[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-30 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer updated this revision to Diff 253712.
aschwaighofer added a comment.

- Change API name to emitObjCProtocolObject.
- Make stuff compile on current ToT.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/CGObjCRuntime.h

Index: clang/lib/CodeGen/CGObjCRuntime.h
===
--- clang/lib/CodeGen/CGObjCRuntime.h
+++ clang/lib/CodeGen/CGObjCRuntime.h
@@ -211,6 +211,16 @@
   /// implementations.
   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
 
+  /// getOrEmitProtocol - Get the protocol object for the given
+  /// declaration, emitting it if necessary. The return value has type
+  /// ProtocolPtrTy.
+  /// \p getProtocolReference is called by the implementation when a
+  /// reference to another protocol is needed.
+  virtual llvm::Constant *getOrEmitProtocol(
+  const ObjCProtocolDecl *OPD,
+  llvm::function_ref
+  getProtocolReference) = 0;
+
   /// Generate a function preamble for a method with the specified
   /// types.
 
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -13,14 +13,15 @@
 //===--===//
 
 #include "CGObjCRuntime.h"
-#include "CGCleanup.h"
 #include "CGCXXABI.h"
+#include "CGCleanup.h"
 #include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/Support/SaveAndRestore.h"
 
 using namespace clang;
@@ -383,3 +384,11 @@
 CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
   return MessageSendInfo(argsInfo, signatureType);
 }
+
+llvm::Constant *clang::CodeGen::emitObjCProtocolObject(
+CodeGenModule , const ObjCProtocolDecl *protocol,
+llvm::function_ref
+createProtocolReference) {
+  return CGM.getObjCRuntime().getOrEmitProtocol(protocol,
+createProtocolReference);
+}
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1110,7 +1110,7 @@
   /// GetOrEmitProtocol - Get the protocol object for the given
   /// declaration, emitting it if necessary. The return value has type
   /// ProtocolPtrTy.
-  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD)=0;
+  llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD);
 
   /// GetOrEmitProtocolRef - Get a forward reference to the protocol
   /// object for the given declaration, emitting it if needed. These
@@ -1288,10 +1288,15 @@
   llvm::Constant *emitMethodList(Twine Name, MethodListType MLT,
  ArrayRef Methods);
 
-  /// GetOrEmitProtocol - Get the protocol object for the given
+  /// getOrEmitProtocol - Get the protocol object for the given
   /// declaration, emitting it if necessary. The return value has type
   /// ProtocolPtrTy.
-  llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) override;
+  /// \p getProtocolReference is called by the implementation when a
+  /// reference to another protocol is needed.
+  llvm::Constant *getOrEmitProtocol(
+  const ObjCProtocolDecl *OPD,
+  llvm::function_ref
+  getProtocolReference) override;
 
   /// GetOrEmitProtocolRef - Get a forward reference to the protocol
   /// object for the given declaration, emitting it if needed. These
@@ -1309,9 +1314,11 @@
 
   /// EmitProtocolList - Generate the list of referenced
   /// protocols. The return value has type ProtocolListPtrTy.
-  llvm::Constant *EmitProtocolList(Twine Name,
-   ObjCProtocolDecl::protocol_iterator begin,
-   ObjCProtocolDecl::protocol_iterator end);
+  llvm::Constant *EmitProtocolList(
+  Twine Name, ObjCProtocolDecl::protocol_iterator begin,
+  ObjCProtocolDecl::protocol_iterator end,
+  llvm::function_ref
+  getProtocolRef);
 
   /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
   /// for the given selector.
@@ -1471,10 +1478,15 @@
 const ObjCIvarDecl *Ivar,
 unsigned long int offset);
 
-  /// GetOrEmitProtocol - Get the protocol object for the given
+  /// getOrEmitProtocol - Get the protocol object for the given
   /// declaration, emitting it if necessary. The return value has type
   /// ProtocolPtrTy.
-  

[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-30 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer marked an inline comment as done.
aschwaighofer added inline comments.



Comment at: clang/include/clang/CodeGen/CodeGenABITypes.h:148
+ llvm::function_ref
+ createProtocolReference);
 }  // end namespace CodeGen

rjmccall wrote:
> I would call this `emitObjCProtocolObject` or something, and maybe say in the 
> comment:
> 
> > Get a pointer to a protocol object for the given declaration, emitting it 
> > if it hasn't already been emitted in this translation unit.  Note that the 
> > ABI for emitting a protocol reference in code (e.g. for a `@protocol` 
> > expression) in most runtimes is not as simple as just materializing a 
> > pointer to this object.
> 
> Can you explain the need for the callback?   Are you expecting to use this 
> for Swift-declared protocols by synthesizing an ObjC protocol declaration for 
> them?  I can see why you'd need a callback in that case.
> Can you explain the need for the callback? Are you expecting to use this for 
> Swift-declared protocols by synthesizing an ObjC protocol declaration for 
> them? I can see why you'd need a callback in that case.

The objective C protocol references other protocols in its inherited list. 
Swift has an internal list that keeps track of those protocols references and 
makes sure to initialized them for the debugger and also makes sure that the 
underlying protocol structure is emitted. The call back is to keep this list in 
sync.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-30 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer added a comment.

> Can you explain the need for the callback? Are you expecting to use this for 
> Swift-declared protocols by synthesizing an ObjC protocol declaration for 
> them? I can see why you'd need a callback in that case.

The objective C protocol references other protocols in its inherited list. 
Swift has an internal list that keeps track of those protocols references and 
makes sure to initialized them for the debugger and also makes sure that the 
underlying protocol structure is emitted. The call back is to keep this list in 
sync.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77077/new/

https://reviews.llvm.org/D77077



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-30 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Swift would like to use clang's abis to emit protocol declarations.

It needs to a hook to register when inherited protocols are emitted.

This commits adds the public API:

emitProtocolDecl(CodeGenModule , const ObjCProtocolDecl *p,

  llvm::function_ref
  createProtocolReference);

rdar://60888524


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77077

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/CGObjCRuntime.h

Index: clang/lib/CodeGen/CGObjCRuntime.h
===
--- clang/lib/CodeGen/CGObjCRuntime.h
+++ clang/lib/CodeGen/CGObjCRuntime.h
@@ -211,6 +211,16 @@
   /// implementations.
   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
 
+  /// getOrEmitProtocol - Get the protocol object for the given
+  /// declaration, emitting it if necessary. The return value has type
+  /// ProtocolPtrTy.
+  /// \p getProtocolReference is called by the implementation when a
+  /// reference to another protocol is needed.
+  virtual llvm::Constant *getOrEmitProtocol(
+  const ObjCProtocolDecl *OPD,
+  llvm::function_ref
+  getProtocolReference) = 0;
+
   /// Generate a function preamble for a method with the specified
   /// types.
 
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -13,14 +13,15 @@
 //===--===//
 
 #include "CGObjCRuntime.h"
-#include "CGCleanup.h"
 #include "CGCXXABI.h"
+#include "CGCleanup.h"
 #include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/Support/SaveAndRestore.h"
 
 using namespace clang;
@@ -383,3 +384,11 @@
 CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
   return MessageSendInfo(argsInfo, signatureType);
 }
+
+llvm::Constant *clang::CodeGen::emitProtocolDecl(
+CodeGenModule , const ObjCProtocolDecl *protocol,
+llvm::function_ref
+createProtocolReference) {
+  return CGM.getObjCRuntime().getOrEmitProtocol(protocol,
+createProtocolReference);
+}
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1110,7 +1110,7 @@
   /// GetOrEmitProtocol - Get the protocol object for the given
   /// declaration, emitting it if necessary. The return value has type
   /// ProtocolPtrTy.
-  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD)=0;
+  llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD);
 
   /// GetOrEmitProtocolRef - Get a forward reference to the protocol
   /// object for the given declaration, emitting it if needed. These
@@ -1288,10 +1288,15 @@
   llvm::Constant *emitMethodList(Twine Name, MethodListType MLT,
  ArrayRef Methods);
 
-  /// GetOrEmitProtocol - Get the protocol object for the given
+  /// getOrEmitProtocol - Get the protocol object for the given
   /// declaration, emitting it if necessary. The return value has type
   /// ProtocolPtrTy.
-  llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) override;
+  /// \p getProtocolReference is called by the implementation when a
+  /// reference to another protocol is needed.
+  llvm::Constant *getOrEmitProtocol(
+  const ObjCProtocolDecl *OPD,
+  llvm::function_ref
+  getProtocolReference) override;
 
   /// GetOrEmitProtocolRef - Get a forward reference to the protocol
   /// object for the given declaration, emitting it if needed. These
@@ -1309,9 +1314,11 @@
 
   /// EmitProtocolList - Generate the list of referenced
   /// protocols. The return value has type ProtocolListPtrTy.
-  llvm::Constant *EmitProtocolList(Twine Name,
-   ObjCProtocolDecl::protocol_iterator begin,
-   ObjCProtocolDecl::protocol_iterator end);
+  llvm::Constant *EmitProtocolList(
+  Twine Name, ObjCProtocolDecl::protocol_iterator begin,
+  ObjCProtocolDecl::protocol_iterator end,
+  llvm::function_ref
+  getProtocolRef);
 
   /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
   /// for the given selector.
@@ -1471,10 +1478,15 @@
 const ObjCIvarDecl *Ivar,
 unsigned long int offset);
 
-  /// GetOrEmitProtocol - Get the protocol object 

[PATCH] D46550: Support Swift calling convention for PPC64 targets

2018-05-17 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer accepted this revision.
aschwaighofer added a comment.
This revision is now accepted and ready to land.

Looks good.


Repository:
  rC Clang

https://reviews.llvm.org/D46550



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34454: SwiftCC: Perform physical layout when computing coercion types

2017-06-21 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer updated this revision to Diff 103459.
aschwaighofer added a comment.

Same patch bug with added diff context.


https://reviews.llvm.org/D34454

Files:
  lib/CodeGen/SwiftCallingConv.cpp
  test/CodeGen/64bit-swiftcall.c


Index: test/CodeGen/64bit-swiftcall.c
===
--- test/CodeGen/64bit-swiftcall.c
+++ test/CodeGen/64bit-swiftcall.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s --check-prefix=X86-64
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s --check-prefix=ARM64
 
@@ -1014,3 +1015,20 @@
 TEST(struct_v1f3)
 // ARM64-LABEL: define swiftcc { <2 x float>, float } @return_struct_v1f3()
 // ARM64-LABEL: define swiftcc void @take_struct_v1f3(<2 x float>, float)
+
+typedef struct {
+  int3 vect;
+  unsigned long long val;
+} __attribute__((packed)) padded_alloc_size_vector;
+TEST(padded_alloc_size_vector)
+// X86-64-LABEL: take_padded_alloc_size_vector(<3 x i32>, i64)
+// X86-64-NOT: [4 x i8]
+// x86-64: ret void
+
+typedef union {
+  float f1;
+  float3 fv2;
+} union_hom_fp_partial2;
+TEST(union_hom_fp_partial2)
+// X86-64-LABEL: take_union_hom_fp_partial2(i64, float)
+// ARM64-LABEL: take_union_hom_fp_partial2(i64, float)
Index: lib/CodeGen/SwiftCallingConv.cpp
===
--- lib/CodeGen/SwiftCallingConv.cpp
+++ lib/CodeGen/SwiftCallingConv.cpp
@@ -57,6 +57,10 @@
   return CharUnits::fromQuantity(CGM.getDataLayout().getTypeStoreSize(type));
 }
 
+static CharUnits getTypeAllocSize(CodeGenModule , llvm::Type *type) {
+  return CharUnits::fromQuantity(CGM.getDataLayout().getTypeAllocSize(type));
+}
+
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
 
@@ -542,7 +546,9 @@
   packed = true;
 
 elts.push_back(entry.Type);
-lastEnd = entry.End;
+
+lastEnd = entry.Begin + getTypeAllocSize(CGM, entry.Type);
+assert(entry.End <= lastEnd);
   }
 
   // We don't need to adjust 'packed' to deal with possible tail padding


Index: test/CodeGen/64bit-swiftcall.c
===
--- test/CodeGen/64bit-swiftcall.c
+++ test/CodeGen/64bit-swiftcall.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=X86-64
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64
 
@@ -1014,3 +1015,20 @@
 TEST(struct_v1f3)
 // ARM64-LABEL: define swiftcc { <2 x float>, float } @return_struct_v1f3()
 // ARM64-LABEL: define swiftcc void @take_struct_v1f3(<2 x float>, float)
+
+typedef struct {
+  int3 vect;
+  unsigned long long val;
+} __attribute__((packed)) padded_alloc_size_vector;
+TEST(padded_alloc_size_vector)
+// X86-64-LABEL: take_padded_alloc_size_vector(<3 x i32>, i64)
+// X86-64-NOT: [4 x i8]
+// x86-64: ret void
+
+typedef union {
+  float f1;
+  float3 fv2;
+} union_hom_fp_partial2;
+TEST(union_hom_fp_partial2)
+// X86-64-LABEL: take_union_hom_fp_partial2(i64, float)
+// ARM64-LABEL: take_union_hom_fp_partial2(i64, float)
Index: lib/CodeGen/SwiftCallingConv.cpp
===
--- lib/CodeGen/SwiftCallingConv.cpp
+++ lib/CodeGen/SwiftCallingConv.cpp
@@ -57,6 +57,10 @@
   return CharUnits::fromQuantity(CGM.getDataLayout().getTypeStoreSize(type));
 }
 
+static CharUnits getTypeAllocSize(CodeGenModule , llvm::Type *type) {
+  return CharUnits::fromQuantity(CGM.getDataLayout().getTypeAllocSize(type));
+}
+
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
 
@@ -542,7 +546,9 @@
   packed = true;
 
 elts.push_back(entry.Type);
-lastEnd = entry.End;
+
+lastEnd = entry.Begin + getTypeAllocSize(CGM, entry.Type);
+assert(entry.End <= lastEnd);
   }
 
   // We don't need to adjust 'packed' to deal with possible tail padding
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34454: SwiftCC: Perform physical layout when computing coercion types

2017-06-21 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer updated this revision to Diff 103458.
aschwaighofer retitled this revision from "SwiftAggregateLowering: Use type 
alloc size to determine the size of types" to "SwiftCC: Perform physical layout 
when computing coercion  types".
aschwaighofer edited the summary of this revision.
aschwaighofer removed a reviewer: cfe-commits.
aschwaighofer added a subscriber: cfe-commits.
aschwaighofer added a comment.

Based on email conversation with John. He pointed out we purposely don't want 
to use the allocation size for the algorithm and that we can just use LLVM's 
layout when we compute the coercion types.


https://reviews.llvm.org/D34454

Files:
  lib/CodeGen/SwiftCallingConv.cpp
  test/CodeGen/64bit-swiftcall.c


Index: test/CodeGen/64bit-swiftcall.c
===
--- test/CodeGen/64bit-swiftcall.c
+++ test/CodeGen/64bit-swiftcall.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s --check-prefix=X86-64
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s --check-prefix=ARM64
 
@@ -1014,3 +1015,20 @@
 TEST(struct_v1f3)
 // ARM64-LABEL: define swiftcc { <2 x float>, float } @return_struct_v1f3()
 // ARM64-LABEL: define swiftcc void @take_struct_v1f3(<2 x float>, float)
+
+typedef struct {
+  int3 vect;
+  unsigned long long val;
+} __attribute__((packed)) padded_alloc_size_vector;
+TEST(padded_alloc_size_vector)
+// X86-64-LABEL: take_padded_alloc_size_vector(<3 x i32>, i64)
+// X86-64-NOT: [4 x i8]
+// x86-64: ret void
+
+typedef union {
+  float f1;
+  float3 fv2;
+} union_hom_fp_partial2;
+TEST(union_hom_fp_partial2)
+// X86-64-LABEL: take_union_hom_fp_partial2(i64, float)
+// ARM64-LABEL: take_union_hom_fp_partial2(i64, float)
Index: lib/CodeGen/SwiftCallingConv.cpp
===
--- lib/CodeGen/SwiftCallingConv.cpp
+++ lib/CodeGen/SwiftCallingConv.cpp
@@ -57,6 +57,10 @@
   return CharUnits::fromQuantity(CGM.getDataLayout().getTypeStoreSize(type));
 }
 
+static CharUnits getTypeAllocSize(CodeGenModule , llvm::Type *type) {
+  return CharUnits::fromQuantity(CGM.getDataLayout().getTypeAllocSize(type));
+}
+
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
 
@@ -542,7 +546,9 @@
   packed = true;
 
 elts.push_back(entry.Type);
-lastEnd = entry.End;
+
+lastEnd = entry.Begin + getTypeAllocSize(CGM, entry.Type);
+assert(entry.End <= lastEnd);
   }
 
   // We don't need to adjust 'packed' to deal with possible tail padding


Index: test/CodeGen/64bit-swiftcall.c
===
--- test/CodeGen/64bit-swiftcall.c
+++ test/CodeGen/64bit-swiftcall.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=X86-64
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64
 
@@ -1014,3 +1015,20 @@
 TEST(struct_v1f3)
 // ARM64-LABEL: define swiftcc { <2 x float>, float } @return_struct_v1f3()
 // ARM64-LABEL: define swiftcc void @take_struct_v1f3(<2 x float>, float)
+
+typedef struct {
+  int3 vect;
+  unsigned long long val;
+} __attribute__((packed)) padded_alloc_size_vector;
+TEST(padded_alloc_size_vector)
+// X86-64-LABEL: take_padded_alloc_size_vector(<3 x i32>, i64)
+// X86-64-NOT: [4 x i8]
+// x86-64: ret void
+
+typedef union {
+  float f1;
+  float3 fv2;
+} union_hom_fp_partial2;
+TEST(union_hom_fp_partial2)
+// X86-64-LABEL: take_union_hom_fp_partial2(i64, float)
+// ARM64-LABEL: take_union_hom_fp_partial2(i64, float)
Index: lib/CodeGen/SwiftCallingConv.cpp
===
--- lib/CodeGen/SwiftCallingConv.cpp
+++ lib/CodeGen/SwiftCallingConv.cpp
@@ -57,6 +57,10 @@
   return CharUnits::fromQuantity(CGM.getDataLayout().getTypeStoreSize(type));
 }
 
+static CharUnits getTypeAllocSize(CodeGenModule , llvm::Type *type) {
+  return CharUnits::fromQuantity(CGM.getDataLayout().getTypeAllocSize(type));
+}
+
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
 
@@ -542,7 +546,9 @@
   packed = true;
 
 elts.push_back(entry.Type);
-lastEnd = entry.End;
+
+lastEnd = entry.Begin + getTypeAllocSize(CGM, entry.Type);
+assert(entry.End <= lastEnd);
   }
 
   // We don't 

[PATCH] D34454: SwiftAggregateLowering: Use type alloc size to determine the size of types

2017-06-21 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer created this revision.

The layout must be compatible with the input layout, offsets are defined in
terms of offsets within a packed struct which are computed in terms of the alloc
size of a type.

Using the store size we would insert padding for the following type for example:

struct {

  int3 v;
  long long l;

} __attribute((packed))

On x86-64 int3 is padded to int4 alignment. The swiftcc type would be
<{ <3 x float>, [4 x i8], i64 }> which is not compatible with <{ <3 x float>, 
i64 }>.

The latter has i64 at offset 16 and the former at offset 20.

rdar://32618125


https://reviews.llvm.org/D34454

Files:
  lib/CodeGen/SwiftCallingConv.cpp
  test/CodeGen/64bit-swiftcall.c
  test/CodeGen/windows-swiftcall.c

Index: test/CodeGen/windows-swiftcall.c
===
--- test/CodeGen/windows-swiftcall.c
+++ test/CodeGen/windows-swiftcall.c
@@ -455,4 +455,4 @@
   int3 v __attribute__((packed));
 } misaligned_int3;
 TEST(misaligned_int3)
-// CHECK-LABEL: define swiftcc void @take_misaligned_int3(i64, i64)
+// CHECK-LABEL: define swiftcc void @take_misaligned_int3(i64, i64, i32)
Index: test/CodeGen/64bit-swiftcall.c
===
--- test/CodeGen/64bit-swiftcall.c
+++ test/CodeGen/64bit-swiftcall.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=X86-64
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64
 
@@ -463,7 +464,7 @@
   int3 v __attribute__((packed));
 } misaligned_int3;
 TEST(misaligned_int3)
-// CHECK-LABEL: define swiftcc void @take_misaligned_int3(i64, i64)
+// CHECK-LABEL: define swiftcc void @take_misaligned_int3(i64, i64, i32)
 
 typedef struct {
   float f0;
@@ -1014,3 +1015,19 @@
 TEST(struct_v1f3)
 // ARM64-LABEL: define swiftcc { <2 x float>, float } @return_struct_v1f3()
 // ARM64-LABEL: define swiftcc void @take_struct_v1f3(<2 x float>, float)
+
+typedef struct {
+  int3 vect;
+  unsigned long long val;
+} __attribute__((packed)) padded_alloc_size_vector;
+TEST(padded_alloc_size_vector)
+// X86-64-LABEL: take_padded_alloc_size_vector(<3 x i32>, i64)
+// ARM64-LABEL: take_padded_alloc_size_vector(<2 x i32>, i32, i64)
+
+typedef union {
+  float f1;
+  float3 fv2;
+} union_hom_fp_partial2;
+TEST(union_hom_fp_partial2)
+// X86-64-LABEL: take_union_hom_fp_partial2(i64, i64)
+// ARM64-LABEL: take_union_hom_fp_partial2(i64, float)
Index: lib/CodeGen/SwiftCallingConv.cpp
===
--- lib/CodeGen/SwiftCallingConv.cpp
+++ lib/CodeGen/SwiftCallingConv.cpp
@@ -57,6 +57,10 @@
   return CharUnits::fromQuantity(CGM.getDataLayout().getTypeStoreSize(type));
 }
 
+static CharUnits getTypeAllocSize(CodeGenModule , llvm::Type *type) {
+  return CharUnits::fromQuantity(CGM.getDataLayout().getTypeAllocSize(type));
+}
+
 void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {
   // Deal with various aggregate types as special cases:
 
@@ -189,24 +193,24 @@
 
 void SwiftAggLowering::addTypedData(llvm::Type *type, CharUnits begin) {
   assert(type && "didn't provide type for typed data");
-  addTypedData(type, begin, begin + getTypeStoreSize(CGM, type));
+  addTypedData(type, begin, begin + getTypeAllocSize(CGM, type));
 }
 
 void SwiftAggLowering::addTypedData(llvm::Type *type,
 CharUnits begin, CharUnits end) {
   assert(type && "didn't provide type for typed data");
-  assert(getTypeStoreSize(CGM, type) == end - begin);
+  assert(getTypeAllocSize(CGM, type) == end - begin);
 
   // Legalize vector types.
   if (auto vecTy = dyn_cast(type)) {
 SmallVector componentTys;
-legalizeVectorType(CGM, end - begin, vecTy, componentTys);
+legalizeVectorType(CGM, getTypeStoreSize(CGM, type), vecTy, componentTys);
 assert(componentTys.size() >= 1);
 
 // Walk the initial components.
 for (size_t i = 0, e = componentTys.size(); i != e - 1; ++i) {
   llvm::Type *componentTy = componentTys[i];
-  auto componentSize = getTypeStoreSize(CGM, componentTy);
+  auto componentSize = getTypeAllocSize(CGM, componentTy);
   assert(componentSize < end - begin);
   addLegalTypedData(componentTy, begin, begin + componentSize);
   begin += componentSize;
@@ -236,14 +240,15 @@
   auto eltTy = split.first;
   auto numElts = split.second;
 
-  auto eltSize = (end - begin) / numElts;
-  assert(eltSize == getTypeStoreSize(CGM, eltTy));
-  for (size_t i = 0, e = numElts; i != e; ++i) {
-addLegalTypedData(eltTy, begin, begin + eltSize);
-begin += eltSize;
+  auto