llvm-project/llvm/lib/Transforms/Utils
Alina Sbirlea dfd14adeb0 Generalize MergeBlockIntoPredecessor. Replace uses of MergeBasicBlockIntoOnlyPred.
Summary:
Two utils methods have essentially the same functionality. This is an attempt to merge them into one.
1. lib/Transforms/Utils/Local.cpp : MergeBasicBlockIntoOnlyPred
2. lib/Transforms/Utils/BasicBlockUtils.cpp : MergeBlockIntoPredecessor

Prior to the patch:
1. MergeBasicBlockIntoOnlyPred
Updates either DomTree or DeferredDominance
Moves all instructions from Pred to BB, deletes Pred
Asserts BB has single predecessor
If address was taken, replace the block address with constant 1 (?)

2. MergeBlockIntoPredecessor
Updates DomTree, LoopInfo and MemoryDependenceResults
Moves all instruction from BB to Pred, deletes BB
Returns if doesn't have a single predecessor
Returns if BB's address was taken

After the patch:
Method 2. MergeBlockIntoPredecessor is attempting to become the new default:
Updates DomTree or DeferredDominance, and LoopInfo and MemoryDependenceResults
Moves all instruction from BB to Pred, deletes BB
Returns if doesn't have a single predecessor
Returns if BB's address was taken

Uses of MergeBasicBlockIntoOnlyPred that need to be replaced:

1. lib/Transforms/Scalar/LoopSimplifyCFG.cpp
Updated in this patch. No challenges.

2. lib/CodeGen/CodeGenPrepare.cpp
Updated in this patch.
  i. eliminateFallThrough is straightforward, but I added using a temporary array to avoid the iterator invalidation.
  ii. eliminateMostlyEmptyBlock(s) methods also now use a temporary array for blocks
Some interesting aspects:
  - Since Pred is not deleted (BB is), the entry block does not need updating.
  - The entry block was being updated with the deleted block in eliminateMostlyEmptyBlock. Added assert to make obvious that BB=SinglePred.
  - isMergingEmptyBlockProfitable assumes BB is the one to be deleted.
  - eliminateMostlyEmptyBlock(BB) does not delete BB on one path, it deletes its unique predecessor instead.
  - adding some test owner as subscribers for the interesting tests modified:
    test/CodeGen/X86/avx-cmp.ll
    test/CodeGen/AMDGPU/nested-loop-conditions.ll
    test/CodeGen/AMDGPU/si-annotate-cf.ll
    test/CodeGen/X86/hoist-spill.ll
    test/CodeGen/X86/2006-11-17-IllegalMove.ll

3. lib/Transforms/Scalar/JumpThreading.cpp
Not covered in this patch. It is the only use case using the DeferredDominance.
I would defer to Brian Rzycki to make this replacement.

Reviewers: chandlerc, spatel, davide, brzycki, bkramer, javed.absar

Subscribers: qcolombet, sanjoy, nemanjai, nhaehnle, jlebar, tpr, kbarton, RKSimon, wmi, arsenm, llvm-commits

Differential Revision: https://reviews.llvm.org/D48202

llvm-svn: 335183
2018-06-20 22:01:04 +00:00
..
ASanStackFrameLayout.cpp [asan] Add a full redzone after every stack variable 2017-11-18 01:13:18 +00:00
AddDiscriminators.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
BasicBlockUtils.cpp Generalize MergeBlockIntoPredecessor. Replace uses of MergeBasicBlockIntoOnlyPred. 2018-06-20 22:01:04 +00:00
BreakCriticalEdges.cpp Transforms: Introduce Transforms/Utils.h rather than spreading the declarations amongst Scalar.h and IPO.h 2018-03-28 17:44:36 +00:00
BuildLibCalls.cpp [InstCombine] Fix the signature of fgets_unlocked. 2018-05-16 21:45:39 +00:00
BypassSlowDivision.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
CMakeLists.txt Revert 333358 as it's failing on some builders. 2018-05-27 12:54:33 +00:00
CallPromotionUtils.cpp [ICP] Do not attempt type matching for variable length arguments. 2018-04-25 17:19:21 +00:00
CloneFunction.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
CloneModule.cpp [DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule 2018-04-13 21:22:24 +00:00
CodeExtractor.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
CtorUtils.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
DemoteRegToStack.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
EntryExitInstrumenter.cpp EntryExitInstrumenter: Handle musttail calls 2018-04-06 10:14:09 +00:00
EscapeEnumerator.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
Evaluator.cpp Fix evaluator for non-zero alloca addr space 2018-05-19 02:58:16 +00:00
FlattenCFG.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
FunctionComparator.cpp Use SmallPtrSet explicitly for SmallSets with pointer types (NFC). 2018-06-12 11:16:56 +00:00
FunctionImportUtils.cpp [ThinLTO] Clear dllimport when setting dso_local. 2018-03-13 15:24:51 +00:00
GlobalStatus.cpp [GlobalOpt] Fix exponential compile-time with selects. 2018-01-31 20:42:25 +00:00
ImportedFunctionsInliningStatistics.cpp [Transforms] Change std::sort to llvm::sort in response to r327219 2018-04-13 19:47:57 +00:00
InlineFunction.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
InstructionNamer.cpp Transforms: Introduce Transforms/Utils.h rather than spreading the declarations amongst Scalar.h and IPO.h 2018-03-28 17:44:36 +00:00
IntegerDivision.cpp Remove @brief commands from doxygen comments, too. 2018-05-01 16:10:38 +00:00
LCSSA.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
LLVMBuild.txt
LibCallsShrinkWrap.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
Local.cpp [Local] Generalize insertReplacementDbgValues, NFC 2018-06-20 18:40:14 +00:00
LoopRotationUtils.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
LoopSimplify.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
LoopUnroll.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
LoopUnrollPeel.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
LoopUnrollRuntime.cpp Use SmallPtrSet explicitly for SmallSets with pointer types (NFC). 2018-06-12 11:16:56 +00:00
LoopUtils.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
LoopVersioning.cpp [LoopVersioning] Don't modify the list that we iterate over in addPHINodes 2018-05-22 08:33:02 +00:00
LowerInvoke.cpp Support a funclet operand bundle in LowerInvoke 2018-05-09 00:53:50 +00:00
LowerMemIntrinsics.cpp [LowerMemIntrinsics] Update uses of deprecated MemIntrinsic::getAlignment API (NFC) 2018-02-05 22:23:58 +00:00
LowerSwitch.cpp [LowerSwitch] Fixed faulty PHI node update 2018-05-22 08:46:48 +00:00
Mem2Reg.cpp Transforms: Introduce Transforms/Utils.h rather than spreading the declarations amongst Scalar.h and IPO.h 2018-03-28 17:44:36 +00:00
MetaRenamer.cpp Transforms: Introduce Transforms/Utils.h rather than spreading the declarations amongst Scalar.h and IPO.h 2018-03-28 17:44:36 +00:00
ModuleUtils.cpp ModuleUtils: Stop using comdat members to generate unique module ids. 2017-10-05 21:54:53 +00:00
NameAnonGlobals.cpp
OrderedInstructions.cpp [PredicateInfo] Order instructions in different BBs by DFSNumIn. 2018-06-20 17:42:01 +00:00
PredicateInfo.cpp [PredicateInfo] Order instructions in different BBs by DFSNumIn. 2018-06-20 17:42:01 +00:00
PromoteMemoryToRegister.cpp [Mem2Reg] Avoid replacing load with itself in promoteSingleBlockAlloca. 2018-06-07 11:09:05 +00:00
SSAUpdater.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
SSAUpdaterBulk.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
SanitizerStats.cpp Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
SimplifyCFG.cpp Use SmallPtrSet explicitly for SmallSets with pointer types (NFC). 2018-06-12 11:16:56 +00:00
SimplifyIndVar.cpp [SimplifyIndVars] Eliminate redundant truncs 2018-06-19 04:48:34 +00:00
SimplifyInstructions.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
SimplifyLibCalls.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
SplitModule.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
StripGCRelocates.cpp Fix a couple of layering violations in Transforms 2018-03-21 22:34:23 +00:00
StripNonLineTableDebugInfo.cpp Fix some layering in StripNonLineTableDebugInfo, moving its declaration from IPO.h to Utils.h to match its implementation 2018-03-29 22:42:08 +00:00
SymbolRewriter.cpp Mark all library options as hidden. 2017-12-01 00:53:10 +00:00
UnifyFunctionExitNodes.cpp Transforms: Introduce Transforms/Utils.h rather than spreading the declarations amongst Scalar.h and IPO.h 2018-03-28 17:44:36 +00:00
Utils.cpp llvm-c: Split Utils out of Scalar.h 2018-03-29 22:31:38 +00:00
VNCoercion.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
ValueMapper.cpp Teach ValueMapper to use ODR uniqued types when available 2018-01-30 20:16:32 +00:00