Skip to content

Commit 64a79bc

Browse files
weiyu-chenigcbot
authored andcommitted
Detect local to generic pointer casts, second try.
1 parent 332f230 commit 64a79bc

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

IGC/Compiler/CISACodeGen/ResolveGAS.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ SPDX-License-Identifier: MIT
3131
#include "common/LLVMWarningsPop.hpp"
3232
#include "GenISAIntrinsics/GenIntrinsics.h"
3333
#include "Probe/Assertion.h"
34+
#include <llvm/IR/PatternMatch.h>
3435

3536
using namespace llvm;
3637
using namespace IGC;
3738
using namespace IGC::IGCMD;
39+
using namespace llvm::PatternMatch;
3840

3941
namespace {
4042

@@ -946,6 +948,7 @@ namespace IGC
946948
void updateFunctionArgs(Function* oldFunc, Function* newFunc, GenericPointerArgs& newArgs);
947949
void updateAllUsesWithNewFunction(FuncToUpdate& f);
948950
void FixAddressSpaceInAllUses(Value* ptr, uint newAS, uint oldAS, AddrSpaceCastInst* recoverASC);
951+
void checkLocalToGenericCast(llvm::Module& M);
949952
};
950953
} // End anonymous namespace
951954

@@ -966,6 +969,43 @@ namespace IGC
966969
IGC_INITIALIZE_PASS_END(LowerGPCallArg, GP_PASS_FLAG, GP_PASS_DESC, GP_PASS_CFG_ONLY, GP_PASS_ANALYSIS)
967970
}
968971

972+
void LowerGPCallArg::checkLocalToGenericCast(llvm::Module& M)
973+
{
974+
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
975+
{
976+
Function* func = &(*I);
977+
// ToDo: replace with generic checks for extern functions
978+
if (func->hasFnAttribute("IndirectlyCalled"))
979+
{
980+
for (auto& arg : func->args())
981+
{
982+
PointerType* argPointerType = dyn_cast<PointerType>(arg.getType());
983+
if (argPointerType && argPointerType->getAddressSpace() == ADDRESS_SPACE_GENERIC)
984+
{
985+
return;
986+
}
987+
}
988+
}
989+
for (auto FI = inst_begin(func), FE = inst_end(func); FI != FE; ++FI)
990+
{
991+
auto addrCast = dyn_cast<AddrSpaceCastInst>(&(*FI));
992+
if (addrCast && addrCast->getDestAddressSpace() == ADDRESS_SPACE_GENERIC &&
993+
addrCast->getSrcAddressSpace() == ADDRESS_SPACE_LOCAL)
994+
{
995+
return;
996+
}
997+
Value *Ptr = nullptr;
998+
if (match(&(*FI), m_PtrToInt(m_Value(Ptr))) && Ptr->getType()->getPointerAddressSpace() == ADDRESS_SPACE_LOCAL)
999+
{
1000+
return;
1001+
}
1002+
}
1003+
}
1004+
1005+
// ToDo: enable in separate check-in
1006+
//ctx->getModuleMetaData()->hasNoLocalToGenericCast = true;
1007+
}
1008+
9691009

9701010
bool LowerGPCallArg::runOnModule(llvm::Module& M)
9711011
{
@@ -1026,7 +1066,10 @@ bool LowerGPCallArg::runOnModule(llvm::Module& M)
10261066

10271067
// If there are no functions to update, finish
10281068
if (funcsToUpdate.empty())
1069+
{
1070+
checkLocalToGenericCast(M);
10291071
return false;
1072+
}
10301073

10311074
// Step 2: update functions and lower their generic pointer arguments
10321075
// to their non-generic address space.
@@ -1155,6 +1198,7 @@ bool LowerGPCallArg::runOnModule(llvm::Module& M)
11551198
}
11561199
}
11571200

1201+
checkLocalToGenericCast(M);
11581202
return true;
11591203
}
11601204

IGC/Compiler/CodeGenContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ namespace IGC
538538

539539
bool OpenCLProgramContext::hasNoLocalToGenericCast() const
540540
{
541-
return m_InternalOptions.hasNoLocalToGeneric;
541+
return m_InternalOptions.hasNoLocalToGeneric || getModuleMetaData()->hasNoLocalToGenericCast;
542542
}
543543

544544
int16_t OpenCLProgramContext::getVectorCoalescingControl() const

IGC/common/MDFrameWork.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ namespace IGC
467467
unsigned int privateMemoryPerWI = 0;
468468
std::array<uint64_t, NUM_SHADER_RESOURCE_VIEW_SIZE> m_ShaderResourceViewMcsMask{};
469469
unsigned int computedDepthMode = 0; //Defaults to 0 meaning depth mode is off
470+
bool hasNoLocalToGenericCast = false; // This is programmed by ResolveGAS pass later.
470471
};
471472
void serialize(const IGC::ModuleMetaData &moduleMD, llvm::Module* module);
472473
void deserialize(IGC::ModuleMetaData &deserializedMD, const llvm::Module* module);

0 commit comments

Comments
 (0)