Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:00

0001 //===-------- llvm/GlobalIFunc.h - GlobalIFunc class ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// This file contains the declaration of the GlobalIFunc class, which
0011 /// represents a single indirect function in the IR. Indirect function uses
0012 /// ELF symbol type extension to mark that the address of a declaration should
0013 /// be resolved at runtime by calling a resolver function.
0014 ///
0015 //===----------------------------------------------------------------------===//
0016 
0017 #ifndef LLVM_IR_GLOBALIFUNC_H
0018 #define LLVM_IR_GLOBALIFUNC_H
0019 
0020 #include "llvm/ADT/ilist_node.h"
0021 #include "llvm/IR/Constant.h"
0022 #include "llvm/IR/GlobalObject.h"
0023 #include "llvm/IR/OperandTraits.h"
0024 #include "llvm/IR/Value.h"
0025 
0026 namespace llvm {
0027 
0028 class Twine;
0029 class Module;
0030 
0031 // Traits class for using GlobalIFunc in symbol table in Module.
0032 template <typename ValueSubClass, typename... Args> class SymbolTableListTraits;
0033 
0034 class GlobalIFunc final : public GlobalObject, public ilist_node<GlobalIFunc> {
0035   friend class SymbolTableListTraits<GlobalIFunc>;
0036 
0037   constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
0038 
0039   GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
0040               const Twine &Name, Constant *Resolver, Module *Parent);
0041 
0042 public:
0043   GlobalIFunc(const GlobalIFunc &) = delete;
0044   GlobalIFunc &operator=(const GlobalIFunc &) = delete;
0045 
0046   /// If a parent module is specified, the ifunc is automatically inserted into
0047   /// the end of the specified module's ifunc list.
0048   static GlobalIFunc *create(Type *Ty, unsigned AddressSpace,
0049                              LinkageTypes Linkage, const Twine &Name,
0050                              Constant *Resolver, Module *Parent);
0051 
0052   // allocate space for exactly one operand
0053   void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
0054   void operator delete(void *Ptr) { User::operator delete(Ptr); }
0055 
0056   /// Provide fast operand accessors
0057   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
0058 
0059   void copyAttributesFrom(const GlobalIFunc *Src) {
0060     GlobalObject::copyAttributesFrom(Src);
0061   }
0062 
0063   /// This method unlinks 'this' from the containing module, but does not
0064   /// delete it.
0065   void removeFromParent();
0066 
0067   /// This method unlinks 'this' from the containing module and deletes it.
0068   void eraseFromParent();
0069 
0070   /// These methods retrieve and set ifunc resolver function.
0071   void setResolver(Constant *Resolver) { Op<0>().set(Resolver); }
0072   const Constant *getResolver() const {
0073     return static_cast<Constant *>(Op<0>().get());
0074   }
0075   Constant *getResolver() { return static_cast<Constant *>(Op<0>().get()); }
0076 
0077   // Return the resolver function after peeling off potential ConstantExpr
0078   // indirection.
0079   const Function *getResolverFunction() const;
0080   Function *getResolverFunction() {
0081     return const_cast<Function *>(
0082         static_cast<const GlobalIFunc *>(this)->getResolverFunction());
0083   }
0084 
0085   static bool isValidLinkage(LinkageTypes L) {
0086     return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) ||
0087            isLinkOnceLinkage(L);
0088   }
0089 
0090   // Methods for support type inquiry through isa, cast, and dyn_cast:
0091   static bool classof(const Value *V) {
0092     return V->getValueID() == Value::GlobalIFuncVal;
0093   }
0094 
0095   // Apply specific operation to all resolver-related values. If resolver target
0096   // is already a global object, then apply the operation to it directly. If
0097   // target is a GlobalExpr or a GlobalAlias, evaluate it to its base object and
0098   // apply the operation for the base object and all aliases along the path.
0099   void applyAlongResolverPath(function_ref<void(const GlobalValue &)> Op) const;
0100 };
0101 
0102 template <>
0103 struct OperandTraits<GlobalIFunc>
0104     : public FixedNumOperandTraits<GlobalIFunc, 1> {};
0105 
0106 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIFunc, Constant)
0107 
0108 } // end namespace llvm
0109 
0110 #endif // LLVM_IR_GLOBALIFUNC_H