Skip to content

Commit a8b4f87

Browse files
karolzwolakigcbot
authored andcommitted
Fix build with LLVM 22 debug records API
In LLVM 22, debug variable intrinsics were replaced with DbgVariableRecord non-instruction debug records. DbgVariableRecord has no metadata slots, so calling setMetadata() on it fails to compile. Guard the affected call sites behind an LLVM version check until the debug info emitter is fully migrated to the new debug records API.
1 parent 16af5c7 commit a8b4f87

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,12 +1036,26 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack, boo
10361036
unsigned scalarBufferOffset = m_ModAllocaInfo->getBufferOffset(pAI);
10371037
unsigned bufferSize = m_ModAllocaInfo->getBufferStride(pAI);
10381038

1039-
// Attach metadata to instruction containing offset of storage
1039+
// Attach metadata to instruction containing offset of storage.
1040+
// In LLVM >= 22 debug declares are DbgVariableRecord objects (not Instructions)
1041+
// and have no metadata slots. The DwarfDebug/DwarfCompileUnit consumers
1042+
// (buildFpBasedLoc, buildPrivateBaseRegBased) are also not yet migrated to
1043+
// the new debug-records API and cannot find these declares anyway, so skip
1044+
// the metadata for now.
1045+
// FIXME: once DwarfDebug is migrated to DbgVariableRecord, carry StorageOffset
1046+
// and StorageSize via an alternative mechanism (e.g. DbgVariableRecord side
1047+
// map or DIExpression extension).
1048+
#if LLVM_VERSION_MAJOR < 22
10401049
auto OffsetMD =
10411050
MDNode::get(builder.getContext(), ConstantAsMetadata::get(builder.getInt32(scalarBufferOffset)));
10421051
DbgDcl->setMetadata("StorageOffset", OffsetMD);
10431052
auto SizeMD = MDNode::get(builder.getContext(), ConstantAsMetadata::get(builder.getInt32(bufferSize)));
10441053
DbgDcl->setMetadata("StorageSize", SizeMD);
1054+
#else
1055+
(void)scalarBufferOffset;
1056+
(void)bufferSize;
1057+
(void)DbgDcl;
1058+
#endif
10451059
}
10461060
}
10471061
// Replace all uses of original alloca with the bitcast
@@ -1335,11 +1349,16 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack, boo
13351349
if (modMD->compOpt.OptDisable) {
13361350
auto DbgDcls = IGCLLVM::findDbgDeclareUses(pAI);
13371351
for (auto DbgDcl : DbgDcls) {
1338-
// Attach metadata to instruction containing offset of storage
1352+
// Attach metadata to instruction containing offset of storage.
1353+
// FIXME: for llvm 22 (see above for more context).
1354+
#if LLVM_VERSION_MAJOR < 22
13391355
unsigned int scalarBufferOffset = m_ModAllocaInfo->getBufferOffset(pAI);
13401356
auto OffsetMD =
13411357
MDNode::get(builder.getContext(), ConstantAsMetadata::get(builder.getInt32(scalarBufferOffset)));
13421358
DbgDcl->setMetadata("StorageOffset", OffsetMD);
1359+
#else
1360+
(void)DbgDcl;
1361+
#endif
13431362
}
13441363
}
13451364

0 commit comments

Comments
 (0)