xref: /freebsd/contrib/llvm-project/clang/include/clang/Basic/TargetID.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1e8d8bef9SDimitry Andric //===--- TargetID.h - Utilities for target ID -------------------*- C++ -*-===//
2e8d8bef9SDimitry Andric //
3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric //
7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric 
904eeddc0SDimitry Andric #ifndef LLVM_CLANG_BASIC_TARGETID_H
1004eeddc0SDimitry Andric #define LLVM_CLANG_BASIC_TARGETID_H
11e8d8bef9SDimitry Andric 
12e8d8bef9SDimitry Andric #include "llvm/ADT/SmallVector.h"
13e8d8bef9SDimitry Andric #include "llvm/ADT/StringMap.h"
14*06c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h"
15bdd1243dSDimitry Andric #include <optional>
16e8d8bef9SDimitry Andric #include <set>
17e8d8bef9SDimitry Andric 
18e8d8bef9SDimitry Andric namespace clang {
19e8d8bef9SDimitry Andric 
20e8d8bef9SDimitry Andric /// Get all feature strings that can be used in target ID for \p Processor.
21e8d8bef9SDimitry Andric /// Target ID is a processor name with optional feature strings
22e8d8bef9SDimitry Andric /// postfixed by a plus or minus sign delimited by colons, e.g.
23e8d8bef9SDimitry Andric /// gfx908:xnack+:sramecc-. Each processor have a limited
24e8d8bef9SDimitry Andric /// number of predefined features when showing up in a target ID.
2504eeddc0SDimitry Andric llvm::SmallVector<llvm::StringRef, 4>
26e8d8bef9SDimitry Andric getAllPossibleTargetIDFeatures(const llvm::Triple &T,
27e8d8bef9SDimitry Andric                                llvm::StringRef Processor);
28e8d8bef9SDimitry Andric 
29e8d8bef9SDimitry Andric /// Get processor name from target ID.
30e8d8bef9SDimitry Andric /// Returns canonical processor name or empty if the processor name is invalid.
31e8d8bef9SDimitry Andric llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T,
32e8d8bef9SDimitry Andric                                          llvm::StringRef OffloadArch);
33e8d8bef9SDimitry Andric 
34e8d8bef9SDimitry Andric /// Parse a target ID to get processor and feature map.
35bdd1243dSDimitry Andric /// Returns canonicalized processor name or std::nullopt if the target ID is
36bdd1243dSDimitry Andric /// invalid.  Returns target ID features in \p FeatureMap if it is not null
37bdd1243dSDimitry Andric /// pointer. This function assumes \p OffloadArch is a valid target ID.
38e8d8bef9SDimitry Andric /// If the target ID contains feature+, map it to true.
39e8d8bef9SDimitry Andric /// If the target ID contains feature-, map it to false.
40e8d8bef9SDimitry Andric /// If the target ID does not contain a feature (default), do not map it.
41bdd1243dSDimitry Andric std::optional<llvm::StringRef> parseTargetID(const llvm::Triple &T,
42bdd1243dSDimitry Andric                                              llvm::StringRef OffloadArch,
43e8d8bef9SDimitry Andric                                              llvm::StringMap<bool> *FeatureMap);
44e8d8bef9SDimitry Andric 
45e8d8bef9SDimitry Andric /// Returns canonical target ID, assuming \p Processor is canonical and all
46e8d8bef9SDimitry Andric /// entries in \p Features are valid.
47e8d8bef9SDimitry Andric std::string getCanonicalTargetID(llvm::StringRef Processor,
48e8d8bef9SDimitry Andric                                  const llvm::StringMap<bool> &Features);
49e8d8bef9SDimitry Andric 
50e8d8bef9SDimitry Andric /// Get the conflicted pair of target IDs for a compilation or a bundled code
51e8d8bef9SDimitry Andric /// object, assuming \p TargetIDs are canonicalized. If there is no conflicts,
52bdd1243dSDimitry Andric /// returns std::nullopt.
53bdd1243dSDimitry Andric std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
54e8d8bef9SDimitry Andric getConflictTargetIDCombination(const std::set<llvm::StringRef> &TargetIDs);
55bdd1243dSDimitry Andric 
56bdd1243dSDimitry Andric /// Check whether the provided target ID is compatible with the requested
57bdd1243dSDimitry Andric /// target ID.
58bdd1243dSDimitry Andric bool isCompatibleTargetID(llvm::StringRef Provided, llvm::StringRef Requested);
59e8d8bef9SDimitry Andric } // namespace clang
60e8d8bef9SDimitry Andric 
61e8d8bef9SDimitry Andric #endif
62