20 #define DEBUG_TYPE "constmerge"
34 STATISTIC(NumMerged,
"Number of global constants merged");
45 bool runOnModule(
Module &M);
60 "Merge Duplicate Global Constants",
false,
false)
69 if (LLVMUsed == 0)
return;
100 return TD->getPreferredAlignment(GV);
104 bool ConstantMerge::runOnModule(
Module &M) {
105 TD = getAnalysisIfAvailable<DataLayout>();
120 bool MadeChange =
false;
144 UsedGlobals.count(GV))
179 UsedGlobals.count(GV))
192 if (!Slot || Slot == GV)
202 Replacements.
push_back(std::make_pair(GV, Slot));
205 if (Replacements.
empty())
212 for (
unsigned i = 0, e = Replacements.
size(); i != e; ++i) {
214 if (Replacements[i].first->getAlignment() ||
215 Replacements[i].second->getAlignment()) {
216 Replacements[i].second->setAlignment(
217 std::max(getAlignment(Replacements[i].first),
218 getAlignment(Replacements[i].second)));
222 Replacements[i].first->replaceAllUsesWith(Replacements[i].second);
225 assert(Replacements[i].first->hasLocalLinkage() &&
226 "Refusing to delete an externally visible global variable.");
227 Replacements[i].first->eraseFromParent();
230 NumMerged += Replacements.
size();
231 Replacements.
clear();
void push_back(const T &Elt)
static PassRegistry * getPassRegistry()
static void FindUsedValues(GlobalVariable *LLVMUsed, SmallPtrSet< const GlobalValue *, 8 > &UsedValues)
Find values that are marked as llvm.used.
The main container class for the LLVM Intermediate Representation.
unsigned getAlignment() const
unsigned getNumOperands() const
static bool IsBetterCannonical(const GlobalVariable &A, const GlobalVariable &B)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
const Constant * getInitializer() const
const GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false) const
ID
LLVM Calling Convention Representation.
global_iterator global_begin()
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
INITIALIZE_PASS(ConstantMerge,"constmerge","Merge Duplicate Global Constants", false, false) ModulePass *llvm
bool hasDefinitiveInitializer() const
static bool isWeakForLinker(LinkageTypes Linkage)
Value * stripPointerCastsNoFollowAliases()
Strips off any unneeded pointer casts and all-zero GEPs from the specified value, returning the origi...
LLVM Constant Representation.
virtual void eraseFromParent()
Value * getOperand(unsigned i) const
ModulePass * createConstantMergePass()
global_iterator global_end()
STATISTIC(NumMerged,"Number of global constants merged")
void setUnnamedAddr(bool Val)
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
PointerType * getType() const
getType - Global values are always pointers.
void initializeConstantMergePass(PassRegistry &)
bool hasLocalLinkage() const
void removeDeadConstantUsers() const
LLVM Value Representation.
bool hasUnnamedAddr() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD