Chris Lattner | 424132a | 2003-04-18 04:34:29 +0000 | [diff] [blame] | 1 | //===- ConstantMerge.cpp - Merge duplicate global constants ---------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4816d63 | 2001-10-18 20:05:37 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines the interface to a pass that merges duplicate global |
| 11 | // constants together into a single constant that is shared. This is useful |
| 12 | // because some passes (ie TraceValues) insert a lot of string constants into |
Chris Lattner | 28d1035 | 2002-09-23 23:00:46 +0000 | [diff] [blame] | 13 | // the program, regardless of whether or not an existing string is available. |
Chris Lattner | 4816d63 | 2001-10-18 20:05:37 +0000 | [diff] [blame] | 14 | // |
| 15 | // Algorithm: ConstantMerge is designed to build up a map of available constants |
Chris Lattner | 28d1035 | 2002-09-23 23:00:46 +0000 | [diff] [blame] | 16 | // and eliminate duplicates when it is initialized. |
Chris Lattner | 4816d63 | 2001-10-18 20:05:37 +0000 | [diff] [blame] | 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 20 | #include "llvm/Transforms/IPO/ConstantMerge.h" |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | 67e5345 | 2010-09-15 00:30:11 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallVector.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Statistic.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Constants.h" |
| 26 | #include "llvm/IR/DataLayout.h" |
| 27 | #include "llvm/IR/DerivedTypes.h" |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 28 | #include "llvm/IR/GlobalValue.h" |
| 29 | #include "llvm/IR/GlobalVariable.h" |
| 30 | #include "llvm/IR/LLVMContext.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 31 | #include "llvm/IR/Module.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 32 | #include "llvm/Pass.h" |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Casting.h" |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 34 | #include "llvm/Transforms/IPO.h" |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 35 | #include <algorithm> |
| 36 | #include <cassert> |
| 37 | #include <utility> |
| 38 | |
Chris Lattner | f52e03c | 2003-11-21 21:54:22 +0000 | [diff] [blame] | 39 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 40 | |
Chandler Carruth | 964daaa | 2014-04-22 02:55:47 +0000 | [diff] [blame] | 41 | #define DEBUG_TYPE "constmerge" |
| 42 | |
Chris Lattner | 1631bcb | 2006-12-19 22:09:18 +0000 | [diff] [blame] | 43 | STATISTIC(NumMerged, "Number of global constants merged"); |
Chris Lattner | eac4dcd | 2002-10-09 23:16:04 +0000 | [diff] [blame] | 44 | |
Chris Lattner | 67e5345 | 2010-09-15 00:30:11 +0000 | [diff] [blame] | 45 | /// Find values that are marked as llvm.used. |
| 46 | static void FindUsedValues(GlobalVariable *LLVMUsed, |
Craig Topper | 71b7b68 | 2014-08-21 05:55:13 +0000 | [diff] [blame] | 47 | SmallPtrSetImpl<const GlobalValue*> &UsedValues) { |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 48 | if (!LLVMUsed) return; |
Rafael Espindola | 74f2e46 | 2013-04-22 14:58:02 +0000 | [diff] [blame] | 49 | ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer()); |
| 50 | |
Rafael Espindola | c229a4f | 2013-05-06 01:48:55 +0000 | [diff] [blame] | 51 | for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) { |
| 52 | Value *Operand = Inits->getOperand(i)->stripPointerCastsNoFollowAliases(); |
| 53 | GlobalValue *GV = cast<GlobalValue>(Operand); |
| 54 | UsedValues.insert(GV); |
| 55 | } |
Chris Lattner | 67e5345 | 2010-09-15 00:30:11 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 58 | // True if A is better than B. |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 59 | static bool IsBetterCanonical(const GlobalVariable &A, |
| 60 | const GlobalVariable &B) { |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 61 | if (!A.hasLocalLinkage() && B.hasLocalLinkage()) |
| 62 | return true; |
| 63 | |
| 64 | if (A.hasLocalLinkage() && !B.hasLocalLinkage()) |
| 65 | return false; |
| 66 | |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 67 | return A.hasGlobalUnnamedAddr(); |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Evgeniy Stepanov | 8537d99 | 2017-03-09 00:03:37 +0000 | [diff] [blame] | 70 | static bool hasMetadataOtherThanDebugLoc(const GlobalVariable *GV) { |
| 71 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; |
| 72 | GV->getAllMetadata(MDs); |
| 73 | for (const auto &V : MDs) |
| 74 | if (V.first != LLVMContext::MD_dbg) |
| 75 | return true; |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | static void copyDebugLocMetadata(const GlobalVariable *From, |
| 80 | GlobalVariable *To) { |
| 81 | SmallVector<DIGlobalVariableExpression *, 1> MDs; |
| 82 | From->getDebugInfo(MDs); |
| 83 | for (auto MD : MDs) |
| 84 | To->addDebugInfo(MD); |
| 85 | } |
| 86 | |
Davide Italiano | 17da174 | 2016-05-04 03:21:20 +0000 | [diff] [blame] | 87 | static unsigned getAlignment(GlobalVariable *GV) { |
Rafael Espindola | dd8757a | 2013-11-12 20:21:43 +0000 | [diff] [blame] | 88 | unsigned Align = GV->getAlignment(); |
| 89 | if (Align) |
| 90 | return Align; |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 91 | return GV->getParent()->getDataLayout().getPreferredAlignment(GV); |
Nick Lewycky | 8ac9ece | 2011-07-27 19:47:34 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 94 | static bool mergeConstants(Module &M) { |
Chris Lattner | 67e5345 | 2010-09-15 00:30:11 +0000 | [diff] [blame] | 95 | // Find all the globals that are marked "used". These cannot be merged. |
| 96 | SmallPtrSet<const GlobalValue*, 8> UsedGlobals; |
| 97 | FindUsedValues(M.getGlobalVariable("llvm.used"), UsedGlobals); |
| 98 | FindUsedValues(M.getGlobalVariable("llvm.compiler.used"), UsedGlobals); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 99 | |
| 100 | // Map unique constants to globals. |
| 101 | DenseMap<Constant *, GlobalVariable *> CMap; |
Chris Lattner | c2ee054 | 2003-12-22 23:49:36 +0000 | [diff] [blame] | 102 | |
| 103 | // Replacements - This vector contains a list of replacements to perform. |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 104 | SmallVector<std::pair<GlobalVariable*, GlobalVariable*>, 32> Replacements; |
Chris Lattner | c2ee054 | 2003-12-22 23:49:36 +0000 | [diff] [blame] | 105 | |
Chris Lattner | 56db5e9 | 2003-12-28 07:19:08 +0000 | [diff] [blame] | 106 | bool MadeChange = false; |
Chris Lattner | 4816d63 | 2001-10-18 20:05:37 +0000 | [diff] [blame] | 107 | |
Chris Lattner | 56db5e9 | 2003-12-28 07:19:08 +0000 | [diff] [blame] | 108 | // Iterate constant merging while we are still making progress. Merging two |
| 109 | // constants together may allow us to merge other constants together if the |
| 110 | // second level constants have initializers which point to the globals that |
| 111 | // were just merged. |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 112 | while (true) { |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 113 | // First: Find the canonical constants others will be merged with. |
Chris Lattner | 6f58839 | 2007-04-14 18:06:52 +0000 | [diff] [blame] | 114 | for (Module::global_iterator GVI = M.global_begin(), E = M.global_end(); |
| 115 | GVI != E; ) { |
Duncan P. N. Exon Smith | 1732340 | 2015-10-13 17:51:03 +0000 | [diff] [blame] | 116 | GlobalVariable *GV = &*GVI++; |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 117 | |
Chris Lattner | 02137ee | 2007-04-14 01:11:54 +0000 | [diff] [blame] | 118 | // If this GV is dead, remove it. |
| 119 | GV->removeDeadConstantUsers(); |
Rafael Espindola | 6de96a1 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 120 | if (GV->use_empty() && GV->hasLocalLinkage()) { |
Jeff Cohen | 4bd0fd3 | 2007-04-14 17:18:29 +0000 | [diff] [blame] | 121 | GV->eraseFromParent(); |
| 122 | continue; |
Chris Lattner | 02137ee | 2007-04-14 01:11:54 +0000 | [diff] [blame] | 123 | } |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 124 | |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 125 | // Only process constants with initializers in the default address space. |
Nick Lewycky | 4a1ff16 | 2011-01-15 18:42:52 +0000 | [diff] [blame] | 126 | if (!GV->isConstant() || !GV->hasDefinitiveInitializer() || |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 127 | GV->getType()->getAddressSpace() != 0 || GV->hasSection() || |
Chris Lattner | 67e5345 | 2010-09-15 00:30:11 +0000 | [diff] [blame] | 128 | // Don't touch values marked with attribute(used). |
| 129 | UsedGlobals.count(GV)) |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 130 | continue; |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 131 | |
Eli Friedman | b31c627 | 2012-01-11 22:06:46 +0000 | [diff] [blame] | 132 | // This transformation is legal for weak ODR globals in the sense it |
| 133 | // doesn't change semantics, but we really don't want to perform it |
| 134 | // anyway; it's likely to pessimize code generation, and some tools |
| 135 | // (like the Darwin linker in cases involving CFString) don't expect it. |
| 136 | if (GV->isWeakForLinker()) |
Bill Wendling | c791551 | 2012-01-11 00:13:08 +0000 | [diff] [blame] | 137 | continue; |
| 138 | |
Evgeniy Stepanov | 8537d99 | 2017-03-09 00:03:37 +0000 | [diff] [blame] | 139 | // Don't touch globals with metadata other then !dbg. |
| 140 | if (hasMetadataOtherThanDebugLoc(GV)) |
| 141 | continue; |
| 142 | |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 143 | Constant *Init = GV->getInitializer(); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 144 | |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 145 | // Check to see if the initializer is already known. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 146 | GlobalVariable *&Slot = CMap[Init]; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 147 | |
Bill Wendling | c791551 | 2012-01-11 00:13:08 +0000 | [diff] [blame] | 148 | // If this is the first constant we find or if the old one is local, |
| 149 | // replace with the current one. If the current is externally visible |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 150 | // it cannot be replace, but can be the canonical constant we merge with. |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 151 | if (!Slot || IsBetterCanonical(*GV, *Slot)) |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 152 | Slot = GV; |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 155 | // Second: identify all globals that can be merged together, filling in |
| 156 | // the Replacements vector. We cannot do the replacement in this pass |
| 157 | // because doing so may cause initializers of other globals to be rewritten, |
| 158 | // invalidating the Constant* pointers in CMap. |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 159 | for (Module::global_iterator GVI = M.global_begin(), E = M.global_end(); |
| 160 | GVI != E; ) { |
Duncan P. N. Exon Smith | 1732340 | 2015-10-13 17:51:03 +0000 | [diff] [blame] | 161 | GlobalVariable *GV = &*GVI++; |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 162 | |
| 163 | // Only process constants with initializers in the default address space. |
Nick Lewycky | 4a1ff16 | 2011-01-15 18:42:52 +0000 | [diff] [blame] | 164 | if (!GV->isConstant() || !GV->hasDefinitiveInitializer() || |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 165 | GV->getType()->getAddressSpace() != 0 || GV->hasSection() || |
| 166 | // Don't touch values marked with attribute(used). |
| 167 | UsedGlobals.count(GV)) |
| 168 | continue; |
| 169 | |
Eli Friedman | b31c627 | 2012-01-11 22:06:46 +0000 | [diff] [blame] | 170 | // We can only replace constant with local linkage. |
| 171 | if (!GV->hasLocalLinkage()) |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 172 | continue; |
| 173 | |
| 174 | Constant *Init = GV->getInitializer(); |
| 175 | |
| 176 | // Check to see if the initializer is already known. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 177 | GlobalVariable *Slot = CMap[Init]; |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 178 | |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 179 | if (!Slot || Slot == GV) |
| 180 | continue; |
| 181 | |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 182 | if (!Slot->hasGlobalUnnamedAddr() && !GV->hasGlobalUnnamedAddr()) |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 183 | continue; |
| 184 | |
Evgeniy Stepanov | 8537d99 | 2017-03-09 00:03:37 +0000 | [diff] [blame] | 185 | if (hasMetadataOtherThanDebugLoc(GV)) |
| 186 | continue; |
| 187 | |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 188 | if (!GV->hasGlobalUnnamedAddr()) |
| 189 | Slot->setUnnamedAddr(GlobalValue::UnnamedAddr::None); |
Rafael Espindola | 751677a | 2011-01-16 17:05:09 +0000 | [diff] [blame] | 190 | |
| 191 | // Make all uses of the duplicate constant use the canonical version. |
| 192 | Replacements.push_back(std::make_pair(GV, Slot)); |
Chris Lattner | 02137ee | 2007-04-14 01:11:54 +0000 | [diff] [blame] | 193 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 194 | |
Chris Lattner | 56db5e9 | 2003-12-28 07:19:08 +0000 | [diff] [blame] | 195 | if (Replacements.empty()) |
| 196 | return MadeChange; |
| 197 | CMap.clear(); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 198 | |
Chris Lattner | 56db5e9 | 2003-12-28 07:19:08 +0000 | [diff] [blame] | 199 | // Now that we have figured out which replacements must be made, do them all |
| 200 | // now. This avoid invalidating the pointers in CMap, which are unneeded |
| 201 | // now. |
| 202 | for (unsigned i = 0, e = Replacements.size(); i != e; ++i) { |
Nick Lewycky | 8ac9ece | 2011-07-27 19:47:34 +0000 | [diff] [blame] | 203 | // Bump the alignment if necessary. |
| 204 | if (Replacements[i].first->getAlignment() || |
| 205 | Replacements[i].second->getAlignment()) { |
Rafael Espindola | dd8757a | 2013-11-12 20:21:43 +0000 | [diff] [blame] | 206 | Replacements[i].second->setAlignment( |
| 207 | std::max(getAlignment(Replacements[i].first), |
| 208 | getAlignment(Replacements[i].second))); |
Nick Lewycky | 8ac9ece | 2011-07-27 19:47:34 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Evgeniy Stepanov | 8537d99 | 2017-03-09 00:03:37 +0000 | [diff] [blame] | 211 | copyDebugLocMetadata(Replacements[i].first, Replacements[i].second); |
| 212 | |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 213 | // Eliminate any uses of the dead global. |
Chris Lattner | 56db5e9 | 2003-12-28 07:19:08 +0000 | [diff] [blame] | 214 | Replacements[i].first->replaceAllUsesWith(Replacements[i].second); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 215 | |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 216 | // Delete the global value from the module. |
Nick Lewycky | 0296a48 | 2011-01-15 18:14:21 +0000 | [diff] [blame] | 217 | assert(Replacements[i].first->hasLocalLinkage() && |
| 218 | "Refusing to delete an externally visible global variable."); |
Chris Lattner | 75879be | 2010-02-12 18:17:23 +0000 | [diff] [blame] | 219 | Replacements[i].first->eraseFromParent(); |
Chris Lattner | 56db5e9 | 2003-12-28 07:19:08 +0000 | [diff] [blame] | 220 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 221 | |
Chris Lattner | 56db5e9 | 2003-12-28 07:19:08 +0000 | [diff] [blame] | 222 | NumMerged += Replacements.size(); |
| 223 | Replacements.clear(); |
Chris Lattner | c2ee054 | 2003-12-22 23:49:36 +0000 | [diff] [blame] | 224 | } |
Chris Lattner | c2ee054 | 2003-12-22 23:49:36 +0000 | [diff] [blame] | 225 | } |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 226 | |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 227 | PreservedAnalyses ConstantMergePass::run(Module &M, ModuleAnalysisManager &) { |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 228 | if (!mergeConstants(M)) |
| 229 | return PreservedAnalyses::all(); |
| 230 | return PreservedAnalyses::none(); |
| 231 | } |
| 232 | |
| 233 | namespace { |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 234 | |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 235 | struct ConstantMergeLegacyPass : public ModulePass { |
| 236 | static char ID; // Pass identification, replacement for typeid |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 237 | |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 238 | ConstantMergeLegacyPass() : ModulePass(ID) { |
| 239 | initializeConstantMergeLegacyPassPass(*PassRegistry::getPassRegistry()); |
| 240 | } |
| 241 | |
| 242 | // For this pass, process all of the globals in the module, eliminating |
| 243 | // duplicate constants. |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 244 | bool runOnModule(Module &M) override { |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 245 | if (skipModule(M)) |
| 246 | return false; |
| 247 | return mergeConstants(M); |
| 248 | } |
| 249 | }; |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 250 | |
| 251 | } // end anonymous namespace |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 252 | |
| 253 | char ConstantMergeLegacyPass::ID = 0; |
Eugene Zelenko | e9ea08a | 2017-10-10 22:49:55 +0000 | [diff] [blame] | 254 | |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 255 | INITIALIZE_PASS(ConstantMergeLegacyPass, "constmerge", |
| 256 | "Merge Duplicate Global Constants", false, false) |
| 257 | |
| 258 | ModulePass *llvm::createConstantMergePass() { |
| 259 | return new ConstantMergeLegacyPass(); |
| 260 | } |