| 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 | |
| 16 | #include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 17 | |
| 18 | using namespace mlir; |
| 19 | using namespace mlir::abi; |
| 20 | using namespace cir; |
| 21 | |
| 22 | namespace { |
| 23 | |
| 24 | class AMDGPUABIClassifier final : public CIRABIClassifierCommon { |
| 25 | public: |
| 26 | AMDGPUABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp) |
| 27 | : CIRABIClassifierCommon(dl, modOp) {} |
| 28 | |
| 29 | mlir::FailureOr<ArgClassification> |
| 30 | classifyVAArg(cir::VAArgOp vaArg) override { |
| 31 | vaArg->emitOpError() |
| 32 | << "not yet implemented in CallConvLowering for AMDGPU"; |
| 33 | return mlir::failure(); |
| 34 | } |
| 35 | |
| 36 | protected: |
| 37 | /// AMDGPU has no per-function feature that changes its ABI rules. |
| 38 | const llvm::abi::TargetInfo &getTargetInfo(cir::FuncOp) override; |
| 39 | |
| 40 | private: |
| 41 | std::unique_ptr<llvm::abi::TargetInfo> target; |
| 42 | }; |
| 43 | |
| 44 | const llvm::abi::TargetInfo &AMDGPUABIClassifier::getTargetInfo(cir::FuncOp) { |
| 45 | if (!target) { |
| 46 | // HIP passes a generic pointer kernel argument as a global one. |
| 47 | auto langOpts = modOp->getAttrOfType<cir::LoweringOptionsAttr>( |
| 48 | name: cir::CIRDialect::getLoweringOptionsAttrName()); |
| 49 | target = llvm::abi::createAMDGPUTargetInfo( |
| 50 | TB&: typeMapper.getTypeBuilder(), |
| 51 | /*CoerceGenericPtrArgToGlobal=*/langOpts && langOpts.getHip()); |
| 52 | } |
| 53 | return *target; |
| 54 | } |
| 55 | |
| 56 | } // namespace |
| 57 | |
| 58 | std::unique_ptr<CIRABIClassifier> |
| 59 | cir::createAMDGPUABIClassifier(const mlir::DataLayout &dl, |
| 60 | mlir::ModuleOp modOp) { |
| 61 | return std::make_unique<AMDGPUABIClassifier>(args: dl, args&: modOp); |
| 62 | } |
| 63 |