123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #pragma once
- #ifdef __GNUC__
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wunused-parameter"
- #endif
- //===-- RISCVISAInfo.h - RISCV ISA Information ------*- C++ -*-===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- #ifndef LLVM_SUPPORT_RISCVISAINFO_H
- #define LLVM_SUPPORT_RISCVISAINFO_H
- #include "llvm/ADT/StringRef.h"
- #include "llvm/Support/Error.h"
- #include <map>
- #include <string>
- #include <vector>
- namespace llvm {
- struct RISCVExtensionInfo {
- std::string ExtName;
- unsigned MajorVersion;
- unsigned MinorVersion;
- };
- class RISCVISAInfo {
- public:
- RISCVISAInfo(const RISCVISAInfo &) = delete;
- RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
- static bool compareExtension(const std::string &LHS, const std::string &RHS);
- /// Helper class for OrderedExtensionMap.
- struct ExtensionComparator {
- bool operator()(const std::string &LHS, const std::string &RHS) const {
- return compareExtension(LHS, RHS);
- }
- };
- /// OrderedExtensionMap is std::map, it's specialized to keep entries
- /// in canonical order of extension.
- typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
- OrderedExtensionMap;
- /// Parse RISCV ISA info from arch string.
- static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
- parseArchString(StringRef Arch, bool EnableExperimentalExtension,
- bool ExperimentalExtensionVersionCheck = true);
- /// Parse RISCV ISA info from feature vector.
- static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
- parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
- /// Convert RISCV ISA info to a feature vector.
- void toFeatures(std::vector<StringRef> &Features,
- std::function<StringRef(const Twine &)> StrAlloc) const;
- const OrderedExtensionMap &getExtensions() const { return Exts; };
- unsigned getXLen() const { return XLen; };
- unsigned getFLen() const { return FLen; };
- unsigned getMinVLen() const { return MinVLen; }
- unsigned getMaxELen() const { return MaxELen; }
- unsigned getMaxELenFp() const { return MaxELenFp; }
- bool hasExtension(StringRef Ext) const;
- std::string toString() const;
- std::vector<std::string> toFeatureVector() const;
- static bool isSupportedExtensionFeature(StringRef Ext);
- static bool isSupportedExtension(StringRef Ext);
- static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
- unsigned MinorVersion);
- private:
- RISCVISAInfo(unsigned XLen)
- : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
- unsigned XLen;
- unsigned FLen;
- unsigned MinVLen;
- unsigned MaxELen, MaxELenFp;
- OrderedExtensionMap Exts;
- void addExtension(StringRef ExtName, unsigned MajorVersion,
- unsigned MinorVersion);
- Error checkDependency();
- void updateImplication();
- void updateFLen();
- void updateMinVLen();
- void updateMaxELen();
- static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
- postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
- };
- } // namespace llvm
- #endif
- #ifdef __GNUC__
- #pragma GCC diagnostic pop
- #endif
|