]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - assembler/AbstractMacroAssembler.h
JavaScriptCore-7600.1.4.11.8.tar.gz
[apple/javascriptcore.git] / assembler / AbstractMacroAssembler.h
index 71b9d1f1649f040a705d9cbfafb179731d6bda83..a20990072fa058ba5cbb1e55a7a85b0da5600e49 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2012, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #ifndef AbstractMacroAssembler_h
 #define AbstractMacroAssembler_h
 
+#include "AbortReason.h"
 #include "AssemblerBuffer.h"
 #include "CodeLocation.h"
 #include "MacroAssemblerCodeRef.h"
+#include "Options.h"
+#include "WeakRandom.h"
 #include <wtf/CryptographicallyRandomNumber.h>
 #include <wtf/Noncopyable.h>
 
 #if ENABLE(ASSEMBLER)
 
-
-#if PLATFORM(QT)
-#define ENABLE_JIT_CONSTANT_BLINDING 0
-#endif
-
-#ifndef ENABLE_JIT_CONSTANT_BLINDING
-#define ENABLE_JIT_CONSTANT_BLINDING 1
-#endif
-
 namespace JSC {
 
 inline bool isARMv7s()
@@ -72,7 +66,21 @@ inline bool isX86()
 #endif
 }
 
-class JumpReplacementWatchpoint;
+inline bool optimizeForARMv7s()
+{
+    return isARMv7s() && Options::enableArchitectureSpecificOptimizations();
+}
+
+inline bool optimizeForARM64()
+{
+    return isARM64() && Options::enableArchitectureSpecificOptimizations();
+}
+
+inline bool optimizeForX86()
+{
+    return isX86() && Options::enableArchitectureSpecificOptimizations();
+}
+
 class LinkBuffer;
 class RepatchBuffer;
 class Watchpoint;
@@ -92,6 +100,13 @@ public:
     class Jump;
 
     typedef typename AssemblerType::RegisterID RegisterID;
+    typedef typename AssemblerType::FPRegisterID FPRegisterID;
+    
+    static RegisterID firstRegister() { return AssemblerType::firstRegister(); }
+    static RegisterID lastRegister() { return AssemblerType::lastRegister(); }
+
+    static FPRegisterID firstFPRegister() { return AssemblerType::firstFPRegister(); }
+    static FPRegisterID lastFPRegister() { return AssemblerType::lastFPRegister(); }
 
     // Section 1: MacroAssembler operand types
     //
@@ -104,6 +119,13 @@ public:
         TimesFour,
         TimesEight,
     };
+    
+    static Scale timesPtr()
+    {
+        if (sizeof(void*) == 4)
+            return TimesFour;
+        return TimesEight;
+    }
 
     // Address:
     //
@@ -114,7 +136,12 @@ public:
             , offset(offset)
         {
         }
-
+        
+        Address withOffset(int32_t additionalOffset)
+        {
+            return Address(base, offset + additionalOffset);
+        }
+        
         RegisterID base;
         int32_t offset;
     };
@@ -226,12 +253,7 @@ public:
         const void* m_value;
     };
 
-    struct ImmPtr : 
-#if ENABLE(JIT_CONSTANT_BLINDING)
-        private TrustedImmPtr 
-#else
-        public TrustedImmPtr
-#endif
+    struct ImmPtr : private TrustedImmPtr
     {
         explicit ImmPtr(const void* value)
             : TrustedImmPtr(value)
@@ -266,13 +288,7 @@ public:
     };
 
 
-    struct Imm32 : 
-#if ENABLE(JIT_CONSTANT_BLINDING)
-        private TrustedImm32 
-#else
-        public TrustedImm32
-#endif
-    {
+    struct Imm32 : private TrustedImm32 {
         explicit Imm32(int32_t value)
             : TrustedImm32(value)
         {
@@ -311,12 +327,7 @@ public:
         int64_t m_value;
     };
 
-    struct Imm64 : 
-#if ENABLE(JIT_CONSTANT_BLINDING)
-        private TrustedImm64 
-#else
-        public TrustedImm64
-#endif
+    struct Imm64 : private TrustedImm64
     {
         explicit Imm64(int64_t value)
             : TrustedImm64(value)
@@ -348,7 +359,6 @@ public:
         friend class AbstractMacroAssembler;
         friend struct DFG::OSRExit;
         friend class Jump;
-        friend class JumpReplacementWatchpoint;
         friend class MacroAssemblerCodeRef;
         friend class LinkBuffer;
         friend class Watchpoint;
@@ -425,7 +435,7 @@ public:
 
     // DataLabel32:
     //
-    // A DataLabelPtr is used to refer to a location in the code containing a pointer to be
+    // A DataLabel32 is used to refer to a location in the code containing a 32-bit constant to be
     // patched after the code has been generated.
     class DataLabel32 {
         template<class TemplateAssemblerType>
@@ -470,6 +480,8 @@ public:
         {
         }
 
+        AssemblerLabel label() const { return m_label; }
+
     private:
         AssemblerLabel m_label;
     };
@@ -682,7 +694,8 @@ public:
         
         JumpList(Jump jump)
         {
-            append(jump);
+            if (jump.isSet())
+                append(jump);
         }
 
         void link(AbstractMacroAssembler<AssemblerType>* masm)
@@ -775,7 +788,7 @@ public:
         {
         }
 
-        void check(unsigned low, unsigned high)
+        void checkOffsets(unsigned low, unsigned high)
         {
             RELEASE_ASSERT_WITH_MESSAGE(!(low <= m_offset && m_offset <= high), "Unsafe branch over register allocation at instruction offset %u in jump offset range %u..%u", m_offset, low, high);
         }
@@ -801,7 +814,7 @@ public:
 
         size_t size = m_registerAllocationForOffsets.size();
         for (size_t i = 0; i < size; ++i)
-            m_registerAllocationForOffsets[i].check(offset1, offset2);
+            m_registerAllocationForOffsets[i].checkOffsets(offset1, offset2);
     }
 #endif
 
@@ -822,14 +835,16 @@ public:
     {
         AssemblerType::cacheFlush(code, size);
     }
+
+    AssemblerType m_assembler;
+    
 protected:
     AbstractMacroAssembler()
         : m_randomSource(cryptographicallyRandomNumber())
     {
+        invalidateAllTempRegisters();
     }
 
-    AssemblerType m_assembler;
-    
     uint32_t random()
     {
         return m_randomSource.getUint32();
@@ -841,11 +856,18 @@ protected:
     Vector<RegisterAllocationOffset, 10> m_registerAllocationForOffsets;
 #endif
 
-#if ENABLE(JIT_CONSTANT_BLINDING)
-    static bool scratchRegisterForBlinding() { return false; }
-    static bool shouldBlindForSpecificArch(uint32_t) { return true; }
-    static bool shouldBlindForSpecificArch(uint64_t) { return true; }
-#endif
+    static bool haveScratchRegisterForBlinding()
+    {
+        return false;
+    }
+    static RegisterID scratchRegisterForBlinding()
+    {
+        UNREACHABLE_FOR_PLATFORM();
+        return firstRegister();
+    }
+    static bool canBlind() { return false; }
+    static bool shouldBlindForSpecificArch(uint32_t) { return false; }
+    static bool shouldBlindForSpecificArch(uint64_t) { return false; }
 
     class CachedTempRegister {
         friend class DataLabelPtr;