Ver código fonte

Replacing recursive Value::MergeUseLists implementation with an iterative one (#1593)

* Replacing the tail-recursive function Value::MergeUseLists with an iterative
version, used in LLVM 8.0.0.

The tail recursive version of the function was causing stack overflow in a large
shader.
Gaurav Sharma 7 anos atrás
pai
commit
483e1fb27b
1 arquivos alterados com 35 adições e 4 exclusões
  1. 35 4
      include/llvm/IR/Value.h

+ 35 - 4
include/llvm/IR/Value.h

@@ -494,15 +494,42 @@ private:
   template <class Compare>
   template <class Compare>
   static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
   static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
     Use *Merged;
     Use *Merged;
-    mergeUseListsImpl(L, R, &Merged, Cmp);
+
+    // HLSL Change Begins. Copied from LLVM Version 8.0.0.
+    // MergeUseListsImpl(L, R, &Merged, Cmp);
+    Use **Next = &Merged;
+
+    while (true) {
+      if (!L) {
+        *Next = R;
+        break;
+      }
+      if (!R) {
+        *Next = L;
+        break;
+      }
+      if (Cmp(*R, *L)) {
+        *Next = R;
+        Next = &R->Next;
+        R = R->Next;
+      } else {
+        *Next = L;
+        Next = &L->Next;
+        L = L->Next;
+      }
+    }
+    // HLSL Change Ends.
+
     return Merged;
     return Merged;
   }
   }
-
+  
   /// \brief Tail-recursive helper for \a mergeUseLists().
   /// \brief Tail-recursive helper for \a mergeUseLists().
   ///
   ///
   /// \param[out] Next the first element in the list.
   /// \param[out] Next the first element in the list.
-  template <class Compare>
-  static void mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp);
+  // HLSL Change Begins.
+  //template <class Compare>
+  //static void mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp);
+  // HLSL Change Ends.
 
 
 protected:
 protected:
   unsigned short getSubclassDataFromValue() const { return SubclassData; }
   unsigned short getSubclassDataFromValue() const { return SubclassData; }
@@ -587,6 +614,8 @@ template <class Compare> void Value::sortUseList(Compare Cmp) {
   }
   }
 }
 }
 
 
+// HLSL Change Begins.
+/*
 template <class Compare>
 template <class Compare>
 void Value::mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp) {
 void Value::mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp) {
   if (!L) {
   if (!L) {
@@ -605,6 +634,8 @@ void Value::mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp) {
   *Next = L;
   *Next = L;
   mergeUseListsImpl(L->Next, R, &L->Next, Cmp);
   mergeUseListsImpl(L->Next, R, &L->Next, Cmp);
 }
 }
+*/
+// HLSL Change Ends.
 
 
 // isa - Provide some specializations of isa so that we don't have to include
 // isa - Provide some specializations of isa so that we don't have to include
 // the subtype header files to test to see if the value is a subclass...
 // the subtype header files to test to see if the value is a subclass...