mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Clean up hash table usage
Remove opaque pointer used for C compatibility which isn't an issue git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6c5a32d545
commit
75279ccc75
@ -24,69 +24,17 @@
|
|||||||
#ifndef LLVM_CODEGEN_INSTRFOREST_H
|
#ifndef LLVM_CODEGEN_INSTRFOREST_H
|
||||||
#define LLVM_CODEGEN_INSTRFOREST_H
|
#define LLVM_CODEGEN_INSTRFOREST_H
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
#include "llvm/Support/Unique.h"
|
||||||
// Data types needed by BURG and implemented by us
|
#include "llvm/Instruction.h"
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
typedef int OpLabel;
|
|
||||||
typedef int StateLabel;
|
|
||||||
|
|
||||||
typedef struct BasicTreeNode_struct {
|
|
||||||
|
|
||||||
BasicTreeNode_struct* leftChild;
|
|
||||||
BasicTreeNode_struct* rightChild;
|
|
||||||
BasicTreeNode_struct* parent;
|
|
||||||
OpLabel opLabel;
|
|
||||||
StateLabel state;
|
|
||||||
void* treeNodePtr; /* points to the C++ tree node object
|
|
||||||
* that "contains" this node */
|
|
||||||
} BasicTreeNode;
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Declarations of data and functions created by BURG
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern short* burm_nts[];
|
|
||||||
|
|
||||||
extern StateLabel burm_label (BasicTreeNode* p);
|
|
||||||
|
|
||||||
extern StateLabel burm_state (OpLabel op, StateLabel leftState,
|
|
||||||
StateLabel rightState);
|
|
||||||
|
|
||||||
extern StateLabel burm_rule (StateLabel state, int goalNT);
|
|
||||||
|
|
||||||
extern BasicTreeNode** burm_kids (BasicTreeNode* p, int eruleno,
|
|
||||||
BasicTreeNode* kids[]);
|
|
||||||
|
|
||||||
extern void printcover (BasicTreeNode*, int, int);
|
|
||||||
extern void printtree (BasicTreeNode*);
|
|
||||||
extern int treecost (BasicTreeNode*, int, int);
|
|
||||||
extern void printMatches (BasicTreeNode*);
|
|
||||||
|
|
||||||
//************************** System Include Files **************************/
|
|
||||||
|
|
||||||
#include <bool.h>
|
|
||||||
#include <hash_map>
|
#include <hash_map>
|
||||||
#include <hash_set>
|
#include <hash_set>
|
||||||
|
|
||||||
//*************************** User Include Files ***************************/
|
|
||||||
|
|
||||||
#include "llvm/Support/Unique.h"
|
|
||||||
#include "llvm/Instruction.h"
|
|
||||||
|
|
||||||
//************************* Opaque Declarations ****************************/
|
|
||||||
|
|
||||||
class Value;
|
|
||||||
class Instruction;
|
|
||||||
class ConstPoolVal;
|
class ConstPoolVal;
|
||||||
class BasicBlock;
|
class BasicBlock;
|
||||||
class Method;
|
class Method;
|
||||||
class InstrTreeNode;
|
class InstrTreeNode;
|
||||||
class InstrForest;
|
class InstrForest;
|
||||||
|
|
||||||
//************************ Exported Constants ******************************/
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
// OpLabel values for special-case nodes created for instruction selection.
|
// OpLabel values for special-case nodes created for instruction selection.
|
||||||
// All op-labels not defined here are identical to the instruction
|
// All op-labels not defined here are identical to the instruction
|
||||||
@ -122,19 +70,51 @@ const int ToDoubleTy = ToBoolTy + 10;
|
|||||||
const int ToArrayTy = ToBoolTy + 11;
|
const int ToArrayTy = ToBoolTy + 11;
|
||||||
const int ToPointerTy = ToBoolTy + 12;
|
const int ToPointerTy = ToBoolTy + 12;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Data types needed by BURG and implemented by us
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef int OpLabel;
|
||||||
|
typedef int StateLabel;
|
||||||
|
|
||||||
|
struct BasicTreeNode {
|
||||||
|
BasicTreeNode* leftChild;
|
||||||
|
BasicTreeNode* rightChild;
|
||||||
|
BasicTreeNode* parent;
|
||||||
|
OpLabel opLabel;
|
||||||
|
StateLabel state;
|
||||||
|
InstrTreeNode *treeNodePtr; // points to the C++ tree node object
|
||||||
|
// that "contains" this node
|
||||||
|
};
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Declarations of data and functions created by BURG
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern short* burm_nts[];
|
||||||
|
|
||||||
|
extern StateLabel burm_label (BasicTreeNode* p);
|
||||||
|
|
||||||
|
extern StateLabel burm_state (OpLabel op, StateLabel leftState,
|
||||||
|
StateLabel rightState);
|
||||||
|
|
||||||
|
extern StateLabel burm_rule (StateLabel state, int goalNT);
|
||||||
|
|
||||||
|
extern BasicTreeNode** burm_kids (BasicTreeNode* p, int eruleno,
|
||||||
|
BasicTreeNode* kids[]);
|
||||||
|
|
||||||
|
extern void printcover (BasicTreeNode*, int, int);
|
||||||
|
extern void printtree (BasicTreeNode*);
|
||||||
|
extern int treecost (BasicTreeNode*, int, int);
|
||||||
|
extern void printMatches (BasicTreeNode*);
|
||||||
|
|
||||||
//************************ Exported Data Types *****************************/
|
//************************ Exported Data Types *****************************/
|
||||||
|
|
||||||
struct ptrHashFunc {
|
// Provide a hash function for arbitrary pointers...
|
||||||
inline size_t operator()(const void* const& p) const
|
template <class T> struct hash<T *> {
|
||||||
{
|
inline size_t operator()(T *Val) const { return (size_t)Val; }
|
||||||
// Copied from body of hash<unsigned long>::operator().
|
|
||||||
// I cannot figure out how to invoke that without an object
|
|
||||||
return (size_t) ((const unsigned long) p);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
// class InstrTreeNode
|
// class InstrTreeNode
|
||||||
//
|
//
|
||||||
@ -144,7 +124,7 @@ struct ptrHashFunc {
|
|||||||
|
|
||||||
inline InstrTreeNode*
|
inline InstrTreeNode*
|
||||||
MainTreeNode(BasicTreeNode* node) {
|
MainTreeNode(BasicTreeNode* node) {
|
||||||
return (InstrTreeNode*) node->treeNodePtr;
|
return node->treeNodePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -175,8 +155,7 @@ public:
|
|||||||
inline OpLabel getOpLabel () const { return basicNode.opLabel; }
|
inline OpLabel getOpLabel () const { return basicNode.opLabel; }
|
||||||
|
|
||||||
inline InstrTreeNode* leftChild () const {
|
inline InstrTreeNode* leftChild () const {
|
||||||
return (InstrTreeNode*)
|
return (basicNode.leftChild? basicNode.leftChild->treeNodePtr : NULL);
|
||||||
(basicNode.leftChild? basicNode.leftChild->treeNodePtr : NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If right child is a list node, recursively get its *left* child
|
// If right child is a list node, recursively get its *left* child
|
||||||
@ -190,8 +169,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline InstrTreeNode* parent () const {
|
inline InstrTreeNode* parent () const {
|
||||||
return (InstrTreeNode*)
|
return (basicNode.parent? basicNode.parent->treeNodePtr : NULL);
|
||||||
(basicNode.parent? basicNode.parent->treeNodePtr : NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump (int dumpChildren,
|
void dump (int dumpChildren,
|
||||||
@ -262,10 +240,10 @@ protected:
|
|||||||
|
|
||||||
class InstrForest :
|
class InstrForest :
|
||||||
public Unique,
|
public Unique,
|
||||||
private hash_map<const Instruction*, InstructionNode*, ptrHashFunc > {
|
private hash_map<const Instruction*, InstructionNode*> {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hash_set<InstructionNode*, ptrHashFunc > treeRoots;
|
hash_set<InstructionNode*> treeRoots;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*ctor*/ InstrForest () {}
|
/*ctor*/ InstrForest () {}
|
||||||
@ -279,8 +257,7 @@ public:
|
|||||||
return (*this)[instr];
|
return (*this)[instr];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const hash_set<InstructionNode*, ptrHashFunc>&
|
inline const hash_set<InstructionNode*> &getRootSet() const {
|
||||||
getRootSet() const {
|
|
||||||
return treeRoots;
|
return treeRoots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ InstrForest::buildTreesForMethod(Method *method)
|
|||||||
void
|
void
|
||||||
InstrForest::dump() const
|
InstrForest::dump() const
|
||||||
{
|
{
|
||||||
for (hash_set<InstructionNode*, ptrHashFunc >::const_iterator
|
for (hash_set<InstructionNode*>::const_iterator
|
||||||
treeRootIter = treeRoots.begin();
|
treeRootIter = treeRoots.begin();
|
||||||
treeRootIter != treeRoots.end();
|
treeRootIter != treeRoots.end();
|
||||||
++treeRootIter)
|
++treeRootIter)
|
||||||
|
@ -52,13 +52,12 @@ bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
|
|||||||
InstrForest instrForest;
|
InstrForest instrForest;
|
||||||
instrForest.buildTreesForMethod(method);
|
instrForest.buildTreesForMethod(method);
|
||||||
|
|
||||||
const hash_set<InstructionNode*, ptrHashFunc>&
|
const hash_set<InstructionNode*> &treeRoots = instrForest.getRootSet();
|
||||||
treeRoots = instrForest.getRootSet();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Invoke BURG instruction selection for each tree
|
// Invoke BURG instruction selection for each tree
|
||||||
//
|
//
|
||||||
for (hash_set<InstructionNode*, ptrHashFunc >::const_iterator
|
for (hash_set<InstructionNode*>::const_iterator
|
||||||
treeRootIter = treeRoots.begin();
|
treeRootIter = treeRoots.begin();
|
||||||
treeRootIter != treeRoots.end();
|
treeRootIter != treeRoots.end();
|
||||||
++treeRootIter)
|
++treeRootIter)
|
||||||
|
@ -253,7 +253,7 @@ InstrForest::buildTreesForMethod(Method *method)
|
|||||||
void
|
void
|
||||||
InstrForest::dump() const
|
InstrForest::dump() const
|
||||||
{
|
{
|
||||||
for (hash_set<InstructionNode*, ptrHashFunc >::const_iterator
|
for (hash_set<InstructionNode*>::const_iterator
|
||||||
treeRootIter = treeRoots.begin();
|
treeRootIter = treeRoots.begin();
|
||||||
treeRootIter != treeRoots.end();
|
treeRootIter != treeRoots.end();
|
||||||
++treeRootIter)
|
++treeRootIter)
|
||||||
|
@ -52,13 +52,12 @@ bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
|
|||||||
InstrForest instrForest;
|
InstrForest instrForest;
|
||||||
instrForest.buildTreesForMethod(method);
|
instrForest.buildTreesForMethod(method);
|
||||||
|
|
||||||
const hash_set<InstructionNode*, ptrHashFunc>&
|
const hash_set<InstructionNode*> &treeRoots = instrForest.getRootSet();
|
||||||
treeRoots = instrForest.getRootSet();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Invoke BURG instruction selection for each tree
|
// Invoke BURG instruction selection for each tree
|
||||||
//
|
//
|
||||||
for (hash_set<InstructionNode*, ptrHashFunc >::const_iterator
|
for (hash_set<InstructionNode*>::const_iterator
|
||||||
treeRootIter = treeRoots.begin();
|
treeRootIter = treeRoots.begin();
|
||||||
treeRootIter != treeRoots.end();
|
treeRootIter != treeRoots.end();
|
||||||
++treeRootIter)
|
++treeRootIter)
|
||||||
|
Loading…
Reference in New Issue
Block a user