• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ArrayRef.h"
18 #include "llvm/ADT/StringRef.h"
19 #include <utility> // for std::pair
20 
21 namespace llvm {
22 
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 template <class PtrType> class SmallPtrSetImpl;
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 
39 /// Same as appendToGlobalCtors(), but for global dtors.
40 void appendToGlobalDtors(Module &M, Function *F, int Priority);
41 
42 /// \brief Given "llvm.used" or "llvm.compiler.used" as a global name, collect
43 /// the initializer elements of that global in Set and return the global itself.
44 GlobalVariable *collectUsedGlobalVariables(Module &M,
45                                            SmallPtrSetImpl<GlobalValue *> &Set,
46                                            bool CompilerUsed);
47 
48 // Validate the result of Module::getOrInsertFunction called for an interface
49 // function of given sanitizer. If the instrumented module defines a function
50 // with the same name, their prototypes must match, otherwise
51 // getOrInsertFunction returns a bitcast.
52 Function *checkSanitizerInterfaceFunction(Constant *FuncOrBitcast);
53 
54 /// \brief Creates sanitizer constructor function, and calls sanitizer's init
55 /// function from it.
56 /// \return Returns pair of pointers to constructor, and init functions
57 /// respectively.
58 std::pair<Function *, Function *> createSanitizerCtorAndInitFunctions(
59     Module &M, StringRef CtorName, StringRef InitName,
60     ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
61     StringRef VersionCheckName = StringRef());
62 } // End llvm namespace
63 
64 #endif //  LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
65