clang 20.0.0git
TCE.cpp
Go to the documentation of this file.
1//===- TCE.cpp ------------------------------------------------------------===//
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#include "ABIInfoImpl.h"
10#include "TargetInfo.h"
11
12using namespace clang;
13using namespace clang::CodeGen;
14
15//===----------------------------------------------------------------------===//
16// TCE ABI Implementation (see http://tce.cs.tut.fi). Uses mostly the defaults.
17// Currently subclassed only to implement custom OpenCL C function attribute
18// handling.
19//===----------------------------------------------------------------------===//
20
21namespace {
22
23class TCETargetCodeGenInfo : public TargetCodeGenInfo {
24public:
25 TCETargetCodeGenInfo(CodeGenTypes &CGT)
26 : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}
27
28 void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
29 CodeGen::CodeGenModule &M) const override;
30};
31
32void TCETargetCodeGenInfo::setTargetAttributes(
33 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
34 if (GV->isDeclaration())
35 return;
36 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
37 if (!FD) return;
38
39 llvm::Function *F = cast<llvm::Function>(GV);
40
41 if (M.getLangOpts().OpenCL) {
42 if (FD->hasAttr<OpenCLKernelAttr>()) {
43 // OpenCL C Kernel functions are not subject to inlining
44 F->addFnAttr(llvm::Attribute::NoInline);
45 const ReqdWorkGroupSizeAttr *Attr = FD->getAttr<ReqdWorkGroupSizeAttr>();
46 if (Attr) {
47 // Convert the reqd_work_group_size() attributes to metadata.
48 llvm::LLVMContext &Context = F->getContext();
49 llvm::NamedMDNode *OpenCLMetadata =
50 M.getModule().getOrInsertNamedMetadata(
51 "opencl.kernel_wg_size_info");
52
54 Operands.push_back(llvm::ConstantAsMetadata::get(F));
55
56 Operands.push_back(
57 llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
58 M.Int32Ty, llvm::APInt(32, Attr->getXDim()))));
59 Operands.push_back(
60 llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
61 M.Int32Ty, llvm::APInt(32, Attr->getYDim()))));
62 Operands.push_back(
63 llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
64 M.Int32Ty, llvm::APInt(32, Attr->getZDim()))));
65
66 // Add a boolean constant operand for "required" (true) or "hint"
67 // (false) for implementing the work_group_size_hint attr later.
68 // Currently always true as the hint is not yet implemented.
69 Operands.push_back(
70 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getTrue(Context)));
71 OpenCLMetadata->addOperand(llvm::MDNode::get(Context, Operands));
72 }
73 }
74 }
75}
76
77}
78
79std::unique_ptr<TargetCodeGenInfo>
81 return std::make_unique<TCETargetCodeGenInfo>(CGM.getTypes());
82}
const Decl * D
Attr - This represents one attribute.
Definition: Attr.h:43
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Module & getModule() const
const LangOptions & getLangOpts() const
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
DefaultABIInfo - The default implementation for ABI specific details.
Definition: ABIInfoImpl.h:21
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:47
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
Definition: TargetInfo.h:76
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
T * getAttr() const
Definition: DeclBase.h:576
bool hasAttr() const
Definition: DeclBase.h:580
Represents a function declaration or definition.
Definition: Decl.h:1935
std::unique_ptr< TargetCodeGenInfo > createTCETargetCodeGenInfo(CodeGenModule &CGM)
Definition: TCE.cpp:80
The JSON file list parser is used to communicate input to InstallAPI.