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)>;
}

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161198 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Grosbach 2012-08-02 18:46:42 +00:00
parent 79a20ce6f0
commit cfbda4a04d

View File

@ -2284,23 +2284,33 @@ InstantiateMulticlassDef(MultiClass &MC,
Ref.Rec = DefProto; Ref.Rec = DefProto;
AddSubClass(CurRec, Ref); AddSubClass(CurRec, Ref);
if (DefNameString == 0) { // Set the value for NAME. We don't resolve references to it 'til later,
// We must resolve references to NAME. // though, so that uses in nested multiclass names don't get
if (SetValue(CurRec, Ref.RefLoc, "NAME", std::vector<unsigned>(), // confused.
DefmPrefix)) { if (SetValue(CurRec, Ref.RefLoc, "NAME", std::vector<unsigned>(),
Error(DefmPrefixLoc, "Could not resolve " DefmPrefix)) {
+ CurRec->getNameInitAsString() + ":NAME to '" Error(DefmPrefixLoc, "Could not resolve "
+ DefmPrefix->getAsUnquotedString() + "'"); + CurRec->getNameInitAsString() + ":NAME to '"
return 0; + 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"); RecordVal *DefNameRV = CurRec->getValue("NAME");
CurRec->resolveReferencesTo(DefNameRV); CurRec->resolveReferencesTo(DefNameRV);
} }
if (!CurMultiClass) { if (!CurMultiClass) {
// We do this after resolving NAME because before resolution, many // Now that we're at the top level, resolve all NAME references
// multiclass defs will have the same name expression. If we are // 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 // currently in a multiclass, it means this defm appears inside a
// multiclass and its name won't be fully resolvable until we see // multiclass and its name won't be fully resolvable until we see
// the top-level defm. Therefore, we don't add this to the // the top-level defm. Therefore, we don't add this to the