LLVM  6.0.0svn
ModuleUtils.h
Go to the documentation of this file.
1 //===-- ModuleUtils.h - Functions to manipulate Modules ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This family of functions perform manipulations on Modules.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
15 #define LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
16 
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 GlobalValue;
26 class GlobalVariable;
27 class Constant;
28 class StringRef;
29 class Value;
30 class Type;
31 
32 /// Append F to the list of global ctors of module M with the given Priority.
33 /// This wraps the function in the appropriate structure and stores it along
34 /// side other global constructors. For details see
35 /// http://llvm.org/docs/LangRef.html#intg_global_ctors
36 void appendToGlobalCtors(Module &M, Function *F, int Priority,
37  Constant *Data = nullptr);
38 
39 /// Same as appendToGlobalCtors(), but for global dtors.
40 void appendToGlobalDtors(Module &M, Function *F, int Priority,
41  Constant *Data = nullptr);
42 
43 // Validate the result of Module::getOrInsertFunction called for an interface
44 // function of given sanitizer. If the instrumented module defines a function
45 // with the same name, their prototypes must match, otherwise
46 // getOrInsertFunction returns a bitcast.
48 
49 Function *declareSanitizerInitFunction(Module &M, StringRef InitName,
50  ArrayRef<Type *> InitArgTypes);
51 
52 /// \brief Creates sanitizer constructor function, and calls sanitizer's init
53 /// function from it.
54 /// \return Returns pair of pointers to constructor, and init functions
55 /// respectively.
56 std::pair<Function *, Function *> createSanitizerCtorAndInitFunctions(
57  Module &M, StringRef CtorName, StringRef InitName,
58  ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
59  StringRef VersionCheckName = StringRef());
60 
61 /// Rename all the anon globals in the module using a hash computed from
62 /// the list of public globals in the module.
63 bool nameUnamedGlobals(Module &M);
64 
65 /// \brief Adds global values to the llvm.used list.
66 void appendToUsed(Module &M, ArrayRef<GlobalValue *> Values);
67 
68 /// \brief Adds global values to the llvm.compiler.used list.
69 void appendToCompilerUsed(Module &M, ArrayRef<GlobalValue *> Values);
70 
71 /// Filter out potentially dead comdat functions where other entries keep the
72 /// entire comdat group alive.
73 ///
74 /// This is designed for cases where functions appear to become dead but remain
75 /// alive due to other live entries in their comdat group.
76 ///
77 /// The \p DeadComdatFunctions container should only have pointers to
78 /// `Function`s which are members of a comdat group and are believed to be
79 /// dead.
80 ///
81 /// After this routine finishes, the only remaining `Function`s in \p
82 /// DeadComdatFunctions are those where every member of the comdat is listed
83 /// and thus removing them is safe (provided *all* are removed).
85  Module &M, SmallVectorImpl<Function *> &DeadComdatFunctions);
86 
87 /// \brief Produce a unique identifier for this module by taking the MD5 sum of
88 /// the names of the module's strong external symbols that are not comdat
89 /// members.
90 ///
91 /// This identifier is normally guaranteed to be unique, or the program would
92 /// fail to link due to multiply defined symbols.
93 ///
94 /// If the module has no strong external symbols (such a module may still have a
95 /// semantic effect if it performs global initialization), we cannot produce a
96 /// unique identifier for this module, so we return the empty string.
97 std::string getUniqueModuleId(Module *M);
98 
99 } // End llvm namespace
100 
101 #endif // LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue *> Values)
Adds global values to the llvm.compiler.used list.
Function * declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type *> InitArgTypes)
void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
Definition: ModuleUtils.cpp:88
Function * checkSanitizerInterfaceFunction(Constant *FuncOrBitcast)
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
F(f)
bool nameUnamedGlobals(Module &M)
Rename all the anon globals in the module using a hash computed from the list of public globals in th...
void appendToUsed(Module &M, ArrayRef< GlobalValue *> Values)
Adds global values to the llvm.used list.
std::pair< Function *, Function * > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type *> InitArgTypes, ArrayRef< Value *> InitArgs, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function, and calls sanitizer&#39;s init function from it.
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module&#39;s strong...
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:84
void filterDeadComdatFunctions(Module &M, SmallVectorImpl< Function *> &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive...