Added support to have TableGen provide information if an intrinsic (core
authorMon P Wang <wangmp@apple.com>
Tue, 24 Feb 2009 23:17:49 +0000 (23:17 +0000)
committerMon P Wang <wangmp@apple.com>
Tue, 24 Feb 2009 23:17:49 +0000 (23:17 +0000)
or target) can be overloaded or not.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65404 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Intrinsics.h
include/llvm/Target/TargetIntrinsicInfo.h
lib/VMCore/Function.cpp
utils/TableGen/IntrinsicEmitter.cpp
utils/TableGen/IntrinsicEmitter.h

index 243359953bcbe18f2876123aa32578017392e15b..227eb5a5b70f44671962a49cc7aa30964e12ada0 100644 (file)
@@ -49,6 +49,10 @@ namespace Intrinsic {
   ///
   const FunctionType *getType(ID id, const Type **Tys = 0, unsigned numTys = 0);
 
+  /// Intrinsic::isOverloaded(ID) - Returns true if the intrinsic can be
+  /// overloaded.
+  bool isOverloaded(ID id);
+
   /// Intrinsic::getAttributes(ID) - Return the attributes for an intrinsic.
   ///
   AttrListPtr getAttributes(ID id);
index 323e29afee7244dd998eca4cf55d5c43337c9416..c14275f52a4ce1c307e66c71177ddb207756a8f4 100644 (file)
@@ -18,6 +18,7 @@ namespace llvm {
 
 class Function;
 class Module;
+class Type;
 
 //---------------------------------------------------------------------------
 ///
@@ -39,7 +40,19 @@ public:
   virtual Function *getDeclaration(Module *M, const char *BuiltinName) const {
     return 0;
   }
-  
+
+  // Returns the Function declaration for intrinsic BuiltinName.  If the
+  // intrinsic can be overloaded, uses Tys to return the correct function.
+  virtual Function *getDeclaration(Module *M, const char *BuiltinName,
+                                   const Type **Tys, unsigned numTys) const {
+    return 0;
+  }
+
+  // Returns true if the Builtin can be overloaded.
+  virtual bool isOverloaded(Module *M, const char *BuiltinName) const {
+    return false;
+  }
+
   virtual unsigned getIntrinsicID(Function *F) const { return 0; }
 };
 
index bc3b611820c12bb08f10210c440f4aba47fa8f9d..cff4457a41804559cc234545082c87896f011424 100644 (file)
@@ -356,6 +356,16 @@ const FunctionType *Intrinsic::getType(ID id, const Type **Tys,
   return FunctionType::get(ResultTy, ArgTys, IsVarArg); 
 }
 
+bool Intrinsic::isOverloaded(ID id) {
+  const bool OTable[] = {
+    false,
+#define GET_INTRINSIC_OVERLOAD_TABLE
+#include "llvm/Intrinsics.gen"
+#undef GET_INTRINSIC_OVERLOAD_TABLE
+  };
+  return OTable[id];
+}
+
 /// This defines the "Intrinsic::getAttributes(ID id)" method.
 #define GET_INTRINSIC_ATTRIBUTES
 #include "llvm/Intrinsics.gen"
index 37fc6702ede6c24595aa2a2353a5bc8edd5b796b..8800a778164d1d7c80a55a1713cc4f5c2ad7cc02 100644 (file)
@@ -35,7 +35,10 @@ void IntrinsicEmitter::run(std::ostream &OS) {
 
   // Emit the intrinsic ID -> name table.
   EmitIntrinsicToNameTable(Ints, OS);
-  
+
+  // Emit the intrinsic ID -> overload table.
+  EmitIntrinsicToOverloadTable(Ints, OS);
+
   // Emit the function name recognizer.
   EmitFnNameRecognizer(Ints, OS);
   
@@ -120,6 +123,23 @@ EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
   OS << "#endif\n\n";
 }
 
+void IntrinsicEmitter::
+EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints, 
+                         std::ostream &OS) {
+  OS << "// Intrinsic ID to overload table\n";
+  OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n";
+  OS << "  // Note that entry #0 is the invalid intrinsic!\n";
+  for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
+    OS << "  ";
+    if (Ints[i].isOverloaded)
+      OS << "true";
+    else
+      OS << "false";
+    OS << ",\n";
+  }
+  OS << "#endif\n\n";
+}
+
 static void EmitTypeForValueType(std::ostream &OS, MVT::SimpleValueType VT) {
   if (MVT(VT).isInteger()) {
     unsigned BitWidth = MVT(VT).getSizeInBits();
index 4a169ffd64703683db76c9f18f178bba250c3cb7..1619d02242929635a92b9101fa92b60b84ea996c 100644 (file)
@@ -36,6 +36,8 @@ namespace llvm {
                               std::ostream &OS);
     void EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints, 
                                   std::ostream &OS);
+    void EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints, 
+                                      std::ostream &OS);
     void EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints, 
                       std::ostream &OS);
     void EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,