LLVM 22.0.0git
FunctionImportUtils.h
Go to the documentation of this file.
1//===- FunctionImportUtils.h - Importing support utilities -----*- 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 file defines the FunctionImportGlobalProcessing class which is used
10// to perform the necessary global value handling for function importing.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TRANSFORMS_UTILS_FUNCTIONIMPORTUTILS_H
15#define LLVM_TRANSFORMS_UTILS_FUNCTIONIMPORTUTILS_H
16
17#include "llvm/ADT/SetVector.h"
20
21namespace llvm {
22class Module;
23
24/// Class to handle necessary GlobalValue changes required by ThinLTO
25/// function importing, including linkage changes and any necessary renaming.
27 /// The Module which we are exporting or importing functions from.
28 Module &M;
29
30 /// Module summary index passed in for function importing/exporting handling.
31 const ModuleSummaryIndex &ImportIndex;
32
33 /// Globals to import from this module, all other functions will be
34 /// imported as declarations instead of definitions.
35 SetVector<GlobalValue *> *GlobalsToImport;
36
37 /// Set to true if the given ModuleSummaryIndex contains any functions
38 /// from this source module, in which case we must conservatively assume
39 /// that any of its functions may be imported into another module
40 /// as part of a different backend compilation process.
41 bool HasExportedFunctions = false;
42
43 /// Set to true (only applicatable to ELF -fpic) if dso_local should be
44 /// dropped for a declaration.
45 ///
46 /// On ELF, the assembler is conservative and assumes a global default
47 /// visibility symbol can be interposable. No direct access relocation is
48 /// allowed, if the definition is not in the translation unit, even if the
49 /// definition is available in the linkage unit. Thus we need to clear
50 /// dso_local to disable direct access.
51 ///
52 /// This flag should not be set for -fno-pic or -fpie, which would
53 /// unnecessarily disable direct access.
54 bool ClearDSOLocalOnDeclarations;
55
56 /// Set of llvm.*used values, in order to validate that we don't try
57 /// to promote any non-renamable values.
59
60 /// Keep track of any COMDATs that require renaming (because COMDAT
61 /// leader was promoted and renamed). Maps from original COMDAT to one
62 /// with new name.
64
65 /// Check if we should promote the given local value to global scope.
66 bool shouldPromoteLocalToGlobal(const GlobalValue *SGV, ValueInfo VI);
67
68#ifndef NDEBUG
69 /// Check if the given value is a local that can't be renamed (promoted).
70 /// Only used in assertion checking, and disabled under NDEBUG since the Used
71 /// set will not be populated.
72 bool isNonRenamableLocal(const GlobalValue &GV) const;
73#endif
74
75 /// Helper methods to check if we are importing from or potentially
76 /// exporting from the current source module.
77 bool isPerformingImport() const { return GlobalsToImport != nullptr; }
78 bool isModuleExporting() const { return HasExportedFunctions; }
79
80 /// If we are importing from the source module, checks if we should
81 /// import SGV as a definition, otherwise import as a declaration.
82 bool doImportAsDefinition(const GlobalValue *SGV);
83
84 /// Get the name for a local SGV that should be promoted and renamed to global
85 /// scope in the linked destination module.
86 std::string getPromotedName(const GlobalValue *SGV);
87
88 /// Process globals so that they can be used in ThinLTO. This includes
89 /// promoting local variables so that they can be reference externally by
90 /// thin lto imported globals and converting strong external globals to
91 /// available_externally.
92 void processGlobalsForThinLTO();
93 void processGlobalForThinLTO(GlobalValue &GV);
94
95 /// Get the new linkage for SGV that should be used in the linked destination
96 /// module. Specifically, for ThinLTO importing or exporting it may need
97 /// to be adjusted. When \p DoPromote is true then we must adjust the
98 /// linkage for a required promotion of a local to global scope.
99 GlobalValue::LinkageTypes getLinkage(const GlobalValue *SGV, bool DoPromote);
100
101 /// The symbols with these names are moved to a different module and should be
102 /// promoted to external linkage where they are defined.
103 DenseSet<GlobalValue::GUID> SymbolsToMove;
104
105public:
108 SetVector<GlobalValue *> *GlobalsToImport,
109 bool ClearDSOLocalOnDeclarations);
110 LLVM_ABI void run();
111};
112
113/// Perform in-place global value handling on the given Module for
114/// exported local functions renamed and promoted for ThinLTO.
115LLVM_ABI void
117 bool ClearDSOLocalOnDeclarations,
118 SetVector<GlobalValue *> *GlobalsToImport = nullptr);
119
120} // End llvm namespace
121
122#endif
#define LLVM_ABI
Definition: Compiler.h:213
uint32_t Index
Machine Check Debug Module
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
This file implements a set that has insertion order iteration characteristics.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:263
Class to handle necessary GlobalValue changes required by ThinLTO function importing,...
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:52
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
A vector that has set insertion semantics.
Definition: SetVector.h:59
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:541
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI void renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, bool ClearDSOLocalOnDeclarations, SetVector< GlobalValue * > *GlobalsToImport=nullptr)
Perform in-place global value handling on the given Module for exported local functions renamed and p...
Struct that holds a reference to a particular GUID in a global value summary.