Mercurial > hg > CbC > CbC_llvm
comparison tools/bugpoint/ExtractFunction.cpp @ 147:c2174574ed3a
LLVM 10
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 16:55:33 +0900 |
parents | 3a76565eade5 |
children |
comparison
equal
deleted
inserted
replaced
134:3a76565eade5 | 147:c2174574ed3a |
---|---|
1 //===- ExtractFunction.cpp - Extract a function from Program --------------===// | 1 //===- ExtractFunction.cpp - Extract a function from Program --------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 // | 8 // |
10 // This file implements several methods that are used to extract functions, | 9 // This file implements several methods that are used to extract functions, |
11 // loops, or portions of a module from the rest of the module. | 10 // loops, or portions of a module from the rest of the module. |
125 } | 124 } |
126 return New; | 125 return New; |
127 } | 126 } |
128 | 127 |
129 std::unique_ptr<Module> | 128 std::unique_ptr<Module> |
130 BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) { | 129 BugDriver::performFinalCleanups(std::unique_ptr<Module> M, |
130 bool MayModifySemantics) { | |
131 // Make all functions external, so GlobalDCE doesn't delete them... | 131 // Make all functions external, so GlobalDCE doesn't delete them... |
132 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) | 132 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) |
133 I->setLinkage(GlobalValue::ExternalLinkage); | 133 I->setLinkage(GlobalValue::ExternalLinkage); |
134 | 134 |
135 std::vector<std::string> CleanupPasses; | 135 std::vector<std::string> CleanupPasses; |
138 if (MayModifySemantics) | 138 if (MayModifySemantics) |
139 CleanupPasses.push_back("deadarghaX0r"); | 139 CleanupPasses.push_back("deadarghaX0r"); |
140 else | 140 else |
141 CleanupPasses.push_back("deadargelim"); | 141 CleanupPasses.push_back("deadargelim"); |
142 | 142 |
143 std::unique_ptr<Module> New = runPassesOn(M, CleanupPasses); | 143 std::unique_ptr<Module> New = runPassesOn(M.get(), CleanupPasses); |
144 if (!New) { | 144 if (!New) { |
145 errs() << "Final cleanups failed. Sorry. :( Please report a bug!\n"; | 145 errs() << "Final cleanups failed. Sorry. :( Please report a bug!\n"; |
146 return nullptr; | 146 return nullptr; |
147 } | 147 } |
148 delete M; | |
149 return New; | 148 return New; |
150 } | 149 } |
151 | 150 |
152 std::unique_ptr<Module> BugDriver::extractLoop(Module *M) { | 151 std::unique_ptr<Module> BugDriver::extractLoop(Module *M) { |
153 std::vector<std::string> LoopExtractPasses; | 152 std::vector<std::string> LoopExtractPasses; |
322 | 321 |
323 // Remove the Test functions from the Safe module | 322 // Remove the Test functions from the Safe module |
324 std::set<Function *> TestFunctions; | 323 std::set<Function *> TestFunctions; |
325 for (unsigned i = 0, e = F.size(); i != e; ++i) { | 324 for (unsigned i = 0, e = F.size(); i != e; ++i) { |
326 Function *TNOF = cast<Function>(VMap[F[i]]); | 325 Function *TNOF = cast<Function>(VMap[F[i]]); |
327 DEBUG(errs() << "Removing function "); | 326 LLVM_DEBUG(errs() << "Removing function "); |
328 DEBUG(TNOF->printAsOperand(errs(), false)); | 327 LLVM_DEBUG(TNOF->printAsOperand(errs(), false)); |
329 DEBUG(errs() << "\n"); | 328 LLVM_DEBUG(errs() << "\n"); |
330 TestFunctions.insert(cast<Function>(NewVMap[TNOF])); | 329 TestFunctions.insert(cast<Function>(NewVMap[TNOF])); |
331 DeleteFunctionBody(TNOF); // Function is now external in this module! | 330 DeleteFunctionBody(TNOF); // Function is now external in this module! |
332 } | 331 } |
333 | 332 |
334 // Remove the Safe functions from the Test module | 333 // Remove the Safe functions from the Test module |