|
122 | 122 | #include "llvm/Support/Debug.h" |
123 | 123 | #include "llvm/Support/raw_ostream.h" |
124 | 124 | #include "llvm/Transforms/IPO.h" |
| 125 | +#include "llvm/Transforms/IPO/MergeFunctions.h" |
125 | 126 | #include "llvm/Transforms/Utils/FunctionComparator.h" |
126 | 127 | #include <algorithm> |
127 | 128 | #include <cassert> |
@@ -196,16 +197,12 @@ class FunctionNode { |
196 | 197 | /// by considering all pointer types to be equivalent. Once identified, |
197 | 198 | /// MergeFunctions will fold them by replacing a call to one to a call to a |
198 | 199 | /// bitcast of the other. |
199 | | -class MergeFunctions : public ModulePass { |
| 200 | +class MergeFunctions { |
200 | 201 | public: |
201 | | - static char ID; |
202 | | - |
203 | | - MergeFunctions() |
204 | | - : ModulePass(ID), FnTree(FunctionNodeCmp(&GlobalNumbers)) { |
205 | | - initializeMergeFunctionsPass(*PassRegistry::getPassRegistry()); |
| 202 | + MergeFunctions() : FnTree(FunctionNodeCmp(&GlobalNumbers)) { |
206 | 203 | } |
207 | 204 |
|
208 | | - bool runOnModule(Module &M) override; |
| 205 | + bool runOnModule(Module &M); |
209 | 206 |
|
210 | 207 | private: |
211 | 208 | // The function comparison operator is provided here so that FunctionNodes do |
@@ -298,14 +295,39 @@ class MergeFunctions : public ModulePass { |
298 | 295 | DenseMap<AssertingVH<Function>, FnTreeType::iterator> FNodesInTree; |
299 | 296 | }; |
300 | 297 |
|
301 | | -} // end anonymous namespace |
| 298 | +class MergeFunctionsLegacyPass : public ModulePass { |
| 299 | +public: |
| 300 | + static char ID; |
302 | 301 |
|
303 | | -char MergeFunctions::ID = 0; |
| 302 | + MergeFunctionsLegacyPass(): ModulePass(ID) { |
| 303 | + initializeMergeFunctionsLegacyPassPass(*PassRegistry::getPassRegistry()); |
| 304 | + } |
304 | 305 |
|
305 | | -INITIALIZE_PASS(MergeFunctions, "mergefunc", "Merge Functions", false, false) |
| 306 | + bool runOnModule(Module &M) override { |
| 307 | + if (skipModule(M)) |
| 308 | + return false; |
| 309 | + |
| 310 | + MergeFunctions MF; |
| 311 | + return MF.runOnModule(M); |
| 312 | + } |
| 313 | +}; |
| 314 | + |
| 315 | +} // end anonymous namespace |
| 316 | + |
| 317 | +char MergeFunctionsLegacyPass::ID = 0; |
| 318 | +INITIALIZE_PASS(MergeFunctionsLegacyPass, "mergefunc", |
| 319 | + "Merge Functions", false, false) |
306 | 320 |
|
307 | 321 | ModulePass *llvm::createMergeFunctionsPass() { |
308 | | - return new MergeFunctions(); |
| 322 | + return new MergeFunctionsLegacyPass(); |
| 323 | +} |
| 324 | + |
| 325 | +PreservedAnalyses MergeFunctionsPass::run(Module &M, |
| 326 | + ModuleAnalysisManager &AM) { |
| 327 | + MergeFunctions MF; |
| 328 | + if (!MF.runOnModule(M)) |
| 329 | + return PreservedAnalyses::all(); |
| 330 | + return PreservedAnalyses::none(); |
309 | 331 | } |
310 | 332 |
|
311 | 333 | #ifndef NDEBUG |
@@ -387,9 +409,6 @@ static bool isEligibleForMerging(Function &F) { |
387 | 409 | } |
388 | 410 |
|
389 | 411 | bool MergeFunctions::runOnModule(Module &M) { |
390 | | - if (skipModule(M)) |
391 | | - return false; |
392 | | - |
393 | 412 | bool Changed = false; |
394 | 413 |
|
395 | 414 | // All functions in the module, ordered by hash. Functions with a unique |
|
0 commit comments