llvm.org GIT mirror llvm / 4717fd4
Allow TableGen DAG arguments to be just a name. DAG arguments can optionally be named: (dag node, node:$name) With this change, the node is also optional: (dag node, node:$name, $name) The missing node is treated as an UnsetInit, so the above is equivalent to: (dag node, node:$name, ?:$name) This syntax is useful in output patterns where we currently require the types of variables to be repeated: def : Pat<(subc i32:$b, i32:$c), (SUBCCrr i32:$b, i32:$c)>; This is preferable: def : Pat<(subc i32:$b, i32:$c), (SUBCCrr $b, $c)>; git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177843 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 6 years ago
3 changed file(s) with 40 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
285285 .. productionlist::
286286 SimpleValue: "(" `DagArg` `DagArgList` ")"
287287 DagArgList: `DagArg` ("," `DagArg`)*
288 DagArg: `Value` [":" `TokVarName`]
288 DagArg: `Value` [":" `TokVarName`] | `TokVarName`
289289
290290 The initial :token:`DagArg` is called the "operator" of the dag.
291291
15461546
15471547 /// ParseDagArgList - Parse the argument list for a dag literal expression.
15481548 ///
1549 /// ParseDagArgList ::= Value (':' VARNAME)?
1550 /// ParseDagArgList ::= ParseDagArgList ',' Value (':' VARNAME)?
1549 /// DagArg ::= Value (':' VARNAME)?
1550 /// DagArg ::= VARNAME
1551 /// DagArgList ::= DagArg
1552 /// DagArgList ::= DagArgList ',' DagArg
15511553 std::vector >
15521554 TGParser::ParseDagArgList(Record *CurRec) {
15531555 std::vector > Result;
15541556
15551557 while (1) {
1556 Init *Val = ParseValue(CurRec);
1557 if (Val == 0) return std::vector >();
1558
1559 // If the variable name is present, add it.
1560 std::string VarName;
1561 if (Lex.getCode() == tgtok::colon) {
1562 if (Lex.Lex() != tgtok::VarName) { // eat the ':'
1563 TokError("expected variable name in dag literal");
1558 // DagArg ::= VARNAME
1559 if (Lex.getCode() == tgtok::VarName) {
1560 // A missing value is treated like '?'.
1561 Result.push_back(std::make_pair(UnsetInit::get(), Lex.getCurStrVal()));
1562 Lex.Lex();
1563 } else {
1564 // DagArg ::= Value (':' VARNAME)?
1565 Init *Val = ParseValue(CurRec);
1566 if (Val == 0)
15641567 return std::vector >();
1565 }
1566 VarName = Lex.getCurStrVal();
1567 Lex.Lex(); // eat the VarName.
1568 }
1569
1570 Result.push_back(std::make_pair(Val, VarName));
1571
1568
1569 // If the variable name is present, add it.
1570 std::string VarName;
1571 if (Lex.getCode() == tgtok::colon) {
1572 if (Lex.Lex() != tgtok::VarName) { // eat the ':'
1573 TokError("expected variable name in dag literal");
1574 return std::vector >();
1575 }
1576 VarName = Lex.getCurStrVal();
1577 Lex.Lex(); // eat the VarName.
1578 }
1579
1580 Result.push_back(std::make_pair(Val, VarName));
1581 }
15721582 if (Lex.getCode() != tgtok::comma) break;
15731583 Lex.Lex(); // eat the ','
15741584 }
6969 // CHECK-NEXT: dag Dag3 = (somedef2 2);
7070 // CHECK-NEXT: NAME = ?
7171 // CHECK-NEXT: }
72
73 def VAL5 : bar {
74 // Named operands.
75 let Dag1 = (somedef1 1:$name1);
76
77 // Name, no node.
78 let Dag2 = (somedef2 $name2, $name3);
79 }
80
81 // CHECK: def VAL5 {
82 // CHECK-NEXT: dag Dag1 = (somedef1 1:$name1);
83 // CHECK-NEXT: dag Dag2 = (somedef2 ?:$name2, ?:$name3);