From 8c8bbdcc14d36fcb349b58626e5970d3bce529b6 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 5 Dec 2016 06:41:47 +0000 Subject: [PATCH] ListInit::convertInitializerTo: avoid foldingset lookup if nothing changed llvm-svn: 288647 --- lib/TableGen/Record.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 2875375f4cd..de13cd2246a 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -533,19 +533,28 @@ void ListInit::Profile(FoldingSetNodeID &ID) const { } Init *ListInit::convertInitializerTo(RecTy *Ty) const { + if (getType() == Ty) + return const_cast(this); + if (auto *LRT = dyn_cast(Ty)) { std::vector 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(getType())) - return ListInit::get(Elements, Ty); + if (!Changed) + return const_cast(this); + return ListInit::get(Elements, Ty); } return nullptr;