[llvm] r288647 - ListInit::convertInitializerTo: avoid foldingset lookup if nothing changed
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 4 22:41:48 PST 2016
Author: matze
Date: Mon Dec 5 00:41:47 2016
New Revision: 288647
URL: http://llvm.org/viewvc/llvm-project?rev=288647&view=rev
Log:
ListInit::convertInitializerTo: avoid foldingset lookup if nothing changed
Modified:
llvm/trunk/lib/TableGen/Record.cpp
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=288647&r1=288646&r2=288647&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Mon Dec 5 00:41:47 2016
@@ -533,19 +533,28 @@ void ListInit::Profile(FoldingSetNodeID
}
Init *ListInit::convertInitializerTo(RecTy *Ty) const {
+ if (getType() == Ty)
+ return const_cast<ListInit*>(this);
+
if (auto *LRT = dyn_cast<ListRecTy>(Ty)) {
std::vector<Init*> Elements;
+ Elements.reserve(getValues().size());
// Verify that all of the elements of the list are subclasses of the
// appropriate class!
+ bool Changed = false;
+ RecTy *ElementType = LRT->getElementType();
for (Init *I : getValues())
- if (Init *CI = I->convertInitializerTo(LRT->getElementType()))
+ if (Init *CI = I->convertInitializerTo(ElementType)) {
Elements.push_back(CI);
- else
+ if (CI != I)
+ Changed = true;
+ } else
return nullptr;
- if (isa<ListRecTy>(getType()))
- return ListInit::get(Elements, Ty);
+ if (!Changed)
+ return const_cast<ListInit*>(this);
+ return ListInit::get(Elements, Ty);
}
return nullptr;
More information about the llvm-commits
mailing list