Skip to content

Commit

Permalink
Use LLVM data structures in WiAnalysis branch info
Browse files Browse the repository at this point in the history
Increase speed of branch info computation.
  • Loading branch information
stefan-il authored and igcbot committed Dec 19, 2024
1 parent f8ec59d commit d805b07
Showing 1 changed file with 42 additions and 51 deletions.
93 changes: 42 additions & 51 deletions IGC/Compiler/CISACodeGen/WIAnalysis.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*========================== begin_copyright_notice ============================
Copyright (C) 2017-2023 Intel Corporation
Copyright (C) 2017-2024 Intel Corporation
SPDX-License-Identifier: MIT
Expand All @@ -22,8 +22,8 @@ SPDX-License-Identifier: MIT
#include <llvm/Support/Debug.h>
#include <llvm/IR/Constants.h>
#include "common/LLVMWarningsPop.hpp"

#include <string>
#include <stack>
#include <sstream>
#include "Probe/Assertion.h"

Expand Down Expand Up @@ -168,7 +168,6 @@ namespace IGC {
const llvm::BasicBlock* full_join;
llvm::DenseSet<llvm::BasicBlock*> influence_region;
llvm::SmallPtrSet<llvm::BasicBlock*, 4> partial_joins;
llvm::BasicBlock* fork_blk = nullptr;
};
} // namespace IGC

Expand Down Expand Up @@ -2327,79 +2326,71 @@ BranchInfo::BranchInfo(const IGCLLVM::TerminatorInst* inst, const BasicBlock* ip
: cbr(inst),
full_join(ipd)
{
const BasicBlock* fork_blk = inst->getParent();
auto* fork_blk = const_cast<BasicBlock*>(inst->getParent());
IGC_ASSERT_MESSAGE(cbr == fork_blk->getTerminator(), "block terminator mismatch");

llvm::SmallVector<BasicBlock*, 4> WorkSet;
if (cbr->getNumSuccessors() != 2) {
std::set<const BasicBlock*> Reached;
for (auto SI = succ_begin(fork_blk),
SE = succ_end(fork_blk); SI != SE; ++SI) {
auto Succ = *SI;
llvm::DenseSet<BasicBlock*> Reached;
llvm::DenseSet<BasicBlock*> Visited;
for (auto* Succ : successors(fork_blk))
{
if (Succ == full_join)
continue;
std::set<const BasicBlock*> Visited;
std::stack<const BasicBlock*> WorkSet;
WorkSet.push(Succ);
Visited.clear();
WorkSet.push_back(Succ);
while (!WorkSet.empty()) {
const BasicBlock* BB = WorkSet.top();
WorkSet.pop();
BasicBlock* BB = WorkSet.pop_back_val();
Visited.insert(BB);
influence_region.insert(const_cast<BasicBlock*>(BB));
if (Reached.count(BB))
partial_joins.insert(const_cast<BasicBlock*>(BB));
for (auto I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
auto SBB = *I;
for (auto* SBB : successors(BB))
{
if (SBB != full_join && !Visited.count(SBB))
WorkSet.push(SBB);
WorkSet.push_back(SBB);
}
}
// Merge Visited into Reached.
for (auto BB : Visited)
Reached.insert(BB);
Reached.insert(Visited.begin(), Visited.end());
}
return;
}
else {
std::set<BasicBlock*> f_set, t_set;
std::stack<BasicBlock*> work_set;
if (cbr->getSuccessor(0) != full_join)
llvm::DenseSet<BasicBlock*> f_set, t_set;
if (cbr->getSuccessor(0) != full_join)
{
WorkSet.push_back(cbr->getSuccessor(0));
while (!WorkSet.empty())
{
work_set.push(cbr->getSuccessor(0));
while (!work_set.empty())
BasicBlock* cur_blk = WorkSet.pop_back_val();
f_set.insert(cur_blk);
influence_region.insert(cur_blk);
for (auto* succ_blk : successors(cur_blk))
{
BasicBlock* cur_blk = work_set.top();
work_set.pop();
f_set.insert(cur_blk);
influence_region.insert(cur_blk);
for (succ_iterator SI = succ_begin(cur_blk), E = succ_end(cur_blk); SI != E; ++SI)
if (succ_blk != full_join && !f_set.count(succ_blk))
{
BasicBlock* succ_blk = (*SI);
if (succ_blk != full_join && !f_set.count(succ_blk))
{
work_set.push(succ_blk);
}
WorkSet.push_back(succ_blk);
}
}
}
if (cbr->getSuccessor(1) != full_join)
}
if (cbr->getSuccessor(1) != full_join)
{
WorkSet.push_back(cbr->getSuccessor(1));
while (!WorkSet.empty())
{
work_set.push(cbr->getSuccessor(1));
while (!work_set.empty())
BasicBlock* cur_blk = WorkSet.pop_back_val();
t_set.insert(cur_blk);
influence_region.insert(cur_blk);
if (f_set.count(cur_blk))
{
BasicBlock* cur_blk = work_set.top();
work_set.pop();
t_set.insert(cur_blk);
influence_region.insert(cur_blk);
if (f_set.count(cur_blk))
{
partial_joins.insert(cur_blk);
}
for (succ_iterator SI = succ_begin(cur_blk), E = succ_end(cur_blk); SI != E; ++SI)
partial_joins.insert(cur_blk);
}
for (auto* succ_blk : successors(cur_blk))
{
if (succ_blk != full_join && !t_set.count(succ_blk))
{
BasicBlock* succ_blk = (*SI);
if (succ_blk != full_join && !t_set.count(succ_blk))
{
work_set.push(succ_blk);
}
WorkSet.push_back(succ_blk);
}
}
}
Expand Down

0 comments on commit d805b07

Please sign in to comment.