@@ -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
3536using namespace llvm ;
3637using namespace IGC ;
3738using namespace IGC ::IGCMD;
39+ using namespace llvm ::PatternMatch;
3840
3941namespace {
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
9701010bool 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
0 commit comments