clang 24.0.0git
CIRABIClassifierAArch64.cpp
Go to the documentation of this file.
1//===- CIRABIClassifierAArch64.cpp - AArch64 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 AArch64 classifier, which classifies with the LLVM
10// ABI Lowering Library's AArch64 target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CIRABIClassifier.h"
15
19#include "llvm/TargetParser/Triple.h"
20
21using namespace mlir;
22using namespace mlir::abi;
23using namespace cir;
24
25namespace {
26
27/// The AArch64 options the library classifies with, derived from \p modOp's
28/// attributes the way classic CodeGen derives them from the target and the
29/// language options. A module with no triple is classified as AAPCS64
30/// little-endian, and one with no source language as C.
31llvm::abi::AArch64ABIOptions getAArch64ABIOptions(mlir::ModuleOp modOp) {
32 llvm::Triple triple("aarch64-unknown-linux-gnu");
33 if (auto tripleAttr = modOp->getAttrOfType<mlir::StringAttr>(
34 cir::CIRDialect::getTripleAttrName()))
35 triple = llvm::Triple(tripleAttr.getValue());
36
37 llvm::StringRef abi;
38 if (auto abiAttr = modOp->getAttrOfType<mlir::StringAttr>(
39 cir::CIRDialect::getTargetABIAttrName()))
40 abi = abiAttr.getValue();
41
42 llvm::abi::AArch64ABIOptions opts;
43 if (abi == "darwinpcs")
44 opts.Kind = llvm::abi::AArch64ABIKind::DarwinPCS;
45 else if (triple.isOSWindows())
46 opts.Kind = llvm::abi::AArch64ABIKind::Win64;
47 else if (abi == "aapcs-soft")
48 opts.Kind = llvm::abi::AArch64ABIKind::AAPCSSoft;
49 else
50 opts.Kind = llvm::abi::AArch64ABIKind::AAPCS;
51
52 auto lang = modOp->getAttrOfType<cir::SourceLanguageAttr>(
53 cir::CIRDialect::getSourceLanguageAttrName());
54 opts.IsCXX = lang && (lang.isCXX() || lang.isOpenCLCXX());
55
56 opts.IsILP32 = triple.getArch() == llvm::Triple::aarch64_32;
57 opts.IsMachO = triple.isOSBinFormatMachO();
58 opts.IsAndroidOrOHOS = triple.isAndroid() || triple.isOHOSFamily();
59 opts.IsWindowsArm64EC = triple.isWindowsArm64EC();
60 if (auto cxxABIAttr = modOp->getAttrOfType<mlir::StringAttr>(
61 cir::CIRDialect::getCXXABIAttrName()))
62 opts.IsMicrosoftCXXABI =
63 clang::TargetCXXABI::getKind(cxxABIAttr.getValue()) ==
64 clang::TargetCXXABI::Microsoft;
65 else
66 opts.IsMicrosoftCXXABI = triple.isWindowsMSVCEnvironment();
67 opts.IsBigEndian = !triple.isLittleEndian();
68
69 auto compat = clang::LangOptions::ClangABI::Latest;
70 if (auto loweringOpts = modOp->getAttrOfType<cir::LoweringOptionsAttr>(
71 cir::CIRDialect::getLoweringOptionsAttrName()))
72 compat = static_cast<clang::LangOptions::ClangABI>(
73 loweringOpts.getClangAbiCompat());
74 opts.CompatInfo.IsMatrixHA = compat > clang::LangOptions::ClangABI::Ver23;
75 return opts;
76}
77
78class AArch64ABIClassifier final : public CIRABIClassifierCommon {
79public:
80 AArch64ABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp)
81 : CIRABIClassifierCommon(dl, modOp),
82 targetInfo(llvm::abi::createAArch64TargetInfo(
83 typeMapper.getTypeBuilder(), getAArch64ABIOptions(modOp))) {}
84
85 /// The AArch64 `va_list` and the expansion of `cir.va_arg` through it are
86 /// not implemented yet.
87 mlir::FailureOr<ArgClassification>
88 classifyVAArg(cir::VAArgOp vaArg) override {
89 vaArg->emitOpError()
90 << "not yet implemented in CallConvLowering for AArch64";
91 return mlir::failure();
92 }
93
94protected:
95 /// AArch64 has no per-function features that change the classification,
96 /// so every function shares the module's classifier.
97 const llvm::abi::TargetInfo &getTargetInfo(cir::FuncOp) override {
98 return *targetInfo;
99 }
100
101private:
102 std::unique_ptr<llvm::abi::TargetInfo> targetInfo;
103};
104
105} // namespace
106
107std::unique_ptr<CIRABIClassifier>
108cir::createAArch64ABIClassifier(const mlir::DataLayout &dl,
109 mlir::ModuleOp modOp) {
110 return std::make_unique<AArch64ABIClassifier>(dl, modOp);
111}
Defines the clang::LangOptions interface.
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting.
Classifies through the LLVM ABI Lowering Library.
ClangABI
Clang versions with different platform ABI conformance.
Kind getKind() const
std::unique_ptr< CIRABIClassifier > createAArch64ABIClassifier(const mlir::DataLayout &dl, mlir::ModuleOp modOp)
The AArch64 classifier, covering AAPCS64 and DarwinPCS.