LLVM 23.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"
26
27namespace llvm {
28
29class Twine;
30class Module;
31
32// Traits class for using GlobalIFunc in symbol table in Module.
33template <typename ValueSubClass, typename... Args> class SymbolTableListTraits;
34
35class GlobalIFunc final : public GlobalObject, public ilist_node<GlobalIFunc> {
36 friend class SymbolTableListTraits<GlobalIFunc>;
37
38 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
39
40 GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
41 const Twine &Name, Constant *Resolver, Module *Parent);
42
43public:
44 GlobalIFunc(const GlobalIFunc &) = delete;
45 GlobalIFunc &operator=(const GlobalIFunc &) = delete;
46
47 /// If a parent module is specified, the ifunc is automatically inserted into
48 /// the end of the specified module's ifunc list.
49 LLVM_ABI static GlobalIFunc *create(Type *Ty, unsigned AddressSpace,
50 LinkageTypes Linkage, const Twine &Name,
52
53 // allocate space for exactly one operand
54 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
55 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
56
57 /// Provide fast operand accessors
59
60 void copyAttributesFrom(const GlobalIFunc *Src) {
62 }
63
64 /// This method unlinks 'this' from the containing module, but does not
65 /// delete it.
67
68 /// This method unlinks 'this' from the containing module and deletes it.
70
71 /// These methods retrieve and set ifunc resolver function.
73 const Constant *getResolver() const {
74 return static_cast<Constant *>(Op<0>().get());
75 }
76 Constant *getResolver() { return static_cast<Constant *>(Op<0>().get()); }
77
78 // Return the resolver function after peeling off potential ConstantExpr
79 // indirection.
82 return const_cast<Function *>(
83 static_cast<const GlobalIFunc *>(this)->getResolverFunction());
84 }
85
87 return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) ||
89 }
90
91 // Methods for support type inquiry through isa, cast, and dyn_cast:
92 static bool classof(const Value *V) {
93 return V->getValueID() == Value::GlobalIFuncVal;
94 }
95
96 // Apply specific operation to all resolver-related values. If resolver target
97 // is already a global object, then apply the operation to it directly. If
98 // target is a GlobalExpr or a GlobalAlias, evaluate it to its base object and
99 // apply the operation for the base object and all aliases along the path.
100 LLVM_ABI void
102};
103
104template <>
106 : public FixedNumOperandTraits<GlobalIFunc, 1> {};
107
109
110} // end namespace llvm
111
112#endif // LLVM_IR_GLOBALIFUNC_H
#define LLVM_ABI
Definition Compiler.h:213
#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:43
GlobalIFunc(const GlobalIFunc &)=delete
LLVM_ABI void applyAlongResolverPath(function_ref< void(const GlobalValue &)> Op) const
Definition Globals.cpp:692
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant)
Provide fast operand accessors.
void copyAttributesFrom(const GlobalIFunc *Src)
Definition GlobalIFunc.h:60
Function * getResolverFunction()
Definition GlobalIFunc.h:81
LLVM_ABI const Function * getResolverFunction() const
Definition Globals.cpp:688
Constant * getResolver()
Definition GlobalIFunc.h:76
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition Globals.cpp:684
static bool isValidLinkage(LinkageTypes L)
Definition GlobalIFunc.h:86
static LLVM_ABI 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:678
void setResolver(Constant *Resolver)
These methods retrieve and set ifunc resolver function.
Definition GlobalIFunc.h:72
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition Globals.cpp:686
static bool classof(const Value *V)
Definition GlobalIFunc.h:92
GlobalIFunc & operator=(const GlobalIFunc &)=delete
const Constant * getResolver() const
Definition GlobalIFunc.h:73
GlobalObject(Type *Ty, ValueTy VTy, AllocInfo AllocInfo, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace=0)
LLVM_ABI void copyAttributesFrom(const GlobalObject *Src)
Definition Globals.cpp:164
friend class Value
static bool isLocalLinkage(LinkageTypes Linkage)
static bool isLinkOnceLinkage(LinkageTypes Linkage)
static bool isExternalLinkage(LinkageTypes Linkage)
static bool isWeakLinkage(LinkageTypes Linkage)
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition GlobalValue.h:52
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition Record.h:2199
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
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.
DWARFExpression::Operation Op
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Compile-time customization of User operands.
Definition User.h:42
Indicates this User has operands co-allocated.
Definition User.h:60