[llvm] [AMDGPU] Fix unittest linking error with `LLVM_LINK_LLVM_DYLIB` (PR #91727)
Jonas Hahnfeld via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 04:15:47 PDT 2024
https://github.com/hahnjo created https://github.com/llvm/llvm-project/pull/91727
Follow-up to https://github.com/llvm/llvm-project/pull/88257
>From 551d74a4defc2607151db330477bba01634b231a Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <jonas.hahnfeld at cern.ch>
Date: Fri, 10 May 2024 11:57:45 +0200
Subject: [PATCH 1/2] [AMDGPU] Simpify Target creation in unittest
Avoid relying on concrete GCN subclasses: They are hidden, which
leads to linking problems with LLVM_LINK_LLVM_DYLIB.
---
llvm/unittests/MC/AMDGPU/SIProgramInfoMCExprs.cpp | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/llvm/unittests/MC/AMDGPU/SIProgramInfoMCExprs.cpp b/llvm/unittests/MC/AMDGPU/SIProgramInfoMCExprs.cpp
index f2161f71e6e99..a0e03347e6914 100644
--- a/llvm/unittests/MC/AMDGPU/SIProgramInfoMCExprs.cpp
+++ b/llvm/unittests/MC/AMDGPU/SIProgramInfoMCExprs.cpp
@@ -7,9 +7,8 @@
//===----------------------------------------------------------------------===//
#include "AMDGPUHSAMetadataStreamer.h"
-#include "AMDGPUTargetMachine.h"
-#include "GCNSubtarget.h"
#include "SIProgramInfo.h"
+#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
@@ -25,9 +24,8 @@ using namespace llvm;
class SIProgramInfoMCExprsTest : public testing::Test {
protected:
- std::unique_ptr<GCNTargetMachine> TM;
+ std::unique_ptr<LLVMTargetMachine> TM;
std::unique_ptr<LLVMContext> Ctx;
- std::unique_ptr<GCNSubtarget> ST;
std::unique_ptr<MachineModuleInfo> MMI;
std::unique_ptr<MachineFunction> MF;
std::unique_ptr<Module> M;
@@ -49,7 +47,7 @@ class SIProgramInfoMCExprsTest : public testing::Test {
const Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
TargetOptions Options;
- TM.reset(static_cast<GCNTargetMachine *>(TheTarget->createTargetMachine(
+ TM.reset(static_cast<LLVMTargetMachine *>(TheTarget->createTargetMachine(
Triple, CPU, FS, Options, std::nullopt, std::nullopt)));
Ctx = std::make_unique<LLVMContext>();
@@ -59,9 +57,7 @@ class SIProgramInfoMCExprsTest : public testing::Test {
auto *F = Function::Create(FType, GlobalValue::ExternalLinkage, "Test", *M);
MMI = std::make_unique<MachineModuleInfo>(TM.get());
- ST = std::make_unique<GCNSubtarget>(TM->getTargetTriple(),
- TM->getTargetCPU(),
- TM->getTargetFeatureString(), *TM);
+ auto *ST = TM->getSubtargetImpl(*F);
MF = std::make_unique<MachineFunction>(*F, *TM, *ST, 1, *MMI);
PI.reset(*MF.get());
>From 853ec603868523e46d873afbdab5f77501916a87 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <jonas.hahnfeld at cern.ch>
Date: Fri, 10 May 2024 11:59:19 +0200
Subject: [PATCH 2/2] [AMDGPU] Export MetadataStreamerMsgPackV4 and
SIProgramInfo
They are used by a unittest, which otherwise has linking problems
with LLVM_LINK_LLVM_DYLIB.
---
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h | 4 +++-
llvm/lib/Target/AMDGPU/SIProgramInfo.h | 3 ++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h b/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
index 26229af638f22..0e3bc63919f06 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
@@ -18,6 +18,7 @@
#include "llvm/BinaryFormat/MsgPackDocument.h"
#include "llvm/Support/AMDGPUMetadata.h"
#include "llvm/Support/Alignment.h"
+#include "llvm/Support/Compiler.h"
namespace llvm {
@@ -61,7 +62,8 @@ class MetadataStreamer {
msgpack::MapDocNode Kern) = 0;
};
-class MetadataStreamerMsgPackV4 : public MetadataStreamer {
+class LLVM_EXTERNAL_VISIBILITY MetadataStreamerMsgPackV4
+ : public MetadataStreamer {
protected:
std::unique_ptr<msgpack::Document> HSAMetadataDoc =
std::make_unique<msgpack::Document>();
diff --git a/llvm/lib/Target/AMDGPU/SIProgramInfo.h b/llvm/lib/Target/AMDGPU/SIProgramInfo.h
index c0a353033c3c5..e66e5a194c8b5 100644
--- a/llvm/lib/Target/AMDGPU/SIProgramInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIProgramInfo.h
@@ -17,6 +17,7 @@
#define LLVM_LIB_TARGET_AMDGPU_SIPROGRAMINFO_H
#include "llvm/IR/CallingConv.h"
+#include "llvm/Support/Compiler.h"
#include <cstdint>
namespace llvm {
@@ -27,7 +28,7 @@ class MCExpr;
class MachineFunction;
/// Track resource usage for kernels / entry functions.
-struct SIProgramInfo {
+struct LLVM_EXTERNAL_VISIBILITY SIProgramInfo {
// Fields set in PGM_RSRC1 pm4 packet.
const MCExpr *VGPRBlocks = nullptr;
const MCExpr *SGPRBlocks = nullptr;
More information about the llvm-commits
mailing list