|
18 | 18 | #include "lldb/Target/SwiftLanguageRuntime.h" |
19 | 19 | #include "lldb/Utility/DataBufferHeap.h" |
20 | 20 | #include "lldb/Utility/Status.h" |
| 21 | +#include "swift/AST/Types.h" |
21 | 22 | #include "swift/Demangling/ManglingMacros.h" |
22 | 23 | #include "llvm/ADT/Optional.h" |
23 | 24 | #include "llvm/ADT/StringRef.h" |
@@ -979,8 +980,9 @@ llvm::Optional<std::vector<std::string>> |
979 | 980 | ReadVector(Process &process, ValueObject &valobj, |
980 | 981 | const SIMDElementFormatter &formatter, unsigned num_elements) { |
981 | 982 | Status error; |
| 983 | + static ConstString g_storage("_storage"); |
982 | 984 | static ConstString g_value("_value"); |
983 | | - ValueObjectSP value_sp = valobj.GetChildAtNamePath({g_value}); |
| 985 | + ValueObjectSP value_sp = valobj.GetChildAtNamePath({g_storage, g_value}); |
984 | 986 | if (!value_sp) |
985 | 987 | return llvm::None; |
986 | 988 |
|
@@ -1032,17 +1034,76 @@ void PrintMatrix(Stream &stream, |
1032 | 1034 |
|
1033 | 1035 | } // end anonymous namespace |
1034 | 1036 |
|
1035 | | -bool lldb_private::formatters::swift::AccelerateSIMD_SummaryProvider( |
| 1037 | +bool lldb_private::formatters::swift::SIMDVector_SummaryProvider( |
1036 | 1038 | ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { |
1037 | 1039 | Status error; |
1038 | 1040 | ProcessSP process_sp(valobj.GetProcessSP()); |
1039 | 1041 | if (!process_sp) |
1040 | 1042 | 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 | + } |
1041 | 1092 |
|
| 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; |
1042 | 1102 | Process &process = *process_sp.get(); |
1043 | 1103 |
|
1044 | 1104 | // Get the type name without the "simd.simd_" prefix. |
1045 | 1105 | ConstString full_type_name = valobj.GetTypeName(); |
| 1106 | + |
1046 | 1107 | llvm::StringRef type_name = full_type_name.GetStringRef(); |
1047 | 1108 | if (type_name.startswith("simd.")) |
1048 | 1109 | type_name = type_name.drop_front(5); |
|
0 commit comments