1//===-- RISCVISAUtils.cpp - RISC-V ISA Utilities --------------------------===//
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
7//===----------------------------------------------------------------------===//
9// Utilities shared by TableGen and RISCVISAInfo.
11//===----------------------------------------------------------------------===//
19// We rank extensions in the following order:
20// -Single letter extensions in canonical order.
21// -Unknown single letter extensions in alphabetical order.
22// -Multi-letter extensions starting with 'z' sorted by canonical order of
23// the second letter then sorted alphabetically.
24// -Multi-letter extensions starting with 's' in alphabetical order.
25// -(TODO) Multi-letter extensions starting with 'zxm' in alphabetical order.
26// -X extensions in alphabetical order.
27// -Unknown multi-letter extensions in alphabetical order.
28// These flags are used to indicate the category. The first 6 bits store the
29// single letter extension rank for single letter and multi-letter extensions
38// Get the rank for single-letter extension, lower value meaning higher
51 return Pos + 2;
// Skip 'e' and 'i' from above.
53 // If we got an unknown extension letter, then give it an alphabetical
54 // order, but after all known standard extensions.
58// Get the rank for multi-letter extension, lower value meaning higher
59// priority/order in canonical order.
61 assert(ExtName.size() >= 1);
66 assert(ExtName.size() >= 2);
67 // `z` extension must be sorted by canonical order of second letter.
68 // e.g. zmx has higher rank than zax.
73 if (ExtName.size() == 1)
79// Compare function for extension.
80// Only compare the extension name, ignore version comparison.
82 const std::string &RHS) {
86 // If the ranks differ, pick the lower rank.
87 if (LHSRank != RHSRank)
88 return LHSRank < RHSRank;
90 // If the rank is same, it must be sorted by lexicographic order.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
@ RF_UNKNOWN_MULTILETTER_EXTENSION
static unsigned getExtensionRank(const std::string &ExtName)
static unsigned singleLetterExtensionRank(char Ext)
static constexpr size_t npos
constexpr StringLiteral AllStdExts
LLVM_ABI bool compareExtension(const std::string &LHS, const std::string &RHS)
This is an optimization pass for GlobalISel generic memory operations.
bool isLower(char C)
Checks if character C is a lowercase letter as classified by "C" locale.