clang 24.0.0git
CIRABIClassifierAMDGPU.cpp
Go to the documentation of this file.
1//===- CIRABIClassifierAMDGPU.cpp - AMDGPU classification -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the AMDGPU classifier, which classifies with the LLVM
10// ABI Lowering Library's AMDGPU target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CIRABIClassifier.h"
15
17
18using namespace mlir;
19using namespace mlir::abi;
20using namespace cir;
21
22namespace {
23
24class AMDGPUABIClassifier final : public CIRABIClassifierCommon {
25public:
26 AMDGPUABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp)
27 : CIRABIClassifierCommon(dl, modOp) {}
28
29 /// Each variadic argument is read in place from its own 4-byte slot.
30 mlir::FailureOr<ArgClassification> classifyVAArg(cir::VAArgOp) override {
31 return ArgClassification::getDirect(/*coerced=*/nullptr, /*offset=*/0,
32 llvm::Align(4));
33 }
34
35protected:
36 /// AMDGPU has no per-function feature that changes its ABI rules.
37 const llvm::abi::TargetInfo &getTargetInfo(cir::FuncOp) override;
38
39private:
40 std::unique_ptr<llvm::abi::TargetInfo> target;
41};
42
43const llvm::abi::TargetInfo &AMDGPUABIClassifier::getTargetInfo(cir::FuncOp) {
44 if (!target) {
45 // HIP passes a generic pointer kernel argument as a global one.
46 auto langOpts = modOp->getAttrOfType<cir::LoweringOptionsAttr>(
47 cir::CIRDialect::getLoweringOptionsAttrName());
48 llvm::abi::AMDGPUABIOptions opts;
49 opts.CoerceGenericPtrArgToGlobal = langOpts && langOpts.getHip();
50 target =
51 llvm::abi::createAMDGPUTargetInfo(typeMapper.getTypeBuilder(), opts);
52 }
53 return *target;
54}
55
56} // namespace
57
58std::unique_ptr<CIRABIClassifier>
59cir::createAMDGPUABIClassifier(const mlir::DataLayout &dl,
60 mlir::ModuleOp modOp) {
61 return std::make_unique<AMDGPUABIClassifier>(dl, modOp);
62}
Classifies through the LLVM ABI Lowering Library.
std::unique_ptr< CIRABIClassifier > createAMDGPUABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp)
The AMDGPU classifier.