clang 24.0.0git
TargetUtils.cpp
Go to the documentation of this file.
1//===--- TargetUtils.cpp - Shared target-specific AST queries ---*- 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
10#include "clang/AST/Attr.h"
11#include "clang/AST/Decl.h"
13
14namespace clang::CodeGenUtils {
15
16//===----------------------------------------------------------------------===//
17// Arm and AArch64
18//===----------------------------------------------------------------------===//
19
20static bool isStreamingCompatible(const FunctionDecl *F) {
21 if (const auto *T = F->getType()->getAs<FunctionProtoType>())
22 return T->getAArch64SMEAttributes() &
24 return false;
25}
26
28 const FunctionDecl *Callee) {
29 bool CallerIsStreaming =
30 IsArmStreamingFunction(Caller, /*IncludeLocallyStreaming=*/true);
31 bool CalleeIsStreaming =
32 IsArmStreamingFunction(Callee, /*IncludeLocallyStreaming=*/true);
33 bool CallerIsStreamingCompatible = isStreamingCompatible(Caller);
34 bool CalleeIsStreamingCompatible = isStreamingCompatible(Callee);
35
37
38 if (!CalleeIsStreamingCompatible &&
39 (CallerIsStreaming != CalleeIsStreaming || CallerIsStreamingCompatible)) {
40 if (CalleeIsStreaming)
42 else
44 }
45 if (auto *NewAttr = Callee->getAttr<ArmNewAttr>()) {
46 if (NewAttr->isNewZA())
48 if (NewAttr->isNewZT0())
50 }
51
52 return Inlinability;
53}
54
55bool hasExtraNeonArgument(unsigned BuiltinID) {
56 // Required by the headers included below, but not in this particular
57 // function.
58 [[maybe_unused]] int PtrArgNum = -1;
59 [[maybe_unused]] bool HasConstPtr = false;
60
61 // The mask encodes the type. We don't care about the actual value. Instead,
62 // we just check whether its been set.
63 uint64_t mask = 0;
64 switch (BuiltinID) {
65#define GET_NEON_OVERLOAD_CHECK
66#include "clang/Basic/arm_fp16.inc"
67#include "clang/Basic/arm_neon.inc"
68#undef GET_NEON_OVERLOAD_CHECK
69 // Non-neon builtins for controling VFP that take extra argument for
70 // discriminating the type.
71 case ARM::BI__builtin_arm_vcvtr_f:
72 case ARM::BI__builtin_arm_vcvtr_d:
73 mask = 1;
74 }
75
76 return mask != 0;
77}
78
79//===----------------------------------------------------------------------===//
80// AMDGPU
81//===----------------------------------------------------------------------===//
82
84 bool HasHiddenVisibility) {
85 if (!HasHiddenVisibility)
86 return false;
87
88 return !D->hasAttr<OMPDeclareTargetDeclAttr>() &&
89 (D->hasAttr<DeviceKernelAttr>() ||
90 (isa<FunctionDecl>(D) && D->hasAttr<CUDAGlobalAttr>()) ||
91 (isa<VarDecl>(D) &&
92 (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>() ||
93 cast<VarDecl>(D)->getType()->isCUDADeviceBuiltinSurfaceType() ||
94 cast<VarDecl>(D)->getType()->isCUDADeviceBuiltinTextureType())));
95}
96
97} // namespace clang::CodeGenUtils
Enumerates target-specific builtins in their own namespaces within namespace clang.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool hasAttr() const
Definition DeclBase.h:585
Represents a function declaration or definition.
Definition Decl.h:2059
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5416
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9299
QualType getType() const
Definition Decl.h:724
bool requiresAMDGPUProtectedVisibility(const Decl *D, bool HasHiddenVisibility)
Returns whether D must be given protected visibility on AMDGPU.
bool hasExtraNeonArgument(unsigned BuiltinID)
Returns whether the Neon builtin BuiltinID takes a trailing argument that discriminates the operand t...
ArmSMEInlinability
The Arm SME ABI issues that can prevent inlining one function into another.
Definition TargetUtils.h:33
static bool isStreamingCompatible(const FunctionDecl *F)
ArmSMEInlinability getArmSMEInlinability(const FunctionDecl *Caller, const FunctionDecl *Callee)
Determines if there are any Arm SME ABI issues with inlining Callee into Caller.
bool isa(CodeGen::Address addr)
Definition Address.h:330
const FunctionProtoType * T
U cast(CodeGen::Address addr)
Definition Address.h:327
bool IsArmStreamingFunction(const FunctionDecl *FD, bool IncludeLocallyStreaming)
Returns whether the given FunctionDecl has an __arm[_locally]_streaming attribute.
Definition Decl.cpp:6182