[llvm-commits] [llvm] r105456 - in /llvm/trunk/utils/TableGen: NeonEmitter.cpp NeonEmitter.h TableGen.cpp

Nate Begeman natebegeman at mac.com
Thu Jun 3 18:26:15 PDT 2010


Author: sampo
Date: Thu Jun  3 20:26:15 2010
New Revision: 105456

URL: http://llvm.org/viewvc/llvm-project?rev=105456&view=rev
Log:
BuiltinsARM.def emitter, still needs a substantial bit of tweaking to lighten the load on clang.

Modified:
    llvm/trunk/utils/TableGen/NeonEmitter.cpp
    llvm/trunk/utils/TableGen/NeonEmitter.h
    llvm/trunk/utils/TableGen/TableGen.cpp

Modified: llvm/trunk/utils/TableGen/NeonEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/NeonEmitter.cpp?rev=105456&r1=105455&r2=105456&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/NeonEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/NeonEmitter.cpp Thu Jun  3 20:26:15 2010
@@ -14,46 +14,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "NeonEmitter.h"
-#include "Record.h"
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringMap.h"
 #include <string>
 
 using namespace llvm;
 
-enum OpKind {
-  OpNone,
-  OpAdd,
-  OpSub,
-  OpMul,
-  OpMla,
-  OpMls,
-  OpEq,
-  OpGe,
-  OpLe,
-  OpGt,
-  OpLt,
-  OpNeg,
-  OpNot,
-  OpAnd,
-  OpOr,
-  OpXor,
-  OpAndNot,
-  OpOrNot,
-  OpCast
-};
-
-enum ClassKind {
-  ClassNone,
-  ClassI,
-  ClassS,
-  ClassW,
-  ClassB
-};
-
 static void ParseTypes(Record *r, std::string &s,
                        SmallVectorImpl<StringRef> &TV) {
   const char *data = s.data();
@@ -483,6 +450,20 @@
   return s;
 }
 
+static std::string GenBuiltinDef(const std::string &name, 
+                                 const std::string &proto,
+                                 StringRef typestr, ClassKind ck) {
+  std::string s("BUILTIN(__builtin_neon_");
+  s += MangleName(name, typestr, ck);
+  s += ", \"";
+  
+  for (unsigned i = 0, e = proto.size(); i != e; ++i) {
+  }
+  
+  s += "\", \"n\")";
+  return s;
+}
+
 void NeonEmitter::run(raw_ostream &OS) {
   EmitSourceFileHeader("ARM NEON Header", OS);
   
@@ -539,37 +520,6 @@
 
   std::vector<Record*> RV = Records.getAllDerivedDefinitions("Inst");
   
-  StringMap<OpKind> OpMap;
-  OpMap["OP_NONE"] = OpNone;
-  OpMap["OP_ADD"]  = OpAdd;
-  OpMap["OP_SUB"]  = OpSub;
-  OpMap["OP_MUL"]  = OpMul;
-  OpMap["OP_MLA"]  = OpMla;
-  OpMap["OP_MLS"]  = OpMls;
-  OpMap["OP_EQ"]   = OpEq;
-  OpMap["OP_GE"]   = OpGe;
-  OpMap["OP_LE"]   = OpLe;
-  OpMap["OP_GT"]   = OpGt;
-  OpMap["OP_LT"]   = OpLt;
-  OpMap["OP_NEG"]  = OpNeg;
-  OpMap["OP_NOT"]  = OpNot;
-  OpMap["OP_AND"]  = OpAnd;
-  OpMap["OP_OR"]   = OpOr;
-  OpMap["OP_XOR"]  = OpXor;
-  OpMap["OP_ANDN"] = OpAndNot;
-  OpMap["OP_ORN"]  = OpOrNot;
-  OpMap["OP_CAST"] = OpCast;
-  
-  DenseMap<Record*, ClassKind> ClassMap;
-  Record *SI = Records.getClass("SInst");
-  Record *II = Records.getClass("IInst");
-  Record *WI = Records.getClass("WInst");
-  Record *BI = Records.getClass("BInst");
-  ClassMap[SI] = ClassS;
-  ClassMap[II] = ClassI;
-  ClassMap[WI] = ClassW;
-  ClassMap[BI] = ClassB;
-  
   // Unique the return+pattern types, and assign them.
   for (unsigned i = 0, e = RV.size(); i != e; ++i) {
     Record *R = RV[i];
@@ -614,14 +564,41 @@
     }
     OS << "\n";
   }
-
-  // TODO: 
-  // Unique the return+pattern types, and assign them to each record
-  // Emit a #define for each unique "type" of intrinsic declaring all variants.
-  // Emit a #define for each intrinsic mapping it to a particular type.
-  
+  OS << "#undef __ai\n\n";
   OS << "#endif /* __ARM_NEON_H */\n";
 }
 
 void NeonEmitter::runHeader(raw_ostream &OS) {
+  std::vector<Record*> RV = Records.getAllDerivedDefinitions("Inst");
+
+  StringMap<OpKind> EmittedMap;
+  
+  for (unsigned i = 0, e = RV.size(); i != e; ++i) {
+    Record *R = RV[i];
+
+    OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
+    if (k != OpNone)
+      continue;
+    
+    std::string name = LowercaseString(R->getName());
+    std::string Proto = R->getValueAsString("Prototype");
+    std::string Types = R->getValueAsString("Types");
+
+    SmallVector<StringRef, 16> TypeVec;
+    ParseTypes(R, Types, TypeVec);
+
+    if (R->getSuperClasses().size() < 2)
+      throw TGError(R->getLoc(), "Builtin has no class kind");
+    
+    ClassKind ck = ClassMap[R->getSuperClasses()[1]];
+    
+    for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
+      std::string bd = GenBuiltinDef(name, Proto, TypeVec[ti], ck);
+      if (EmittedMap.count(bd))
+        continue;
+      
+      EmittedMap[bd] = OpNone;
+      OS << bd << "\n";
+    }
+  }
 }

Modified: llvm/trunk/utils/TableGen/NeonEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/NeonEmitter.h?rev=105456&r1=105455&r2=105456&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/NeonEmitter.h (original)
+++ llvm/trunk/utils/TableGen/NeonEmitter.h Thu Jun  3 20:26:15 2010
@@ -16,14 +16,79 @@
 #ifndef NEON_EMITTER_H
 #define NEON_EMITTER_H
 
+#include "Record.h"
 #include "TableGenBackend.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringMap.h"
+
+enum OpKind {
+  OpNone,
+  OpAdd,
+  OpSub,
+  OpMul,
+  OpMla,
+  OpMls,
+  OpEq,
+  OpGe,
+  OpLe,
+  OpGt,
+  OpLt,
+  OpNeg,
+  OpNot,
+  OpAnd,
+  OpOr,
+  OpXor,
+  OpAndNot,
+  OpOrNot,
+  OpCast
+};
+
+enum ClassKind {
+  ClassNone,
+  ClassI,
+  ClassS,
+  ClassW,
+  ClassB
+};
 
 namespace llvm {
   
   class NeonEmitter : public TableGenBackend {
     RecordKeeper &Records;
+    StringMap<OpKind> OpMap;
+    DenseMap<Record*, ClassKind> ClassMap;
+    
   public:
-    NeonEmitter(RecordKeeper &R) : Records(R) {}
+    NeonEmitter(RecordKeeper &R) : Records(R) {
+      OpMap["OP_NONE"] = OpNone;
+      OpMap["OP_ADD"]  = OpAdd;
+      OpMap["OP_SUB"]  = OpSub;
+      OpMap["OP_MUL"]  = OpMul;
+      OpMap["OP_MLA"]  = OpMla;
+      OpMap["OP_MLS"]  = OpMls;
+      OpMap["OP_EQ"]   = OpEq;
+      OpMap["OP_GE"]   = OpGe;
+      OpMap["OP_LE"]   = OpLe;
+      OpMap["OP_GT"]   = OpGt;
+      OpMap["OP_LT"]   = OpLt;
+      OpMap["OP_NEG"]  = OpNeg;
+      OpMap["OP_NOT"]  = OpNot;
+      OpMap["OP_AND"]  = OpAnd;
+      OpMap["OP_OR"]   = OpOr;
+      OpMap["OP_XOR"]  = OpXor;
+      OpMap["OP_ANDN"] = OpAndNot;
+      OpMap["OP_ORN"]  = OpOrNot;
+      OpMap["OP_CAST"] = OpCast;
+
+      Record *SI = R.getClass("SInst");
+      Record *II = R.getClass("IInst");
+      Record *WI = R.getClass("WInst");
+      Record *BI = R.getClass("BInst");
+      ClassMap[SI] = ClassS;
+      ClassMap[II] = ClassI;
+      ClassMap[WI] = ClassW;
+      ClassMap[BI] = ClassB;
+    }
     
     // run - Emit arm_neon.h.inc
     void run(raw_ostream &o);

Modified: llvm/trunk/utils/TableGen/TableGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TableGen.cpp?rev=105456&r1=105455&r2=105456&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/TableGen.cpp (original)
+++ llvm/trunk/utils/TableGen/TableGen.cpp Thu Jun  3 20:26:15 2010
@@ -66,6 +66,7 @@
   GenLLVMCConf,
   GenEDHeader, GenEDInfo,
   GenNeonHeader,
+  GenNeonBuiltinsDef,
   PrintEnums
 };
 
@@ -126,6 +127,8 @@
                                "Generate enhanced disassembly info"),
                     clEnumValN(GenNeonHeader, "gen-arm-neon-header",
                                "Generate arm_neon.h for clang"),
+                    clEnumValN(GenNeonBuiltinsDef, "gen-arm-neon-builtins-def",
+                               "Generate NEON BuiltinsARM.def for clang"),
                     clEnumValN(PrintEnums, "print-enums",
                                "Print enum values for a class"),
                     clEnumValEnd));
@@ -294,6 +297,9 @@
     case GenNeonHeader:
       NeonEmitter(Records).run(Out);
       break;
+    case GenNeonBuiltinsDef:
+      NeonEmitter(Records).runHeader(Out);
+      break;
     case PrintEnums:
     {
       std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);





More information about the llvm-commits mailing list