Files
Joseph Huber 105bd6b654 [Offload] Clean up and split Shared/Utils.h (#194876)
Summary:
This is used in the GPU portion of the build, but really shouldn't be.
Most of these helpers were only used by the GPU portion, which has much
nicer builtins available in new clang. Using these in the main offload
build is broken on Windows and not available on older compilers, so we
split. Also means one less header we share.

The alignment helpers are trivially replaced by an LLVM utility, the
only thing that remains are the pointer arithmetic functions. There's no
conveient place to put these so I just let them stay.
2026-04-29 13:10:38 -05:00

36 lines
1.1 KiB
C++

//===-- Shared/Utils.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
//
//===----------------------------------------------------------------------===//
//
// Routines and classes used to provide useful functionalities for the host and
// the device.
//
//===----------------------------------------------------------------------===//
#ifndef OMPTARGET_SHARED_UTILS_H
#define OMPTARGET_SHARED_UTILS_H
#include <stdint.h>
namespace utils {
/// Return the difference (in bytes) between \p Begin and \p End.
template <typename Ty = char>
auto getPtrDiff(const void *End, const void *Begin) {
return reinterpret_cast<const Ty *>(End) -
reinterpret_cast<const Ty *>(Begin);
}
/// Return \p Ptr advanced by \p Offset bytes.
template <typename Ty1, typename Ty2> Ty1 *advancePtr(Ty1 *Ptr, Ty2 Offset) {
return (Ty1 *)(const_cast<char *>((const char *)(Ptr)) + Offset);
}
} // namespace utils
#endif // OMPTARGET_SHARED_UTILS_H