From 95af592a631f403e1458ec1155f89fc31011572c Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Wed, 7 Feb 2007 20:38:26 +0000 Subject: Automatically generating intrinsic declarations from Dan Gohman. Modified to construct FunctionType in separate function, and, have getDeclaration return a Function instead of a Constant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34008 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/IntrinsicEmitter.cpp | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'utils/TableGen/IntrinsicEmitter.cpp') diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp index ab527521dc..1a70b257f1 100644 --- a/utils/TableGen/IntrinsicEmitter.cpp +++ b/utils/TableGen/IntrinsicEmitter.cpp @@ -38,6 +38,9 @@ void IntrinsicEmitter::run(std::ostream &OS) { // Emit the intrinsic verifier. EmitVerifier(Ints, OS); + // Emit the intrinsic declaration generator. + EmitGenerator(Ints, OS); + // Emit mod/ref info for each function. EmitModRefInfo(Ints, OS); @@ -125,6 +128,25 @@ static bool EmitTypeVerify(std::ostream &OS, Record *ArgType) { return false; } +static void EmitTypeGenerate(std::ostream &OS, Record *ArgType) { + if (ArgType->isSubClassOf("LLVMIntegerType")) { + OS << "IntegerType::get(" << ArgType->getValueAsInt("Width") << ")"; + } else if (ArgType->isSubClassOf("LLVMPackedType")) { + OS << "PackedType::get("; + EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy")); + OS << ", " << ArgType->getValueAsInt("NumElts") << ")"; + } else if (ArgType->isSubClassOf("LLVMPointerType")) { + OS << "PointerType::get("; + EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy")); + OS << ")"; + } else if (ArgType->isSubClassOf("LLVMEmptyStructType")) { + OS << "StructType::get(std::vector())"; + } else { + OS << "Type::getPrimitiveType("; + OS << ArgType->getValueAsString("TypeVal") << ")"; + } +} + /// RecordListComparator - Provide a determinstic comparator for lists of /// records. namespace { @@ -188,6 +210,55 @@ void IntrinsicEmitter::EmitVerifier(const std::vector &Ints, OS << "#endif\n\n"; } +void IntrinsicEmitter::EmitGenerator(const std::vector &Ints, + std::ostream &OS) { + OS << "// Code for generating Intrinsic function declarations.\n"; + OS << "#ifdef GET_INTRINSIC_GENERATOR\n"; + OS << " switch (id) {\n"; + OS << " default: assert(0 && \"Invalid intrinsic!\");\n"; + + // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical + // types. + typedef std::map, std::vector, + RecordListComparator> MapTy; + MapTy UniqueArgInfos; + + // Compute the unique argument type info. + for (unsigned i = 0, e = Ints.size(); i != e; ++i) + UniqueArgInfos[Ints[i].ArgTypeDefs].push_back(i); + + // Loop through the array, emitting one generator for each batch. + for (MapTy::iterator I = UniqueArgInfos.begin(), + E = UniqueArgInfos.end(); I != E; ++I) { + for (unsigned i = 0, e = I->second.size(); i != e; ++i) { + OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// " + << Ints[I->second[i]].Name << "\n"; + } + + const std::vector &ArgTypes = I->first; + unsigned N = ArgTypes.size(); + + if (ArgTypes[N-1]->getValueAsString("TypeVal") == "...") { + OS << " IsVarArg = true;\n"; + --N; + } + + OS << " ResultTy = "; + EmitTypeGenerate(OS, ArgTypes[0]); + OS << ";\n"; + + for (unsigned j = 1; j != N; ++j) { + OS << " ArgTys.push_back("; + EmitTypeGenerate(OS, ArgTypes[j]); + OS << ");\n"; + } + + OS << " break;\n"; + } + OS << " }\n"; + OS << "#endif\n\n"; +} + void IntrinsicEmitter::EmitModRefInfo(const std::vector &Ints, std::ostream &OS) { OS << "// BasicAliasAnalysis code.\n"; -- cgit v1.2.3