diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h --- a/llvm/include/llvm/IR/Intrinsics.h +++ b/llvm/include/llvm/IR/Intrinsics.h @@ -149,13 +149,11 @@ 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 --- a/llvm/include/llvm/IR/Intrinsics.td +++ b/llvm/include/llvm/IR/Intrinsics.td @@ -167,6 +167,21 @@ // defined by the hasSideEffects property of the TableGen Instruction class. 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 --- a/llvm/utils/TableGen/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -54,6 +54,7 @@ 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); @@ -78,6 +79,9 @@ if (Enums) { // Emit the enum information. EmitEnumInfo(Ints, OS); + + // Emit ArgKind for Intrinsics.h. + EmitArgKind(OS); } else { // Emit the target metadata. EmitTargetInfo(Ints, OS); @@ -125,7 +129,9 @@ } // Generate a complete header for target specific intrinsics. - if (!IntrinsicPrefix.empty()) { + if (IntrinsicPrefix.empty()) { + OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n"; + } else { std::string UpperPrefix = StringRef(IntrinsicPrefix).upper(); OS << "#ifndef LLVM_IR_INTRINSIC_" << UpperPrefix << "_ENUMS_H\n"; OS << "#define LLVM_IR_INTRINSIC_" << UpperPrefix << "_ENUMS_H\n\n"; @@ -152,6 +158,7 @@ // Emit num_intrinsics into the target neutral enum. if (IntrinsicPrefix.empty()) { OS << " num_intrinsics = " << (Ints.size() + 1) << "\n"; + OS << "#endif\n\n"; } else { OS << "}; // enum\n"; OS << "} // namespace Intrinsic\n"; @@ -160,6 +167,20 @@ } } +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";