clang 24.0.0git
CIRABIClassifierSPIRV.cpp
Go to the documentation of this file.
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"
16
18
19using namespace mlir;
20using namespace mlir::abi;
21using namespace cir;
22
23namespace {
24
25class SPIRVABIClassifier final : public CIRABIClassifierCommon {
26public:
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
37protected:
38 /// SPIR-V has no per-function feature that changes its ABI rules.
39 const llvm::abi::TargetInfo &getTargetInfo(cir::FuncOp) override;
40
41private:
42 std::unique_ptr<llvm::abi::TargetInfo> target;
43};
44
45const 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 =
50 assert(lowerModule && "LowerModule shouldn't be null");
51 unsigned defaultAddrSpace =
52 lowerModule->hasTarget()
53 ? lowerModule->getTarget().getTargetAddressSpace(
55 : 0;
56
57 target = llvm::abi::createSPIRVTargetInfo(
58 typeMapper.getTypeBuilder(), defaultAddrSpace,
59 /*KernelPassAggregatesIndirect=*/
60 lowerModule->getLangOpts().isTargetDevice());
61 }
62 return *target;
63}
64
65} // namespace
66
67std::unique_ptr<CIRABIClassifier>
68cir::createSPIRVABIClassifier(const mlir::DataLayout &dl,
69 mlir::ModuleOp modOp) {
70 return std::make_unique<SPIRVABIClassifier>(dl, modOp);
71}
Classifies through the LLVM ABI Lowering Library.
std::unique_ptr< CIRABIClassifier > createSPIRVABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp)
The SPIR-V classifier.
std::unique_ptr< LowerModule > createLowerModule(mlir::ModuleOp module)