diff options
author | Jim Laskey <jlaskey@mac.com> | 2007-02-07 20:38:26 +0000 |
---|---|---|
committer | Jim Laskey <jlaskey@mac.com> | 2007-02-07 20:38:26 +0000 |
commit | 95af592a631f403e1458ec1155f89fc31011572c (patch) | |
tree | a94263cf593b27cab111ee994ccd56c3e0b4fb94 /utils/TableGen/IntrinsicEmitter.cpp | |
parent | 0d3382ac921c27a702dcd5c14a74d6313334f62e (diff) | |
download | llvm-95af592a631f403e1458ec1155f89fc31011572c.tar.gz llvm-95af592a631f403e1458ec1155f89fc31011572c.tar.bz2 llvm-95af592a631f403e1458ec1155f89fc31011572c.tar.xz |
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
Diffstat (limited to 'utils/TableGen/IntrinsicEmitter.cpp')
-rw-r--r-- | utils/TableGen/IntrinsicEmitter.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
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<const Type *>())"; + } 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<CodeGenIntrinsic> &Ints, OS << "#endif\n\n"; } +void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &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<Record*>, std::vector<unsigned>, + 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<Record*> &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<CodeGenIntrinsic> &Ints, std::ostream &OS) { OS << "// BasicAliasAnalysis code.\n"; |