source: webkit/trunk/Source/JavaScriptCore/dfg/DFGLivenessAnalysisPhase.cpp

Last change on this file was 290026, checked in by Chris Dumez, 3 years ago

Clean up / optimize call sites constructing vectors
https://bugs.webkit.org/show_bug.cgi?id=236748

Reviewed by Dean Jackson.

Clean up / optimize call sites constructing vectors:

  • Use Vector::map() / WTF::map() where appropriate

Source/JavaScriptCore:

  • Replace Vector::reserveCapacity() with Vector::reserveInitialCapacity() where appropriate
  • Replace Vector::append() with Vector::uncheckedAppend() where appropriate
  • Leverage the fact that Vector<Ref<Foo>> is now copyable (Because Ref<> now has a copy constructor)
  • Call crossThreadCopy() to isolate-copy a Vector() without iterating.
  • Leverage Vector constructor that takes in an intialization list in more cases
  • Leverage Vector::from() in more cases to simplify vector construction in some case.
  • Drop unnecessary calls to Vector::reserve*Capacity() before calling Vector::append(T*, size_t) since the append() implementation already does this for us.
  • Leverage copyToVector() and copyToVectorOf<> in more cases
  • Call shrinkToFit() in some cases where we reserve capacity and then append() but may not append() as much as we reserved.
  • b3/air/AirCode.cpp:

(JSC::B3::Air::Code::setNumEntrypoints):

  • bytecompiler/NodesCodegen.cpp:

(JSC::ArrayPatternNode::emitDirectBinding):

  • dfg/DFGInPlaceAbstractState.cpp:

(JSC::DFG::setLiveValues):

  • dfg/DFGLivenessAnalysisPhase.cpp:
  • dfg/DFGScoreBoard.h:

(JSC::DFG::ScoreBoard::ScoreBoard):

  • inspector/agents/InspectorDebuggerAgent.cpp:

(Inspector::parseBreakpointOptions):

  • inspector/remote/socket/RemoteInspectorMessageParser.cpp:

(Inspector::MessageParser::pushReceivedData):

  • parser/VariableEnvironment.cpp:

(JSC::CompactTDZEnvironment::CompactTDZEnvironment):

  • wasm/WasmWorklist.cpp:

(JSC::Wasm::Worklist::Worklist):

Source/WebCore:

  • Replace Vector::reserveCapacity() with Vector::reserveInitialCapacity() where appropriate
  • Replace Vector::append() with Vector::uncheckedAppend() where appropriate
  • Leverage the fact that Vector<Ref<Foo>> is now copyable (Because Ref<> now has a copy constructor)
  • Call crossThreadCopy() to isolate-copy a Vector() without iterating.
  • Leverage Vector constructor that takes in an intialization list in more cases
  • Leverage Vector::from() in more cases to simplify vector construction in some case.
  • Drop unnecessary calls to Vector::reserve*Capacity() before calling Vector::append(T*, size_t) since the append() implementation already does this for us.
  • Leverage copyToVector() and copyToVectorOf<> in more cases
  • Call shrinkToFit() in some cases where we reserve capacity and then append() but may not append() as much as we reserved.
  • Modules/async-clipboard/Clipboard.cpp:

(WebCore::Clipboard::read):
(WebCore::Clipboard::ItemWriter::didSetAllData):

  • Modules/encryptedmedia/MediaKeySession.cpp:

(WebCore::MediaKeySession::updateKeyStatuses):

  • Modules/entriesapi/FileSystemEntriesCallback.cpp:

(WebCore::FileSystemEntriesCallback::scheduleCallback):
(WebCore::copyVector): Deleted.

  • Modules/entriesapi/HTMLInputElementEntriesAPI.cpp:

(WebCore::HTMLInputElementEntriesAPI::webkitEntries):

  • Modules/geolocation/GeolocationController.cpp:

(WebCore::GeolocationController::positionChanged):
(WebCore::GeolocationController::errorOccurred):

  • Modules/indexeddb/IDBDatabase.cpp:

(WebCore::IDBDatabase::stop):

  • Modules/indexeddb/IDBGetAllResult.cpp:

(WebCore::IDBGetAllResult::isolatedCopy):

  • Modules/indexeddb/IDBGetResult.cpp:

(WebCore::IDBGetResult::isolatedCopy):

  • Modules/indexeddb/IDBKeyPath.cpp:

(WebCore::isolatedCopy): Deleted.

  • Modules/indexeddb/IDBKeyPath.h:

(WebCore::isolatedCopy): Deleted.

  • Modules/indexeddb/IDBTransaction.cpp:

(WebCore::IDBTransaction::abortInProgressOperations):

  • Modules/indexeddb/client/IDBConnectionProxy.cpp:

(WebCore::IDBClient::removeItemsMatchingCurrentThread):

  • Modules/indexeddb/server/MemoryObjectStore.cpp:

(WebCore::IDBServer::MemoryObjectStore::deleteAllIndexes):

  • Modules/indexeddb/server/SQLiteIDBCursor.cpp:

(WebCore::IDBServer::SQLiteIDBCursor::currentData):

  • Modules/indexeddb/shared/IDBDatabaseInfo.cpp:

(WebCore::IDBDatabaseInfo::objectStoreNames const):

  • Modules/indexeddb/shared/IDBIndexInfo.cpp:

(WebCore::IDBIndexInfo::isolatedCopy const):

  • Modules/indexeddb/shared/IDBObjectStoreInfo.cpp:

(WebCore::IDBObjectStoreInfo::isolatedCopy const):
(WebCore::IDBObjectStoreInfo::indexNames const):

  • Modules/indexeddb/shared/IDBTransactionInfo.cpp:

(WebCore::IDBTransactionInfo::isolatedCopy):

  • Modules/indexeddb/shared/IndexKey.cpp:

(WebCore::IndexKey::isolatedCopy const):

  • Modules/mediastream/MediaStream.cpp:

(WebCore::MediaStream::clone):

  • Modules/mediastream/MediaStreamTrack.cpp:

(WebCore::capabilityStringVector):

  • Modules/mediastream/MediaTrackConstraints.cpp:

(WebCore::convertAdvancedToInternalForm):

  • Modules/mediastream/SFrameUtils.cpp:

(WebCore::toRbsp):

  • Modules/remoteplayback/RemotePlayback.cpp:

(WebCore::RemotePlayback::availabilityChanged):

  • Modules/speech/SpeechRecognition.cpp:

(WebCore::SpeechRecognition::didReceiveResult):

  • Modules/webauthn/cbor/CBORValue.cpp:

(cbor::CBORValue::CBORValue):

  • Modules/webauthn/fido/AuthenticatorGetInfoResponse.cpp:

(fido::toArrayValue):

  • Modules/webauthn/fido/DeviceRequestConverter.cpp:

(fido::convertParametersToCBOR):

  • Modules/webauthn/fido/Pin.cpp:

(fido::pin::encodeRawPublicKey):

  • Modules/webdatabase/DatabaseTracker.cpp:

(WebCore::DatabaseTracker::databaseNames):
(WebCore::isolatedCopy): Deleted.

  • accessibility/AXObjectCache.cpp:

(WebCore::AXObjectCache::notificationPostTimerFired):

  • accessibility/isolatedtree/AXIsolatedObject.cpp:

(WebCore::AXIsolatedObject::setMathscripts):
(WebCore::AXIsolatedObject::setObjectVectorProperty):

  • accessibility/isolatedtree/AXIsolatedTree.cpp:

(WebCore::AXIsolatedTree::objectsForIDs const):
(WebCore::AXIsolatedTree::collectNodeChangesForSubtree):

  • animation/CSSPropertyAnimation.cpp:

(WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):

  • bindings/js/SerializedScriptValue.cpp:

(WebCore::CloneDeserializer::readString):
(WebCore::SerializedScriptValue::blobURLs const):

  • crypto/mac/CryptoAlgorithmECDSAMac.cpp:

(WebCore::signECDSA):
(WebCore::verifyECDSA):

  • crypto/mac/CryptoKeyECMac.cpp:

(WebCore::CryptoKeyEC::platformExportSpki const):
(WebCore::CryptoKeyEC::platformExportPkcs8 const):

  • crypto/mac/CryptoKeyRSAMac.cpp:

(WebCore::CryptoKeyRSA::exportSpki const):
(WebCore::CryptoKeyRSA::exportPkcs8 const):

  • css/CSSBasicShapes.cpp:

(WebCore::CSSBasicShapePolygon::cssText const):

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::copyPropertiesInSet):
(WebCore::ComputedStyleExtractor::copyProperties):

  • css/CSSFontFace.cpp:

(WebCore::iterateClients):

  • css/CSSFontFaceSet.cpp:

(WebCore::CSSFontFaceSet::matchingFacesExcludingPreinstalledFonts):
(WebCore::CSSFontFaceSet::fontFace):

  • css/CSSKeyframesRule.cpp:

(WebCore::StyleRuleKeyframes::StyleRuleKeyframes):

  • css/StyleProperties.cpp:

(WebCore::StyleProperties::copyPropertiesInSet const):
(WebCore::DeferredStyleProperties::DeferredStyleProperties):

  • css/StyleRule.cpp:

(WebCore::DeferredStyleGroupRuleList::DeferredStyleGroupRuleList):
(WebCore::StyleRuleGroup::StyleRuleGroup):

  • css/calc/CSSCalcOperationNode.h:
  • css/calc/CSSCalcValue.cpp:

(WebCore::createCSS):

  • display/css/DisplayBoxDecorationPainter.cpp:

(WebCore::Display::BorderPainter::clipBorderSidePolygon const):
(WebCore::Display::BorderPainter::drawLineForBoxSide const):

  • dom/DOMRectList.cpp:

(WebCore::DOMRectList::DOMRectList):

  • dom/Document.cpp:

(WebCore::Document::updateElementsAffectedByMediaQueries):
(WebCore::Document::didAssociateFormControlsTimerFired):

  • dom/ElementData.cpp:

(WebCore::UniqueElementData::UniqueElementData):

  • dom/EventListenerMap.cpp:

(WebCore::EventListenerMap::eventTypes const):

  • dom/TreeScopeOrderedMap.cpp:

(WebCore::TreeScopeOrderedMap::keys const):

  • editing/CompositeEditCommand.cpp:

(WebCore::copyMarkers):

  • editing/Editor.cpp:

(WebCore::editableTextListsAtPositionInDescendingOrder):

  • fileapi/FileList.cpp:

(WebCore::FileList::paths const):

  • history/HistoryItem.cpp:

(WebCore::HistoryItem::HistoryItem):
(WebCore::m_formData):
(WebCore::m_identifier):

  • html/FileInputType.cpp:

(WebCore::FileInputType::setFiles):
(WebCore::FileInputType::filesChosen):

  • html/LinkIconCollector.cpp:

(WebCore::LinkIconCollector::iconsOfTypes):

  • html/URLSearchParams.cpp:

(WebCore::URLSearchParams::getAll const):

  • layout/formattingContexts/inline/InlineLineBuilder.cpp:

(WebCore::Layout::LineBuilder::layoutInlineContent):

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::startIconLoading):
(WebCore::DocumentLoader::setActiveContentRuleListActionPatterns):

  • loader/TextTrackLoader.cpp:

(WebCore::TextTrackLoader::getNewCues):

  • loader/archive/cf/LegacyWebArchive.cpp:

(WebCore::LegacyWebArchive::createFromSelection):

  • page/CaptionUserPreferencesMediaAF.cpp:

(WebCore::CaptionUserPreferencesMediaAF::preferredAudioCharacteristics const):

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::dispatchAllPendingBeforeUnloadEvents):

  • page/IntersectionObserver.cpp:

(WebCore::IntersectionObserver::create):

  • page/Page.cpp:

(WebCore::Page::replaceRangesWithText):

  • page/csp/ContentSecurityPolicy.cpp:

(WebCore::ContentSecurityPolicy::responseHeaders const):

  • page/csp/ContentSecurityPolicyResponseHeaders.cpp:

(WebCore::ContentSecurityPolicyResponseHeaders::isolatedCopy const):

  • page/mac/ImageOverlayControllerMac.mm:

(WebCore::ImageOverlayController::updateDataDetectorHighlights):

  • page/mac/ServicesOverlayController.mm:

(WebCore::ServicesOverlayController::buildSelectionHighlight):
(WebCore::ServicesOverlayController::handleClick):

  • page/scrolling/AsyncScrollingCoordinator.cpp:

(WebCore::AsyncScrollingCoordinator::childrenOfNode const):

  • page/scrolling/ScrollSnapOffsetsInfo.cpp:

(WebCore::convertOffsetInfo):

  • platform/Length.cpp:

(WebCore::makeCalculated):

  • platform/animation/AnimationList.cpp:

(WebCore::AnimationList::AnimationList):

  • platform/cocoa/PlaybackSessionModelMediaElement.mm:

(WebCore::PlaybackSessionModelMediaElement::audioMediaSelectionOptions const):

  • platform/encryptedmedia/CDMProxy.cpp:

(WebCore::KeyStore::convertToJSKeyStatusVector const):

  • platform/graphics/FloatPolygon.cpp:

(WebCore::FloatPolygon::overlappingEdges const):

  • platform/graphics/FloatQuad.cpp:

(WebCore::boundingBoxes):

  • platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:

(WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense):

  • platform/graphics/ca/TileGrid.cpp:

(WebCore::TileGrid::removeTiles):
(WebCore::TileGrid::removeAllTiles):

  • platform/graphics/ca/TileGrid.h:
  • platform/graphics/cg/ImageUtilitiesCG.cpp:

(WebCore::findImagesForTranscoding):
(WebCore::transcodeImages):

  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::findClosestFont):
(WebCore::FontCache::getFontSelectionCapabilitiesInFamily):

  • platform/mediastream/RealtimeMediaSource.cpp:

(WebCore::RealtimeMediaSource::fitnessDistance):

  • platform/network/CacheValidation.cpp:

(WebCore::collectVaryingRequestHeadersInternal):

  • platform/network/FormData.cpp:

(WebCore::FormData::isolatedCopy const):

  • platform/network/SocketStreamHandleImpl.cpp:

(WebCore::SocketStreamHandleImpl::platformSendHandshake):

  • platform/network/cocoa/NetworkStorageSessionCocoa.mm:
  • platform/text/LocaleICU.cpp:

(WebCore::LocaleICU::createLabelVector):
(WebCore::createFallbackMonthLabels):
(WebCore::createFallbackAMPMLabels):

  • platform/text/LocaleNone.cpp:

(WebCore::LocaleNone::monthLabels):
(WebCore::LocaleNone::shortMonthLabels):
(WebCore::LocaleNone::timeAMPMLabels):

  • platform/text/cocoa/LocaleCocoa.mm:

(WebCore::LocaleCocoa::monthLabels):
(WebCore::LocaleCocoa::shortMonthLabels):
(WebCore::LocaleCocoa::standAloneMonthLabels):
(WebCore::LocaleCocoa::shortStandAloneMonthLabels):
(WebCore::LocaleCocoa::timeAMPMLabels):

  • plugins/DOMMimeTypeArray.cpp:

(WebCore::DOMMimeTypeArray::supportedPropertyNames const):
(WebCore::DOMMimeTypeArray::supportedPropertyNames): Deleted.

  • plugins/DOMMimeTypeArray.h:
  • plugins/DOMPlugin.cpp:

(WebCore::makeMimeTypes):
(WebCore::DOMPlugin::supportedPropertyNames const):
(WebCore::DOMPlugin::supportedPropertyNames): Deleted.

  • plugins/DOMPlugin.h:
  • plugins/DOMPluginArray.cpp:

(WebCore::DOMPluginArray::supportedPropertyNames const):
(WebCore::DOMPluginArray::supportedPropertyNames): Deleted.

  • plugins/DOMPluginArray.h:
  • rendering/LayerAncestorClippingStack.cpp:

(WebCore::LayerAncestorClippingStack::LayerAncestorClippingStack):
(WebCore::LayerAncestorClippingStack::compositedClipData const):

  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::clipBorderSidePolygon):

  • rendering/RenderElement.cpp:

(WebCore::RenderElement::drawLineForBoxSide const):

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::trackSizesForComputedStyle const):

  • style/ClassChangeInvalidation.cpp:

(WebCore::Style::collectClasses):

  • style/StyleBuilderConverter.h:

(WebCore::Style::BuilderConverter::convertTo100PercentMinusLength):

  • testing/MockCDMFactory.cpp:

(WebCore::MockCDMInstanceSession::updateLicense):
(WebCore::MockCDMInstanceSession::removeSessionData):

  • workers/service/server/SWServer.cpp:

(WebCore::SWServer::getRegistrations):

Source/WebKit:

  • Replace Vector::reserveCapacity() with Vector::reserveInitialCapacity() where appropriate
  • Replace Vector::append() with Vector::uncheckedAppend() where appropriate
  • Leverage the fact that Vector<Ref<Foo>> is now copyable (Because Ref<> now has a copy constructor)
  • Call crossThreadCopy() to isolate-copy a Vector() without iterating.
  • Leverage Vector constructor that takes in an intialization list in more cases
  • Leverage Vector::from() in more cases to simplify vector construction in some case.
  • Drop unnecessary calls to Vector::reserve*Capacity() before calling Vector::append(T*, size_t) since the append() implementation already does this for us.
  • Leverage copyToVector() and copyToVectorOf<> in more cases
  • Call shrinkToFit() in some cases where we reserve capacity and then append() but may not append() as much as we reserved.
  • NetworkProcess/WebStorage/LocalStorageDatabaseTracker.cpp:

(WebKit::LocalStorageDatabaseTracker::originDetailsCrossThreadCopy):

  • NetworkProcess/cache/CacheStorageEngineCaches.cpp:

(WebKit::CacheStorage::Caches::cacheInfos):

  • Shared/API/APIArray.cpp:

(API::Array::createStringArray):
(API::Array::copy):

  • Shared/API/APIDictionary.cpp:

(API::Dictionary::keys const):

  • Shared/UserData.cpp:

(WebKit::transformGraph):

  • Shared/WebContextMenuItem.cpp:

(WebKit::WebContextMenuItem::create):
(WebKit::WebContextMenuItem::submenuItemsAsAPIArray const):

  • Shared/WebContextMenuItemData.cpp:

(WebKit::kitItems):
(WebKit::coreItems):

  • UIProcess/API/APIWebAuthenticationPanel.cpp:

(API::WebAuthenticationPanel::WebAuthenticationPanel):

  • UIProcess/API/APIWebsitePolicies.cpp:

(API::WebsitePolicies::copy const):
(API::WebsitePolicies::data):

  • UIProcess/API/C/WKPage.cpp:

(API::toAPIObjectVector):
(WKPageSetPageContextMenuClient):
(WKPageSetPageFindMatchesClient):
(WKPageSetPageLoaderClient):

  • UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:

(WebKit::VideoFullscreenManagerProxy::forEachSession):

  • UIProcess/Gamepad/UIGamepadProvider.cpp:

(WebKit::UIGamepadProvider::snapshotGamepads):

  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::allNetworkProcesses):
(WebKit::NetworkProcessProxy::updatePrevalentDomainsToBlockCookiesFor):

  • UIProcess/Notifications/WebNotificationManagerProxy.cpp:

(WebKit::WebNotificationManagerProxy::providerDidRemoveNotificationPolicies):

  • UIProcess/Notifications/WebNotificationProvider.cpp:

(WebKit::WebNotificationProvider::clearNotifications):

  • UIProcess/StatisticsRequest.cpp:

(WebKit::StatisticsRequest::completedRequest):

  • UIProcess/UserContent/WebUserContentControllerProxy.cpp:

(WebKit::WebUserContentControllerProxy::removeAllUserScripts):
(WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets):

  • UIProcess/WebAuthentication/Cocoa/WebAuthenticationPanelClient.mm:

(WebKit::WebAuthenticationPanelClient::selectAssertionResponse const):

  • UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp:

(WebKit::CtapAuthenticator::continueGetNextAssertionAfterResponseReceived):

  • UIProcess/WebBackForwardList.cpp:

(WebKit::WebBackForwardList::addItem):
(WebKit::WebBackForwardList::clear):
(WebKit::WebBackForwardList::restoreFromState):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::runJavaScriptInFrameInScriptWorld):
(WebKit::WebPageProxy::speechSynthesisVoiceList):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::fetchDataAndApply):
(WebKit::WebsiteDataStore::parametersFromEachWebsiteDataStore):

  • UIProcess/mac/WKTextFinderClient.mm:

(-[WKTextFinderClient replaceMatches:withString:inSelectionOnly:resultCollector:]):

  • WebProcess/GPU/media/RemoteRemoteCommandListener.cpp:

(WebKit::RemoteRemoteCommandListener::updateSupportedCommands):

  • WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:

(contextMenuItems):
(WKBundlePageCopyOriginsWithApplicationCache):

  • WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.cpp:

(WebKit::InjectedBundlePageContextMenuClient::getCustomMenuFromDefaultItems):

  • WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp:

(WebKit::InjectedBundlePageFormClient::didAssociateFormControls):

  • WebProcess/Network/WebSocketStream.cpp:

(WebKit::WebSocketStream::networkProcessCrashed):

  • WebProcess/Network/webrtc/WebRTCResolver.cpp:

(WebKit::WebRTCResolver::setResolvedAddress):

  • WebProcess/WebCoreSupport/WebResourceLoadObserver.cpp:

(WebKit::WebResourceLoadObserver::takeStatistics):

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::replaceMatches):

  • WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:

(WebKit::toKeyframeValueVector):
(WebKit::PlatformCAAnimationRemote::setValues):
(WebKit::PlatformCAAnimationRemote::setTimingFunctions):

  • WebProcess/WebPage/ViewGestureGeometryCollector.cpp:

(WebKit::ViewGestureGeometryCollector::computeTextLegibilityScales):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::trackedRepaintRects):
(WebKit::dumpHistoryItem):

Source/WTF:

  • Replace Vector::reserveCapacity() with Vector::reserveInitialCapacity() where appropriate
  • Replace Vector::append() with Vector::uncheckedAppend() where appropriate
  • Leverage the fact that Vector<Ref<Foo>> is now copyable (Because Ref<> now has a copy constructor)
  • Call crossThreadCopy() to isolate-copy a Vector() without iterating.
  • Leverage Vector constructor that takes in an intialization list in more cases
  • Leverage Vector::from() in more cases to simplify vector construction in some case.
  • Drop unnecessary calls to Vector::reserve*Capacity() before calling Vector::append(T*, size_t) since the append() implementation already does this for us.
  • Leverage copyToVector() and copyToVectorOf<> in more cases
  • Call shrinkToFit() in some cases where we reserve capacity and then append() but may not append() as much as we reserved.
  • wtf/Language.cpp:

(WTF::userPreferredLanguages):
(WTF::isolatedCopy): Deleted.

File size: 6.8 KB
Line 
1/*
2 * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "DFGLivenessAnalysisPhase.h"
28
29#if ENABLE(DFG_JIT)
30
31#include "DFGBlockMapInlines.h"
32#include "DFGFlowIndexing.h"
33#include "DFGGraph.h"
34#include "DFGPhase.h"
35#include "JSCJSValueInlines.h"
36#include <wtf/BitVector.h>
37#include <wtf/IndexSparseSet.h>
38
39namespace JSC { namespace DFG {
40
41namespace {
42
43// Uncomment this to log hashtable operations.
44// static const char templateString[] = "unsigned, DefaultHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>";
45// typedef LoggingHashSet<templateString, unsigned, DefaultHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> LiveSet;
46
47typedef HashSet<unsigned, DefaultHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> LiveSet;
48
49typedef IndexSparseSet<unsigned, DefaultIndexSparseSetTraits<unsigned>, UnsafeVectorOverflow> Workset;
50
51class LivenessAnalysisPhase : public Phase {
52public:
53 LivenessAnalysisPhase(Graph& graph)
54 : Phase(graph, "liveness analysis")
55 , m_dirtyBlocks(m_graph.numBlocks())
56 , m_indexing(*m_graph.m_indexingCache)
57 , m_liveAtHead(m_graph)
58 , m_liveAtTail(m_graph)
59 {
60 m_graph.m_indexingCache->recompute();
61 m_workset = makeUnique<Workset>(m_graph.m_indexingCache->numIndices());
62 }
63
64 bool run()
65 {
66 // Start with all valid block dirty.
67 BlockIndex numBlock = m_graph.numBlocks();
68 m_dirtyBlocks.ensureSize(numBlock);
69 for (BlockIndex blockIndex = 0; blockIndex < numBlock; ++blockIndex) {
70 if (m_graph.block(blockIndex))
71 m_dirtyBlocks.quickSet(blockIndex);
72 }
73
74 // Fixpoint until we do not add any new live values at tail.
75 bool changed;
76 do {
77 changed = false;
78
79 for (BlockIndex blockIndex = numBlock; blockIndex--;) {
80 if (!m_dirtyBlocks.quickClear(blockIndex))
81 continue;
82
83 changed |= processBlock(blockIndex);
84 }
85 } while (changed);
86
87 // Update the per-block node list for live and tail.
88 for (BlockIndex blockIndex = numBlock; blockIndex--;) {
89 BasicBlock* block = m_graph.block(blockIndex);
90 if (!block)
91 continue;
92
93 {
94 block->ssa->liveAtHead = m_liveAtHead[blockIndex].map([this](auto index) {
95 return m_indexing.nodeProjection(index);
96 });
97 }
98 {
99 block->ssa->liveAtTail = WTF::map(m_liveAtTail[blockIndex], [this](auto index) {
100 return m_indexing.nodeProjection(index);
101 });
102 }
103 }
104
105 return true;
106 }
107
108private:
109 bool processBlock(BlockIndex blockIndex)
110 {
111 BasicBlock* block = m_graph.block(blockIndex);
112 ASSERT_WITH_MESSAGE(block, "Only dirty blocks needs updates. A null block should never be dirty.");
113
114 m_workset->clear();
115 for (unsigned index : m_liveAtTail[blockIndex])
116 m_workset->add(index);
117
118 for (unsigned nodeIndex = block->size(); nodeIndex--;) {
119 Node* node = block->at(nodeIndex);
120
121 auto handleEdge = [&] (Edge& edge) {
122 bool newEntry = m_workset->add(m_indexing.index(edge.node()));
123 edge.setKillStatus(newEntry ? DoesKill : DoesNotKill);
124 };
125
126 switch (node->op()) {
127 case Upsilon: {
128 ASSERT_WITH_MESSAGE(!m_workset->contains(node->index()), "Upsilon should not be used as defs by other nodes.");
129
130 Node* phi = node->phi();
131 m_workset->remove(m_indexing.shadowIndex(phi));
132 handleEdge(node->child1());
133 break;
134 }
135 case Phi: {
136 m_workset->remove(m_indexing.index(node));
137 m_workset->add(m_indexing.shadowIndex(node));
138 break;
139 }
140 default:
141 m_workset->remove(m_indexing.index(node));
142 m_graph.doToChildren(node, handleEdge);
143 break;
144 }
145 }
146
147 // Update live at head.
148 Vector<unsigned, 0, UnsafeVectorOverflow, 1>& liveAtHead = m_liveAtHead[blockIndex];
149 if (m_workset->size() == liveAtHead.size())
150 return false;
151
152 for (unsigned liveIndexAtHead : liveAtHead)
153 m_workset->remove(liveIndexAtHead);
154 ASSERT(!m_workset->isEmpty());
155
156 liveAtHead.reserveCapacity(liveAtHead.size() + m_workset->size());
157 for (unsigned newValue : *m_workset)
158 liveAtHead.uncheckedAppend(newValue);
159
160 bool changedPredecessor = false;
161 for (BasicBlock* predecessor : block->predecessors) {
162 LiveSet& liveAtTail = m_liveAtTail[predecessor];
163 for (unsigned newValue : *m_workset) {
164 if (liveAtTail.add(newValue)) {
165 if (!m_dirtyBlocks.quickSet(predecessor->index))
166 changedPredecessor = true;
167 }
168 }
169 }
170 return changedPredecessor;
171 }
172
173 // Blocks with new live values at tail.
174 BitVector m_dirtyBlocks;
175
176 FlowIndexing& m_indexing;
177
178 // Live values per block edge.
179 BlockMap<Vector<unsigned, 0, UnsafeVectorOverflow, 1>> m_liveAtHead;
180 BlockMap<LiveSet> m_liveAtTail;
181
182 // Single sparse set allocated once and used by every basic block.
183 std::unique_ptr<Workset> m_workset;
184};
185
186} // anonymous namespace
187
188bool performLivenessAnalysis(Graph& graph)
189{
190 graph.packNodeIndices();
191
192 return runPhase<LivenessAnalysisPhase>(graph);
193}
194
195} } // namespace JSC::DFG
196
197#endif // ENABLE(DFG_JIT)
198
Note: See TracBrowser for help on using the repository browser.