Lines Matching full:region

77   /// replace the extracted function for each region.
101 /// extraction of the first region.
112 /// The number of branches in the region target a basic block that is outside
113 /// of the region.
138 /// we check whether it is the same in Region.
266 // region is the same as the recorded instruction following the last
281 // We iterate over the instructions in the region, if we find a PHINode, we
282 // check if there are predecessors outside of the region, if there are,
283 // we ignore this region since we are unable to handle the severing of the
318 // If the region starts with a PHINode, but is not the initial instruction of
319 // the BasicBlock, we ignore this region for now.
323 // If the region ends with a PHINode, but does not contain all of the phi node
324 // instructions of the region, we ignore it for now.
348 // If there was a PHINode with an incoming block outside the region,
368 // For the phi nodes in the new starting basic block of the region, we
405 // incoming blocks to the first block are contained in the region, and there
526 /// after being used as an output for an outlined region.
539 /// Find whether \p Region matches the global value numbering to Constant
542 /// \param Region - The OutlinableRegion we are checking for constants
545 /// constant in each region.
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);
636 // region occur in the same place.
639 // needed, meaning that we could branch within the region or out, it is
772 /// as they are not the same in each instance of the region.
774 /// \param [in] C - The IRSimilarityCandidate containing the region we are
779 /// arguments needed for the region of code.
802 /// \param [in] C - The IRSimilarityCandidate containing the region we are
847 /// Find the input GVNs and the output values for a region of Instructions.
850 /// The \p Region can be identified as needing to be ignored in this function.
854 /// \param [in,out] Region - The region of code to be analyzed.
857 /// \param [in] NotSame - The global value numbers in the region that do not
859 /// \p Region.
866 OutlinableRegion &Region, std::vector<unsigned> &InputGVNs,
869 IRSimilarityCandidate &C = *Region.Candidate;
871 // OverallInputs are the inputs to the region found by the CodeExtractor,
874 // outlined region. PremappedInputs are the arguments found by the
885 CodeExtractor *CE = Region.CE;
887 assert(Region.StartBB && "Region must have a start BasicBlock!");
888 Function *OrigF = Region.StartBB->getParent();
892 // The region may be ineligible due to VarArgs in the parent function. In this
893 // case we ignore the region.
895 Region.IgnoreRegion = true;
904 // contained completely within the outlined region. These are not guaranteed
905 // to be the same in every region, so we must elevate them all to arguments
909 Region.IgnoreRegion = true;
930 /// \param [in,out] Region - The region of code to be analyzed.
936 findExtractedInputToOverallInputMapping(OutlinableRegion &Region,
940 IRSimilarityCandidate &C = *Region.Candidate;
941 OutlinableGroup &Group = *Region.Parent;
983 // number to Constant map for the region, and continue to the next input.
986 Region.AggArgToConstant.insert(std::make_pair(AggArgIt->second, CST));
990 Region.AggArgToConstant.insert(std::make_pair(TypeIndex, CST));
1002 Region.ChangedArgOrder = true;
1003 Region.ExtractedArgToAgg.insert(
1005 Region.AggArgToExtracted.insert(
1010 Region.ExtractedArgToAgg.insert(std::make_pair(OriginalIndex, TypeIndex));
1011 Region.AggArgToExtracted.insert(std::make_pair(TypeIndex, OriginalIndex));
1017 // If the function type definitions for the OutlinableGroup holding the region
1026 Region.NumExtractedInputs = OriginalIndex;
1029 /// Check if the \p V has any uses outside of the region other than \p PN.
1035 /// region.
1036 /// \param BlocksInRegion [in] - The basic blocks contained in the region.
1037 /// \returns true if \p V has any use soutside its region other than \p PN.
1042 // predecessor not included in the region. If it is, we make sure
1051 // Check if the value is used by any other instructions outside the region.
1057 // If the use of the item is inside the region, we skip it. Uses
1058 // inside the region give us useful information about how the item could be
1087 /// region.
1088 /// \param RegionBlocks [in] - The basic blocks in the region.
1089 /// \param Outputs [in, out] - The existing outputs for the region, we may add
1102 // Find all incoming values from the outlining region.
1108 // Do not process PHI if there are no predecessors from region.
1126 // outputs may have uses in outlined region. If they have other uses
1163 /// the region. We create a hash code based on the Canonical number of the
1170 /// \param Region - The region that \p PN is an output for.
1172 /// \param Blocks - The blocks for the region we are analyzing.
1176 static std::optional<unsigned> getGVNForPHINode(OutlinableRegion &Region,
1180 OutlinableGroup &Group = *Region.Parent;
1181 IRSimilarityCandidate &Cand = *Region.Candidate;
1189 // If we cannot find a GVN, and the incoming block is included in the region
1190 // this means that the input to the PHINode is not included in the region we
1193 // region.
1196 Region.IgnoreRegion = true;
1200 // If the incoming block isn't in the region, we don't have to worry about
1224 // PHINode, when we find a block that is not contained in the region
1272 /// Create a mapping of the output arguments for the \p Region to the output
1275 /// \param [in,out] Region - The region of code to be analyzed.
1278 findExtractedOutputToOverallOutputMapping(Module &M, OutlinableRegion &Region,
1280 OutlinableGroup &Group = *Region.Parent;
1281 IRSimilarityCandidate &C = *Region.Candidate;
1287 // Find the exits to the region.
1305 unsigned OriginalIndex = Region.NumExtractedInputs;
1341 Region.ExtractedArgToAgg.insert(std::make_pair(OriginalIndex, Jdx));
1342 Region.AggArgToExtracted.insert(std::make_pair(Jdx, OriginalIndex));
1357 Region.ExtractedArgToAgg.insert(
1359 Region.AggArgToExtracted.insert(
1369 // Values outside the region can be combined into PHINode when we
1378 GVN = getGVNForPHINode(Region, PN, BlocksInRegion, AggArgIdx);
1389 // Each region has a potentially unique set of outputs. We save which
1392 Region.GVNStores.push_back(*GVN);
1400 stable_sort(Region.GVNStores);
1403 void IROutliner::findAddInputsOutputs(Module &M, OutlinableRegion &Region,
1408 getCodeExtractorArguments(Region, Inputs, NotSame, OutputMappings, ArgInputs,
1411 if (Region.IgnoreRegion)
1416 findExtractedInputToOverallInputMapping(Region, Inputs, ArgInputs);
1420 findExtractedOutputToOverallOutputMapping(M, Region, Outputs);
1423 /// Replace the extracted function in the Region with a call to the overall
1429 /// \param [in] Region - The regions of extracted code to be replaced with a new
1432 CallInst *replaceCalledFunction(Module &M, OutlinableRegion &Region) {
1436 OutlinableGroup &Group = *Region.Parent;
1437 CallInst *Call = Region.Call;
1446 if (!Region.ChangedArgOrder && AggFunc->arg_size() == Call->arg_size()) {
1465 << Region.OutputBlockNum << "\n");
1467 Region.OutputBlockNum));
1471 ArgPair = Region.AggArgToExtracted.find(AggArgIdx);
1472 if (ArgPair != Region.AggArgToExtracted.end()) {
1484 if (Region.AggArgToConstant.contains(AggArgIdx)) {
1485 Constant *CST = Region.AggArgToConstant.find(AggArgIdx)->second;
1494 // for the region, so we should not pass anything to it.
1510 CallInst *OldCall = Region.Call;
1511 if (Region.NewFront->Inst == OldCall)
1512 Region.NewFront->Inst = Call;
1513 if (Region.NewBack->Inst == OldCall)
1514 Region.NewBack->Inst = Call;
1517 Call->setDebugLoc(Region.Call->getDebugLoc());
1524 Region.Call = Call;
1587 /// For the function call now representing the \p Region, find the passed value
1593 /// \param Region - The extracted Region corresponding to the outlined function.
1597 const OutlinableRegion &Region) {
1601 return Region.Call->getArgOperand(A->getArgNo());
1604 /// For the function call now representing the \p Region, find the passed value
1609 /// \param Region - The extracted Region corresponding to the outlined function.
1613 const OutlinableRegion &Region) {
1618 if (Region.AggArgToConstant.count(ArgNum))
1619 return Region.AggArgToConstant.find(ArgNum)->second;
1623 ArgNum = Region.AggArgToExtracted.find(ArgNum)->second;
1624 return Region.Call->getArgOperand(ArgNum);
1630 /// \param Region [in] - The OutlinableRegion containing \p PN.
1632 /// region to their original values.
1636 /// of \p Region rather than the overall function's call.
1638 PHINode *PN, OutlinableRegion &Region,
1650 IVal = getPassedArgumentInAlreadyOutlinedFunction(A, Region);
1652 IVal = getPassedArgumentAndAdjustArgumentLocation(A, Region);
1659 std::optional<unsigned> GVN = Region.Candidate->getGVN(IVal);
1661 std::optional<unsigned> CanonNum = Region.Candidate->getCanonicalNum(*GVN);
1672 /// \param Region [in] - The OutlinableRegion containing \p PN.
1676 /// region to their original values.
1681 findOrCreatePHIInBlock(PHINode &PN, OutlinableRegion &Region,
1685 OutlinableGroup &Group = *Region.Parent;
1692 // We have to use the extracted function since we have merged this region into
1696 findCanonNumsForPHI(&PN, Region, OutputMappings, PNCanonNums,
1726 // in PHINode to one already present in the outlined region. If the
1730 // finding the corresponding incoming block in the combined outlined region
1731 // for the current outlined region.
1741 Region.findCorrespondingBlockIn(*FirstRegion, ToAdd.second);
1769 Region.findCorrespondingBlockIn(*FirstRegion, IncomingBlock);
1782 Value *Val = Region.findCorrespondingValueIn(*FirstRegion, IncomingVal);
1794 // region with the arguments of the function for an OutlinableGroup.
1796 /// \param [in] Region - The region of extracted code to be changed.
1798 /// region.
1803 replaceArgumentUses(OutlinableRegion &Region,
1807 OutlinableGroup &Group = *Region.Parent;
1808 assert(Region.ExtractedFunction && "Region has no extracted function?");
1810 Function *DominatingFunction = Region.ExtractedFunction;
1816 for (unsigned ArgIdx = 0; ArgIdx < Region.ExtractedFunction->arg_size();
1818 assert(Region.ExtractedArgToAgg.contains(ArgIdx) &&
1820 unsigned AggArgIdx = Region.ExtractedArgToAgg.find(ArgIdx)->second;
1822 Argument *Arg = Region.ExtractedFunction->getArg(ArgIdx);
1825 if (ArgIdx < Region.NumExtractedInputs) {
1827 << *Region.ExtractedFunction << " with " << *AggArg
1830 Value *V = Region.Call->getArgOperand(ArgIdx);
1831 Region.RemappedArguments.insert(std::make_pair(V, AggArg));
1880 Region.Candidate->getGVN(ValueOperand).has_value()) {
1884 Region.findCorrespondingValueIn(*Group.Regions[0], ValueOperand);
1892 if (Region.Candidate->getGVN(PN))
1895 // We record the parent block for the PHINode in the Region so that
1897 Region.PHIBlocks.insert(std::make_pair(RetVal, PN->getParent()));
1915 PHINode *NewPN = findOrCreatePHIInBlock(*PN, Region, OverallPhiBlock,
1927 << *Region.ExtractedFunction << " with " << *AggArg
1936 /// \param Region [in] - The region of extracted code to be changed.
1937 void replaceConstants(OutlinableRegion &Region) {
1938 OutlinableGroup &Group = *Region.Parent;
1940 for (std::pair<unsigned, Constant *> &Const : Region.AggArgToConstant) {
2019 /// Remove empty output blocks from the outlined region.
2022 /// Region.
2023 /// \param Region - The OutlinableRegion we are analyzing.
2026 OutlinableRegion &Region) {
2053 // Mark the region as having the no output scheme.
2055 Region.OutputBlockNum = -1;
2065 /// \param [in] Region - The OutlinableRegion that is being analyzed.
2066 /// \param [in,out] OutputBBs - the blocks that stores for this region will be
2073 OutlinableGroup &OG, OutlinableRegion &Region,
2081 if (analyzeAndPruneOutputBlocks(OutputBBs, Region))
2091 LLVM_DEBUG(dbgs() << "Set output block for region in function"
2092 << Region.ExtractedFunction << " to " << *MatchingBB);
2094 Region.OutputBlockNum = *MatchingBB;
2100 Region.OutputBlockNum = OutputStoreBBs.size();
2110 LLVM_DEBUG(dbgs() << "Create output block for region in"
2111 << Region.ExtractedFunction << " to "
2160 // in a PHINode outside of the region in one outlined instance, and are used
2234 /// the extracted regions of a certain structure from the first region in the
2235 /// list of regions. Replace this first region's extracted function with the
2364 const OutlinableRegion &Region) {
2365 IRSimilarityCandidate *IRSC = Region.Candidate;
2377 if (!Region.Candidate->backInstruction()->isTerminator()) {
2379 Region.Candidate->backInstruction()->getNextNonDebugInstruction();
2381 if (Region.Candidate->end()->Inst != NewEndInst) {
2382 IRInstructionDataList *IDL = Region.Candidate->front()->IDL;
2387 // Insert the first IRInstructionData of the new region after the
2389 IDL->insert(Region.Candidate->end(), *NewEndIRID);
2487 for (OutlinableRegion *Region : CurrentGroup.Regions) {
2488 TargetTransformInfo &TTI = getTTI(*Region->StartBB->getParent());
2489 // We add the number of instructions in the region to the benefit as an
2491 RegionBenefit += Region->getBenefit(TTI);
2503 /// \param Region - The OutlinableRegion to get the Value from.
2506 /// Region.
2507 static Value *findOutputValueInRegion(OutlinableRegion &Region,
2509 OutlinableGroup &CurrentGroup = *Region.Parent;
2521 Region.Candidate->fromCanonicalNum(OutputCanon);
2523 std::optional<Value *> OV = Region.Candidate->fromGVN(*OGVN);
2531 for (OutlinableRegion *Region : CurrentGroup.Regions) {
2532 TargetTransformInfo &TTI = getTTI(*Region->StartBB->getParent());
2535 for (unsigned OutputCanon : Region->GVNStores) {
2536 Value *V = findOutputValueInRegion(*Region, OutputCanon);
2552 /// region.
2571 // of the region.
2648 // We add one region to the cost once, to account for the instructions added
2679 void IROutliner::updateOutputMapping(OutlinableRegion &Region,
2686 for (unsigned ArgIdx = Region.NumExtractedInputs;
2687 ArgIdx < Region.Call->arg_size(); ArgIdx++) {
2688 if (Operand == Region.Call->getArgOperand(ArgIdx)) {
2689 OutputIdx = ArgIdx - Region.NumExtractedInputs;
2711 bool IROutliner::extractSection(OutlinableRegion &Region) {
2713 assert(Region.StartBB && "StartBB for the OutlinableRegion is nullptr!");
2714 BasicBlock *InitialStart = Region.StartBB;
2715 Function *OrigF = Region.StartBB->getParent();
2717 Region.ExtractedFunction =
2718 Region.CE->extractCodeRegion(CEAC, ArgInputs, Outputs);
2722 if (!Region.ExtractedFunction) {
2723 LLVM_DEBUG(dbgs() << "CodeExtractor failed to outline " << Region.StartBB
2725 Region.reattachCandidate();
2733 User *InstAsUser = Region.ExtractedFunction->user_back();
2735 Region.PrevBB = RewrittenBB->getSinglePredecessor();
2736 assert(Region.PrevBB && "PrevBB is nullptr?");
2737 if (Region.PrevBB == InitialStart) {
2742 Region.PrevBB = NewPrev;
2746 Region.StartBB = RewrittenBB;
2747 Region.EndBB = RewrittenBB;
2754 IRInstructionDataList *IDL = Region.Candidate->front()->IDL;
2757 Region.NewFront = new (InstDataAllocator.Allocate()) IRInstructionData(
2759 Region.NewBack = new (InstDataAllocator.Allocate()) IRInstructionData(
2762 // Insert the first IRInstructionData of the new region in front of the
2764 IDL->insert(Region.Candidate->begin(), *Region.NewFront);
2765 // Insert the first IRInstructionData of the new region after the
2767 IDL->insert(Region.Candidate->end(), *Region.NewBack);
2769 IDL->erase(Region.Candidate->begin(), std::prev(Region.Candidate->end()));
2778 if (Region.ExtractedFunction == CI->getCalledFunction())
2779 Region.Call = CI;
2781 updateOutputMapping(Region, Outputs.getArrayRef(), LI);
2782 Region.reattachCandidate();
2835 // Create a CodeExtractor for each outlinable region. Identify inputs and
2840 // Break the outlinable region out of its parent BasicBlock into its own
2844 // There's a chance that when the region is split, extra instructions are
2845 // added to the region. This makes the region no longer viable
2892 [&R](OutlinableRegion *Region) {
2895 Region->Candidate->frontInstruction()->getDebugLoc());
2919 for (OutlinableRegion *Region : CurrentGroup.Regions) {
2920 // We check whether our region is compatible with what has already been
2922 if (!isCompatibleWithAlreadyOutlinedCode(*Region))
2924 OutlinedRegions.push_back(Region);
2941 for (OutlinableRegion *Region : CurrentGroup.Regions) {
2942 Region->splitCandidate();
2943 if (!Region->CandidateSplit)
2945 OutlinedRegions.push_back(Region);
2998 [&R](OutlinableRegion *Region) {
3000 Region->Candidate->frontInstruction()->getDebugLoc());