clang  10.0.0svn
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  CodeGen::CGCXXABI &getCXXABI() const;
64  ASTContext &getContext() const;
65  llvm::LLVMContext &getVMContext() const;
66  const llvm::DataLayout &getDataLayout() const;
67  const TargetInfo &getTarget() const;
68  const CodeGenOptions &getCodeGenOpts() const;
69 
70  /// Return the calling convention to use for system runtime
71  /// functions.
73  return RuntimeCC;
74  }
75 
76  virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
77 
78  /// EmitVAArg - Emit the target dependent code to load a value of
79  /// \arg Ty from the va_list pointed to by \arg VAListAddr.
80 
81  // FIXME: This is a gaping layering violation if we wanted to drop
82  // the ABI information any lower than CodeGen. Of course, for
83  // VAArg handling it has to be at this level; there is no way to
84  // abstract this out.
85  virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
86  CodeGen::Address VAListAddr,
87  QualType Ty) const = 0;
88 
89  bool isAndroid() const;
90 
91  /// Emit the target dependent code to load a value of
92  /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
93  virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
94  CodeGen::Address VAListAddr,
95  QualType Ty) const;
96 
97  virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
98 
99  virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
100  uint64_t Members) const;
101 
102  bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
103  uint64_t &Members) const;
104 
105  /// A convenience method to return an indirect ABIArgInfo with an
106  /// expected alignment equal to the ABI alignment of the given type.
108  getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
109  bool Realign = false,
110  llvm::Type *Padding = nullptr) const;
111 
113  getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
114 
115 
116  };
117 
118  /// A refining implementation of ABIInfo for targets that support swiftcall.
119  ///
120  /// If we find ourselves wanting multiple such refinements, they'll probably
121  /// be independent refinements, and we should probably find another way
122  /// to do it than simple inheritance.
123  class SwiftABIInfo : public ABIInfo {
124  public:
126 
127  bool supportsSwift() const final override { return true; }
128 
129  virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types,
130  bool asReturnValue) const = 0;
131 
132  virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
133  llvm::Type *eltTy,
134  unsigned elts) const;
135 
136  virtual bool isSwiftErrorInRegister() const = 0;
137 
138  static bool classof(const ABIInfo *info) {
139  return info->supportsSwift();
140  }
141  };
142 } // end namespace CodeGen
143 } // end namespace clang
144 
145 #endif
bool supportsSwift() const final override
Definition: ABIInfo.h:127
A (possibly-)qualified type.
Definition: Type.h:643
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
C Language Family Type Representation.
The base class of the type hierarchy.
Definition: Type.h:1436
SwiftABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:125
CodeGen::CodeGenTypes & CGT
Definition: ABIInfo.h:52
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
ABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:56
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static bool classof(const ABIInfo *info)
Definition: ABIInfo.h:138
Exposes information about the current target.
Definition: TargetInfo.h:163
llvm::CallingConv::ID RuntimeCC
Definition: ABIInfo.h:54
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:265
An aligned address.
Definition: Address.h:24
llvm::CallingConv::ID getRuntimeCC() const
Return the calling convention to use for system runtime functions.
Definition: ABIInfo.h:72
virtual bool supportsSwift() const
Definition: ABIInfo.h:61
CGFunctionInfo - Class to encapsulate the information about a function definition.
Optional< types::ID > Type
Dataflow Directional Tag Classes.
A refining implementation of ABIInfo for targets that support swiftcall.
Definition: ABIInfo.h:123
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:43
This class organizes the cross-module state that is used while lowering AST types to LLVM types...
Definition: CodeGenTypes.h:59
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions...
Definition: ABIInfo.h:50