Changes in directory llvm/utils/TableGen:
CodeGenIntrinsics.h updated: 1.5 -> 1.6 IntrinsicEmitter.cpp updated: 1.9 -> 1.10 IntrinsicEmitter.h updated: 1.6 -> 1.7 --- Log message: Autogenerate code to map from GCC builtin to LLVM intrinsic. --- Diffs of the changes: (+59 -1) CodeGenIntrinsics.h | 1 IntrinsicEmitter.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- IntrinsicEmitter.h | 2 + 3 files changed, 59 insertions(+), 1 deletion(-) Index: llvm/utils/TableGen/CodeGenIntrinsics.h diff -u llvm/utils/TableGen/CodeGenIntrinsics.h:1.5 llvm/utils/TableGen/CodeGenIntrinsics.h:1.6 --- llvm/utils/TableGen/CodeGenIntrinsics.h:1.5 Mon Mar 13 17:08:44 2006 +++ llvm/utils/TableGen/CodeGenIntrinsics.h Tue Mar 14 19:33:26 2006 @@ -26,6 +26,7 @@ std::string Name; // The name of the LLVM function "llvm.bswap.i32" std::string EnumName; // The name of the enum "bswap_i32" std::string GCCBuiltinName;// Name of the corresponding GCC builtin, or "". + std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics. /// ArgTypes - The type primitive enum value for the return value and all /// of the arguments. These are things like Type::UIntTyID. Index: llvm/utils/TableGen/IntrinsicEmitter.cpp diff -u llvm/utils/TableGen/IntrinsicEmitter.cpp:1.9 llvm/utils/TableGen/IntrinsicEmitter.cpp:1.10 --- llvm/utils/TableGen/IntrinsicEmitter.cpp:1.9 Mon Mar 13 23:59:52 2006 +++ llvm/utils/TableGen/IntrinsicEmitter.cpp Tue Mar 14 19:33:26 2006 @@ -34,7 +34,7 @@ throw "Intrinsic '" + DefName + "' does not start with 'int_'!"; EnumName = std::string(DefName.begin()+4, DefName.end()); GCCBuiltinName = R->getValueAsString("GCCBuiltinName"); - + TargetPrefix = R->getValueAsString("TargetPrefix"); Name = R->getValueAsString("LLVMName"); if (Name == "") { // If an explicit name isn't specified, derive one from the DefName. @@ -44,6 +44,21 @@ Name += '.'; else Name += EnumName[i]; + } else { + // Verify it starts with "llvm.". + if (Name.size() <= 5 || + std::string(Name.begin(), Name.begin()+5) != "llvm.") + throw "Intrinsic '" + DefName + "'s name does not start with 'llvm.'!"; + } + + // If TargetPrefix is specified, make sure that Name starts with + // "llvm.<targetprefix>.". + if (!TargetPrefix.empty()) { + if (Name.size() < 6+TargetPrefix.size() || + std::string(Name.begin()+5, Name.begin()+6+TargetPrefix.size()) + != (TargetPrefix+".")) + throw "Intrinsic '" + DefName + "' does not start with 'llvm." + + TargetPrefix + ".'!"; } // Parse the list of argument types. @@ -109,6 +124,9 @@ // Emit a list of intrinsics with corresponding GCC builtins. EmitGCCBuiltinList(Ints, OS); + + // Emit code to translate GCC builtins into LLVM intrinsics. + EmitIntrinsicToGCCBuiltinMap(Ints, OS); } void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints, @@ -253,3 +271,40 @@ OS << " }\n"; OS << "#endif\n\n"; } + +void IntrinsicEmitter:: +EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints, + std::ostream &OS) { + typedef std::map<std::pair<std::string, std::string>, std::string> BIMTy; + BIMTy BuiltinMap; + for (unsigned i = 0, e = Ints.size(); i != e; ++i) { + if (!Ints[i].GCCBuiltinName.empty()) { + std::pair<std::string, std::string> Key(Ints[i].GCCBuiltinName, + Ints[i].TargetPrefix); + if (!BuiltinMap.insert(std::make_pair(Key, Ints[i].EnumName)).second) + throw "Intrinsic '" + Ints[i].TheDef->getName() + + "': duplicate GCC builtin name!"; + } + } + + OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n"; + OS << "// This is used by the C front-end. The GCC builtin name is passed\n"; + OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n"; + OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n"; + OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n"; + OS << " if (0);\n"; + // Note: this could emit significantly better code if we cared. + for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){ + OS << " else if ("; + if (!I->first.second.empty()) { + // Emit this as a strcmp, so it can be constant folded by the FE. + OS << "!strcmp(TargetPrefix, \"" << I->first.second << "\") &&\n" + << " "; + } + OS << "!strcmp(BuiltinName, \"" << I->first.first << "\"))\n"; + OS << " IntrinsicID = Intrinsic::" << I->second << "\";\n"; + } + OS << " else\n"; + OS << " IntrinsicID = Intrinsic::not_intrinsic;\n"; + OS << "#endif\n\n"; +} Index: llvm/utils/TableGen/IntrinsicEmitter.h diff -u llvm/utils/TableGen/IntrinsicEmitter.h:1.6 llvm/utils/TableGen/IntrinsicEmitter.h:1.7 --- llvm/utils/TableGen/IntrinsicEmitter.h:1.6 Mon Mar 13 17:08:44 2006 +++ llvm/utils/TableGen/IntrinsicEmitter.h Tue Mar 14 19:33:26 2006 @@ -39,6 +39,8 @@ std::ostream &OS); void EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS); + void EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints, + std::ostream &OS); }; } // End llvm namespace _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits