clang  12.0.0git
AMDGPU.h
Go to the documentation of this file.
1 //===--- AMDGPU.h - AMDGPU ToolChain Implementations ----------*- 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 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
11 
12 #include "Gnu.h"
13 #include "ROCm.h"
14 #include "clang/Driver/Options.h"
15 #include "clang/Driver/Tool.h"
16 #include "clang/Driver/ToolChain.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/Support/TargetParser.h"
19 
20 #include <map>
21 
22 namespace clang {
23 namespace driver {
24 
25 namespace tools {
26 namespace amdgpu {
27 
28 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
29 public:
30  Linker(const ToolChain &TC) : Tool("amdgpu::Linker", "ld.lld", TC) {}
31  bool isLinkJob() const override { return true; }
32  bool hasIntegratedCPP() const override { return false; }
33  void ConstructJob(Compilation &C, const JobAction &JA,
34  const InputInfo &Output, const InputInfoList &Inputs,
35  const llvm::opt::ArgList &TCArgs,
36  const char *LinkingOutput) const override;
37 };
38 
39 void getAMDGPUTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
40  std::vector<StringRef> &Features);
41 
42 } // end namespace amdgpu
43 } // end namespace tools
44 
45 namespace toolchains {
46 
47 class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
48 protected:
49  const std::map<options::ID, const StringRef> OptionsDefault;
50 
51  Tool *buildLinker() const override;
52  const StringRef getOptionDefault(options::ID OptID) const {
53  auto opt = OptionsDefault.find(OptID);
54  assert(opt != OptionsDefault.end() && "No Default for Option");
55  return opt->second;
56  }
57 
58 public:
59  AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
60  const llvm::opt::ArgList &Args);
61  unsigned GetDefaultDwarfVersion() const override { return 4; }
62  bool IsIntegratedAssemblerDefault() const override { return true; }
63  bool IsMathErrnoDefault() const override { return false; }
64 
65  llvm::opt::DerivedArgList *
66  TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
67  Action::OffloadKind DeviceOffloadKind) const override;
68 
69  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
70  llvm::opt::ArgStringList &CC1Args,
71  Action::OffloadKind DeviceOffloadKind) const override;
72 
73  /// Return whether denormals should be flushed, and treated as 0 by default
74  /// for the subtarget.
75  static bool getDefaultDenormsAreZeroForTarget(llvm::AMDGPU::GPUKind GPUKind);
76 
77  llvm::DenormalMode getDefaultDenormalModeForType(
78  const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
79  const llvm::fltSemantics *FPType = nullptr) const override;
80 
81  static bool isWave64(const llvm::opt::ArgList &DriverArgs,
82  llvm::AMDGPU::GPUKind Kind);
83  /// Needed for using lto.
84  bool HasNativeLLVMSupport() const override {
85  return true;
86  }
87 
88  /// Needed for translating LTO options.
89  const char *getDefaultLinker() const override { return "ld.lld"; }
90 };
91 
92 class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
93 public:
94  ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
95  const llvm::opt::ArgList &Args);
96  void
97  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
98  llvm::opt::ArgStringList &CC1Args,
99  Action::OffloadKind DeviceOffloadKind) const override;
100 };
101 
102 } // end namespace toolchains
103 } // end namespace driver
104 } // end namespace clang
105 
106 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
bool isLinkJob() const override
Definition: AMDGPU.h:31
const std::map< options::ID, const StringRef > OptionsDefault
Definition: AMDGPU.h:49
unsigned GetDefaultDwarfVersion() const override
Definition: AMDGPU.h:61
const char * getDefaultLinker() const override
Needed for translating LTO options.
Definition: AMDGPU.h:89
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: AMDGPU.h:63
Linker(const ToolChain &TC)
Definition: AMDGPU.h:30
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
void getAMDGPUTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
Definition: AMDGPU.cpp:362
bool HasNativeLLVMSupport() const override
Needed for using lto.
Definition: AMDGPU.h:84
Kind
Dataflow Directional Tag Classes.
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
const StringRef getOptionDefault(options::ID OptID) const
Definition: AMDGPU.h:52
bool IsIntegratedAssemblerDefault() const override
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: AMDGPU.h:62
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
bool hasIntegratedCPP() const override
Definition: AMDGPU.h:32
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:90