From 8922a1c15ba24ca3449fc475998bc037608d428b Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Thu, 9 Mar 2023 00:50:45 +0900 Subject: [PATCH] Move definitions of ArgKind from Intrinsics.h to Intrinsics.td Values of ArgKind are used (as naked constants) also in IntrinsicEmitter. They can be dissolved to move their logic to Intrinsics.td. Differential Revision: https://reviews.llvm.org/D145873 --- llvm/include/llvm/IR/Intrinsics.h | 10 ++++------ llvm/include/llvm/IR/Intrinsics.td | 15 +++++++++++++++ llvm/utils/TableGen/IntrinsicEmitter.cpp | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h index 9bb7c86..c677983 100644 --- a/llvm/include/llvm/IR/Intrinsics.h +++ b/llvm/include/llvm/IR/Intrinsics.h @@ -149,13 +149,11 @@ namespace Intrinsic { ElementCount Vector_Width; }; + // AK_% : Defined in Intrinsics.td enum ArgKind { - AK_Any, - AK_AnyInteger, - AK_AnyFloat, - AK_AnyVector, - AK_AnyPointer, - AK_MatchType = 7 +#define GET_INTRINSIC_ARGKIND +#include "llvm/IR/IntrinsicEnums.inc" +#undef GET_INTRINSIC_ARGKIND }; unsigned getArgumentNumber() const { diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td index c24f53c..5962471 100644 --- a/llvm/include/llvm/IR/Intrinsics.td +++ b/llvm/include/llvm/IR/Intrinsics.td @@ -168,6 +168,21 @@ def IntrSpeculatable : IntrinsicProperty; def IntrHasSideEffects : IntrinsicProperty; //===----------------------------------------------------------------------===// +// IIT constants and utils +//===----------------------------------------------------------------------===// + +// llvm::Intrinsic::IITDescriptor::ArgKind::AK_% +def ArgKind { + int Any = 0; + int AnyInteger = 1; + int AnyFloat = 2; + int AnyVector = 3; + int AnyPointer = 4; + + int MatchType = 7; +} + +//===----------------------------------------------------------------------===// // Types used by intrinsics. //===----------------------------------------------------------------------===// diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp index e931828..0e3c9694 100644 --- a/llvm/utils/TableGen/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -53,6 +53,7 @@ public: void run(raw_ostream &OS, bool Enums); void EmitEnumInfo(const CodeGenIntrinsicTable &Ints, raw_ostream &OS); + void EmitArgKind(raw_ostream &OS); void EmitTargetInfo(const CodeGenIntrinsicTable &Ints, raw_ostream &OS); void EmitIntrinsicToNameTable(const CodeGenIntrinsicTable &Ints, raw_ostream &OS); @@ -77,6 +78,9 @@ void IntrinsicEmitter::run(raw_ostream &OS, bool Enums) { if (Enums) { // Emit the enum information. EmitEnumInfo(Ints, OS); + + // Emit ArgKind for Intrinsics.h. + EmitArgKind(OS); } else { // Emit the target metadata. EmitTargetInfo(Ints, OS); @@ -162,6 +166,20 @@ void IntrinsicEmitter::EmitEnumInfo(const CodeGenIntrinsicTable &Ints, } } +void IntrinsicEmitter::EmitArgKind(raw_ostream &OS) { + if (!IntrinsicPrefix.empty()) + return; + OS << "// llvm::Intrinsic::IITDescriptor::ArgKind\n"; + OS << "#ifdef GET_INTRINSIC_ARGKIND\n"; + if (auto RecArgKind = Records.getDef("ArgKind")) { + for (auto &RV : RecArgKind->getValues()) + OS << " AK_" << RV.getName() << " = " << *RV.getValue() << ",\n"; + } else { + OS << "#error \"ArgKind is not defined\"\n"; + } + OS << "#endif\n\n"; +} + void IntrinsicEmitter::EmitTargetInfo(const CodeGenIntrinsicTable &Ints, raw_ostream &OS) { OS << "// Target mapping\n"; -- 2.7.4