@@ -31,10 +31,12 @@ SPDX-License-Identifier: MIT
31
31
#include " common/LLVMWarningsPop.hpp"
32
32
#include " GenISAIntrinsics/GenIntrinsics.h"
33
33
#include " Probe/Assertion.h"
34
+ #include < llvm/IR/PatternMatch.h>
34
35
35
36
using namespace llvm ;
36
37
using namespace IGC ;
37
38
using namespace IGC ::IGCMD;
39
+ using namespace llvm ::PatternMatch;
38
40
39
41
namespace {
40
42
@@ -946,6 +948,7 @@ namespace IGC
946
948
void updateFunctionArgs (Function* oldFunc, Function* newFunc, GenericPointerArgs& newArgs);
947
949
void updateAllUsesWithNewFunction (FuncToUpdate& f);
948
950
void FixAddressSpaceInAllUses (Value* ptr, uint newAS, uint oldAS, AddrSpaceCastInst* recoverASC);
951
+ void checkLocalToGenericCast (llvm::Module& M);
949
952
};
950
953
} // End anonymous namespace
951
954
@@ -966,6 +969,43 @@ namespace IGC
966
969
IGC_INITIALIZE_PASS_END (LowerGPCallArg, GP_PASS_FLAG, GP_PASS_DESC, GP_PASS_CFG_ONLY, GP_PASS_ANALYSIS)
967
970
}
968
971
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
+
969
1009
970
1010
bool LowerGPCallArg::runOnModule (llvm::Module& M)
971
1011
{
@@ -1026,7 +1066,10 @@ bool LowerGPCallArg::runOnModule(llvm::Module& M)
1026
1066
1027
1067
// If there are no functions to update, finish
1028
1068
if (funcsToUpdate.empty ())
1069
+ {
1070
+ checkLocalToGenericCast (M);
1029
1071
return false ;
1072
+ }
1030
1073
1031
1074
// Step 2: update functions and lower their generic pointer arguments
1032
1075
// to their non-generic address space.
@@ -1155,6 +1198,7 @@ bool LowerGPCallArg::runOnModule(llvm::Module& M)
1155
1198
}
1156
1199
}
1157
1200
1201
+ checkLocalToGenericCast (M);
1158
1202
return true ;
1159
1203
}
1160
1204
0 commit comments