mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[TableGen] Correct Namespace lookup with AltNames in AsmWriterEmitter
AsmWriterEmitter will generate a getRegisterName function with an alternate register name index as its second argument if the target makes use of them. The enum of these values is generated in RegisterInfoEmitter. The getRegisterName generator would assume the namespace could always be found by reading index 1 of the list of AltNameIndices, but this will fail if this list is sorted such that the NoRegAltName is at index 1. Because this list is sorted by record name (in CodeGenTarget::ReadRegAltNameIndices), you only run in to problems if your MyTargetRegisterInfo.td defines a single RegAltNameIndex that sorts lexically before NoRegAltName. For example, if a target has something like def AnAltNameIndex : RegAltNameIndex and defines RegAltNameIndices for some registers then, prior to this change, AsmWriterEmitter would generate references to ::AnAltNameIndex and ::NoRegAltName Patch by Alex Bradbury! llvm-svn: 255344
This commit is contained in:
parent
8b6635b2f6
commit
94fa3b65bf
@ -586,6 +586,8 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) {
|
||||
const auto &Registers = Target.getRegBank().getRegisters();
|
||||
std::vector<Record*> AltNameIndices = Target.getRegAltNameIndices();
|
||||
bool hasAltNames = AltNameIndices.size() > 1;
|
||||
std::string Namespace =
|
||||
Registers.front().TheDef->getValueAsString("Namespace");
|
||||
|
||||
O <<
|
||||
"\n\n/// getRegisterName - This method is automatically generated by tblgen\n"
|
||||
@ -610,9 +612,9 @@ void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) {
|
||||
O << " switch(AltIdx) {\n"
|
||||
<< " default: llvm_unreachable(\"Invalid register alt name index!\");\n";
|
||||
for (unsigned i = 0, e = AltNameIndices.size(); i < e; ++i) {
|
||||
std::string Namespace = AltNameIndices[1]->getValueAsString("Namespace");
|
||||
std::string AltName(AltNameIndices[i]->getName());
|
||||
O << " case " << Namespace << "::" << AltName << ":\n"
|
||||
std::string Prefix = !Namespace.empty() ? Namespace + "::" : "";
|
||||
O << " case " << Prefix << AltName << ":\n"
|
||||
<< " assert(*(AsmStrs" << AltName << "+RegAsmOffset"
|
||||
<< AltName << "[RegNo-1]) &&\n"
|
||||
<< " \"Invalid alt name index for register!\");\n"
|
||||
|
Loading…
Reference in New Issue
Block a user