1 | //===- VE.cpp -------------------------------------------------------------===// |
---|---|
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 | #include "ABIInfoImpl.h" |
10 | #include "TargetInfo.h" |
11 | |
12 | using namespace clang; |
13 | using namespace clang::CodeGen; |
14 | |
15 | //===----------------------------------------------------------------------===// |
16 | // VE ABI Implementation. |
17 | // |
18 | namespace { |
19 | class VEABIInfo : public DefaultABIInfo { |
20 | public: |
21 | VEABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {} |
22 | |
23 | private: |
24 | ABIArgInfo classifyReturnType(QualType RetTy) const; |
25 | ABIArgInfo classifyArgumentType(QualType RetTy) const; |
26 | void computeInfo(CGFunctionInfo &FI) const override; |
27 | }; |
28 | } // end anonymous namespace |
29 | |
30 | ABIArgInfo VEABIInfo::classifyReturnType(QualType Ty) const { |
31 | if (Ty->isAnyComplexType()) |
32 | return ABIArgInfo::getDirect(); |
33 | uint64_t Size = getContext().getTypeSize(T: Ty); |
34 | if (Size < 64 && Ty->isIntegerType()) |
35 | return ABIArgInfo::getExtend(Ty); |
36 | return DefaultABIInfo::classifyReturnType(RetTy: Ty); |
37 | } |
38 | |
39 | ABIArgInfo VEABIInfo::classifyArgumentType(QualType Ty) const { |
40 | if (Ty->isAnyComplexType()) |
41 | return ABIArgInfo::getDirect(); |
42 | uint64_t Size = getContext().getTypeSize(T: Ty); |
43 | if (Size < 64 && Ty->isIntegerType()) |
44 | return ABIArgInfo::getExtend(Ty); |
45 | return DefaultABIInfo::classifyArgumentType(RetTy: Ty); |
46 | } |
47 | |
48 | void VEABIInfo::computeInfo(CGFunctionInfo &FI) const { |
49 | FI.getReturnInfo() = classifyReturnType(Ty: FI.getReturnType()); |
50 | for (auto &Arg : FI.arguments()) |
51 | Arg.info = classifyArgumentType(Ty: Arg.type); |
52 | } |
53 | |
54 | namespace { |
55 | class VETargetCodeGenInfo : public TargetCodeGenInfo { |
56 | public: |
57 | VETargetCodeGenInfo(CodeGenTypes &CGT) |
58 | : TargetCodeGenInfo(std::make_unique<VEABIInfo>(args&: CGT)) {} |
59 | // VE ABI requires the arguments of variadic and prototype-less functions |
60 | // are passed in both registers and memory. |
61 | bool isNoProtoCallVariadic(const CallArgList &args, |
62 | const FunctionNoProtoType *fnType) const override { |
63 | return true; |
64 | } |
65 | }; |
66 | } // end anonymous namespace |
67 | |
68 | std::unique_ptr<TargetCodeGenInfo> |
69 | CodeGen::createVETargetCodeGenInfo(CodeGenModule &CGM) { |
70 | return std::make_unique<VETargetCodeGenInfo>(args&: CGM.getTypes()); |
71 | } |
72 |