LLVM 20.0.0git
GlobalIFunc.h
Go to the documentation of this file.
1//===-------- llvm/GlobalIFunc.h - GlobalIFunc class ------------*- C++ -*-===//
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/// \file
10/// This file contains the declaration of the GlobalIFunc class, which
11/// represents a single indirect function in the IR. Indirect function uses
12/// ELF symbol type extension to mark that the address of a declaration should
13/// be resolved at runtime by calling a resolver function.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_IR_GLOBALIFUNC_H
18#define LLVM_IR_GLOBALIFUNC_H
19
20#include "llvm/ADT/ilist_node.h"
21#include "llvm/IR/Constant.h"
24#include "llvm/IR/Value.h"
25
26namespace llvm {
27
28class Twine;
29class Module;
30
31// Traits class for using GlobalIFunc in symbol table in Module.
32template <typename ValueSubClass, typename... Args> class SymbolTableListTraits;
33
34class GlobalIFunc final : public GlobalObject, public ilist_node<GlobalIFunc> {
36
39
40public:
41 GlobalIFunc(const GlobalIFunc &) = delete;
42 GlobalIFunc &operator=(const GlobalIFunc &) = delete;
43
44 /// If a parent module is specified, the ifunc is automatically inserted into
45 /// the end of the specified module's ifunc list.
46 static GlobalIFunc *create(Type *Ty, unsigned AddressSpace,
49
50 // allocate space for exactly one operand
51 void *operator new(size_t S) { return User::operator new(S, 1); }
52 void operator delete(void *Ptr) { User::operator delete(Ptr); }
53
54 /// Provide fast operand accessors
56
59 }
60
61 /// This method unlinks 'this' from the containing module, but does not
62 /// delete it.
63 void removeFromParent();
64
65 /// This method unlinks 'this' from the containing module and deletes it.
66 void eraseFromParent();
67
68 /// These methods retrieve and set ifunc resolver function.
70 const Constant *getResolver() const {
71 return static_cast<Constant *>(Op<0>().get());
72 }
73 Constant *getResolver() { return static_cast<Constant *>(Op<0>().get()); }
74
75 // Return the resolver function after peeling off potential ConstantExpr
76 // indirection.
77 const Function *getResolverFunction() const;
79 return const_cast<Function *>(
80 static_cast<const GlobalIFunc *>(this)->getResolverFunction());
81 }
82
84 return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) ||
86 }
87
88 // Methods for support type inquiry through isa, cast, and dyn_cast:
89 static bool classof(const Value *V) {
90 return V->getValueID() == Value::GlobalIFuncVal;
91 }
92
93 // Apply specific operation to all resolver-related values. If resolver target
94 // is already a global object, then apply the operation to it directly. If
95 // target is a GlobalExpr or a GlobalAlias, evaluate it to its base object and
96 // apply the operation for the base object and all aliases along the path.
97 void applyAlongResolverPath(function_ref<void(const GlobalValue &)> Op) const;
98};
99
100template <>
102 : public FixedNumOperandTraits<GlobalIFunc, 1> {};
103
105
106} // end namespace llvm
107
108#endif // LLVM_IR_GLOBALIFUNC_H
std::string Name
Machine Check Debug Module
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
This is an important base class in LLVM.
Definition: Constant.h:42
This class represents an Operation in the Expression.
GlobalIFunc(const GlobalIFunc &)=delete
void applyAlongResolverPath(function_ref< void(const GlobalValue &)> Op) const
Definition: Globals.cpp:621
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant)
Provide fast operand accessors.
void copyAttributesFrom(const GlobalIFunc *Src)
Definition: GlobalIFunc.h:57
Function * getResolverFunction()
Definition: GlobalIFunc.h:78
const Function * getResolverFunction() const
Definition: Globals.cpp:617
Constant * getResolver()
Definition: GlobalIFunc.h:73
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:613
static bool isValidLinkage(LinkageTypes L)
Definition: GlobalIFunc.h:83
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
Definition: Globals.cpp:607
void setResolver(Constant *Resolver)
These methods retrieve and set ifunc resolver function.
Definition: GlobalIFunc.h:69
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:615
static bool classof(const Value *V)
Definition: GlobalIFunc.h:89
GlobalIFunc & operator=(const GlobalIFunc &)=delete
const Constant * getResolver() const
Definition: GlobalIFunc.h:70
void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:147
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:409
static bool isLinkOnceLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:388
static bool isExternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:376
static bool isWeakLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:397
unsigned Linkage
Definition: GlobalValue.h:98
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:51
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2212
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
An efficient, type-erasing, non-owning reference to a callable.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AddressSpace
Definition: NVPTXBaseInfo.h:21
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:30
Compile-time customization of User operands.
Definition: User.h:42