From: Chris Lattner Date: Fri, 3 Mar 2006 02:32:46 +0000 (+0000) Subject: initial implementation of intrinsic parsing X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9e493cfcc32aee58e6750ce1efa52d5c3bc3f893;p=oota-llvm.git initial implementation of intrinsic parsing git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26495 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/TableGen/CodeGenIntrinsics.h b/utils/TableGen/CodeGenIntrinsics.h new file mode 100644 index 00000000000..71529966a46 --- /dev/null +++ b/utils/TableGen/CodeGenIntrinsics.h @@ -0,0 +1,42 @@ +//===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines a wrapper class for the 'Intrinsic' TableGen class. +// +//===----------------------------------------------------------------------===// + +#ifndef CODEGEN_INTRINSIC_H +#define CODEGEN_INTRINSIC_H + +#include +#include + +namespace llvm { + class Record; + class RecordKeeper; + + struct CodeGenIntrinsic { + Record *TheDef; // The actual record defining this instruction. + std::string Name; // The name of the LLVM function "llvm.bswap.i32" + std::string EnumName; // The name of the enum "bswap_i32" + + // Memory mod/ref behavior of this intrinsic. + enum { + NoMem, ReadArgMem, ReadMem, WriteArgMem, WriteMem + } ModRef; + + CodeGenIntrinsic(Record *R); + }; + + /// LoadIntrinsics - Read all of the intrinsics defined in the specified + /// .td file. + std::vector LoadIntrinsics(const RecordKeeper &RC); +} + +#endif diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp new file mode 100644 index 00000000000..dd4324ee11c --- /dev/null +++ b/utils/TableGen/IntrinsicEmitter.cpp @@ -0,0 +1,70 @@ +//===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Chris Lattner and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This tablegen backend emits information about intrinsic functions. +// +//===----------------------------------------------------------------------===// + +#include "IntrinsicEmitter.h" +#include "Record.h" +using namespace llvm; + +//===----------------------------------------------------------------------===// +// CodeGenIntrinsic Implementation +//===----------------------------------------------------------------------===// + +std::vector llvm::LoadIntrinsics(const RecordKeeper &RC) { + std::vector I = RC.getAllDerivedDefinitions("Intrinsic"); + return std::vector(I.begin(), I.end()); +} + +CodeGenIntrinsic::CodeGenIntrinsic(Record *R) { + std::string DefName = R->getName(); + + if (DefName.size() <= 4 || + std::string(DefName.begin(), DefName.begin()+4) != "int_") + throw "Intrinsic '" + DefName + "' does not start with 'int_'!"; + EnumName = std::string(DefName.begin()+4, DefName.end()); + + Name = R->getValueAsString("LLVMName"); + if (Name == "") { + // If an explicit name isn't specified, derive one from the DefName. + Name = "llvm."; + for (unsigned i = 0, e = EnumName.size(); i != e; ++i) + if (EnumName[i] == '_') + Name += '.'; + else + Name += EnumName[i]; + } +} + +//===----------------------------------------------------------------------===// +// IntrinsicEmitter Implementation +//===----------------------------------------------------------------------===// + +void IntrinsicEmitter::run(std::ostream &OS) { + EmitSourceFileHeader("Intrinsic Function Source Fragment", OS); + + std::vector Ints = LoadIntrinsics(Records); + + // Emit the enum information. + EmitEnumInfo(Ints, OS); +} + +void IntrinsicEmitter::EmitEnumInfo(const std::vector &Ints, + std::ostream &OS) { + OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n"; + for (unsigned i = 0, e = Ints.size(); i != e; ++i) { + OS << " " << Ints[i].EnumName; + OS << ((i != e-1) ? ", " : " "); + OS << std::string(40-Ints[i].EnumName.size(), ' ') + << "// " << Ints[i].Name << "\n"; + } + OS << "#endif\n\n"; +} diff --git a/utils/TableGen/IntrinsicEmitter.h b/utils/TableGen/IntrinsicEmitter.h new file mode 100644 index 00000000000..debbe4bbcc8 --- /dev/null +++ b/utils/TableGen/IntrinsicEmitter.h @@ -0,0 +1,38 @@ +//===- IntrinsicEmitter.h - Generate intrinsic information ------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Chris Lattner and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This tablegen backend emits information about intrinsic functions. +// +//===----------------------------------------------------------------------===// + +#ifndef INTRINSIC_EMITTER_H +#define INTRINSIC_EMITTER_H + +#include "CodeGenIntrinsics.h" +#include "TableGenBackend.h" + +namespace llvm { + class IntrinsicEmitter : public TableGenBackend { + RecordKeeper &Records; + + public: + IntrinsicEmitter(RecordKeeper &R) : Records(R) {} + + void run(std::ostream &OS); + + void EmitEnumInfo(const std::vector &Ints, + std::ostream &OS); + }; + +} // End llvm namespace + +#endif + + + diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index 366af85bc6e..4c8b3a0fcd3 100644 --- a/utils/TableGen/TableGen.cpp +++ b/utils/TableGen/TableGen.cpp @@ -25,6 +25,7 @@ #include "AsmWriterEmitter.h" #include "DAGISelEmitter.h" #include "SubtargetEmitter.h" +#include "IntrinsicEmitter.h" #include #include #include @@ -38,6 +39,7 @@ enum ActionType { GenInstrEnums, GenInstrs, GenAsmWriter, GenDAGISel, GenSubtarget, + GenIntrinsic, PrintEnums, Parse }; @@ -65,6 +67,8 @@ namespace { "Generate a DAG instruction selector"), clEnumValN(GenSubtarget, "gen-subtarget", "Generate subtarget enumerations"), + clEnumValN(GenIntrinsic, "gen-intrinsic", + "Generate intrinsic information"), clEnumValN(PrintEnums, "print-enums", "Print enum values for a class"), clEnumValN(Parse, "parse", @@ -474,6 +478,9 @@ int main(int argc, char **argv) { case GenSubtarget: SubtargetEmitter(Records).run(*Out); break; + case GenIntrinsic: + IntrinsicEmitter(Records).run(*Out); + break; case PrintEnums: { std::vector Recs = Records.getAllDerivedDefinitions(Class);