[llvm] r258875 - [llvm-tblgen] Stop emitting the intrinsic name matching code

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 15:01:21 PST 2016


Author: rnk
Date: Tue Jan 26 17:01:21 2016
New Revision: 258875

URL: http://llvm.org/viewvc/llvm-project?rev=258875&view=rev
Log:
[llvm-tblgen] Stop emitting the intrinsic name matching code

The AMDGPU backend was the last user of the old StringMatcher
recognition code. Move it over to the new lookupLLVMIntrinsicName
funciton, which is now improved to handle all of the interesting edge
cases exposed by AMDGPU intrinsic names.

Removed:
    llvm/trunk/test/TableGen/intrinsic-order.td
Modified:
    llvm/trunk/lib/Target/AMDGPU/AMDGPUIntrinsicInfo.cpp
    llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp

Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPUIntrinsicInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPUIntrinsicInfo.cpp?rev=258875&r1=258874&r2=258875&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUIntrinsicInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPUIntrinsicInfo.cpp Tue Jan 26 17:01:21 2016
@@ -27,40 +27,43 @@ using namespace llvm;
 AMDGPUIntrinsicInfo::AMDGPUIntrinsicInfo()
     : TargetIntrinsicInfo() {}
 
-std::string AMDGPUIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
-                                         unsigned numTys) const {
-  static const char *const names[] = {
+static const char *const IntrinsicNameTable[] = {
 #define GET_INTRINSIC_NAME_TABLE
 #include "AMDGPUGenIntrinsics.inc"
 #undef GET_INTRINSIC_NAME_TABLE
-  };
+};
 
+std::string AMDGPUIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
+                                         unsigned numTys) const {
   if (IntrID < Intrinsic::num_intrinsics) {
     return nullptr;
   }
   assert(IntrID < AMDGPUIntrinsic::num_AMDGPU_intrinsics &&
          "Invalid intrinsic ID");
 
-  std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
+  std::string Result(IntrinsicNameTable[IntrID - Intrinsic::num_intrinsics]);
   return Result;
 }
 
-unsigned AMDGPUIntrinsicInfo::lookupName(const char *Name,
+unsigned AMDGPUIntrinsicInfo::lookupName(const char *NameData,
                                          unsigned Len) const {
-  if (!StringRef(Name, Len).startswith("llvm."))
+  StringRef Name(NameData, Len);
+  if (!Name.startswith("llvm."))
     return 0; // All intrinsics start with 'llvm.'
 
-#define GET_FUNCTION_RECOGNIZER
-#include "AMDGPUGenIntrinsics.inc"
-#undef GET_FUNCTION_RECOGNIZER
-  AMDGPUIntrinsic::ID IntrinsicID =
-      (AMDGPUIntrinsic::ID)Intrinsic::not_intrinsic;
-  IntrinsicID = getIntrinsicForGCCBuiltin("AMDGPU", Name);
-
-  if (IntrinsicID != (AMDGPUIntrinsic::ID)Intrinsic::not_intrinsic) {
-    return IntrinsicID;
+  // Look for a name match in our table.  If the intrinsic is not overloaded,
+  // require an exact match. If it is overloaded, require a prefix match. The
+  // AMDGPU enum enum starts at Intrinsic::num_intrinsics.
+  int Idx = Intrinsic::lookupLLVMIntrinsicByName(IntrinsicNameTable, Name);
+  if (Idx >= 0) {
+    bool IsPrefixMatch = Name.size() > strlen(IntrinsicNameTable[Idx]);
+    return IsPrefixMatch == isOverloaded(Idx + 1)
+               ? Intrinsic::num_intrinsics + Idx
+               : 0;
   }
-  return 0;
+
+  // Fall back on GCC builtin names.
+  return getIntrinsicForGCCBuiltin("AMDGPU", NameData);
 }
 
 bool AMDGPUIntrinsicInfo::isOverloaded(unsigned id) const {

Removed: llvm/trunk/test/TableGen/intrinsic-order.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/intrinsic-order.td?rev=258874&view=auto
==============================================================================
--- llvm/trunk/test/TableGen/intrinsic-order.td (original)
+++ llvm/trunk/test/TableGen/intrinsic-order.td (removed)
@@ -1,36 +0,0 @@
-// RUN: llvm-tblgen -gen-intrinsic %s | FileCheck %s
-// XFAIL: vg_leak
-
-class IntrinsicProperty;
-
-class ValueType<int size, int value> {
-  string Namespace = "MVT";
-  int Size = size;
-  int Value = value;
-}
-
-class LLVMType<ValueType vt> {
-  ValueType VT = vt;
-}
-
-class Intrinsic<string name, list<LLVMType> param_types = []> {
-  string LLVMName = name;
-  bit isTarget = 0;
-  string TargetPrefix = "";
-  list<LLVMType> RetTypes = [];
-  list<LLVMType> ParamTypes = param_types;
-  list<IntrinsicProperty> Properties = [];
-}
-
-def iAny : ValueType<0, 254>;
-def llvm_anyint_ty : LLVMType<iAny>;
-
-
-// Make sure an intrinsic name that is a prefix of another is checked after the
-// other.
-
-// CHECK: if (NameR.startswith("oo.bar.")) return Intrinsic::foo_bar;
-// CHECK: if (NameR.startswith("oo.")) return Intrinsic::foo;
-
-def int_foo : Intrinsic<"llvm.foo", [llvm_anyint_ty]>;
-def int_foo_bar : Intrinsic<"llvm.foo.bar", [llvm_anyint_ty]>;

Modified: llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp?rev=258875&r1=258874&r2=258875&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp Tue Jan 26 17:01:21 2016
@@ -40,8 +40,6 @@ public:
   void EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
                     raw_ostream &OS);
 
-  void EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
-                            raw_ostream &OS);
   void EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
                                 raw_ostream &OS);
   void EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
@@ -81,9 +79,6 @@ void IntrinsicEmitter::run(raw_ostream &
   // Emit the intrinsic ID -> overload table.
   EmitIntrinsicToOverloadTable(Ints, OS);
 
-  // Emit the function name recognizer.
-  EmitFnNameRecognizer(Ints, OS);
-
   // Emit the intrinsic declaration generator.
   EmitGenerator(Ints, OS);
 
@@ -131,61 +126,6 @@ void IntrinsicEmitter::EmitEnumInfo(cons
   OS << "#endif\n\n";
 }
 
-void IntrinsicEmitter::
-EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
-                     raw_ostream &OS) {
-  // Build a 'first character of function name' -> intrinsic # mapping.
-  std::map<char, std::vector<unsigned> > IntMapping;
-  for (unsigned i = 0, e = Ints.size(); i != e; ++i)
-    IntMapping[Ints[i].Name[5]].push_back(i);
-
-  OS << "// Function name -> enum value recognizer code.\n";
-  OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
-  OS << "  StringRef NameR(Name+6, Len-6);   // Skip over 'llvm.'\n";
-  OS << "  switch (Name[5]) {                  // Dispatch on first letter.\n";
-  OS << "  default: break;\n";
-  // Emit the intrinsic matching stuff by first letter.
-  for (std::map<char, std::vector<unsigned> >::iterator I = IntMapping.begin(),
-       E = IntMapping.end(); I != E; ++I) {
-    OS << "  case '" << I->first << "':\n";
-    std::vector<unsigned> &IntList = I->second;
-
-    // Sort in reverse order of intrinsic name so "abc.def" appears after
-    // "abd.def.ghi" in the overridden name matcher
-    std::sort(IntList.begin(), IntList.end(), [&](unsigned i, unsigned j) {
-      return Ints[i].Name > Ints[j].Name;
-    });
-
-    // Emit all the overloaded intrinsics first, build a table of the
-    // non-overloaded ones.
-    std::vector<StringMatcher::StringPair> MatchTable;
-
-    for (unsigned i = 0, e = IntList.size(); i != e; ++i) {
-      unsigned IntNo = IntList[i];
-      std::string Result = "return " + TargetPrefix + "Intrinsic::" +
-        Ints[IntNo].EnumName + ";";
-
-      if (!Ints[IntNo].isOverloaded) {
-        MatchTable.push_back(std::make_pair(Ints[IntNo].Name.substr(6),Result));
-        continue;
-      }
-
-      // For overloaded intrinsics, only the prefix needs to match
-      std::string TheStr = Ints[IntNo].Name.substr(6);
-      TheStr += '.';  // Require "bswap." instead of bswap.
-      OS << "    if (NameR.startswith(\"" << TheStr << "\")) "
-         << Result << '\n';
-    }
-
-    // Emit the matcher logic for the fixed length strings.
-    StringMatcher("NameR", MatchTable, OS).Emit(1);
-    OS << "    break;  // end of '" << I->first << "' case.\n";
-  }
-
-  OS << "  }\n";
-  OS << "#endif\n\n";
-}
-
 void IntrinsicEmitter::
 EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
                          raw_ostream &OS) {




More information about the llvm-commits mailing list