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