llvm.org GIT mirror llvm / df72eae
enhance tblgen to support anonymous defm's, use this to simplify the X86 CMOVmr's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115702 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
3 changed file(s) with 60 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
859859 (Inst64 GR64:$src2, addr:$src1)>;
860860 }
861861
862 defm CMOVAEmr : CMOVmr;
863 defm CMOVBmr : CMOVmr;
864 defm CMOVNEmr : CMOVmr;
865 defm CMOVEmr : CMOVmr;
866 defm CMOVAmr : CMOVmr;
867 defm CMOVBEmr : CMOVmr;
868 defm CMOVGEmr : CMOVmr;
869 defm CMOVLmr : CMOVmr;
870 defm CMOVGmr : CMOVmr;
871 defm CMOVLEmr : CMOVmr;
872 defm CMOVNPmr : CMOVmr;
873 defm CMOVPmr : CMOVmr;
874 defm CMOVNSmr : CMOVmr;
875 defm CMOVSmr : CMOVmr;
876 defm CMOVNOmr : CMOVmr;
877 defm CMOVOmr : CMOVmr64rm>;
862 defm : CMOVmr64rm>;
863 defm : CMOVmr;
864 defm : CMOVmr;
865 defm : CMOVmr;
866 defm : CMOVmr;
867 defm : CMOVmr;
868 defm : CMOVmr;
869 defm : CMOVmr;
870 defm : CMOVmr;
871 defm : CMOVmr;
872 defm : CMOVmr;
873 defm : CMOVmr;
874 defm : CMOVmr;
875 defm : CMOVmr;
876 defm : CMOVmr;
877 defm : CMOVmr;
878878
879879 // zextload bool -> zextload byte
880880 def : Pat<(zextloadi8i1 addr:$src), (MOV8rm addr:$src)>;
3535
3636 // CHECK: int check = 0;
3737 defm Instr : Y, VEX;
38
39
40 // Anonymous defm.
41
42 multiclass SomeAnonymous {
43 def rm;
44 def mr;
45 }
46
47 // These multiclasses shouldn't conflict.
48 defm : SomeAnonymous<1>;
49 defm : SomeAnonymous<2>;
293293 K == tgtok::Defm || K == tgtok::Let || K == tgtok::MultiClass;
294294 }
295295
296 static std::string GetNewAnonymousName() {
297 static unsigned AnonCounter = 0;
298 return "anonymous."+utostr(AnonCounter++);
299 }
300
296301 /// ParseObjectName - If an object name is specified, return it. Otherwise,
297302 /// return an anonymous name.
298303 /// ObjectName ::= ID
299304 /// ObjectName ::= /*empty*/
300305 ///
301306 std::string TGParser::ParseObjectName() {
302 if (Lex.getCode() == tgtok::Id) {
303 std::string Ret = Lex.getCurStrVal();
304 Lex.Lex();
305 return Ret;
306 }
307
308 static unsigned AnonCounter = 0;
309 return "anonymous."+utostr(AnonCounter++);
307 if (Lex.getCode() != tgtok::Id)
308 return GetNewAnonymousName();
309
310 std::string Ret = Lex.getCurStrVal();
311 Lex.Lex();
312 return Ret;
310313 }
311314
312315
18981901 ///
18991902 bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
19001903 assert(Lex.getCode() == tgtok::Defm && "Unexpected token!");
1901 if (Lex.Lex() != tgtok::Id) // eat the defm.
1902 return TokError("expected identifier after defm");
1903
1904
1905 std::string DefmPrefix;
1906 if (Lex.Lex() == tgtok::Id) { // eat the defm.
1907 DefmPrefix = Lex.getCurStrVal();
1908 Lex.Lex(); // Eat the defm prefix.
1909 }
1910
19041911 SMLoc DefmPrefixLoc = Lex.getLoc();
1905 std::string DefmPrefix = Lex.getCurStrVal();
1906 if (Lex.Lex() != tgtok::colon)
1912 if (Lex.getCode() != tgtok::colon)
19071913 return TokError("expected ':' after defm identifier");
19081914
19091915 // Keep track of the new generated record definitions.
19381944 for (unsigned i = 0, e = MC->DefPrototypes.size(); i != e; ++i) {
19391945 Record *DefProto = MC->DefPrototypes[i];
19401946
1941 // Add in the defm name
1947 // Add in the defm name. If the defm prefix is empty, give each
1948 // instantiated def a unique name. Otherwise, if "#NAME#" exists in the
1949 // name, substitute the prefix for #NAME#. Otherwise, use the defm name
1950 // as a prefix.
19421951 std::string DefName = DefProto->getName();
1943 std::string::size_type idx = DefName.find("#NAME#");
1944 if (idx != std::string::npos) {
1945 DefName.replace(idx, 6, DefmPrefix);
1952 if (DefmPrefix.empty()) {
1953 DefName = GetNewAnonymousName();
19461954 } else {
1947 // Add the suffix to the defm name to get the new name.
1948 DefName = DefmPrefix + DefName;
1955 std::string::size_type idx = DefName.find("#NAME#");
1956 if (idx != std::string::npos) {
1957 DefName.replace(idx, 6, DefmPrefix);
1958 } else {
1959 // Add the suffix to the defm name to get the new name.
1960 DefName = DefmPrefix + DefName;
1961 }
19491962 }
19501963
19511964 Record *CurRec = new Record(DefName, DefmPrefixLoc);