Skip to content

Commit eed6476

Browse files
s-perronkuhar
authored andcommitted
Reset PAL metadata when AMDGPU traget stream finishes
If the same stream object is used for multiple compiles, the PAL metadata from eariler compilations will leak into later one. See GPUOpen-Drivers/llpc#882 for how this is happening in LLPC. No tests were added because multiple compiles will have to happen using the same pass manager, and I do not see a setup for that on the LLVM side. Let me know if there is a good way to test this. Reviewed By: nhaehnle Differential Revision: https://reviews.llvm.org/D85667
1 parent cddb0db commit eed6476

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,15 @@ AMDGPUTargetAsmStreamer::AMDGPUTargetAsmStreamer(MCStreamer &S,
168168

169169
// A hook for emitting stuff at the end.
170170
// We use it for emitting the accumulated PAL metadata as directives.
171+
// The PAL metadata is reset after it is emitted.
171172
void AMDGPUTargetAsmStreamer::finish() {
172173
std::string S;
173174
getPALMetadata()->toString(S);
174175
OS << S;
176+
177+
// Reset the pal metadata so its data will not affect a compilation that
178+
// reuses this object.
179+
getPALMetadata()->reset();
175180
}
176181

177182
void AMDGPUTargetAsmStreamer::EmitDirectiveAMDGCNTarget(StringRef Target) {
@@ -423,6 +428,7 @@ MCELFStreamer &AMDGPUTargetELFStreamer::getStreamer() {
423428

424429
// A hook for emitting stuff at the end.
425430
// We use it for emitting the accumulated PAL metadata as a .note record.
431+
// The PAL metadata is reset after it is emitted.
426432
void AMDGPUTargetELFStreamer::finish() {
427433
std::string Blob;
428434
const char *Vendor = getPALMetadata()->getVendor();
@@ -432,6 +438,10 @@ void AMDGPUTargetELFStreamer::finish() {
432438
return;
433439
EmitNote(Vendor, MCConstantExpr::create(Blob.size(), getContext()), Type,
434440
[&](MCELFStreamer &OS) { OS.emitBytes(Blob); });
441+
442+
// Reset the pal metadata so its data will not affect a compilation that
443+
// reuses this object.
444+
getPALMetadata()->reset();
435445
}
436446

437447
void AMDGPUTargetELFStreamer::EmitNote(

llvm/lib/Target/AMDGPU/Utils/AMDGPUPALMetadata.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,3 +773,9 @@ void AMDGPUPALMetadata::setLegacy() {
773773
BlobType = ELF::NT_AMD_AMDGPU_PAL_METADATA;
774774
}
775775

776+
// Erase all PAL metadata.
777+
void AMDGPUPALMetadata::reset() {
778+
MsgPackDoc.clear();
779+
Registers = MsgPackDoc.getEmptyNode();
780+
HwStages = MsgPackDoc.getEmptyNode();
781+
}

llvm/lib/Target/AMDGPU/Utils/AMDGPUPALMetadata.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class AMDGPUPALMetadata {
106106
// Set legacy PAL metadata format.
107107
void setLegacy();
108108

109+
// Erase all PAL metadata.
110+
void reset();
111+
109112
private:
110113
// Return whether the blob type is legacy PAL metadata.
111114
bool isLegacy() const;

0 commit comments

Comments
 (0)