blob: ece36e8879c105a66cdd1d2b7d672ee02d4ed7b4 [file] [log] [blame]
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +00001//===----- 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
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
11#define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000012
Anton Korobeynikov244360d2009-06-05 22:08:42 +000013#include "clang/AST/Type.h"
John McCall882987f2013-02-28 19:01:20 +000014#include "llvm/IR/CallingConv.h"
Chandler Carruth5553d0d2014-01-07 11:51:46 +000015#include "llvm/IR/Type.h"
Anton Korobeynikov244360d2009-06-05 22:08:42 +000016
Daniel Dunbar313321e2009-02-03 05:31:23 +000017namespace llvm {
Anton Korobeynikov244360d2009-06-05 22:08:42 +000018 class Value;
Benjamin Kramer9cd050a2009-08-11 17:46:57 +000019 class LLVMContext;
Micah Villmowdd31ca12012-10-08 16:25:52 +000020 class DataLayout;
Daniel Dunbar313321e2009-02-03 05:31:23 +000021}
22
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000023namespace clang {
Daniel Dunbar32931eb2009-02-03 06:51:18 +000024 class ASTContext;
John McCallc8e01702013-04-16 22:48:15 +000025 class TargetInfo;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000026
Daniel Dunbar32931eb2009-02-03 06:51:18 +000027 namespace CodeGen {
John McCall7f416cc2015-09-08 08:05:57 +000028 class ABIArgInfo;
29 class Address;
Mark Lacey3825e832013-10-06 01:33:34 +000030 class CGCXXABI;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000031 class CGFunctionInfo;
Daniel Dunbare46506e2009-02-10 21:44:36 +000032 class CodeGenFunction;
Chris Lattner2b037972010-07-29 02:01:43 +000033 class CodeGenTypes;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000034 }
35
Chris Lattner4b8585e2010-07-28 23:46:15 +000036 // FIXME: All of this stuff should be part of the target interface
37 // somehow. It is currently here because it is not clear how to factor
38 // the targets to support this, since the Targets currently live in a
39 // layer below types n'stuff.
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000040
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000041
42 /// ABIInfo - Target specific hooks for defining how a type should be
43 /// passed or returned from functions.
44 class ABIInfo {
45 public:
Chris Lattner2b037972010-07-29 02:01:43 +000046 CodeGen::CodeGenTypes &CGT;
John McCall882987f2013-02-28 19:01:20 +000047 protected:
48 llvm::CallingConv::ID RuntimeCC;
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000049 llvm::CallingConv::ID BuiltinCC;
John McCall882987f2013-02-28 19:01:20 +000050 public:
51 ABIInfo(CodeGen::CodeGenTypes &cgt)
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000052 : CGT(cgt),
53 RuntimeCC(llvm::CallingConv::C),
54 BuiltinCC(llvm::CallingConv::C) {}
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000055
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000056 virtual ~ABIInfo();
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000057
Mark Lacey3825e832013-10-06 01:33:34 +000058 CodeGen::CGCXXABI &getCXXABI() const;
Chris Lattner2b037972010-07-29 02:01:43 +000059 ASTContext &getContext() const;
60 llvm::LLVMContext &getVMContext() const;
Micah Villmowdd31ca12012-10-08 16:25:52 +000061 const llvm::DataLayout &getDataLayout() const;
John McCallc8e01702013-04-16 22:48:15 +000062 const TargetInfo &getTarget() const;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000063
John McCall882987f2013-02-28 19:01:20 +000064 /// Return the calling convention to use for system runtime
65 /// functions.
66 llvm::CallingConv::ID getRuntimeCC() const {
67 return RuntimeCC;
68 }
69
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000070 /// Return the calling convention to use for compiler builtins
71 llvm::CallingConv::ID getBuiltinCC() const {
72 return BuiltinCC;
73 }
74
Chris Lattner22326a12010-07-29 02:31:05 +000075 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
Daniel Dunbare46506e2009-02-10 21:44:36 +000076
77 /// EmitVAArg - Emit the target dependent code to load a value of
78 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
Anton Korobeynikov244360d2009-06-05 22:08:42 +000079
Daniel Dunbare46506e2009-02-10 21:44:36 +000080 // FIXME: This is a gaping layering violation if we wanted to drop
81 // the ABI information any lower than CodeGen. Of course, for
82 // VAArg handling it has to be at this level; there is no way to
83 // abstract this out.
John McCall7f416cc2015-09-08 08:05:57 +000084 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
85 CodeGen::Address VAListAddr,
86 QualType Ty) const = 0;
Reid Klecknere9f6a712014-10-31 17:10:41 +000087
88 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
89
90 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
91 uint64_t Members) const;
92
Petar Jovanovic1a3f9652015-05-26 21:07:19 +000093 virtual bool shouldSignExtUnsignedType(QualType Ty) const;
94
Reid Klecknere9f6a712014-10-31 17:10:41 +000095 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
96 uint64_t &Members) const;
97
John McCall7f416cc2015-09-08 08:05:57 +000098 /// A convenience method to return an indirect ABIArgInfo with an
99 /// expected alignment equal to the ABI alignment of the given type.
100 CodeGen::ABIArgInfo
101 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
102 bool Realign = false,
103 llvm::Type *Padding = nullptr) const;
104
105 CodeGen::ABIArgInfo
106 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000107 };
108} // end namespace clang
109
110#endif