|
10 | 10 |
|
11 | 11 | #include "llvm/ADT/ArrayRef.h"
|
12 | 12 | #include "llvm/ADT/STLExtras.h"
|
| 13 | +#include "llvm/ADT/SmallString.h" |
13 | 14 | #include "llvm/ADT/SmallVector.h"
|
14 | 15 | #include "llvm/ADT/StringRef.h"
|
15 | 16 | #include "llvm/ADT/StringSwitch.h"
|
| 17 | +#include "llvm/Demangle/Demangle.h" |
| 18 | +#include "llvm/Frontend/OpenMP/OMPIRBuilder.h" |
16 | 19 | #include "llvm/Support/ErrorHandling.h"
|
| 20 | +#include "llvm/Support/StringSaver.h" |
17 | 21 |
|
18 | 22 | #include <algorithm>
|
| 23 | +#include <cstdio> |
19 | 24 | #include <iterator>
|
| 25 | +#include <string> |
20 | 26 | #include <type_traits>
|
21 | 27 |
|
22 | 28 | using namespace llvm;
|
@@ -186,4 +192,42 @@ bool isCombinedConstruct(Directive D) {
|
186 | 192 | // Otherwise directive-name is a combined construct.
|
187 | 193 | return !getLeafConstructs(D).empty() && !isCompositeConstruct(D);
|
188 | 194 | }
|
| 195 | + |
| 196 | +std::string prettifyFunctionName(StringRef FunctionName) { |
| 197 | + // Internalized functions have the right name, but simply a suffix. |
| 198 | + if (FunctionName.ends_with(".internalized")) |
| 199 | + return FunctionName.drop_back(sizeof("internalized")).str() + |
| 200 | + " (internalized)"; |
| 201 | + unsigned LineNo = 0; |
| 202 | + auto ParentName = deconstructOpenMPKernelName(FunctionName, LineNo); |
| 203 | + if (LineNo == 0) |
| 204 | + return FunctionName.str(); |
| 205 | + return ("omp target in " + ParentName + " @ " + std::to_string(LineNo) + |
| 206 | + " (" + FunctionName + ")") |
| 207 | + .str(); |
| 208 | +} |
| 209 | + |
| 210 | +std::string deconstructOpenMPKernelName(StringRef KernelName, |
| 211 | + unsigned &LineNo) { |
| 212 | + |
| 213 | + // Only handle functions with an OpenMP kernel prefix for now. Naming scheme: |
| 214 | + // __omp_offloading_<hex_hash1>_<hex_hash2>_<name>_l<line>_[<count>_]<suffix> |
| 215 | + if (!KernelName.starts_with(TargetRegionEntryInfo::KernelNamePrefix)) |
| 216 | + return ""; |
| 217 | + |
| 218 | + auto PrettyName = KernelName.drop_front( |
| 219 | + sizeof(TargetRegionEntryInfo::KernelNamePrefix) - /*'\0'*/ 1); |
| 220 | + for (int I = 0; I < 3; ++I) { |
| 221 | + PrettyName = PrettyName.drop_while([](char c) { return c != '_'; }); |
| 222 | + PrettyName = PrettyName.drop_front(); |
| 223 | + } |
| 224 | + |
| 225 | + // Look for the last '_l<line>'. |
| 226 | + size_t LineIdx = PrettyName.rfind("_l"); |
| 227 | + if (LineIdx == StringRef::npos) |
| 228 | + return ""; |
| 229 | + if (PrettyName.drop_front(LineIdx + 2).consumeInteger(10, LineNo)) |
| 230 | + return ""; |
| 231 | + return demangle(PrettyName.take_front(LineIdx)); |
| 232 | +} |
189 | 233 | } // namespace llvm::omp
|
0 commit comments