114 lines · c
1//===---- TargetInfo.h - Encapsulate target details -------------*- 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-exception6//7//===----------------------------------------------------------------------===//8//9// These classes wrap the information about a call or function definition used10// to handle ABI compliancy.11//12//===----------------------------------------------------------------------===//13 14#ifndef LLVM_CLANG_LIB_CIR_TARGETINFO_H15#define LLVM_CLANG_LIB_CIR_TARGETINFO_H16 17#include "ABIInfo.h"18#include "CIRGenTypes.h"19#include "clang/Basic/AddressSpaces.h"20#include "clang/CIR/Dialect/IR/CIRAttrs.h"21 22#include <memory>23#include <utility>24 25namespace clang::CIRGen {26 27/// isEmptyFieldForLayout - Return true if the field is "empty", that is,28/// either a zero-width bit-field or an isEmptyRecordForLayout.29bool isEmptyFieldForLayout(const ASTContext &context, const FieldDecl *fd);30 31/// isEmptyRecordForLayout - Return true if a structure contains only empty32/// base classes (per isEmptyRecordForLayout) and fields (per33/// isEmptyFieldForLayout). Note, C++ record fields are considered empty34/// if the [[no_unique_address]] attribute would have made them empty.35bool isEmptyRecordForLayout(const ASTContext &context, QualType t);36 37class CIRGenFunction;38 39class TargetCIRGenInfo {40 std::unique_ptr<ABIInfo> info;41 42public:43 TargetCIRGenInfo(std::unique_ptr<ABIInfo> info) : info(std::move(info)) {}44 45 virtual ~TargetCIRGenInfo() = default;46 47 /// Returns ABI info helper for the target.48 const ABIInfo &getABIInfo() const { return *info; }49 50 /// Get the address space for alloca.51 virtual cir::TargetAddressSpaceAttr getCIRAllocaAddressSpace() const {52 return {};53 }54 /// Perform address space cast of an expression of pointer type.55 /// \param V is the value to be casted to another address space.56 /// \param DestTy is the destination pointer type.57 /// \param srcAS is theaddress space of \p V.58 /// \param IsNonNull is the flag indicating \p V is known to be non null.59 virtual mlir::Value performAddrSpaceCast(CIRGenFunction &cgf, mlir::Value v,60 cir::TargetAddressSpaceAttr srcAddr,61 mlir::Type destTy,62 bool isNonNull = false) const;63 64 /// Determine whether a call to an unprototyped functions under65 /// the given calling convention should use the variadic66 /// convention or the non-variadic convention.67 ///68 /// There's a good reason to make a platform's variadic calling69 /// convention be different from its non-variadic calling70 /// convention: the non-variadic arguments can be passed in71 /// registers (better for performance), and the variadic arguments72 /// can be passed on the stack (also better for performance). If73 /// this is done, however, unprototyped functions *must* use the74 /// non-variadic convention, because C99 states that a call75 /// through an unprototyped function type must succeed if the76 /// function was defined with a non-variadic prototype with77 /// compatible parameters. Therefore, splitting the conventions78 /// makes it impossible to call a variadic function through an79 /// unprototyped type. Since function prototypes came out in the80 /// late 1970s, this is probably an acceptable trade-off.81 /// Nonetheless, not all platforms are willing to make it, and in82 /// particularly x86-64 bends over backwards to make the83 /// conventions compatible.84 ///85 /// The default is false. This is correct whenever:86 /// - the conventions are exactly the same, because it does not87 /// matter and the resulting IR will be somewhat prettier in88 /// certain cases; or89 /// - the conventions are substantively different in how they pass90 /// arguments, because in this case using the variadic convention91 /// will lead to C99 violations.92 ///93 /// However, some platforms make the conventions identical except94 /// for passing additional out-of-band information to a variadic95 /// function: for example, x86-64 passes the number of SSE96 /// arguments in %al. On these platforms, it is desirable to97 /// call unprototyped functions using the variadic convention so98 /// that unprototyped calls to varargs functions still succeed.99 ///100 /// Relatedly, platforms which pass the fixed arguments to this:101 /// A foo(B, C, D);102 /// differently than they would pass them to this:103 /// A foo(B, C, D, ...);104 /// may need to adjust the debugger-support code in Sema to do the105 /// right thing when calling a function with no know signature.106 virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const;107};108 109std::unique_ptr<TargetCIRGenInfo> createX8664TargetCIRGenInfo(CIRGenTypes &cgt);110 111} // namespace clang::CIRGen112 113#endif // LLVM_CLANG_LIB_CIR_TARGETINFO_H114