[llvm-commits] CVS: llvm/utils/TableGen/CodeGenIntrinsics.h IntrinsicEmitter.cpp IntrinsicEmitter.h TableGen.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Mar 2 18:32:58 PST 2006



Changes in directory llvm/utils/TableGen:

CodeGenIntrinsics.h added (r1.1)
IntrinsicEmitter.cpp added (r1.1)
IntrinsicEmitter.h added (r1.1)
TableGen.cpp updated: 1.44 -> 1.45
---
Log message:

initial implementation of intrinsic parsing


---
Diffs of the changes:  (+157 -0)

 CodeGenIntrinsics.h  |   42 ++++++++++++++++++++++++++++++
 IntrinsicEmitter.cpp |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++
 IntrinsicEmitter.h   |   38 +++++++++++++++++++++++++++
 TableGen.cpp         |    7 +++++
 4 files changed, 157 insertions(+)


Index: llvm/utils/TableGen/CodeGenIntrinsics.h
diff -c /dev/null llvm/utils/TableGen/CodeGenIntrinsics.h:1.1
*** /dev/null	Thu Mar  2 20:32:56 2006
--- llvm/utils/TableGen/CodeGenIntrinsics.h	Thu Mar  2 20:32:46 2006
***************
*** 0 ****
--- 1,42 ----
+ //===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===//
+ //
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file defines a wrapper class for the 'Intrinsic' TableGen class.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #ifndef CODEGEN_INTRINSIC_H
+ #define CODEGEN_INTRINSIC_H
+ 
+ #include <string>
+ #include <vector>
+ 
+ namespace llvm {
+   class Record;
+   class RecordKeeper;
+ 
+   struct CodeGenIntrinsic {
+     Record *TheDef;            // The actual record defining this instruction.
+     std::string Name;          // The name of the LLVM function "llvm.bswap.i32"
+     std::string EnumName;      // The name of the enum "bswap_i32"
+ 
+     // Memory mod/ref behavior of this intrinsic.
+     enum {
+       NoMem, ReadArgMem, ReadMem, WriteArgMem, WriteMem
+     } ModRef;
+ 
+     CodeGenIntrinsic(Record *R);
+   };
+ 
+   /// LoadIntrinsics - Read all of the intrinsics defined in the specified
+   /// .td file.
+   std::vector<CodeGenIntrinsic> LoadIntrinsics(const RecordKeeper &RC);
+ }
+ 
+ #endif


Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
diff -c /dev/null llvm/utils/TableGen/IntrinsicEmitter.cpp:1.1
*** /dev/null	Thu Mar  2 20:32:58 2006
--- llvm/utils/TableGen/IntrinsicEmitter.cpp	Thu Mar  2 20:32:46 2006
***************
*** 0 ****
--- 1,70 ----
+ //===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
+ //
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by Chris Lattner and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This tablegen backend emits information about intrinsic functions.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include "IntrinsicEmitter.h"
+ #include "Record.h"
+ using namespace llvm;
+ 
+ //===----------------------------------------------------------------------===//
+ // CodeGenIntrinsic Implementation
+ //===----------------------------------------------------------------------===//
+ 
+ std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC) {
+   std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
+   return std::vector<CodeGenIntrinsic>(I.begin(), I.end());
+ }
+ 
+ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
+   std::string DefName = R->getName();
+   
+   if (DefName.size() <= 4 || 
+       std::string(DefName.begin(), DefName.begin()+4) != "int_")
+     throw "Intrinsic '" + DefName + "' does not start with 'int_'!";
+   EnumName = std::string(DefName.begin()+4, DefName.end());
+   
+   Name = R->getValueAsString("LLVMName");
+   if (Name == "") {
+     // If an explicit name isn't specified, derive one from the DefName.
+     Name = "llvm.";
+     for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
+       if (EnumName[i] == '_')
+         Name += '.';
+       else
+         Name += EnumName[i];
+   }
+ }
+ 
+ //===----------------------------------------------------------------------===//
+ // IntrinsicEmitter Implementation
+ //===----------------------------------------------------------------------===//
+ 
+ void IntrinsicEmitter::run(std::ostream &OS) {
+   EmitSourceFileHeader("Intrinsic Function Source Fragment", OS);
+   
+   std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records);
+ 
+   // Emit the enum information.
+   EmitEnumInfo(Ints, OS);
+ }
+ 
+ void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
+                                     std::ostream &OS) {
+   OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
+   for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
+     OS << "    " << Ints[i].EnumName;
+     OS << ((i != e-1) ? ", " : "  ");
+     OS << std::string(40-Ints[i].EnumName.size(), ' ') 
+       << "// " << Ints[i].Name << "\n";
+   }
+   OS << "#endif\n\n";
+ }


Index: llvm/utils/TableGen/IntrinsicEmitter.h
diff -c /dev/null llvm/utils/TableGen/IntrinsicEmitter.h:1.1
*** /dev/null	Thu Mar  2 20:32:58 2006
--- llvm/utils/TableGen/IntrinsicEmitter.h	Thu Mar  2 20:32:46 2006
***************
*** 0 ****
--- 1,38 ----
+ //===- IntrinsicEmitter.h - Generate intrinsic information ------*- C++ -*-===//
+ //
+ //                     The LLVM Compiler Infrastructure
+ //
+ // This file was developed by Chris Lattner and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This tablegen backend emits information about intrinsic functions.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #ifndef INTRINSIC_EMITTER_H
+ #define INTRINSIC_EMITTER_H
+ 
+ #include "CodeGenIntrinsics.h"
+ #include "TableGenBackend.h"
+ 
+ namespace llvm {
+   class IntrinsicEmitter : public TableGenBackend {
+     RecordKeeper &Records;
+     
+   public:
+     IntrinsicEmitter(RecordKeeper &R) : Records(R) {}
+ 
+     void run(std::ostream &OS);
+     
+     void EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints, 
+                       std::ostream &OS);
+   };
+ 
+ } // End llvm namespace
+ 
+ #endif
+ 
+ 
+ 


Index: llvm/utils/TableGen/TableGen.cpp
diff -u llvm/utils/TableGen/TableGen.cpp:1.44 llvm/utils/TableGen/TableGen.cpp:1.45
--- llvm/utils/TableGen/TableGen.cpp:1.44	Thu Mar  2 19:53:40 2006
+++ llvm/utils/TableGen/TableGen.cpp	Thu Mar  2 20:32:46 2006
@@ -25,6 +25,7 @@
 #include "AsmWriterEmitter.h"
 #include "DAGISelEmitter.h"
 #include "SubtargetEmitter.h"
+#include "IntrinsicEmitter.h"
 #include <algorithm>
 #include <cstdio>
 #include <fstream>
@@ -38,6 +39,7 @@
   GenInstrEnums, GenInstrs, GenAsmWriter, 
   GenDAGISel,
   GenSubtarget,
+  GenIntrinsic,
   PrintEnums,
   Parse
 };
@@ -65,6 +67,8 @@
                                "Generate a DAG instruction selector"),
                     clEnumValN(GenSubtarget, "gen-subtarget",
                                "Generate subtarget enumerations"),
+                    clEnumValN(GenIntrinsic, "gen-intrinsic",
+                               "Generate intrinsic information"),
                     clEnumValN(PrintEnums, "print-enums",
                                "Print enum values for a class"),
                     clEnumValN(Parse, "parse",
@@ -474,6 +478,9 @@
     case GenSubtarget:
       SubtargetEmitter(Records).run(*Out);
       break;
+    case GenIntrinsic:
+      IntrinsicEmitter(Records).run(*Out);
+      break;
     case PrintEnums:
     {
       std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);






More information about the llvm-commits mailing list