40#define DEBUG_TYPE "constmerge"
42STATISTIC(NumIdenticalMerged,
"Number of identical global constants merged");
47 if (!LLVMUsed)
return;
60 if (!
A.hasLocalLinkage() &&
B.hasLocalLinkage())
63 if (
A.hasLocalLinkage() && !
B.hasLocalLinkage())
66 return A.hasGlobalUnnamedAddr();
72 for (
const auto &V : MDs)
73 if (V.first != LLVMContext::MD_dbg)
81 From->getDebugInfo(MDs);
100 UsedGlobals.
count(GV);
111 New->setUnnamedAddr(GlobalValue::UnnamedAddr::None);
119 << New->getName() <<
"\n");
122 if (Old->
getAlign() || New->getAlign())
130 "Refusing to delete an externally visible global variable.");
138 FindUsedValues(M.getGlobalVariable(
"llvm.compiler.used"), UsedGlobals);
144 SameContentReplacements;
146 size_t ChangesMade = 0;
147 size_t OldChangesMade = 0;
157 GV.removeDeadConstantUsers();
158 if (GV.use_empty() && GV.hasLocalLinkage()) {
159 GV.eraseFromParent();
171 if (GV.isWeakForLinker())
186 bool FirstConstantFound = !Slot;
190 << (FirstConstantFound ?
"\n" :
" (updated)\n"));
203 if (!GV.hasLocalLinkage())
210 if (Found == CMap.
end())
222 << Slot->getName() <<
"\n");
223 SameContentReplacements.
push_back(std::make_pair(&GV, Slot));
229 for (
unsigned i = 0, e = SameContentReplacements.
size(); i != e; ++i) {
234 ++NumIdenticalMerged;
237 if (ChangesMade == OldChangesMade)
239 OldChangesMade = ChangesMade;
241 SameContentReplacements.
clear();
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static bool IsBetterCanonical(const GlobalVariable &A, const GlobalVariable &B)
static bool hasMetadataOtherThanDebugLoc(const GlobalVariable *GV)
static void copyDebugLocMetadata(const GlobalVariable *From, GlobalVariable *To)
static bool mergeConstants(Module &M)
static Align getAlign(GlobalVariable *GV)
static bool isUnmergeableGlobal(GlobalVariable *GV, const SmallPtrSetImpl< const GlobalValue * > &UsedGlobals)
static void FindUsedValues(GlobalVariable *LLVMUsed, SmallPtrSetImpl< const GlobalValue * > &UsedValues)
Find values that are marked as llvm.used.
static void replace(Module &M, GlobalVariable *Old, GlobalVariable *New)
static CanMerge makeMergeable(GlobalVariable *Old, GlobalVariable *New)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A container for analyses that lazily runs them and caches their results.
ConstantArray - Constant Array Declarations.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
This is an important base class in LLVM.
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
iterator find(const_arg_type_t< KeyT > Val)
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
bool hasSection() const
Check if this global has a custom object file section.
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
bool hasLocalLinkage() const
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
bool hasGlobalUnnamedAddr() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
void addDebugInfo(DIGlobalVariableExpression *GV)
Attach a DIGlobalVariableExpression.
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
A Module instance is used to store all the information related to an LLVM module.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
StringRef getName() const
Return a constant reference to the value's name.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
This struct is a compact representation of a valid (non-zero power of two) alignment.