CallLinkStatus should be aware of closure calls, and the DFG bytecode parser should use that as its sole internal notion of how to optimize calls
https://bugs.webkit.org/show_bug.cgi?id=106027

Source/JavaScriptCore: 

Reviewed by Mark Hahnenberg.
        
Previously, the DFG bytecode parser had its own internal notion of exactly what CallLinkStatus was
meant to do, in the form of a CallType, expectedFunction, intrinsic, etc. This change makes CallLinkStatus
smart enough to do all of that, and also gives it the ability to understand closure calls.

* bytecode/CallLinkStatus.cpp:
(JSC::CallLinkStatus::CallLinkStatus):
(JSC):
(JSC::CallLinkStatus::function):
(JSC::CallLinkStatus::internalFunction):
(JSC::CallLinkStatus::intrinsicFor):
(JSC::CallLinkStatus::setIsProved):
(JSC::CallLinkStatus::computeFromLLInt):
(JSC::CallLinkStatus::computeFor):
(JSC::CallLinkStatus::dump):
* bytecode/CallLinkStatus.h:
(JSC):
(JSC::CallLinkStatus::CallLinkStatus):
(CallLinkStatus):
(JSC::CallLinkStatus::takesSlowPath):
(JSC::CallLinkStatus::isSet):
(JSC::CallLinkStatus::isClosureCall):
(JSC::CallLinkStatus::callTarget):
(JSC::CallLinkStatus::executable):
(JSC::CallLinkStatus::structure):
(JSC::CallLinkStatus::isProved):
(JSC::CallLinkStatus::canOptimize):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleCall):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::valueOfFunctionConstant):

Source/WTF: 

Reviewed by Mark Hahnenberg.
        
I got tired of the various idioms for printing a list of things with comma in between, so I wrote a helper.

* WTF.xcodeproj/project.pbxproj:
* wtf/CommaPrinter.h: Added.
(WTF):
(CommaPrinter):
(WTF::CommaPrinter::CommaPrinter):
(WTF::CommaPrinter::dump):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@138737 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/bytecode/CallLinkStatus.cpp b/Source/JavaScriptCore/bytecode/CallLinkStatus.cpp
index da7af8a..ad82c85 100644
--- a/Source/JavaScriptCore/bytecode/CallLinkStatus.cpp
+++ b/Source/JavaScriptCore/bytecode/CallLinkStatus.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,9 +28,64 @@
 
 #include "CodeBlock.h"
 #include "LLIntCallLinkInfo.h"
+#include <wtf/CommaPrinter.h>
 
 namespace JSC {
 
+CallLinkStatus::CallLinkStatus(JSValue value)
+    : m_callTarget(value)
+    , m_executable(0)
+    , m_structure(0)
+    , m_couldTakeSlowPath(false)
+    , m_isProved(false)
+{
+    if (!value || !value.isCell())
+        return;
+    
+    m_structure = value.asCell()->structure();
+    
+    if (!value.asCell()->inherits(&JSFunction::s_info))
+        return;
+    
+    m_executable = jsCast<JSFunction*>(value.asCell())->executable();
+}
+
+JSFunction* CallLinkStatus::function() const
+{
+    if (!m_callTarget || !m_callTarget.isCell())
+        return 0;
+    
+    if (!m_callTarget.asCell()->inherits(&JSFunction::s_info))
+        return 0;
+    
+    return jsCast<JSFunction*>(m_callTarget.asCell());
+}
+
+InternalFunction* CallLinkStatus::internalFunction() const
+{
+    if (!m_callTarget || !m_callTarget.isCell())
+        return 0;
+    
+    if (!m_callTarget.asCell()->inherits(&InternalFunction::s_info))
+        return 0;
+    
+    return jsCast<InternalFunction*>(m_callTarget.asCell());
+}
+
+Intrinsic CallLinkStatus::intrinsicFor(CodeSpecializationKind kind) const
+{
+    if (!m_executable)
+        return NoIntrinsic;
+    
+    return m_executable->intrinsicFor(kind);
+}
+
+CallLinkStatus& CallLinkStatus::setIsProved(bool isProved)
+{
+    m_isProved = isProved;
+    return *this;
+}
+
 CallLinkStatus CallLinkStatus::computeFromLLInt(CodeBlock* profiledBlock, unsigned bytecodeIndex)
 {
     UNUSED_PARAM(profiledBlock);
@@ -39,9 +94,9 @@
     Instruction* instruction = profiledBlock->instructions().begin() + bytecodeIndex;
     LLIntCallLinkInfo* callLinkInfo = instruction[4].u.callLinkInfo;
     
-    return CallLinkStatus(callLinkInfo->lastSeenCallee.get(), false, false);
+    return CallLinkStatus(callLinkInfo->lastSeenCallee.get());
 #else
-    return CallLinkStatus(0, false, false);
+    return CallLinkStatus();
 #endif
 }
 
@@ -54,18 +109,44 @@
         return computeFromLLInt(profiledBlock, bytecodeIndex);
     
     if (profiledBlock->couldTakeSlowCase(bytecodeIndex))
-        return CallLinkStatus(0, true);
+        return CallLinkStatus::takesSlowPath();
     
     CallLinkInfo& callLinkInfo = profiledBlock->getCallLinkInfo(bytecodeIndex);
+    if (callLinkInfo.stub)
+        return CallLinkStatus(callLinkInfo.stub->executable(), callLinkInfo.stub->structure());
+    
     JSFunction* target = callLinkInfo.lastSeenCallee.get();
     if (!target)
         return computeFromLLInt(profiledBlock, bytecodeIndex);
-    
-    return CallLinkStatus(target, false, !!callLinkInfo.stub);
+
+    return CallLinkStatus(target);
 #else
-    return CallLinkStatus(0, false, false);
+    return CallLinkStatus();
 #endif
 }
 
+void CallLinkStatus::dump(PrintStream& out)
+{
+    if (!isSet()) {
+        out.print("Not Set");
+        return;
+    }
+    
+    CommaPrinter comma;
+    
+    if (m_isProved)
+        out.print(comma, "Statically Proved");
+    
+    if (m_couldTakeSlowPath)
+        out.print(comma, "Could Take Slow Path");
+    
+    if (m_callTarget)
+        out.print(comma, "Known target: ", m_callTarget);
+    
+    ASSERT(!!m_executable == !!m_structure);
+    if (m_executable)
+        out.print(comma, "Executable/CallHash/Structure: ", RawPointer(m_executable), "/", m_executable->hashFor(CodeForCall), "/", RawPointer(m_structure));
+}
+
 } // namespace JSC
 
diff --git a/Source/JavaScriptCore/bytecode/CallLinkStatus.h b/Source/JavaScriptCore/bytecode/CallLinkStatus.h
index 8dd49eb..071aa1db 100644
--- a/Source/JavaScriptCore/bytecode/CallLinkStatus.h
+++ b/Source/JavaScriptCore/bytecode/CallLinkStatus.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,44 +26,75 @@
 #ifndef CallLinkStatus_h
 #define CallLinkStatus_h
 
+#include "CodeSpecializationKind.h"
+#include "Intrinsic.h"
+#include "JSValue.h"
+
 namespace JSC {
 
-class JSFunction;
 class CodeBlock;
+class ExecutableBase;
+class InternalFunction;
+class JSFunction;
+class Structure;
 
 class CallLinkStatus {
 public:
     CallLinkStatus()
-        : m_callTarget(0)
+        : m_executable(0)
+        , m_structure(0)
         , m_couldTakeSlowPath(false)
-        , m_isClosureCall(false)
+        , m_isProved(false)
     {
     }
     
-    CallLinkStatus(JSFunction* callTarget, bool couldTakeSlowPath, bool isClosureCall = false)
-        : m_callTarget(callTarget)
-        , m_couldTakeSlowPath(couldTakeSlowPath)
-        , m_isClosureCall(isClosureCall)
+    static CallLinkStatus takesSlowPath()
+    {
+        CallLinkStatus result;
+        result.m_couldTakeSlowPath = true;
+        return result;
+    }
+    
+    explicit CallLinkStatus(JSValue);
+    
+    CallLinkStatus(ExecutableBase* executable, Structure* structure)
+        : m_executable(executable)
+        , m_structure(structure)
+        , m_couldTakeSlowPath(false)
+        , m_isProved(false)
     {
     }
     
+    CallLinkStatus& setIsProved(bool);
+    
     static CallLinkStatus computeFor(CodeBlock*, unsigned bytecodeIndex);
     
-    bool isSet() const { return !!m_callTarget || m_couldTakeSlowPath; }
+    bool isSet() const { return m_callTarget || m_executable || m_couldTakeSlowPath; }
     
     bool operator!() const { return !isSet(); }
     
     bool couldTakeSlowPath() const { return m_couldTakeSlowPath; }
-    bool isClosureCall() const { return m_isClosureCall; }
+    bool isClosureCall() const { return !m_callTarget; }
     
-    JSFunction* callTarget() const { return m_callTarget; }
+    JSValue callTarget() const { return m_callTarget; }
+    JSFunction* function() const;
+    InternalFunction* internalFunction() const;
+    Intrinsic intrinsicFor(CodeSpecializationKind) const;
+    ExecutableBase* executable() const { return m_executable; }
+    Structure* structure() const { return m_structure; }
+    bool isProved() const { return m_isProved; }
+    bool canOptimize() const { return (m_callTarget || m_executable) && !m_couldTakeSlowPath; }
+    
+    void dump(PrintStream&);
     
 private:
     static CallLinkStatus computeFromLLInt(CodeBlock*, unsigned bytecodeIndex);
     
-    JSFunction* m_callTarget;
+    JSValue m_callTarget;
+    ExecutableBase* m_executable;
+    Structure* m_structure;
     bool m_couldTakeSlowPath;
-    bool m_isClosureCall;
+    bool m_isProved;
 };
 
 } // namespace JSC