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

Jim Laskey jlaskey at apple.com
Wed Feb 7 12:38:49 PST 2007



Changes in directory llvm/utils/TableGen:

IntrinsicEmitter.cpp updated: 1.24 -> 1.25
IntrinsicEmitter.h updated: 1.9 -> 1.10
---
Log message:

Automatically generating intrinsic declarations from Dan Gohman.  Modified
to construct FunctionType in separate function, and, have getDeclaration
return a Function instead of a Constant.


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

 IntrinsicEmitter.cpp |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++
 IntrinsicEmitter.h   |    2 +
 2 files changed, 73 insertions(+)


Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
diff -u llvm/utils/TableGen/IntrinsicEmitter.cpp:1.24 llvm/utils/TableGen/IntrinsicEmitter.cpp:1.25
--- llvm/utils/TableGen/IntrinsicEmitter.cpp:1.24	Tue Feb  6 12:30:58 2007
+++ llvm/utils/TableGen/IntrinsicEmitter.cpp	Wed Feb  7 14:38:26 2007
@@ -38,6 +38,9 @@
   // Emit the intrinsic verifier.
   EmitVerifier(Ints, OS);
   
+  // Emit the intrinsic declaration generator.
+  EmitGenerator(Ints, OS);
+  
   // Emit mod/ref info for each function.
   EmitModRefInfo(Ints, OS);
   
@@ -125,6 +128,25 @@
   return false;
 }
 
+static void EmitTypeGenerate(std::ostream &OS, Record *ArgType) {
+  if (ArgType->isSubClassOf("LLVMIntegerType")) {
+    OS << "IntegerType::get(" << ArgType->getValueAsInt("Width") << ")";
+  } else if (ArgType->isSubClassOf("LLVMPackedType")) {
+    OS << "PackedType::get(";
+    EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"));
+    OS << ", " << ArgType->getValueAsInt("NumElts") << ")";
+  } else if (ArgType->isSubClassOf("LLVMPointerType")) {
+    OS << "PointerType::get(";
+    EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"));
+    OS << ")";
+  } else if (ArgType->isSubClassOf("LLVMEmptyStructType")) {
+    OS << "StructType::get(std::vector<const Type *>())";
+  } else {
+    OS << "Type::getPrimitiveType(";
+    OS << ArgType->getValueAsString("TypeVal") << ")";
+  }
+}
+
 /// RecordListComparator - Provide a determinstic comparator for lists of
 /// records.
 namespace {
@@ -188,6 +210,55 @@
   OS << "#endif\n\n";
 }
 
+void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints, 
+                                     std::ostream &OS) {
+  OS << "// Code for generating Intrinsic function declarations.\n";
+  OS << "#ifdef GET_INTRINSIC_GENERATOR\n";
+  OS << "  switch (id) {\n";
+  OS << "  default: assert(0 && \"Invalid intrinsic!\");\n";
+  
+  // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical
+  // types.
+  typedef std::map<std::vector<Record*>, std::vector<unsigned>, 
+    RecordListComparator> MapTy;
+  MapTy UniqueArgInfos;
+  
+  // Compute the unique argument type info.
+  for (unsigned i = 0, e = Ints.size(); i != e; ++i)
+    UniqueArgInfos[Ints[i].ArgTypeDefs].push_back(i);
+
+  // Loop through the array, emitting one generator for each batch.
+  for (MapTy::iterator I = UniqueArgInfos.begin(),
+       E = UniqueArgInfos.end(); I != E; ++I) {
+    for (unsigned i = 0, e = I->second.size(); i != e; ++i) {
+      OS << "  case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
+         << Ints[I->second[i]].Name << "\n";
+    }
+    
+    const std::vector<Record*> &ArgTypes = I->first;
+    unsigned N = ArgTypes.size();
+
+    if (ArgTypes[N-1]->getValueAsString("TypeVal") == "...") {
+      OS << "    IsVarArg = true;\n";
+      --N;
+    }
+    
+    OS << "    ResultTy = ";
+    EmitTypeGenerate(OS, ArgTypes[0]);
+    OS << ";\n";
+    
+    for (unsigned j = 1; j != N; ++j) {
+      OS << "    ArgTys.push_back(";
+      EmitTypeGenerate(OS, ArgTypes[j]);
+      OS << ");\n";
+    }
+    
+    OS << "    break;\n";
+  }
+  OS << "  }\n";
+  OS << "#endif\n\n";
+}
+
 void IntrinsicEmitter::EmitModRefInfo(const std::vector<CodeGenIntrinsic> &Ints,
                                       std::ostream &OS) {
   OS << "// BasicAliasAnalysis code.\n";


Index: llvm/utils/TableGen/IntrinsicEmitter.h
diff -u llvm/utils/TableGen/IntrinsicEmitter.h:1.9 llvm/utils/TableGen/IntrinsicEmitter.h:1.10
--- llvm/utils/TableGen/IntrinsicEmitter.h:1.9	Thu Mar 23 19:13:55 2006
+++ llvm/utils/TableGen/IntrinsicEmitter.h	Wed Feb  7 14:38:26 2007
@@ -35,6 +35,8 @@
                                   std::ostream &OS);
     void EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints, 
                       std::ostream &OS);
+    void EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints, 
+                       std::ostream &OS);
     void EmitModRefInfo(const std::vector<CodeGenIntrinsic> &Ints, 
                         std::ostream &OS);
     void EmitNoMemoryInfo(const std::vector<CodeGenIntrinsic> &Ints, 






More information about the llvm-commits mailing list