From d2cc6c2d0c2f8a6e272110416a3fd579ed5a3ac1 Mon Sep 17 00:00:00 2001 From: Serge Guelton Date: Mon, 3 Jan 2022 13:32:19 -0500 Subject: Use a sorted array instead of a map to store AttrBuilder string attributes Using and std::map for target dependent attributes is inefficient: it makes its constructor slightly heavier, and involves extra allocation for each new string attribute. Storing the attribute key/value as strings implies extra allocation/copy step. Use a sorted vector instead. Given the low number of attributes generally involved, this is cheaper, as showcased by https://llvm-compile-time-tracker.com/compare.php?from=5de322295f4ade692dc4f1823ae4450ad3c48af2&to=05bc480bf641a9e3b466619af43a2d123ee3f71d&stat=instructions Differential Revision: https://reviews.llvm.org/D116599 --- clang/lib/CodeGen/CodeGenModule.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 79e7197d0e0a..6d6f154f45bf 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1819,7 +1819,7 @@ CodeGenModule::getMostBaseClasses(const CXXRecordDecl *RD) { void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F) { - llvm::AttrBuilder B; + llvm::AttrBuilder B(F->getContext()); if (CodeGenOpts.UnwindTables) B.addAttribute(llvm::Attribute::UWTable); @@ -1982,7 +1982,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, void CodeGenModule::setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F) { if (D->hasAttr()) { - llvm::AttrBuilder FuncAttrs; + llvm::AttrBuilder FuncAttrs(F->getContext()); FuncAttrs.addAttribute("strictfp"); F->addFnAttrs(FuncAttrs); } @@ -2092,7 +2092,7 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, if (!D->getAttr()) F->addFnAttr("implicit-section-name", SA->getName()); - llvm::AttrBuilder Attrs; + llvm::AttrBuilder Attrs(F->getContext()); if (GetCPUAndFeaturesAttributes(GD, Attrs)) { // We know that GetCPUAndFeaturesAttributes will always have the // newest set, since it has the newest possible FunctionDecl, so the @@ -3785,7 +3785,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction( if (D) SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk); if (ExtraAttrs.hasFnAttrs()) { - llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeList::FunctionIndex); + llvm::AttrBuilder B(F->getContext(), ExtraAttrs, llvm::AttributeList::FunctionIndex); F->addFnAttrs(B); } -- cgit v1.2.3