@@ -668,53 +668,60 @@ Type LLVM::GEPOp::getSourceElementType() {
668
668
// Builder, printer and parser for for LLVM::LoadOp.
669
669
// ===----------------------------------------------------------------------===//
670
670
671
- LogicalResult verifySymbolAttribute (
672
- Operation *op, StringRef attributeName,
671
+ // / Verifies the given array attribute contains symbol references and checks the
672
+ // / referenced symbol types using the provided verification function.
673
+ LogicalResult verifyMemOpSymbolRefs (
674
+ Operation *op, StringRef name, ArrayAttr symbolRefs,
673
675
llvm::function_ref<LogicalResult(Operation *, SymbolRefAttr)>
674
676
verifySymbolType) {
675
- if (Attribute attribute = op->getAttr (attributeName)) {
676
- // Verify that the attribute is a symbol ref array attribute,
677
- // because this constraint is not verified for all attribute
678
- // names processed here (e.g. 'tbaa'). This verification
679
- // is redundant in some cases.
680
- if (!(attribute.isa <ArrayAttr>() &&
681
- llvm::all_of (attribute.cast <ArrayAttr>(), [&](Attribute attr) {
682
- return attr && attr.isa <SymbolRefAttr>();
683
- })))
684
- return op->emitOpError (" attribute '" )
685
- << attributeName
686
- << " ' failed to satisfy constraint: symbol ref array attribute" ;
687
-
688
- for (SymbolRefAttr symbolRef :
689
- attribute.cast <ArrayAttr>().getAsRange <SymbolRefAttr>()) {
690
- StringAttr metadataName = symbolRef.getRootReference ();
691
- StringAttr symbolName = symbolRef.getLeafReference ();
692
- // We want @metadata::@symbol, not just @symbol
693
- if (metadataName == symbolName) {
694
- return op->emitOpError () << " expected '" << symbolRef
695
- << " ' to specify a fully qualified reference" ;
696
- }
697
- auto metadataOp = SymbolTable::lookupNearestSymbolFrom<LLVM::MetadataOp>(
698
- op->getParentOp (), metadataName);
699
- if (!metadataOp)
700
- return op->emitOpError ()
701
- << " expected '" << symbolRef << " ' to reference a metadata op" ;
702
- Operation *symbolOp =
703
- SymbolTable::lookupNearestSymbolFrom (metadataOp, symbolName);
704
- if (!symbolOp)
705
- return op->emitOpError ()
706
- << " expected '" << symbolRef << " ' to be a valid reference" ;
707
- if (failed (verifySymbolType (symbolOp, symbolRef))) {
708
- return failure ();
709
- }
677
+ assert (symbolRefs && " expected a non-null attribute" );
678
+
679
+ // Verify that the attribute is a symbol ref array attribute,
680
+ // because this constraint is not verified for all attribute
681
+ // names processed here (e.g. 'tbaa'). This verification
682
+ // is redundant in some cases.
683
+ if (!llvm::all_of (symbolRefs, [](Attribute attr) {
684
+ return attr && attr.isa <SymbolRefAttr>();
685
+ }))
686
+ return op->emitOpError (" attribute '" )
687
+ << name
688
+ << " ' failed to satisfy constraint: symbol ref array attribute" ;
689
+
690
+ for (SymbolRefAttr symbolRef : symbolRefs.getAsRange <SymbolRefAttr>()) {
691
+ StringAttr metadataName = symbolRef.getRootReference ();
692
+ StringAttr symbolName = symbolRef.getLeafReference ();
693
+ // We want @metadata::@symbol, not just @symbol
694
+ if (metadataName == symbolName) {
695
+ return op->emitOpError () << " expected '" << symbolRef
696
+ << " ' to specify a fully qualified reference" ;
697
+ }
698
+ auto metadataOp = SymbolTable::lookupNearestSymbolFrom<LLVM::MetadataOp>(
699
+ op->getParentOp (), metadataName);
700
+ if (!metadataOp)
701
+ return op->emitOpError ()
702
+ << " expected '" << symbolRef << " ' to reference a metadata op" ;
703
+ Operation *symbolOp =
704
+ SymbolTable::lookupNearestSymbolFrom (metadataOp, symbolName);
705
+ if (!symbolOp)
706
+ return op->emitOpError ()
707
+ << " expected '" << symbolRef << " ' to be a valid reference" ;
708
+ if (failed (verifySymbolType (symbolOp, symbolRef))) {
709
+ return failure ();
710
710
}
711
711
}
712
+
712
713
return success ();
713
714
}
714
715
715
- // Verifies that metadata ops are wired up properly.
716
+ // / Verifies the given array attribute contains symbol references that point to
717
+ // / metadata operations of the given type.
716
718
template <typename OpTy>
717
- static LogicalResult verifyOpMetadata (Operation *op, StringRef attributeName) {
719
+ static LogicalResult
720
+ verifyMemOpSymbolRefsPointTo (Operation *op, StringRef name,
721
+ std::optional<ArrayAttr> symbolRefs) {
722
+ if (!symbolRefs)
723
+ return success ();
724
+
718
725
auto verifySymbolType = [op](Operation *symbolOp,
719
726
SymbolRefAttr symbolRef) -> LogicalResult {
720
727
if (!isa<OpTy>(symbolOp)) {
@@ -724,35 +731,33 @@ static LogicalResult verifyOpMetadata(Operation *op, StringRef attributeName) {
724
731
}
725
732
return success ();
726
733
};
727
-
728
- return verifySymbolAttribute (op, attributeName, verifySymbolType);
734
+ return verifyMemOpSymbolRefs (op, name, *symbolRefs, verifySymbolType);
729
735
}
730
736
731
- static LogicalResult verifyMemoryOpMetadata (Operation *op) {
732
- // access_groups
733
- if (failed (verifyOpMetadata<LLVM::AccessGroupMetadataOp>(
734
- op, LLVMDialect::getAccessGroupsAttrName ())))
737
+ // / Verifies the types of the metadata operations referenced by aliasing and
738
+ // / access group metadata.
739
+ template <typename OpTy>
740
+ LogicalResult verifyMemOpMetadata (OpTy memOp) {
741
+ if (failed (verifyMemOpSymbolRefsPointTo<LLVM::AccessGroupMetadataOp>(
742
+ memOp, memOp.getAccessGroupsAttrName (), memOp.getAccessGroups ())))
735
743
return failure ();
736
744
737
- // alias_scopes
738
- if (failed (verifyOpMetadata<LLVM::AliasScopeMetadataOp>(
739
- op, LLVMDialect::getAliasScopesAttrName ())))
745
+ if (failed (verifyMemOpSymbolRefsPointTo<LLVM::AliasScopeMetadataOp>(
746
+ memOp, memOp.getAliasScopesAttrName (), memOp.getAliasScopes ())))
740
747
return failure ();
741
748
742
- // noalias_scopes
743
- if (failed (verifyOpMetadata<LLVM::AliasScopeMetadataOp>(
744
- op, LLVMDialect::getNoAliasScopesAttrName ())))
749
+ if (failed (verifyMemOpSymbolRefsPointTo<LLVM::AliasScopeMetadataOp>(
750
+ memOp, memOp.getNoaliasScopesAttrName (), memOp.getNoaliasScopes ())))
745
751
return failure ();
746
752
747
- // tbaa
748
- if (failed (verifyOpMetadata<LLVM::TBAATagOp>(op,
749
- LLVMDialect::getTBAAAttrName ())))
753
+ if (failed (verifyMemOpSymbolRefsPointTo<LLVM::TBAATagOp>(
754
+ memOp, memOp.getTbaaAttrName (), memOp.getTbaa ())))
750
755
return failure ();
751
756
752
757
return success ();
753
758
}
754
759
755
- LogicalResult LoadOp::verify () { return verifyMemoryOpMetadata (*this ); }
760
+ LogicalResult LoadOp::verify () { return verifyMemOpMetadata (*this ); }
756
761
757
762
void LoadOp::build (OpBuilder &builder, OperationState &result, Type t,
758
763
Value addr, unsigned alignment, bool isVolatile,
@@ -828,7 +833,7 @@ ParseResult LoadOp::parse(OpAsmParser &parser, OperationState &result) {
828
833
// Builder, printer and parser for LLVM::StoreOp.
829
834
// ===----------------------------------------------------------------------===//
830
835
831
- LogicalResult StoreOp::verify () { return verifyMemoryOpMetadata (*this ); }
836
+ LogicalResult StoreOp::verify () { return verifyMemOpMetadata (*this ); }
832
837
833
838
void StoreOp::build (OpBuilder &builder, OperationState &result, Value value,
834
839
Value addr, unsigned alignment, bool isVolatile,
0 commit comments