Skip to content

Commit

Permalink
[RISCV] Generate RISCVISAInfo table from RISCVFeatures.td. (#89955)
Browse files Browse the repository at this point in the history
This generates the SupportedExtensions and ImpliedExts information from
the RISCVExtension records found in RISCVFeatures.td.

Some of the extensions listed in the individual `ImpliedExts*` arrays
may be in a different, but the order in those array doesn't matter. I
manually verified the all the extensions were still present in each
array.

I've added the new information to the existing RISCVTargetParserDef.inc
and RISCVTargetDefEmitter.cpp so we don't need to re-parse the entirety
of RISCV.td a second time for a new file.
  • Loading branch information
topperc committed Apr 25, 2024
1 parent 1c8410a commit 80628ee
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 339 deletions.
323 changes: 4 additions & 319 deletions llvm/lib/TargetParser/RISCVISAInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,204 +47,8 @@ static const char *RISCVGImplications[] = {
"i", "m", "a", "f", "d", "zicsr", "zifencei"
};

// NOTE: This table should be sorted alphabetically by extension name.
static const RISCVSupportedExtension SupportedExtensions[] = {
{"a", {2, 1}},
{"c", {2, 0}},
{"d", {2, 2}},
{"e", {2, 0}},
{"f", {2, 2}},
{"h", {1, 0}},
{"i", {2, 1}},
{"m", {2, 0}},

{"shcounterenw", {1, 0}},
{"shgatpa", {1, 0}},
{"shtvala", {1, 0}},
{"shvsatpa", {1, 0}},
{"shvstvala", {1, 0}},
{"shvstvecd", {1, 0}},
{"smaia", {1, 0}},
{"smepmp", {1, 0}},
{"ssaia", {1, 0}},
{"ssccptr", {1, 0}},
{"sscofpmf", {1, 0}},
{"sscounterenw", {1, 0}},
{"ssstateen", {1, 0}},
{"ssstrict", {1, 0}},
{"sstc", {1, 0}},
{"sstvala", {1, 0}},
{"sstvecd", {1, 0}},
{"ssu64xl", {1, 0}},
{"svade", {1, 0}},
{"svadu", {1, 0}},
{"svbare", {1, 0}},
{"svinval", {1, 0}},
{"svnapot", {1, 0}},
{"svpbmt", {1, 0}},

{"v", {1, 0}},

// vendor-defined ('X') extensions
{"xcvalu", {1, 0}},
{"xcvbi", {1, 0}},
{"xcvbitmanip", {1, 0}},
{"xcvelw", {1, 0}},
{"xcvmac", {1, 0}},
{"xcvmem", {1, 0}},
{"xcvsimd", {1, 0}},
{"xsfcease", {1, 0}},
{"xsfvcp", {1, 0}},
{"xsfvfnrclipxfqf", {1, 0}},
{"xsfvfwmaccqqq", {1, 0}},
{"xsfvqmaccdod", {1, 0}},
{"xsfvqmaccqoq", {1, 0}},
{"xsifivecdiscarddlone", {1, 0}},
{"xsifivecflushdlone", {1, 0}},
{"xtheadba", {1, 0}},
{"xtheadbb", {1, 0}},
{"xtheadbs", {1, 0}},
{"xtheadcmo", {1, 0}},
{"xtheadcondmov", {1, 0}},
{"xtheadfmemidx", {1, 0}},
{"xtheadmac", {1, 0}},
{"xtheadmemidx", {1, 0}},
{"xtheadmempair", {1, 0}},
{"xtheadsync", {1, 0}},
{"xtheadvdot", {1, 0}},
{"xventanacondops", {1, 0}},

{"za128rs", {1, 0}},
{"za64rs", {1, 0}},
{"zacas", {1, 0}},
{"zama16b", {1, 0}},
{"zawrs", {1, 0}},

{"zba", {1, 0}},
{"zbb", {1, 0}},
{"zbc", {1, 0}},
{"zbkb", {1, 0}},
{"zbkc", {1, 0}},
{"zbkx", {1, 0}},
{"zbs", {1, 0}},

{"zca", {1, 0}},
{"zcb", {1, 0}},
{"zcd", {1, 0}},
{"zce", {1, 0}},
{"zcf", {1, 0}},
{"zcmop", {1, 0}},
{"zcmp", {1, 0}},
{"zcmt", {1, 0}},

{"zdinx", {1, 0}},

{"zfa", {1, 0}},
{"zfh", {1, 0}},
{"zfhmin", {1, 0}},
{"zfinx", {1, 0}},

{"zhinx", {1, 0}},
{"zhinxmin", {1, 0}},

{"zic64b", {1, 0}},
{"zicbom", {1, 0}},
{"zicbop", {1, 0}},
{"zicboz", {1, 0}},
{"ziccamoa", {1, 0}},
{"ziccif", {1, 0}},
{"zicclsm", {1, 0}},
{"ziccrse", {1, 0}},
{"zicntr", {2, 0}},
{"zicond", {1, 0}},
{"zicsr", {2, 0}},
{"zifencei", {2, 0}},
{"zihintntl", {1, 0}},
{"zihintpause", {2, 0}},
{"zihpm", {2, 0}},
{"zimop", {1, 0}},

{"zk", {1, 0}},
{"zkn", {1, 0}},
{"zknd", {1, 0}},
{"zkne", {1, 0}},
{"zknh", {1, 0}},
{"zkr", {1, 0}},
{"zks", {1, 0}},
{"zksed", {1, 0}},
{"zksh", {1, 0}},
{"zkt", {1, 0}},

{"zmmul", {1, 0}},

{"zvbb", {1, 0}},
{"zvbc", {1, 0}},

{"zve32f", {1, 0}},
{"zve32x", {1, 0}},
{"zve64d", {1, 0}},
{"zve64f", {1, 0}},
{"zve64x", {1, 0}},

{"zvfh", {1, 0}},
{"zvfhmin", {1, 0}},

// vector crypto
{"zvkb", {1, 0}},
{"zvkg", {1, 0}},
{"zvkn", {1, 0}},
{"zvknc", {1, 0}},
{"zvkned", {1, 0}},
{"zvkng", {1, 0}},
{"zvknha", {1, 0}},
{"zvknhb", {1, 0}},
{"zvks", {1, 0}},
{"zvksc", {1, 0}},
{"zvksed", {1, 0}},
{"zvksg", {1, 0}},
{"zvksh", {1, 0}},
{"zvkt", {1, 0}},

{"zvl1024b", {1, 0}},
{"zvl128b", {1, 0}},
{"zvl16384b", {1, 0}},
{"zvl2048b", {1, 0}},
{"zvl256b", {1, 0}},
{"zvl32768b", {1, 0}},
{"zvl32b", {1, 0}},
{"zvl4096b", {1, 0}},
{"zvl512b", {1, 0}},
{"zvl64b", {1, 0}},
{"zvl65536b", {1, 0}},
{"zvl8192b", {1, 0}},
};

// NOTE: This table should be sorted alphabetically by extension name.
// clang-format off
static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
{"smmpm", {0, 8}},
{"smnpm", {0, 8}},
{"ssnpm", {0, 8}},
{"sspm", {0, 8}},
{"ssqosid", {1, 0}},
{"supm", {0, 8}},

{"zaamo", {0, 2}},
{"zabha", {1, 0}},
{"zalasr", {0, 1}},
{"zalrsc", {0, 2}},

{"zfbfmin", {1, 0}},

{"zicfilp", {0, 4}},
{"zicfiss", {0, 4}},

{"ztso", {0, 1}},

{"zvfbfmin", {1, 0}},
{"zvfbfwma", {1, 0}},
};
// clang-format on
#define GET_SUPPORTED_EXTENSIONS
#include "llvm/TargetParser/RISCVTargetParserDef.inc"

static constexpr RISCVProfile SupportedProfiles[] = {
{"rvi20u32", "rv32i"},
Expand Down Expand Up @@ -1041,66 +845,6 @@ Error RISCVISAInfo::checkDependency() {
return Error::success();
}

static const char *ImpliedExtsD[] = {"f"};
static const char *ImpliedExtsF[] = {"zicsr"};
static const char *ImpliedExtsV[] = {"zvl128b", "zve64d"};
static const char *ImpliedExtsXSfvcp[] = {"zve32x"};
static const char *ImpliedExtsXSfvfnrclipxfqf[] = {"zve32f"};
static const char *ImpliedExtsXSfvfwmaccqqq[] = {"zvfbfmin"};
static const char *ImpliedExtsXSfvqmaccdod[] = {"zve32x"};
static const char *ImpliedExtsXSfvqmaccqoq[] = {"zve32x"};
static const char *ImpliedExtsXTHeadVdot[] = {"v"};
static const char *ImpliedExtsZcb[] = {"zca"};
static const char *ImpliedExtsZcd[] = {"d", "zca"};
static const char *ImpliedExtsZce[] = {"zcb", "zcmp", "zcmt"};
static const char *ImpliedExtsZcf[] = {"f", "zca"};
static const char *ImpliedExtsZcmop[] = {"zca"};
static const char *ImpliedExtsZcmp[] = {"zca"};
static const char *ImpliedExtsZcmt[] = {"zca", "zicsr"};
static const char *ImpliedExtsZdinx[] = {"zfinx"};
static const char *ImpliedExtsZfa[] = {"f"};
static const char *ImpliedExtsZfbfmin[] = {"f"};
static const char *ImpliedExtsZfh[] = {"zfhmin"};
static const char *ImpliedExtsZfhmin[] = {"f"};
static const char *ImpliedExtsZfinx[] = {"zicsr"};
static const char *ImpliedExtsZhinx[] = {"zhinxmin"};
static const char *ImpliedExtsZhinxmin[] = {"zfinx"};
static const char *ImpliedExtsZicfiss[] = {"zicsr", "zimop"};
static const char *ImpliedExtsZicntr[] = {"zicsr"};
static const char *ImpliedExtsZihpm[] = {"zicsr"};
static const char *ImpliedExtsZk[] = {"zkn", "zkt", "zkr"};
static const char *ImpliedExtsZkn[] = {"zbkb", "zbkc", "zbkx",
"zkne", "zknd", "zknh"};
static const char *ImpliedExtsZks[] = {"zbkb", "zbkc", "zbkx", "zksed", "zksh"};
static const char *ImpliedExtsZvbb[] = {"zvkb"};
static const char *ImpliedExtsZve32f[] = {"zve32x", "f"};
static const char *ImpliedExtsZve32x[] = {"zvl32b", "zicsr"};
static const char *ImpliedExtsZve64d[] = {"zve64f", "d"};
static const char *ImpliedExtsZve64f[] = {"zve64x", "zve32f"};
static const char *ImpliedExtsZve64x[] = {"zve32x", "zvl64b"};
static const char *ImpliedExtsZvfbfmin[] = {"zve32f"};
static const char *ImpliedExtsZvfbfwma[] = {"zvfbfmin", "zfbfmin"};
static const char *ImpliedExtsZvfh[] = {"zvfhmin", "zfhmin"};
static const char *ImpliedExtsZvfhmin[] = {"zve32f"};
static const char *ImpliedExtsZvkn[] = {"zvkb", "zvkned", "zvknhb", "zvkt"};
static const char *ImpliedExtsZvknc[] = {"zvbc", "zvkn"};
static const char *ImpliedExtsZvkng[] = {"zvkg", "zvkn"};
static const char *ImpliedExtsZvknhb[] = {"zve64x"};
static const char *ImpliedExtsZvks[] = {"zvkb", "zvksed", "zvksh", "zvkt"};
static const char *ImpliedExtsZvksc[] = {"zvbc", "zvks"};
static const char *ImpliedExtsZvksg[] = {"zvkg", "zvks"};
static const char *ImpliedExtsZvl1024b[] = {"zvl512b"};
static const char *ImpliedExtsZvl128b[] = {"zvl64b"};
static const char *ImpliedExtsZvl16384b[] = {"zvl8192b"};
static const char *ImpliedExtsZvl2048b[] = {"zvl1024b"};
static const char *ImpliedExtsZvl256b[] = {"zvl128b"};
static const char *ImpliedExtsZvl32768b[] = {"zvl16384b"};
static const char *ImpliedExtsZvl4096b[] = {"zvl2048b"};
static const char *ImpliedExtsZvl512b[] = {"zvl256b"};
static const char *ImpliedExtsZvl64b[] = {"zvl32b"};
static const char *ImpliedExtsZvl65536b[] = {"zvl32768b"};
static const char *ImpliedExtsZvl8192b[] = {"zvl4096b"};

struct ImpliedExtsEntry {
StringLiteral Name;
ArrayRef<const char *> Exts;
Expand All @@ -1112,67 +856,8 @@ struct ImpliedExtsEntry {
bool operator<(StringRef Other) const { return Name < Other; }
};

// Note: The table needs to be sorted by name.
static constexpr ImpliedExtsEntry ImpliedExts[] = {
{{"d"}, {ImpliedExtsD}},
{{"f"}, {ImpliedExtsF}},
{{"v"}, {ImpliedExtsV}},
{{"xsfvcp"}, {ImpliedExtsXSfvcp}},
{{"xsfvfnrclipxfqf"}, {ImpliedExtsXSfvfnrclipxfqf}},
{{"xsfvfwmaccqqq"}, {ImpliedExtsXSfvfwmaccqqq}},
{{"xsfvqmaccdod"}, {ImpliedExtsXSfvqmaccdod}},
{{"xsfvqmaccqoq"}, {ImpliedExtsXSfvqmaccqoq}},
{{"xtheadvdot"}, {ImpliedExtsXTHeadVdot}},
{{"zcb"}, {ImpliedExtsZcb}},
{{"zcd"}, {ImpliedExtsZcd}},
{{"zce"}, {ImpliedExtsZce}},
{{"zcf"}, {ImpliedExtsZcf}},
{{"zcmop"}, {ImpliedExtsZcmop}},
{{"zcmp"}, {ImpliedExtsZcmp}},
{{"zcmt"}, {ImpliedExtsZcmt}},
{{"zdinx"}, {ImpliedExtsZdinx}},
{{"zfa"}, {ImpliedExtsZfa}},
{{"zfbfmin"}, {ImpliedExtsZfbfmin}},
{{"zfh"}, {ImpliedExtsZfh}},
{{"zfhmin"}, {ImpliedExtsZfhmin}},
{{"zfinx"}, {ImpliedExtsZfinx}},
{{"zhinx"}, {ImpliedExtsZhinx}},
{{"zhinxmin"}, {ImpliedExtsZhinxmin}},
{{"zicfiss"}, {ImpliedExtsZicfiss}},
{{"zicntr"}, {ImpliedExtsZicntr}},
{{"zihpm"}, {ImpliedExtsZihpm}},
{{"zk"}, {ImpliedExtsZk}},
{{"zkn"}, {ImpliedExtsZkn}},
{{"zks"}, {ImpliedExtsZks}},
{{"zvbb"}, {ImpliedExtsZvbb}},
{{"zve32f"}, {ImpliedExtsZve32f}},
{{"zve32x"}, {ImpliedExtsZve32x}},
{{"zve64d"}, {ImpliedExtsZve64d}},
{{"zve64f"}, {ImpliedExtsZve64f}},
{{"zve64x"}, {ImpliedExtsZve64x}},
{{"zvfbfmin"}, {ImpliedExtsZvfbfmin}},
{{"zvfbfwma"}, {ImpliedExtsZvfbfwma}},
{{"zvfh"}, {ImpliedExtsZvfh}},
{{"zvfhmin"}, {ImpliedExtsZvfhmin}},
{{"zvkn"}, {ImpliedExtsZvkn}},
{{"zvknc"}, {ImpliedExtsZvknc}},
{{"zvkng"}, {ImpliedExtsZvkng}},
{{"zvknhb"}, {ImpliedExtsZvknhb}},
{{"zvks"}, {ImpliedExtsZvks}},
{{"zvksc"}, {ImpliedExtsZvksc}},
{{"zvksg"}, {ImpliedExtsZvksg}},
{{"zvl1024b"}, {ImpliedExtsZvl1024b}},
{{"zvl128b"}, {ImpliedExtsZvl128b}},
{{"zvl16384b"}, {ImpliedExtsZvl16384b}},
{{"zvl2048b"}, {ImpliedExtsZvl2048b}},
{{"zvl256b"}, {ImpliedExtsZvl256b}},
{{"zvl32768b"}, {ImpliedExtsZvl32768b}},
{{"zvl4096b"}, {ImpliedExtsZvl4096b}},
{{"zvl512b"}, {ImpliedExtsZvl512b}},
{{"zvl64b"}, {ImpliedExtsZvl64b}},
{{"zvl65536b"}, {ImpliedExtsZvl65536b}},
{{"zvl8192b"}, {ImpliedExtsZvl8192b}},
};
#define GET_IMPLIED_EXTENSIONS
#include "llvm/TargetParser/RISCVTargetParserDef.inc"

void RISCVISAInfo::updateImplication() {
bool HasE = Exts.count("e") != 0;
Expand Down
Loading

0 comments on commit 80628ee

Please sign in to comment.