41 #define DEBUG_TYPE "constmerge" 43 STATISTIC(NumIdenticalMerged,
"Number of identical global constants merged");
48 if (!LLVMUsed)
return;
73 for (
const auto &V : MDs)
121 "Refusing to delete an externally visible global variable.");
135 SameContentReplacements;
137 size_t ChangesMade = 0;
138 size_t OldChangesMade = 0;
162 UsedGlobals.
count(GV))
184 bool FirstConstantFound = !Slot;
188 << (FirstConstantFound ?
"\n" :
" (updated)\n"));
204 UsedGlobals.
count(GV))
214 auto Found = CMap.find(Init);
215 if (Found == CMap.end())
228 SameContentReplacements.
push_back(std::make_pair(GV, Slot));
234 for (
unsigned i = 0, e = SameContentReplacements.
size(); i != e; ++i) {
239 ++NumIdenticalMerged;
242 if (ChangesMade == OldChangesMade)
244 OldChangesMade = ChangesMade;
246 SameContentReplacements.
clear();
261 struct ConstantMergeLegacyPass :
public ModulePass {
270 bool runOnModule(
Module &M)
override {
282 "Merge Duplicate Global Constants",
false,
false)
285 return new ConstantMergeLegacyPass();
unsigned getAlignment() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
bool hasLocalLinkage() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
STATISTIC(NumFunctions, "Total number of functions")
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode *>> &MDs) const
Appends all attachments for the global to MDs, sorting by attachment ID.
void setAlignment(unsigned Align)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
global_iterator global_begin()
static bool IsBetterCanonical(const GlobalVariable &A, const GlobalVariable &B)
static unsigned getAlignment(GlobalVariable *GV)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static bool hasMetadataOtherThanDebugLoc(const GlobalVariable *GV)
Value * getOperand(unsigned i) const
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
INITIALIZE_PASS(ConstantMergeLegacyPass, "constmerge", "Merge Duplicate Global Constants", false, false) ModulePass *llvm
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static void copyDebugLocMetadata(const GlobalVariable *From, GlobalVariable *To)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void getDebugInfo(SmallVectorImpl< DIGlobalVariableExpression *> &GVs) const
Fill the vector with all debug info attachements.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
static void replace(Module &M, GlobalVariable *Old, GlobalVariable *New)
ModulePass * createConstantMergePass()
createConstantMergePass - This function returns a new pass that merges duplicate global constants tog...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void initializeConstantMergeLegacyPassPass(PassRegistry &)
global_iterator global_end()
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
BlockVerifier::State From
bool hasSection() const
Check if this global has a custom object file section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
bool hasGlobalUnnamedAddr() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
ConstantArray - Constant Array Declarations.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
void setUnnamedAddr(UnnamedAddr Val)
const Value * stripPointerCastsNoFollowAliases() const
Strip off pointer casts and all-zero GEPs.
StringRef getName() const
Return a constant reference to the value's name.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static bool mergeConstants(Module &M)
static void FindUsedValues(GlobalVariable *LLVMUsed, SmallPtrSetImpl< const GlobalValue *> &UsedValues)
Find values that are marked as llvm.used.
static CanMerge makeMergeable(GlobalVariable *Old, GlobalVariable *New)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
void addDebugInfo(DIGlobalVariableExpression *GV)
Attach a DIGlobalVariableExpression.
A container for analyses that lazily runs them and caches their results.
PointerType * getType() const
Global values are always pointers.