Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenMP][NFC] Extract timescope profile support into its own header #73727

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

jdoerfert
Copy link
Member

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 29, 2023

@llvm/pr-subscribers-openmp

Author: Johannes Doerfert (jdoerfert)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/73727.diff

7 Files Affected:

  • (added) openmp/libomptarget/include/Shared/Profile.h (+36)
  • (modified) openmp/libomptarget/src/LegacyAPI.cpp (+2)
  • (modified) openmp/libomptarget/src/api.cpp (+2)
  • (modified) openmp/libomptarget/src/interface.cpp (+1)
  • (modified) openmp/libomptarget/src/omptarget.cpp (+2)
  • (modified) openmp/libomptarget/src/private.h (-19)
  • (modified) openmp/libomptarget/src/rtl.cpp (+1)
diff --git a/openmp/libomptarget/include/Shared/Profile.h b/openmp/libomptarget/include/Shared/Profile.h
new file mode 100644
index 000000000000000..bbdefea06d90e85
--- /dev/null
+++ b/openmp/libomptarget/include/Shared/Profile.h
@@ -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)
diff --git a/openmp/libomptarget/src/LegacyAPI.cpp b/openmp/libomptarget/src/LegacyAPI.cpp
index 54dbe19c1714474..d0f21a36513ada1 100644
--- a/openmp/libomptarget/src/LegacyAPI.cpp
+++ b/openmp/libomptarget/src/LegacyAPI.cpp
@@ -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) {
diff --git a/openmp/libomptarget/src/api.cpp b/openmp/libomptarget/src/api.cpp
index ecef02c8a0d3d07..7fc13cb698213b9 100644
--- a/openmp/libomptarget/src/api.cpp
+++ b/openmp/libomptarget/src/api.cpp
@@ -15,6 +15,8 @@
 #include "private.h"
 #include "rtl.h"
 
+#include "Shared/Profile.h"
+
 #include "llvm/ADT/SmallVector.h"
 
 #include <climits>
diff --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp
index 4735469b55aa055..8a1dcf577f1baeb 100644
--- a/openmp/libomptarget/src/interface.cpp
+++ b/openmp/libomptarget/src/interface.cpp
@@ -18,6 +18,7 @@
 #include "private.h"
 #include "rtl.h"
 
+#include "Shared/Profile.h"
 #include "Shared/Utils.h"
 
 #include <cassert>
diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index d3b299ca58f5172..f4b244aac13ae4e 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -18,6 +18,8 @@
 #include "private.h"
 #include "rtl.h"
 
+#include "Shared/Profile.h"
+
 #include "OpenMP/omp.h"
 
 #include "llvm/ADT/StringExtras.h"
diff --git a/openmp/libomptarget/src/private.h b/openmp/libomptarget/src/private.h
index f082f6e3b9fc83a..e9b9794308f0937 100644
--- a/openmp/libomptarget/src/private.h
+++ b/openmp/libomptarget/src/private.h
@@ -419,23 +419,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
diff --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp
index 86509cd69c5614f..6e012bae8a6ace2 100644
--- a/openmp/libomptarget/src/rtl.cpp
+++ b/openmp/libomptarget/src/rtl.cpp
@@ -17,6 +17,7 @@
 #include "private.h"
 #include "rtl.h"
 
+#include "Shared/Profile.h"
 #include "Shared/Utils.h"
 
 #include <cassert>

@jdoerfert jdoerfert merged commit 2cfe7b1 into llvm:main Nov 29, 2023
5 checks passed
@jdoerfert jdoerfert deleted the offload_prep6 branch November 29, 2023 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openmp:libomptarget OpenMP offload runtime openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants