Skip to content

Commit

Permalink
Addressing const-correctness for recently introduced genx.vload-rela…
Browse files Browse the repository at this point in the history
…ted APIs.

This change addresses only the recently introduced API part.
This should help in making the codebase more "const-ok".
  • Loading branch information
lsatanov authored and igcbot committed Jan 10, 2024
1 parent 4603e7c commit 50db156
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 163 deletions.
4 changes: 2 additions & 2 deletions IGC/VectorCompiler/lib/GenXCodeGen/GenXBaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2645,8 +2645,8 @@ bool Bale::isGStoreBaleLegal() const {
return isGlobalStoreLegal(ST);
}

llvm::SmallPtrSet<Instruction *, 2> Bale::getVLoadSources() const {
llvm::SmallPtrSet<Instruction *, 2> res;
llvm::SmallPtrSet<const Instruction *, 2> Bale::getVLoadSources() const {
llvm::SmallPtrSet<const Instruction *, 2> res;
for (const auto &Inst : Insts)
for (const auto &VLoad : genx::getSrcVLoads(Inst.Inst))
res.insert(VLoad);
Expand Down
2 changes: 1 addition & 1 deletion IGC/VectorCompiler/lib/GenXCodeGen/GenXBaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class Bale {
BaleInst *getHeadIgnoreGStore() {
return &*getHeadIgnoreGStoreIt();
}
llvm::SmallPtrSet<Instruction *, 2> getVLoadSources() const;
llvm::SmallPtrSet<const Instruction *, 2> getVLoadSources() const;
bool hasVLoadSources() const;
bool endsWithGStore() const {
return !empty() && rbegin()->Info.Type == BaleInfo::GSTORE;
Expand Down
37 changes: 21 additions & 16 deletions IGC/VectorCompiler/lib/GenXCodeGen/GenXGVClobberChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@ class GenXGVClobberChecker : public ModulePass,
GenXLiveness *Liveness = nullptr;
llvm::DenseMap<const Function *, GenXBaling *> BalingPerFunc;
llvm::DenseMap<const Function *, GenXLiveness *> LivenessPerFunc;
llvm::SmallPtrSet<BasicBlock *, 2> PhiUserExcludeBlocksOnCfgTraversal;
llvm::SmallPtrSet<const BasicBlock *, 2> PhiUserExcludeBlocksOnCfgTraversal;

StringRef DbgPrefix = "[gvload clobber checker] ";

bool
checkGVClobberingByInterveningStore(Instruction *LI,
llvm::SmallVector<Instruction *, 8> *SIs);
bool checkGVClobberingByInterveningStore(
Instruction *const LI,
const llvm::SmallVector<const Instruction *, 8> *const SIs);

using CallSitesPerFunctionT =
llvm::DenseMap<Function *, llvm::SmallVector<Instruction *, 8>>;
llvm::DenseMap<const Function *,
llvm::SmallVector<const Instruction *, 8>>;
void collectKillCallSites(
Function *Func,
const Function *Func,
GenXGVClobberChecker::CallSitesPerFunctionT &CallSitesPerFunction);

public:
Expand Down Expand Up @@ -210,7 +211,8 @@ ModulePass *llvm::createGenXGVClobberCheckerPass() {
}

bool GenXGVClobberChecker::checkGVClobberingByInterveningStore(
Instruction *LI, llvm::SmallVector<Instruction *, 8> *SIs) {
Instruction *const LI,
const llvm::SmallVector<const Instruction *, 8> *const SIs) {

auto CheckUserInst = [&](Instruction *UI) -> bool {
// TODO: this is an exceptional case. Maybe change GenXArgIndirectionWrapper
Expand Down Expand Up @@ -307,10 +309,10 @@ bool GenXGVClobberChecker::checkGVClobberingByInterveningStore(
};

void GenXGVClobberChecker::collectKillCallSites(
Function *Func,
const Function *Func,
GenXGVClobberChecker::CallSitesPerFunctionT &CallSitesPerFunction) {
llvm::SmallPtrSet<Function *, 4> VisitedFuncs;
llvm::SmallVector<Function *, 32> Stack;
llvm::SmallPtrSet<const Function *, 4> VisitedFuncs;
llvm::SmallVector<const Function *, 32> Stack;
Stack.push_back(Func);
while (!Stack.empty()) {
auto *CurrFunc = Stack.pop_back_val();
Expand All @@ -329,7 +331,7 @@ void GenXGVClobberChecker::collectKillCallSites(

bool GenXGVClobberChecker::runOnModule(Module &M) {
llvm::SetVector<Instruction *> Loads;
std::unordered_map<Value *, CallSitesPerFunctionT> KillCallSites;
std::unordered_map<const Value *, CallSitesPerFunctionT> KillCallSites;

if (CheckGVClobbOpt_CollectKillCallSites)
LLVM_DEBUG(dbgs() << DbgPrefix
Expand Down Expand Up @@ -385,13 +387,16 @@ bool GenXGVClobberChecker::runOnModule(Module &M) {
}
}

for (auto &G : M.globals()) {
for (const auto &G : M.globals()) {
if (!G.hasAttribute(genx::FunctionMD::GenXVolatile))
continue;
for (auto *V : genx::peelBitCastsGetUserValues(&G)) {
if (auto *I = dyn_cast<Instruction>(V)) {
for (const auto *V : genx::peelBitCastsGetUsers(&G)) {
if (const auto *I = dyn_cast<Instruction>(V)) {
if (genx::isAVLoad(I))
Loads.insert(I);
Loads.insert(const_cast<Instruction *>(
I)); // Loads can be modified further if fixup mode is enabled, so
// we are intentionally storing a pointer to non-const load
// here.
else if (CheckGVClobbOpt_CollectKillCallSites && genx::isAVStore(I))
collectKillCallSites(I->getFunction(), KillCallSites[&G]);
}
Expand All @@ -402,7 +407,7 @@ bool GenXGVClobberChecker::runOnModule(Module &M) {
return false;

bool ChangedOrNeedToAbort = false;
for (const auto &LI : Loads)
for (auto &LI : Loads)
ChangedOrNeedToAbort |= checkGVClobberingByInterveningStore(
LI, CheckGVClobbOpt_CollectKillCallSites
? &KillCallSites[genx::getBitCastedValue(LI->getOperand(0))]
Expand Down
Loading

0 comments on commit 50db156

Please sign in to comment.