LLVM  15.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"
22 #include "llvm/IR/GlobalObject.h"
23 #include "llvm/IR/OperandTraits.h"
24 #include "llvm/IR/Value.h"
25 
26 namespace llvm {
27 
28 class Twine;
29 class Module;
30 
31 // Traits class for using GlobalIFunc in symbol table in Module.
32 template <typename ValueSubClass> class SymbolTableListTraits;
33 
34 class GlobalIFunc final : public GlobalObject, public ilist_node<GlobalIFunc> {
36 
39 
40 public:
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 
57  void copyAttributesFrom(const GlobalIFunc *Src) {
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.
69  void setResolver(Constant *Resolver) { Op<0>().set(Resolver); }
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 
83  static FunctionType *getResolverFunctionType(Type *IFuncValTy) {
84  return FunctionType::get(IFuncValTy->getPointerTo(), false);
85  }
86 
87  static bool isValidLinkage(LinkageTypes L) {
88  return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) ||
90  }
91 
92  // Methods for support type inquiry through isa, cast, and dyn_cast:
93  static bool classof(const Value *V) {
94  return V->getValueID() == Value::GlobalIFuncVal;
95  }
96 };
97 
98 template <>
100  : public FixedNumOperandTraits<GlobalIFunc, 1> {};
101 
103 
104 } // end namespace llvm
105 
106 #endif // LLVM_IR_GLOBALIFUNC_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::Function
Definition: Function.h:60
llvm::GlobalValue::isLocalLinkage
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:331
llvm::FunctionType::get
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:361
llvm::GlobalIFunc::getResolverFunction
Function * getResolverFunction()
Definition: GlobalIFunc.h:78
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DEFINE_TRANSPARENT_OPERAND_ACCESSORS
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
Definition: OperandTraits.h:125
GlobalObject.h
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
llvm::Resolver
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2052
llvm::OperandTraits
Compile-time customization of User operands.
Definition: User.h:42
llvm::GlobalIFunc::copyAttributesFrom
void copyAttributesFrom(const GlobalIFunc *Src)
Definition: GlobalIFunc.h:57
llvm::GlobalObject
Definition: GlobalObject.h:27
llvm::Value::getValueID
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:532
OperandTraits.h
llvm::GlobalIFunc::removeFromParent
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:547
llvm::AddressSpace
AddressSpace
Definition: NVPTXBaseInfo.h:21
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::SymbolTableListTraits
Definition: GlobalAlias.h:26
llvm::GlobalIFunc::setResolver
void setResolver(Constant *Resolver)
These methods retrieve and set ifunc resolver function.
Definition: GlobalIFunc.h:69
llvm::GlobalIFunc::getResolver
const Constant * getResolver() const
Definition: GlobalIFunc.h:70
llvm::GlobalValue::Linkage
unsigned Linkage
Definition: GlobalValue.h:93
llvm::GlobalValue::isExternalLinkage
static bool isExternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:298
llvm::GlobalValue::isWeakLinkage
static bool isWeakLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:319
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::GlobalIFunc::getResolver
Constant * getResolver()
Definition: GlobalIFunc.h:73
llvm::GlobalIFunc::DECLARE_TRANSPARENT_OPERAND_ACCESSORS
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant)
Provide fast operand accessors.
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::GlobalIFunc::create
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:541
llvm::GlobalIFunc::operator=
GlobalIFunc & operator=(const GlobalIFunc &)=delete
llvm::ilist_node
Definition: ilist_node.h:149
llvm::GlobalValue::isLinkOnceLinkage
static bool isLinkOnceLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:310
llvm::GlobalIFunc::isValidLinkage
static bool isValidLinkage(LinkageTypes L)
Definition: GlobalIFunc.h:87
Constant.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::GlobalIFunc::getResolverFunctionType
static FunctionType * getResolverFunctionType(Type *IFuncValTy)
Definition: GlobalIFunc.h:83
llvm::Type::getPointerTo
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
Definition: Type.cpp:774
llvm::GlobalObject::copyAttributesFrom
void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:132
llvm::FixedNumOperandTraits
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:30
ilist_node.h
llvm::GlobalIFunc::getResolverFunction
const Function * getResolverFunction() const
Definition: Globals.cpp:555
Value.h
llvm::GlobalIFunc
Definition: GlobalIFunc.h:34
llvm::GlobalValue::Parent
Module * Parent
Definition: GlobalValue.h:165
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::GlobalIFunc::eraseFromParent
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:551
llvm::GlobalIFunc::classof
static bool classof(const Value *V)
Definition: GlobalIFunc.h:93
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103