Refactor to use Target.getRegisterClasses consistently, which provides

anonymous regclass definition renaming.

Change the generated code to emit register classes as properly namespace
qualified entities like everything else.

expose the actual class definition as an object, though this isn't quite
usable yet.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22920 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-08-19 18:47:59 +00:00
parent d5aa3e26bb
commit 42de581b2f

View File

@ -61,16 +61,18 @@ void RegisterInfoEmitter::runHeader(std::ostream &OS) {
<< " const unsigned* getCalleeSaveRegs() const;\n" << " const unsigned* getCalleeSaveRegs() const;\n"
<< "};\n\n"; << "};\n\n";
std::vector<Record*> RegisterClasses = const std::vector<CodeGenRegisterClass> &RegisterClasses =
Records.getAllDerivedDefinitions("RegisterClass"); Target.getRegisterClasses();
OS << "namespace " << TargetName << " { // Register classes\n"; if (!RegisterClasses.empty()) {
for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i) { OS << "namespace " << RegisterClasses[0].Namespace
const std::string &Name = RegisterClasses[i]->getName(); << " { // Register classes\n";
if (Name.size() < 9 || Name[9] != '.') // Ignore anonymous classes for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i) {
OS << " extern TargetRegisterClass *" << Name << "RegisterClass;\n"; const std::string &Name = RegisterClasses[i].getName();
OS << " extern TargetRegisterClass * const "<< Name <<"RegisterClass;\n";
}
OS << "} // end of namespace " << TargetName << "\n\n";
} }
OS << "} // end of namespace " << TargetName << "\n\n";
OS << "} // End llvm namespace \n"; OS << "} // End llvm namespace \n";
} }
@ -90,7 +92,6 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
Target.getRegisterClasses(); Target.getRegisterClasses();
std::set<Record*> RegistersFound; std::set<Record*> RegistersFound;
std::vector<std::string> RegClassNames;
// Loop over all of the register classes... emitting each one. // Loop over all of the register classes... emitting each one.
OS << "namespace { // Register classes...\n"; OS << "namespace { // Register classes...\n";
@ -102,15 +103,10 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) { for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
const CodeGenRegisterClass &RC = RegisterClasses[rc]; const CodeGenRegisterClass &RC = RegisterClasses[rc];
std::string Name = RC.getName(); // Give the register class a legal C name if it's anonymous.
if (Name.size() > 9 && Name[9] == '.') { std::string Name = RC.TheDef->getName();
static unsigned AnonCounter = 0;
Name = "AnonRegClass_"+utostr(AnonCounter++); // Emit the register list now.
}
RegClassNames.push_back(Name);
// Emit the register list now...
OS << " // " << Name << " Register Class...\n const unsigned " << Name OS << " // " << Name << " Register Class...\n const unsigned " << Name
<< "[] = {\n "; << "[] = {\n ";
for (unsigned i = 0, e = RC.Elements.size(); i != e; ++i) { for (unsigned i = 0, e = RC.Elements.size(); i != e; ++i) {
@ -130,12 +126,25 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
<< " " << Name << "Class() : TargetRegisterClass(" << " " << Name << "Class() : TargetRegisterClass("
<< RC.SpillSize/8 << ", " << RC.SpillAlignment/8 << ", " << Name << ", " << RC.SpillSize/8 << ", " << RC.SpillAlignment/8 << ", " << Name << ", "
<< Name << " + " << RC.Elements.size() << ") {}\n" << Name << " + " << RC.Elements.size() << ") {}\n"
<< RC.MethodDefinitions << " } " << Name << "Instance;\n\n"; << RC.MethodDefinitions << " };\n\n";
}
OS << "} // end anonymous namespace\n\n";
// Now that all of the structs have been emitted, emit the instances.
if (!RegisterClasses.empty()) {
OS << "namespace " << RegisterClasses[0].Namespace
<< " { // Register class instances\n";
for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i)
OS << " " << RegisterClasses[i].getName() << "Class\t"
<< RegisterClasses[i].getName() << "RegClassInstance;\n";
OS << "}\n";
} }
OS << "\nnamespace {\n";
OS << " const TargetRegisterClass* const RegisterClasses[] = {\n"; OS << " const TargetRegisterClass* const RegisterClasses[] = {\n";
for (unsigned i = 0, e = RegClassNames.size(); i != e; ++i) for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i)
OS << " &" << RegClassNames[i] << "Instance,\n"; OS << " &" << getQualifiedName(RegisterClasses[i].TheDef)
<< "RegClassInstance,\n";
OS << " };\n"; OS << " };\n";
// Emit register class aliases... // Emit register class aliases...
@ -228,15 +237,16 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
OS << " };\n"; // End of register descriptors... OS << " };\n"; // End of register descriptors...
OS << "}\n\n"; // End of anonymous namespace... OS << "}\n\n"; // End of anonymous namespace...
OS << "namespace " << Target.getName() << " { // Register classes\n"; if (!RegisterClasses.empty()) {
for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i) { OS << "namespace " << RegisterClasses[0].Namespace
const std::string &Name = RegisterClasses[i].getName(); << " { // Register classes\n";
if (Name.size() < 9 || Name[9] != '.') // Ignore anonymous classes for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i) {
OS << " TargetRegisterClass *" << Name << "RegisterClass = &" OS << " TargetRegisterClass * const " << RegisterClasses[i].getName()
<< Name << "Instance;\n"; << "RegisterClass = &" << getQualifiedName(RegisterClasses[i].TheDef)
<< "RegClassInstance;\n";
}
OS << "} // end of namespace " << RegisterClasses[0].Namespace << "\n\n";
} }
OS << "} // end of namespace " << Target.getName() << "\n\n";
std::string ClassName = Target.getName() + "GenRegisterInfo"; std::string ClassName = Target.getName() + "GenRegisterInfo";
@ -245,7 +255,7 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
OS << ClassName << "::" << ClassName OS << ClassName << "::" << ClassName
<< "(int CallFrameSetupOpcode, int CallFrameDestroyOpcode)\n" << "(int CallFrameSetupOpcode, int CallFrameDestroyOpcode)\n"
<< " : MRegisterInfo(RegisterDescriptors, " << Registers.size()+1 << " : MRegisterInfo(RegisterDescriptors, " << Registers.size()+1
<< ", RegisterClasses, RegisterClasses+" << RegClassNames.size() << ",\n " << ", RegisterClasses, RegisterClasses+" << RegisterClasses.size() <<",\n "
<< " CallFrameSetupOpcode, CallFrameDestroyOpcode) {}\n\n"; << " CallFrameSetupOpcode, CallFrameDestroyOpcode) {}\n\n";
// Emit the getCalleeSaveRegs method... // Emit the getCalleeSaveRegs method...