[AsmParser] Avoid instantiating LLVMContext if not needed. NFC
authorYevgeny Rouban <yrouban@azul.com>
Mon, 20 Mar 2023 07:54:10 +0000 (14:54 +0700)
committerYevgeny Rouban <yrouban@azul.com>
Mon, 20 Mar 2023 07:56:57 +0000 (14:56 +0700)
Differential Revision: https://reviews.llvm.org/D142699

llvm/lib/AsmParser/Parser.cpp

index 035eea8..eded892 100644 (file)
@@ -28,9 +28,9 @@ static bool parseAssemblyInto(MemoryBufferRef F, Module *M,
   std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F);
   SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
 
-  LLVMContext Context;
+  std::optional<LLVMContext> OptContext;
   return LLParser(F.getBuffer(), SM, Err, M, Index,
-                  M ? M->getContext() : Context, Slots)
+                  M ? M->getContext() : OptContext.emplace(), Slots)
       .Run(UpgradeDebugInfo, DataLayoutCallback);
 }