diff --git a/llvm/utils/TableGen/CodeGenIntrinsics.h b/llvm/utils/TableGen/CodeGenIntrinsics.h index 5315856a9e0330461c49525205cf4af35cad959e..7404c70e22ab5cc16b37099b7e51baa8cfcfccd8 100644 --- a/llvm/utils/TableGen/CodeGenIntrinsics.h +++ b/llvm/utils/TableGen/CodeGenIntrinsics.h @@ -26,6 +26,10 @@ namespace llvm { std::string Name; // The name of the LLVM function "llvm.bswap.i32" std::string EnumName; // The name of the enum "bswap_i32" + /// ArgTypes - The type primitive enum value for the return value and all + /// of the arguments. These are things like Type::UIntTyID. + std::vector ArgTypes; + // Memory mod/ref behavior of this intrinsic. enum { NoMem, ReadArgMem, ReadMem, WriteArgMem, WriteMem diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp index 902c261c8802b83ac98db4ec5e4d802d86b12cc7..8981311def2ee30be4a8432e92a2f964bd46bd26 100644 --- a/llvm/utils/TableGen/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -42,6 +42,18 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) { else Name += EnumName[i]; } + + // Parse the list of argument types. + ListInit *TypeList = R->getValueAsListInit("Types"); + for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) { + DefInit *DI = dynamic_cast(TypeList->getElement(i)); + assert(DI && "Invalid list type!"); + Record *TyEl = DI->getDef(); + assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!"); + ArgTypes.push_back(TyEl->getValueAsString("TypeVal")); + } + if (ArgTypes.size() == 0) + throw "Intrinsic '"+DefName+"' needs at least a type for the ret value!"; } //===----------------------------------------------------------------------===// @@ -58,6 +70,9 @@ void IntrinsicEmitter::run(std::ostream &OS) { // Emit the function name recognizer. EmitFnNameRecognizer(Ints, OS); + + // Emit the intrinsic verifier. + EmitVerifier(Ints, OS); } void IntrinsicEmitter::EmitEnumInfo(const std::vector &Ints, @@ -84,8 +99,7 @@ EmitFnNameRecognizer(const std::vector &Ints, OS << "// Function name -> enum value recognizer code.\n"; OS << "#ifdef GET_FUNCTION_RECOGNIZER\n"; OS << " switch (Name[5]) {\n"; - OS << " // The 'llvm.' namespace is reserved!\n"; - OS << " default: assert(0 && \"Unknown LLVM intrinsic function!\");\n"; + OS << " default: break;\n"; // Emit the intrinsics in sorted order. char LastChar = 0; for (std::map::iterator I = IntMapping.begin(), @@ -102,6 +116,33 @@ EmitFnNameRecognizer(const std::vector &Ints, << I->second << ";\n"; } OS << " }\n"; - OS << "#endif\n"; + OS << " // The 'llvm.' namespace is reserved!\n"; + OS << " assert(0 && \"Unknown LLVM intrinsic function!\");\n"; + OS << "#endif\n\n"; +} + +void IntrinsicEmitter::EmitVerifier(const std::vector &Ints, + std::ostream &OS) { + OS << "// Verifier::visitIntrinsicFunctionCall code.\n"; + OS << "#ifdef GET_INTRINSIC_VERIFIER\n"; + OS << " switch (ID) {\n"; + OS << " default: assert(0 && \"Invalid intrinsic!\");\n"; + for (unsigned i = 0, e = Ints.size(); i != e; ++i) { + OS << " case Intrinsic::" << Ints[i].EnumName << ":\t\t// " + << Ints[i].Name << "\n"; + OS << " Assert1(FTy->getNumParams() == " << Ints[i].ArgTypes.size()-1 + << ",\n" + << " \"Illegal # arguments for intrinsic function!\", IF);\n"; + OS << " Assert1(FTy->getReturnType()->getTypeID() == " + << Ints[i].ArgTypes[0] << ",\n" + << " \"Illegal result type!\", IF);\n"; + for (unsigned j = 1; j != Ints[i].ArgTypes.size(); ++j) + OS << " Assert1(FTy->getParamType(" << j-1 << ")->getTypeID() == " + << Ints[i].ArgTypes[j] << ",\n" + << " \"Illegal result type!\", IF);\n"; + OS << " break;\n"; + } + OS << " }\n"; + OS << "#endif\n\n"; } diff --git a/llvm/utils/TableGen/IntrinsicEmitter.h b/llvm/utils/TableGen/IntrinsicEmitter.h index 5ce12da802a6b1731055a1aeac4ccedc2c7785ae..f09f6f633b43a8f6792f8d321e8c785d9cda2319 100644 --- a/llvm/utils/TableGen/IntrinsicEmitter.h +++ b/llvm/utils/TableGen/IntrinsicEmitter.h @@ -31,7 +31,8 @@ namespace llvm { void EmitFnNameRecognizer(const std::vector &Ints, std::ostream &OS); - + void EmitVerifier(const std::vector &Ints, + std::ostream &OS); }; } // End llvm namespace