Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/clang/lib/CodeGen/Targets/TCE.cpp
Line
Count
Source (jump to first uncovered line)
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
12
using namespace clang;
13
using 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
21
namespace {
22
23
class TCETargetCodeGenInfo : public TargetCodeGenInfo {
24
public:
25
  TCETargetCodeGenInfo(CodeGenTypes &CGT)
26
0
      : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}
27
28
  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
29
                           CodeGen::CodeGenModule &M) const override;
30
};
31
32
void TCETargetCodeGenInfo::setTargetAttributes(
33
0
    const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
34
0
  if (GV->isDeclaration())
35
0
    return;
36
0
  const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
37
0
  if (!FD) return;
38
39
0
  llvm::Function *F = cast<llvm::Function>(GV);
40
41
0
  if (M.getLangOpts().OpenCL) {
42
0
    if (FD->hasAttr<OpenCLKernelAttr>()) {
43
      // OpenCL C Kernel functions are not subject to inlining
44
0
      F->addFnAttr(llvm::Attribute::NoInline);
45
0
      const ReqdWorkGroupSizeAttr *Attr = FD->getAttr<ReqdWorkGroupSizeAttr>();
46
0
      if (Attr) {
47
        // Convert the reqd_work_group_size() attributes to metadata.
48
0
        llvm::LLVMContext &Context = F->getContext();
49
0
        llvm::NamedMDNode *OpenCLMetadata =
50
0
            M.getModule().getOrInsertNamedMetadata(
51
0
                "opencl.kernel_wg_size_info");
52
53
0
        SmallVector<llvm::Metadata *, 5> Operands;
54
0
        Operands.push_back(llvm::ConstantAsMetadata::get(F));
55
56
0
        Operands.push_back(
57
0
            llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
58
0
                M.Int32Ty, llvm::APInt(32, Attr->getXDim()))));
59
0
        Operands.push_back(
60
0
            llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
61
0
                M.Int32Ty, llvm::APInt(32, Attr->getYDim()))));
62
0
        Operands.push_back(
63
0
            llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
64
0
                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
0
        Operands.push_back(
70
0
            llvm::ConstantAsMetadata::get(llvm::ConstantInt::getTrue(Context)));
71
0
        OpenCLMetadata->addOperand(llvm::MDNode::get(Context, Operands));
72
0
      }
73
0
    }
74
0
  }
75
0
}
76
77
}
78
79
std::unique_ptr<TargetCodeGenInfo>
80
0
CodeGen::createTCETargetCodeGenInfo(CodeGenModule &CGM) {
81
0
  return std::make_unique<TCETargetCodeGenInfo>(CGM.getTypes());
82
0
}