clang  3.9.0
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/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 TargetInfo;
27 
28 namespace CodeGen {
29  class ABIArgInfo;
30  class Address;
31  class CGCXXABI;
32  class CGFunctionInfo;
33  class CodeGenFunction;
34  class CodeGenTypes;
35  class SwiftABIInfo;
36 
37 namespace swiftcall {
38  class SwiftAggLowering;
39 }
40 
41  // FIXME: All of this stuff should be part of the target interface
42  // somehow. It is currently here because it is not clear how to factor
43  // the targets to support this, since the Targets currently live in a
44  // layer below types n'stuff.
45 
46 
47  /// ABIInfo - Target specific hooks for defining how a type should be
48  /// passed or returned from functions.
49  class ABIInfo {
50  public:
52  protected:
55  public:
57  : CGT(cgt),
58  RuntimeCC(llvm::CallingConv::C),
59  BuiltinCC(llvm::CallingConv::C) {}
60 
61  virtual ~ABIInfo();
62 
63  virtual bool supportsSwift() 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 
71  /// Return the calling convention to use for system runtime
72  /// functions.
74  return RuntimeCC;
75  }
76 
77  /// Return the calling convention to use for compiler builtins
79  return BuiltinCC;
80  }
81 
82  virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
83 
84  /// EmitVAArg - Emit the target dependent code to load a value of
85  /// \arg Ty from the va_list pointed to by \arg VAListAddr.
86 
87  // FIXME: This is a gaping layering violation if we wanted to drop
88  // the ABI information any lower than CodeGen. Of course, for
89  // VAArg handling it has to be at this level; there is no way to
90  // abstract this out.
92  CodeGen::Address VAListAddr,
93  QualType Ty) const = 0;
94 
95  bool isAndroid() const;
96 
97  /// Emit the target dependent code to load a value of
98  /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
100  CodeGen::Address VAListAddr,
101  QualType Ty) const;
102 
103  virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
104 
105  virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
106  uint64_t Members) const;
107 
108  virtual bool shouldSignExtUnsignedType(QualType Ty) const;
109 
110  bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
111  uint64_t &Members) const;
112 
113  /// A convenience method to return an indirect ABIArgInfo with an
114  /// expected alignment equal to the ABI alignment of the given type.
116  getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
117  bool Realign = false,
118  llvm::Type *Padding = nullptr) const;
119 
121  getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
122 
123 
124  };
125 
126  /// A refining implementation of ABIInfo for targets that support swiftcall.
127  ///
128  /// If we find ourselves wanting multiple such refinements, they'll probably
129  /// be independent refinements, and we should probably find another way
130  /// to do it than simple inheritance.
131  class SwiftABIInfo : public ABIInfo {
132  public:
134 
135  bool supportsSwift() const final override { return true; }
136 
137  virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize,
138  ArrayRef<llvm::Type*> types,
139  bool asReturnValue) const = 0;
140 
141  virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
142  llvm::Type *eltTy,
143  unsigned elts) const;
144 
145  static bool classof(const ABIInfo *info) {
146  return info->supportsSwift();
147  }
148  };
149 
150 } // end namespace CodeGen
151 } // end namespace clang
152 
153 #endif
A (possibly-)qualified type.
Definition: Type.h:598
llvm::CallingConv::ID getBuiltinCC() const
Return the calling convention to use for compiler builtins.
Definition: ABIInfo.h:78
C Language Family Type Representation.
CodeGen::ABIArgInfo getNaturalAlignIndirect(QualType Ty, bool ByRef=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...
CodeGen::CGCXXABI & getCXXABI() const
The base class of the type hierarchy.
Definition: Type.h:1281
SwiftABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:133
virtual bool shouldSignExtUnsignedType(QualType Ty) const
llvm::LLVMContext & getVMContext() const
virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize, ArrayRef< llvm::Type * > types, bool asReturnValue) const =0
CodeGen::CodeGenTypes & CGT
Definition: ABIInfo.h:51
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:92
virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty) const
Emit the target dependent code to load a value of.
ABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:56
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty, bool Realign=false) const
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:145
const llvm::DataLayout & getDataLayout() const
Exposes information about the current target.
friend class ASTContext
Definition: Type.h:4178
virtual bool isHomogeneousAggregateBaseType(QualType Ty) const
virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, llvm::Type *eltTy, unsigned elts) const
llvm::CallingConv::ID RuntimeCC
Definition: ABIInfo.h:53
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:231
The l-value was considered opaque, so the alignment was determined from a type.
const std::string ID
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const =0
bool isHomogeneousAggregate(QualType Ty, const Type *&Base, uint64_t &Members) const
isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous aggregate. ...
An aligned address.
Definition: Address.h:25
llvm::CallingConv::ID BuiltinCC
Definition: ABIInfo.h:54
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.
CGFunctionInfo - Class to encapsulate the information about a function definition.
virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, uint64_t Members) const
A refining implementation of ABIInfo for targets that support swiftcall.
Definition: ABIInfo.h:131
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:120
const TargetInfo & getTarget() const
llvm::CallingConv::ID getRuntimeCC() const
Return the calling convention to use for system runtime functions.
Definition: ABIInfo.h:73
virtual bool supportsSwift() const
Definition: ABIInfo.h:63
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions...
Definition: ABIInfo.h:49
bool supportsSwift() const finaloverride
Definition: ABIInfo.h:135
ASTContext & getContext() const