LLVM  16.0.0git
ModuleUtils.h
Go to the documentation of this file.
1 //===-- ModuleUtils.h - Functions to manipulate Modules ---------*- 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 // This family of functions perform manipulations on Modules.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
14 #define LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/Alignment.h"
19 #include <utility> // for std::pair
20 
21 namespace llvm {
22 template <typename T> class SmallVectorImpl;
23 
24 template <typename T> class ArrayRef;
25 class Module;
26 class Function;
27 class FunctionCallee;
28 class GlobalValue;
29 class Constant;
30 class Value;
31 class Type;
32 
33 /// Append F to the list of global ctors of module M with the given Priority.
34 /// This wraps the function in the appropriate structure and stores it along
35 /// side other global constructors. For details see
36 /// http://llvm.org/docs/LangRef.html#intg_global_ctors
37 void appendToGlobalCtors(Module &M, Function *F, int Priority,
38  Constant *Data = nullptr);
39 
40 /// Same as appendToGlobalCtors(), but for global dtors.
41 void appendToGlobalDtors(Module &M, Function *F, int Priority,
42  Constant *Data = nullptr);
43 
44 FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName,
45  ArrayRef<Type *> InitArgTypes);
46 
47 /// Creates sanitizer constructor function.
48 /// \return Returns pointer to constructor.
49 Function *createSanitizerCtor(Module &M, StringRef CtorName);
50 
51 /// Creates sanitizer constructor function, and calls sanitizer's init
52 /// function from it.
53 /// \return Returns pair of pointers to constructor, and init functions
54 /// respectively.
55 std::pair<Function *, FunctionCallee> createSanitizerCtorAndInitFunctions(
56  Module &M, StringRef CtorName, StringRef InitName,
57  ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
58  StringRef VersionCheckName = StringRef());
59 
60 /// Creates sanitizer constructor function lazily. If a constructor and init
61 /// function already exist, this function returns it. Otherwise it calls \c
62 /// createSanitizerCtorAndInitFunctions. The FunctionsCreatedCallback is invoked
63 /// in that case, passing the new Ctor and Init function.
64 ///
65 /// \return Returns pair of pointers to constructor, and init functions
66 /// respectively.
67 std::pair<Function *, FunctionCallee> getOrCreateSanitizerCtorAndInitFunctions(
68  Module &M, StringRef CtorName, StringRef InitName,
69  ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
70  function_ref<void(Function *, FunctionCallee)> FunctionsCreatedCallback,
71  StringRef VersionCheckName = StringRef());
72 
73 /// Rename all the anon globals in the module using a hash computed from
74 /// the list of public globals in the module.
76 
77 /// Adds global values to the llvm.used list.
78 void appendToUsed(Module &M, ArrayRef<GlobalValue *> Values);
79 
80 /// Adds global values to the llvm.compiler.used list.
81 void appendToCompilerUsed(Module &M, ArrayRef<GlobalValue *> Values);
82 
83 /// Filter out potentially dead comdat functions where other entries keep the
84 /// entire comdat group alive.
85 ///
86 /// This is designed for cases where functions appear to become dead but remain
87 /// alive due to other live entries in their comdat group.
88 ///
89 /// The \p DeadComdatFunctions container should only have pointers to
90 /// `Function`s which are members of a comdat group and are believed to be
91 /// dead.
92 ///
93 /// After this routine finishes, the only remaining `Function`s in \p
94 /// DeadComdatFunctions are those where every member of the comdat is listed
95 /// and thus removing them is safe (provided *all* are removed).
97  SmallVectorImpl<Function *> &DeadComdatFunctions);
98 
99 /// Produce a unique identifier for this module by taking the MD5 sum of
100 /// the names of the module's strong external symbols that are not comdat
101 /// members.
102 ///
103 /// This identifier is normally guaranteed to be unique, or the program would
104 /// fail to link due to multiply defined symbols.
105 ///
106 /// If the module has no strong external symbols (such a module may still have a
107 /// semantic effect if it performs global initialization), we cannot produce a
108 /// unique identifier for this module, so we return the empty string.
109 std::string getUniqueModuleId(Module *M);
110 
111 /// Embed the memory buffer \p Buf into the module \p M as a global using the
112 /// specified section name. Also provide a metadata entry to identify it in the
113 /// module using the same section name.
114 void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName,
115  Align Alignment = Align(1));
116 
117 class CallInst;
118 namespace VFABI {
119 /// Overwrite the Vector Function ABI variants attribute with the names provide
120 /// in \p VariantMappings.
121 void setVectorVariantNames(CallInst *CI, ArrayRef<std::string> VariantMappings);
122 } // End VFABI namespace
123 } // End llvm namespace
124 
125 #endif // LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
StringRef.h
llvm::createSanitizerCtor
Function * createSanitizerCtor(Module &M, StringRef CtorName)
Creates sanitizer constructor function.
Definition: ModuleUtils.cpp:125
MemoryBufferRef.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::appendToGlobalDtors
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
Definition: ModuleUtils.cpp:71
llvm::getOrCreateSanitizerCtorAndInitFunctions
std::pair< Function *, FunctionCallee > getOrCreateSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, function_ref< void(Function *, FunctionCallee)> FunctionsCreatedCallback, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function lazily.
Definition: ModuleUtils.cpp:160
llvm::nameUnamedGlobals
bool nameUnamedGlobals(Module &M)
Rename all the anon globals in the module using a hash computed from the list of public globals in th...
Definition: NameAnonGlobals.cpp:66
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::appendToCompilerUsed
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
Definition: ModuleUtils.cpp:111
llvm::AMDGPU::ElfNote::SectionName
const char SectionName[]
Definition: AMDGPUPTNote.h:24
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
llvm::createSanitizerCtorAndInitFunctions
std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function, and calls sanitizer's init function from it.
Definition: ModuleUtils.cpp:138
llvm::filterDeadComdatFunctions
void filterDeadComdatFunctions(SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.
Definition: ModuleUtils.cpp:182
llvm::declareSanitizerInitFunction
FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes)
Definition: ModuleUtils.cpp:116
llvm::embedBufferInModule
void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName, Align Alignment=Align(1))
Embed the memory buffer Buf into the module M as a global using the specified section name.
Definition: ModuleUtils.cpp:270
llvm::appendToUsed
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
Definition: ModuleUtils.cpp:107
TemplateParamKind::Type
@ Type
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
Alignment.h
llvm::VFABI::setVectorVariantNames
void setVectorVariantNames(CallInst *CI, ArrayRef< std::string > VariantMappings)
Overwrite the Vector Function ABI variants attribute with the names provide in VariantMappings.
Definition: ModuleUtils.cpp:242
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::getUniqueModuleId
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
Definition: ModuleUtils.cpp:210
llvm::appendToGlobalCtors
void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
Definition: ModuleUtils.cpp:67
llvm::codeview::PublicSymFlags::Function
@ Function