llvm-project/llvm/lib/Target/SPIRV/SPIRVCBufferAccess.h
Steven Perron 00ad9ecc1c
[SPIRV][HLSL] Implement CBuffer access lowering pass (#159136)
This patch introduces a new pass, SPIRVCBufferAccess, which is
responsible for translating accesses to HLSL constant buffer (cbuffer)
global variables into accesses to the proper SPIR-V resource.

The pass operates by:
1. Identifying all cbuffers via the `!hlsl.cbs` metadata.
2. Replacing all uses of cbuffer member global variables with
`llvm.spv.resource.getpointer` intrinsics.
3. Cleaning up the original global variables and metadata.

This approach allows subsequent passes, like SPIRVEmitIntrinsics, to
correctly fold GEPs into a single OpAccessChain instruction.

The patch also includes a comprehensive set of lit tests to cover
various scenarios:
- Basic cbuffer access direct load and GEPs.
- Unused and partially unused cbuffers.

This implements the SPIR-V version of

https://github.com/llvm/wg-hlsl/blob/main/proposals/0016-constant-buffers.md#lowering-to-buffer-load-intrinsics.
2025-09-22 09:01:48 -04:00

23 lines
665 B
C++

//===- SPIRVCBufferAccess.h - Translate CBuffer Loads ----------*- C++ -*-===//
//
// 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
//
#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVCBUFFERACCESS_H_
#define LLVM_LIB_TARGET_SPIRV_SPIRVCBUFFERACCESS_H_
#include "llvm/IR/PassManager.h"
namespace llvm {
class SPIRVCBufferAccess : public PassInfoMixin<SPIRVCBufferAccess> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
} // namespace llvm
#endif // LLVM_LIB_TARGET_SPIRV_SPIRVCBUFFERACCESS_H_