<p dir="ltr">That works for me; most of our tablegen backends are tested merely through the fact that they generate code that passes its tests.</p>
<div class="gmail_quote">On 22 Jul 2014 10:43, "Tom Stellard" <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, Jul 21, 2014 at 06:48:51PM -0700, Richard Smith wrote:<br>
> On Mon, Jul 21, 2014 at 6:28 AM, Tom Stellard <<a href="mailto:thomas.stellard@amd.com">thomas.stellard@amd.com</a>><br>
> wrote:<br>
><br>
> > Author: tstellar<br>
> > Date: Mon Jul 21 08:28:54 2014<br>
> > New Revision: 213521<br>
> ><br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=213521&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=213521&view=rev</a><br>
> > Log:<br>
> > TableGen: Allow AddedComplexity values to be negative<br>
> ><br>
> > This is useful for cases when stand-alone patterns are preferred to the<br>
> > patterns included in the instruction definitions. Instead of requiring<br>
> > that stand-alone patterns set a larger AddedComplexity value, which<br>
> > can be confusing to new developers, the allows us to reduce the<br>
> > complexity of the included patterns to achieve the same result.<br>
> ><br>
> > Added:<br>
> > llvm/trunk/test/TableGen/NegativeAddedComplexity.ll<br>
> > Modified:<br>
> > llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp<br>
> > llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h<br>
> > llvm/trunk/utils/TableGen/DAGISelEmitter.cpp<br>
> ><br>
> > Added: llvm/trunk/test/TableGen/NegativeAddedComplexity.ll<br>
> > URL:<br>
> > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/NegativeAddedComplexity.ll?rev=213521&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/NegativeAddedComplexity.ll?rev=213521&view=auto</a><br>
> ><br>
> > ==============================================================================<br>
> > --- llvm/trunk/test/TableGen/NegativeAddedComplexity.ll (added)<br>
> > +++ llvm/trunk/test/TableGen/NegativeAddedComplexity.ll Mon Jul 21<br>
> > 08:28:54 2014<br>
> > @@ -0,0 +1,41 @@<br>
> > +// RUN: llvm-tblgen -I../../include -gen-dag-isel %s | FileCheck %s<br>
> > +// XFAIL: vg_leak<br>
> > +<br>
> > +include "llvm/Target/Target.td"<br>
> ><br>
><br>
> It seems unreasonable for this test to include a source file. No other test<br>
> does this; can you reduce this to directly specify a minimal set of<br>
> necessary functionality?<br>
><br>
<br>
I tried to do this, but it looks like I will need to copy and paste large<br>
portions of the include files into the test to get it to work. Since I<br>
have some target changes with test cases that depend on this patch,<br>
would it be better to drop the test case and add a note to the commit<br>
message saying there are test cases in the R600 target?<br>
<br>
-Tom<br>
<br>
><br>
> > +// Make sure the higher complexity pattern comes first<br>
> > +// CHECK: TARGET_VAL(::ADD0)<br>
> > +// CHECK: Complexity = {{[^-]}}<br>
> > +// Make sure the ADD1 pattern has a negative complexity<br>
> > +// CHECK: TARGET_VAL(::ADD1)<br>
> > +// CHECK: Complexity = -{{[0-9]+}}<br>
> > +<br>
> > +def TestRC : RegisterClass<"TEST", [i32], 32, (add)>;<br>
> > +<br>
> > +def TestInstrInfo : InstrInfo;<br>
> > +<br>
> > +def Test : Target {<br>
> > + let InstructionSet = TestInstrInfo;<br>
> > +}<br>
> > +<br>
> > +def ADD0 : Instruction {<br>
> > + let OutOperandList = (outs TestRC:$dst);<br>
> > + let InOperandList = (ins TestRC:$src0, TestRC:$src1);<br>
> > +}<br>
> > +<br>
> > +def ADD1 : Instruction {<br>
> > + let OutOperandList = (outs TestRC:$dst);<br>
> > + let InOperandList = (ins TestRC:$src0, TestRC:$src1);<br>
> > +}<br>
> > +<br>
> > +def : Pat <<br>
> > + (add i32:$src0, i32:$src1),<br>
> > + (ADD1 $src0, $src1)<br>
> > +> {<br>
> > + let AddedComplexity = -1000;<br>
> > +}<br>
> > +<br>
> > +def : Pat <<br>
> > + (add i32:$src0, i32:$src1),<br>
> > + (ADD0 $src0, $src1)<br>
> > +>;<br>
> ><br>
> > Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp<br>
> > URL:<br>
> > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=213521&r1=213520&r2=213521&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=213521&r1=213520&r2=213521&view=diff</a><br>
> ><br>
> > ==============================================================================<br>
> > --- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)<br>
> > +++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Mon Jul 21 08:28:54<br>
> > 2014<br>
> > @@ -771,7 +771,7 @@ static unsigned getPatternSize(const Tre<br>
> ><br>
> > /// Compute the complexity metric for the input pattern. This roughly<br>
> > /// corresponds to the number of nodes that are covered.<br>
> > -unsigned PatternToMatch::<br>
> > +int PatternToMatch::<br>
> > getPatternComplexity(const CodeGenDAGPatterns &CGP) const {<br>
> > return getPatternSize(getSrcPattern(), CGP) + getAddedComplexity();<br>
> > }<br>
> ><br>
> > Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h<br>
> > URL:<br>
> > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=213521&r1=213520&r2=213521&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=213521&r1=213520&r2=213521&view=diff</a><br>
> ><br>
> > ==============================================================================<br>
> > --- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h (original)<br>
> > +++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h Mon Jul 21 08:28:54 2014<br>
> > @@ -667,7 +667,7 @@ public:<br>
> > PatternToMatch(Record *srcrecord, ListInit *preds,<br>
> > TreePatternNode *src, TreePatternNode *dst,<br>
> > const std::vector<Record*> &dstregs,<br>
> > - unsigned complexity, unsigned uid)<br>
> > + int complexity, unsigned uid)<br>
> > : SrcRecord(srcrecord), Predicates(preds), SrcPattern(src),<br>
> > DstPattern(dst),<br>
> > Dstregs(dstregs), AddedComplexity(complexity), ID(uid) {}<br>
> ><br>
> > @@ -676,7 +676,7 @@ public:<br>
> > TreePatternNode *SrcPattern; // Source pattern to match.<br>
> > TreePatternNode *DstPattern; // Resulting pattern.<br>
> > std::vector<Record*> Dstregs; // Physical register defs being matched.<br>
> > - unsigned AddedComplexity; // Add to matching pattern complexity.<br>
> > + int AddedComplexity; // Add to matching pattern complexity.<br>
> > unsigned ID; // Unique ID for the record.<br>
> ><br>
> > Record *getSrcRecord() const { return SrcRecord; }<br>
> > @@ -684,13 +684,13 @@ public:<br>
> > TreePatternNode *getSrcPattern() const { return SrcPattern; }<br>
> > TreePatternNode *getDstPattern() const { return DstPattern; }<br>
> > const std::vector<Record*> &getDstRegs() const { return Dstregs; }<br>
> > - unsigned getAddedComplexity() const { return AddedComplexity; }<br>
> > + int getAddedComplexity() const { return AddedComplexity; }<br>
> ><br>
> > std::string getPredicateCheck() const;<br>
> ><br>
> > /// Compute the complexity metric for the input pattern. This roughly<br>
> > /// corresponds to the number of nodes that are covered.<br>
> > - unsigned getPatternComplexity(const CodeGenDAGPatterns &CGP) const;<br>
> > + int getPatternComplexity(const CodeGenDAGPatterns &CGP) const;<br>
> > };<br>
> ><br>
> > class CodeGenDAGPatterns {<br>
> ><br>
> > Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.cpp<br>
> > URL:<br>
> > <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=213521&r1=213520&r2=213521&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=213521&r1=213520&r2=213521&view=diff</a><br>
> ><br>
> > ==============================================================================<br>
> > --- llvm/trunk/utils/TableGen/DAGISelEmitter.cpp (original)<br>
> > +++ llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Mon Jul 21 08:28:54 2014<br>
> > @@ -94,8 +94,8 @@ struct PatternSortingPredicate {<br>
> > // Otherwise, if the patterns might both match, sort based on<br>
> > complexity,<br>
> > // which means that we prefer to match patterns that cover more nodes<br>
> > in the<br>
> > // input over nodes that cover fewer.<br>
> > - unsigned LHSSize = LHS->getPatternComplexity(CGP);<br>
> > - unsigned RHSSize = RHS->getPatternComplexity(CGP);<br>
> > + int LHSSize = LHS->getPatternComplexity(CGP);<br>
> > + int RHSSize = RHS->getPatternComplexity(CGP);<br>
> > if (LHSSize > RHSSize) return true; // LHS -> bigger -> less cost<br>
> > if (LHSSize < RHSSize) return false;<br>
> ><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > llvm-commits mailing list<br>
> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
> ><br>
<br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br>
</blockquote></div>