[llvm] 5d48b45 - [AMDGPU] Use depth first iterator instead of recursive DFS. NFCI.
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 15 03:33:04 PDT 2021
Author: Jay Foad
Date: 2021-03-15T10:32:55Z
New Revision: 5d48b45ce3bf45f8b8e1195fd74287ba90d70e89
URL: https://github.com/llvm/llvm-project/commit/5d48b45ce3bf45f8b8e1195fd74287ba90d70e89
DIFF: https://github.com/llvm/llvm-project/commit/5d48b45ce3bf45f8b8e1195fd74287ba90d70e89.diff
LOG: [AMDGPU] Use depth first iterator instead of recursive DFS. NFCI.
The reason for this is to avoid deep recursion in DFS() which can cause
stack overflow on large CFGs, especially on Windows.
Differential Revision: https://reviews.llvm.org/D98528
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
index c2a4d67ea98e..0bd6297c5296 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
@@ -14,6 +14,7 @@
#include "AMDGPU.h"
#include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/LegacyDivergenceAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
@@ -75,12 +76,6 @@ static void setNoClobberMetadata(Instruction *I) {
I->setMetadata("amdgpu.noclobber", MDNode::get(I->getContext(), {}));
}
-static void DFS(BasicBlock *Root, SetVector<BasicBlock*> & Set) {
- for (auto I : predecessors(Root))
- if (Set.insert(I))
- DFS(I, Set);
-}
-
bool AMDGPUAnnotateUniformValues::isClobberedInFunction(LoadInst * Load) {
// 1. get Loop for the Load->getparent();
// 2. if it exists, collect all the BBs from the most outer
@@ -101,7 +96,7 @@ bool AMDGPUAnnotateUniformValues::isClobberedInFunction(LoadInst * Load) {
Start = L->getHeader();
}
- DFS(Start, Checklist);
+ Checklist.insert(idf_begin(Start), idf_end(Start));
for (auto &BB : Checklist) {
BasicBlock::iterator StartIt = (!L && (BB == Load->getParent())) ?
BasicBlock::iterator(Load) : BB->end();
More information about the llvm-commits
mailing list