Skip to content

Commit 48f5748

Browse files
committed
[clang][NFC] Lazily create clang offload bundler timer group
1 parent a46e7a4 commit 48f5748

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/Support/ErrorOr.h"
3838
#include "llvm/Support/FileSystem.h"
3939
#include "llvm/Support/MD5.h"
40+
#include "llvm/Support/ManagedStatic.h"
4041
#include "llvm/Support/MemoryBuffer.h"
4142
#include "llvm/Support/Path.h"
4243
#include "llvm/Support/Program.h"
@@ -63,9 +64,17 @@ using namespace llvm;
6364
using namespace llvm::object;
6465
using namespace clang;
6566

66-
static llvm::TimerGroup
67-
ClangOffloadBundlerTimerGroup("Clang Offload Bundler Timer Group",
68-
"Timer group for clang offload bundler");
67+
namespace {
68+
struct CreateClangOffloadBundlerTimerGroup {
69+
static void *call() {
70+
return new TimerGroup("Clang Offload Bundler Timer Group",
71+
"Timer group for clang offload bundler");
72+
}
73+
};
74+
} // namespace
75+
static llvm::ManagedStatic<llvm::TimerGroup,
76+
CreateClangOffloadBundlerTimerGroup>
77+
ClangOffloadBundlerTimerGroup;
6978

7079
/// Magic string that marks the existence of offloading data.
7180
#define OFFLOAD_BUNDLER_MAGIC_STR "__CLANG_OFFLOAD_BUNDLE__"
@@ -987,7 +996,7 @@ CompressedOffloadBundle::compress(llvm::compression::Params P,
987996
"Compression not supported");
988997

989998
llvm::Timer HashTimer("Hash Calculation Timer", "Hash calculation time",
990-
ClangOffloadBundlerTimerGroup);
999+
*ClangOffloadBundlerTimerGroup);
9911000
if (Verbose)
9921001
HashTimer.startTimer();
9931002
llvm::MD5 Hash;
@@ -1004,7 +1013,7 @@ CompressedOffloadBundle::compress(llvm::compression::Params P,
10041013
Input.getBuffer().size());
10051014

10061015
llvm::Timer CompressTimer("Compression Timer", "Compression time",
1007-
ClangOffloadBundlerTimerGroup);
1016+
*ClangOffloadBundlerTimerGroup);
10081017
if (Verbose)
10091018
CompressTimer.startTimer();
10101019
llvm::compression::compress(P, BufferUint8, CompressedBuffer);
@@ -1119,7 +1128,7 @@ CompressedOffloadBundle::decompress(const llvm::MemoryBuffer &Input,
11191128
"Unknown compressing method");
11201129

11211130
llvm::Timer DecompressTimer("Decompression Timer", "Decompression time",
1122-
ClangOffloadBundlerTimerGroup);
1131+
*ClangOffloadBundlerTimerGroup);
11231132
if (Verbose)
11241133
DecompressTimer.startTimer();
11251134

@@ -1141,7 +1150,7 @@ CompressedOffloadBundle::decompress(const llvm::MemoryBuffer &Input,
11411150
// Recalculate MD5 hash for integrity check
11421151
llvm::Timer HashRecalcTimer("Hash Recalculation Timer",
11431152
"Hash recalculation time",
1144-
ClangOffloadBundlerTimerGroup);
1153+
*ClangOffloadBundlerTimerGroup);
11451154
HashRecalcTimer.startTimer();
11461155
llvm::MD5 Hash;
11471156
llvm::MD5::MD5Result Result;

0 commit comments

Comments
 (0)