@@ -18,6 +18,7 @@ SPDX-License-Identifier: MIT
18
18
19
19
#include " visa/include/visaBuilder_interface.h"
20
20
21
+ #include " DebugInfo/DwarfCompileUnit.hpp"
21
22
#include " DebugInfo/StreamEmitter.hpp"
22
23
#include " DebugInfo/VISAIDebugEmitter.hpp"
23
24
#include " DebugInfo/VISAModule.hpp"
@@ -835,11 +836,12 @@ class GenXFunction final : public IGC::VISAModule {
835
836
836
837
public:
837
838
GenXFunction (const GenXSubtarget &STIn, const GenXVisaRegAlloc &RAIn,
838
- const Function &F, CompiledVisaWrapper &&CW ,
839
- const genx::di::VisaMapping &V2I,
839
+ const GenXBaling &BAn, const Function &F ,
840
+ CompiledVisaWrapper &&CW, const genx::di::VisaMapping &V2I,
840
841
const ModuleToVisaTransformInfo &MVTI, bool IsPrimary)
841
- : F{F}, ST{STIn}, VisaMapping{V2I}, CompiledVisa{std::move (CW)}, RA{RAIn},
842
- MVTI (MVTI), VISAModule(const_cast <Function *>(&F), IsPrimary) {
842
+ : F{F}, ST{STIn}, VisaMapping{V2I},
843
+ CompiledVisa{std::move (CW)}, RA{RAIn}, BA{BAn}, MVTI(MVTI),
844
+ VISAModule (const_cast <Function *>(&F), IsPrimary) {
843
845
844
846
if (MVTI.isSubroutine (&F))
845
847
SetType (ObjectType::SUBROUTINE);
@@ -913,34 +915,98 @@ class GenXFunction final : public IGC::VISAModule {
913
915
914
916
const genx::di::VisaMapping &getVisaMapping () const { return VisaMapping; }
915
917
918
+ static constexpr unsigned RdIndex =
919
+ GenXIntrinsic::GenXRegion::RdIndexOperandNum;
920
+ static constexpr unsigned RdVstride =
921
+ GenXIntrinsic::GenXRegion::RdVStrideOperandNum;
922
+ static constexpr unsigned RdWidth =
923
+ GenXIntrinsic::GenXRegion::RdWidthOperandNum;
924
+ static constexpr unsigned RdStride =
925
+ GenXIntrinsic::GenXRegion::RdStrideOperandNum;
926
+ static constexpr unsigned RdNumOp =
927
+ GenXIntrinsic::GenXRegion::OldValueOperandNum;
928
+
929
+ static const Value *
930
+ CalculateBaledLocation (const CallInst *UseInst,
931
+ llvm::SmallVector<unsigned , 0 > *Offsets,
932
+ const GenXBaling &BA, const DataLayout &DL) {
933
+ IGC_ASSERT (UseInst);
934
+ IGC_ASSERT (Offsets);
935
+ if (!GenXIntrinsic::isRdRegion (UseInst))
936
+ return UseInst;
937
+ auto BI = BA.getBaleInfo (UseInst);
938
+
939
+ if (BI.Type != genx::BaleInfo::RDREGION ||
940
+ !dyn_cast<ConstantInt>(UseInst->getOperand (RdIndex)) ||
941
+ BI.isOperandBaled (RdNumOp) || !BA.isBaled (UseInst))
942
+ return UseInst;
943
+
944
+ auto getSignConstant = [](Value *operand) {
945
+ auto *CI = cast<ConstantInt>(operand);
946
+ return CI->getSExtValue ();
947
+ };
948
+
949
+ // In this place comes rdregion, whose operand is not baled - here we
950
+ // build location for its operand
951
+ LLVM_DEBUG (dbgs () << " Found Bale candidate for propagation:\n " ;
952
+ UseInst->dump (););
953
+ auto *VTy = dyn_cast<IGCLLVM::FixedVectorType>(UseInst->getType ());
954
+ // TODO: Investigate scalar
955
+ if (!VTy)
956
+ return UseInst;
957
+ auto Vstride = getSignConstant (UseInst->getOperand (RdVstride));
958
+ auto Width = getSignConstant (UseInst->getOperand (RdWidth));
959
+ auto Stride = getSignConstant (UseInst->getOperand (RdStride));
960
+ auto StartIdx = getSignConstant (UseInst->getOperand (RdIndex));
961
+ auto ElSize = vc::getTypeSize (VTy->getElementType (), &DL).inBits ();
962
+ IGC_ASSERT (Width);
963
+ unsigned NumElements = VTy->getNumElements () / Width;
964
+
965
+ for (unsigned i = 0 ; i < NumElements; ++i) {
966
+ for (unsigned j = 0 ; j < Width; ++j) {
967
+ auto CurrOffset = StartIdx + i * Vstride * ElSize + j * Stride * ElSize;
968
+ // Check type overflow
969
+ IGC_ASSERT (CurrOffset <= std::numeric_limits<unsigned >::max ());
970
+ Offsets->push_back (CurrOffset);
971
+ }
972
+ }
973
+ // Replace value to source of rdregion
974
+ return UseInst->getOperand (RdNumOp);
975
+ }
976
+
916
977
IGC::VISAVariableLocation
917
978
GetVariableLocation (const Instruction *DbgInst) const override {
918
-
919
979
using Location = IGC::VISAVariableLocation;
920
980
auto EmptyLoc = [this ](StringRef Reason) {
921
981
LLVM_DEBUG (dbgs () << " Empty Location Returned (" << Reason
922
982
<< " )\n <<<\n " );
923
983
return Location (this );
924
984
};
925
- auto ConstantLoc = [this ](const Constant *C) {
926
- LLVM_DEBUG (dbgs () << " ConstantLoc\n <<<\n " );
927
- return Location (C, this );
928
- };
929
985
930
986
IGC_ASSERT (isa<DbgInfoIntrinsic>(DbgInst));
931
987
932
988
LLVM_DEBUG (dbgs () << " >>>\n GetVariableLocation for " << *DbgInst << " \n " );
933
- const Value *DbgValue = nullptr ;
934
989
const DIVariable *VarDescr = nullptr ;
935
990
if (const auto *pDbgAddrInst = dyn_cast<DbgDeclareInst>(DbgInst)) {
936
- DbgValue = pDbgAddrInst->getAddress ();
937
991
VarDescr = pDbgAddrInst->getVariable ();
938
992
} else if (const auto *pDbgValInst = dyn_cast<DbgValueInst>(DbgInst)) {
939
- DbgValue = pDbgValInst->getValue ();
940
993
VarDescr = pDbgValInst->getVariable ();
941
994
} else {
942
995
return EmptyLoc (" unsupported Debug Intrinsic" );
943
996
}
997
+ const Value *DbgValue =
998
+ IGCLLVM::getVariableLocation (cast<DbgVariableIntrinsic>(DbgInst));
999
+
1000
+ llvm::SmallVector<unsigned , 0 > Offsets;
1001
+ if (auto *UseInst = dyn_cast_or_null<CallInst>(DbgValue)) {
1002
+ DbgValue = CalculateBaledLocation (UseInst, &Offsets, BA,
1003
+ F.getParent ()->getDataLayout ());
1004
+ if (!Offsets.empty () &&
1005
+ !std::any_of (Offsets.begin (), Offsets.end (),
1006
+ [&](auto off) { return off < getGRFSizeInBits (); })) {
1007
+ return EmptyLoc (" Unsupported cross-GRF offset\n " );
1008
+ }
1009
+ }
944
1010
945
1011
IGC_ASSERT (VarDescr);
946
1012
if (!DbgValue) {
@@ -957,23 +1023,16 @@ class GenXFunction final : public IGC::VISAModule {
957
1023
return EmptyLoc (" UndefValue" );
958
1024
}
959
1025
if (auto *ConstVal = dyn_cast<Constant>(DbgValue)) {
960
- return ConstantLoc (ConstVal);
1026
+ LLVM_DEBUG (dbgs () << " ConstantLoc\n <<<\n " );
1027
+ return Location (ConstVal, this );
961
1028
}
962
1029
963
1030
auto *Reg = getRegisterForValue (DbgValue);
964
1031
if (!Reg) {
965
1032
return EmptyLoc (" could not find virtual register" );
966
1033
}
967
1034
968
- const bool IsRegister = true ;
969
- const bool IsMemory = false ;
970
- const bool IsGlobalASI = false ;
971
- auto *VTy = dyn_cast<IGCLLVM::FixedVectorType>(DbgValue->getType ());
972
- unsigned NumElements = VTy ? VTy->getNumElements () : 1 ;
973
- const bool IsVectorized = false ;
974
-
975
- return Location (Reg->Num , IsRegister, IsMemory, NumElements, IsVectorized,
976
- IsGlobalASI, this );
1035
+ return Location (Reg->Num , std::move (Offsets), this );
977
1036
}
978
1037
979
1038
void UpdateVisaId () override {
@@ -1063,6 +1122,7 @@ class GenXFunction final : public IGC::VISAModule {
1063
1122
const genx::di::VisaMapping &VisaMapping;
1064
1123
CompiledVisaWrapper CompiledVisa;
1065
1124
const GenXVisaRegAlloc &RA;
1125
+ const GenXBaling &BA;
1066
1126
const ModuleToVisaTransformInfo &MVTI;
1067
1127
};
1068
1128
@@ -1146,7 +1206,8 @@ GenXObjectHolder buildGenXFunctionObject(const ModuleToVisaTransformInfo &MVTI,
1146
1206
const GenObjectWrapper &GOW,
1147
1207
const ProgramInfo::FunctionInfo &FI,
1148
1208
const GenXSubtarget &ST,
1149
- const GenXVisaRegAlloc &RA) {
1209
+ const GenXVisaRegAlloc &RA,
1210
+ const GenXBaling &BA) {
1150
1211
StringRef CompiledObjectName = FI.F .getName ();
1151
1212
if (MVTI.isSubroutine (&FI.F ))
1152
1213
CompiledObjectName = MVTI.getSubroutineOwner (&FI.F )->getName ();
@@ -1157,22 +1218,26 @@ GenXObjectHolder buildGenXFunctionObject(const ModuleToVisaTransformInfo &MVTI,
1157
1218
1158
1219
bool IsPrimaryFunction = &GOW.getEntryPoint () == &FI.F ;
1159
1220
return std::make_unique<GenXFunction>(
1160
- ST, RA, FI.F , std::move (CW), FI.VisaMapping , MVTI, IsPrimaryFunction);
1221
+ ST, RA, BA, FI.F , std::move (CW), FI.VisaMapping , MVTI, IsPrimaryFunction);
1161
1222
}
1162
1223
1163
1224
using GenXObjectHolderList = std::vector<GenXObjectHolder>;
1164
1225
GenXObjectHolderList translateProgramInfoToGenXFunctionObjects (
1165
1226
const GenObjectWrapper &GOW, const ProgramInfo &PI, const GenXSubtarget &ST,
1166
- const std::vector<const GenXVisaRegAlloc *> &RAs) {
1227
+ const std::vector<const GenXVisaRegAlloc *> &RAs,
1228
+ const std::vector<const GenXBaling *> &BAs) {
1167
1229
const auto &MVTI = PI.MVTI ;
1168
1230
GenXObjectHolderList GenXFunctionHolders;
1169
1231
IGC_ASSERT (PI.FIs .size () == RAs.size ());
1170
- std::transform (
1171
- PI.FIs .begin (), PI.FIs .end (), RAs.begin (),
1172
- std::back_inserter (GenXFunctionHolders),
1173
- [&ST, &MVTI, &GOW](const auto &FI, const GenXVisaRegAlloc *const RA) {
1174
- return buildGenXFunctionObject (MVTI, GOW, FI, ST, *RA);
1175
- });
1232
+ IGC_ASSERT (BAs.size () == RAs.size ());
1233
+ auto Zippy = llvm::zip (RAs, BAs);
1234
+ std::transform (PI.FIs .begin (), PI.FIs .end (), Zippy.begin (),
1235
+ std::back_inserter (GenXFunctionHolders),
1236
+ [&ST, &MVTI, &GOW](const auto &FI, const auto &ZIP) {
1237
+ const GenXVisaRegAlloc *RA = std::get<0 >(ZIP);
1238
+ const GenXBaling *BA = std::get<1 >(ZIP);
1239
+ return buildGenXFunctionObject (MVTI, GOW, FI, ST, *RA, *BA);
1240
+ });
1176
1241
return GenXFunctionHolders;
1177
1242
}
1178
1243
@@ -1365,15 +1430,20 @@ void GenXDebugInfo::processKernel(const IGC::DebugEmitterOpts &DebugOpts,
1365
1430
.getGenXSubtarget ();
1366
1431
auto *FGA = &getAnalysis<FunctionGroupAnalysis>();
1367
1432
std::vector<const GenXVisaRegAlloc *> VisaRegAllocs;
1433
+ std::vector<const GenXBaling *> BalingList;
1368
1434
for (const auto &FP : PI.FIs ) {
1369
1435
FunctionGroup *currentFG = FGA->getAnyGroup (&FP.F );
1370
1436
VisaRegAllocs.push_back (
1371
1437
&(getAnalysis<GenXVisaRegAllocWrapper>().getFGPassImpl (currentFG)));
1438
+ GenXBaling *Baling =
1439
+ &(getAnalysis<GenXGroupBalingWrapper>().getFGPassImpl (currentFG));
1440
+ BalingList.push_back (Baling);
1372
1441
}
1373
1442
1374
- GenXFunctionPtrList GFPointers = initializeDebugEmitter (
1375
- *Emitter, DebugOpts, PI,
1376
- translateProgramInfoToGenXFunctionObjects (GOW, PI, ST, VisaRegAllocs));
1443
+ GenXFunctionPtrList GFPointers =
1444
+ initializeDebugEmitter (*Emitter, DebugOpts, PI,
1445
+ translateProgramInfoToGenXFunctionObjects (
1446
+ GOW, PI, ST, VisaRegAllocs, BalingList));
1377
1447
1378
1448
auto &KF = GOW.getEntryPoint ();
1379
1449
IGC_ASSERT (ElfOutputs.count (&KF) == 0 );
@@ -1421,6 +1491,7 @@ void GenXDebugInfo::getAnalysisUsage(AnalysisUsage &AU) const {
1421
1491
AU.addRequired <TargetPassConfig>();
1422
1492
AU.addRequired <GenXVisaRegAllocWrapper>();
1423
1493
AU.addRequired <CallGraphWrapperPass>();
1494
+ AU.addRequired <GenXGroupBaling>();
1424
1495
AU.setPreservesAll ();
1425
1496
}
1426
1497
0 commit comments