| 1 | //===- CIRABIClassifierSPIRV.cpp - SPIR-V 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 SPIR-V classifier, which classifies with the LLVM |
| 10 | // ABI Lowering Library's SPIR-V target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CIRABIClassifier.h" |
| 15 | #include "TargetLowering/LowerModule.h" |
| 16 | |
| 17 | #include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 18 | |
| 19 | using namespace mlir; |
| 20 | using namespace mlir::abi; |
| 21 | using namespace cir; |
| 22 | |
| 23 | namespace { |
| 24 | |
| 25 | class SPIRVABIClassifier final : public CIRABIClassifierCommon { |
| 26 | public: |
| 27 | SPIRVABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp) |
| 28 | : CIRABIClassifierCommon(dl, modOp) {} |
| 29 | |
| 30 | mlir::FailureOr<ArgClassification> |
| 31 | classifyVAArg(cir::VAArgOp vaArg) override { |
| 32 | vaArg->emitOpError() |
| 33 | << "not yet implemented in CallConvLowering for SPIR-V"; |
| 34 | return mlir::failure(); |
| 35 | } |
| 36 | |
| 37 | protected: |
| 38 | /// SPIR-V has no per-function feature that changes its ABI rules. |
| 39 | const llvm::abi::TargetInfo &getTargetInfo(cir::FuncOp) override; |
| 40 | |
| 41 | private: |
| 42 | std::unique_ptr<llvm::abi::TargetInfo> target; |
| 43 | }; |
| 44 | |
| 45 | const llvm::abi::TargetInfo &SPIRVABIClassifier::getTargetInfo(cir::FuncOp) { |
| 46 | if (!target) { |
| 47 | // Without cir.triple there is no target, so use 0 as default address space. |
| 48 | std::unique_ptr<cir::LowerModule> lowerModule = |
| 49 | cir::createLowerModule(module: modOp); |
| 50 | assert(lowerModule && "LowerModule shouldn't be null"); |
| 51 | unsigned defaultAddrSpace = |
| 52 | lowerModule->hasTarget() |
| 53 | ? lowerModule->getTarget().getTargetAddressSpace( |
| 54 | AS: clang::LangAS::Default) |
| 55 | : 0; |
| 56 | |
| 57 | target = llvm::abi::createSPIRVTargetInfo( |
| 58 | TB&: typeMapper.getTypeBuilder(), DefaultAddrSpace: defaultAddrSpace, |
| 59 | /*KernelPassAggregatesIndirect=*/ |
| 60 | lowerModule->getLangOpts().isTargetDevice()); |
| 61 | } |
| 62 | return *target; |
| 63 | } |
| 64 | |
| 65 | } // namespace |
| 66 | |
| 67 | std::unique_ptr<CIRABIClassifier> |
| 68 | cir::createSPIRVABIClassifier(const mlir::DataLayout &dl, |
| 69 | mlir::ModuleOp modOp) { |
| 70 | return std::make_unique<SPIRVABIClassifier>(args: dl, args&: modOp); |
| 71 | } |
| 72 |