emit a mapping from LLVM intrinsic -> GCC builtins.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26736 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-03-13 23:08:44 +00:00
parent 18faf5d9f7
commit 022f64fbbc
3 changed files with 30 additions and 8 deletions

View File

@ -25,7 +25,8 @@ namespace llvm {
Record *TheDef; // The actual record defining this instruction. Record *TheDef; // The actual record defining this instruction.
std::string Name; // The name of the LLVM function "llvm.bswap.i32" std::string Name; // The name of the LLVM function "llvm.bswap.i32"
std::string EnumName; // The name of the enum "bswap_i32" std::string EnumName; // The name of the enum "bswap_i32"
std::string GCCBuiltinName;// Name of the corresponding GCC builtin, or "".
/// ArgTypes - The type primitive enum value for the return value and all /// ArgTypes - The type primitive enum value for the return value and all
/// of the arguments. These are things like Type::UIntTyID. /// of the arguments. These are things like Type::UIntTyID.
std::vector<std::string> ArgTypes; std::vector<std::string> ArgTypes;

View File

@ -33,6 +33,7 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
std::string(DefName.begin(), DefName.begin()+4) != "int_") std::string(DefName.begin(), DefName.begin()+4) != "int_")
throw "Intrinsic '" + DefName + "' does not start with 'int_'!"; throw "Intrinsic '" + DefName + "' does not start with 'int_'!";
EnumName = std::string(DefName.begin()+4, DefName.end()); EnumName = std::string(DefName.begin()+4, DefName.end());
GCCBuiltinName = R->getValueAsString("GCCBuiltinName");
Name = R->getValueAsString("LLVMName"); Name = R->getValueAsString("LLVMName");
if (Name == "") { if (Name == "") {
@ -105,6 +106,9 @@ void IntrinsicEmitter::run(std::ostream &OS) {
// Emit side effect info for each function. // Emit side effect info for each function.
EmitSideEffectInfo(Ints, OS); EmitSideEffectInfo(Ints, OS);
// Emit a list of intrinsics with corresponding GCC builtins.
EmitGCCBuiltinList(Ints, OS);
} }
void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints, void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
@ -221,16 +225,31 @@ EmitSideEffectInfo(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS){
OS << " default: break;\n"; OS << " default: break;\n";
for (unsigned i = 0, e = Ints.size(); i != e; ++i) { for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
switch (Ints[i].ModRef) { switch (Ints[i].ModRef) {
default: break; default: break;
case CodeGenIntrinsic::NoMem: case CodeGenIntrinsic::NoMem:
case CodeGenIntrinsic::ReadArgMem: case CodeGenIntrinsic::ReadArgMem:
case CodeGenIntrinsic::ReadMem: case CodeGenIntrinsic::ReadMem:
OS << " case Intrinsic::" << Ints[i].EnumName << ":\n"; OS << " case Intrinsic::" << Ints[i].EnumName << ":\n";
break; break;
} }
} }
OS << " return true; // These intrinsics have no side effects.\n"; OS << " return true; // These intrinsics have no side effects.\n";
OS << " }\n"; OS << " }\n";
OS << "#endif\n\n"; OS << "#endif\n\n";
} }
void IntrinsicEmitter::
EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS){
OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n";
OS << "#ifdef GET_GCC_BUILTIN_NAME\n";
OS << " switch (F->getIntrinsicID()) {\n";
OS << " default: BuiltinName = \"\"; break;\n";
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
if (!Ints[i].GCCBuiltinName.empty()) {
OS << " case Intrinsic::" << Ints[i].EnumName << ": BuiltinName = \""
<< Ints[i].GCCBuiltinName << "\"; break;\n";
}
}
OS << " }\n";
OS << "#endif\n\n";
}

View File

@ -37,6 +37,8 @@ namespace llvm {
std::ostream &OS); std::ostream &OS);
void EmitSideEffectInfo(const std::vector<CodeGenIntrinsic> &Ints, void EmitSideEffectInfo(const std::vector<CodeGenIntrinsic> &Ints,
std::ostream &OS); std::ostream &OS);
void EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints,
std::ostream &OS);
}; };
} // End llvm namespace } // End llvm namespace