Don't override subreg functions in targets without subregisters.

Some targets have no sub-registers at all. Use the TargetRegisterInfo
versions of composeSubRegIndices(), getSubClassWithSubReg(), and
getMatchingSuperRegClass() for those targets.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156075 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen 2012-05-03 16:26:20 +00:00
parent 71d56462a1
commit 309076ff76
2 changed files with 46 additions and 44 deletions

View File

@ -421,7 +421,9 @@ public:
/// TableGen will synthesize missing A sub-classes. /// TableGen will synthesize missing A sub-classes.
virtual const TargetRegisterClass * virtual const TargetRegisterClass *
getMatchingSuperRegClass(const TargetRegisterClass *A, getMatchingSuperRegClass(const TargetRegisterClass *A,
const TargetRegisterClass *B, unsigned Idx) const =0; const TargetRegisterClass *B, unsigned Idx) const {
llvm_unreachable("Target has no sub-registers");
}
/// getSubClassWithSubReg - Returns the largest legal sub-class of RC that /// getSubClassWithSubReg - Returns the largest legal sub-class of RC that
/// supports the sub-register index Idx. /// supports the sub-register index Idx.
@ -436,7 +438,10 @@ public:
/// ///
/// TableGen will synthesize missing RC sub-classes. /// TableGen will synthesize missing RC sub-classes.
virtual const TargetRegisterClass * virtual const TargetRegisterClass *
getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const =0; getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const {
assert(Idx == 0 && "Target has no sub-registers");
return RC;
}
/// composeSubRegIndices - Return the subregister index you get from composing /// composeSubRegIndices - Return the subregister index you get from composing
/// two subregister indices. /// two subregister indices.

View File

@ -672,14 +672,16 @@ RegisterInfoEmitter::runTargetHeader(raw_ostream &OS, CodeGenTarget &Target,
<< " explicit " << ClassName << " explicit " << ClassName
<< "(unsigned RA, unsigned D = 0, unsigned E = 0);\n" << "(unsigned RA, unsigned D = 0, unsigned E = 0);\n"
<< " virtual bool needsStackRealignment(const MachineFunction &) const\n" << " virtual bool needsStackRealignment(const MachineFunction &) const\n"
<< " { return false; }\n" << " { return false; }\n";
<< " unsigned composeSubRegIndices(unsigned, unsigned) const;\n" if (!RegBank.getSubRegIndices().empty()) {
OS << " unsigned composeSubRegIndices(unsigned, unsigned) const;\n"
<< " const TargetRegisterClass *" << " const TargetRegisterClass *"
"getSubClassWithSubReg(const TargetRegisterClass*, unsigned) const;\n" "getSubClassWithSubReg(const TargetRegisterClass*, unsigned) const;\n"
<< " const TargetRegisterClass *getMatchingSuperRegClass(" << " const TargetRegisterClass *getMatchingSuperRegClass("
"const TargetRegisterClass*, const TargetRegisterClass*, " "const TargetRegisterClass*, const TargetRegisterClass*, "
"unsigned) const;\n" "unsigned) const;\n";
<< " const RegClassWeight &getRegClassWeight(" }
OS << " const RegClassWeight &getRegClassWeight("
<< "const TargetRegisterClass *RC) const;\n" << "const TargetRegisterClass *RC) const;\n"
<< " unsigned getNumRegPressureSets() const;\n" << " unsigned getNumRegPressureSets() const;\n"
<< " const char *getRegPressureSetName(unsigned Idx) const;\n" << " const char *getRegPressureSetName(unsigned Idx) const;\n"
@ -945,6 +947,7 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
std::string ClassName = Target.getName() + "GenRegisterInfo"; std::string ClassName = Target.getName() + "GenRegisterInfo";
// Emit composeSubRegIndices // Emit composeSubRegIndices
if (!SubRegIndices.empty()) {
OS << "unsigned " << ClassName OS << "unsigned " << ClassName
<< "::composeSubRegIndices(unsigned IdxA, unsigned IdxB) const {\n" << "::composeSubRegIndices(unsigned IdxA, unsigned IdxB) const {\n"
<< " switch (IdxA) {\n" << " switch (IdxA) {\n"
@ -967,15 +970,13 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
OS << " }\n"; OS << " }\n";
} }
OS << " }\n}\n\n"; OS << " }\n}\n\n";
}
// Emit getSubClassWithSubReg. // Emit getSubClassWithSubReg.
if (!SubRegIndices.empty()) {
OS << "const TargetRegisterClass *" << ClassName OS << "const TargetRegisterClass *" << ClassName
<< "::getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx)" << "::getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx)"
" const {\n"; << " const {\n";
if (SubRegIndices.empty()) {
OS << " assert(Idx == 0 && \"Target has no sub-registers\");\n"
<< " return RC;\n";
} else {
// Use the smallest type that can hold a regclass ID with room for a // Use the smallest type that can hold a regclass ID with room for a
// sentinel. // sentinel.
if (RegisterClasses.size() < UINT8_MAX) if (RegisterClasses.size() < UINT8_MAX)
@ -1002,17 +1003,14 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
<< " if (!Idx) return RC;\n --Idx;\n" << " if (!Idx) return RC;\n --Idx;\n"
<< " assert(Idx < " << SubRegIndices.size() << " && \"Bad subreg\");\n" << " assert(Idx < " << SubRegIndices.size() << " && \"Bad subreg\");\n"
<< " unsigned TV = Table[RC->getID()][Idx];\n" << " unsigned TV = Table[RC->getID()][Idx];\n"
<< " return TV ? getRegClass(TV - 1) : 0;\n"; << " return TV ? getRegClass(TV - 1) : 0;\n}\n\n";
} }
OS << "}\n\n";
// Emit getMatchingSuperRegClass. // Emit getMatchingSuperRegClass.
if (!SubRegIndices.empty()) {
OS << "const TargetRegisterClass *" << ClassName OS << "const TargetRegisterClass *" << ClassName
<< "::getMatchingSuperRegClass(const TargetRegisterClass *A," << "::getMatchingSuperRegClass(const TargetRegisterClass *A,"
" const TargetRegisterClass *B, unsigned Idx) const {\n"; << " const TargetRegisterClass *B, unsigned Idx) const {\n";
if (SubRegIndices.empty()) {
OS << " llvm_unreachable(\"Target has no sub-registers\");\n";
} else {
// We need to find the largest sub-class of A such that every register has // We need to find the largest sub-class of A such that every register has
// an Idx sub-register in B. Map (B, Idx) to a bit-vector of // an Idx sub-register in B. Map (B, Idx) to a bit-vector of
// super-register classes that map into B. Then compute the largest common // super-register classes that map into B. Then compute the largest common
@ -1047,9 +1045,8 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
<< " for (unsigned i = 0; i != " << BVWords << "; ++i)\n" << " for (unsigned i = 0; i != " << BVWords << "; ++i)\n"
<< " if (unsigned Common = TV[i] & SC[i])\n" << " if (unsigned Common = TV[i] & SC[i])\n"
<< " return getRegClass(32*i + CountTrailingZeros_32(Common));\n" << " return getRegClass(32*i + CountTrailingZeros_32(Common));\n"
<< " return 0;\n"; << " return 0;\n}\n\n";
} }
OS << "}\n\n";
EmitRegUnitPressure(OS, RegBank, ClassName); EmitRegUnitPressure(OS, RegBank, ClassName);