comparison lib/Transforms/IPO/MergeFunctions.cpp @ 83:60c9769439b8 LLVM3.7

LLVM 3.7
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Wed, 18 Feb 2015 14:55:36 +0900
parents 54457678186b
children 5e5d649e25d2 afa8332a0e37
comparison
equal deleted inserted replaced
78:af83660cff7b 83:60c9769439b8
390 /// could be operands from further BBs we didn't scan yet. 390 /// could be operands from further BBs we didn't scan yet.
391 /// So it's impossible to use dominance properties in general. 391 /// So it's impossible to use dominance properties in general.
392 DenseMap<const Value*, int> sn_mapL, sn_mapR; 392 DenseMap<const Value*, int> sn_mapL, sn_mapR;
393 }; 393 };
394 394
395 class FunctionPtr { 395 class FunctionNode {
396 AssertingVH<Function> F; 396 AssertingVH<Function> F;
397 const DataLayout *DL; 397 const DataLayout *DL;
398 398
399 public: 399 public:
400 FunctionPtr(Function *F, const DataLayout *DL) : F(F), DL(DL) {} 400 FunctionNode(Function *F, const DataLayout *DL) : F(F), DL(DL) {}
401 Function *getFunc() const { return F; } 401 Function *getFunc() const { return F; }
402 void release() { F = 0; } 402 void release() { F = 0; }
403 bool operator<(const FunctionPtr &RHS) const { 403 bool operator<(const FunctionNode &RHS) const {
404 return (FunctionComparator(DL, F, RHS.getFunc()).compare()) == -1; 404 return (FunctionComparator(DL, F, RHS.getFunc()).compare()) == -1;
405 } 405 }
406 }; 406 };
407 } 407 }
408 408
1047 const TerminatorInst *TermL = BBL->getTerminator(); 1047 const TerminatorInst *TermL = BBL->getTerminator();
1048 const TerminatorInst *TermR = BBR->getTerminator(); 1048 const TerminatorInst *TermR = BBR->getTerminator();
1049 1049
1050 assert(TermL->getNumSuccessors() == TermR->getNumSuccessors()); 1050 assert(TermL->getNumSuccessors() == TermR->getNumSuccessors());
1051 for (unsigned i = 0, e = TermL->getNumSuccessors(); i != e; ++i) { 1051 for (unsigned i = 0, e = TermL->getNumSuccessors(); i != e; ++i) {
1052 if (!VisitedBBs.insert(TermL->getSuccessor(i))) 1052 if (!VisitedBBs.insert(TermL->getSuccessor(i)).second)
1053 continue; 1053 continue;
1054 1054
1055 FnLBBs.push_back(TermL->getSuccessor(i)); 1055 FnLBBs.push_back(TermL->getSuccessor(i));
1056 FnRBBs.push_back(TermR->getSuccessor(i)); 1056 FnRBBs.push_back(TermR->getSuccessor(i));
1057 } 1057 }
1075 } 1075 }
1076 1076
1077 bool runOnModule(Module &M) override; 1077 bool runOnModule(Module &M) override;
1078 1078
1079 private: 1079 private:
1080 typedef std::set<FunctionPtr> FnTreeType; 1080 typedef std::set<FunctionNode> FnTreeType;
1081 1081
1082 /// A work queue of functions that may have been modified and should be 1082 /// A work queue of functions that may have been modified and should be
1083 /// analyzed again. 1083 /// analyzed again.
1084 std::vector<WeakVH> Deferred; 1084 std::vector<WeakVH> Deferred;
1085 1085
1418 1418
1419 // Insert a ComparableFunction into the FnTree, or merge it away if equal to one 1419 // Insert a ComparableFunction into the FnTree, or merge it away if equal to one
1420 // that was already inserted. 1420 // that was already inserted.
1421 bool MergeFunctions::insert(Function *NewFunction) { 1421 bool MergeFunctions::insert(Function *NewFunction) {
1422 std::pair<FnTreeType::iterator, bool> Result = 1422 std::pair<FnTreeType::iterator, bool> Result =
1423 FnTree.insert(FunctionPtr(NewFunction, DL)); 1423 FnTree.insert(FunctionNode(NewFunction, DL));
1424 1424
1425 if (Result.second) { 1425 if (Result.second) {
1426 DEBUG(dbgs() << "Inserting as unique: " << NewFunction->getName() << '\n'); 1426 DEBUG(dbgs() << "Inserting as unique: " << NewFunction->getName() << '\n');
1427 return false; 1427 return false;
1428 } 1428 }
1429 1429
1430 const FunctionPtr &OldF = *Result.first; 1430 const FunctionNode &OldF = *Result.first;
1431 1431
1432 // Don't merge tiny functions, since it can just end up making the function 1432 // Don't merge tiny functions, since it can just end up making the function
1433 // larger. 1433 // larger.
1434 // FIXME: Should still merge them if they are unnamed_addr and produce an 1434 // FIXME: Should still merge them if they are unnamed_addr and produce an
1435 // alias. 1435 // alias.
1455 // Remove a function from FnTree. If it was already in FnTree, add 1455 // Remove a function from FnTree. If it was already in FnTree, add
1456 // it to Deferred so that we'll look at it in the next round. 1456 // it to Deferred so that we'll look at it in the next round.
1457 void MergeFunctions::remove(Function *F) { 1457 void MergeFunctions::remove(Function *F) {
1458 // We need to make sure we remove F, not a function "equal" to F per the 1458 // We need to make sure we remove F, not a function "equal" to F per the
1459 // function equality comparator. 1459 // function equality comparator.
1460 FnTreeType::iterator found = FnTree.find(FunctionPtr(F, DL)); 1460 FnTreeType::iterator found = FnTree.find(FunctionNode(F, DL));
1461 size_t Erased = 0; 1461 size_t Erased = 0;
1462 if (found != FnTree.end() && found->getFunc() == F) { 1462 if (found != FnTree.end() && found->getFunc() == F) {
1463 Erased = 1; 1463 Erased = 1;
1464 FnTree.erase(found); 1464 FnTree.erase(found);
1465 } 1465 }