[llvm-branch-commits] [lld] [llvm] [RFC][AMDGPU][lld] Add object linking support (PR #206787)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jul 2 00:15:01 PDT 2026
================
@@ -0,0 +1,1757 @@
+//===- AMDGPUObjectLinking.cpp - AMDGPU link-time resolution --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements link-time resolution and patching for AMDGPU object linking.
+//
+// The linker:
+// 1. Uses the linked image's resolved target e_flags
+// 2. Collects SHN_AMDGPU_LDS and named-barrier symbols
+// 3. Parses .amdgpu.info to build the cross-TU call graph, type-ID
+// signatures, LDS and named-barrier uses, and per-function resource usage
+// 4. Resolves indirect call edges, function aliases, and kernel entries
+// 5. Validates call-edge wave-size compatibility
+// 6. Builds a shared SCC condensation graph for kernel-reachable functions
+// 7. Computes per-kernel LDS and named-barrier reachability
+// 8. Assigns LDS offsets and named-barrier IDs
+// 9. Propagates resource usage across the SCC graph (MAX for registers, OR
+// for flags, caller scratch plus maximum callee scratch path)
+// 10. Validates required ABI occupancy and wave-size metadata, call-edge ABI
+// compatibility, and each kernel's LDS usage against its occupancy
+//
+// After resolution, the linker patches kernel descriptors and HSA metadata
+// with the resolved LDS size, named-barrier count, propagated register usage,
+// scratch size, dynamic-stack flag, and related resource fields.
+//
+//===----------------------------------------------------------------------===//
+
+#include "AMDGPUObjectLinking.h"
+#include "Config.h"
+#include "InputFiles.h"
+#include "InputSection.h"
+#include "SymbolTable.h"
+#include "Symbols.h"
+#include "lld/Common/ErrorHandler.h"
+#include "llvm/BinaryFormat/AMDGPUMetadataVerifier.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/BinaryFormat/MsgPackDocument.h"
+#include "llvm/Support/AMDGPUObjLinkingInfo.h"
+#include "llvm/Support/AMDGPUObjectLinkingHelper.h"
+#include "llvm/Support/AMDHSAKernelDescriptor.h"
+#include "llvm/Support/Alignment.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/TimeProfiler.h"
+#include "llvm/TargetParser/AMDGPUTargetParser.h"
+
+#define DEBUG_TYPE "amdgpu-object-linking"
+
+using namespace llvm;
+using namespace llvm::support::endian;
+using namespace llvm::object;
+using namespace llvm::ELF;
+using namespace lld;
+using namespace lld::elf;
+
+namespace {
+
+// One SHN_AMDGPU_LDS symbol after collection and before it is rewritten to a
+// concrete offset.
+struct LDSSymbolInfo {
+ Symbol *sym = nullptr;
+ uint64_t size = 0;
+ Align alignment = Align(1);
----------------
arsenm wrote:
I think this is the default
https://github.com/llvm/llvm-project/pull/206787
More information about the llvm-branch-commits
mailing list