clang 19.0.0git
PNaCl.cpp
Go to the documentation of this file.
1//===- PNaCl.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
12using namespace clang;
13using namespace clang::CodeGen;
14
15//===----------------------------------------------------------------------===//
16// le32/PNaCl bitcode ABI Implementation
17//
18// This is a simplified version of the x86_32 ABI. Arguments and return values
19// are always passed on the stack.
20//===----------------------------------------------------------------------===//
21
22class PNaClABIInfo : public ABIInfo {
23 public:
25
28
29 void computeInfo(CGFunctionInfo &FI) const override;
31 Address VAListAddr, QualType Ty) const override;
32};
33
35 public:
37 : TargetCodeGenInfo(std::make_unique<PNaClABIInfo>(CGT)) {}
38};
39
43
44 for (auto &I : FI.arguments())
45 I.info = classifyArgumentType(I.type);
46}
47
49 QualType Ty) const {
50 // The PNaCL ABI is a bit odd, in that varargs don't use normal
51 // function classification. Structs get passed directly for varargs
52 // functions, through a rewriting transform in
53 // pnacl-llvm/lib/Transforms/NaCl/ExpandVarArgs.cpp, which allows
54 // this target to actually support a va_arg instructions with an
55 // aggregate type, unlike other targets.
56 return EmitVAArgInstr(CGF, VAListAddr, Ty, ABIArgInfo::getDirect());
57}
58
59/// Classify argument of given type \p Ty.
61 if (isAggregateTypeForABI(Ty)) {
64 return getNaturalAlignIndirect(Ty);
65 } else if (const EnumType *EnumTy = Ty->getAs<EnumType>()) {
66 // Treat an enum type as its underlying type.
67 Ty = EnumTy->getDecl()->getIntegerType();
68 } else if (Ty->isFloatingType()) {
69 // Floating-point types don't go inreg.
70 return ABIArgInfo::getDirect();
71 } else if (const auto *EIT = Ty->getAs<BitIntType>()) {
72 // Treat bit-precise integers as integers if <= 64, otherwise pass
73 // indirectly.
74 if (EIT->getNumBits() > 64)
75 return getNaturalAlignIndirect(Ty);
76 return ABIArgInfo::getDirect();
77 }
78
81}
82
84 if (RetTy->isVoidType())
85 return ABIArgInfo::getIgnore();
86
87 // In the PNaCl ABI we always return records/structures on the stack.
88 if (isAggregateTypeForABI(RetTy))
89 return getNaturalAlignIndirect(RetTy);
90
91 // Treat bit-precise integers as integers if <= 64, otherwise pass indirectly.
92 if (const auto *EIT = RetTy->getAs<BitIntType>()) {
93 if (EIT->getNumBits() > 64)
94 return getNaturalAlignIndirect(RetTy);
95 return ABIArgInfo::getDirect();
96 }
97
98 // Treat an enum type as its underlying type.
99 if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
100 RetTy = EnumTy->getDecl()->getIntegerType();
101
104}
105
106std::unique_ptr<TargetCodeGenInfo>
108 return std::make_unique<PNaClTargetCodeGenInfo>(CGM.getTypes());
109}
void computeInfo(CGFunctionInfo &FI) const override
Definition: PNaCl.cpp:40
PNaClABIInfo(CodeGen::CodeGenTypes &CGT)
Definition: PNaCl.cpp:24
ABIArgInfo classifyReturnType(QualType RetTy) const
Definition: PNaCl.cpp:83
Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty) const override
EmitVAArg - Emit the target dependent code to load a value of.
Definition: PNaCl.cpp:48
ABIArgInfo classifyArgumentType(QualType RetTy) const
Classify argument of given type Ty.
Definition: PNaCl.cpp:60
PNaClTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
Definition: PNaCl.cpp:36
A fixed int type of a specified bitwidth.
Definition: Type.h:7242
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static ABIArgInfo getIgnore()
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
static ABIArgInfo getExtend(QualType Ty, llvm::Type *T=nullptr)
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
Definition: ABIInfo.h:45
CodeGen::CodeGenTypes & CGT
Definition: ABIInfo.h:47
CodeGen::CGCXXABI & getCXXABI() const
Definition: ABIInfo.cpp:18
bool isPromotableIntegerTypeForABI(QualType Ty) const
Definition: ABIInfo.cpp:163
CodeGen::ABIArgInfo getNaturalAlignIndirect(QualType Ty, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr) const
A convenience method to return an indirect ABIArgInfo with an expected alignment equal to the ABI ali...
Definition: ABIInfo.cpp:174
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition: Address.h:111
RecordArgABI
Specify how one should pass an argument of a record type.
Definition: CGCXXABI.h:150
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
Definition: CGCXXABI.h:158
CGFunctionInfo - Class to encapsulate the information about a function definition.
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:46
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5575
A (possibly-)qualified type.
Definition: Type.h:940
bool isVoidType() const
Definition: Type.h:7905
bool isFloatingType() const
Definition: Type.cpp:2237
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8123
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, const ABIArgInfo &AI)
bool isAggregateTypeForABI(QualType T)
std::unique_ptr< TargetCodeGenInfo > createPNaClTargetCodeGenInfo(CodeGenModule &CGM)
Definition: PNaCl.cpp:107
The JSON file list parser is used to communicate input to InstallAPI.
Definition: Format.h:5394