Skip to content

Commit

Permalink
uniform analysis cross-loop def-use random
Browse files Browse the repository at this point in the history
add another condition for def-use affected by divergent-branch
  • Loading branch information
Gang Y Chen authored and igcbot committed Jun 18, 2023
1 parent 4b858d0 commit 28ad061
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
4 changes: 3 additions & 1 deletion IGC/AdaptorCommon/DivergentBarrierPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SPDX-License-Identifier: MIT
#include "llvmWrapper/IR/DerivedTypes.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Verifier.h"
Expand Down Expand Up @@ -96,10 +97,11 @@ bool DivergentBarrierPass::hasDivergentBarrier(

PostDominatorTree PDT(*F);
DominatorTree DT(*F);
LoopInfo LI(DT);

TranslationTable TT;
TT.run(*F);
WIAnalysisRunner WI(F, &DT, &PDT, m_MDUtils, m_CGCtx, ModMD, &TT);
WIAnalysisRunner WI(F, &LI, &DT, &PDT, m_MDUtils, m_CGCtx, ModMD, &TT);
WI.run();

return llvm::any_of(Barriers, [&](Instruction* I) {
Expand Down
5 changes: 4 additions & 1 deletion IGC/Compiler/CISACodeGen/VectorPreProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ namespace
AU.addRequired<MetaDataUtilsWrapper>();
AU.addRequired<DominatorTreeWrapperPass>();
AU.addRequired<PostDominatorTreeWrapperPass>();
AU.addRequired<LoopInfoWrapperPass>();
}

private:
Expand Down Expand Up @@ -1809,12 +1810,14 @@ bool VectorPreProcess::runOnFunction(Function& F)
&getAnalysis<DominatorTreeWrapperPass>().getDomTree();
auto* PDT =
&getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
auto *LI =
&getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
auto* ModMD =
getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();

TranslationTable TT;
TT.run(F);
WIAnalysisRunner WI(&F, DT, PDT, MDUtils, m_CGCtx, ModMD, &TT);
WIAnalysisRunner WI(&F, LI, DT, PDT, MDUtils, m_CGCtx, ModMD, &TT);
WI.run();

for (uint32_t i = 0; i < m_WorkList.size(); ++i)
Expand Down
48 changes: 43 additions & 5 deletions IGC/Compiler/CISACodeGen/WIAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ void WIAnalysisRunner::dump() const

void WIAnalysisRunner::init(
llvm::Function* F,
llvm::LoopInfo* LI,
llvm::DominatorTree* DT,
llvm::PostDominatorTree* PDT,
IGC::IGCMD::MetaDataUtils* MDUtils,
Expand All @@ -282,6 +283,7 @@ void WIAnalysisRunner::init(
IGC::TranslationTable* TransTable)
{
m_func = F;
this->LI = LI;
this->DT = DT;
this->PDT = PDT;
m_pMdUtils = MDUtils;
Expand Down Expand Up @@ -381,11 +383,12 @@ bool WIAnalysis::runOnFunction(Function& F)
auto* MDUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
auto* DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
auto* PDT = &getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
auto* CGCtx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
auto *CGCtx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
auto* ModMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
auto* pTT = &getAnalysis<TranslationTable>();

Runner.init(&F, DT, PDT, MDUtils, CGCtx, ModMD, pTT);
Runner.init(&F, LI, DT, PDT, MDUtils, CGCtx, ModMD, pTT);
return Runner.run();
}

Expand Down Expand Up @@ -911,17 +914,47 @@ void WIAnalysisRunner::update_cf_dep(const IGCLLVM::TerminatorInst* inst)
BranchInfo br_info(inst, ipd);
// debug: dump influence region and partial-joins
// br_info.print(ods());

auto* CbrLoop = LI->getLoopFor(blk);
// Loop* IPDLoop = nullptr;
// check dep-type for every phi in the full join
if (ipd)
{
updatePHIDepAtJoin(ipd, &br_info);
// IPDLoop = LI->getLoopFor(ipd);
}
// check dep-type for every phi in the partial-joins
for (SmallPtrSet<BasicBlock*, 4>::iterator join_it = br_info.partial_joins.begin(),
join_e = br_info.partial_joins.end(); join_it != join_e; ++join_it)
{
updatePHIDepAtJoin(*join_it, &br_info);
auto *PJ = *join_it;
// skip the special loop-entry case
if (DT->dominates(PJ, blk)) {
int NumPreds = 0;
for (auto *pred : predecessors(PJ)) {
if (br_info.influence_region.count(pred)) {
NumPreds++;
}
}
if (NumPreds <= 1)
continue;
}
auto PJDom = DT->getNode(PJ)->getIDom()->getBlock();
// If both partial-join and it IDom are in partial-join region
// there are cases in which phi-nodes in partial-joins are not
// relevant to the cbr under the investigation
auto LoopA = LI->getLoopFor(PJDom);
//auto LoopB = LI->getLoopFor(PJ);
if (br_info.partial_joins.count(PJDom))
{
// both PJ and its IDom are outside the CBR loop
if (!CbrLoop || !CbrLoop->contains(LoopA))
continue;
// cbr and its IPD are at the same loop level
// the influence region can be considered as a DAG
// if (IPDLoop == CbrLoop)
// continue;
}
updatePHIDepAtJoin(PJ, &br_info);
}

// walk through all the instructions in the influence-region
Expand Down Expand Up @@ -970,6 +1003,7 @@ void WIAnalysisRunner::update_cf_dep(const IGCLLVM::TerminatorInst* inst)
// 1) if use is in the full-join
// 2) if use is even outside the full-join
// 3) if use is in partial-join but def is not in partial-join
// 4) if def and use are in partial-join but def inside loop
Value::use_iterator use_it = defi->use_begin();
Value::use_iterator use_e = defi->use_end();
for (; use_it != use_e; ++use_it)
Expand All @@ -989,10 +1023,14 @@ void WIAnalysisRunner::update_cf_dep(const IGCLLVM::TerminatorInst* inst)
// local def-use, not related to control-dependence
continue; // skip
}
auto DefLoop = LI->getLoopFor(def_blk);
auto UseLoop = LI->getLoopFor(user_blk);
if (user_blk == br_info.full_join ||
!br_info.influence_region.count(user_blk) ||
(br_info.partial_joins.count(user_blk) &&
!br_info.partial_joins.count(def_blk))
(!br_info.partial_joins.count(def_blk) ||
(DefLoop && !DefLoop->contains(UseLoop)))
)
)
{
updateDepMap(defi, instDep);
Expand Down
16 changes: 6 additions & 10 deletions IGC/Compiler/CISACodeGen/WIAnalysis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SPDX-License-Identifier: MIT
#include <llvm/IR/Value.h>
#include <llvm/IR/InstIterator.h>
#include <llvm/IR/Dominators.h>
#include <llvm/Analysis/LoopInfo.h>
#include <llvm/Analysis/PostDominators.h>
#include "common/LLVMWarningsPop.hpp"

Expand Down Expand Up @@ -78,6 +79,7 @@ namespace IGC
public:
void init(
llvm::Function* F,
llvm::LoopInfo* LI,
llvm::DominatorTree* DT,
llvm::PostDominatorTree* PDT,
IGCMD::MetaDataUtils* MDUtils,
Expand All @@ -87,14 +89,15 @@ namespace IGC

WIAnalysisRunner(
llvm::Function* F,
llvm::LoopInfo* LI,
llvm::DominatorTree* DT,
llvm::PostDominatorTree* PDT,
IGCMD::MetaDataUtils* MDUtils,
CodeGenContext* CGCtx,
ModuleMetaData* ModMD,
TranslationTable* TransTable)
{
init(F, DT, PDT, MDUtils, CGCtx, ModMD, TransTable);
init(F, LI, DT, PDT, MDUtils, CGCtx, ModMD, TransTable);
}

WIAnalysisRunner() {}
Expand Down Expand Up @@ -247,12 +250,6 @@ namespace IGC
bool& IsLzUniform);

private:
#ifdef OCL_SPECIFIC
// @brief pointer to Soa alloca analysis performed for this function
SoaAllocaAnalysis* m_soaAllocaAnalysis = nullptr;
/// Runtime services pointer
RuntimeServices* m_rtServices = nullptr;
#endif

/// The WIAnalysis follows pointer arithmetic
/// and Index arithmetic when calculating dependency
Expand Down Expand Up @@ -281,6 +278,7 @@ namespace IGC
std::vector<const llvm::Value*> m_forcedUniforms;

llvm::Function* m_func = nullptr;
llvm::LoopInfo *LI = nullptr;
llvm::DominatorTree* DT = nullptr;
llvm::PostDominatorTree* PDT = nullptr;
IGC::IGCMD::MetaDataUtils* m_pMdUtils = nullptr;
Expand Down Expand Up @@ -325,11 +323,9 @@ namespace IGC
{
// Analysis pass preserve all
AU.setPreservesAll();
#ifdef OCL_SPECIFIC
AU.addRequired<SoaAllocaAnalysis>();
#endif
AU.addRequired<llvm::DominatorTreeWrapperPass>();
AU.addRequired<llvm::PostDominatorTreeWrapperPass>();
AU.addRequired<llvm::LoopInfoWrapperPass>();
AU.addRequired<MetaDataUtilsWrapper>();
AU.addRequired<CodeGenContextWrapper>();
AU.addRequired<TranslationTable>();
Expand Down

0 comments on commit 28ad061

Please sign in to comment.