[Clang][CodeGen] Fix type for atomic float incdec operators (#107075)
[llvm-project.git] / clang / lib / CodeGen / ABIInfo.h
blobb8a8de57e5b971af5d0a1531d25e8cd681a0ce38
1 //===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
10 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
12 #include "clang/AST/Attr.h"
13 #include "clang/AST/CharUnits.h"
14 #include "clang/AST/Type.h"
15 #include "llvm/IR/CallingConv.h"
16 #include "llvm/IR/Type.h"
18 namespace llvm {
19 class Value;
20 class LLVMContext;
21 class DataLayout;
22 class Type;
23 } // namespace llvm
25 namespace clang {
26 class ASTContext;
27 class CodeGenOptions;
28 class TargetInfo;
30 namespace CodeGen {
31 class ABIArgInfo;
32 class Address;
33 class CGCXXABI;
34 class CGFunctionInfo;
35 class CodeGenFunction;
36 class CodeGenTypes;
37 class RValue;
38 class AggValueSlot;
40 // FIXME: All of this stuff should be part of the target interface
41 // somehow. It is currently here because it is not clear how to factor
42 // the targets to support this, since the Targets currently live in a
43 // layer below types n'stuff.
45 /// ABIInfo - Target specific hooks for defining how a type should be
46 /// passed or returned from functions.
47 class ABIInfo {
48 protected:
49 CodeGen::CodeGenTypes &CGT;
50 llvm::CallingConv::ID RuntimeCC;
52 public:
53 ABIInfo(CodeGen::CodeGenTypes &cgt)
54 : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
56 virtual ~ABIInfo();
58 virtual bool allowBFloatArgsAndRet() const { return false; }
60 CodeGen::CGCXXABI &getCXXABI() const;
61 ASTContext &getContext() const;
62 llvm::LLVMContext &getVMContext() const;
63 const llvm::DataLayout &getDataLayout() const;
64 const TargetInfo &getTarget() const;
65 const CodeGenOptions &getCodeGenOpts() const;
67 /// Return the calling convention to use for system runtime
68 /// functions.
69 llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
71 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
73 /// EmitVAArg - Emit the target dependent code to load a value of
74 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
76 // FIXME: This is a gaping layering violation if we wanted to drop
77 // the ABI information any lower than CodeGen. Of course, for
78 // VAArg handling it has to be at this level; there is no way to
79 // abstract this out.
80 virtual RValue EmitVAArg(CodeGen::CodeGenFunction &CGF,
81 CodeGen::Address VAListAddr, QualType Ty,
82 AggValueSlot Slot) const = 0;
84 bool isAndroid() const;
85 bool isOHOSFamily() const;
87 /// Emit the target dependent code to load a value of
88 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
89 virtual RValue EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
90 CodeGen::Address VAListAddr, QualType Ty,
91 AggValueSlot Slot) const;
93 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
95 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
96 uint64_t Members) const;
97 virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const;
99 /// isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous
100 /// aggregate. Base is set to the base element type, and Members is set
101 /// to the number of base elements.
102 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
103 uint64_t &Members) const;
105 // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
106 // only difference is that this considers bit-precise integer types as well.
107 bool isPromotableIntegerTypeForABI(QualType Ty) const;
109 /// A convenience method to return an indirect ABIArgInfo with an
110 /// expected alignment equal to the ABI alignment of the given type.
111 CodeGen::ABIArgInfo
112 getNaturalAlignIndirect(QualType Ty, bool ByVal = true, bool Realign = false,
113 llvm::Type *Padding = nullptr) const;
115 CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty,
116 bool Realign = false) const;
118 virtual void appendAttributeMangling(TargetAttr *Attr,
119 raw_ostream &Out) const;
120 virtual void appendAttributeMangling(TargetVersionAttr *Attr,
121 raw_ostream &Out) const;
122 virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
123 raw_ostream &Out) const;
124 virtual void appendAttributeMangling(StringRef AttrStr,
125 raw_ostream &Out) const;
128 /// Target specific hooks for defining how a type should be passed or returned
129 /// from functions with one of the Swift calling conventions.
130 class SwiftABIInfo {
131 protected:
132 CodeGenTypes &CGT;
133 bool SwiftErrorInRegister;
135 bool occupiesMoreThan(ArrayRef<llvm::Type *> scalarTypes,
136 unsigned maxAllRegisters) const;
138 public:
139 SwiftABIInfo(CodeGen::CodeGenTypes &CGT, bool SwiftErrorInRegister)
140 : CGT(CGT), SwiftErrorInRegister(SwiftErrorInRegister) {}
142 virtual ~SwiftABIInfo();
144 /// Returns true if an aggregate which expands to the given type sequence
145 /// should be passed / returned indirectly.
146 virtual bool shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,
147 bool AsReturnValue) const;
149 /// Returns true if the given vector type is legal from Swift's calling
150 /// convention perspective.
151 virtual bool isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
152 unsigned NumElts) const;
154 /// Returns true if swifterror is lowered to a register by the target ABI.
155 bool isSwiftErrorInRegister() const { return SwiftErrorInRegister; };
157 } // end namespace CodeGen
158 } // end namespace clang
160 #endif