================
@@ -141,6 +142,78 @@ CompilerType RegisterTypeBuilderClang::BuildFlagsType(
   return flags_type;
 }
 
+CompilerType
+RegisterTypeBuilderClang::BuildVectorType(const RegisterTypeVector 
*vector_type,
+                                          uint32_t expected_byte_size,
+                                          lldb::TypeSystemClangSP type_system) 
{
+  if (!expected_byte_size)
+    return {};
+  if (auto type = GetExistingCompilerType(vector_type, expected_byte_size))
+    return *type;
+
+  std::optional<uint64_t> element_size =
+      vector_type->GetElementType()->GetByteSize();
+  if (!element_size) {
+    if (expected_byte_size % vector_type->GetCount())
+      return {};
+    element_size = expected_byte_size / vector_type->GetCount();
+  }
+  if (*element_size > UINT32_MAX ||
+      expected_byte_size % vector_type->GetCount() ||
+      *element_size != expected_byte_size / vector_type->GetCount())
+    return {};
+
+  CompilerType element_type;
+  const RegisterType *element_register_type = vector_type->GetElementType();
+  switch (element_register_type->getKind()) {
+  case RegisterType::eRegisterTypeKindBuiltin:
+    element_type =
+        
BuildBuiltinType(llvm::cast<RegisterTypeBuiltin>(element_register_type),
+                         *element_size, type_system);
+    break;
+  case RegisterType::eRegisterTypeKindVector:
+    element_type =
+        BuildVectorType(llvm::cast<RegisterTypeVector>(element_register_type),
+                        *element_size, type_system);
+    break;
+  case RegisterType::eRegisterTypeKindEnum:
+  case RegisterType::eRegisterTypeKindFlags:
+    return {};
+  }
+  if (!element_type.IsValid())
+    return {};
+
+  const auto *builtin_element =
+      llvm::dyn_cast<RegisterTypeBuiltin>(element_register_type);
+  bool pointer_element =
+      builtin_element && (builtin_element->GetID() == "data_ptr" ||
+                          builtin_element->GetID() == "code_ptr");
+  // Clang vectors can pad non-power-of-two element counts. Pointer, boolean
+  // and nested elements also need array layout to match the XML exactly.
+  bool use_vector = builtin_element && !pointer_element &&
+                    builtin_element->GetID() != "bool" &&
+                    llvm::has_single_bit(vector_type->GetCount());
+  CompilerType compiler_type = type_system->CreateArrayType(
+      element_type, vector_type->GetCount(), use_vector);
+
+  auto compiler_size =
+      llvm::expectedToOptional(compiler_type.GetByteSize(nullptr));
+  // Target ABI rules can still pad a Clang vector. Prefer an array when that
+  // gives the exact byte size described by the register XML.
+  if (compiler_size != expected_byte_size) {
----------------
DavidSpickett wrote:

As I understand it:
* If vector type would not pad, use a vector type.
* Otherwise use an array, but - 
* Whatever we chose might pad according to ABI rules, if so
* Use an array

Is there any reason to ever use a vector instead of an array? What's the 
downside of always using array here?

https://github.com/llvm/llvm-project/pull/220707
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to