@@ -476,6 +476,64 @@ struct EnzymeFunctionLikeAttrInfo : public ParsedAttrInfo {
476476static ParsedAttrInfoRegistry::Add<EnzymeFunctionLikeAttrInfo>
477477 X4 (" enzyme_function_like" , " " );
478478
479+ struct TesseraOpAttrInfo : public ParsedAttrInfo {
480+ TesseraOpAttrInfo () {
481+ OptArgs = 1 ;
482+ // GNU-style __attribute__(("example")) and C++/C2x-style [[example]] and
483+ // [[plugin::example]] supported.
484+ static constexpr Spelling S[] = {
485+ {ParsedAttr::AS_GNU, " tessera_op" },
486+ #if LLVM_VERSION_MAJOR > 17
487+ {ParsedAttr::AS_C23, " tessera_op" },
488+ #else
489+ {ParsedAttr::AS_C2x, " tessera_op" },
490+ #endif
491+ {ParsedAttr::AS_CXX11, " tessera_op" },
492+ {ParsedAttr::AS_CXX11, " tessera::op" }
493+ };
494+ Spellings = S;
495+ }
496+
497+ bool diagAppertainsToDecl (Sema &S, const ParsedAttr &Attr,
498+ const Decl *D) const override {
499+ // This attribute appertains to functions only.
500+ if (!isa<FunctionDecl>(D)) {
501+ S.Diag (Attr.getLoc (), diag::warn_attribute_wrong_decl_type_str)
502+ << Attr << " functions" ;
503+ return false ;
504+ }
505+ return true ;
506+ }
507+
508+ AttrHandling handleDeclAttribute (Sema &S, Decl *D,
509+ const ParsedAttr &Attr) const override {
510+ if (Attr.getNumArgs () != 1 ) {
511+ unsigned ID = S.getDiagnostics ().getCustomDiagID (
512+ DiagnosticsEngine::Error,
513+ " 'tessera_op' attribute requires a single string argument" );
514+ S.Diag (Attr.getLoc (), ID);
515+ return AttributeNotApplied;
516+ }
517+ auto *Arg0 = Attr.getArgAsExpr (0 );
518+ StringLiteral *Literal = dyn_cast<StringLiteral>(Arg0->IgnoreParenCasts ());
519+ if (!Literal) {
520+ unsigned ID = S.getDiagnostics ().getCustomDiagID (
521+ DiagnosticsEngine::Error, " first argument to 'tessera_op' "
522+ " attribute must be a string literal" );
523+ S.Diag (Attr.getLoc (), ID);
524+ return AttributeNotApplied;
525+ }
526+
527+ D->addAttr (AnnotateAttr::Create (
528+ S.Context , (" tessera_op=" + Literal->getString ()).str (),
529+ nullptr , 0 , Attr.getRange ()));
530+ return AttributeApplied;
531+ }
532+ };
533+
534+ static ParsedAttrInfoRegistry::Add<TesseraOpAttrInfo>
535+ T1 (" tessera_op" , " " );
536+
479537struct EnzymeShouldRecomputeAttrInfo : public ParsedAttrInfo {
480538 EnzymeShouldRecomputeAttrInfo () {
481539 OptArgs = 1 ;
0 commit comments