Title: [229412] trunk/Source
Revision
229412
Author
[email protected]
Date
2018-03-08 09:11:51 -0800 (Thu, 08 Mar 2018)

Log Message

Make it possible to randomize register allocation
https://bugs.webkit.org/show_bug.cgi?id=183416

Reviewed by Keith Miller.
Source/_javascript_Core:

        
This is disabled by default for now, because it reveals a regalloc bug in wasm.

* b3/air/AirCode.cpp:
(JSC::B3::Air::Code::Code):
* b3/air/AirCode.h:
(JSC::B3::Air::Code::weakRandom):
* runtime/Options.h:

Source/WTF:


* wtf/MathExtras.h:
(WTF::shuffleVector):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (229411 => 229412)


--- trunk/Source/_javascript_Core/ChangeLog	2018-03-08 16:58:54 UTC (rev 229411)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-03-08 17:11:51 UTC (rev 229412)
@@ -1,3 +1,18 @@
+2018-03-07  Filip Pizlo  <[email protected]>
+
+        Make it possible to randomize register allocation
+        https://bugs.webkit.org/show_bug.cgi?id=183416
+
+        Reviewed by Keith Miller.
+        
+        This is disabled by default for now, because it reveals a regalloc bug in wasm.
+
+        * b3/air/AirCode.cpp:
+        (JSC::B3::Air::Code::Code):
+        * b3/air/AirCode.h:
+        (JSC::B3::Air::Code::weakRandom):
+        * runtime/Options.h:
+
 2018-03-08  Yusuke Suzuki  <[email protected]>
 
         [JSC] Add inherits<T>(VM&) leveraging JSCast fast path

Modified: trunk/Source/_javascript_Core/b3/air/AirCode.cpp (229411 => 229412)


--- trunk/Source/_javascript_Core/b3/air/AirCode.cpp	2018-03-08 16:58:54 UTC (rev 229411)
+++ trunk/Source/_javascript_Core/b3/air/AirCode.cpp	2018-03-08 17:11:51 UTC (rev 229412)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -35,6 +35,7 @@
 #include "B3Procedure.h"
 #include "B3StackSlot.h"
 #include <wtf/ListDump.h>
+#include <wtf/MathExtras.h>
 
 namespace JSC { namespace B3 { namespace Air {
 
@@ -58,7 +59,8 @@
     // Come up with initial orderings of registers. The user may replace this with something else.
     forEachBank(
         [&] (Bank bank) {
-            Vector<Reg> result;
+            Vector<Reg> volatileRegs;
+            Vector<Reg> calleeSaveRegs;
             RegisterSet all = bank == GP ? RegisterSet::allGPRs() : RegisterSet::allFPRs();
             all.exclude(RegisterSet::stackRegisters());
             all.exclude(RegisterSet::reservedHardwareRegisters());
@@ -66,13 +68,20 @@
             all.forEach(
                 [&] (Reg reg) {
                     if (!calleeSave.get(reg))
-                        result.append(reg);
+                        volatileRegs.append(reg);
                 });
             all.forEach(
                 [&] (Reg reg) {
                     if (calleeSave.get(reg))
-                        result.append(reg);
+                        calleeSaveRegs.append(reg);
                 });
+            if (Options::airRandomizeRegs()) {
+                shuffleVector(volatileRegs, [&] (unsigned limit) { return m_weakRandom.getUint32(limit); });
+                shuffleVector(calleeSaveRegs, [&] (unsigned limit) { return m_weakRandom.getUint32(limit); });
+            }
+            Vector<Reg> result;
+            result.appendVector(volatileRegs);
+            result.appendVector(calleeSaveRegs);
             setRegsInPriorityOrder(bank, result);
         });
 

Modified: trunk/Source/_javascript_Core/b3/air/AirCode.h (229411 => 229412)


--- trunk/Source/_javascript_Core/b3/air/AirCode.h	2018-03-08 16:58:54 UTC (rev 229411)
+++ trunk/Source/_javascript_Core/b3/air/AirCode.h	2018-03-08 17:11:51 UTC (rev 229412)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,6 +38,7 @@
 #include "RegisterAtOffsetList.h"
 #include "StackAlignment.h"
 #include <wtf/IndexMap.h>
+#include <wtf/WeakRandom.h>
 
 namespace JSC { namespace B3 {
 
@@ -333,7 +334,9 @@
     RegisterSet mutableGPRs();
     RegisterSet mutableFPRs();
     RegisterSet pinnedRegisters() const { return m_pinnedRegs; }
-
+    
+    WeakRandom& weakRandom() { return m_weakRandom; }
+    
 private:
     friend class ::JSC::B3::Procedure;
     friend class BlockInsertionSet;
@@ -353,6 +356,7 @@
         ASSERT_NOT_REACHED();
     }
 
+    WeakRandom m_weakRandom;
     Procedure& m_proc; // Some meta-data, like byproducts, is stored in the Procedure.
     Vector<Reg> m_gpRegsInPriorityOrder;
     Vector<Reg> m_fpRegsInPriorityOrder;

Modified: trunk/Source/_javascript_Core/runtime/Options.h (229411 => 229412)


--- trunk/Source/_javascript_Core/runtime/Options.h	2018-03-08 16:58:54 UTC (rev 229411)
+++ trunk/Source/_javascript_Core/runtime/Options.h	2018-03-08 17:11:51 UTC (rev 229412)
@@ -426,6 +426,7 @@
     v(bool, airLinearScanSpillsEverything, false, Normal, nullptr) \
     v(bool, airForceBriggsAllocator, false, Normal, nullptr) \
     v(bool, airForceIRCAllocator, false, Normal, nullptr) \
+    v(bool, airRandomizeRegs, false, Normal, nullptr) \
     v(bool, coalesceSpillSlots, true, Normal, nullptr) \
     v(bool, logAirRegisterPressure, false, Normal, nullptr) \
     v(unsigned, maxB3TailDupBlockSize, 3, Normal, nullptr) \

Modified: trunk/Source/WTF/ChangeLog (229411 => 229412)


--- trunk/Source/WTF/ChangeLog	2018-03-08 16:58:54 UTC (rev 229411)
+++ trunk/Source/WTF/ChangeLog	2018-03-08 17:11:51 UTC (rev 229412)
@@ -1,3 +1,13 @@
+2018-03-07  Filip Pizlo  <[email protected]>
+
+        Make it possible to randomize register allocation
+        https://bugs.webkit.org/show_bug.cgi?id=183416
+
+        Reviewed by Keith Miller.
+
+        * wtf/MathExtras.h:
+        (WTF::shuffleVector):
+
 2018-03-08  Yusuke Suzuki  <[email protected]>
 
         [Win] Use __debugbreak for WTFBreakpointTrap

Modified: trunk/Source/WTF/wtf/MathExtras.h (229411 => 229412)


--- trunk/Source/WTF/wtf/MathExtras.h	2018-03-08 16:58:54 UTC (rev 229411)
+++ trunk/Source/WTF/wtf/MathExtras.h	2018-03-08 17:11:51 UTC (rev 229412)
@@ -526,6 +526,19 @@
 #endif
 }
 
+template<typename VectorType, typename RandomFunc>
+void shuffleVector(VectorType& vector, size_t size, const RandomFunc& randomFunc)
+{
+    for (size_t i = 0; i + 1 < size; ++i)
+        std::swap(vector[i], vector[i + randomFunc(size - i)]);
+}
+
+template<typename VectorType, typename RandomFunc>
+void shuffleVector(VectorType& vector, const RandomFunc& randomFunc)
+{
+    shuffleVector(vector, vector.size(), randomFunc);
+}
+
 } // namespace WTF
 
 using WTF::dynamicPoison;
@@ -533,5 +546,6 @@
 using WTF::preciseIndexMaskPtr;
 using WTF::preciseIndexMaskShift;
 using WTF::preciseIndexMaskShiftForSize;
+using WTF::shuffleVector;
 
 #endif // #ifndef WTF_MathExtras_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to