| 1 | //===--- Hexagon.h - Hexagon 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_HEXAGON_H |
| 10 | #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HEXAGON_H |
| 11 | |
| 12 | #include "Linux.h" |
| 13 | #include "clang/Driver/Tool.h" |
| 14 | #include "clang/Driver/ToolChain.h" |
| 15 | |
| 16 | #include <optional> |
| 17 | #include <string> |
| 18 | |
| 19 | namespace clang { |
| 20 | namespace driver { |
| 21 | namespace tools { |
| 22 | namespace hexagon { |
| 23 | // For Hexagon, we do not need to instantiate tools for PreProcess, PreCompile |
| 24 | // and Compile. |
| 25 | // We simply use "clang -cc1" for those actions. |
| 26 | class LLVM_LIBRARY_VISIBILITY Assembler final : public Tool { |
| 27 | public: |
| 28 | Assembler(const ToolChain &TC) |
| 29 | : Tool("hexagon::Assembler" , "hexagon-as" , TC) {} |
| 30 | |
| 31 | bool hasIntegratedCPP() const override { return false; } |
| 32 | |
| 33 | void (const JobAction &JA, |
| 34 | llvm::opt::ArgStringList &CmdArgs) const; |
| 35 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 36 | const InputInfo &Output, const InputInfoList &Inputs, |
| 37 | const llvm::opt::ArgList &TCArgs, |
| 38 | const char *LinkingOutput) const override; |
| 39 | }; |
| 40 | |
| 41 | class LLVM_LIBRARY_VISIBILITY Linker final : public Tool { |
| 42 | public: |
| 43 | Linker(const ToolChain &TC) : Tool("hexagon::Linker" , "hexagon-ld" , TC) {} |
| 44 | |
| 45 | bool hasIntegratedCPP() const override { return false; } |
| 46 | bool isLinkJob() const override { return true; } |
| 47 | |
| 48 | void (const JobAction &JA, |
| 49 | llvm::opt::ArgStringList &CmdArgs) const; |
| 50 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 51 | const InputInfo &Output, const InputInfoList &Inputs, |
| 52 | const llvm::opt::ArgList &TCArgs, |
| 53 | const char *LinkingOutput) const override; |
| 54 | }; |
| 55 | |
| 56 | void getHexagonTargetFeatures(const Driver &D, const llvm::Triple &Triple, |
| 57 | const llvm::opt::ArgList &Args, |
| 58 | std::vector<StringRef> &Features); |
| 59 | |
| 60 | } // end namespace hexagon. |
| 61 | } // end namespace tools |
| 62 | |
| 63 | namespace toolchains { |
| 64 | |
| 65 | class LLVM_LIBRARY_VISIBILITY HexagonToolChain : public Linux { |
| 66 | protected: |
| 67 | GCCVersion GCCLibAndIncVersion; |
| 68 | Tool *buildAssembler() const override; |
| 69 | Tool *buildLinker() const override; |
| 70 | |
| 71 | unsigned getOptimizationLevel(const llvm::opt::ArgList &DriverArgs) const; |
| 72 | |
| 73 | public: |
| 74 | HexagonToolChain(const Driver &D, const llvm::Triple &Triple, |
| 75 | const llvm::opt::ArgList &Args); |
| 76 | ~HexagonToolChain() override; |
| 77 | |
| 78 | void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, |
| 79 | llvm::opt::ArgStringList &CC1Args, |
| 80 | Action::OffloadKind DeviceOffloadKind) const override; |
| 81 | void |
| 82 | AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, |
| 83 | llvm::opt::ArgStringList &CC1Args) const override; |
| 84 | void addLibStdCxxIncludePaths( |
| 85 | const llvm::opt::ArgList &DriverArgs, |
| 86 | llvm::opt::ArgStringList &CC1Args) const override; |
| 87 | |
| 88 | void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
| 89 | llvm::opt::ArgStringList &CC1Args) const override; |
| 90 | |
| 91 | const char *getDefaultLinker() const override { |
| 92 | return getTriple().isMusl() ? "ld.lld" : "hexagon-link" ; |
| 93 | } |
| 94 | |
| 95 | CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; |
| 96 | |
| 97 | void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, |
| 98 | llvm::opt::ArgStringList &CmdArgs) const override; |
| 99 | |
| 100 | StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; } |
| 101 | |
| 102 | std::string getHexagonTargetDir( |
| 103 | const std::string &InstalledDir, |
| 104 | const SmallVectorImpl<std::string> &PrefixDirs) const; |
| 105 | void getHexagonLibraryPaths(const llvm::opt::ArgList &Args, |
| 106 | ToolChain::path_list &LibPaths) const; |
| 107 | |
| 108 | std::string getCompilerRTPath() const override; |
| 109 | |
| 110 | static bool isAutoHVXEnabled(const llvm::opt::ArgList &Args); |
| 111 | static StringRef GetDefaultCPU(); |
| 112 | static StringRef GetTargetCPUVersion(const llvm::opt::ArgList &Args); |
| 113 | |
| 114 | static std::optional<unsigned> |
| 115 | getSmallDataThreshold(const llvm::opt::ArgList &Args); |
| 116 | static std::optional<std::string> |
| 117 | GetHVXVersion(const llvm::opt::ArgList &Args); |
| 118 | }; |
| 119 | |
| 120 | } // end namespace toolchains |
| 121 | } // end namespace driver |
| 122 | } // end namespace clang |
| 123 | |
| 124 | #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HEXAGON_H |
| 125 | |