Skip to content

Commit 854c754

Browse files
authored
Merge pull request swiftlang#1303 from dcci/simd-50
apple-llvm-split-commit: a13041f1f6d3a8c7e10b41b8eed39bf1b74390b8 apple-llvm-split-dir: lldb/
2 parents ace60c2 + d13f94a commit 854c754

File tree

6 files changed

+97
-30
lines changed

6 files changed

+97
-30
lines changed

lldb/lit/SwiftREPL/SIMD.test

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Test formatters for Accelerate/simd.
1+
// Test formatters for SIMD.
22
// REQUIRES: darwin
3-
// REQUIRES: rdar46330565
43

54
// RUN: %lldb --repl < %s | FileCheck %s
65

@@ -169,3 +168,10 @@ simd_quatf(vector: colf4)
169168

170169
simd_quatd(vector: cold4)
171170
// CHECK: $R{{.*}}: simd_quatd = (1.500000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00)
171+
172+
// Test the new SIMD types
173+
let tinky = SIMD2<Int>(1, 2)
174+
// CHECK: {{tinky}}: SIMD2<Int> = (1, 2)
175+
176+
let patatino = SIMD4<Double>(1.5, 2.5, 3.5, 4.5)
177+
// CHECK: {{patatino}}: SIMD4<Double> = (1.5, 2.5, 3.5, 4.5)

lldb/packages/Python/lldbsuite/test/lang/swift/accelerate_simd/TestAccelerateSIMD.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@
1313
from lldbsuite.test.decorators import *
1414

1515
lldbinline.MakeInlineTest(__file__, globals(),
16-
decorators=[swiftTest,skipUnlessDarwin,
17-
skipIf(bugnumber=46330565)])
16+
decorators=[swiftTest,skipUnlessDarwin])
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
// main.swift
2-
//
3-
// This source file is part of the Swift.org open source project
4-
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6-
// Licensed under Apache License v2.0 with Runtime Library Exception
7-
//
8-
// See https://swift.org/LICENSE.txt for license information
9-
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10-
//
11-
// -----------------------------------------------------------------------------
12-
131
import simd
142

153
func main() -> Int {
16-
let d4 = simd_double4(1.5, 2, 3, 4) //%self.expect('frame variable d4', substrs=['1.5', '2', '3', '4'])
17-
print(d4)
18-
return 0
4+
let d4 = simd_double4(1.5, 2, 3, 4)
5+
let patatino = SIMD4<Int>(1,2,3,4)
6+
let tinky = SIMD2<Int>(12, 24)
7+
return 0 //%self.expect('frame variable d4', substrs=['1.5', '2', '3', '4'])
8+
//%self.expect('frame var patatino', substrs=['(1, 2, 3, 4)'])
9+
//%self.expect('frame var tinky', substrs=['(12, 24)'])
1910
}
2011

2112
main()

lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Target/SwiftLanguageRuntime.h"
1919
#include "lldb/Utility/DataBufferHeap.h"
2020
#include "lldb/Utility/Status.h"
21+
#include "swift/AST/Types.h"
2122
#include "swift/Demangling/ManglingMacros.h"
2223
#include "llvm/ADT/Optional.h"
2324
#include "llvm/ADT/StringRef.h"
@@ -979,8 +980,9 @@ llvm::Optional<std::vector<std::string>>
979980
ReadVector(Process &process, ValueObject &valobj,
980981
const SIMDElementFormatter &formatter, unsigned num_elements) {
981982
Status error;
983+
static ConstString g_storage("_storage");
982984
static ConstString g_value("_value");
983-
ValueObjectSP value_sp = valobj.GetChildAtNamePath({g_value});
985+
ValueObjectSP value_sp = valobj.GetChildAtNamePath({g_storage, g_value});
984986
if (!value_sp)
985987
return llvm::None;
986988

@@ -1032,17 +1034,76 @@ void PrintMatrix(Stream &stream,
10321034

10331035
} // end anonymous namespace
10341036

1035-
bool lldb_private::formatters::swift::AccelerateSIMD_SummaryProvider(
1037+
bool lldb_private::formatters::swift::SIMDVector_SummaryProvider(
10361038
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
10371039
Status error;
10381040
ProcessSP process_sp(valobj.GetProcessSP());
10391041
if (!process_sp)
10401042
return false;
1043+
Process &process = *process_sp.get();
1044+
1045+
// SIMD vector contains an inner member `_storage` which is an opaque
1046+
// container. Given SIMD is always in the form SIMDX<Type> where X is a
1047+
// positive integer, we can calculate the number of elements and the
1048+
// dynamic archetype (and hence its size). Everything follows naturally
1049+
// as the elements are laid out in a contigous buffer without padding.
1050+
CompilerType simd_type = valobj.GetCompilerType();
1051+
void *type_buffer = reinterpret_cast<void *>(simd_type.GetOpaqueQualType());
1052+
llvm::Optional<uint64_t> opt_type_size = simd_type.GetByteSize(nullptr);
1053+
if (!opt_type_size)
1054+
return false;
1055+
uint64_t type_size = *opt_type_size;
1056+
1057+
auto swift_type = reinterpret_cast<::swift::TypeBase *>(type_buffer);
1058+
auto bound_type = dyn_cast<::swift::BoundGenericType>(swift_type);
1059+
if (!bound_type)
1060+
return false;
1061+
auto generic_args = bound_type->getGenericArgs();
1062+
lldbassert(generic_args.size() == 1 && "broken SIMD type");
1063+
if (generic_args.size() != 1)
1064+
return false;
1065+
auto swift_arg_type = generic_args[0];
1066+
CompilerType arg_type(swift_arg_type);
1067+
1068+
llvm::Optional<uint64_t> opt_arg_size = arg_type.GetByteSize(nullptr);
1069+
if (!opt_arg_size)
1070+
return false;
1071+
uint64_t arg_size = *opt_arg_size;
1072+
1073+
DataExtractor storage_buf;
1074+
uint64_t len = valobj.GetData(storage_buf, error);
1075+
lldbassert(len == type_size && "extracted less bytes than requested");
1076+
if (len < type_size)
1077+
return false;
1078+
1079+
uint64_t num_elements = type_size / arg_size;
1080+
std::vector<std::string> elem_vector;
1081+
for (int i = 0; i < num_elements; ++i) {
1082+
DataExtractor elem_extractor(storage_buf, i * arg_size, arg_size);
1083+
auto simd_elem = ValueObject::CreateValueObjectFromData(
1084+
"simd_elem", elem_extractor, valobj.GetExecutionContextRef(), arg_type);
1085+
if (!simd_elem || simd_elem->GetError().Fail())
1086+
return false;
1087+
1088+
auto synthetic = simd_elem->GetSyntheticValue();
1089+
const char *value_string = synthetic->GetValueAsCString();
1090+
elem_vector.push_back(value_string);
1091+
}
10411092

1093+
return PrintRow(stream, elem_vector);
1094+
}
1095+
1096+
bool lldb_private::formatters::swift::LegacySIMD_SummaryProvider(
1097+
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
1098+
Status error;
1099+
ProcessSP process_sp(valobj.GetProcessSP());
1100+
if (!process_sp)
1101+
return false;
10421102
Process &process = *process_sp.get();
10431103

10441104
// Get the type name without the "simd.simd_" prefix.
10451105
ConstString full_type_name = valobj.GetTypeName();
1106+
10461107
llvm::StringRef type_name = full_type_name.GetStringRef();
10471108
if (type_name.startswith("simd."))
10481109
type_name = type_name.drop_front(5);

lldb/source/Plugins/Language/Swift/SwiftFormatters.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ bool CountableClosedRange_SummaryProvider(ValueObject &valobj, Stream &stream,
9090
bool StridedRangeGenerator_SummaryProvider(ValueObject &valobj, Stream &stream,
9191
const TypeSummaryOptions &options);
9292

93-
bool AccelerateSIMD_SummaryProvider(ValueObject &valobj, Stream &stream,
94-
const TypeSummaryOptions &options);
93+
bool SIMDVector_SummaryProvider(ValueObject &valobj, Stream &stream,
94+
const TypeSummaryOptions &options);
95+
96+
bool LegacySIMD_SummaryProvider(ValueObject &valobj, Stream &stream,
97+
const TypeSummaryOptions &options);
9598

9699
bool GLKit_SummaryProvider(ValueObject &valobj, Stream &stream,
97100
const TypeSummaryOptions &options);

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,21 @@ static void LoadSwiftFormatters(lldb::TypeCategoryImplSP swift_category_sp) {
538538
.SetDontShowChildren(true)
539539
.SetHideItemNames(true)
540540
.SetShowMembersOneLiner(false);
541-
const char *accelSIMDTypes = "^(simd\\.)?(simd_)?("
542-
"(int|uint|float|double)[234]|"
543-
"(float|double)[234]x[234]|"
544-
"quat(f|d)"
545-
")$";
541+
const char *SIMDTypes = "^(simd\\.)?(simd_)?("
542+
"(int|uint|float|double)[234]|"
543+
"(float|double)[234]x[234]|"
544+
"quat(f|d)"
545+
")$";
546+
547+
const char *newSIMDTypes = "^SIMD[0-9]+<.*>$";
548+
549+
AddCXXSummary(swift_category_sp,
550+
lldb_private::formatters::swift::LegacySIMD_SummaryProvider,
551+
"SIMD (legacy) summary provider", ConstString(SIMDTypes),
552+
simd_summary_flags, true);
546553
AddCXXSummary(swift_category_sp,
547-
lldb_private::formatters::swift::AccelerateSIMD_SummaryProvider,
548-
"Accelerate/SIMD summary provider", ConstString(accelSIMDTypes),
554+
lldb_private::formatters::swift::SIMDVector_SummaryProvider,
555+
"Vector SIMD summary provider", ConstString(newSIMDTypes),
549556
simd_summary_flags, true);
550557

551558
const char *GLKitTypes = "^(GLKMatrix[234]|GLKVector[234]|GLKQuaternion)$";

0 commit comments

Comments
 (0)