[llvm] c49f850 - Migrate `IIT_Info` into `Intrinsics.td`
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 24 16:53:42 PDT 2023
Author: NAKAMURA Takumi
Date: 2023-04-25T08:53:18+09:00
New Revision: c49f850d55221e84c675f03c68fec2801674a4d3
URL: https://github.com/llvm/llvm-project/commit/c49f850d55221e84c675f03c68fec2801674a4d3
DIFF: https://github.com/llvm/llvm-project/commit/c49f850d55221e84c675f03c68fec2801674a4d3.diff
LOG: Migrate `IIT_Info` into `Intrinsics.td`
- Define `IIT_Info` in `Intrinsics.td`
- Implement `EmitIITInfo` in `IntrinsicEmitter.cpp`
- Use generated `IIT_Info` in `Function.cpp`
Depends on D145873 and D146179
Differential Revision: https://reviews.llvm.org/D146914
Added:
Modified:
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/IR/Function.cpp
llvm/utils/TableGen/IntrinsicEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 48372362fdbf..c831c9d21c40 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -182,6 +182,92 @@ def ArgKind {
int MatchType = 7;
}
+//===----------------------------------------------------------------------===//
+// IIT_Info
+//===----------------------------------------------------------------------===//
+
+class IIT_Base<int num> {
+ int Number = num;
+ list<ValueType> VTs = ?;
+}
+
+class IIT_VT<ValueType vt, int num> : IIT_Base<num> {
+ let VTs = [vt];
+}
+
+class IIT_Int<int size, int num> : IIT_Base<num> {
+ let VTs = !filter(vti, ValueTypes,
+ !and(vti.isInteger, !eq(vti.Size, size)));
+}
+
+class IIT_Vec<int nelem, int num> : IIT_Base<num> {
+ let VTs = !filter(vti, ValueTypes,
+ !and(vti.isVector, !eq(vti.nElem, nelem)));
+}
+
+defset list<IIT_Base> IIT_all = {
+def IIT_Done : IIT_Base< 0>;
+def IIT_I1 : IIT_Int<1, 1>;
+def IIT_I8 : IIT_Int<8, 2>;
+def IIT_I16 : IIT_Int<16, 3>;
+def IIT_I32 : IIT_Int<32, 4>;
+def IIT_I64 : IIT_Int<64, 5>;
+def IIT_F16 : IIT_VT<f16, 6>;
+def IIT_F32 : IIT_VT<f32, 7>;
+def IIT_F64 : IIT_VT<f64, 8>;
+def IIT_V2 : IIT_Vec<2, 9>;
+def IIT_V4 : IIT_Vec<4, 10>;
+def IIT_V8 : IIT_Vec<8, 11>;
+def IIT_V16 : IIT_Vec<16, 12>;
+def IIT_V32 : IIT_Vec<32, 13>;
+def IIT_PTR : IIT_Base< 14>;
+def IIT_ARG : IIT_Base< 15>;
+
+def IIT_V64 : IIT_Vec<64, 16>;
+def IIT_MMX : IIT_VT<x86mmx, 17>;
+def IIT_TOKEN : IIT_VT<token, 18>;
+def IIT_METADATA : IIT_VT<MetadataVT, 19>;
+def IIT_EMPTYSTRUCT : IIT_VT<OtherVT, 20>;
+def IIT_STRUCT2 : IIT_Base<21>;
+def IIT_STRUCT3 : IIT_Base<22>;
+def IIT_STRUCT4 : IIT_Base<23>;
+def IIT_STRUCT5 : IIT_Base<24>;
+def IIT_EXTEND_ARG : IIT_Base<25>;
+def IIT_TRUNC_ARG : IIT_Base<26>;
+def IIT_ANYPTR : IIT_Base<27>;
+def IIT_V1 : IIT_Vec<1, 28>;
+def IIT_VARARG : IIT_VT<isVoid, 29>;
+def IIT_HALF_VEC_ARG : IIT_Base<30>;
+def IIT_SAME_VEC_WIDTH_ARG : IIT_Base<31>;
+def IIT_PTR_TO_ARG : IIT_Base<32>;
+def IIT_PTR_TO_ELT : IIT_Base<33>;
+def IIT_VEC_OF_ANYPTRS_TO_ELT : IIT_Base<34>;
+def IIT_I128 : IIT_Int<128, 35>;
+def IIT_V512 : IIT_Vec<512, 36>;
+def IIT_V1024 : IIT_Vec<1024, 37>;
+def IIT_STRUCT6 : IIT_Base<38>;
+def IIT_STRUCT7 : IIT_Base<39>;
+def IIT_STRUCT8 : IIT_Base<40>;
+def IIT_F128 : IIT_VT<f128, 41>;
+def IIT_VEC_ELEMENT : IIT_Base<42>;
+def IIT_SCALABLE_VEC : IIT_Base<43>;
+def IIT_SUBDIVIDE2_ARG : IIT_Base<44>;
+def IIT_SUBDIVIDE4_ARG : IIT_Base<45>;
+def IIT_VEC_OF_BITCASTS_TO_INT : IIT_Base<46>;
+def IIT_V128 : IIT_Vec<128, 47>;
+def IIT_BF16 : IIT_VT<bf16, 48>;
+def IIT_STRUCT9 : IIT_Base<49>;
+def IIT_V256 : IIT_Vec<256, 50>;
+def IIT_AMX : IIT_VT<x86amx, 51>;
+def IIT_PPCF128 : IIT_VT<ppcf128, 52>;
+def IIT_V3 : IIT_Vec<3, 53>;
+def IIT_EXTERNREF : IIT_VT<externref, 54>;
+def IIT_FUNCREF : IIT_VT<funcref, 55>;
+def IIT_ANYPTR_TO_ELT : IIT_Base<56>;
+def IIT_I2 : IIT_Int<2, 57>;
+def IIT_I4 : IIT_Int<4, 58>;
+}
+
//===----------------------------------------------------------------------===//
// Types used by intrinsics.
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 3a214cc91209..bb097e8bec68 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -1023,70 +1023,11 @@ std::string Intrinsic::getNameNoUnnamedTypes(ID Id, ArrayRef<Type *> Tys) {
/// IIT_Info - These are enumerators that describe the entries returned by the
/// getIntrinsicInfoTableEntries function.
///
-/// NOTE: This must be kept in synch with the copy in TblGen/IntrinsicEmitter!
+/// Defined in Intrinsics.td.
enum IIT_Info {
- // Common values should be encoded with 0-15.
- IIT_Done = 0,
- IIT_I1 = 1,
- IIT_I8 = 2,
- IIT_I16 = 3,
- IIT_I32 = 4,
- IIT_I64 = 5,
- IIT_F16 = 6,
- IIT_F32 = 7,
- IIT_F64 = 8,
- IIT_V2 = 9,
- IIT_V4 = 10,
- IIT_V8 = 11,
- IIT_V16 = 12,
- IIT_V32 = 13,
- IIT_PTR = 14,
- IIT_ARG = 15,
-
- // Values from 16+ are only encodable with the inefficient encoding.
- IIT_V64 = 16,
- IIT_MMX = 17,
- IIT_TOKEN = 18,
- IIT_METADATA = 19,
- IIT_EMPTYSTRUCT = 20,
- IIT_STRUCT2 = 21,
- IIT_STRUCT3 = 22,
- IIT_STRUCT4 = 23,
- IIT_STRUCT5 = 24,
- IIT_EXTEND_ARG = 25,
- IIT_TRUNC_ARG = 26,
- IIT_ANYPTR = 27,
- IIT_V1 = 28,
- IIT_VARARG = 29,
- IIT_HALF_VEC_ARG = 30,
- IIT_SAME_VEC_WIDTH_ARG = 31,
- IIT_PTR_TO_ARG = 32,
- IIT_PTR_TO_ELT = 33,
- IIT_VEC_OF_ANYPTRS_TO_ELT = 34,
- IIT_I128 = 35,
- IIT_V512 = 36,
- IIT_V1024 = 37,
- IIT_STRUCT6 = 38,
- IIT_STRUCT7 = 39,
- IIT_STRUCT8 = 40,
- IIT_F128 = 41,
- IIT_VEC_ELEMENT = 42,
- IIT_SCALABLE_VEC = 43,
- IIT_SUBDIVIDE2_ARG = 44,
- IIT_SUBDIVIDE4_ARG = 45,
- IIT_VEC_OF_BITCASTS_TO_INT = 46,
- IIT_V128 = 47,
- IIT_BF16 = 48,
- IIT_STRUCT9 = 49,
- IIT_V256 = 50,
- IIT_AMX = 51,
- IIT_PPCF128 = 52,
- IIT_V3 = 53,
- IIT_EXTERNREF = 54,
- IIT_FUNCREF = 55,
- IIT_ANYPTR_TO_ELT = 56,
- IIT_I2 = 57,
- IIT_I4 = 58,
+#define GET_INTRINSIC_IITINFO
+#include "llvm/IR/IntrinsicImpl.inc"
+#undef GET_INTRINSIC_IITINFO
};
static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index 0e3c9694097c..928debaf38da 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -28,6 +28,7 @@
#include "llvm/TableGen/StringToOffsetTable.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <algorithm>
+#include <array>
#include <cassert>
#include <map>
#include <optional>
@@ -54,6 +55,7 @@ class IntrinsicEmitter {
void EmitEnumInfo(const CodeGenIntrinsicTable &Ints, raw_ostream &OS);
void EmitArgKind(raw_ostream &OS);
+ void EmitIITInfo(raw_ostream &OS);
void EmitTargetInfo(const CodeGenIntrinsicTable &Ints, raw_ostream &OS);
void EmitIntrinsicToNameTable(const CodeGenIntrinsicTable &Ints,
raw_ostream &OS);
@@ -82,6 +84,9 @@ void IntrinsicEmitter::run(raw_ostream &OS, bool Enums) {
// Emit ArgKind for Intrinsics.h.
EmitArgKind(OS);
} else {
+ // Emit IIT_Info constants.
+ EmitIITInfo(OS);
+
// Emit the target metadata.
EmitTargetInfo(Ints, OS);
@@ -180,6 +185,27 @@ void IntrinsicEmitter::EmitArgKind(raw_ostream &OS) {
OS << "#endif\n\n";
}
+void IntrinsicEmitter::EmitIITInfo(raw_ostream &OS) {
+ OS << "#ifdef GET_INTRINSIC_IITINFO\n";
+ std::array<StringRef, 256> RecsByNumber;
+ auto IIT_Base = Records.getAllDerivedDefinitionsIfDefined("IIT_Base");
+ for (auto Rec : IIT_Base) {
+ auto Number = Rec->getValueAsInt("Number");
+ assert(0 <= Number && Number < (int)RecsByNumber.size() &&
+ "IIT_Info.Number should be uint8_t");
+ assert(RecsByNumber[Number].empty() && "Duplicate IIT_Info.Number");
+ RecsByNumber[Number] = Rec->getName();
+ }
+ if (IIT_Base.size() > 0) {
+ for (unsigned I = 0, E = RecsByNumber.size(); I < E; ++I)
+ if (!RecsByNumber[I].empty())
+ OS << " " << RecsByNumber[I] << " = " << I << ",\n";
+ } else {
+ OS << "#error \"class IIT_Base is not defined\"\n";
+ }
+ OS << "#endif\n\n";
+}
+
void IntrinsicEmitter::EmitTargetInfo(const CodeGenIntrinsicTable &Ints,
raw_ostream &OS) {
OS << "// Target mapping\n";
More information about the llvm-commits
mailing list