Paul-C-Anagnostopoulos created this revision. Paul-C-Anagnostopoulos added reviewers: lattner, nhaehnle, rengolin, asl. Herald added subscribers: llvm-commits, cfe-commits, dexonsmith, dmgreen, hiraditya, kristof.beyls. Herald added projects: clang, LLVM. Paul-C-Anagnostopoulos requested review of this revision.
In order to make the bang operators related to DAGs consistent, I'm adding 'dag' to the names that don't already include it. This will help with overall consistency when the new DAG operators are added over the next few weeks. I updated the test, along with uses of the two operators in clang/Basic/arm_mve.td and Target/ARM/ARMInstrMVE.td Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D89814 Files: clang/include/clang/Basic/arm_mve.td llvm/docs/TableGen/ProgRef.rst llvm/include/llvm/TableGen/Record.h llvm/lib/TableGen/Record.cpp llvm/lib/TableGen/TGLexer.cpp llvm/lib/TableGen/TGLexer.h llvm/lib/TableGen/TGParser.cpp llvm/lib/Target/ARM/ARMInstrMVE.td llvm/test/TableGen/getsetop.td
Index: llvm/test/TableGen/getsetop.td =================================================================== --- llvm/test/TableGen/getsetop.td +++ llvm/test/TableGen/getsetop.td @@ -3,6 +3,9 @@ // RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s // RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s +// !setop and !getop are deprecated in favor of !setdagop and !getdagop. +// Two tests retain the old names just to be sure they are still supported. + class Base; class OtherBase; @@ -18,28 +21,28 @@ dag replaceWithBar = !setop(orig, bar); // CHECK: dag replaceWithBaz = (qux 1, 2:$a, ?:$b); - dag replaceWithBaz = !setop(orig, qux); + dag replaceWithBaz = !setdagop(orig, qux); // CHECK: Base getopWithCast = foo; Base getopWithCast = !getop<Base>(orig); // CHECK: dag getopToSetop = (foo "hello", ?:$world); - dag getopToSetop = !setop(another, !getop(orig)); + dag getopToSetop = !setdagop(another, !getdagop(orig)); // CHECK: dag getopToBangDag = (foo 1:$a, 2:$b, 3:$c); - dag getopToBangDag = !dag(!getop(orig), [1, 2, 3], ["a", "b", "c"]); + dag getopToBangDag = !dag(!getdagop(orig), [1, 2, 3], ["a", "b", "c"]); // CHECK: dag getopToDagInit = (foo "it worked"); - dag getopToDagInit = (!getop(orig) "it worked"); + dag getopToDagInit = (!getdagop(orig) "it worked"); #ifdef ERROR1 - // !getop(...) has a static type of 'any record at all, with no + // !getdagop(...) has a static type of 'any record at all, with no // required superclasses'. That's too general to use in an // assignment whose LHS demands an instance of Base, so we expect a // static (parse-time) type-checking error. - // ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getop(orig)' of type '{}' - Base noCast = !getop(orig); + // ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getdagop(orig)' of type '{}' + Base noCast = !getdagop(orig); #endif #ifdef ERROR2 @@ -47,15 +50,15 @@ // evaluation time that the operator of 'another' is a record that // isn't an instance of the specified base class. - // ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getop((qux "hello", ?:$world)) - Base badCast = !getop<Base>(another); + // ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getdagop((qux "hello", ?:$world)) + Base badCast = !getdagop<Base>(another); #endif #ifdef ERROR3 - // Obviously, you shouldn't be able to give any type to !getop that + // Obviously, you shouldn't be able to give any type to !getdagop that // isn't a class type. - // ERROR3: error: type for !getop must be a record type - int ridiculousCast = !getop<int>(orig); + // ERROR3: error: type for !getdagop must be a record type + int ridiculousCast = !getdagop<int>(orig); #endif } Index: llvm/lib/Target/ARM/ARMInstrMVE.td =================================================================== --- llvm/lib/Target/ARM/ARMInstrMVE.td +++ llvm/lib/Target/ARM/ARMInstrMVE.td @@ -3033,7 +3033,7 @@ defvar outparams = (inst (OutVTI.Vec MQPR:$QdSrc), (InVTI.Vec MQPR:$Qm), (imm:$imm)); - def : Pat<(OutVTI.Vec !setop(inparams, int_arm_mve_vshrn)), + def : Pat<(OutVTI.Vec !setdagop(inparams, int_arm_mve_vshrn)), (OutVTI.Vec outparams)>; def : Pat<(OutVTI.Vec !con(inparams, (int_arm_mve_vshrn_predicated (InVTI.Pred VCCR:$pred)))), @@ -3235,7 +3235,7 @@ defvar unpred_int = !cast<Intrinsic>("int_arm_mve_" # name); defvar pred_int = !cast<Intrinsic>("int_arm_mve_" # name # "_predicated"); - def : Pat<(VTI.Vec !setop(inparams, unpred_int)), + def : Pat<(VTI.Vec !setdagop(inparams, unpred_int)), (VTI.Vec outparams)>; def : Pat<(VTI.Vec !con(inparams, (pred_int (VTI.Pred VCCR:$pred)))), (VTI.Vec !con(outparams, (? ARMVCCThen, VCCR:$pred)))>; Index: llvm/lib/TableGen/TGParser.cpp =================================================================== --- llvm/lib/TableGen/TGParser.cpp +++ llvm/lib/TableGen/TGParser.cpp @@ -914,7 +914,7 @@ case tgtok::XSize: case tgtok::XEmpty: case tgtok::XCast: - case tgtok::XGetOp: { // Value ::= !unop '(' Value ')' + case tgtok::XGetDagOp: { // Value ::= !unop '(' Value ')' UnOpInit::UnaryOp Code; RecTy *Type = nullptr; @@ -955,12 +955,12 @@ Code = UnOpInit::EMPTY; Type = IntRecTy::get(); break; - case tgtok::XGetOp: + case tgtok::XGetDagOp: Lex.Lex(); // eat the operation if (Lex.getCode() == tgtok::less) { // Parse an optional type suffix, so that you can say - // !getop<BaseClass>(someDag) as a shorthand for - // !cast<BaseClass>(!getop(someDag)). + // !getdagop<BaseClass>(someDag) as a shorthand for + // !cast<BaseClass>(!getdagop(someDag)). Type = ParseOperatorType(); if (!Type) { @@ -969,13 +969,13 @@ } if (!isa<RecordRecTy>(Type)) { - TokError("type for !getop must be a record type"); + TokError("type for !getdagop must be a record type"); // but keep parsing, to consume the operand } } else { Type = RecordRecTy::get({}); } - Code = UnOpInit::GETOP; + Code = UnOpInit::GETDAGOP; break; } if (!consume(tgtok::l_paren)) { @@ -1091,7 +1091,7 @@ case tgtok::XListConcat: case tgtok::XListSplat: case tgtok::XStrConcat: - case tgtok::XSetOp: { // Value ::= !binop '(' Value ',' Value ')' + case tgtok::XSetDagOp: { // Value ::= !binop '(' Value ',' Value ')' tgtok::TokKind OpTok = Lex.getCode(); SMLoc OpLoc = Lex.getLoc(); Lex.Lex(); // eat the operation @@ -1115,9 +1115,9 @@ case tgtok::XGe: Code = BinOpInit::GE; break; case tgtok::XGt: Code = BinOpInit::GT; break; case tgtok::XListConcat: Code = BinOpInit::LISTCONCAT; break; - case tgtok::XListSplat: Code = BinOpInit::LISTSPLAT; break; - case tgtok::XStrConcat: Code = BinOpInit::STRCONCAT; break; - case tgtok::XSetOp: Code = BinOpInit::SETOP; break; + case tgtok::XListSplat: Code = BinOpInit::LISTSPLAT; break; + case tgtok::XStrConcat: Code = BinOpInit::STRCONCAT; break; + case tgtok::XSetDagOp: Code = BinOpInit::SETDAGOP; break; } RecTy *Type = nullptr; @@ -1126,7 +1126,7 @@ default: llvm_unreachable("Unhandled code!"); case tgtok::XConcat: - case tgtok::XSetOp: + case tgtok::XSetDagOp: Type = DagRecTy::get(); ArgType = DagRecTy::get(); break; @@ -1259,7 +1259,7 @@ // Deal with BinOps whose arguments have different types, by // rewriting ArgType in between them. switch (Code) { - case BinOpInit::SETOP: + case BinOpInit::SETDAGOP: // After parsing the first dag argument, switch to expecting // a record, with no restriction on its superclasses. ArgType = RecordRecTy::get({}); @@ -2051,7 +2051,7 @@ case tgtok::l_paren: { // Value ::= '(' IDValue DagArgList ')' Lex.Lex(); // eat the '(' if (Lex.getCode() != tgtok::Id && Lex.getCode() != tgtok::XCast && - Lex.getCode() != tgtok::question && Lex.getCode() != tgtok::XGetOp) { + Lex.getCode() != tgtok::question && Lex.getCode() != tgtok::XGetDagOp) { TokError("expected identifier in dag init"); return nullptr; } @@ -2089,7 +2089,7 @@ case tgtok::XSize: case tgtok::XEmpty: case tgtok::XCast: - case tgtok::XGetOp: // Value ::= !unop '(' Value ')' + case tgtok::XGetDagOp: // Value ::= !unop '(' Value ')' case tgtok::XIsA: case tgtok::XConcat: case tgtok::XDag: @@ -2111,7 +2111,7 @@ case tgtok::XListConcat: case tgtok::XListSplat: case tgtok::XStrConcat: - case tgtok::XSetOp: // Value ::= !binop '(' Value ',' Value ')' + case tgtok::XSetDagOp: // Value ::= !binop '(' Value ',' Value ')' case tgtok::XIf: case tgtok::XCond: case tgtok::XFoldl: Index: llvm/lib/TableGen/TGLexer.h =================================================================== --- llvm/lib/TableGen/TGLexer.h +++ llvm/lib/TableGen/TGLexer.h @@ -54,7 +54,7 @@ XConcat, XADD, XMUL, XNOT, XAND, XOR, XXOR, XSRA, XSRL, XSHL, XListConcat, XListSplat, XStrConcat, XCast, XSubst, XForEach, XFoldl, XHead, XTail, XSize, XEmpty, XIf, XCond, XEq, XIsA, XDag, XNe, XLe, - XLt, XGe, XGt, XSetOp, XGetOp, + XLt, XGe, XGt, XSetDagOp, XGetDagOp, // Integer value. IntVal, Index: llvm/lib/TableGen/TGLexer.cpp =================================================================== --- llvm/lib/TableGen/TGLexer.cpp +++ llvm/lib/TableGen/TGLexer.cpp @@ -578,8 +578,8 @@ .Case("listconcat", tgtok::XListConcat) .Case("listsplat", tgtok::XListSplat) .Case("strconcat", tgtok::XStrConcat) - .Case("setop", tgtok::XSetOp) - .Case("getop", tgtok::XGetOp) + .Cases("setdagop", "setop", tgtok::XSetDagOp) // !setop is deprecated. + .Cases("getdagop", "getop", tgtok::XGetDagOp) // !getop is deprecated. .Default(tgtok::Error); return Kind != tgtok::Error ? Kind : ReturnError(Start-1, "Unknown operator"); Index: llvm/lib/TableGen/Record.cpp =================================================================== --- llvm/lib/TableGen/Record.cpp +++ llvm/lib/TableGen/Record.cpp @@ -801,7 +801,7 @@ return IntInit::get(LHSs->getValue().empty()); break; - case GETOP: + case GETDAGOP: if (DagInit *Dag = dyn_cast<DagInit>(LHS)) { DefInit *DI = DefInit::get(Dag->getOperatorAsDef({})); if (!DI->getType()->typeIsA(getType())) { @@ -837,7 +837,7 @@ case TAIL: Result = "!tail"; break; case SIZE: Result = "!size"; break; case EMPTY: Result = "!empty"; break; - case GETOP: Result = "!getop"; break; + case GETDAGOP: Result = "!getdagop"; break; } return Result + "(" + LHS->getAsString() + ")"; } @@ -1009,7 +1009,7 @@ break; } - case SETOP: { + case SETDAGOP: { DagInit *Dag = dyn_cast<DagInit>(LHS); DefInit *Op = dyn_cast<DefInit>(RHS); if (Dag && Op) { @@ -1088,7 +1088,7 @@ case LISTCONCAT: Result = "!listconcat"; break; case LISTSPLAT: Result = "!listsplat"; break; case STRCONCAT: Result = "!strconcat"; break; - case SETOP: Result = "!setop"; break; + case SETDAGOP: Result = "!setdagop"; break; } return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")"; } Index: llvm/include/llvm/TableGen/Record.h =================================================================== --- llvm/include/llvm/TableGen/Record.h +++ llvm/include/llvm/TableGen/Record.h @@ -753,7 +753,7 @@ /// class UnOpInit : public OpInit, public FoldingSetNode { public: - enum UnaryOp : uint8_t { CAST, NOT, HEAD, TAIL, SIZE, EMPTY, GETOP }; + enum UnaryOp : uint8_t { CAST, NOT, HEAD, TAIL, SIZE, EMPTY, GETDAGOP }; private: Init *LHS; @@ -804,7 +804,7 @@ public: enum BinaryOp : uint8_t { ADD, MUL, AND, OR, XOR, SHL, SRA, SRL, LISTCONCAT, LISTSPLAT, STRCONCAT, CONCAT, EQ, NE, LE, LT, GE, - GT, SETOP }; + GT, SETDAGOP }; private: Init *LHS, *RHS; Index: llvm/docs/TableGen/ProgRef.rst =================================================================== --- llvm/docs/TableGen/ProgRef.rst +++ llvm/docs/TableGen/ProgRef.rst @@ -206,13 +206,13 @@ .. productionlist:: BangOperator: one of - : !add !and !cast !con !dag - : !empty !eq !foldl !foreach !ge - : !getop !gt !head !if !isa - : !le !listconcat !listsplat !lt !mul - : !ne !not !or !setop !shl - : !size !sra !srl !strconcat !subst - : !tail !xor + : !add !and !cast !con !dag + : !empty !eq !foldl !foreach !ge + : !getdagop !gt !head !if !isa + : !le !listconcat !listsplat !lt !mul + : !ne !not !or !setdagop !shl + : !size !sra !srl !strconcat !subst + : !tail !xor The ``!cond`` operator has a slightly different syntax compared to other bang operators, so it is defined separately: @@ -1243,7 +1243,7 @@ DAG. The following bang operators are useful for working with DAGs: -``!con``, ``!dag``, ``!empty``, ``!foreach``, ``!getop``, ``!setop``, ``!size``. +``!con``, ``!dag``, ``!empty``, ``!foreach``, ``!getdagop``, ``!setdagop``, ``!size``. Defvar in a record body ----------------------- @@ -1445,6 +1445,10 @@ for false. When an operator tests a boolean argument, it interprets 0 as false and non-0 as true. +.. warning:: + The ``!getop`` and ``!setop`` bang operators are deprecated in favor of + ``!getdagop`` and ``!setdagop``. + ``!add(``\ *a*\ ``,`` *b*\ ``, ...)`` This operator adds *a*, *b*, etc., and produces the sum. @@ -1544,26 +1548,27 @@ The arguments must be ``bit``, ``int``, or ``string`` values. Use ``!cast<string>`` to compare other types of objects. -``!getop(``\ *dag*\ ``)`` --or-- ``!getop<``\ *type*\ ``>(``\ *dag*\ ``)`` +``!getdagop(``\ *dag*\ ``)`` --or-- ``!getdagop<``\ *type*\ ``>(``\ *dag*\ ``)`` This operator produces the operator of the given *dag* node. - Example: ``!getop((foo 1, 2))`` results in ``foo``. + Example: ``!getdagop((foo 1, 2))`` results in ``foo``. Recall that + DAG operators are always records. - The result of ``!getop`` can be used directly in a context where - any record value at all is acceptable (typically placing it into + The result of ``!getdagop`` can be used directly in a context where + any record class at all is acceptable (typically placing it into another dag value). But in other contexts, it must be explicitly - cast to a particular class type. The ``<``\ *type*\ ``>`` syntax is + cast to a particular class. The ``<``\ *type*\ ``>`` syntax is provided to make this easy. For example, to assign the result to a value of type ``BaseClass``, you could write either of these:: - BaseClass b = !getop<BaseClass>(someDag); - BaseClass b = !cast<BaseClass>(!getop(someDag)); + BaseClass b = !getdagop<BaseClass>(someDag); + BaseClass b = !cast<BaseClass>(!getdagop(someDag)); But to create a new DAG node that reuses the operator from another, no cast is necessary:: - dag d = !dag(!getop(someDag), args, names); + dag d = !dag(!getdagop(someDag), args, names); ``!gt(``\ *a*\ `,` *b*\ ``)`` This operator produces 1 if *a* is greater than *b*; 0 otherwise. @@ -1620,11 +1625,11 @@ result. A logical OR can be performed if all the arguments are either 0 or 1. -``!setop(``\ *dag*\ ``,`` *op*\ ``)`` +``!setdagop(``\ *dag*\ ``,`` *op*\ ``)`` This operator produces a DAG node with the same arguments as *dag*, but with its operator replaced with *op*. - Example: ``!setop((foo 1, 2), bar)`` results in ``(bar 1, 2)``. + Example: ``!setdagop((foo 1, 2), bar)`` results in ``(bar 1, 2)``. ``!shl(``\ *a*\ ``,`` *count*\ ``)`` This operator shifts *a* left logically by *count* bits and produces the resulting Index: clang/include/clang/Basic/arm_mve.td =================================================================== --- clang/include/clang/Basic/arm_mve.td +++ clang/include/clang/Basic/arm_mve.td @@ -545,8 +545,8 @@ defvar intArgsUnpred = !con(intArgsBase, !if(needSign, (? (unsignedflag Scalar)), (?))); defvar intArgsPred = !con(intArgsUnpred, (? $pred)); - defvar intUnpred = !setop(intArgsUnpred, IRInt<basename, basetypes>); - defvar intPred = !setop(intArgsPred, IRInt< + defvar intUnpred = !setdagop(intArgsUnpred, IRInt<basename, basetypes>); + defvar intPred = !setdagop(intArgsPred, IRInt< basename#"_predicated", !listconcat(basetypes, [Predicate])>); def "": Intrinsic<
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits