@@ -535,30 +535,31 @@ static Type parseImageType(SPIRVDialect const &dialect,
535
535
static ParseResult parseStructMemberDecorations (
536
536
SPIRVDialect const &dialect, DialectAsmParser &parser,
537
537
ArrayRef<Type> memberTypes,
538
- SmallVectorImpl<StructType::LayoutInfo > &layoutInfo ,
538
+ SmallVectorImpl<StructType::OffsetInfo > &offsetInfo ,
539
539
SmallVectorImpl<StructType::MemberDecorationInfo> &memberDecorationInfo) {
540
540
541
541
// Check if the first element is offset.
542
- llvm::SMLoc layoutLoc = parser.getCurrentLocation ();
543
- StructType::LayoutInfo layout = 0 ;
544
- OptionalParseResult layoutParseResult = parser.parseOptionalInteger (layout );
545
- if (layoutParseResult .hasValue ()) {
546
- if (failed (*layoutParseResult ))
542
+ llvm::SMLoc offsetLoc = parser.getCurrentLocation ();
543
+ StructType::OffsetInfo offset = 0 ;
544
+ OptionalParseResult offsetParseResult = parser.parseOptionalInteger (offset );
545
+ if (offsetParseResult .hasValue ()) {
546
+ if (failed (*offsetParseResult ))
547
547
return failure ();
548
548
549
- if (layoutInfo.size () != memberTypes.size () - 1 ) {
550
- return parser.emitError (
551
- layoutLoc, " layout specification must be given for all members" );
549
+ if (offsetInfo.size () != memberTypes.size () - 1 ) {
550
+ return parser.emitError (offsetLoc,
551
+ " offset specification must be given for "
552
+ " all members" );
552
553
}
553
- layoutInfo .push_back (layout );
554
+ offsetInfo .push_back (offset );
554
555
}
555
556
556
557
// Check for no spirv::Decorations.
557
558
if (succeeded (parser.parseOptionalRSquare ()))
558
559
return success ();
559
560
560
- // If there was a layout , make sure to parse the comma.
561
- if (layoutParseResult .hasValue () && parser.parseComma ())
561
+ // If there was an offset , make sure to parse the comma.
562
+ if (offsetParseResult .hasValue () && parser.parseComma ())
562
563
return failure ();
563
564
564
565
// Check for spirv::Decorations.
@@ -567,9 +568,23 @@ static ParseResult parseStructMemberDecorations(
567
568
if (!memberDecoration)
568
569
return failure ();
569
570
570
- memberDecorationInfo.emplace_back (
571
- static_cast <uint32_t >(memberTypes.size () - 1 ),
572
- memberDecoration.getValue ());
571
+ // Parse member decoration value if it exists.
572
+ if (succeeded (parser.parseOptionalEqual ())) {
573
+ auto memberDecorationValue =
574
+ parseAndVerifyInteger<uint32_t >(dialect, parser);
575
+
576
+ if (!memberDecorationValue)
577
+ return failure ();
578
+
579
+ memberDecorationInfo.emplace_back (
580
+ static_cast <uint32_t >(memberTypes.size () - 1 ), 1 ,
581
+ memberDecoration.getValue (), memberDecorationValue.getValue ());
582
+ } else {
583
+ memberDecorationInfo.emplace_back (
584
+ static_cast <uint32_t >(memberTypes.size () - 1 ), 0 ,
585
+ memberDecoration.getValue (), 0 );
586
+ }
587
+
573
588
} while (succeeded (parser.parseOptionalComma ()));
574
589
575
590
return parser.parseRSquare ();
@@ -587,7 +602,7 @@ static Type parseStructType(SPIRVDialect const &dialect,
587
602
return StructType::getEmpty (dialect.getContext ());
588
603
589
604
SmallVector<Type, 4 > memberTypes;
590
- SmallVector<StructType::LayoutInfo , 4 > layoutInfo ;
605
+ SmallVector<StructType::OffsetInfo , 4 > offsetInfo ;
591
606
SmallVector<StructType::MemberDecorationInfo, 4 > memberDecorationInfo;
592
607
593
608
do {
@@ -597,21 +612,21 @@ static Type parseStructType(SPIRVDialect const &dialect,
597
612
memberTypes.push_back (memberType);
598
613
599
614
if (succeeded (parser.parseOptionalLSquare ())) {
600
- if (parseStructMemberDecorations (dialect, parser, memberTypes, layoutInfo ,
615
+ if (parseStructMemberDecorations (dialect, parser, memberTypes, offsetInfo ,
601
616
memberDecorationInfo)) {
602
617
return Type ();
603
618
}
604
619
}
605
620
} while (succeeded (parser.parseOptionalComma ()));
606
621
607
- if (!layoutInfo .empty () && memberTypes.size () != layoutInfo .size ()) {
622
+ if (!offsetInfo .empty () && memberTypes.size () != offsetInfo .size ()) {
608
623
parser.emitError (parser.getNameLoc (),
609
- " layout specification must be given for all members" );
624
+ " offset specification must be given for all members" );
610
625
return Type ();
611
626
}
612
627
if (parser.parseGreater ())
613
628
return Type ();
614
- return StructType::get (memberTypes, layoutInfo , memberDecorationInfo);
629
+ return StructType::get (memberTypes, offsetInfo , memberDecorationInfo);
615
630
}
616
631
617
632
// spirv-type ::= array-type
@@ -679,17 +694,20 @@ static void print(StructType type, DialectAsmPrinter &os) {
679
694
os << " struct<" ;
680
695
auto printMember = [&](unsigned i) {
681
696
os << type.getElementType (i);
682
- SmallVector<spirv::Decoration , 0 > decorations;
697
+ SmallVector<spirv::StructType::MemberDecorationInfo , 0 > decorations;
683
698
type.getMemberDecorations (i, decorations);
684
- if (type.hasLayout () || !decorations.empty ()) {
699
+ if (type.hasOffset () || !decorations.empty ()) {
685
700
os << " [" ;
686
- if (type.hasLayout ()) {
687
- os << type.getOffset (i);
701
+ if (type.hasOffset ()) {
702
+ os << type.getMemberOffset (i);
688
703
if (!decorations.empty ())
689
704
os << " , " ;
690
705
}
691
- auto eachFn = [&os](spirv::Decoration decoration) {
692
- os << stringifyDecoration (decoration);
706
+ auto eachFn = [&os](spirv::StructType::MemberDecorationInfo decoration) {
707
+ os << stringifyDecoration (decoration.decoration );
708
+ if (decoration.hasValue ) {
709
+ os << " =" << decoration.decorationValue ;
710
+ }
693
711
};
694
712
llvm::interleaveComma (decorations, os, eachFn);
695
713
os << " ]" ;
0 commit comments