<div class="gmail_quote">On Wed, Jun 27, 2012 at 11:38 PM, Anshuman Dasgupta <span dir="ltr"><<a href="mailto:adasgupt@codeaurora.org" target="_blank">adasgupt@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: adasgupt<br>
Date: Wed Jun 27 14:38:29 2012<br>
New Revision: 159281<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=159281&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=159281&view=rev</a><br>
Log:<br>
Refactor and speed up DFA generator.<br>
<br>
Patch by Ivan Llopard!<br>
<br>
Modified:<br>
    llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp<br>
<br>
Modified: llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp?rev=159281&r1=159280&r2=159281&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp?rev=159281&r1=159280&r2=159281&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp (original)<br>
+++ llvm/trunk/utils/TableGen/DFAPacketizerEmitter.cpp Wed Jun 27 14:38:29 2012<br>
@@ -94,7 +94,12 @@<br>
   // PossibleStates is the set of valid resource states that ensue from valid<br>
   // transitions.<br>
   //<br>
-  bool canAddInsnClass(unsigned InsnClass, std::set<unsigned> &PossibleStates);<br>
+  bool canAddInsnClass(unsigned InsnClass) const;<br>
+  //<br>
+  // AddInsnClass - Return all combinations of resource reservation<br>
+  // which are possible from this state (PossibleStates).<br>
+  //<br>
+  void AddInsnClass(unsigned InsnClass, std::set<unsigned> &PossibleStates);<br>
 };<br>
 } // End anonymous namespace.<br>
<br>
@@ -120,6 +125,10 @@<br>
 struct ltState {<br>
   bool operator()(const State *s1, const State *s2) const;<br>
 };<br>
+<br>
+struct ltTransition {<br>
+  bool operator()(const Transition *s1, const Transition *s2) const;<br>
+};<br>
 } // End anonymous namespace.<br>
<br>
<br>
@@ -135,7 +144,8 @@<br>
   std::set<State*, ltState> states;<br>
<br>
   // Map from a state to the list of transitions with that state as source.<br>
-  std::map<State*, SmallVector<Transition*, 16>, ltState> stateTransitions;<br>
+  std::map<State*, std::set<Transition*, ltTransition>, ltState><br>
+    stateTransitions;<br>
   State *currentState;<br>
<br>
   // Highest valued Input seen.<br>
@@ -193,21 +203,19 @@<br>
     return (s1->stateNum < s2->stateNum);<br>
 }<br>
<br>
+bool ltTransition::operator()(const Transition *s1, const Transition *s2) const {<br>
+    return (s1->input < s2->input);<br>
+}<br>
<br>
 //<br>
-// canAddInsnClass - Returns true if an instruction of type InsnClass is a<br>
-// valid transition from this state i.e., can an instruction of type InsnClass<br>
-// be added to the packet represented by this state.<br>
+// AddInsnClass - Return all combinations of resource reservation<br>
+// which are possible from this state (PossibleStates).<br>
 //<br>
-// PossibleStates is the set of valid resource states that ensue from valid<br>
-// transitions.<br>
-//<br>
-bool State::canAddInsnClass(unsigned InsnClass,<br>
+void State::AddInsnClass(unsigned InsnClass,<br>
                             std::set<unsigned> &PossibleStates) {<br>
   //<br>
   // Iterate over all resource states in currentState.<br>
   //<br>
-  bool AddedState = false;<br>
<br>
   for (std::set<unsigned>::iterator SI = stateInfo.begin();<br>
        SI != stateInfo.end(); ++SI) {<br>
@@ -240,13 +248,26 @@<br>
             (VisitedResourceStates.count(ResultingResourceState) == 0)) {<br>
           VisitedResourceStates.insert(ResultingResourceState);<br>
           PossibleStates.insert(ResultingResourceState);<br>
-          AddedState = true;<br>
         }<br>
       }<br>
     }<br>
   }<br>
<br>
-  return AddedState;<br>
+}<br>
+<br>
+<br>
+//<br>
+// canAddInsnClass - Quickly verifies if an instruction of type InsnClass is a<br>
+// valid transition from this state i.e., can an instruction of type InsnClass<br>
+// be added to the packet represented by this state.<br>
+//<br>
+bool State::canAddInsnClass(unsigned InsnClass) const {<br>
+  for (std::set<unsigned>::iterator SI = stateInfo.begin();<br>
+       SI != stateInfo.end(); ++SI) {<br>
+    if (~*SI & InsnClass)<br>
+      return true;<br>
+  }<br>
+  return false;<br>
 }<br></blockquote><div><br></div><div>I guess we should use const_iterator here. Submitted a fixup as r159334.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
<br>
@@ -267,7 +288,8 @@<br>
     LargestInput = T->input;<br>
<br>
   // Add the new transition.<br>
-  stateTransitions[T->from].push_back(T);<br>
+  bool Added = stateTransitions[T->from].insert(T).second;<br>
+  assert(Added && "Cannot have multiple states for the same input");<br>
 }<br>
<br>
<br>
@@ -281,11 +303,13 @@<br>
     return NULL;<br>
<br>
   // Do we have a transition from state From with Input I?<br>
-  for (SmallVector<Transition*, 16>::iterator VI =<br>
-         stateTransitions[From].begin();<br>
-         VI != stateTransitions[From].end(); ++VI)<br>
-    if ((*VI)->input == I)<br>
-      return (*VI)->to;<br>
+  Transition TVal(NULL, I, NULL);<br>
+  // Do not count this temporal instance<br>
+  Transition::currentTransitionNum--;<br>
+  std::set<Transition*, ltTransition>::iterator T =<br>
+    stateTransitions[From].find(&TVal);<br>
+  if (T != stateTransitions[From].end())<br>
+    return (*T)->to;<br>
<br>
   return NULL;<br>
 }<br>
@@ -331,11 +355,12 @@<br>
     StateEntry[i] = ValidTransitions;<br>
     for (unsigned j = 0; j <= LargestInput; ++j) {<br>
       assert (((*SI)->stateNum == (int) i) && "Mismatch in state numbers");<br>
-      if (!isValidTransition(*SI, j))<br>
+      State *To = getTransition(*SI, j);<br>
+      if (To == NULL)<br>
         continue;<br>
<br>
       OS << "{" << j << ", "<br>
-         << getTransition(*SI, j)->stateNum<br>
+         << To->stateNum<br>
          << "},    ";<br>
       ++ValidTransitions;<br>
     }<br>
@@ -514,8 +539,10 @@<br>
       // and the state can accommodate this InsnClass, create a transition.<br>
       //<br>
       if (!D.getTransition(current, InsnClass) &&<br>
-          current->canAddInsnClass(InsnClass, NewStateResources)) {<br>
+          current->canAddInsnClass(InsnClass)) {<br>
         State *NewState = NULL;<br>
+        current->AddInsnClass(InsnClass, NewStateResources);<br>
+        assert(NewStateResources.size() && "New states must be generated");<br>
<br>
         //<br>
         // If we have seen this state before, then do not create a new state.<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div><br>