clang 23.0.0git
TargetInfo.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// These classes wrap the information about a call or function definition used
10// to handle ABI compliancy.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LIB_CIR_TARGETINFO_H
15#define LLVM_CLANG_LIB_CIR_TARGETINFO_H
16
17#include "ABIInfo.h"
18#include "CIRGenTypes.h"
19#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
23
24#include <memory>
25#include <utility>
26
27namespace clang::CIRGen {
28
29/// isEmptyFieldForLayout - Return true if the field is "empty", that is,
30/// either a zero-width bit-field or an isEmptyRecordForLayout.
31bool isEmptyFieldForLayout(const ASTContext &context, const FieldDecl *fd);
32
33/// isEmptyRecordForLayout - Return true if a structure contains only empty
34/// base classes (per isEmptyRecordForLayout) and fields (per
35/// isEmptyFieldForLayout). Note, C++ record fields are considered empty
36/// if the [[no_unique_address]] attribute would have made them empty.
37bool isEmptyRecordForLayout(const ASTContext &context, QualType t);
38
39class CIRGenFunction;
40
42 std::unique_ptr<ABIInfo> info;
43
44public:
45 TargetCIRGenInfo(std::unique_ptr<ABIInfo> info) : info(std::move(info)) {}
46
47 virtual ~TargetCIRGenInfo() = default;
48
49 /// Returns ABI info helper for the target.
50 const ABIInfo &getABIInfo() const { return *info; }
51
52 /// Get target favored AST address space of a global variable for languages
53 /// other than OpenCL and CUDA.
54 /// If \p d is nullptr, returns the default target favored address space
55 /// for global variable.
57 const clang::VarDecl *d) const;
58
59 /// Get the address space for alloca.
60 virtual mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const {
61 return cir::LangAddressSpaceAttr::get(&info->cgt.getMLIRContext(),
62 cir::LangAddressSpace::Default);
63 }
64
65 /// Determine whether a call to an unprototyped functions under
66 /// the given calling convention should use the variadic
67 /// convention or the non-variadic convention.
68 ///
69 /// There's a good reason to make a platform's variadic calling
70 /// convention be different from its non-variadic calling
71 /// convention: the non-variadic arguments can be passed in
72 /// registers (better for performance), and the variadic arguments
73 /// can be passed on the stack (also better for performance). If
74 /// this is done, however, unprototyped functions *must* use the
75 /// non-variadic convention, because C99 states that a call
76 /// through an unprototyped function type must succeed if the
77 /// function was defined with a non-variadic prototype with
78 /// compatible parameters. Therefore, splitting the conventions
79 /// makes it impossible to call a variadic function through an
80 /// unprototyped type. Since function prototypes came out in the
81 /// late 1970s, this is probably an acceptable trade-off.
82 /// Nonetheless, not all platforms are willing to make it, and in
83 /// particularly x86-64 bends over backwards to make the
84 /// conventions compatible.
85 ///
86 /// The default is false. This is correct whenever:
87 /// - the conventions are exactly the same, because it does not
88 /// matter and the resulting IR will be somewhat prettier in
89 /// certain cases; or
90 /// - the conventions are substantively different in how they pass
91 /// arguments, because in this case using the variadic convention
92 /// will lead to C99 violations.
93 ///
94 /// However, some platforms make the conventions identical except
95 /// for passing additional out-of-band information to a variadic
96 /// function: for example, x86-64 passes the number of SSE
97 /// arguments in %al. On these platforms, it is desirable to
98 /// call unprototyped functions using the variadic convention so
99 /// that unprototyped calls to varargs functions still succeed.
100 ///
101 /// Relatedly, platforms which pass the fixed arguments to this:
102 /// A foo(B, C, D);
103 /// differently than they would pass them to this:
104 /// A foo(B, C, D, ...);
105 /// may need to adjust the debugger-support code in Sema to do the
106 /// right thing when calling a function with no know signature.
107 virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const;
108
109 /// Provides a convenient hook to handle extra target-specific attributes
110 /// for the given global.
111 /// In OG, the function receives an llvm::GlobalValue. However, functions
112 /// and global variables are separate types in Clang IR, so we use a general
113 /// mlir::Operation*.
115 mlir::Operation *global,
116 CIRGenModule &module) const {}
117
119 mlir::Type ty) const {
120 return false;
121 }
122
123 /// Corrects the MLIR type for a given constraint and "usual"
124 /// type.
125 ///
126 /// \returns A new MLIR type, possibly the same as the original
127 /// on success
128 virtual mlir::Type adjustInlineAsmType(CIRGenFunction &cgf,
129 llvm::StringRef constraint,
130 mlir::Type ty) const {
131 return ty;
132 }
133};
134
135std::unique_ptr<TargetCIRGenInfo>
136createAMDGPUTargetCIRGenInfo(CIRGenTypes &cgt);
137
138std::unique_ptr<TargetCIRGenInfo> createX8664TargetCIRGenInfo(CIRGenTypes &cgt);
139
140std::unique_ptr<TargetCIRGenInfo> createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt);
141
142} // namespace clang::CIRGen
143
144#endif // LLVM_CLANG_LIB_CIR_TARGETINFO_H
Provides definitions for the various language-specific address spaces.
This class organizes the cross-function state that is used while generating CIR code.
virtual ~TargetCIRGenInfo()=default
virtual mlir::Type adjustInlineAsmType(CIRGenFunction &cgf, llvm::StringRef constraint, mlir::Type ty) const
Corrects the MLIR type for a given constraint and "usual" type.
Definition TargetInfo.h:128
const ABIInfo & getABIInfo() const
Returns ABI info helper for the target.
Definition TargetInfo.h:50
TargetCIRGenInfo(std::unique_ptr< ABIInfo > info)
Definition TargetInfo.h:45
virtual clang::LangAS getGlobalVarAddressSpace(CIRGenModule &cgm, const clang::VarDecl *d) const
Get target favored AST address space of a global variable for languages other than OpenCL and CUDA.
virtual bool isScalarizableAsmOperand(CIRGenFunction &cgf, mlir::Type ty) const
Definition TargetInfo.h:118
virtual bool isNoProtoCallVariadic(const FunctionNoProtoType *fnType) const
Determine whether a call to an unprototyped functions under the given calling convention should use t...
virtual mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const
Get the address space for alloca.
Definition TargetInfo.h:60
virtual void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global, CIRGenModule &module) const
Provides a convenient hook to handle extra target-specific attributes for the given global.
Definition TargetInfo.h:114
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4893
Represents a variable declaration or definition.
Definition Decl.h:926
std::unique_ptr< TargetCIRGenInfo > createAMDGPUTargetCIRGenInfo(CIRGenTypes &cgt)
std::unique_ptr< TargetCIRGenInfo > createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
std::unique_ptr< TargetCIRGenInfo > createX8664TargetCIRGenInfo(CIRGenTypes &cgt)
bool isEmptyFieldForLayout(const ASTContext &context, const FieldDecl *fd)
isEmptyFieldForLayout - Return true if the field is "empty", that is, either a zero-width bit-field o...
bool isEmptyRecordForLayout(const ASTContext &context, QualType t)
isEmptyRecordForLayout - Return true if a structure contains only empty base classes (per isEmptyReco...
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
LangAS
Defines the address space values used by the address space qualifier of QualType.