From faca5ab1895da74d451d7187dc3f0d4191efeee1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 6 Aug 2003 05:42:05 +0000 Subject: [PATCH] Initial support for an instruction selector emitter git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7631 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../tools/TableGen/InstrSelectorEmitter.cpp | 56 ++++++++++++++++++ support/tools/TableGen/InstrSelectorEmitter.h | 59 +++++++++++++++++++ utils/TableGen/InstrSelectorEmitter.cpp | 56 ++++++++++++++++++ utils/TableGen/InstrSelectorEmitter.h | 59 +++++++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 support/tools/TableGen/InstrSelectorEmitter.cpp create mode 100644 support/tools/TableGen/InstrSelectorEmitter.h create mode 100644 utils/TableGen/InstrSelectorEmitter.cpp create mode 100644 utils/TableGen/InstrSelectorEmitter.h diff --git a/support/tools/TableGen/InstrSelectorEmitter.cpp b/support/tools/TableGen/InstrSelectorEmitter.cpp new file mode 100644 index 00000000000..98bd9943074 --- /dev/null +++ b/support/tools/TableGen/InstrSelectorEmitter.cpp @@ -0,0 +1,56 @@ +//===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===// +// +// This tablegen backend is responsible for emitting a description of the target +// instruction set for the code generator. +// +//===----------------------------------------------------------------------===// + +#include "InstrSelectorEmitter.h" +#include "Record.h" + +NodeType::ArgResultTypes NodeType::Translate(Record *R) { + const std::string &Name = R->getName(); + if (Name == "DNRT_void") return Void; + if (Name == "DNRT_val" || Name == "DNAT_val") return Val; + if (Name == "DNRT_arg0" || Name == "DNAT_arg0") return Arg0; + if (Name == "DNAT_ptr") return Ptr; + throw "Unknown DagNodeResult Type '" + Name + "'!"; +} + + +/// ProcessNodeTypes - Process all of the node types in the current +/// RecordKeeper, turning them into the more accessible NodeTypes data +/// structure. +/// +void InstrSelectorEmitter::ProcessNodeTypes() { + std::vector Nodes = Records.getAllDerivedDefinitions("DagNode"); + + for (unsigned i = 0, e = Nodes.size(); i != e; ++i) { + Record *Node = Nodes[i]; + + // Translate the return type... + NodeType::ArgResultTypes RetTy = + NodeType::Translate(Node->getValueAsDef("RetType")); + + // Translate the arguments... + ListInit *Args = Node->getValueAsListInit("ArgTypes"); + std::vector ArgTypes; + + for (unsigned a = 0, e = Args->getSize(); a != e; ++a) + if (DefInit *DI = dynamic_cast(Args->getElement(a))) + ArgTypes.push_back(NodeType::Translate(DI->getDef())); + else + throw "In node " + Node->getName() + ", argument is not a Def!"; + + // Add the node type mapping now... + NodeTypes[Node] = NodeType(RetTy, ArgTypes); + } +} + +void InstrSelectorEmitter::run(std::ostream &OS) { + // Type-check all of the node types to ensure we "understand" them. + ProcessNodeTypes(); + + + +} diff --git a/support/tools/TableGen/InstrSelectorEmitter.h b/support/tools/TableGen/InstrSelectorEmitter.h new file mode 100644 index 00000000000..5033a417d63 --- /dev/null +++ b/support/tools/TableGen/InstrSelectorEmitter.h @@ -0,0 +1,59 @@ +//===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===// +// +// This tablegen backend is responsible for emitting a description of the target +// instruction set for the code generator. +// +//===----------------------------------------------------------------------===// + +#ifndef INSTRSELECTOR_EMITTER_H +#define INSTRSELECTOR_EMITTER_H + +#include "TableGenBackend.h" +#include +#include + +struct NodeType { + enum ArgResultTypes { + // Both argument and return types... + Val, // A non-void type + Arg0, // Value matches the type of Arg0 + + // Return types + Void, // Tree node always returns void + + // Argument types + Ptr, // Tree node is the target argument type + }; + + ArgResultTypes ResultType; + std::vector ArgTypes; + + NodeType(ArgResultTypes RT, std::vector &AT) : ResultType(RT){ + AT.swap(ArgTypes); + } + + NodeType() : ResultType(Val) {} + NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){} + + static ArgResultTypes Translate(Record *R); + +}; + +class InstrSelectorEmitter : public TableGenBackend { + RecordKeeper &Records; + + std::map NodeTypes; +public: + InstrSelectorEmitter(RecordKeeper &R) : Records(R) {} + + // run - Output the instruction set description, returning true on failure. + void run(std::ostream &OS); + +private: + // ProcessNodeTypes - Process all of the node types in the current + // RecordKeeper, turning them into the more accessible NodeTypes data + // structure. + void ProcessNodeTypes(); +}; + +#endif diff --git a/utils/TableGen/InstrSelectorEmitter.cpp b/utils/TableGen/InstrSelectorEmitter.cpp new file mode 100644 index 00000000000..98bd9943074 --- /dev/null +++ b/utils/TableGen/InstrSelectorEmitter.cpp @@ -0,0 +1,56 @@ +//===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===// +// +// This tablegen backend is responsible for emitting a description of the target +// instruction set for the code generator. +// +//===----------------------------------------------------------------------===// + +#include "InstrSelectorEmitter.h" +#include "Record.h" + +NodeType::ArgResultTypes NodeType::Translate(Record *R) { + const std::string &Name = R->getName(); + if (Name == "DNRT_void") return Void; + if (Name == "DNRT_val" || Name == "DNAT_val") return Val; + if (Name == "DNRT_arg0" || Name == "DNAT_arg0") return Arg0; + if (Name == "DNAT_ptr") return Ptr; + throw "Unknown DagNodeResult Type '" + Name + "'!"; +} + + +/// ProcessNodeTypes - Process all of the node types in the current +/// RecordKeeper, turning them into the more accessible NodeTypes data +/// structure. +/// +void InstrSelectorEmitter::ProcessNodeTypes() { + std::vector Nodes = Records.getAllDerivedDefinitions("DagNode"); + + for (unsigned i = 0, e = Nodes.size(); i != e; ++i) { + Record *Node = Nodes[i]; + + // Translate the return type... + NodeType::ArgResultTypes RetTy = + NodeType::Translate(Node->getValueAsDef("RetType")); + + // Translate the arguments... + ListInit *Args = Node->getValueAsListInit("ArgTypes"); + std::vector ArgTypes; + + for (unsigned a = 0, e = Args->getSize(); a != e; ++a) + if (DefInit *DI = dynamic_cast(Args->getElement(a))) + ArgTypes.push_back(NodeType::Translate(DI->getDef())); + else + throw "In node " + Node->getName() + ", argument is not a Def!"; + + // Add the node type mapping now... + NodeTypes[Node] = NodeType(RetTy, ArgTypes); + } +} + +void InstrSelectorEmitter::run(std::ostream &OS) { + // Type-check all of the node types to ensure we "understand" them. + ProcessNodeTypes(); + + + +} diff --git a/utils/TableGen/InstrSelectorEmitter.h b/utils/TableGen/InstrSelectorEmitter.h new file mode 100644 index 00000000000..5033a417d63 --- /dev/null +++ b/utils/TableGen/InstrSelectorEmitter.h @@ -0,0 +1,59 @@ +//===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===// +// +// This tablegen backend is responsible for emitting a description of the target +// instruction set for the code generator. +// +//===----------------------------------------------------------------------===// + +#ifndef INSTRSELECTOR_EMITTER_H +#define INSTRSELECTOR_EMITTER_H + +#include "TableGenBackend.h" +#include +#include + +struct NodeType { + enum ArgResultTypes { + // Both argument and return types... + Val, // A non-void type + Arg0, // Value matches the type of Arg0 + + // Return types + Void, // Tree node always returns void + + // Argument types + Ptr, // Tree node is the target argument type + }; + + ArgResultTypes ResultType; + std::vector ArgTypes; + + NodeType(ArgResultTypes RT, std::vector &AT) : ResultType(RT){ + AT.swap(ArgTypes); + } + + NodeType() : ResultType(Val) {} + NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){} + + static ArgResultTypes Translate(Record *R); + +}; + +class InstrSelectorEmitter : public TableGenBackend { + RecordKeeper &Records; + + std::map NodeTypes; +public: + InstrSelectorEmitter(RecordKeeper &R) : Records(R) {} + + // run - Output the instruction set description, returning true on failure. + void run(std::ostream &OS); + +private: + // ProcessNodeTypes - Process all of the node types in the current + // RecordKeeper, turning them into the more accessible NodeTypes data + // structure. + void ProcessNodeTypes(); +}; + +#endif -- 2.34.1