clang  15.0.0git
ABIInfo.h
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
10 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
11 
12 #include "clang/AST/CharUnits.h"
13 #include "clang/AST/Type.h"
14 #include "llvm/IR/CallingConv.h"
15 #include "llvm/IR/Type.h"
16 
17 namespace llvm {
18  class Value;
19  class LLVMContext;
20  class DataLayout;
21  class Type;
22 }
23 
24 namespace clang {
25  class ASTContext;
26  class CodeGenOptions;
27  class TargetInfo;
28 
29 namespace CodeGen {
30  class ABIArgInfo;
31  class Address;
32  class CGCXXABI;
33  class CGFunctionInfo;
34  class CodeGenFunction;
35  class CodeGenTypes;
36  class SwiftABIInfo;
37 
38 namespace swiftcall {
39  class SwiftAggLowering;
40 }
41 
42  // FIXME: All of this stuff should be part of the target interface
43  // somehow. It is currently here because it is not clear how to factor
44  // the targets to support this, since the Targets currently live in a
45  // layer below types n'stuff.
46 
47 
48  /// ABIInfo - Target specific hooks for defining how a type should be
49  /// passed or returned from functions.
50  class ABIInfo {
51  public:
53  protected:
55  public:
57  : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
58 
59  virtual ~ABIInfo();
60 
61  virtual bool supportsSwift() const { return false; }
62 
63  virtual bool allowBFloatArgsAndRet() const { return false; }
64 
66  ASTContext &getContext() const;
67  llvm::LLVMContext &getVMContext() const;
68  const llvm::DataLayout &getDataLayout() const;
69  const TargetInfo &getTarget() const;
70  const CodeGenOptions &getCodeGenOpts() const;
71 
72  /// Return the calling convention to use for system runtime
73  /// functions.
75  return RuntimeCC;
76  }
77 
78  virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
79 
80  /// EmitVAArg - Emit the target dependent code to load a value of
81  /// \arg Ty from the va_list pointed to by \arg VAListAddr.
82 
83  // FIXME: This is a gaping layering violation if we wanted to drop
84  // the ABI information any lower than CodeGen. Of course, for
85  // VAArg handling it has to be at this level; there is no way to
86  // abstract this out.
88  CodeGen::Address VAListAddr,
89  QualType Ty) const = 0;
90 
91  bool isAndroid() const;
92 
93  /// Emit the target dependent code to load a value of
94  /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
96  CodeGen::Address VAListAddr,
97  QualType Ty) const;
98 
99  virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
100 
101  virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
102  uint64_t Members) const;
104 
105  bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
106  uint64_t &Members) const;
107 
108  // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
109  // only difference is that this considers bit-precise integer types as well.
111 
112  /// A convenience method to return an indirect ABIArgInfo with an
113  /// expected alignment equal to the ABI alignment of the given type.
115  getNaturalAlignIndirect(QualType Ty, bool ByVal = true,
116  bool Realign = false,
117  llvm::Type *Padding = nullptr) const;
118 
120  getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
121 
122 
123  };
124 
125  /// A refining implementation of ABIInfo for targets that support swiftcall.
126  ///
127  /// If we find ourselves wanting multiple such refinements, they'll probably
128  /// be independent refinements, and we should probably find another way
129  /// to do it than simple inheritance.
130  class SwiftABIInfo : public ABIInfo {
131  public:
133 
134  bool supportsSwift() const final override { return true; }
135 
137  bool asReturnValue) const = 0;
138 
139  virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
140  llvm::Type *eltTy,
141  unsigned elts) const;
142 
143  virtual bool isSwiftErrorInRegister() const = 0;
144 
145  static bool classof(const ABIInfo *info) {
146  return info->supportsSwift();
147  }
148  };
149 } // end namespace CodeGen
150 } // end namespace clang
151 
152 #endif
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::CodeGen::SwiftABIInfo
A refining implementation of ABIInfo for targets that support swiftcall.
Definition: ABIInfo.h:130
clang::CodeGen::ABIInfo::getRuntimeCC
llvm::CallingConv::ID getRuntimeCC() const
Return the calling convention to use for system runtime functions.
Definition: ABIInfo.h:74
clang::CodeGen::ABIInfo::getNaturalAlignIndirect
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: TargetInfo.cpp:86
clang::CodeGen::SwiftABIInfo::shouldPassIndirectlyForSwift
virtual bool shouldPassIndirectlyForSwift(ArrayRef< llvm::Type * > types, bool asReturnValue) const =0
clang::CodeGen::ABIInfo::ABIInfo
ABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:56
clang::CodeGen::ABIInfo::~ABIInfo
virtual ~ABIInfo()
Definition: TargetInfo.cpp:120
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:731
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:190
clang::CodeGen::ABIInfo::isHomogeneousAggregateBaseType
virtual bool isHomogeneousAggregateBaseType(QualType Ty) const
Definition: TargetInfo.cpp:234
clang::CodeGen::ABIInfo::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: TargetInfo.cpp:228
clang::CodeGen::ABIInfo::getContext
ASTContext & getContext() const
Definition: TargetInfo.cpp:212
clang::CodeGen::ABIInfo::isZeroLengthBitfieldPermittedInHomogeneousAggregate
virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const
Definition: TargetInfo.cpp:243
clang::CodeGen::SwiftABIInfo::isLegalVectorTypeForSwift
virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, llvm::Type *eltTy, unsigned elts) const
Definition: TargetInfo.cpp:154
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1556
uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:24
clang::CodeGen::ABIArgInfo
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
Definition: CGFunctionInfo.h:32
clang::CodeGen::ABIInfo::isHomogeneousAggregate
bool isHomogeneousAggregate(QualType Ty, const Type *&Base, uint64_t &Members) const
isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous aggregate.
Definition: TargetInfo.cpp:5174
clang::CodeGen::ABIInfo::supportsSwift
virtual bool supportsSwift() const
Definition: ABIInfo.h:61
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:208
clang::CodeGen::ABIInfo::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: TargetInfo.cpp:220
Type.h
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:263
clang::CodeGen::Address
An aligned address.
Definition: Address.h:74
Base
clang::CodeGen::SwiftABIInfo::supportsSwift
bool supportsSwift() const final override
Definition: ABIInfo.h:134
clang::CodeGenOptions
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
Definition: CodeGenOptions.h:49
clang::CodeGen::ABIInfo::RuntimeCC
llvm::CallingConv::ID RuntimeCC
Definition: ABIInfo.h:54
CharUnits.h
clang::CodeGen::ABIInfo::computeInfo
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const =0
clang::CodeGen::ABIInfo::EmitVAArg
virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty) const =0
EmitVAArg - Emit the target dependent code to load a value of.
clang::CodeGen::SwiftABIInfo::SwiftABIInfo
SwiftABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:132
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:231
llvm::ArrayRef
Definition: LLVM.h:34
Value
Value
Definition: UninitializedValues.cpp:102
clang::CodeGen::ABIInfo::getVMContext
llvm::LLVMContext & getVMContext() const
Definition: TargetInfo.cpp:216
clang::CodeGen::CodeGenTypes
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
clang::CodeGen::ABIInfo::getTarget
const TargetInfo & getTarget() const
Definition: TargetInfo.cpp:224
clang::CodeGen::ABIInfo::allowBFloatArgsAndRet
virtual bool allowBFloatArgsAndRet() const
Definition: ABIInfo.h:63
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
clang::driver::types
Definition: Types.h:22
clang::CodeGen::ABIInfo::getNaturalAlignIndirectInReg
CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty, bool Realign=false) const
Definition: TargetInfo.cpp:94
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang
Definition: CalledOnceCheck.h:17
clang::CodeGen::ABIInfo::isPromotableIntegerTypeForABI
bool isPromotableIntegerTypeForABI(QualType Ty) const
Definition: TargetInfo.cpp:109
clang::CodeGen::ABIInfo::isAndroid
bool isAndroid() const
Definition: TargetInfo.cpp:232
clang::CodeGen::SwiftABIInfo::isSwiftErrorInRegister
virtual bool isSwiftErrorInRegister() const =0
clang::CodeGen::ABIInfo::CGT
CodeGen::CodeGenTypes & CGT
Definition: ABIInfo.h:52
clang::CodeGen::ABIInfo::getCXXABI
CodeGen::CGCXXABI & getCXXABI() const
Definition: TargetInfo.cpp:208
clang::CodeGen::SwiftABIInfo::classof
static bool classof(const ABIInfo *info)
Definition: ABIInfo.h:145
clang::CodeGen::CGCXXABI
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:43
clang::CodeGen::ABIInfo::EmitMSVAArg
virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty) const
Emit the target dependent code to load a value of.
Definition: TargetInfo.cpp:99
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::CodeGen::ABIInfo
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
Definition: ABIInfo.h:50
clang::CodeGen::ABIInfo::isHomogeneousAggregateSmallEnough
virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, uint64_t Members) const
Definition: TargetInfo.cpp:238
Type
MatchType Type
Definition: ASTMatchFinder.cpp:71