2009-02-03 09:05:53 +08:00
|
|
|
//===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-02-03 09:05:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
|
2009-02-03 09:05:53 +08:00
|
|
|
|
2017-01-30 23:39:18 +08:00
|
|
|
#include "clang/AST/CharUnits.h"
|
2009-06-06 06:08:42 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2013-03-01 03:01:20 +08:00
|
|
|
#include "llvm/IR/CallingConv.h"
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "llvm/IR/Type.h"
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2009-02-03 13:31:23 +08:00
|
|
|
namespace llvm {
|
2009-06-06 06:08:42 +08:00
|
|
|
class Value;
|
2009-08-12 01:46:57 +08:00
|
|
|
class LLVMContext;
|
2012-10-09 00:25:52 +08:00
|
|
|
class DataLayout;
|
2016-04-05 02:33:08 +08:00
|
|
|
class Type;
|
2009-02-03 13:31:23 +08:00
|
|
|
}
|
|
|
|
|
2009-02-03 09:05:53 +08:00
|
|
|
namespace clang {
|
2009-02-03 14:51:18 +08:00
|
|
|
class ASTContext;
|
2017-08-26 09:04:35 +08:00
|
|
|
class CodeGenOptions;
|
2013-04-17 06:48:15 +08:00
|
|
|
class TargetInfo;
|
2009-02-03 14:51:18 +08:00
|
|
|
|
2016-04-05 02:33:08 +08:00
|
|
|
namespace CodeGen {
|
|
|
|
class ABIArgInfo;
|
2020-07-02 14:56:51 +08:00
|
|
|
class Address;
|
2016-04-05 02:33:08 +08:00
|
|
|
class CGCXXABI;
|
|
|
|
class CGFunctionInfo;
|
|
|
|
class CodeGenFunction;
|
|
|
|
class CodeGenTypes;
|
|
|
|
class SwiftABIInfo;
|
|
|
|
|
|
|
|
namespace swiftcall {
|
|
|
|
class SwiftAggLowering;
|
|
|
|
}
|
2009-02-03 14:51:18 +08:00
|
|
|
|
2010-07-29 07:46:15 +08:00
|
|
|
// FIXME: All of this stuff should be part of the target interface
|
|
|
|
// somehow. It is currently here because it is not clear how to factor
|
|
|
|
// the targets to support this, since the Targets currently live in a
|
|
|
|
// layer below types n'stuff.
|
2009-02-03 09:05:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// ABIInfo - Target specific hooks for defining how a type should be
|
|
|
|
/// passed or returned from functions.
|
|
|
|
class ABIInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
CodeGen::CodeGenTypes &CGT;
|
2013-03-01 03:01:20 +08:00
|
|
|
protected:
|
|
|
|
llvm::CallingConv::ID RuntimeCC;
|
|
|
|
public:
|
|
|
|
ABIInfo(CodeGen::CodeGenTypes &cgt)
|
2018-03-21 06:02:57 +08:00
|
|
|
: CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2009-02-03 09:05:53 +08:00
|
|
|
virtual ~ABIInfo();
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2016-04-05 02:33:08 +08:00
|
|
|
virtual bool supportsSwift() const { return false; }
|
|
|
|
|
[ARM] Add __bf16 as new Bfloat16 C Type
Summary:
This patch upstreams support for a new storage only bfloat16 C type.
This type is used to implement primitive support for bfloat16 data, in
line with the Bfloat16 extension of the Armv8.6-a architecture, as
detailed here:
https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/arm-architecture-developments-armv8-6-a
The bfloat type, and its properties are specified in the Arm Architecture
Reference Manual:
https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
In detail this patch:
- introduces an opaque, storage-only C-type __bf16, which introduces a new bfloat IR type.
This is part of a patch series, starting with command-line and Bfloat16
assembly support. The subsequent patches will upstream intrinsics
support for BFloat16, followed by Matrix Multiplication and the
remaining Virtualization features of the armv8.6-a architecture.
The following people contributed to this patch:
- Luke Cheeseman
- Momchil Velikov
- Alexandros Lamprineas
- Luke Geeson
- Simon Tatham
- Ties Stuij
Reviewers: SjoerdMeijer, rjmccall, rsmith, liutianle, RKSimon, craig.topper, jfb, LukeGeeson, fpetrogalli
Reviewed By: SjoerdMeijer
Subscribers: labrinea, majnemer, asmith, dexonsmith, kristof.beyls, arphaman, danielkiss, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D76077
2020-06-05 07:20:02 +08:00
|
|
|
virtual bool allowBFloatArgsAndRet() const { return false; }
|
|
|
|
|
2013-10-06 09:33:34 +08:00
|
|
|
CodeGen::CGCXXABI &getCXXABI() const;
|
2010-07-29 10:01:43 +08:00
|
|
|
ASTContext &getContext() const;
|
|
|
|
llvm::LLVMContext &getVMContext() const;
|
2012-10-09 00:25:52 +08:00
|
|
|
const llvm::DataLayout &getDataLayout() const;
|
2013-04-17 06:48:15 +08:00
|
|
|
const TargetInfo &getTarget() const;
|
2017-08-26 09:04:35 +08:00
|
|
|
const CodeGenOptions &getCodeGenOpts() const;
|
2009-02-03 14:51:18 +08:00
|
|
|
|
2013-03-01 03:01:20 +08:00
|
|
|
/// Return the calling convention to use for system runtime
|
|
|
|
/// functions.
|
|
|
|
llvm::CallingConv::ID getRuntimeCC() const {
|
|
|
|
return RuntimeCC;
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
|
2009-02-11 05:44:36 +08:00
|
|
|
|
|
|
|
/// EmitVAArg - Emit the target dependent code to load a value of
|
|
|
|
/// \arg Ty from the va_list pointed to by \arg VAListAddr.
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2009-02-11 05:44:36 +08:00
|
|
|
// FIXME: This is a gaping layering violation if we wanted to drop
|
|
|
|
// the ABI information any lower than CodeGen. Of course, for
|
|
|
|
// VAArg handling it has to be at this level; there is no way to
|
|
|
|
// abstract this out.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
|
|
|
|
CodeGen::Address VAListAddr,
|
|
|
|
QualType Ty) const = 0;
|
2014-11-01 01:10:41 +08:00
|
|
|
|
2016-02-23 00:48:42 +08:00
|
|
|
bool isAndroid() const;
|
|
|
|
|
2015-09-18 04:55:33 +08:00
|
|
|
/// Emit the target dependent code to load a value of
|
|
|
|
/// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
|
|
|
|
virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
|
|
|
|
CodeGen::Address VAListAddr,
|
|
|
|
QualType Ty) const;
|
|
|
|
|
2014-11-01 01:10:41 +08:00
|
|
|
virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
|
|
|
|
|
|
|
|
virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
|
|
|
|
uint64_t Members) const;
|
|
|
|
|
|
|
|
bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
|
|
|
|
uint64_t &Members) const;
|
|
|
|
|
2020-04-30 03:48:07 +08:00
|
|
|
// Implement the Type::IsPromotableIntegerType for ABI specific needs. The
|
|
|
|
// only difference is that this considers _ExtInt as well.
|
|
|
|
bool isPromotableIntegerTypeForABI(QualType Ty) const;
|
|
|
|
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
/// A convenience method to return an indirect ABIArgInfo with an
|
|
|
|
/// expected alignment equal to the ABI alignment of the given type.
|
|
|
|
CodeGen::ABIArgInfo
|
2020-08-06 19:34:10 +08:00
|
|
|
getNaturalAlignIndirect(QualType Ty, bool ByVal = true,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
bool Realign = false,
|
|
|
|
llvm::Type *Padding = nullptr) const;
|
|
|
|
|
|
|
|
CodeGen::ABIArgInfo
|
|
|
|
getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
|
2016-04-05 02:33:08 +08:00
|
|
|
|
|
|
|
|
2009-02-03 09:05:53 +08:00
|
|
|
};
|
2016-04-05 02:33:08 +08:00
|
|
|
|
|
|
|
/// A refining implementation of ABIInfo for targets that support swiftcall.
|
|
|
|
///
|
|
|
|
/// If we find ourselves wanting multiple such refinements, they'll probably
|
|
|
|
/// be independent refinements, and we should probably find another way
|
|
|
|
/// to do it than simple inheritance.
|
|
|
|
class SwiftABIInfo : public ABIInfo {
|
|
|
|
public:
|
|
|
|
SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
|
|
|
|
|
|
|
|
bool supportsSwift() const final override { return true; }
|
|
|
|
|
2018-01-07 14:28:49 +08:00
|
|
|
virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types,
|
2016-04-05 02:33:08 +08:00
|
|
|
bool asReturnValue) const = 0;
|
|
|
|
|
|
|
|
virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
|
|
|
|
llvm::Type *eltTy,
|
|
|
|
unsigned elts) const;
|
|
|
|
|
2016-12-02 02:07:38 +08:00
|
|
|
virtual bool isSwiftErrorInRegister() const = 0;
|
|
|
|
|
2016-04-05 02:33:08 +08:00
|
|
|
static bool classof(const ABIInfo *info) {
|
|
|
|
return info->supportsSwift();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
2009-02-03 09:05:53 +08:00
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|