]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - dfg/DFGValueSource.h
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / dfg / DFGValueSource.h
index 36207264787ce63b6efdfe79ab8cc283b53dcaa2..33bb457bd4fcd3aa56b17da795e19ca8a0b4dce7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013, 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 DFGValueSource_h
 #define DFGValueSource_h
 
-#include <wtf/Platform.h>
-
 #if ENABLE(DFG_JIT)
 
 #include "DFGCommon.h"
+#include "DFGFlushFormat.h"
 #include "DFGMinifiedID.h"
 #include "DataFormat.h"
 #include "SpeculatedType.h"
@@ -42,6 +41,7 @@ enum ValueSourceKind {
     SourceNotSet,
     ValueInJSStack,
     Int32InJSStack,
+    Int52InJSStack,
     CellInJSStack,
     BooleanInJSStack,
     DoubleInJSStack,
@@ -53,8 +53,10 @@ enum ValueSourceKind {
 static inline ValueSourceKind dataFormatToValueSourceKind(DataFormat dataFormat)
 {
     switch (dataFormat) {
-    case DataFormatInteger:
+    case DataFormatInt32:
         return Int32InJSStack;
+    case DataFormatInt52:
+        return Int52InJSStack;
     case DataFormatDouble:
         return DoubleInJSStack;
     case DataFormatBoolean:
@@ -77,7 +79,9 @@ static inline DataFormat valueSourceKindToDataFormat(ValueSourceKind kind)
     case ValueInJSStack:
         return DataFormatJS;
     case Int32InJSStack:
-        return DataFormatInteger;
+        return DataFormatInt32;
+    case Int52InJSStack:
+        return DataFormatInt52;
     case CellInJSStack:
         return DataFormatCell;
     case BooleanInJSStack:
@@ -109,48 +113,72 @@ static inline bool isTriviallyRecoverable(ValueSourceKind kind)
 class ValueSource {
 public:
     ValueSource()
-        : m_value(idFromKind(SourceNotSet))
+        : m_kind(SourceNotSet)
     {
     }
     
     explicit ValueSource(ValueSourceKind valueSourceKind)
-        : m_value(idFromKind(valueSourceKind))
+        : m_kind(valueSourceKind)
     {
-        ASSERT(kind() != SourceNotSet);
-        ASSERT(kind() != HaveNode);
+        ASSERT(kind() == ArgumentsSource || kind() == SourceIsDead || kind() == ArgumentsSource);
     }
     
     explicit ValueSource(MinifiedID id)
-        : m_value(id)
+        : m_kind(HaveNode)
+        , m_value(id.bits())
     {
         ASSERT(!!id);
         ASSERT(kind() == HaveNode);
     }
     
-    static ValueSource forSpeculation(SpeculatedType prediction)
+    ValueSource(ValueSourceKind valueSourceKind, VirtualRegister where)
+        : m_kind(valueSourceKind)
+        , m_value(static_cast<intptr_t>(where.offset()))
     {
-        if (isInt32Speculation(prediction))
-            return ValueSource(Int32InJSStack);
-        if (isArraySpeculation(prediction) || isCellSpeculation(prediction))
-            return ValueSource(CellInJSStack);
-        if (isBooleanSpeculation(prediction))
-            return ValueSource(BooleanInJSStack);
-        return ValueSource(ValueInJSStack);
+        ASSERT(kind() != SourceNotSet);
+        ASSERT(kind() != HaveNode);
     }
     
-    static ValueSource forDataFormat(DataFormat dataFormat)
+    static ValueSource forFlushFormat(VirtualRegister where, FlushFormat format)
     {
-        return ValueSource(dataFormatToValueSourceKind(dataFormat));
+        switch (format) {
+        case DeadFlush:
+        case ConflictingFlush:
+            return ValueSource(SourceIsDead);
+        case FlushedJSValue:
+            return ValueSource(ValueInJSStack, where);
+        case FlushedDouble:
+            return ValueSource(DoubleInJSStack, where);
+        case FlushedInt32:
+            return ValueSource(Int32InJSStack, where);
+        case FlushedInt52:
+            return ValueSource(Int52InJSStack, where);
+        case FlushedCell:
+            return ValueSource(CellInJSStack, where);
+        case FlushedBoolean:
+            return ValueSource(BooleanInJSStack, where);
+        case FlushedArguments:
+            return ValueSource(ArgumentsSource);
+        }
+        RELEASE_ASSERT_NOT_REACHED();
+        return ValueSource();
+    }
+    
+    static ValueSource forDataFormat(VirtualRegister where, DataFormat dataFormat)
+    {
+        return ValueSource(dataFormatToValueSourceKind(dataFormat), where);
     }
     
     bool isSet() const
     {
-        return kindFromID(m_value) != SourceNotSet;
+        return kind() != SourceNotSet;
     }
     
+    bool operator!() const { return !isSet(); }
+    
     ValueSourceKind kind() const
     {
-        return kindFromID(m_value);
+        return m_kind;
     }
     
     bool isInJSStack() const { return JSC::DFG::isInJSStack(kind()); }
@@ -165,21 +193,6 @@ public:
     {
         ASSERT(isTriviallyRecoverable());
         switch (kind()) {
-        case ValueInJSStack:
-            return ValueRecovery::alreadyInJSStack();
-            
-        case Int32InJSStack:
-            return ValueRecovery::alreadyInJSStackAsUnboxedInt32();
-            
-        case CellInJSStack:
-            return ValueRecovery::alreadyInJSStackAsUnboxedCell();
-            
-        case BooleanInJSStack:
-            return ValueRecovery::alreadyInJSStackAsUnboxedBoolean();
-            
-        case DoubleInJSStack:
-            return ValueRecovery::alreadyInJSStackAsUnboxedDouble();
-            
         case SourceIsDead:
             return ValueRecovery::constant(jsUndefined());
             
@@ -187,35 +200,28 @@ public:
             return ValueRecovery::argumentsThatWereNotCreated();
             
         default:
-            RELEASE_ASSERT_NOT_REACHED();
-            return ValueRecovery();
+            return ValueRecovery::displacedInJSStack(virtualRegister(), dataFormat());
         }
     }
     
     MinifiedID id() const
     {
         ASSERT(kind() == HaveNode);
-        return m_value;
+        return MinifiedID::fromBits(m_value);
     }
     
-    void dump(PrintStream&) const;
-    
-private:
-    static MinifiedID idFromKind(ValueSourceKind kind)
+    VirtualRegister virtualRegister() const
     {
-        ASSERT(kind >= SourceNotSet && kind < HaveNode);
-        return MinifiedID::fromBits(MinifiedID::invalidID() - kind);
+        ASSERT(isInJSStack());
+        return VirtualRegister(m_value);
     }
     
-    static ValueSourceKind kindFromID(MinifiedID id)
-    {
-        uintptr_t kind = static_cast<uintptr_t>(MinifiedID::invalidID() - id.m_id);
-        if (kind >= static_cast<uintptr_t>(HaveNode))
-            return HaveNode;
-        return static_cast<ValueSourceKind>(kind);
-    }
+    void dump(PrintStream&) const;
+    void dumpInContext(PrintStream&, DumpContext*) const;
     
-    MinifiedID m_value;
+private:
+    ValueSourceKind m_kind;
+    uintptr_t m_value;
 };
 
 } } // namespace JSC::DFG