mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
Add weights to graph edges. Choose between edges based on their weight.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50757 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d83038c960
commit
bb8b58dcf3
@ -33,35 +33,37 @@ extern cl::list<std::string> Languages;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Go through the list C and find the edge that isEnabled(); if
|
// Return the edge with the maximum weight.
|
||||||
// there is no such edge, return the default edge; if there is no
|
|
||||||
// default edge, throw an exception.
|
|
||||||
template <class C>
|
template <class C>
|
||||||
const Edge* ChooseEdge(const C& EdgesContainer,
|
const Edge* ChooseEdge(const C& EdgesContainer,
|
||||||
const std::string& NodeName = "root") {
|
const std::string& NodeName = "root") {
|
||||||
const Edge* DefaultEdge = 0;
|
const Edge* MaxEdge = 0;
|
||||||
|
unsigned MaxWeight = 0;
|
||||||
|
bool SingleMax = true;
|
||||||
|
|
||||||
for (typename C::const_iterator B = EdgesContainer.begin(),
|
for (typename C::const_iterator B = EdgesContainer.begin(),
|
||||||
E = EdgesContainer.end(); B != E; ++B) {
|
E = EdgesContainer.end(); B != E; ++B) {
|
||||||
const Edge* E = B->getPtr();
|
const Edge* E = B->getPtr();
|
||||||
|
unsigned EW = E->Weight();
|
||||||
if (E->isDefault())
|
if (EW > MaxWeight) {
|
||||||
if (!DefaultEdge)
|
MaxEdge = E;
|
||||||
DefaultEdge = E;
|
MaxWeight = EW;
|
||||||
else
|
SingleMax = true;
|
||||||
throw std::runtime_error("Node " + NodeName
|
}
|
||||||
+ ": multiple default outward edges found!"
|
else if (EW == MaxWeight) {
|
||||||
" Most probably a specification error.");
|
SingleMax = false;
|
||||||
if (E->isEnabled())
|
}
|
||||||
return E;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DefaultEdge)
|
if (!SingleMax)
|
||||||
return DefaultEdge;
|
throw std::runtime_error("Node " + NodeName +
|
||||||
else
|
": multiple maximal outward edges found!"
|
||||||
throw std::runtime_error("Node " + NodeName
|
|
||||||
+ ": no default outward edge found!"
|
|
||||||
" Most probably a specification error.");
|
" Most probably a specification error.");
|
||||||
|
if (!MaxEdge)
|
||||||
|
throw std::runtime_error("Node " + NodeName +
|
||||||
|
": no maximal outward edge found!"
|
||||||
|
" Most probably a specification error.");
|
||||||
|
return MaxEdge;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,7 @@ namespace llvmc {
|
|||||||
virtual ~Edge() {};
|
virtual ~Edge() {};
|
||||||
|
|
||||||
const std::string& ToolName() const { return ToolName_; }
|
const std::string& ToolName() const { return ToolName_; }
|
||||||
virtual bool isEnabled() const = 0;
|
virtual unsigned Weight() const = 0;
|
||||||
virtual bool isDefault() const = 0;
|
|
||||||
private:
|
private:
|
||||||
std::string ToolName_;
|
std::string ToolName_;
|
||||||
};
|
};
|
||||||
@ -45,8 +44,7 @@ namespace llvmc {
|
|||||||
class SimpleEdge : public Edge {
|
class SimpleEdge : public Edge {
|
||||||
public:
|
public:
|
||||||
SimpleEdge(const std::string& T) : Edge(T) {}
|
SimpleEdge(const std::string& T) : Edge(T) {}
|
||||||
bool isEnabled() const { return false;}
|
unsigned Weight() const { return 1; }
|
||||||
bool isDefault() const { return true;}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// A node of the compilation graph.
|
// A node of the compilation graph.
|
||||||
|
@ -974,9 +974,9 @@ void EmitEdgeClass(unsigned N, const std::string& Target,
|
|||||||
<< Indent1 << "Edge" << N << "() : Edge(\"" << Target
|
<< Indent1 << "Edge" << N << "() : Edge(\"" << Target
|
||||||
<< "\") {}\n\n"
|
<< "\") {}\n\n"
|
||||||
|
|
||||||
// Function isEnabled().
|
// Function Weight().
|
||||||
<< Indent1 << "bool isEnabled() const {\n"
|
<< Indent1 << "unsigned Weight() const {\n"
|
||||||
<< Indent2 << "bool ret = false;\n";
|
<< Indent2 << "unsigned ret = 0;\n";
|
||||||
|
|
||||||
for (size_t i = 0, PropsSize = Props->size(); i < PropsSize; ++i) {
|
for (size_t i = 0, PropsSize = Props->size(); i < PropsSize; ++i) {
|
||||||
const DagInit& Prop = dynamic_cast<DagInit&>(*Props->getElement(i));
|
const DagInit& Prop = dynamic_cast<DagInit&>(*Props->getElement(i));
|
||||||
@ -985,7 +985,7 @@ void EmitEdgeClass(unsigned N, const std::string& Target,
|
|||||||
if (PropName == "default")
|
if (PropName == "default")
|
||||||
IsDefault = true;
|
IsDefault = true;
|
||||||
|
|
||||||
O << Indent2 << "if (ret || (";
|
O << Indent2 << "if ((";
|
||||||
if (PropName == "and") {
|
if (PropName == "and") {
|
||||||
O << '(';
|
O << '(';
|
||||||
for (unsigned j = 0, NumArgs = Prop.getNumArgs(); j < NumArgs; ++j) {
|
for (unsigned j = 0, NumArgs = Prop.getNumArgs(); j < NumArgs; ++j) {
|
||||||
@ -1002,19 +1002,14 @@ void EmitEdgeClass(unsigned N, const std::string& Target,
|
|||||||
else {
|
else {
|
||||||
EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
|
EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
|
||||||
}
|
}
|
||||||
O << "))\n" << Indent3 << "ret = true;\n";
|
O << "))\n" << Indent3 << "ret += 2;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
O << Indent2 << "return ret;\n"
|
|
||||||
<< Indent1 << "};\n\n"
|
|
||||||
|
|
||||||
// Function isDefault().
|
|
||||||
<< Indent1 << "bool isDefault() const { return ";
|
|
||||||
if (IsDefault)
|
if (IsDefault)
|
||||||
O << "true";
|
O << Indent2 << "ret += 1;\n";
|
||||||
else
|
|
||||||
O << "false";
|
O << Indent2 << "return ret;\n"
|
||||||
O <<"; }\n};\n\n";
|
<< Indent1 << "};\n\n};\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit Edge* classes that represent graph edges.
|
// Emit Edge* classes that represent graph edges.
|
||||||
|
Loading…
Reference in New Issue
Block a user