clang  6.0.0svn
ABIInfo.h
Go to the documentation of this file.
1 //===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
11 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
12 
13 #include "clang/AST/CharUnits.h"
14 #include "clang/AST/Type.h"
15 #include "llvm/IR/CallingConv.h"
16 #include "llvm/IR/Type.h"
17 
18 namespace llvm {
19  class Value;
20  class LLVMContext;
21  class DataLayout;
22  class Type;
23 }
24 
25 namespace clang {
26  class ASTContext;
27  class CodeGenOptions;
28  class TargetInfo;
29 
30 namespace CodeGen {
31  class ABIArgInfo;
32  class Address;
33  class CGCXXABI;
34  class CGFunctionInfo;
35  class CodeGenFunction;
36  class CodeGenTypes;
37  class SwiftABIInfo;
38 
39 namespace swiftcall {
40  class SwiftAggLowering;
41 }
42 
43  // FIXME: All of this stuff should be part of the target interface
44  // somehow. It is currently here because it is not clear how to factor
45  // the targets to support this, since the Targets currently live in a
46  // layer below types n'stuff.
47 
48 
49  /// ABIInfo - Target specific hooks for defining how a type should be
50  /// passed or returned from functions.
51  class ABIInfo {
52  public:
54  protected:
57  public:
59  : CGT(cgt),
60  RuntimeCC(llvm::CallingConv::C),
61  BuiltinCC(llvm::CallingConv::C) {}
62 
63  virtual ~ABIInfo();
64 
65  virtual bool supportsSwift() const { return false; }
66 
67  CodeGen::CGCXXABI &getCXXABI() const;
68  ASTContext &getContext() const;
69  llvm::LLVMContext &getVMContext() const;
70  const llvm::DataLayout &getDataLayout() const;
71  const TargetInfo &getTarget() const;
72  const CodeGenOptions &getCodeGenOpts() const;
73 
74  /// Return the calling convention to use for system runtime
75  /// functions.
77  return RuntimeCC;
78  }
79 
80  /// Return the calling convention to use for compiler builtins
82  return BuiltinCC;
83  }
84 
85  virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
86 
87  /// EmitVAArg - Emit the target dependent code to load a value of
88  /// \arg Ty from the va_list pointed to by \arg VAListAddr.
89 
90  // FIXME: This is a gaping layering violation if we wanted to drop
91  // the ABI information any lower than CodeGen. Of course, for
92  // VAArg handling it has to be at this level; there is no way to
93  // abstract this out.
94  virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
95  CodeGen::Address VAListAddr,
96  QualType Ty) const = 0;
97 
98  bool isAndroid() const;
99 
100  /// Emit the target dependent code to load a value of
101  /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
102  virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
103  CodeGen::Address VAListAddr,
104  QualType Ty) const;
105 
106  virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
107 
108  virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
109  uint64_t Members) const;
110 
111  virtual bool shouldSignExtUnsignedType(QualType Ty) const;
112 
113  bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
114  uint64_t &Members) const;
115 
116  /// A convenience method to return an indirect ABIArgInfo with an
117  /// expected alignment equal to the ABI alignment of the given type.
119  getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
120  bool Realign = false,
121  llvm::Type *Padding = nullptr) const;
122 
124  getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
125 
126 
127  };
128 
129  /// A refining implementation of ABIInfo for targets that support swiftcall.
130  ///
131  /// If we find ourselves wanting multiple such refinements, they'll probably
132  /// be independent refinements, and we should probably find another way
133  /// to do it than simple inheritance.
134  class SwiftABIInfo : public ABIInfo {
135  public:
137 
138  bool supportsSwift() const final override { return true; }
139 
140  virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize,
141  ArrayRef<llvm::Type*> types,
142  bool asReturnValue) const = 0;
143 
144  virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
145  llvm::Type *eltTy,
146  unsigned elts) const;
147 
148  virtual bool isSwiftErrorInRegister() const = 0;
149 
150  static bool classof(const ABIInfo *info) {
151  return info->supportsSwift();
152  }
153  };
154 } // end namespace CodeGen
155 } // end namespace clang
156 
157 #endif
bool supportsSwift() const final override
Definition: ABIInfo.h:138
A (possibly-)qualified type.
Definition: Type.h:614
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
C Language Family Type Representation.
The base class of the type hierarchy.
Definition: Type.h:1300
SwiftABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:136
CodeGen::CodeGenTypes & CGT
Definition: ABIInfo.h:53
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:128
ABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:58
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:150
Exposes information about the current target.
Definition: TargetInfo.h:55
llvm::CallingConv::ID getBuiltinCC() const
Return the calling convention to use for compiler builtins.
Definition: ABIInfo.h:81
llvm::CallingConv::ID RuntimeCC
Definition: ABIInfo.h:55
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:233
The l-value was considered opaque, so the alignment was determined from a type.
An aligned address.
Definition: Address.h:25
llvm::CallingConv::ID getRuntimeCC() const
Return the calling convention to use for system runtime functions.
Definition: ABIInfo.h:76
virtual bool supportsSwift() const
Definition: ABIInfo.h:65
llvm::CallingConv::ID BuiltinCC
Definition: ABIInfo.h:56
CGFunctionInfo - Class to encapsulate the information about a function definition.
Dataflow Directional Tag Classes.
A refining implementation of ABIInfo for targets that support swiftcall.
Definition: ABIInfo.h:134
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:44
This class organizes the cross-module state that is used while lowering AST types to LLVM types...
Definition: CodeGenTypes.h:120
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:51