ABIInfo.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
  9. #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
  10. #include "clang/AST/CharUnits.h"
  11. #include "clang/AST/Type.h"
  12. #include "llvm/IR/CallingConv.h"
  13. #include "llvm/IR/Type.h"
  14. namespace llvm {
  15. class Value;
  16. class LLVMContext;
  17. class DataLayout;
  18. class Type;
  19. }
  20. namespace clang {
  21. class ASTContext;
  22. class CodeGenOptions;
  23. class TargetInfo;
  24. namespace CodeGen {
  25. class ABIArgInfo;
  26. class Address;
  27. class CGCXXABI;
  28. class CGFunctionInfo;
  29. class CodeGenFunction;
  30. class CodeGenTypes;
  31. class SwiftABIInfo;
  32. namespace swiftcall {
  33. class SwiftAggLowering;
  34. }
  35. // FIXME: All of this stuff should be part of the target interface
  36. // somehow. It is currently here because it is not clear how to factor
  37. // the targets to support this, since the Targets currently live in a
  38. // layer below types n'stuff.
  39. /// ABIInfo - Target specific hooks for defining how a type should be
  40. /// passed or returned from functions.
  41. class ABIInfo {
  42. public:
  43. CodeGen::CodeGenTypes &CGT;
  44. protected:
  45. llvm::CallingConv::ID RuntimeCC;
  46. public:
  47. ABIInfo(CodeGen::CodeGenTypes &cgt)
  48. : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
  49. virtual ~ABIInfo();
  50. virtual bool supportsSwift() const { return false; }
  51. virtual bool allowBFloatArgsAndRet() const { return false; }
  52. CodeGen::CGCXXABI &getCXXABI() const;
  53. ASTContext &getContext() const;
  54. llvm::LLVMContext &getVMContext() const;
  55. const llvm::DataLayout &getDataLayout() const;
  56. const TargetInfo &getTarget() const;
  57. const CodeGenOptions &getCodeGenOpts() const;
  58. /// Return the calling convention to use for system runtime
  59. /// functions.
  60. llvm::CallingConv::ID getRuntimeCC() const {
  61. return RuntimeCC;
  62. }
  63. virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
  64. /// EmitVAArg - Emit the target dependent code to load a value of
  65. /// \arg Ty from the va_list pointed to by \arg VAListAddr.
  66. // FIXME: This is a gaping layering violation if we wanted to drop
  67. // the ABI information any lower than CodeGen. Of course, for
  68. // VAArg handling it has to be at this level; there is no way to
  69. // abstract this out.
  70. virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
  71. CodeGen::Address VAListAddr,
  72. QualType Ty) const = 0;
  73. bool isAndroid() const;
  74. /// Emit the target dependent code to load a value of
  75. /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
  76. virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
  77. CodeGen::Address VAListAddr,
  78. QualType Ty) const;
  79. virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
  80. virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
  81. uint64_t Members) const;
  82. bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
  83. uint64_t &Members) const;
  84. // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
  85. // only difference is that this considers bit-precise integer types as well.
  86. bool isPromotableIntegerTypeForABI(QualType Ty) const;
  87. /// A convenience method to return an indirect ABIArgInfo with an
  88. /// expected alignment equal to the ABI alignment of the given type.
  89. CodeGen::ABIArgInfo
  90. getNaturalAlignIndirect(QualType Ty, bool ByVal = true,
  91. bool Realign = false,
  92. llvm::Type *Padding = nullptr) const;
  93. CodeGen::ABIArgInfo
  94. getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
  95. };
  96. /// A refining implementation of ABIInfo for targets that support swiftcall.
  97. ///
  98. /// If we find ourselves wanting multiple such refinements, they'll probably
  99. /// be independent refinements, and we should probably find another way
  100. /// to do it than simple inheritance.
  101. class SwiftABIInfo : public ABIInfo {
  102. public:
  103. SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
  104. bool supportsSwift() const final override { return true; }
  105. virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types,
  106. bool asReturnValue) const = 0;
  107. virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
  108. llvm::Type *eltTy,
  109. unsigned elts) const;
  110. virtual bool isSwiftErrorInRegister() const = 0;
  111. static bool classof(const ABIInfo *info) {
  112. return info->supportsSwift();
  113. }
  114. };
  115. } // end namespace CodeGen
  116. } // end namespace clang
  117. #endif