mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-24 20:29:53 +00:00
Make synthesized sub-register indexes available in the target namespace.
TableGen sometimes synthesizes missing sub-register indexes. Emit these indexes as enumerators in the target namespace along with the user-defined ones. Also take this opportunity to stop creating new Record objects for synthetic indexes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161964 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a99c508c8d
commit
c97eda2c9e
@ -28,19 +28,15 @@ using namespace llvm;
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
CodeGenSubRegIndex::CodeGenSubRegIndex(Record *R, unsigned Enum)
|
||||
: TheDef(R),
|
||||
EnumValue(Enum)
|
||||
{}
|
||||
|
||||
std::string CodeGenSubRegIndex::getNamespace() const {
|
||||
if (TheDef->getValue("Namespace"))
|
||||
return TheDef->getValueAsString("Namespace");
|
||||
else
|
||||
return "";
|
||||
: TheDef(R), EnumValue(Enum) {
|
||||
Name = R->getName();
|
||||
if (R->getValue("Namespace"))
|
||||
Namespace = R->getValueAsString("Namespace");
|
||||
}
|
||||
|
||||
const std::string &CodeGenSubRegIndex::getName() const {
|
||||
return TheDef->getName();
|
||||
CodeGenSubRegIndex::CodeGenSubRegIndex(StringRef N, StringRef Nspace,
|
||||
unsigned Enum)
|
||||
: TheDef(0), Name(N), Namespace(Nspace), EnumValue(Enum) {
|
||||
}
|
||||
|
||||
std::string CodeGenSubRegIndex::getQualifiedName() const {
|
||||
@ -52,6 +48,8 @@ std::string CodeGenSubRegIndex::getQualifiedName() const {
|
||||
}
|
||||
|
||||
void CodeGenSubRegIndex::updateComponents(CodeGenRegBank &RegBank) {
|
||||
if (!TheDef)
|
||||
return;
|
||||
std::vector<Record*> Comps = TheDef->getValueAsListOfDefs("ComposedOf");
|
||||
if (Comps.empty())
|
||||
return;
|
||||
@ -937,7 +935,7 @@ void CodeGenRegisterClass::buildRegUnitSet(
|
||||
// CodeGenRegBank
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) : Records(Records) {
|
||||
CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) {
|
||||
// Configure register Sets to understand register classes and tuples.
|
||||
Sets.addFieldExpander("RegisterClass", "MemberList");
|
||||
Sets.addFieldExpander("CalleeSavedRegs", "SaveList");
|
||||
@ -947,7 +945,6 @@ CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) : Records(Records) {
|
||||
// More indices will be synthesized later.
|
||||
std::vector<Record*> SRIs = Records.getAllDerivedDefinitions("SubRegIndex");
|
||||
std::sort(SRIs.begin(), SRIs.end(), LessRecord());
|
||||
NumNamedIndices = SRIs.size();
|
||||
for (unsigned i = 0, e = SRIs.size(); i != e; ++i)
|
||||
getSubRegIdx(SRIs[i]);
|
||||
// Build composite maps from ComposedOf fields.
|
||||
@ -1015,6 +1012,15 @@ CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) : Records(Records) {
|
||||
CodeGenRegisterClass::computeSubClasses(*this);
|
||||
}
|
||||
|
||||
// Create a synthetic CodeGenSubRegIndex without a corresponding Record.
|
||||
CodeGenSubRegIndex*
|
||||
CodeGenRegBank::createSubRegIndex(StringRef Name, StringRef Namespace) {
|
||||
CodeGenSubRegIndex *Idx = new CodeGenSubRegIndex(Name, Namespace,
|
||||
SubRegIndices.size() + 1);
|
||||
SubRegIndices.push_back(Idx);
|
||||
return Idx;
|
||||
}
|
||||
|
||||
CodeGenSubRegIndex *CodeGenRegBank::getSubRegIdx(Record *Def) {
|
||||
CodeGenSubRegIndex *&Idx = Def2SubRegIdx[Def];
|
||||
if (Idx)
|
||||
@ -1079,7 +1085,7 @@ CodeGenRegBank::getCompositeSubRegIndex(CodeGenSubRegIndex *A,
|
||||
|
||||
// None exists, synthesize one.
|
||||
std::string Name = A->getName() + "_then_" + B->getName();
|
||||
Comp = getSubRegIdx(new Record(Name, SMLoc(), Records));
|
||||
Comp = createSubRegIndex(Name, A->getNamespace());
|
||||
A->addComposite(B, Comp);
|
||||
return Comp;
|
||||
}
|
||||
@ -1099,7 +1105,7 @@ getConcatSubRegIndex(const SmallVector<CodeGenSubRegIndex*, 8> &Parts) {
|
||||
Name += '_';
|
||||
Name += Parts[i]->getName();
|
||||
}
|
||||
return Idx = getSubRegIdx(new Record(Name, SMLoc(), Records));
|
||||
return Idx = createSubRegIndex(Name, Parts.front()->getNamespace());
|
||||
}
|
||||
|
||||
void CodeGenRegBank::computeComposites() {
|
||||
|
@ -35,14 +35,17 @@ namespace llvm {
|
||||
/// CodeGenSubRegIndex - Represents a sub-register index.
|
||||
class CodeGenSubRegIndex {
|
||||
Record *const TheDef;
|
||||
std::string Name;
|
||||
std::string Namespace;
|
||||
|
||||
public:
|
||||
const unsigned EnumValue;
|
||||
|
||||
CodeGenSubRegIndex(Record *R, unsigned Enum);
|
||||
CodeGenSubRegIndex(StringRef N, StringRef Nspace, unsigned Enum);
|
||||
|
||||
const std::string &getName() const;
|
||||
std::string getNamespace() const;
|
||||
const std::string &getName() const { return Name; }
|
||||
const std::string &getNamespace() const { return Namespace; }
|
||||
std::string getQualifiedName() const;
|
||||
|
||||
// Order CodeGenSubRegIndex pointers by EnumValue.
|
||||
@ -422,13 +425,13 @@ namespace llvm {
|
||||
// CodeGenRegBank - Represent a target's registers and the relations between
|
||||
// them.
|
||||
class CodeGenRegBank {
|
||||
RecordKeeper &Records;
|
||||
SetTheory Sets;
|
||||
|
||||
// SubRegIndices.
|
||||
std::vector<CodeGenSubRegIndex*> SubRegIndices;
|
||||
DenseMap<Record*, CodeGenSubRegIndex*> Def2SubRegIdx;
|
||||
unsigned NumNamedIndices;
|
||||
|
||||
CodeGenSubRegIndex *createSubRegIndex(StringRef Name, StringRef NameSpace);
|
||||
|
||||
typedef std::map<SmallVector<CodeGenSubRegIndex*, 8>,
|
||||
CodeGenSubRegIndex*> ConcatIdxMap;
|
||||
@ -495,7 +498,6 @@ namespace llvm {
|
||||
// in the .td files. The rest are synthesized such that all sub-registers
|
||||
// have a unique name.
|
||||
ArrayRef<CodeGenSubRegIndex*> getSubRegIndices() { return SubRegIndices; }
|
||||
unsigned getNumNamedIndices() { return NumNamedIndices; }
|
||||
|
||||
// Find a SubRegIndex form its Record def.
|
||||
CodeGenSubRegIndex *getSubRegIdx(Record*);
|
||||
|
@ -145,9 +145,9 @@ void RegisterInfoEmitter::runEnums(raw_ostream &OS,
|
||||
if (!Namespace.empty())
|
||||
OS << "namespace " << Namespace << " {\n";
|
||||
OS << "enum {\n NoSubRegister,\n";
|
||||
for (unsigned i = 0, e = Bank.getNumNamedIndices(); i != e; ++i)
|
||||
for (unsigned i = 0, e = SubRegIndices.size(); i != e; ++i)
|
||||
OS << " " << SubRegIndices[i]->getName() << ",\t// " << i+1 << "\n";
|
||||
OS << " NUM_TARGET_NAMED_SUBREGS\n};\n";
|
||||
OS << " NUM_TARGET_SUBREGS\n};\n";
|
||||
if (!Namespace.empty())
|
||||
OS << "}\n";
|
||||
}
|
||||
@ -885,17 +885,6 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
|
||||
}
|
||||
OS << "\" };\n\n";
|
||||
|
||||
// Emit names of the anonymous subreg indices.
|
||||
unsigned NamedIndices = RegBank.getNumNamedIndices();
|
||||
if (SubRegIndices.size() > NamedIndices) {
|
||||
OS << " enum {";
|
||||
for (unsigned i = NamedIndices, e = SubRegIndices.size(); i != e; ++i) {
|
||||
OS << "\n " << SubRegIndices[i]->getName() << " = " << i+1;
|
||||
if (i+1 != e)
|
||||
OS << ',';
|
||||
}
|
||||
OS << "\n };\n\n";
|
||||
}
|
||||
OS << "\n";
|
||||
|
||||
// Now that all of the structs have been emitted, emit the instances.
|
||||
|
Loading…
Reference in New Issue
Block a user