LLVM 19.0.0git
Utility.h
Go to the documentation of this file.
1//===- Utility.h - Collection of geneirc offloading utilities -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_FRONTEND_OFFLOADING_UTILITY_H
10#define LLVM_FRONTEND_OFFLOADING_UTILITY_H
11
12#include "llvm/IR/Module.h"
14
15namespace llvm {
16namespace offloading {
17
18/// Offloading entry flags for CUDA / HIP. The first three bits indicate the
19/// type of entry while the others are a bit field for additional information.
21 /// Mark the entry as a global entry. This indicates the presense of a
22 /// kernel if the size size field is zero and a variable otherwise.
24 /// Mark the entry as a managed global variable.
26 /// Mark the entry as a surface variable.
28 /// Mark the entry as a texture variable.
30 /// Mark the entry as being extern.
32 /// Mark the entry as being constant.
34 /// Mark the entry as being a normalized surface.
36};
37
38/// Returns the type of the offloading entry we use to store kernels and
39/// globals that will be registered with the offloading runtime.
41
42/// Create an offloading section struct used to register this global at
43/// runtime.
44///
45/// Type struct __tgt_offload_entry {
46/// void *addr; // Pointer to the offload entry info.
47/// // (function or global)
48/// char *name; // Name of the function or global.
49/// size_t size; // Size of the entry info (0 if it a function).
50/// int32_t flags;
51/// int32_t data;
52/// };
53///
54/// \param M The module to be used
55/// \param Addr The pointer to the global being registered.
56/// \param Name The symbol name associated with the global.
57/// \param Size The size in bytes of the global (0 for functions).
58/// \param Flags Flags associated with the entry.
59/// \param Data Extra data storage associated with the entry.
60/// \param SectionName The section this entry will be placed at.
62 uint64_t Size, int32_t Flags, int32_t Data,
64/// Create a constant struct initializer used to register this global at
65/// runtime.
66/// \return the constant struct and the global variable holding the symbol name.
67std::pair<Constant *, GlobalVariable *>
69 uint64_t Size, int32_t Flags, int32_t Data);
70
71/// Creates a pair of globals used to iterate the array of offloading entries by
72/// accessing the section variables provided by the linker.
73std::pair<GlobalVariable *, GlobalVariable *>
75
76} // namespace offloading
77} // namespace llvm
78
79#endif // LLVM_FRONTEND_OFFLOADING_UTILITY_H
uint64_t Addr
std::string Name
uint64_t Size
Module.h This file contains the declarations for the Module class.
This is an important base class in LLVM.
Definition: Constant.h:41
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Class to represent struct types.
Definition: DerivedTypes.h:216
std::pair< Constant *, GlobalVariable * > getOffloadingEntryInitializer(Module &M, Constant *Addr, StringRef Name, uint64_t Size, int32_t Flags, int32_t Data)
Create a constant struct initializer used to register this global at runtime.
Definition: Utility.cpp:33
StructType * getEntryTy(Module &M)
Returns the type of the offloading entry we use to store kernels and globals that will be registered ...
Definition: Utility.cpp:19
OffloadEntryKindFlag
Offloading entry flags for CUDA / HIP.
Definition: Utility.h:20
@ OffloadGlobalSurfaceEntry
Mark the entry as a surface variable.
Definition: Utility.h:27
@ OffloadGlobalTextureEntry
Mark the entry as a texture variable.
Definition: Utility.h:29
@ OffloadGlobalNormalized
Mark the entry as being a normalized surface.
Definition: Utility.h:35
@ OffloadGlobalEntry
Mark the entry as a global entry.
Definition: Utility.h:23
@ OffloadGlobalManagedEntry
Mark the entry as a managed global variable.
Definition: Utility.h:25
@ OffloadGlobalExtern
Mark the entry as being extern.
Definition: Utility.h:31
@ OffloadGlobalConstant
Mark the entry as being constant.
Definition: Utility.h:33
void emitOffloadingEntry(Module &M, Constant *Addr, StringRef Name, uint64_t Size, int32_t Flags, int32_t Data, StringRef SectionName)
Create an offloading section struct used to register this global at runtime.
Definition: Utility.cpp:64
std::pair< GlobalVariable *, GlobalVariable * > getOffloadEntryArray(Module &M, StringRef SectionName)
Creates a pair of globals used to iterate the array of offloading entries by accessing the section va...
Definition: Utility.cpp:89
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18