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.
47 Function *checkSanitizerInterfaceFunction(Constant *FuncOrBitcast);
48 
49 /// \brief 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 *, Function *> createSanitizerCtorAndInitFunctions(
54     Module &M, StringRef CtorName, StringRef InitName,
55     ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
56     StringRef VersionCheckName = StringRef());
57 
58 /// Rename all the anon functions in the module using a hash computed from
59 /// the list of public globals in the module.
60 bool nameUnamedFunctions(Module &M);
61 
62 } // End llvm namespace
63 
64 #endif //  LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
65