Index: llvm/test/TableGen/Common/reg-with-subregs-common.td =================================================================== --- llvm/test/TableGen/Common/reg-with-subregs-common.td +++ llvm/test/TableGen/Common/reg-with-subregs-common.td @@ -16,6 +16,9 @@ !listconcat(acc, !if(!lt(cur, N), [cur], []))); } +#ifdef USE_NAMESPACE + let Namespace = "TestNamespace" in { +#endif foreach Index = 0-31 in { def sub#Index : SubRegIndex<32, !shl(Index, 5)>; } @@ -35,6 +38,9 @@ foreach Index = 0-255 in { def R#Index : Register <"r"#Index>; } +#ifdef USE_NAMESPACE +} +#endif def GPR32 : RegisterClass<"TestTarget", [i32], 32, (add (sequence "R%u", 0, 255))>; @@ -124,5 +130,11 @@ (decimate (shl GPR32, 31), 1) ]>; +#ifdef USE_NAMESPACE + let Namespace = "TestNamespace" in { +#endif def GPR_64 : RegisterClass<"", [v2i32], 64, (add GPR64)>; def GPR_1024 : RegisterClass<"", [v32i32], 1024, (add GPR1024)>; +#ifdef USE_NAMESPACE +} +#endif Index: llvm/test/TableGen/pset-enum.td =================================================================== --- /dev/null +++ llvm/test/TableGen/pset-enum.td @@ -0,0 +1,11 @@ +// RUN: llvm-tblgen -gen-register-info -I %p/../../include -I %p/Common %s | FileCheck %s +// RUN: llvm-tblgen -gen-register-info -I %p/../../include -I %p/Common -DUSE_NAMESPACE %s | FileCheck --check-prefixes=CHECK,NAMESPACE %s + +include "reg-with-subregs-common.td" + +// CHECK-LABEL: // Register pressure sets enum. +// NAMESPACE-NEXT: namespace TestNamespace { +// CHECK-NEXT: enum RegisterPressureSets { +// CHECK-NEXT: GPR32 = 0, +// CHECK-NEXT: }; +// NAMESPACE-NEXT: } // end namespace TestNamespace Index: llvm/utils/TableGen/RegisterInfoEmitter.cpp =================================================================== --- llvm/utils/TableGen/RegisterInfoEmitter.cpp +++ llvm/utils/TableGen/RegisterInfoEmitter.cpp @@ -98,6 +98,16 @@ } // end anonymous namespace +static std::string getLegalCName(std::string Name) { + static const char legal_elements[] = + "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + std::string::size_type pos = 0; + while ((pos = Name.find_first_not_of(legal_elements, pos)) != + std::string::npos) + Name.replace(pos, 1, "_"); + return Name; +} + // runEnums - Print out enum values for all of the registers. void RegisterInfoEmitter::runEnums(raw_ostream &OS, CodeGenTarget &Target, CodeGenRegBank &Bank) { @@ -182,6 +192,20 @@ OS << "} // end namespace " << Namespace << "\n\n"; } + OS << "// Register pressure sets enum.\n"; + if (!Namespace.empty()) + OS << "namespace " << Namespace << " {\n"; + OS << "enum RegisterPressureSets {\n"; + unsigned NumSets = Bank.getNumRegPressureSets(); + for (unsigned i = 0; i < NumSets; ++i ) { + const RegUnitSet &RegUnits = Bank.getRegSetAt(i); + OS << " " << getLegalCName(RegUnits.Name) << " = " << i << ",\n"; + } + OS << "};\n"; + if (!Namespace.empty()) + OS << "} // end namespace " << Namespace << '\n'; + OS << '\n'; + OS << "} // end namespace llvm\n\n"; OS << "#endif // GET_REGINFO_ENUM\n\n"; }