Skip to content

Commit 4558842

Browse files
committed
[OPENMP]Reduce calls for the mangled names.
Use canonical decls instead of mangled names in the set of already emitted decls. This allows to reduce the number of function calls for getting declarations mangled names and speedup the compilation.
1 parent acd2580 commit 4558842

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9659,9 +9659,9 @@ bool CGOpenMPRuntime::emitTargetFunctions(GlobalDecl GD) {
96599659
}
96609660

96619661
const ValueDecl *VD = cast<ValueDecl>(GD.getDecl());
9662-
StringRef Name = CGM.getMangledName(GD);
96639662
// Try to detect target regions in the function.
96649663
if (const auto *FD = dyn_cast<FunctionDecl>(VD)) {
9664+
StringRef Name = CGM.getMangledName(GD);
96659665
scanForTargetRegionsFunctions(FD->getBody(), Name);
96669666
Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
96679667
OMPDeclareTargetDeclAttr::getDeviceType(FD);
@@ -9672,7 +9672,7 @@ bool CGOpenMPRuntime::emitTargetFunctions(GlobalDecl GD) {
96729672

96739673
// Do not to emit function if it is not marked as declare target.
96749674
return !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD) &&
9675-
AlreadyEmittedTargetFunctions.count(Name) == 0;
9675+
AlreadyEmittedTargetDecls.count(VD) == 0;
96769676
}
96779677

96789678
bool CGOpenMPRuntime::emitTargetGlobalVariable(GlobalDecl GD) {
@@ -9903,20 +9903,20 @@ bool CGOpenMPRuntime::markAsGlobalTarget(GlobalDecl GD) {
99039903
if (!CGM.getLangOpts().OpenMPIsDevice || !ShouldMarkAsGlobal)
99049904
return true;
99059905

9906-
StringRef Name = CGM.getMangledName(GD);
99079906
const auto *D = cast<FunctionDecl>(GD.getDecl());
99089907
// Do not to emit function if it is marked as declare target as it was already
99099908
// emitted.
99109909
if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(D)) {
9911-
if (D->hasBody() && AlreadyEmittedTargetFunctions.count(Name) == 0) {
9912-
if (auto *F = dyn_cast_or_null<llvm::Function>(CGM.GetGlobalValue(Name)))
9910+
if (D->hasBody() && AlreadyEmittedTargetDecls.count(D) == 0) {
9911+
if (auto *F = dyn_cast_or_null<llvm::Function>(
9912+
CGM.GetGlobalValue(CGM.getMangledName(GD))))
99139913
return !F->isDeclaration();
99149914
return false;
99159915
}
99169916
return true;
99179917
}
99189918

9919-
return !AlreadyEmittedTargetFunctions.insert(Name).second;
9919+
return !AlreadyEmittedTargetDecls.insert(D).second;
99209920
}
99219921

99229922
llvm::Function *CGOpenMPRuntime::emitRequiresDirectiveRegFun() {

clang/lib/CodeGen/CGOpenMPRuntime.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clang/Basic/OpenMPKinds.h"
2121
#include "clang/Basic/SourceLocation.h"
2222
#include "llvm/ADT/DenseMap.h"
23+
#include "llvm/ADT/SmallPtrSet.h"
2324
#include "llvm/ADT/StringMap.h"
2425
#include "llvm/ADT/StringSet.h"
2526
#include "llvm/Frontend/OpenMP/OMPConstants.h"
@@ -672,8 +673,8 @@ class CGOpenMPRuntime {
672673
OffloadEntriesInfoManagerTy OffloadEntriesInfoManager;
673674

674675
bool ShouldMarkAsGlobal = true;
675-
/// List of the emitted functions.
676-
llvm::StringSet<> AlreadyEmittedTargetFunctions;
676+
/// List of the emitted declarations.
677+
llvm::DenseSet<CanonicalDeclPtr<const Decl>> AlreadyEmittedTargetDecls;
677678
/// List of the global variables with their addresses that should not be
678679
/// emitted for the target.
679680
llvm::StringMap<llvm::WeakTrackingVH> EmittedNonTargetVariables;

0 commit comments

Comments
 (0)