llvm.org GIT mirror llvm / 6e0a99a
Teach tablegen how to inherit from classes in 'defm' definitions. The rule is simple: only inherit from a class list if they come in the end, after the last multiclass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106305 91177308-0d34-0410-b5e6-96231b3b80d8 Bruno Cardoso Lopes 10 years ago
3 changed file(s) with 127 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
731731
732732
733733
734

735 defm declarations can inherit from classes too, the
736 rule to follow is that the class list must start after the
737 last multiclass, and there must be at least one multiclass
738 before them.
739

740
741
742

                  
                
743 class XD { bits<4> Prefix = 11; }
744 class XS { bits<4> Prefix = 12; }
745
746 class I<bits<4> op> {
747 bits<4> opcode = op;
748 }
749
750 multiclass R {
751 def rr : I<4>;
752 def rm : I<2>;
753 }
754
755 multiclass Y {
756 defm SS : R, XD;
757 defm SD : R, XS;
758 }
759
760 defm Instr : Y;
761
762 // Results
763 def InstrSDrm {
764 bits<4> opcode = { 0, 0, 1, 0 };
765 bits<4> Prefix = { 1, 1, 0, 0 };
766 }
767 ...
768 def InstrSSrr {
769 bits<4> opcode = { 0, 1, 0, 0 };
770 bits<4> Prefix = { 1, 0, 1, 1 };
771 }
772
773
774
734775
735776
736777
0 // RUN: tblgen %s | FileCheck %s
1 // XFAIL: vg_leak
2
3 class XD { bits<4> Prefix = 11; }
4 // CHECK: Prefix = { 1, 1, 0, 0 };
5 class XS { bits<4> Prefix = 12; }
6 class VEX { bit hasVEX_4VPrefix = 1; }
7
8 def xd : XD;
9
10 class BaseI {
11 bits<4> Prefix = 0;
12 bit hasVEX_4VPrefix = 0;
13 }
14
15 class I op> : BaseI {
16 bits<4> opcode = op;
17 int val = !if(!eq(Prefix, xd.Prefix), 7, 21);
18 }
19
20 multiclass R {
21 def rr : I<4>;
22 }
23
24 multiclass M {
25 def rm : I<2>;
26 }
27
28 multiclass Y {
29 defm SS : R, M, XD;
30 // CHECK: Prefix = { 1, 1, 0, 0 };
31 // CHECK: Prefix = { 1, 1, 0, 0 };
32 defm SD : R, M, XS;
33 }
34
35 defm Instr : Y, VEX;
19061906 if (Lex.Lex() != tgtok::colon)
19071907 return TokError("expected ':' after defm identifier");
19081908
1909 // Keep track of the new generated record definitions.
1910 std::vector NewRecDefs;
1911
1912 // This record also inherits from a regular class (non-multiclass)?
1913 bool InheritFromClass = false;
1914
19091915 // eat the colon.
19101916 Lex.Lex();
19111917
20152021 Records.addDef(CurRec);
20162022 CurRec->resolveReferences();
20172023 }
2024
2025 NewRecDefs.push_back(CurRec);
20182026 }
20192027
20202028 if (Lex.getCode() != tgtok::comma) break;
20212029 Lex.Lex(); // eat ','.
20222030
20232031 SubClassLoc = Lex.getLoc();
2032
2033 // A defm can inherit from regular classes (non-multiclass) as
2034 // long as they come in the end of the inheritance list.
2035 InheritFromClass = (Records.getClass(Lex.getCurStrVal()) != 0);
2036
2037 if (InheritFromClass)
2038 break;
2039
20242040 Ref = ParseSubClassReference(0, true);
2041 }
2042
2043 if (InheritFromClass) {
2044 // Process all the classes to inherit as if they were part of a
2045 // regular 'def' and inherit all record values.
2046 SubClassReference SubClass = ParseSubClassReference(0, false);
2047 while (1) {
2048 // Check for error.
2049 if (SubClass.Rec == 0) return true;
2050
2051 // Get the expanded definition prototypes and teach them about
2052 // the record values the current class to inherit has
2053 for (unsigned i = 0, e = NewRecDefs.size(); i != e; ++i) {
2054 Record *CurRec = NewRecDefs[i];
2055
2056 // Add it.
2057 if (AddSubClass(CurRec, SubClass))
2058 return true;
2059
2060 // Process any variables on the let stack.
2061 for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
2062 for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
2063 if (SetValue(CurRec, LetStack[i][j].Loc, LetStack[i][j].Name,
2064 LetStack[i][j].Bits, LetStack[i][j].Value))
2065 return true;
2066
2067 if (!CurMultiClass)
2068 CurRec->resolveReferences();
2069 }
2070
2071 if (Lex.getCode() != tgtok::comma) break;
2072 Lex.Lex(); // eat ','.
2073 SubClass = ParseSubClassReference(0, false);
2074 }
20252075 }
20262076
20272077 if (Lex.getCode() != tgtok::semi)