summaryrefslogtreecommitdiff
path: root/js/src/jit/FlowAliasAnalysis.h
blob: 91309d0d49ab9a02e78f17578949bec29edd672b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef jit_FlowAliasAnalysis_h
#define jit_FlowAliasAnalysis_h

#include "jit/AliasAnalysisShared.h"
#include "jit/MIR.h"
#include "jit/MIRGraph.h"

namespace js {
namespace jit {

class LoopInfo;
class MIRGraph;
class GraphStoreInfo;

typedef MDefinitionVector BlockStoreInfo;
typedef Vector<BlockStoreInfo*, 50, JitAllocPolicy> GraphStoreVector;

class FlowAliasAnalysis : public AliasAnalysisShared
{
    // Info on the graph.
    LoopInfo* loop_;
    GraphStoreInfo* stores_;

    // Helper vectors. In order to not have to recreate them the whole time.
    MDefinitionVector output_;
    MDefinitionVector worklist_;

  public:
    FlowAliasAnalysis(MIRGenerator* mir, MIRGraph& graph);
    MOZ_MUST_USE bool analyze() override;

  protected:
    /* Process instructions. */
    MOZ_MUST_USE bool processStore(BlockStoreInfo& stores, MDefinition* store);
    MOZ_MUST_USE bool processLoad(BlockStoreInfo& stores, MDefinition* load);
    MOZ_MUST_USE bool processDeferredLoads(LoopInfo* info);

    /* Improve dependency and helpers. */
    MOZ_MUST_USE bool improveDependency(MDefinition* load, MDefinitionVector& inputStores,
                                        MDefinitionVector& outputStores);
    MOZ_MUST_USE bool improveNonAliasedStores(MDefinition* load, MDefinitionVector& inputStores,
                                              MDefinitionVector& outputStores, bool* improved,
                                              bool onlyControlInstructions = false);
    MOZ_MUST_USE bool improveStoresInFinishedLoops(MDefinition* load, MDefinitionVector& stores,
                                                   bool* improved);

    MOZ_MUST_USE bool improveLoopDependency(MDefinition* load, MDefinitionVector& inputStores,
                                            MDefinitionVector& outputStores);
    MOZ_MUST_USE bool deferImproveDependency(MDefinitionVector& stores);

    /* Save dependency info. */
    void saveLoadDependency(MDefinition* load, MDefinitionVector& dependencies);
    MOZ_MUST_USE bool saveStoreDependency(MDefinition* store, BlockStoreInfo& prevStores);

    /* Helper functions. */
    MOZ_MUST_USE bool computeBlockStores(MBasicBlock* block);
    MOZ_MUST_USE bool isLoopInvariant(MDefinition* load, MDefinition* store, bool* loopinvariant);
    bool loopIsFinished(MBasicBlock* loopheader);

};

} // namespace jit
} // namespace js

#endif /* jit_FlowAliasAnalysis_h */