From cd7f205ade20915e16c70a22687af5c3c0ea8923 Mon Sep 17 00:00:00 2001 From: Martin Boehme Date: Fri, 24 Apr 2020 17:19:19 +0200 Subject: [PATCH] [IRGen] Check as early as possible for Clang decls we've seen before. Previously, we were only doing this after the fast-path code that handles decls without any executable code. This meant, however, that we were potentially processing these decls multiple times. This is definitely inefficient; it may even be a correctness issue, depending on what amount of checking `HandleTopLevelDecl` does to see if it has processed a particular decl before (which I'm not sure about either way). --- lib/IRGen/GenClangDecl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/IRGen/GenClangDecl.cpp b/lib/IRGen/GenClangDecl.cpp index 00b5a0e697352..b281db94a0298 100644 --- a/lib/IRGen/GenClangDecl.cpp +++ b/lib/IRGen/GenClangDecl.cpp @@ -37,6 +37,10 @@ class ClangDeclRefFinder } // end anonymous namespace void IRGenModule::emitClangDecl(const clang::Decl *decl) { + // Ignore this decl if we've seen it before. + if (!GlobalClangDecls.insert(decl->getCanonicalDecl()).second) + return; + auto valueDecl = dyn_cast(decl); if (!valueDecl || valueDecl->isExternallyVisible()) { ClangCodeGen->HandleTopLevelDecl( @@ -44,8 +48,6 @@ void IRGenModule::emitClangDecl(const clang::Decl *decl) { return; } - if (!GlobalClangDecls.insert(decl->getCanonicalDecl()).second) - return; SmallVector stack; stack.push_back(decl);