llvm.org GIT mirror llvm / a2c9188
Split out register class subclassing to a separate function and clean up accordingly. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112008 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 9 years ago
2 changed file(s) with 33 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
1818 #include "llvm/ADT/DenseMap.h"
1919 #include
2020 #include
21 #include
2122 #include
2223
2324 namespace llvm {
5455 assert(0 && "VTNum greater than number of ValueTypes in RegClass!");
5556 abort();
5657 }
58
59 // Returns true if RC is a strict subclass.
60 // RC is a sub-class of this class if it is a valid replacement for any
61 // instruction operand where a register of this classis required. It must
62 // satisfy these conditions:
63 //
64 // 1. All RC registers are also in this.
65 // 2. The RC spill size must not be smaller than our spill size.
66 // 3. RC spill alignment must be compatible with ours.
67 //
68 bool hasSubClass(const CodeGenRegisterClass *RC) const {
69
70 if (RC->Elements.size() > Elements.size() ||
71 (SpillAlignment && RC->SpillAlignment % SpillAlignment) ||
72 SpillSize > RC->SpillSize)
73 return false;
74
75 std::set RegSet;
76 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
77 Record *Reg = Elements[i];
78 RegSet.insert(Reg);
79 }
80
81 for (unsigned i = 0, e = RC->Elements.size(); i != e; ++i) {
82 Record *Reg = RC->Elements[i];
83 if (!RegSet.count(Reg))
84 return false;
85 }
86
87 return true;
88 }
5789
5890 CodeGenRegisterClass(Record *R);
5991 };
116116 OS << "} // end of namespace " << TargetName << "\n\n";
117117 }
118118 OS << "} // End llvm namespace \n";
119 }
120
121 bool isSubRegisterClass(const CodeGenRegisterClass &RC,
122 std::set &RegSet) {
123 for (unsigned i = 0, e = RC.Elements.size(); i != e; ++i) {
124 Record *Reg = RC.Elements[i];
125 if (!RegSet.count(Reg))
126 return false;
127 }
128 return true;
129119 }
130120
131121 static void addSuperReg(Record *R, Record *S,
497487 // Give the register class a legal C name if it's anonymous.
498488 std::string Name = RC.TheDef->getName();
499489
500 std::set RegSet;
501 for (unsigned i = 0, e = RC.Elements.size(); i != e; ++i) {
502 Record *Reg = RC.Elements[i];
503 RegSet.insert(Reg);
504 }
505
506490 OS << " // " << Name
507491 << " Register Class sub-classes...\n"
508492 << " static const TargetRegisterClass* const "
512496 for (unsigned rc2 = 0, e2 = RegisterClasses.size(); rc2 != e2; ++rc2) {
513497 const CodeGenRegisterClass &RC2 = RegisterClasses[rc2];
514498
515 // RC2 is a sub-class of RC if it is a valid replacement for any
516 // instruction operand where an RC register is required. It must satisfy
517 // these conditions:
518 //
519 // 1. All RC2 registers are also in RC.
520 // 2. The RC2 spill size must not be smaller that the RC spill size.
521 // 3. RC2 spill alignment must be compatible with RC.
522 //
523499 // Sub-classes are used to determine if a virtual register can be used
524500 // as an instruction operand, or if it must be copied first.
525
526 if (rc == rc2 || RC2.Elements.size() > RC.Elements.size() ||
527 (RC.SpillAlignment && RC2.SpillAlignment % RC.SpillAlignment) ||
528 RC.SpillSize > RC2.SpillSize || !isSubRegisterClass(RC2, RegSet))
529 continue;
501 if (rc == rc2 || !RC.hasSubClass(&RC2)) continue;
530502
531503 if (!Empty) OS << ", ";
532504 OS << "&" << getQualifiedName(RC2.TheDef) << "RegClass";