Lines Matching defs:Region

138   /// we check whether it is the same in Region.
539 /// Find whether \p Region matches the global value numbering to Constant
542 /// \param Region - The OutlinableRegion we are checking for constants
547 /// Region and false if not
549 collectRegionsConstants(OutlinableRegion &Region,
554 IRSimilarityCandidate &C = *Region.Candidate;
601 for (OutlinableRegion *Region : Regions)
602 collectRegionsConstants(*Region, GVNToConstant, NotSame);
848 /// The \p Region can be identified as needing to be ignored in this function.
852 /// \param [in,out] Region - The region of code to be analyzed.
857 /// \p Region.
864 OutlinableRegion &Region, std::vector<unsigned> &InputGVNs,
867 IRSimilarityCandidate &C = *Region.Candidate;
883 CodeExtractor *CE = Region.CE;
885 assert(Region.StartBB && "Region must have a start BasicBlock!");
886 Function *OrigF = Region.StartBB->getParent();
893 Region.IgnoreRegion = true;
907 Region.IgnoreRegion = true;
928 /// \param [in,out] Region - The region of code to be analyzed.
934 findExtractedInputToOverallInputMapping(OutlinableRegion &Region,
938 IRSimilarityCandidate &C = *Region.Candidate;
939 OutlinableGroup &Group = *Region.Parent;
984 Region.AggArgToConstant.insert(std::make_pair(AggArgIt->second, CST));
988 Region.AggArgToConstant.insert(std::make_pair(TypeIndex, CST));
1000 Region.ChangedArgOrder = true;
1001 Region.ExtractedArgToAgg.insert(
1003 Region.AggArgToExtracted.insert(
1008 Region.ExtractedArgToAgg.insert(std::make_pair(OriginalIndex, TypeIndex));
1009 Region.AggArgToExtracted.insert(std::make_pair(TypeIndex, OriginalIndex));
1024 Region.NumExtractedInputs = OriginalIndex;
1168 /// \param Region - The region that \p PN is an output for.
1174 static std::optional<unsigned> getGVNForPHINode(OutlinableRegion &Region,
1178 OutlinableGroup &Group = *Region.Parent;
1179 IRSimilarityCandidate &Cand = *Region.Candidate;
1194 Region.IgnoreRegion = true;
1270 /// Create a mapping of the output arguments for the \p Region to the output
1273 /// \param [in,out] Region - The region of code to be analyzed.
1276 findExtractedOutputToOverallOutputMapping(Module &M, OutlinableRegion &Region,
1278 OutlinableGroup &Group = *Region.Parent;
1279 IRSimilarityCandidate &C = *Region.Candidate;
1303 unsigned OriginalIndex = Region.NumExtractedInputs;
1338 Region.ExtractedArgToAgg.insert(std::make_pair(OriginalIndex, Jdx));
1339 Region.AggArgToExtracted.insert(std::make_pair(Jdx, OriginalIndex));
1354 Region.ExtractedArgToAgg.insert(
1356 Region.AggArgToExtracted.insert(
1375 GVN = getGVNForPHINode(Region, PN, BlocksInRegion, AggArgIdx);
1389 Region.GVNStores.push_back(*GVN);
1397 stable_sort(Region.GVNStores);
1400 void IROutliner::findAddInputsOutputs(Module &M, OutlinableRegion &Region,
1405 getCodeExtractorArguments(Region, Inputs, NotSame, OutputMappings, ArgInputs,
1408 if (Region.IgnoreRegion)
1413 findExtractedInputToOverallInputMapping(Region, Inputs, ArgInputs);
1417 findExtractedOutputToOverallOutputMapping(M, Region, Outputs);
1420 /// Replace the extracted function in the Region with a call to the overall
1426 /// \param [in] Region - The regions of extracted code to be replaced with a new
1429 CallInst *replaceCalledFunction(Module &M, OutlinableRegion &Region) {
1433 OutlinableGroup &Group = *Region.Parent;
1434 CallInst *Call = Region.Call;
1443 if (!Region.ChangedArgOrder && AggFunc->arg_size() == Call->arg_size()) {
1462 << Region.OutputBlockNum << "\n");
1464 Region.OutputBlockNum));
1468 ArgPair = Region.AggArgToExtracted.find(AggArgIdx);
1469 if (ArgPair != Region.AggArgToExtracted.end()) {
1481 if (Region.AggArgToConstant.contains(AggArgIdx)) {
1482 Constant *CST = Region.AggArgToConstant.find(AggArgIdx)->second;
1507 CallInst *OldCall = Region.Call;
1508 if (Region.NewFront->Inst == OldCall)
1509 Region.NewFront->Inst = Call;
1510 if (Region.NewBack->Inst == OldCall)
1511 Region.NewBack->Inst = Call;
1514 Call->setDebugLoc(Region.Call->getDebugLoc());
1521 Region.Call = Call;
1584 /// For the function call now representing the \p Region, find the passed value
1590 /// \param Region - The extracted Region corresponding to the outlined function.
1594 const OutlinableRegion &Region) {
1598 return Region.Call->getArgOperand(A->getArgNo());
1601 /// For the function call now representing the \p Region, find the passed value
1606 /// \param Region - The extracted Region corresponding to the outlined function.
1610 const OutlinableRegion &Region) {
1615 if (Region.AggArgToConstant.count(ArgNum))
1616 return Region.AggArgToConstant.find(ArgNum)->second;
1620 ArgNum = Region.AggArgToExtracted.find(ArgNum)->second;
1621 return Region.Call->getArgOperand(ArgNum);
1627 /// \param Region [in] - The OutlinableRegion containing \p PN.
1633 /// of \p Region rather than the overall function's call.
1635 PHINode *PN, OutlinableRegion &Region,
1647 IVal = getPassedArgumentInAlreadyOutlinedFunction(A, Region);
1649 IVal = getPassedArgumentAndAdjustArgumentLocation(A, Region);
1656 std::optional<unsigned> GVN = Region.Candidate->getGVN(IVal);
1658 std::optional<unsigned> CanonNum = Region.Candidate->getCanonicalNum(*GVN);
1669 /// \param Region [in] - The OutlinableRegion containing \p PN.
1678 findOrCreatePHIInBlock(PHINode &PN, OutlinableRegion &Region,
1682 OutlinableGroup &Group = *Region.Parent;
1693 findCanonNumsForPHI(&PN, Region, OutputMappings, PNCanonNums,
1738 Region.findCorrespondingBlockIn(*FirstRegion, ToAdd.second);
1766 Region.findCorrespondingBlockIn(*FirstRegion, IncomingBlock);
1779 Value *Val = Region.findCorrespondingValueIn(*FirstRegion, IncomingVal);
1793 /// \param [in] Region - The region of extracted code to be changed.
1800 replaceArgumentUses(OutlinableRegion &Region,
1804 OutlinableGroup &Group = *Region.Parent;
1805 assert(Region.ExtractedFunction && "Region has no extracted function?");
1807 Function *DominatingFunction = Region.ExtractedFunction;
1813 for (unsigned ArgIdx = 0; ArgIdx < Region.ExtractedFunction->arg_size();
1815 assert(Region.ExtractedArgToAgg.contains(ArgIdx) &&
1817 unsigned AggArgIdx = Region.ExtractedArgToAgg.find(ArgIdx)->second;
1819 Argument *Arg = Region.ExtractedFunction->getArg(ArgIdx);
1822 if (ArgIdx < Region.NumExtractedInputs) {
1824 << *Region.ExtractedFunction << " with " << *AggArg
1827 Value *V = Region.Call->getArgOperand(ArgIdx);
1828 Region.RemappedArguments.insert(std::make_pair(V, AggArg));
1877 Region.Candidate->getGVN(ValueOperand).has_value()) {
1881 Region.findCorrespondingValueIn(*Group.Regions[0], ValueOperand);
1889 if (Region.Candidate->getGVN(PN))
1892 // We record the parent block for the PHINode in the Region so that
1894 Region.PHIBlocks.insert(std::make_pair(RetVal, PN->getParent()));
1912 PHINode *NewPN = findOrCreatePHIInBlock(*PN, Region, OverallPhiBlock,
1924 << *Region.ExtractedFunction << " with " << *AggArg
1933 /// \param Region [in] - The region of extracted code to be changed.
1934 void replaceConstants(OutlinableRegion &Region) {
1935 OutlinableGroup &Group = *Region.Parent;
1937 for (std::pair<unsigned, Constant *> &Const : Region.AggArgToConstant) {
2019 /// Region.
2020 /// \param Region - The OutlinableRegion we are analyzing.
2023 OutlinableRegion &Region) {
2052 Region.OutputBlockNum = -1;
2062 /// \param [in] Region - The OutlinableRegion that is being analyzed.
2070 OutlinableGroup &OG, OutlinableRegion &Region,
2078 if (analyzeAndPruneOutputBlocks(OutputBBs, Region))
2089 << Region.ExtractedFunction << " to " << *MatchingBB);
2091 Region.OutputBlockNum = *MatchingBB;
2097 Region.OutputBlockNum = OutputStoreBBs.size();
2108 << Region.ExtractedFunction << " to "
2361 const OutlinableRegion &Region) {
2362 IRSimilarityCandidate *IRSC = Region.Candidate;
2374 if (!Region.Candidate->backInstruction()->isTerminator()) {
2376 Region.Candidate->backInstruction()->getNextNonDebugInstruction();
2378 if (Region.Candidate->end()->Inst != NewEndInst) {
2379 IRInstructionDataList *IDL = Region.Candidate->front()->IDL;
2386 IDL->insert(Region.Candidate->end(), *NewEndIRID);
2484 for (OutlinableRegion *Region : CurrentGroup.Regions) {
2485 TargetTransformInfo &TTI = getTTI(*Region->StartBB->getParent());
2488 RegionBenefit += Region->getBenefit(TTI);
2500 /// \param Region - The OutlinableRegion to get the Value from.
2503 /// Region.
2504 static Value *findOutputValueInRegion(OutlinableRegion &Region,
2506 OutlinableGroup &CurrentGroup = *Region.Parent;
2518 Region.Candidate->fromCanonicalNum(OutputCanon);
2520 std::optional<Value *> OV = Region.Candidate->fromGVN(*OGVN);
2528 for (OutlinableRegion *Region : CurrentGroup.Regions) {
2529 TargetTransformInfo &TTI = getTTI(*Region->StartBB->getParent());
2532 for (unsigned OutputCanon : Region->GVNStores) {
2533 Value *V = findOutputValueInRegion(*Region, OutputCanon);
2676 void IROutliner::updateOutputMapping(OutlinableRegion &Region,
2683 for (unsigned ArgIdx = Region.NumExtractedInputs;
2684 ArgIdx < Region.Call->arg_size(); ArgIdx++) {
2685 if (Operand == Region.Call->getArgOperand(ArgIdx)) {
2686 OutputIdx = ArgIdx - Region.NumExtractedInputs;
2708 bool IROutliner::extractSection(OutlinableRegion &Region) {
2710 assert(Region.StartBB && "StartBB for the OutlinableRegion is nullptr!");
2711 BasicBlock *InitialStart = Region.StartBB;
2712 Function *OrigF = Region.StartBB->getParent();
2714 Region.ExtractedFunction =
2715 Region.CE->extractCodeRegion(CEAC, ArgInputs, Outputs);
2719 if (!Region.ExtractedFunction) {
2720 LLVM_DEBUG(dbgs() << "CodeExtractor failed to outline " << Region.StartBB
2722 Region.reattachCandidate();
2730 User *InstAsUser = Region.ExtractedFunction->user_back();
2732 Region.PrevBB = RewrittenBB->getSinglePredecessor();
2733 assert(Region.PrevBB && "PrevBB is nullptr?");
2734 if (Region.PrevBB == InitialStart) {
2739 Region.PrevBB = NewPrev;
2743 Region.StartBB = RewrittenBB;
2744 Region.EndBB = RewrittenBB;
2751 IRInstructionDataList *IDL = Region.Candidate->front()->IDL;
2754 Region.NewFront = new (InstDataAllocator.Allocate()) IRInstructionData(
2756 Region.NewBack = new (InstDataAllocator.Allocate()) IRInstructionData(
2761 IDL->insert(Region.Candidate->begin(), *Region.NewFront);
2764 IDL->insert(Region.Candidate->end(), *Region.NewBack);
2766 IDL->erase(Region.Candidate->begin(), std::prev(Region.Candidate->end()));
2775 if (Region.ExtractedFunction == CI->getCalledFunction())
2776 Region.Call = CI;
2778 updateOutputMapping(Region, Outputs.getArrayRef(), LI);
2779 Region.reattachCandidate();
2889 [&R](OutlinableRegion *Region) {
2892 Region->Candidate->frontInstruction()->getDebugLoc());
2916 for (OutlinableRegion *Region : CurrentGroup.Regions) {
2919 if (!isCompatibleWithAlreadyOutlinedCode(*Region))
2921 OutlinedRegions.push_back(Region);
2938 for (OutlinableRegion *Region : CurrentGroup.Regions) {
2939 Region->splitCandidate();
2940 if (!Region->CandidateSplit)
2942 OutlinedRegions.push_back(Region);
2995 [&R](OutlinableRegion *Region) {
2997 Region->Candidate->frontInstruction()->getDebugLoc());