Skip to content

[5.1] Replace mapIntoContext with DWARF Archetype name lookup. #22810

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

Merged
merged 3 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
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
58 changes: 32 additions & 26 deletions lib/IRGen/DebugTypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
using namespace swift;
using namespace irgen;

DebugTypeInfo::DebugTypeInfo(DeclContext *DC, GenericEnvironment *GE,
swift::Type Ty, llvm::Type *StorageTy, Size size,
Alignment align, bool HasDefaultAlignment)
: DeclCtx(DC), GenericEnv(GE), Type(Ty.getPointer()),
StorageType(StorageTy), size(size), align(align),
DefaultAlignment(HasDefaultAlignment) {
DebugTypeInfo::DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size size,
Alignment align, bool HasDefaultAlignment,
bool IsMetadata)
: Type(Ty.getPointer()), StorageType(StorageTy), size(size), align(align),
DefaultAlignment(HasDefaultAlignment), IsMetadataType(IsMetadata) {
assert(StorageType && "StorageType is a nullptr");
assert(align.getValue() != 0);
}
Expand All @@ -43,9 +42,7 @@ static bool hasDefaultAlignment(swift::Type Ty) {
return true;
}

DebugTypeInfo DebugTypeInfo::getFromTypeInfo(DeclContext *DC,
GenericEnvironment *GE,
swift::Type Ty,
DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty,
const TypeInfo &Info) {
Size size;
if (Info.isFixedSize()) {
Expand All @@ -56,13 +53,12 @@ DebugTypeInfo DebugTypeInfo::getFromTypeInfo(DeclContext *DC,
// encounter one.
size = Size(0);
}
return DebugTypeInfo(DC, GE, Ty.getPointer(), Info.getStorageType(), size,
Info.getBestKnownAlignment(), hasDefaultAlignment(Ty));
return DebugTypeInfo(Ty.getPointer(), Info.getStorageType(), size,
Info.getBestKnownAlignment(), hasDefaultAlignment(Ty),
false);
}

DebugTypeInfo DebugTypeInfo::getLocalVariable(DeclContext *DC,
GenericEnvironment *GE,
VarDecl *Decl, swift::Type Ty,
DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
const TypeInfo &Info) {

auto DeclType = Decl->getInterfaceType();
Expand All @@ -77,13 +73,21 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(DeclContext *DC,
// the type hasn't been mucked with by an optimization pass.
auto *Type = Sugared->isEqual(RealType) ? DeclType.getPointer()
: RealType.getPointer();
return getFromTypeInfo(DC, GE, Type, Info);
return getFromTypeInfo(Type, Info);
}

DebugTypeInfo DebugTypeInfo::getMetadata(swift::Type Ty, llvm::Type *StorageTy,
Size size, Alignment align) {
DebugTypeInfo DbgTy(nullptr, nullptr, Ty.getPointer(), StorageTy, size,
align, true);
DebugTypeInfo DbgTy(Ty.getPointer(), StorageTy, size,
align, true, false);
assert(!DbgTy.isArchetype() && "type metadata cannot contain an archetype");
return DbgTy;
}

DebugTypeInfo DebugTypeInfo::getArchetype(swift::Type Ty, llvm::Type *StorageTy,
Size size, Alignment align) {
DebugTypeInfo DbgTy(Ty.getPointer(), StorageTy, size,
align, true, true);
assert(!DbgTy.isArchetype() && "type metadata cannot contain an archetype");
return DbgTy;
}
Expand All @@ -93,19 +97,15 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
Alignment align) {
// Prefer the original, potentially sugared version of the type if
// the type hasn't been mucked with by an optimization pass.
DeclContext *DC = nullptr;
GenericEnvironment *GE = nullptr;
auto LowTy = GV->getLoweredType().getASTType();
auto *Type = LowTy.getPointer();
if (auto *Decl = GV->getDecl()) {
DC = Decl->getDeclContext();
GE = DC->getGenericEnvironmentOfContext();
auto DeclType = Decl->getType();
if (DeclType->isEqual(LowTy))
Type = DeclType.getPointer();
}
DebugTypeInfo DbgTy(DC, GE, Type, StorageTy, size, align,
hasDefaultAlignment(Type));
DebugTypeInfo DbgTy(Type, StorageTy, size, align, hasDefaultAlignment(Type),
false);
assert(StorageTy && "StorageType is a nullptr");
assert(!DbgTy.isArchetype() &&
"type of global variable cannot be an archetype");
Expand All @@ -116,13 +116,19 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass,
llvm::Type *StorageType, Size size,
Alignment align) {
DebugTypeInfo DbgTy(nullptr, nullptr,
theClass->getInterfaceType().getPointer(), StorageType,
size, align, true);
DebugTypeInfo DbgTy(theClass->getInterfaceType().getPointer(), StorageType,
size, align, true, false);
assert(!DbgTy.isArchetype() && "type of objc class cannot be an archetype");
return DbgTy;
}

DebugTypeInfo DebugTypeInfo::getErrorResult(swift::Type Ty,
llvm::Type *StorageType, Size size,
Alignment align) {
assert(StorageType && "StorageType is a nullptr");
return {Ty, StorageType, size, align, true, false};
}

bool DebugTypeInfo::operator==(DebugTypeInfo T) const {
return (getType() == T.getType() &&
size == T.size &&
Expand Down
36 changes: 16 additions & 20 deletions lib/IRGen/DebugTypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ class TypeInfo;
/// for a type.
class DebugTypeInfo {
public:
/// The DeclContext of the function. This might not be the DeclContext of
/// the variable if inlining took place.
DeclContext *DeclCtx = nullptr;

/// The generic environment of the type. Ideally we should need only this and
/// retire the DeclCtxt.
GenericEnvironment *GenericEnv = nullptr;

/// The type we need to emit may be different from the type
/// mentioned in the Decl, for example, stripped of qualifiers.
TypeBase *Type = nullptr;
Expand All @@ -54,34 +46,39 @@ class DebugTypeInfo {
Size size = Size(0);
Alignment align = Alignment(0);
bool DefaultAlignment = true;
bool IsMetadataType = false;

DebugTypeInfo() {}
DebugTypeInfo(DeclContext *DC, GenericEnvironment *GE, swift::Type Ty,
llvm::Type *StorageTy, Size SizeInBytes, Alignment AlignInBytes,
bool HasDefaultAlignment);
DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size SizeInBytes,
Alignment AlignInBytes, bool HasDefaultAlignment,
bool IsMetadataType);

/// Create type for a local variable.
static DebugTypeInfo getLocalVariable(DeclContext *DeclCtx,
GenericEnvironment *GE, VarDecl *Decl,
static DebugTypeInfo getLocalVariable(VarDecl *Decl,
swift::Type Ty, const TypeInfo &Info);
/// Create type for an artificial metadata variable.
/// Create type for global type metadata.
static DebugTypeInfo getMetadata(swift::Type Ty, llvm::Type *StorageTy,
Size size, Alignment align);
/// Create type for an artificial metadata variable.
static DebugTypeInfo getArchetype(swift::Type Ty, llvm::Type *StorageTy,
Size size, Alignment align);

/// Create a standalone type from a TypeInfo object.
static DebugTypeInfo getFromTypeInfo(DeclContext *DC, GenericEnvironment *GE,
swift::Type Ty, const TypeInfo &Info);
static DebugTypeInfo getFromTypeInfo(swift::Type Ty, const TypeInfo &Info);
/// Global variables.
static DebugTypeInfo getGlobal(SILGlobalVariable *GV, llvm::Type *StorageType,
Size size, Alignment align);
/// ObjC classes.
static DebugTypeInfo getObjCClass(ClassDecl *theClass,
llvm::Type *StorageType, Size size,
Alignment align);
/// Error type.
static DebugTypeInfo getErrorResult(swift::Type Ty, llvm::Type *StorageType,
Size size, Alignment align);

TypeBase *getType() const { return Type; }

TypeDecl *getDecl() const;
DeclContext *getDeclContext() const { return DeclCtx; }
GenericEnvironment *getGenericEnvironment() const { return GenericEnv; }

// Determine whether this type is an Archetype itself.
bool isArchetype() const {
Expand All @@ -106,9 +103,8 @@ template <> struct DenseMapInfo<swift::irgen::DebugTypeInfo> {
}
static swift::irgen::DebugTypeInfo getTombstoneKey() {
return swift::irgen::DebugTypeInfo(
nullptr, nullptr,
llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey(), nullptr,
swift::irgen::Size(0), swift::irgen::Alignment(0), false);
swift::irgen::Size(0), swift::irgen::Alignment(0), false, false);
}
static unsigned getHashValue(swift::irgen::DebugTypeInfo Val) {
return DenseMapInfo<swift::CanType>::getHashValue(Val.getType());
Expand Down
Loading