Skip to content

Commit

Permalink
Extract a method.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146374 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
stoklund committed Dec 12, 2011
1 parent f931261 commit 1b3d218
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
35 changes: 21 additions & 14 deletions utils/TableGen/CodeGenRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,23 @@ void CodeGenRegBank::addToMaps(CodeGenRegisterClass *RC) {
Key2RC.insert(std::make_pair(K, RC));
}

// Create a synthetic sub-class if it is missing.
CodeGenRegisterClass*
CodeGenRegBank::getOrCreateSubClass(const CodeGenRegisterClass *RC,
const CodeGenRegister::Set *Members,
StringRef Name) {
// Synthetic sub-class has the same size and alignment as RC.
CodeGenRegisterClass::Key K(Members, RC->SpillSize, RC->SpillAlignment);
RCKeyMap::const_iterator FoundI = Key2RC.find(K);
if (FoundI != Key2RC.end())
return FoundI->second;

// Sub-class doesn't exist, create a new one.
CodeGenRegisterClass *NewRC = new CodeGenRegisterClass(Name, K);
addToMaps(NewRC);
return NewRC;
}

CodeGenRegisterClass *CodeGenRegBank::getRegClass(Record *Def) {
if (CodeGenRegisterClass *RC = Def2RC[Def])
return RC;
Expand Down Expand Up @@ -778,21 +795,11 @@ void CodeGenRegBank::computeInferredRegisterClasses() {
RC.setSubClassWithSubReg(SubIdx, &RC);
continue;
}

// This is a real subset. See if we have a matching class.
CodeGenRegisterClass::Key K(&I->second, RC.SpillSize, RC.SpillAlignment);
RCKeyMap::const_iterator FoundI = Key2RC.find(K);
if (FoundI != Key2RC.end()) {
RC.setSubClassWithSubReg(SubIdx, FoundI->second);
continue;
}

// Class doesn't exist.
CodeGenRegisterClass *NewRC =
new CodeGenRegisterClass(RC.getName() + "_with_" +
I->first->getName(), K);
addToMaps(NewRC);
RC.setSubClassWithSubReg(SubIdx, NewRC);
CodeGenRegisterClass *SubRC =
getOrCreateSubClass(&RC, &I->second,
RC.getName() + "_with_" + I->first->getName());
RC.setSubClassWithSubReg(SubIdx, SubRC);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions utils/TableGen/CodeGenRegisters.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ namespace llvm {
// Add RC to *2RC maps.
void addToMaps(CodeGenRegisterClass*);

// Create a synthetic sub-class if it is missing.
CodeGenRegisterClass *getOrCreateSubClass(const CodeGenRegisterClass *RC,
const CodeGenRegister::Set *Membs,
StringRef Name);

// Infer missing register classes.
void computeInferredRegisterClasses();

Expand Down

0 comments on commit 1b3d218

Please sign in to comment.