Minor performance tweaks to llvm-tblgen (and a few that might be a good idea)

Summary:
This patch adds a reserve call to an expensive function
(`llvm::LoadIntrinsics`), and may fix a few other low hanging
performance fruit (I've put them in comments for now, so we can
discuss).

**Motivation:**

As I'm sure other developers do, when I build LLVM, I build the entire
project with the same config (`Debug`, `MinSizeRel`, `Release`, or
`RelWithDebInfo`). However, the `Debug` config also builds llvm-tblgen
in `Debug` mode. Later build steps that run llvm-tblgen then can
actually be the slowest steps in the entire build. Nobody likes slow
builds.

Reviewers: rnk, dblaikie

Differential Revision: http://reviews.llvm.org/D16832

Patch by Alexander G. Riccio

llvm-svn: 259683
This commit is contained in:
Reid Kleckner 2016-02-03 19:34:28 +00:00
parent f42ef3efca
commit 45b6159ed3
3 changed files with 12 additions and 4 deletions

View File

@ -1307,9 +1307,14 @@ public:
}
bool isSubClassOf(StringRef Name) const {
for (const auto &SCPair : SuperClasses)
if (SCPair.first->getNameInitAsString() == Name)
for (const auto &SCPair : SuperClasses) {
if (const auto *SI = dyn_cast<StringInit>(SCPair.first->getNameInit())) {
if (SI->getValue() == Name)
return true;
} else if (SCPair.first->getNameInitAsString() == Name) {
return true;
}
}
return false;
}

View File

@ -49,7 +49,9 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) {
unsigned MIOperandNo = 0;
std::set<std::string> OperandNames;
for (unsigned i = 0, e = InDI->getNumArgs()+OutDI->getNumArgs(); i != e; ++i){
unsigned e = InDI->getNumArgs() + OutDI->getNumArgs();
OperandList.reserve(e);
for (unsigned i = 0; i != e; ++i){
Init *ArgInit;
std::string ArgName;
if (i < NumDefs) {

View File

@ -441,6 +441,7 @@ std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC,
std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
std::vector<CodeGenIntrinsic> Result;
Result.reserve(I.size());
for (unsigned i = 0, e = I.size(); i != e; ++i) {
bool isTarget = I[i]->getValueAsBit("isTarget");
@ -448,7 +449,7 @@ std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC,
Result.push_back(CodeGenIntrinsic(I[i]));
}
std::sort(Result.begin(), Result.end(),
[](CodeGenIntrinsic LHS, CodeGenIntrinsic RHS) {
[](const CodeGenIntrinsic& LHS, const CodeGenIntrinsic& RHS) {
return LHS.Name < RHS.Name;
});
return Result;