From 0d52ff1f7b993750a74a5d4432273092de9af069 Mon Sep 17 00:00:00 2001 From: Mon P Wang Date: Tue, 24 Feb 2009 23:17:49 +0000 Subject: [PATCH] Added support to have TableGen provide information if an intrinsic (core 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 | 4 ++++ include/llvm/Target/TargetIntrinsicInfo.h | 15 ++++++++++++++- lib/VMCore/Function.cpp | 10 ++++++++++ utils/TableGen/IntrinsicEmitter.cpp | 22 +++++++++++++++++++++- utils/TableGen/IntrinsicEmitter.h | 2 ++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/include/llvm/Intrinsics.h b/include/llvm/Intrinsics.h index 243359953bc..227eb5a5b70 100644 --- a/include/llvm/Intrinsics.h +++ b/include/llvm/Intrinsics.h @@ -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); diff --git a/include/llvm/Target/TargetIntrinsicInfo.h b/include/llvm/Target/TargetIntrinsicInfo.h index 323e29afee7..c14275f52a4 100644 --- a/include/llvm/Target/TargetIntrinsicInfo.h +++ b/include/llvm/Target/TargetIntrinsicInfo.h @@ -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; } }; diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index bc3b611820c..cff4457a418 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -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" diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp index 37fc6702ede..8800a778164 100644 --- a/utils/TableGen/IntrinsicEmitter.cpp +++ b/utils/TableGen/IntrinsicEmitter.cpp @@ -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 &Ints, OS << "#endif\n\n"; } +void IntrinsicEmitter:: +EmitIntrinsicToOverloadTable(const std::vector &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(); diff --git a/utils/TableGen/IntrinsicEmitter.h b/utils/TableGen/IntrinsicEmitter.h index 4a169ffd647..1619d022429 100644 --- a/utils/TableGen/IntrinsicEmitter.h +++ b/utils/TableGen/IntrinsicEmitter.h @@ -36,6 +36,8 @@ namespace llvm { std::ostream &OS); void EmitIntrinsicToNameTable(const std::vector &Ints, std::ostream &OS); + void EmitIntrinsicToOverloadTable(const std::vector &Ints, + std::ostream &OS); void EmitVerifier(const std::vector &Ints, std::ostream &OS); void EmitGenerator(const std::vector &Ints,