Skip to content

[sil] Add dumpers for ResilienceExpansion/TypeLowering. #25918

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
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
12 changes: 12 additions & 0 deletions include/swift/AST/ResilienceExpansion.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#ifndef SWIFT_AST_RESILIENCE_EXPANSION_H
#define SWIFT_AST_RESILIENCE_EXPANSION_H

#include "llvm/Support/raw_ostream.h"

namespace swift {

/// A specification for how much to expand resilient types.
Expand Down Expand Up @@ -44,6 +46,16 @@ enum class ResilienceExpansion : unsigned {
Last_ResilienceExpansion = Maximal
};

inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
ResilienceExpansion expansion) {
switch (expansion) {
case ResilienceExpansion::Minimal:
return os << "Minimal";
case ResilienceExpansion::Maximal:
return os << "Maximal";
}
}

} // namespace swift

#endif // LLVM_SWIFT_AST_CAPTURE_INFO_H
Expand Down
6 changes: 6 additions & 0 deletions include/swift/SIL/TypeLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ class TypeLowering {

virtual ~TypeLowering() {}

/// Print out the internal state of this type lowering into \p os.
void print(llvm::raw_ostream &os) const;

/// Dump out the internal state of this type lowering to llvm::dbgs().
LLVM_ATTRIBUTE_DEPRECATED(void dump() const, "Only for use in the debugger");

/// Are r-values of this type passed as arguments indirectly by formal
/// convention?
///
Expand Down
19 changes: 19 additions & 0 deletions lib/SIL/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2687,3 +2687,22 @@ unsigned TypeConverter::countNumberOfFields(SILType Ty,
TypeFields[key] = fieldsCount;
return std::max(fieldsCount, 1U);
}

void TypeLowering::print(llvm::raw_ostream &os) const {
auto BOOL = [&](bool b) -> StringRef {
if (b)
return "true";
return "false";
};
os << "Type Lowering for lowered type: " << LoweredType << ".\n"
<< "Expansion: " << ResilienceExpansion(ForExpansion) << "\n"
<< "isTrivial: " << BOOL(Properties.isTrivial()) << ".\n"
<< "isFixedABI: " << BOOL(Properties.isFixedABI()) << ".\n"
<< "isAddressOnly: " << BOOL(Properties.isAddressOnly()) << ".\n"
<< "isResilient: " << BOOL(Properties.isResilient()) << ".\n"
<< "\n";
}

void TypeLowering::dump() const {
print(llvm::dbgs());
}