Skip to content

Commit

Permalink
[OpenMP][NFC] Extract timescope profile support into its own header (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jdoerfert committed Nov 29, 2023
1 parent dc16964 commit 2cfe7b1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 19 deletions.
36 changes: 36 additions & 0 deletions openmp/libomptarget/include/Shared/Profile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===-- Shared/Profile.h - Target independent OpenMP target RTL -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Macros to provide profile support via LLVM's time profiler.
//
//===----------------------------------------------------------------------===//

#include "llvm/Support/TimeProfiler.h"

/// Time spend in the current scope, assigned to the function name.
#define TIMESCOPE() llvm::TimeTraceScope TimeScope(__FUNCTION__)

/// Time spend in the current scope, assigned to the function name and source
/// info.
#define TIMESCOPE_WITH_IDENT(IDENT) \
SourceInfo SI(IDENT); \
llvm::TimeTraceScope TimeScope(__FUNCTION__, SI.getProfileLocation())

/// Time spend in the current scope, assigned to the given name and source
/// info.
#define TIMESCOPE_WITH_NAME_AND_IDENT(NAME, IDENT) \
SourceInfo SI(IDENT); \
llvm::TimeTraceScope TimeScope(NAME, SI.getProfileLocation())

/// Time spend in the current scope, assigned to the function name and source
/// info and RegionTypeMsg.
#define TIMESCOPE_WITH_RTM_AND_IDENT(RegionTypeMsg, IDENT) \
SourceInfo SI(IDENT); \
std::string ProfileLocation = SI.getProfileLocation(); \
std::string RTM = RegionTypeMsg; \
llvm::TimeTraceScope TimeScope(__FUNCTION__, ProfileLocation + RTM)
2 changes: 2 additions & 0 deletions openmp/libomptarget/src/LegacyAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "omptarget.h"
#include "private.h"

#include "Shared/Profile.h"

EXTERN void __tgt_target_data_begin(int64_t DeviceId, int32_t ArgNum,
void **ArgsBase, void **Args,
int64_t *ArgSizes, int64_t *ArgTypes) {
Expand Down
2 changes: 2 additions & 0 deletions openmp/libomptarget/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "private.h"
#include "rtl.h"

#include "Shared/Profile.h"

#include "llvm/ADT/SmallVector.h"

#include <climits>
Expand Down
1 change: 1 addition & 0 deletions openmp/libomptarget/src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "private.h"
#include "rtl.h"

#include "Shared/Profile.h"
#include "Shared/Utils.h"

#include <cassert>
Expand Down
2 changes: 2 additions & 0 deletions openmp/libomptarget/src/omptarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "private.h"
#include "rtl.h"

#include "Shared/Profile.h"

#include "OpenMP/omp.h"

#include "llvm/ADT/StringExtras.h"
Expand Down
19 changes: 0 additions & 19 deletions openmp/libomptarget/src/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,23 +414,4 @@ class ExponentialBackoff {
bool isAboveThreshold() const { return Count > CountThreshold; }
};

#include "llvm/Support/TimeProfiler.h"
#define TIMESCOPE() llvm::TimeTraceScope TimeScope(__FUNCTION__)
#define TIMESCOPE_WITH_IDENT(IDENT) \
SourceInfo SI(IDENT); \
llvm::TimeTraceScope TimeScope(__FUNCTION__, SI.getProfileLocation())
#define TIMESCOPE_WITH_NAME_AND_IDENT(NAME, IDENT) \
SourceInfo SI(IDENT); \
llvm::TimeTraceScope TimeScope(NAME, SI.getProfileLocation())
#define TIMESCOPE_WITH_RTM_AND_IDENT(RegionTypeMsg, IDENT) \
SourceInfo SI(IDENT); \
std::string ProfileLocation = SI.getProfileLocation(); \
std::string RTM = RegionTypeMsg; \
llvm::TimeTraceScope TimeScope(__FUNCTION__, ProfileLocation + RTM)
#else
#define TIMESCOPE()
#define TIMESCOPE_WITH_IDENT(IDENT)
#define TIMESCOPE_WITH_NAME_AND_IDENT(NAME, IDENT)
#define TIMESCOPE_WITH_RTM_AND_IDENT(RegionTypeMsg, IDENT)

#endif
1 change: 1 addition & 0 deletions openmp/libomptarget/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "private.h"
#include "rtl.h"

#include "Shared/Profile.h"
#include "Shared/Utils.h"

#include <cassert>
Expand Down

0 comments on commit 2cfe7b1

Please sign in to comment.