clang  14.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;
103 
104  bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
105  uint64_t &Members) const;
106 
107  // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
108  // only difference is that this considers _ExtInt as well.
110 
111  /// A convenience method to return an indirect ABIArgInfo with an
112  /// expected alignment equal to the ABI alignment of the given type.
114  getNaturalAlignIndirect(QualType Ty, bool ByVal = true,
115  bool Realign = false,
116  llvm::Type *Padding = nullptr) const;
117 
119  getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
120 
121 
122  };
123 
124  /// A refining implementation of ABIInfo for targets that support swiftcall.
125  ///
126  /// If we find ourselves wanting multiple such refinements, they'll probably
127  /// be independent refinements, and we should probably find another way
128  /// to do it than simple inheritance.
129  class SwiftABIInfo : public ABIInfo {
130  public:
132 
133  bool supportsSwift() const final override { return true; }
134 
136  bool asReturnValue) const = 0;
137 
138  virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
139  llvm::Type *eltTy,
140  unsigned elts) const;
141 
142  virtual bool isSwiftErrorInRegister() const = 0;
143 
144  static bool classof(const ABIInfo *info) {
145  return info->supportsSwift();
146  }
147  };
148 } // end namespace CodeGen
149 } // end namespace clang
150 
151 #endif
llvm
Definition: Dominators.h:30
clang::CodeGen::SwiftABIInfo
A refining implementation of ABIInfo for targets that support swiftcall.
Definition: ABIInfo.h:129
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:85
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:114
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::CodeGen::ABIInfo::isHomogeneousAggregateBaseType
virtual bool isHomogeneousAggregateBaseType(QualType Ty) const
Definition: TargetInfo.cpp:228
clang::CodeGen::ABIInfo::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: TargetInfo.cpp:222
clang::CodeGen::ABIInfo::getContext
ASTContext & getContext() const
Definition: TargetInfo.cpp:206
clang::CodeGen::SwiftABIInfo::isLegalVectorTypeForSwift
virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, llvm::Type *eltTy, unsigned elts) const
Definition: TargetInfo.cpp:148
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
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:5134
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:212
clang::CodeGen::ABIInfo::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: TargetInfo.cpp:214
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:24
Base
clang::CodeGen::SwiftABIInfo::supportsSwift
bool supportsSwift() const final override
Definition: ABIInfo.h:133
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:131
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:235
llvm::ArrayRef
Definition: LLVM.h:34
Value
Value
Definition: UninitializedValues.cpp:102
clang::CodeGen::ABIInfo::getVMContext
llvm::LLVMContext & getVMContext() const
Definition: TargetInfo.cpp:210
clang::CodeGen::CodeGenTypes
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:59
clang::CodeGen::ABIInfo::getTarget
const TargetInfo & getTarget() const
Definition: TargetInfo.cpp:218
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:93
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang
Definition: CalledOnceCheck.h:17
clang::CodeGen::ABIInfo::isPromotableIntegerTypeForABI
bool isPromotableIntegerTypeForABI(QualType Ty) const
Definition: TargetInfo.cpp:103
clang::CodeGen::ABIInfo::isAndroid
bool isAndroid() const
Definition: TargetInfo.cpp:226
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:202
clang::CodeGen::SwiftABIInfo::classof
static bool classof(const ABIInfo *info)
Definition: ABIInfo.h:144
clang::CodeGen::CGCXXABI
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:44
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:98
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:232
Type
MatchType Type
Definition: ASTMatchFinder.cpp:70