comparison lib/Transforms/IPO/ArgumentPromotion.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 afa8332a0e37
comparison
equal deleted inserted replaced
78:af83660cff7b 83:60c9769439b8
180 WorkList.insert(WorkList.end(), arg->user_begin(), arg->user_end()); 180 WorkList.insert(WorkList.end(), arg->user_begin(), arg->user_end());
181 while (!WorkList.empty()) { 181 while (!WorkList.empty()) {
182 Value *V = WorkList.back(); 182 Value *V = WorkList.back();
183 WorkList.pop_back(); 183 WorkList.pop_back();
184 if (isa<GetElementPtrInst>(V) || isa<PHINode>(V)) { 184 if (isa<GetElementPtrInst>(V) || isa<PHINode>(V)) {
185 if (PtrValues.insert(V)) 185 if (PtrValues.insert(V).second)
186 WorkList.insert(WorkList.end(), V->user_begin(), V->user_end()); 186 WorkList.insert(WorkList.end(), V->user_begin(), V->user_end());
187 } else if (StoreInst *Store = dyn_cast<StoreInst>(V)) { 187 } else if (StoreInst *Store = dyn_cast<StoreInst>(V)) {
188 Stores.push_back(Store); 188 Stores.push_back(Store);
189 } else if (!isa<LoadInst>(V)) { 189 } else if (!isa<LoadInst>(V)) {
190 return true; 190 return true;
528 << "than " << maxElements << " arguments to the function.\n"); 528 << "than " << maxElements << " arguments to the function.\n");
529 // We limit aggregate promotion to only promoting up to a fixed number 529 // We limit aggregate promotion to only promoting up to a fixed number
530 // of elements of the aggregate. 530 // of elements of the aggregate.
531 return false; 531 return false;
532 } 532 }
533 ToPromote.insert(Operands); 533 ToPromote.insert(std::move(Operands));
534 } 534 }
535 } 535 }
536 536
537 if (Loads.empty()) return true; // No users, this is a dead argument. 537 if (Loads.empty()) return true; // No users, this is a dead argument.
538 538
552 // the load itself. 552 // the load itself.
553 LoadInst *Load = Loads[i]; 553 LoadInst *Load = Loads[i];
554 BasicBlock *BB = Load->getParent(); 554 BasicBlock *BB = Load->getParent();
555 555
556 AliasAnalysis::Location Loc = AA.getLocation(Load); 556 AliasAnalysis::Location Loc = AA.getLocation(Load);
557 if (AA.canInstructionRangeModify(BB->front(), *Load, Loc)) 557 if (AA.canInstructionRangeModRef(BB->front(), *Load, Loc,
558 AliasAnalysis::Mod))
558 return false; // Pointer is invalidated! 559 return false; // Pointer is invalidated!
559 560
560 // Now check every path from the entry block to the load for transparency. 561 // Now check every path from the entry block to the load for transparency.
561 // To do this, we perform a depth first search on the inverse CFG from the 562 // To do this, we perform a depth first search on the inverse CFG from the
562 // loading block. 563 // loading block.
563 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { 564 for (BasicBlock *P : predecessors(BB)) {
564 BasicBlock *P = *PI;
565 for (BasicBlock *TranspBB : inverse_depth_first_ext(P, TranspBlocks)) 565 for (BasicBlock *TranspBB : inverse_depth_first_ext(P, TranspBlocks))
566 if (AA.canBasicBlockModify(*TranspBB, Loc)) 566 if (AA.canBasicBlockModify(*TranspBB, Loc))
567 return false; 567 return false;
568 } 568 }
569 } 569 }
701 // Patch the pointer to LLVM function in debug info descriptor. 701 // Patch the pointer to LLVM function in debug info descriptor.
702 auto DI = FunctionDIs.find(F); 702 auto DI = FunctionDIs.find(F);
703 if (DI != FunctionDIs.end()) { 703 if (DI != FunctionDIs.end()) {
704 DISubprogram SP = DI->second; 704 DISubprogram SP = DI->second;
705 SP.replaceFunction(NF); 705 SP.replaceFunction(NF);
706 // Ensure the map is updated so it can be reused on subsequent argument
707 // promotions of the same function.
706 FunctionDIs.erase(DI); 708 FunctionDIs.erase(DI);
707 FunctionDIs[NF] = SP; 709 FunctionDIs[NF] = SP;
708 } 710 }
709 711
710 DEBUG(dbgs() << "ARG PROMOTION: Promoting to:" << *NF << "\n" 712 DEBUG(dbgs() << "ARG PROMOTION: Promoting to:" << *NF << "\n"