Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 pmbaty 1
//===-- RISCVISAInfo.h - RISCV ISA Information ------------------*- 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_SUPPORT_RISCVISAINFO_H
10
#define LLVM_SUPPORT_RISCVISAINFO_H
11
 
12
#include "llvm/ADT/StringRef.h"
13
#include "llvm/Support/Error.h"
14
 
15
#include <map>
16
#include <string>
17
#include <vector>
18
 
19
namespace llvm {
20
struct RISCVExtensionInfo {
21
  std::string ExtName;
22
  unsigned MajorVersion;
23
  unsigned MinorVersion;
24
};
25
 
26
class RISCVISAInfo {
27
public:
28
  RISCVISAInfo(const RISCVISAInfo &) = delete;
29
  RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
30
 
31
  static bool compareExtension(const std::string &LHS, const std::string &RHS);
32
 
33
  /// Helper class for OrderedExtensionMap.
34
  struct ExtensionComparator {
35
    bool operator()(const std::string &LHS, const std::string &RHS) const {
36
      return compareExtension(LHS, RHS);
37
    }
38
  };
39
 
40
  /// OrderedExtensionMap is std::map, it's specialized to keep entries
41
  /// in canonical order of extension.
42
  typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
43
      OrderedExtensionMap;
44
 
45
  RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
46
      : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
47
 
48
  /// Parse RISCV ISA info from arch string.
49
  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
50
  parseArchString(StringRef Arch, bool EnableExperimentalExtension,
51
                  bool ExperimentalExtensionVersionCheck = true,
52
                  bool IgnoreUnknown = false);
53
 
54
  /// Parse RISCV ISA info from an arch string that is already in normalized
55
  /// form (as defined in the psABI). Unlike parseArchString, this function
56
  /// will not error for unrecognized extension names or extension versions.
57
  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
58
  parseNormalizedArchString(StringRef Arch);
59
 
60
  /// Parse RISCV ISA info from feature vector.
61
  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
62
  parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
63
 
64
  /// Convert RISCV ISA info to a feature vector.
65
  void toFeatures(std::vector<StringRef> &Features,
66
                  llvm::function_ref<StringRef(const Twine &)> StrAlloc,
67
                  bool AddAllExtensions) const;
68
 
69
  const OrderedExtensionMap &getExtensions() const { return Exts; };
70
 
71
  unsigned getXLen() const { return XLen; };
72
  unsigned getFLen() const { return FLen; };
73
  unsigned getMinVLen() const { return MinVLen; }
74
  unsigned getMaxVLen() const { return 65536; }
75
  unsigned getMaxELen() const { return MaxELen; }
76
  unsigned getMaxELenFp() const { return MaxELenFp; }
77
 
78
  bool hasExtension(StringRef Ext) const;
79
  std::string toString() const;
80
  std::vector<std::string> toFeatureVector() const;
81
  StringRef computeDefaultABI() const;
82
 
83
  static bool isSupportedExtensionFeature(StringRef Ext);
84
  static bool isSupportedExtension(StringRef Ext);
85
  static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
86
                                   unsigned MinorVersion);
87
  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
88
  postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
89
 
90
private:
91
  RISCVISAInfo(unsigned XLen)
92
      : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
93
 
94
  unsigned XLen;
95
  unsigned FLen;
96
  unsigned MinVLen;
97
  unsigned MaxELen, MaxELenFp;
98
 
99
  OrderedExtensionMap Exts;
100
 
101
  void addExtension(StringRef ExtName, unsigned MajorVersion,
102
                    unsigned MinorVersion);
103
 
104
  Error checkDependency();
105
 
106
  void updateImplication();
107
  void updateCombination();
108
  void updateFLen();
109
  void updateMinVLen();
110
  void updateMaxELen();
111
};
112
 
113
} // namespace llvm
114
 
115
#endif