Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb] Make GetClangTypeNode aware of SIMD types. #3322

Open
wants to merge 1 commit into
base: stable/20210726
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <algorithm>
#include <sstream>
#include <regex>

using namespace lldb;
using namespace lldb_private;
Expand Down Expand Up @@ -307,6 +308,65 @@ GetClangTypeNode(CompilerType clang_type, swift::Demangle::Demangler &dem,
kind = Node::Kind::TypeAlias;
pointee = {};
break;
case eTypeClassVector: {
CompilerType element_type;
uint64_t size;
bool is_vector = clang_type.IsVectorType(&element_type, &size);
if (!is_vector)
break;

// Check if this is a SIMD type. For a vector this is something like
// type __attribute__((ext_vector_type(dimension))).
if (!clang_name.contains("__attribute__((ext_vector_type"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be cleaner to use ClangUtil::GetQualType(clang_type)->hasAttr()?

break;

// Build a tree with this structure:
// kind=BoundGenericStructure
// kind=Type
// kind=Structure
// kind=Module, text="Swift"
// kind=Identifier, text="SIMDN"
// kind=TypeList
// kind=Type
// kind=Structure
// kind=Module, text="Swift"
// kind=Identifier, text="Type"
NodePointer element_type_node =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe factor out a static DemangleNode* GetBoundGenericStruct(Name, TypeParam)?

GetClangTypeNode(element_type, dem, swift_ast_context);
NodePointer type_list = dem.createNode(Node::Kind::TypeList);
type_list->addChild(element_type_node, dem);
NodePointer identifier =
dem.createNode(Node::Kind::Identifier, "SIMD" + std::to_string(size));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a micro-optimization that will not matter, but we could do this with fewer memory allocations by using

SmallString<6> name;
llvm::raw_string_ostream(name)<<"SIMD"<<size;

NodePointer module = dem.createNode(Node::Kind::Module, "Swift");
NodePointer structure = dem.createNode(Node::Kind::Structure);
structure->addChild(module, dem);
structure->addChild(identifier, dem);
NodePointer type = dem.createNode(Node::Kind::Type);
type->addChild(structure, dem);
NodePointer signature = dem.createNode(Node::Kind::BoundGenericStructure);
signature->addChild(type, dem);
signature->addChild(type_list, dem);
NodePointer outer_type = dem.createNode(Node::Kind::Type);
outer_type->addChild(signature, dem);
return outer_type;
}
case eTypeClassStruct: {
// Check if this is a SIMD type. SIMD structs are matrixes, and they're
// in the format simd_typeNxN.
// Regex: start with simd_ and end with NxN.
std::regex simd_matrix_recognizer("^simd_.*[0-9]+x[0-9]+");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, there was some supported platform that didn't have a regex implementation. Maybe grep for regex in the lldb sources. If there is no comment about it there then this is probably no longer an issue.

if (!std::regex_match(clang_name.begin(), simd_matrix_recognizer))
break;

NodePointer identifier = dem.createNode(Node::Kind::Identifier, clang_name);
NodePointer module = dem.createNode(Node::Kind::Module, "simd");
NodePointer struct_ = dem.createNode(Node::Kind::Structure);
struct_->addChild(module, dem);
struct_->addChild(identifier, dem);
NodePointer type = dem.createNode(Node::Kind::Type);
type->addChild(struct_, dem);
return type;
}
default:
break;
}
Expand Down