LLVM  13.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/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
18 #include <utility> // for std::pair
19 
20 namespace llvm {
21 
22 template <typename T> class ArrayRef;
23 class Module;
24 class Function;
25 class FunctionCallee;
26 class GlobalValue;
27 class Constant;
28 class Value;
29 class Type;
30 
31 /// Append F to the list of global ctors of module M with the given Priority.
32 /// This wraps the function in the appropriate structure and stores it along
33 /// side other global constructors. For details see
34 /// http://llvm.org/docs/LangRef.html#intg_global_ctors
35 void appendToGlobalCtors(Module &M, Function *F, int Priority,
36  Constant *Data = nullptr);
37 
38 /// Same as appendToGlobalCtors(), but for global dtors.
39 void appendToGlobalDtors(Module &M, Function *F, int Priority,
40  Constant *Data = nullptr);
41 
42 FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName,
43  ArrayRef<Type *> InitArgTypes);
44 
45 /// Creates sanitizer constructor function.
46 /// \return Returns pointer to constructor.
47 Function *createSanitizerCtor(Module &M, StringRef CtorName);
48 
49 /// Creates sanitizer constructor function, and calls sanitizer's init
50 /// function from it.
51 /// \return Returns pair of pointers to constructor, and init functions
52 /// respectively.
53 std::pair<Function *, FunctionCallee> createSanitizerCtorAndInitFunctions(
54  Module &M, StringRef CtorName, StringRef InitName,
55  ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
56  StringRef VersionCheckName = StringRef());
57 
58 /// Creates sanitizer constructor function lazily. If a constructor and init
59 /// function already exist, this function returns it. Otherwise it calls \c
60 /// createSanitizerCtorAndInitFunctions. The FunctionsCreatedCallback is invoked
61 /// in that case, passing the new Ctor and Init function.
62 ///
63 /// \return Returns pair of pointers to constructor, and init functions
64 /// respectively.
65 std::pair<Function *, FunctionCallee> getOrCreateSanitizerCtorAndInitFunctions(
66  Module &M, StringRef CtorName, StringRef InitName,
67  ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
68  function_ref<void(Function *, FunctionCallee)> FunctionsCreatedCallback,
69  StringRef VersionCheckName = StringRef());
70 
71 // Creates and returns a sanitizer init function without argument if it doesn't
72 // exist, and adds it to the global constructors list. Otherwise it returns the
73 // existing function.
75 
76 /// Rename all the anon globals in the module using a hash computed from
77 /// the list of public globals in the module.
79 
80 /// Adds global values to the llvm.used list.
81 void appendToUsed(Module &M, ArrayRef<GlobalValue *> Values);
82 
83 /// Adds global values to the llvm.compiler.used list.
84 void appendToCompilerUsed(Module &M, ArrayRef<GlobalValue *> Values);
85 
86 /// Filter out potentially dead comdat functions where other entries keep the
87 /// entire comdat group alive.
88 ///
89 /// This is designed for cases where functions appear to become dead but remain
90 /// alive due to other live entries in their comdat group.
91 ///
92 /// The \p DeadComdatFunctions container should only have pointers to
93 /// `Function`s which are members of a comdat group and are believed to be
94 /// dead.
95 ///
96 /// After this routine finishes, the only remaining `Function`s in \p
97 /// DeadComdatFunctions are those where every member of the comdat is listed
98 /// and thus removing them is safe (provided *all* are removed).
100  Module &M, SmallVectorImpl<Function *> &DeadComdatFunctions);
101 
102 /// Produce a unique identifier for this module by taking the MD5 sum of
103 /// the names of the module's strong external symbols that are not comdat
104 /// members.
105 ///
106 /// This identifier is normally guaranteed to be unique, or the program would
107 /// fail to link due to multiply defined symbols.
108 ///
109 /// If the module has no strong external symbols (such a module may still have a
110 /// semantic effect if it performs global initialization), we cannot produce a
111 /// unique identifier for this module, so we return the empty string.
112 std::string getUniqueModuleId(Module *M);
113 
114 class CallInst;
115 namespace VFABI {
116 /// Overwrite the Vector Function ABI variants attribute with the names provide
117 /// in \p VariantMappings.
118 void setVectorVariantNames(CallInst *CI,
119  const SmallVector<std::string, 8> &VariantMappings);
120 } // End VFABI namespace
121 } // End llvm namespace
122 
123 #endif // LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
llvm
Definition: AllocatorList.h:23
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
llvm::VFABI::setVectorVariantNames
void setVectorVariantNames(CallInst *CI, const SmallVector< std::string, 8 > &VariantMappings)
Overwrite the Vector Function ABI variants attribute with the names provide in VariantMappings.
Definition: ModuleUtils.cpp:296
llvm::filterDeadComdatFunctions
void filterDeadComdatFunctions(Module &M, SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.
Definition: ModuleUtils.cpp:200
StringRef.h
llvm::createSanitizerCtor
Function * createSanitizerCtor(Module &M, StringRef CtorName)
Creates sanitizer constructor function.
Definition: ModuleUtils.cpp:124
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::appendToGlobalDtors
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
Definition: ModuleUtils.cpp:70
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:156
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:65
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:69
llvm::appendToCompilerUsed
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
Definition: ModuleUtils.cpp:110
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:134
llvm::declareSanitizerInitFunction
FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes)
Definition: ModuleUtils.cpp:115
llvm::appendToUsed
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
Definition: ModuleUtils.cpp:106
TemplateParamKind::Type
@ Type
llvm::getOrCreateInitFunction
Function * getOrCreateInitFunction(Module &M, StringRef Name)
Definition: ModuleUtils.cpp:178
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
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:264
SmallVector.h
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:66
llvm::codeview::PublicSymFlags::Function
@ Function