Skip to content
  • oliver@apple.com's avatar
    fourthTier: DFG should have switch_char · 9e1c8098
    oliver@apple.com authored
    https://bugs.webkit.org/show_bug.cgi?id=117710
    
    Source/JavaScriptCore:
    
    Reviewed by Michael Saboff.
    
    Add op_switch_char. Most of this is fairly simple, except for the whole
    LazyJSValue thing.
    
    It's long been the case that anytime you wanted the DFG to speak of a string
    that didn't appear in the constant pool, you would have a hard time since
    the DFG isn't allowed to allocate in the GC heap. For example, if you know
    that you want to speak of a single character string, you might find that
    the one you wanted to speak of had been GC'd. Another example is if you
    wanted to add constant folding for string concatenation - something we don't
    have yet but will want eventually.
    
    I solve this by finally adding the notion of LazyJSValue. In the future I
    anticipate using this for a variety of string-related things. The idea here
    is that the DFG can either say that it already knows what the value is, or
    it can describe the value. For example, in this patch I needed to be able to
    describe single-character strings.
    
    * JavaScriptCore.xcodeproj/project.pbxproj:
    * bytecode/CodeBlock.cpp:
    (JSC::CodeBlock::dumpBytecode):
    (JSC::CodeBlock::CodeBlock):
    * bytecode/JumpTable.h:
    * dfg/DFGBackwardsPropagationPhase.cpp:
    (JSC::DFG::BackwardsPropagationPhase::propagate):
    * dfg/DFGByteCodeParser.cpp:
    (InlineStackEntry):
    (JSC::DFG::ByteCodeParser::parseBlock):
    (JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):
    * dfg/DFGCFGSimplificationPhase.cpp:
    (JSC::DFG::CFGSimplificationPhase::run):
    * dfg/DFGCapabilities.cpp:
    (JSC::DFG::capabilityLevel):
    * dfg/DFGDriver.cpp:
    (JSC::DFG::compile):
    * dfg/DFGFixupPhase.cpp:
    (JSC::DFG::FixupPhase::fixupNode):
    * dfg/DFGGPRInfo.h:
    (JSC::DFG::JSValueRegs::payloadGPR):
    * dfg/DFGJITCompiler.cpp:
    (JSC::DFG::JITCompiler::jumpTable):
    (DFG):
    (JSC::DFG::JITCompiler::numberOfJumpTables):
    (JSC::DFG::JITCompiler::linkSwitches):
    (JSC::DFG::JITCompiler::link):
    * dfg/DFGJITCompiler.h:
    (JITCompiler):
    * dfg/DFGLazyJSValue.cpp: Added.
    (DFG):
    (JSC::DFG::LazyJSValue::getValue):
    (JSC::DFG::equalToSingleCharacter):
    (JSC::DFG::LazyJSValue::strictEqual):
    (JSC::DFG::LazyJSValue::dump):
    * dfg/DFGLazyJSValue.h: Added.
    (DFG):
    (LazyJSValue):
    (JSC::DFG::LazyJSValue::LazyJSValue):
    (JSC::DFG::LazyJSValue::singleCharacterString):
    (JSC::DFG::LazyJSValue::tryGetValue):
    (JSC::DFG::LazyJSValue::value):
    (JSC::DFG::LazyJSValue::character):
    (JSC::DFG::LazyJSValue::switchLookupValue):
    * dfg/DFGNode.h:
    (JSC::DFG::SwitchCase::SwitchCase):
    (SwitchCase):
    * dfg/DFGSpeculativeJIT.cpp:
    (JSC::DFG::SpeculativeJIT::emitSwitchIntJump):
    (JSC::DFG::SpeculativeJIT::emitSwitchImmIntJump):
    (DFG):
    (JSC::DFG::SpeculativeJIT::emitSwitchImm):
    (JSC::DFG::SpeculativeJIT::emitSwitchCharStringJump):
    (JSC::DFG::SpeculativeJIT::emitSwitchChar):
    (JSC::DFG::SpeculativeJIT::emitSwitch):
    * dfg/DFGSpeculativeJIT.h:
    (SpeculativeJIT):
    
    Source/WTF:
    
    Reviewed by Michael Saboff.
    
    I wanted to be able to say stringImpl->at(index), and now I can!
    
    Also made it possible to convert a UChar to a utf8 CString without
    allocating a StringImpl.
    
    * wtf/text/StringImpl.cpp:
    (WTF::StringImpl::utf8Impl):
    (WTF):
    (WTF::StringImpl::utf8ForCharacters):
    (WTF::StringImpl::utf8ForRange):
    * wtf/text/StringImpl.h:
    (StringImpl):
    (WTF::StringImpl::at):
    (WTF::StringImpl::operator[]):
    
    LayoutTests:
    
    Rubber stamped by Mark Hahnenberg.
    
    * fast/js/regress/script-tests/switch-char-constant.js: Added.
    (foo):
    (bar):
    * fast/js/regress/script-tests/switch-char.js: Added.
    (foo):
    (bar):
    * fast/js/regress/switch-char-constant-expected.txt: Added.
    * fast/js/regress/switch-char-constant.html: Added.
    * fast/js/regress/switch-char-expected.txt: Added.
    * fast/js/regress/switch-char.html: Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153234 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    9e1c8098