[llvm-commits] [llvm] r161198 - /llvm/trunk/lib/TableGen/TGParser.cpp
Sean Silva
silvas at purdue.edu
Thu Aug 2 13:15:07 PDT 2012
Please add a test case.
--Sean Silva
On Thu, Aug 2, 2012 at 11:46 AM, Jim Grosbach <grosbach at apple.com> wrote:
> Author: grosbach
> Date: Thu Aug 2 13:46:42 2012
> New Revision: 161198
>
> URL: http://llvm.org/viewvc/llvm-project?rev=161198&view=rev
> Log:
> TableGen: Allow use of #NAME# outside of 'def' names.
>
> Previously, def NAME values were only populated, and references to NAME
> resolved, when NAME was referenced in the 'def' entry of the multiclass
> sub-entry. e.g.,
> multiclass foo<...> {
> def prefix_#NAME : ...
> }
>
> It's useful, however, to be able to reference NAME even when the default
> def name is used. For example, when a multiclass has 'def : Pat<...>'
> or 'def : InstAlias<...>' entries which refer to earlier instruction
> definitions in the same multiclass. e.g.,
> multiclass myMulti<RegisterClass rc> {
> def _r : myI<(outs rc:$d), (ins rc:$r), "r $d, $r", []>;
>
> def : InstAlias<\"wilma $r\", (!cast<Instruction>(NAME#\"_r\") rc:$r, rc:$r)>;
> }
>
> Modified:
> llvm/trunk/lib/TableGen/TGParser.cpp
>
> Modified: llvm/trunk/lib/TableGen/TGParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=161198&r1=161197&r2=161198&view=diff
> ==============================================================================
> --- llvm/trunk/lib/TableGen/TGParser.cpp (original)
> +++ llvm/trunk/lib/TableGen/TGParser.cpp Thu Aug 2 13:46:42 2012
> @@ -2284,23 +2284,33 @@
> Ref.Rec = DefProto;
> AddSubClass(CurRec, Ref);
>
> - if (DefNameString == 0) {
> - // We must resolve references to NAME.
> - if (SetValue(CurRec, Ref.RefLoc, "NAME", std::vector<unsigned>(),
> - DefmPrefix)) {
> - Error(DefmPrefixLoc, "Could not resolve "
> - + CurRec->getNameInitAsString() + ":NAME to '"
> - + DefmPrefix->getAsUnquotedString() + "'");
> - return 0;
> - }
> + // Set the value for NAME. We don't resolve references to it 'til later,
> + // though, so that uses in nested multiclass names don't get
> + // confused.
> + if (SetValue(CurRec, Ref.RefLoc, "NAME", std::vector<unsigned>(),
> + DefmPrefix)) {
> + Error(DefmPrefixLoc, "Could not resolve "
> + + CurRec->getNameInitAsString() + ":NAME to '"
> + + DefmPrefix->getAsUnquotedString() + "'");
> + return 0;
> + }
>
> + // If the DefNameString didn't resolve, we probably have a reference to
> + // NAME and need to replace it. We need to do at least this much greedily,
> + // otherwise nested multiclasses will end up with incorrect NAME expansions.
> + if (DefNameString == 0) {
> RecordVal *DefNameRV = CurRec->getValue("NAME");
> CurRec->resolveReferencesTo(DefNameRV);
> }
>
> if (!CurMultiClass) {
> - // We do this after resolving NAME because before resolution, many
> - // multiclass defs will have the same name expression. If we are
> + // Now that we're at the top level, resolve all NAME references
> + // in the resultant defs that weren't in the def names themselves.
> + RecordVal *DefNameRV = CurRec->getValue("NAME");
> + CurRec->resolveReferencesTo(DefNameRV);
> +
> + // Now that NAME references are resolved and we're at the top level of
> + // any multiclass expansions, add the record to the RecordKeeper. If we are
> // currently in a multiclass, it means this defm appears inside a
> // multiclass and its name won't be fully resolvable until we see
> // the top-level defm. Therefore, we don't add this to the
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list