Skip to content
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
5 changes: 4 additions & 1 deletion llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6336,7 +6336,10 @@ array is currently associated. The optional ``allocated`` is a
DIExpression that describes whether the allocatable array is currently
allocated. The optional ``rank`` is a DIExpression that describes the
rank (number of dimensions) of fortran assumed rank array (rank is
known at runtime).
known at runtime). The optional ``bitStride`` is an unsigned constant
that describes the number of bits occupied by an element of the array;
this is only needed if it differs from the element type's natural
size, and is normally used for packed arrays.

For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
descriptors <DIEnumerator>`, each representing the definition of an enumeration
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,15 @@ namespace llvm {
/// \param Rank The rank attribute of a descriptor-based
/// Fortran array, either a DIExpression* or
/// a DIVariable*.
/// \param BitStride The bit size of an element of the array.
DICompositeType *createArrayType(
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
PointerUnion<DIExpression *, DIVariable *> DataLocation = nullptr,
PointerUnion<DIExpression *, DIVariable *> Associated = nullptr,
PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr,
Metadata *BitStride = nullptr);

/// Create debugging information entry for a vector type.
/// \param Size Array size.
Expand Down
45 changes: 28 additions & 17 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1302,15 +1302,15 @@ class DICompositeType : public DIType {
DIType *VTableHolder, DITemplateParameterArray TemplateParams,
StringRef Identifier, DIDerivedType *Discriminator,
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
Metadata *Rank, DINodeArray Annotations, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
Flags, Elements.get(), RuntimeLang, EnumKind, VTableHolder,
TemplateParams.get(),
getCanonicalMDString(Context, Identifier), Discriminator,
DataLocation, Associated, Allocated, Rank, Annotations.get(),
Specification, NumExtraInhabitants, Storage, ShouldCreate);
Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(
Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
getCanonicalMDString(Context, Identifier), Discriminator, DataLocation,
Associated, Allocated, Rank, Annotations.get(), Specification,
NumExtraInhabitants, BitStride, Storage, ShouldCreate);
}
static DICompositeType *
getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Expand All @@ -1322,7 +1322,7 @@ class DICompositeType : public DIType {
Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated,
Metadata *Allocated, Metadata *Rank, Metadata *Annotations,
Metadata *Specification, uint32_t NumExtraInhabitants,
StorageType Storage, bool ShouldCreate = true);
Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);

TempDICompositeType cloneImpl() const {
return getTemporary(
Expand All @@ -1332,7 +1332,7 @@ class DICompositeType : public DIType {
getVTableHolder(), getTemplateParams(), getIdentifier(),
getDiscriminator(), getRawDataLocation(), getRawAssociated(),
getRawAllocated(), getRawRank(), getAnnotations(), getSpecification(),
getNumExtraInhabitants());
getNumExtraInhabitants(), getRawBitStride());
}

public:
Expand All @@ -1348,11 +1348,12 @@ class DICompositeType : public DIType {
Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
uint32_t NumExtraInhabitants = 0),
uint32_t NumExtraInhabitants = 0, Metadata *BitStride = nullptr),
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
OffsetInBits, Specification, NumExtraInhabitants, Flags, Elements,
RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
Discriminator, DataLocation, Associated, Allocated, Rank, Annotations))
Discriminator, DataLocation, Associated, Allocated, Rank, Annotations,
BitStride))
DEFINE_MDNODE_GET(
DICompositeType,
(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Expand All @@ -1364,11 +1365,13 @@ class DICompositeType : public DIType {
Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
Metadata *Specification = nullptr, uint32_t NumExtraInhabitants = 0),
Metadata *Specification = nullptr, uint32_t NumExtraInhabitants = 0,
Metadata *BitStride = nullptr),
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
TemplateParams, Identifier, Discriminator, DataLocation, Associated,
Allocated, Rank, Annotations, Specification, NumExtraInhabitants))
Allocated, Rank, Annotations, Specification, NumExtraInhabitants,
BitStride))

TempDICompositeType clone() const { return cloneImpl(); }

Expand All @@ -1389,7 +1392,7 @@ class DICompositeType : public DIType {
Metadata *VTableHolder, Metadata *TemplateParams,
Metadata *Discriminator, Metadata *DataLocation,
Metadata *Associated, Metadata *Allocated, Metadata *Rank,
Metadata *Annotations);
Metadata *Annotations, Metadata *BitStride);
static DICompositeType *getODRTypeIfExists(LLVMContext &Context,
MDString &Identifier);

Expand All @@ -1412,7 +1415,7 @@ class DICompositeType : public DIType {
Metadata *VTableHolder, Metadata *TemplateParams,
Metadata *Discriminator, Metadata *DataLocation,
Metadata *Associated, Metadata *Allocated, Metadata *Rank,
Metadata *Annotations);
Metadata *Annotations, Metadata *BitStride);

DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
DINodeArray getElements() const {
Expand Down Expand Up @@ -1477,6 +1480,14 @@ class DICompositeType : public DIType {
DIType *getSpecification() const {
return cast_or_null<DIType>(getRawSpecification());
}

Metadata *getRawBitStride() const { return getOperand(15); }
ConstantInt *getBitStrideConst() const {
if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawBitStride()))
return dyn_cast_or_null<ConstantInt>(MD->getValue());
return nullptr;
}

/// Replace operands.
///
/// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
Expand Down
8 changes: 5 additions & 3 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5613,7 +5613,8 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
OPTIONAL(rank, MDSignedOrMDField, ); \
OPTIONAL(annotations, MDField, ); \
OPTIONAL(num_extra_inhabitants, MDUnsignedField, (0, UINT32_MAX)); \
OPTIONAL(specification, MDField, );
OPTIONAL(specification, MDField, ); \
OPTIONAL(bitStride, MDField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS

Expand All @@ -5636,7 +5637,8 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
specification.Val, num_extra_inhabitants.Val, flags.Val,
elements.Val, runtimeLang.Val, EnumKind, vtableHolder.Val,
templateParams.Val, discriminator.Val, dataLocation.Val,
associated.Val, allocated.Val, Rank, annotations.Val)) {
associated.Val, allocated.Val, Rank, annotations.Val,
bitStride.Val)) {
Result = CT;
return false;
}
Expand All @@ -5650,7 +5652,7 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
runtimeLang.Val, EnumKind, vtableHolder.Val, templateParams.Val,
identifier.Val, discriminator.Val, dataLocation.Val, associated.Val,
allocated.Val, Rank, annotations.Val, specification.Val,
num_extra_inhabitants.Val));
num_extra_inhabitants.Val, bitStride.Val));
return false;
}

Expand Down
21 changes: 12 additions & 9 deletions llvm/lib/Bitcode/Reader/MetadataLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_COMPOSITE_TYPE: {
if (Record.size() < 16 || Record.size() > 25)
if (Record.size() < 16 || Record.size() > 26)
return error("Invalid record");

// If we have a UUID and this is not a forward declaration, lookup the
Expand Down Expand Up @@ -1651,6 +1651,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Metadata *Rank = nullptr;
Metadata *Annotations = nullptr;
Metadata *Specification = nullptr;
Metadata *BitStride = nullptr;
auto *Identifier = getMDString(Record[15]);
// If this module is being parsed so that it can be ThinLTO imported
// into another module, composite types only need to be imported as
Expand Down Expand Up @@ -1702,6 +1703,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (Record.size() > 23) {
Specification = getMDOrNull(Record[23]);
}
if (Record.size() > 25)
BitStride = getMDOrNull(Record[25]);
}

if (Record.size() > 24 && Record[24] != dwarf::DW_APPLE_ENUM_KIND_invalid)
Expand All @@ -1714,17 +1717,17 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
SizeInBits, AlignInBits, OffsetInBits, Specification,
NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind,
VTableHolder, TemplateParams, Discriminator, DataLocation, Associated,
Allocated, Rank, Annotations);
Allocated, Rank, Annotations, BitStride);

// Create a node if we didn't get a lazy ODR type.
if (!CT)
CT = GET_OR_DISTINCT(DICompositeType,
(Context, Tag, Name, File, Line, Scope, BaseType,
SizeInBits, AlignInBits, OffsetInBits, Flags,
Elements, RuntimeLang, EnumKind, VTableHolder,
TemplateParams, Identifier, Discriminator,
DataLocation, Associated, Allocated, Rank,
Annotations, Specification, NumExtraInhabitants));
CT = GET_OR_DISTINCT(
DICompositeType,
(Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, EnumKind,
VTableHolder, TemplateParams, Identifier, Discriminator,
DataLocation, Associated, Allocated, Rank, Annotations,
Specification, NumExtraInhabitants, BitStride));
if (!IsNotUsedInTypeRef && Identifier)
MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT));

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ void ModuleBitcodeWriter::writeDICompositeType(
Record.push_back(VE.getMetadataOrNullID(N->getRawSpecification()));
Record.push_back(
N->getEnumKind().value_or(dwarf::DW_APPLE_ENUM_KIND_invalid));
Record.push_back(VE.getMetadataOrNullID(N->getRawBitStride()));

Stream.EmitRecord(bitc::METADATA_COMPOSITE_TYPE, Record, Abbrev);
Record.clear();
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,10 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
addBlock(Buffer, dwarf::DW_AT_rank, DwarfExpr.finalize());
}

if (auto *BitStride = CTy->getBitStrideConst()) {
addUInt(Buffer, dwarf::DW_AT_bit_stride, {}, BitStride->getZExtValue());
}

// Emit the element type.
addType(Buffer, CTy->getBaseType());

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,7 @@ static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N,
Printer.printDwarfEnum("enumKind", *EnumKind, dwarf::EnumKindString,
/*ShouldSkipZero=*/false);

Printer.printMetadata("bitStride", N->getRawBitStride());
Out << ")";
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/IR/DIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ DICompositeType *DIBuilder::createArrayType(
PointerUnion<DIExpression *, DIVariable *> DL,
PointerUnion<DIExpression *, DIVariable *> AS,
PointerUnion<DIExpression *, DIVariable *> AL,
PointerUnion<DIExpression *, DIVariable *> RK) {
PointerUnion<DIExpression *, DIVariable *> RK, Metadata *BitStride) {
auto *R = DICompositeType::get(
VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
Expand All @@ -623,7 +623,8 @@ DICompositeType *DIBuilder::createArrayType(
isa<DIExpression *>(AL) ? (Metadata *)cast<DIExpression *>(AL)
: (Metadata *)cast<DIVariable *>(AL),
isa<DIExpression *>(RK) ? (Metadata *)cast<DIExpression *>(RK)
: (Metadata *)cast<DIVariable *>(RK));
: (Metadata *)cast<DIVariable *>(RK),
nullptr, nullptr, 0, BitStride);
trackIfUnresolved(R);
return R;
}
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/IR/DebugInfoMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ DICompositeType *DICompositeType::getImpl(
Metadata *VTableHolder, Metadata *TemplateParams, MDString *Identifier,
Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated,
Metadata *Allocated, Metadata *Rank, Metadata *Annotations,
Metadata *Specification, uint32_t NumExtraInhabitants, StorageType Storage,
bool ShouldCreate) {
Metadata *Specification, uint32_t NumExtraInhabitants, Metadata *BitStride,
StorageType Storage, bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString");

// Keep this in sync with buildODRType.
Expand All @@ -823,11 +823,11 @@ DICompositeType *DICompositeType::getImpl(
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator, DataLocation, Associated, Allocated, Rank,
Annotations, Specification, NumExtraInhabitants));
Annotations, Specification, NumExtraInhabitants, BitStride));
Metadata *Ops[] = {File, Scope, Name, BaseType,
Elements, VTableHolder, TemplateParams, Identifier,
Discriminator, DataLocation, Associated, Allocated,
Rank, Annotations, Specification};
Rank, Annotations, Specification, BitStride};
DEFINE_GETIMPL_STORE(DICompositeType,
(Tag, Line, RuntimeLang, SizeInBits, AlignInBits,
OffsetInBits, NumExtraInhabitants, EnumKind, Flags),
Expand All @@ -842,7 +842,7 @@ DICompositeType *DICompositeType::buildODRType(
Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
Metadata *Rank, Metadata *Annotations) {
Metadata *Rank, Metadata *Annotations, Metadata *BitStride) {
assert(!Identifier.getString().empty() && "Expected valid identifier");
if (!Context.isODRUniquingDebugTypes())
return nullptr;
Expand All @@ -853,7 +853,7 @@ DICompositeType *DICompositeType::buildODRType(
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
EnumKind, VTableHolder, TemplateParams, &Identifier,
Discriminator, DataLocation, Associated, Allocated, Rank,
Annotations, Specification, NumExtraInhabitants);
Annotations, Specification, NumExtraInhabitants, BitStride);
if (CT->getTag() != Tag)
return nullptr;

Expand All @@ -868,7 +868,7 @@ DICompositeType *DICompositeType::buildODRType(
Metadata *Ops[] = {File, Scope, Name, BaseType,
Elements, VTableHolder, TemplateParams, &Identifier,
Discriminator, DataLocation, Associated, Allocated,
Rank, Annotations, Specification};
Rank, Annotations, Specification, BitStride};
assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
"Mismatched number of operands");
for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
Expand All @@ -885,7 +885,7 @@ DICompositeType *DICompositeType::getODRType(
Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
Metadata *Rank, Metadata *Annotations) {
Metadata *Rank, Metadata *Annotations, Metadata *BitStride) {
assert(!Identifier.getString().empty() && "Expected valid identifier");
if (!Context.isODRUniquingDebugTypes())
return nullptr;
Expand All @@ -896,7 +896,7 @@ DICompositeType *DICompositeType::getODRType(
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, EnumKind,
VTableHolder, TemplateParams, &Identifier, Discriminator, DataLocation,
Associated, Allocated, Rank, Annotations, Specification,
NumExtraInhabitants);
NumExtraInhabitants, BitStride);
} else {
if (CT->getTag() != Tag)
return nullptr;
Expand Down
Loading