Files
Alex Duran 525b9ff127 [Offload][Omp][Acc][NFC] Restructure offload directory (#242220)
Create a src and include directory for libomptarget and libompaccsupport
following the same structure as liboffload.

Move headers from the base include directory to the directories that use
them.

Just a few utility headers remain in the share base include/Shared
directory. Of those, Environment.h and RPCOpcodes.h seem questionable
but seem in used in both the plugins and libomptarget (which seems to
point to further refactoring needed).

Changes in source files are basically due to directory changes, leftover
headers, and in a few cases, changing headers that were only used
transitively for their own dependence.

Headers in libompaccsupport seem like they could be further refined as
they contain both shared and things only neeeded by libomptarget, but
that's a larger refactoring to be done later.

Mechanical work done by Claude.
2026-11-17 10:29:55 +01:00

103 lines
3.4 KiB
C++

//===-- SourceInfo.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
//
//===----------------------------------------------------------------------===//
//
// Methods used to describe source information in target regions
//
//===----------------------------------------------------------------------===//
#ifndef OMPTARGET_SHARED_SOURCE_INFO_H
#define OMPTARGET_SHARED_SOURCE_INFO_H
#include <cstdint>
#include <string>
/// Type alias for source location information for variable mappings with
/// data layout ";name;filename;row;col;;\0" from clang.
using map_var_info_t = void *;
/// The ident structure that describes a source location from kmp.h. with
/// source location string data as ";filename;function;line;column;;\0".
struct ident_t {
// Ident_t flags described in kmp.h.
int32_t reserved_1;
int32_t flags;
int32_t reserved_2;
int32_t reserved_3;
char const *psource;
};
/// Struct to hold source individual location information.
class SourceInfo {
/// Underlying string copy of the original source information.
const std::string SourceStr;
/// Location fields extracted from the source information string.
const std::string Name;
const std::string Filename;
const int32_t Line;
const int32_t Column;
std::string initStr(const void *Name) {
if (!Name)
return ";unknown;unknown;0;0;;";
std::string Str = std::string(reinterpret_cast<const char *>(Name));
if (Str.find(';') == std::string::npos)
return ";" + Str + ";unknown;0;0;;";
return Str;
}
std::string initStr(const ident_t *Loc) {
if (!Loc)
return ";unknown;unknown;0;0;;";
return std::string(reinterpret_cast<const char *>(Loc->psource));
}
/// Get n-th substring in an expression separated by ;.
std::string getSubstring(const unsigned N) const {
std::size_t Begin = SourceStr.find(';');
std::size_t End = SourceStr.find(';', Begin + 1);
for (unsigned I = 0; I < N; I++) {
Begin = End;
End = SourceStr.find(';', Begin + 1);
}
return SourceStr.substr(Begin + 1, End - Begin - 1);
};
public:
SourceInfo(const ident_t *Loc)
: SourceStr(initStr(Loc)), Name(getSubstring(1)),
Filename(getSubstring(0)), Line(std::stoi(getSubstring(2))),
Column(std::stoi(getSubstring(3))) {}
SourceInfo(const map_var_info_t Name)
: SourceStr(initStr(Name)), Name(getSubstring(0)),
Filename(getSubstring(1)), Line(std::stoi(getSubstring(2))),
Column(std::stoi(getSubstring(3))) {}
const char *getName() const { return Name.c_str(); }
const char *getFilename() const { return Filename.c_str(); }
const char *getProfileLocation() const { return SourceStr.data(); }
int32_t getLine() const { return Line; }
int32_t getColumn() const { return Column; }
bool isAvailable() const { return (Line || Column); }
};
/// Standalone function for getting the variable name of a mapping.
static inline std::string getNameFromMapping(const map_var_info_t Name) {
if (!Name)
return "unknown";
const std::string NameStr(reinterpret_cast<const char *>(Name));
std::size_t Begin = NameStr.find(';');
std::size_t End = NameStr.find(';', Begin + 1);
return NameStr.substr(Begin + 1, End - Begin - 1);
}
#endif // OMPTARGET_SHARED_SOURCE_INFO_H