Skip to content

Commit 8f40ade

Browse files
committed
Merge commit 'f89129af8adf' from llvm.org/main into next
Conflicts: llvm/lib/Bitcode/Reader/MetadataLoader.cpp rdar://147885176
2 parents fa694ad + f89129a commit 8f40ade

File tree

14 files changed

+146
-63
lines changed

14 files changed

+146
-63
lines changed

llvm/docs/LangRef.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6336,7 +6336,10 @@ array is currently associated. The optional ``allocated`` is a
63366336
DIExpression that describes whether the allocatable array is currently
63376337
allocated. The optional ``rank`` is a DIExpression that describes the
63386338
rank (number of dimensions) of fortran assumed rank array (rank is
6339-
known at runtime).
6339+
known at runtime). The optional ``bitStride`` is an unsigned constant
6340+
that describes the number of bits occupied by an element of the array;
6341+
this is only needed if it differs from the element type's natural
6342+
size, and is normally used for packed arrays.
63406343

63416344
For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
63426345
descriptors <DIEnumerator>`, each representing the definition of an enumeration

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,15 @@ namespace llvm {
608608
/// \param Rank The rank attribute of a descriptor-based
609609
/// Fortran array, either a DIExpression* or
610610
/// a DIVariable*.
611+
/// \param BitStride The bit size of an element of the array.
611612
DICompositeType *createArrayType(
612613
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
613614
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
614615
PointerUnion<DIExpression *, DIVariable *> DataLocation = nullptr,
615616
PointerUnion<DIExpression *, DIVariable *> Associated = nullptr,
616617
PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
617-
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
618+
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr,
619+
Metadata *BitStride = nullptr);
618620

619621
/// Create debugging information entry for a vector type.
620622
/// \param Size Array size.

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,15 +1306,15 @@ class DICompositeType : public DIType {
13061306
DIType *VTableHolder, DITemplateParameterArray TemplateParams,
13071307
StringRef Identifier, DIDerivedType *Discriminator,
13081308
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
1309-
Metadata *Rank, DINodeArray Annotations, StorageType Storage,
1310-
bool ShouldCreate = true) {
1311-
return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
1312-
Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
1313-
Flags, Elements.get(), RuntimeLang, EnumKind, VTableHolder,
1314-
TemplateParams.get(),
1315-
getCanonicalMDString(Context, Identifier), Discriminator,
1316-
DataLocation, Associated, Allocated, Rank, Annotations.get(),
1317-
Specification, NumExtraInhabitants, Storage, ShouldCreate);
1309+
Metadata *Rank, DINodeArray Annotations, Metadata *BitStride,
1310+
StorageType Storage, bool ShouldCreate = true) {
1311+
return getImpl(
1312+
Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
1313+
BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
1314+
RuntimeLang, EnumKind, VTableHolder, TemplateParams.get(),
1315+
getCanonicalMDString(Context, Identifier), Discriminator, DataLocation,
1316+
Associated, Allocated, Rank, Annotations.get(), Specification,
1317+
NumExtraInhabitants, BitStride, Storage, ShouldCreate);
13181318
}
13191319
static DICompositeType *
13201320
getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
@@ -1326,7 +1326,7 @@ class DICompositeType : public DIType {
13261326
Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated,
13271327
Metadata *Allocated, Metadata *Rank, Metadata *Annotations,
13281328
Metadata *Specification, uint32_t NumExtraInhabitants,
1329-
StorageType Storage, bool ShouldCreate = true);
1329+
Metadata *BitStride, StorageType Storage, bool ShouldCreate = true);
13301330

13311331
TempDICompositeType cloneImpl() const {
13321332
return getTemporary(
@@ -1336,7 +1336,7 @@ class DICompositeType : public DIType {
13361336
getVTableHolder(), getTemplateParams(), getIdentifier(),
13371337
getDiscriminator(), getRawDataLocation(), getRawAssociated(),
13381338
getRawAllocated(), getRawRank(), getAnnotations(), getSpecification(),
1339-
getNumExtraInhabitants());
1339+
getNumExtraInhabitants(), getRawBitStride());
13401340
}
13411341

13421342
public:
@@ -1352,11 +1352,12 @@ class DICompositeType : public DIType {
13521352
Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
13531353
Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
13541354
DINodeArray Annotations = nullptr, DIType *Specification = nullptr,
1355-
uint32_t NumExtraInhabitants = 0),
1355+
uint32_t NumExtraInhabitants = 0, Metadata *BitStride = nullptr),
13561356
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
13571357
OffsetInBits, Specification, NumExtraInhabitants, Flags, Elements,
13581358
RuntimeLang, EnumKind, VTableHolder, TemplateParams, Identifier,
1359-
Discriminator, DataLocation, Associated, Allocated, Rank, Annotations))
1359+
Discriminator, DataLocation, Associated, Allocated, Rank, Annotations,
1360+
BitStride))
13601361
DEFINE_MDNODE_GET(
13611362
DICompositeType,
13621363
(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
@@ -1368,11 +1369,13 @@ class DICompositeType : public DIType {
13681369
Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
13691370
Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
13701371
Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
1371-
Metadata *Specification = nullptr, uint32_t NumExtraInhabitants = 0),
1372+
Metadata *Specification = nullptr, uint32_t NumExtraInhabitants = 0,
1373+
Metadata *BitStride = nullptr),
13721374
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
13731375
OffsetInBits, Flags, Elements, RuntimeLang, EnumKind, VTableHolder,
13741376
TemplateParams, Identifier, Discriminator, DataLocation, Associated,
1375-
Allocated, Rank, Annotations, Specification, NumExtraInhabitants))
1377+
Allocated, Rank, Annotations, Specification, NumExtraInhabitants,
1378+
BitStride))
13761379

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

@@ -1393,7 +1396,7 @@ class DICompositeType : public DIType {
13931396
Metadata *VTableHolder, Metadata *TemplateParams,
13941397
Metadata *Discriminator, Metadata *DataLocation,
13951398
Metadata *Associated, Metadata *Allocated, Metadata *Rank,
1396-
Metadata *Annotations);
1399+
Metadata *Annotations, Metadata *BitStride);
13971400
static DICompositeType *getODRTypeIfExists(LLVMContext &Context,
13981401
MDString &Identifier);
13991402

@@ -1416,7 +1419,7 @@ class DICompositeType : public DIType {
14161419
Metadata *VTableHolder, Metadata *TemplateParams,
14171420
Metadata *Discriminator, Metadata *DataLocation,
14181421
Metadata *Associated, Metadata *Allocated, Metadata *Rank,
1419-
Metadata *Annotations);
1422+
Metadata *Annotations, Metadata *BitStride);
14201423

14211424
DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
14221425
DINodeArray getElements() const {
@@ -1481,6 +1484,14 @@ class DICompositeType : public DIType {
14811484
DIType *getSpecification() const {
14821485
return cast_or_null<DIType>(getRawSpecification());
14831486
}
1487+
1488+
Metadata *getRawBitStride() const { return getOperand(15); }
1489+
ConstantInt *getBitStrideConst() const {
1490+
if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawBitStride()))
1491+
return dyn_cast_or_null<ConstantInt>(MD->getValue());
1492+
return nullptr;
1493+
}
1494+
14841495
/// Replace operands.
14851496
///
14861497
/// If this \a isUniqued() and not \a isResolved(), on a uniquing collision

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5617,7 +5617,8 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
56175617
OPTIONAL(rank, MDSignedOrMDField, ); \
56185618
OPTIONAL(annotations, MDField, ); \
56195619
OPTIONAL(num_extra_inhabitants, MDUnsignedField, (0, UINT32_MAX)); \
5620-
OPTIONAL(specification, MDField, );
5620+
OPTIONAL(specification, MDField, ); \
5621+
OPTIONAL(bitStride, MDField, );
56215622
PARSE_MD_FIELDS();
56225623
#undef VISIT_MD_FIELDS
56235624

@@ -5640,7 +5641,8 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
56405641
specification.Val, num_extra_inhabitants.Val, flags.Val,
56415642
elements.Val, runtimeLang.Val, EnumKind, vtableHolder.Val,
56425643
templateParams.Val, discriminator.Val, dataLocation.Val,
5643-
associated.Val, allocated.Val, Rank, annotations.Val)) {
5644+
associated.Val, allocated.Val, Rank, annotations.Val,
5645+
bitStride.Val)) {
56445646
Result = CT;
56455647
return false;
56465648
}
@@ -5654,7 +5656,7 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
56545656
runtimeLang.Val, EnumKind, vtableHolder.Val, templateParams.Val,
56555657
identifier.Val, discriminator.Val, dataLocation.Val, associated.Val,
56565658
allocated.Val, Rank, annotations.Val, specification.Val,
5657-
num_extra_inhabitants.Val));
5659+
num_extra_inhabitants.Val, bitStride.Val));
56585660
return false;
56595661
}
56605662

llvm/lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
16181618
break;
16191619
}
16201620
case bitc::METADATA_COMPOSITE_TYPE: {
1621-
if (Record.size() < 16)
1621+
if (Record.size() < 16 || Record.size() > 26)
16221622
return error("Invalid record");
16231623

16241624
IsDistinct = Record[0] & 1;
@@ -1652,6 +1652,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
16521652
Metadata *Rank = nullptr;
16531653
Metadata *Annotations = nullptr;
16541654
Metadata *Specification = nullptr;
1655+
Metadata *BitStride = nullptr;
16551656
auto *Identifier = getMDString(Record[15]);
16561657
// If this module is being parsed so that it can be ThinLTO imported
16571658
// into another module, composite types only need to be imported as
@@ -1703,6 +1704,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
17031704
if (Record.size() > 23) {
17041705
Specification = getMDOrNull(Record[23]);
17051706
}
1707+
if (Record.size() > 25)
1708+
BitStride = getMDOrNull(Record[25]);
17061709
}
17071710

17081711
if (Record.size() > 24 && Record[24] != dwarf::DW_APPLE_ENUM_KIND_invalid)
@@ -1715,17 +1718,17 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
17151718
SizeInBits, AlignInBits, OffsetInBits, Specification,
17161719
NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind,
17171720
VTableHolder, TemplateParams, Discriminator, DataLocation, Associated,
1718-
Allocated, Rank, Annotations);
1721+
Allocated, Rank, Annotations, BitStride);
17191722

17201723
// Create a node if we didn't get a lazy ODR type.
17211724
if (!CT)
1722-
CT = GET_OR_DISTINCT(DICompositeType,
1723-
(Context, Tag, Name, File, Line, Scope, BaseType,
1724-
SizeInBits, AlignInBits, OffsetInBits, Flags,
1725-
Elements, RuntimeLang, EnumKind, VTableHolder,
1726-
TemplateParams, Identifier, Discriminator,
1727-
DataLocation, Associated, Allocated, Rank,
1728-
Annotations, Specification, NumExtraInhabitants));
1725+
CT = GET_OR_DISTINCT(
1726+
DICompositeType,
1727+
(Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1728+
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, EnumKind,
1729+
VTableHolder, TemplateParams, Identifier, Discriminator,
1730+
DataLocation, Associated, Allocated, Rank, Annotations,
1731+
Specification, NumExtraInhabitants, BitStride));
17291732
if (!IsNotUsedInTypeRef && Identifier)
17301733
MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT));
17311734

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,7 @@ void ModuleBitcodeWriter::writeDICompositeType(
19911991
Record.push_back(VE.getMetadataOrNullID(N->getRawSpecification()));
19921992
Record.push_back(
19931993
N->getEnumKind().value_or(dwarf::DW_APPLE_ENUM_KIND_invalid));
1994+
Record.push_back(VE.getMetadataOrNullID(N->getRawBitStride()));
19941995

19951996
Stream.EmitRecord(bitc::METADATA_COMPOSITE_TYPE, Record, Abbrev);
19961997
Record.clear();

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,10 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
16671667
addBlock(Buffer, dwarf::DW_AT_rank, DwarfExpr.finalize());
16681668
}
16691669

1670+
if (auto *BitStride = CTy->getBitStrideConst()) {
1671+
addUInt(Buffer, dwarf::DW_AT_bit_stride, {}, BitStride->getZExtValue());
1672+
}
1673+
16701674
// Emit the element type.
16711675
addType(Buffer, CTy->getBaseType());
16721676

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,7 @@ static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N,
23082308
Printer.printDwarfEnum("enumKind", *EnumKind, dwarf::EnumKindString,
23092309
/*ShouldSkipZero=*/false);
23102310

2311+
Printer.printMetadata("bitStride", N->getRawBitStride());
23112312
Out << ")";
23122313
}
23132314

llvm/lib/IR/DIBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ DICompositeType *DIBuilder::createArrayType(
611611
PointerUnion<DIExpression *, DIVariable *> DL,
612612
PointerUnion<DIExpression *, DIVariable *> AS,
613613
PointerUnion<DIExpression *, DIVariable *> AL,
614-
PointerUnion<DIExpression *, DIVariable *> RK) {
614+
PointerUnion<DIExpression *, DIVariable *> RK, Metadata *BitStride) {
615615
auto *R = DICompositeType::get(
616616
VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
617617
getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
@@ -623,7 +623,8 @@ DICompositeType *DIBuilder::createArrayType(
623623
isa<DIExpression *>(AL) ? (Metadata *)cast<DIExpression *>(AL)
624624
: (Metadata *)cast<DIVariable *>(AL),
625625
isa<DIExpression *>(RK) ? (Metadata *)cast<DIExpression *>(RK)
626-
: (Metadata *)cast<DIVariable *>(RK));
626+
: (Metadata *)cast<DIVariable *>(RK),
627+
nullptr, nullptr, 0, BitStride);
627628
trackIfUnresolved(R);
628629
return R;
629630
}

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ DICompositeType *DICompositeType::getImpl(
813813
Metadata *VTableHolder, Metadata *TemplateParams, MDString *Identifier,
814814
Metadata *Discriminator, Metadata *DataLocation, Metadata *Associated,
815815
Metadata *Allocated, Metadata *Rank, Metadata *Annotations,
816-
Metadata *Specification, uint32_t NumExtraInhabitants, StorageType Storage,
817-
bool ShouldCreate) {
816+
Metadata *Specification, uint32_t NumExtraInhabitants, Metadata *BitStride,
817+
StorageType Storage, bool ShouldCreate) {
818818
assert(isCanonical(Name) && "Expected canonical MDString");
819819

820820
// Keep this in sync with buildODRType.
@@ -823,11 +823,11 @@ DICompositeType *DICompositeType::getImpl(
823823
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
824824
OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
825825
Identifier, Discriminator, DataLocation, Associated, Allocated, Rank,
826-
Annotations, Specification, NumExtraInhabitants));
826+
Annotations, Specification, NumExtraInhabitants, BitStride));
827827
Metadata *Ops[] = {File, Scope, Name, BaseType,
828828
Elements, VTableHolder, TemplateParams, Identifier,
829829
Discriminator, DataLocation, Associated, Allocated,
830-
Rank, Annotations, Specification};
830+
Rank, Annotations, Specification, BitStride};
831831
DEFINE_GETIMPL_STORE(DICompositeType,
832832
(Tag, Line, RuntimeLang, SizeInBits, AlignInBits,
833833
OffsetInBits, NumExtraInhabitants, EnumKind, Flags),
@@ -842,7 +842,7 @@ DICompositeType *DICompositeType::buildODRType(
842842
Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
843843
Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
844844
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
845-
Metadata *Rank, Metadata *Annotations) {
845+
Metadata *Rank, Metadata *Annotations, Metadata *BitStride) {
846846
assert(!Identifier.getString().empty() && "Expected valid identifier");
847847
if (!Context.isODRUniquingDebugTypes())
848848
return nullptr;
@@ -853,7 +853,7 @@ DICompositeType *DICompositeType::buildODRType(
853853
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
854854
EnumKind, VTableHolder, TemplateParams, &Identifier,
855855
Discriminator, DataLocation, Associated, Allocated, Rank,
856-
Annotations, Specification, NumExtraInhabitants);
856+
Annotations, Specification, NumExtraInhabitants, BitStride);
857857
if (CT->getTag() != Tag)
858858
return nullptr;
859859

@@ -868,7 +868,7 @@ DICompositeType *DICompositeType::buildODRType(
868868
Metadata *Ops[] = {File, Scope, Name, BaseType,
869869
Elements, VTableHolder, TemplateParams, &Identifier,
870870
Discriminator, DataLocation, Associated, Allocated,
871-
Rank, Annotations, Specification};
871+
Rank, Annotations, Specification, BitStride};
872872
assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
873873
"Mismatched number of operands");
874874
for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
@@ -885,7 +885,7 @@ DICompositeType *DICompositeType::getODRType(
885885
Metadata *Elements, unsigned RuntimeLang, std::optional<uint32_t> EnumKind,
886886
Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
887887
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
888-
Metadata *Rank, Metadata *Annotations) {
888+
Metadata *Rank, Metadata *Annotations, Metadata *BitStride) {
889889
assert(!Identifier.getString().empty() && "Expected valid identifier");
890890
if (!Context.isODRUniquingDebugTypes())
891891
return nullptr;
@@ -896,7 +896,7 @@ DICompositeType *DICompositeType::getODRType(
896896
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, EnumKind,
897897
VTableHolder, TemplateParams, &Identifier, Discriminator, DataLocation,
898898
Associated, Allocated, Rank, Annotations, Specification,
899-
NumExtraInhabitants);
899+
NumExtraInhabitants, BitStride);
900900
} else {
901901
if (CT->getTag() != Tag)
902902
return nullptr;

0 commit comments

Comments
 (0)