From 7538ed80a95b908ca0227c637add96950f5ccb28 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 5 Oct 2010 22:51:56 +0000 Subject: [PATCH] enhance tblgen to support anonymous defm's, use this to simplify the X86 CMOVmr's. llvm-svn: 115702 --- llvm/lib/Target/X86/X86InstrCompiler.td | 32 ++++++++-------- llvm/test/TableGen/defmclass.td | 12 ++++++ llvm/utils/TableGen/TGParser.cpp | 49 ++++++++++++++++--------- 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/llvm/lib/Target/X86/X86InstrCompiler.td b/llvm/lib/Target/X86/X86InstrCompiler.td index 28ccc4958e51..4dc412b05e10 100644 --- a/llvm/lib/Target/X86/X86InstrCompiler.td +++ b/llvm/lib/Target/X86/X86InstrCompiler.td @@ -860,22 +860,22 @@ multiclass CMOVmr; } -defm CMOVAEmr : CMOVmr; -defm CMOVBmr : CMOVmr; -defm CMOVNEmr : CMOVmr; -defm CMOVEmr : CMOVmr; -defm CMOVAmr : CMOVmr; -defm CMOVBEmr : CMOVmr; -defm CMOVGEmr : CMOVmr; -defm CMOVLmr : CMOVmr; -defm CMOVGmr : CMOVmr; -defm CMOVLEmr : CMOVmr; -defm CMOVNPmr : CMOVmr; -defm CMOVPmr : CMOVmr; -defm CMOVNSmr : CMOVmr; -defm CMOVSmr : CMOVmr; -defm CMOVNOmr : CMOVmr; -defm CMOVOmr : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; +defm : CMOVmr; // zextload bool -> zextload byte def : Pat<(zextloadi8i1 addr:$src), (MOV8rm addr:$src)>; diff --git a/llvm/test/TableGen/defmclass.td b/llvm/test/TableGen/defmclass.td index 55482da4d072..57972b6dae54 100644 --- a/llvm/test/TableGen/defmclass.td +++ b/llvm/test/TableGen/defmclass.td @@ -36,3 +36,15 @@ multiclass Y { // CHECK: int check = 0; defm Instr : Y, VEX; + + +// Anonymous defm. + +multiclass SomeAnonymous { + def rm; + def mr; +} + +// These multiclasses shouldn't conflict. +defm : SomeAnonymous<1>; +defm : SomeAnonymous<2>; \ No newline at end of file diff --git a/llvm/utils/TableGen/TGParser.cpp b/llvm/utils/TableGen/TGParser.cpp index f81aabe79b03..d3bd5cd710c5 100644 --- a/llvm/utils/TableGen/TGParser.cpp +++ b/llvm/utils/TableGen/TGParser.cpp @@ -294,20 +294,23 @@ static bool isObjectStart(tgtok::TokKind K) { K == tgtok::Defm || K == tgtok::Let || K == tgtok::MultiClass; } +static std::string GetNewAnonymousName() { + static unsigned AnonCounter = 0; + return "anonymous."+utostr(AnonCounter++); +} + /// ParseObjectName - If an object name is specified, return it. Otherwise, /// return an anonymous name. /// ObjectName ::= ID /// ObjectName ::= /*empty*/ /// std::string TGParser::ParseObjectName() { - if (Lex.getCode() == tgtok::Id) { - std::string Ret = Lex.getCurStrVal(); - Lex.Lex(); - return Ret; - } - - static unsigned AnonCounter = 0; - return "anonymous."+utostr(AnonCounter++); + if (Lex.getCode() != tgtok::Id) + return GetNewAnonymousName(); + + std::string Ret = Lex.getCurStrVal(); + Lex.Lex(); + return Ret; } @@ -1899,12 +1902,15 @@ bool TGParser::ParseMultiClass() { /// bool TGParser::ParseDefm(MultiClass *CurMultiClass) { assert(Lex.getCode() == tgtok::Defm && "Unexpected token!"); - if (Lex.Lex() != tgtok::Id) // eat the defm. - return TokError("expected identifier after defm"); + std::string DefmPrefix; + if (Lex.Lex() == tgtok::Id) { // eat the defm. + DefmPrefix = Lex.getCurStrVal(); + Lex.Lex(); // Eat the defm prefix. + } + SMLoc DefmPrefixLoc = Lex.getLoc(); - std::string DefmPrefix = Lex.getCurStrVal(); - if (Lex.Lex() != tgtok::colon) + if (Lex.getCode() != tgtok::colon) return TokError("expected ':' after defm identifier"); // Keep track of the new generated record definitions. @@ -1939,14 +1945,21 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { for (unsigned i = 0, e = MC->DefPrototypes.size(); i != e; ++i) { Record *DefProto = MC->DefPrototypes[i]; - // Add in the defm name + // Add in the defm name. If the defm prefix is empty, give each + // instantiated def a unique name. Otherwise, if "#NAME#" exists in the + // name, substitute the prefix for #NAME#. Otherwise, use the defm name + // as a prefix. std::string DefName = DefProto->getName(); - std::string::size_type idx = DefName.find("#NAME#"); - if (idx != std::string::npos) { - DefName.replace(idx, 6, DefmPrefix); + if (DefmPrefix.empty()) { + DefName = GetNewAnonymousName(); } else { - // Add the suffix to the defm name to get the new name. - DefName = DefmPrefix + DefName; + std::string::size_type idx = DefName.find("#NAME#"); + if (idx != std::string::npos) { + DefName.replace(idx, 6, DefmPrefix); + } else { + // Add the suffix to the defm name to get the new name. + DefName = DefmPrefix + DefName; + } } Record *CurRec = new Record(DefName, DefmPrefixLoc);