xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Support/RISCVISAUtils.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- RISCVISAUtils.h - RISC-V ISA Utilities ------------------*- 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 // Utilities shared by TableGen and RISCVISAInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_SUPPORT_RISCVISAUTILS_H
14 #define LLVM_SUPPORT_RISCVISAUTILS_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/Compiler.h"
18 #include <map>
19 #include <string>
20 
21 namespace llvm {
22 
23 namespace RISCVISAUtils {
24 constexpr StringLiteral AllStdExts = "mafdqlcbkjtpvnh";
25 
26 /// Represents the major and version number components of a RISC-V extension.
27 struct ExtensionVersion {
28   unsigned Major;
29   unsigned Minor;
30 };
31 
32 LLVM_ABI bool compareExtension(const std::string &LHS, const std::string &RHS);
33 
34 /// Helper class for OrderedExtensionMap.
35 struct ExtensionComparator {
operatorExtensionComparator36   bool operator()(const std::string &LHS, const std::string &RHS) const {
37     return compareExtension(LHS, RHS);
38   }
39 };
40 
41 /// OrderedExtensionMap is std::map, it's specialized to keep entries
42 /// in canonical order of extension.
43 typedef std::map<std::string, ExtensionVersion, ExtensionComparator>
44     OrderedExtensionMap;
45 
46 } // namespace RISCVISAUtils
47 
48 } // namespace llvm
49 
50 #endif
51