clang 20.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;
30 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
31 AggValueSlot Slot) 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, AggValueSlot Slot) 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 CGF.EmitLoadOfAnyValue(
58 EmitVAArgInstr(CGF, VAListAddr, Ty, ABIArgInfo::getDirect()), Ty),
59 Slot);
60}
61
62/// Classify argument of given type \p Ty.
64 if (isAggregateTypeForABI(Ty)) {
67 return getNaturalAlignIndirect(Ty);
68 } else if (const EnumType *EnumTy = Ty->getAs<EnumType>()) {
69 // Treat an enum type as its underlying type.
70 Ty = EnumTy->getDecl()->getIntegerType();
71 } else if (Ty->isFloatingType()) {
72 // Floating-point types don't go inreg.
73 return ABIArgInfo::getDirect();
74 } else if (const auto *EIT = Ty->getAs<BitIntType>()) {
75 // Treat bit-precise integers as integers if <= 64, otherwise pass
76 // indirectly.
77 if (EIT->getNumBits() > 64)
78 return getNaturalAlignIndirect(Ty);
79 return ABIArgInfo::getDirect();
80 }
81
84}
85
87 if (RetTy->isVoidType())
88 return ABIArgInfo::getIgnore();
89
90 // In the PNaCl ABI we always return records/structures on the stack.
91 if (isAggregateTypeForABI(RetTy))
92 return getNaturalAlignIndirect(RetTy);
93
94 // Treat bit-precise integers as integers if <= 64, otherwise pass indirectly.
95 if (const auto *EIT = RetTy->getAs<BitIntType>()) {
96 if (EIT->getNumBits() > 64)
97 return getNaturalAlignIndirect(RetTy);
98 return ABIArgInfo::getDirect();
99 }
100
101 // Treat an enum type as its underlying type.
102 if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
103 RetTy = EnumTy->getDecl()->getIntegerType();
104
107}
108
109std::unique_ptr<TargetCodeGenInfo>
111 return std::make_unique<PNaClTargetCodeGenInfo>(CGM.getTypes());
112}
RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const override
EmitVAArg - Emit the target dependent code to load a value of.
Definition: PNaCl.cpp:48
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:86
ABIArgInfo classifyArgumentType(QualType RetTy) const
Classify argument of given type Ty.
Definition: PNaCl.cpp:63
PNaClTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
Definition: PNaCl.cpp:36
A fixed int type of a specified bitwidth.
Definition: Type.h:7633
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:47
CodeGen::CodeGenTypes & CGT
Definition: ABIInfo.h:49
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:128
An aggregate value slot.
Definition: CGValue.h:504
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...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})
Like EmitLoadOfLValue but also handles complex and aggregate types.
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
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:42
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:47
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5991
A (possibly-)qualified type.
Definition: Type.h:941
bool isVoidType() const
Definition: Type.h:8319
bool isFloatingType() const
Definition: Type.cpp:2249
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8540
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:110
The JSON file list parser is used to communicate input to InstallAPI.