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