diff options
author | Roman Levenstein <romix.llvm@googlemail.com> | 2008-05-14 10:17:11 +0000 |
---|---|---|
committer | Roman Levenstein <romix.llvm@googlemail.com> | 2008-05-14 10:17:11 +0000 |
commit | 393ad0f5d2f3d0091d49be0822e432ef19323ba2 (patch) | |
tree | a65abb80f3525c30669d116a9ea23e1bb9e29d99 /utils | |
parent | e810b596a23336ed140038dae0b1091f41ec57a5 (diff) | |
download | external_llvm-393ad0f5d2f3d0091d49be0822e432ef19323ba2.zip external_llvm-393ad0f5d2f3d0091d49be0822e432ef19323ba2.tar.gz external_llvm-393ad0f5d2f3d0091d49be0822e432ef19323ba2.tar.bz2 |
Do not generate by TableGen the hard-coded standard, target-independent part of
DAG instruction selectors. Introudce a dedicated header file for this part:
include/llvm/CodeGen/DAGISelHeader.h
TableGen now only generates the include preprocessor directive to include this
new header.
This is a preparation for supporting multiple implementations of instruction
selectors in the future.
Reviewed and approved by Evan and Dan.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51102 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r-- | utils/TableGen/DAGISelEmitter.cpp | 143 |
1 files changed, 3 insertions, 140 deletions
diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 70d88ce..72bd5bd 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -2011,147 +2011,10 @@ void DAGISelEmitter::run(std::ostream &OS) { OS << "// *** NOTE: This file is #included into the middle of the target\n" << "// *** instruction selector class. These functions are really " << "methods.\n\n"; - - OS << "// Instruction selector priority queue:\n" - << "std::vector<SDNode*> ISelQueue;\n"; - OS << "/// Keep track of nodes which have already been added to queue.\n" - << "unsigned char *ISelQueued;\n"; - OS << "/// Keep track of nodes which have already been selected.\n" - << "unsigned char *ISelSelected;\n"; - - - OS << "/// IsChainCompatible - Returns true if Chain is Op or Chain does\n"; - OS << "/// not reach Op.\n"; - OS << "static bool IsChainCompatible(SDNode *Chain, SDNode *Op) {\n"; - OS << " if (Chain->getOpcode() == ISD::EntryToken)\n"; - OS << " return true;\n"; - OS << " else if (Chain->getOpcode() == ISD::TokenFactor)\n"; - OS << " return false;\n"; - OS << " else if (Chain->getNumOperands() > 0) {\n"; - OS << " SDOperand C0 = Chain->getOperand(0);\n"; - OS << " if (C0.getValueType() == MVT::Other)\n"; - OS << " return C0.Val != Op && IsChainCompatible(C0.Val, Op);\n"; - OS << " }\n"; - OS << " return true;\n"; - OS << "}\n"; - - OS << "/// Sorting functions for the selection queue.\n" - << "struct isel_sort : public std::binary_function" - << "<SDNode*, SDNode*, bool> {\n" - << " bool operator()(const SDNode* left, const SDNode* right) " - << "const {\n" - << " return (left->getNodeId() > right->getNodeId());\n" - << " }\n" - << "};\n\n"; - - OS << "inline void setQueued(int Id) {\n"; - OS << " ISelQueued[Id / 8] |= 1 << (Id % 8);\n"; - OS << "}\n"; - OS << "inline bool isQueued(int Id) {\n"; - OS << " return ISelQueued[Id / 8] & (1 << (Id % 8));\n"; - OS << "}\n"; - OS << "inline void setSelected(int Id) {\n"; - OS << " ISelSelected[Id / 8] |= 1 << (Id % 8);\n"; - OS << "}\n"; - OS << "inline bool isSelected(int Id) {\n"; - OS << " return ISelSelected[Id / 8] & (1 << (Id % 8));\n"; - OS << "}\n\n"; - - OS << "void AddToISelQueue(SDOperand N) DISABLE_INLINE {\n"; - OS << " int Id = N.Val->getNodeId();\n"; - OS << " if (Id != -1 && !isQueued(Id)) {\n"; - OS << " ISelQueue.push_back(N.Val);\n"; - OS << " std::push_heap(ISelQueue.begin(), ISelQueue.end(), isel_sort());\n"; - OS << " setQueued(Id);\n"; - OS << " }\n"; - OS << "}\n\n"; - - OS << "class VISIBILITY_HIDDEN ISelQueueUpdater :\n"; - OS << " public SelectionDAG::DAGUpdateListener {\n"; - OS << " std::vector<SDNode*> &ISelQueue;\n"; - OS << " bool HadDelete;\n"; - OS << " public:\n"; - OS << " explicit ISelQueueUpdater(std::vector<SDNode*> &isq)\n"; - OS << " : ISelQueue(isq), HadDelete(false) {}\n"; - OS << " \n"; - OS << " bool hadDelete() const { return HadDelete; }\n"; - OS << " \n"; - OS << " virtual void NodeDeleted(SDNode *N) {\n"; - OS << " ISelQueue.erase(std::remove(ISelQueue.begin(), ISelQueue.end(),"; - OS << " N),\n ISelQueue.end());\n"; - OS << " HadDelete = true;\n"; - OS << " }\n"; - OS << " \n"; - OS << " // Ignore updates.\n"; - OS << " virtual void NodeUpdated(SDNode *N) {}\n"; - OS << " };\n"; - - OS << "inline void UpdateQueue(const ISelQueueUpdater &ISQU) {\n"; - OS << " if (ISQU.hadDelete())\n"; - OS << " std::make_heap(ISelQueue.begin(), ISelQueue.end(),isel_sort());\n"; - OS << "}\n\n"; - - OS << "void ReplaceUses(SDOperand F, SDOperand T) DISABLE_INLINE {\n"; - OS << " ISelQueueUpdater ISQU(ISelQueue);\n"; - OS << " CurDAG->ReplaceAllUsesOfValueWith(F, T, &ISQU);\n"; - OS << " setSelected(F.Val->getNodeId());\n"; - OS << " UpdateQueue(ISQU);\n"; - OS << "}\n"; - OS << "void ReplaceUses(SDNode *F, SDNode *T) DISABLE_INLINE {\n"; - OS << " unsigned FNumVals = F->getNumValues();\n"; - OS << " unsigned TNumVals = T->getNumValues();\n"; - OS << " ISelQueueUpdater ISQU(ISelQueue);\n"; - OS << " if (FNumVals != TNumVals) {\n"; - OS << " for (unsigned i = 0, e = std::min(FNumVals, TNumVals); " - << "i < e; ++i)\n"; - OS << " CurDAG->ReplaceAllUsesOfValueWith(SDOperand(F, i), " - << "SDOperand(T, i), &ISQU);\n"; - OS << " } else {\n"; - OS << " CurDAG->ReplaceAllUsesWith(F, T, &ISQU);\n"; - OS << " }\n"; - OS << " setSelected(F->getNodeId());\n"; - OS << " UpdateQueue(ISQU);\n"; - OS << "}\n\n"; - - OS << "// SelectRoot - Top level entry to DAG isel.\n"; - OS << "SDOperand SelectRoot(SDOperand Root) {\n"; - OS << " SelectRootInit();\n"; - OS << " unsigned NumBytes = (DAGSize + 7) / 8;\n"; - OS << " ISelQueued = new unsigned char[NumBytes];\n"; - OS << " ISelSelected = new unsigned char[NumBytes];\n"; - OS << " memset(ISelQueued, 0, NumBytes);\n"; - OS << " memset(ISelSelected, 0, NumBytes);\n"; - OS << "\n"; - OS << " // Create a dummy node (which is not added to allnodes), that adds\n" - << " // a reference to the root node, preventing it from being deleted,\n" - << " // and tracking any changes of the root.\n" - << " HandleSDNode Dummy(CurDAG->getRoot());\n" - << " ISelQueue.push_back(CurDAG->getRoot().Val);\n"; - OS << " while (!ISelQueue.empty()) {\n"; - OS << " SDNode *Node = ISelQueue.front();\n"; - OS << " std::pop_heap(ISelQueue.begin(), ISelQueue.end(), isel_sort());\n"; - OS << " ISelQueue.pop_back();\n"; - OS << " if (!isSelected(Node->getNodeId())) {\n"; - OS << " SDNode *ResNode = Select(SDOperand(Node, 0));\n"; - OS << " if (ResNode != Node) {\n"; - OS << " if (ResNode)\n"; - OS << " ReplaceUses(Node, ResNode);\n"; - OS << " if (Node->use_empty()) { // Don't delete EntryToken, etc.\n"; - OS << " ISelQueueUpdater ISQU(ISelQueue);\n"; - OS << " CurDAG->RemoveDeadNode(Node, &ISQU);\n"; - OS << " UpdateQueue(ISQU);\n"; - OS << " }\n"; - OS << " }\n"; - OS << " }\n"; - OS << " }\n"; - OS << "\n"; - OS << " delete[] ISelQueued;\n"; - OS << " ISelQueued = NULL;\n"; - OS << " delete[] ISelSelected;\n"; - OS << " ISelSelected = NULL;\n"; - OS << " return Dummy.getValue();\n"; - OS << "}\n"; + OS << "// Include standard, target-independent definitions and methods used\n" + << "// by the instruction selector.\n"; + OS << "#include <llvm/CodeGen/DAGISelHeader.h>\n\n"; EmitNodeTransforms(OS); EmitPredicateFunctions(OS); |