codemod 2010-2016 to 2010-present
[hiphop-php.git] / hphp / runtime / vm / jit / mutation.h
bloba9558cbb6c4cc516e97acc39b204b9fe4e8d63b4
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_JIT_MUTATION_H_
18 #define incl_HPHP_JIT_MUTATION_H_
20 #include "hphp/runtime/vm/jit/block.h"
21 #include "hphp/runtime/vm/jit/cfg.h"
23 namespace HPHP { namespace jit {
25 struct IRInstruction;
26 struct IRUnit;
28 //////////////////////////////////////////////////////////////////////
31 * Utility routines for mutating the IR during optimization passes.
34 //////////////////////////////////////////////////////////////////////
37 * Clone a range of IRInstructions into the front of a target block
38 * (immediately after its DefLabel).
40 * Then, for any block reachable from `target', rewrite the sources of
41 * any instructions that referred to the old destinations of the
42 * cloned instructions so that they refer to the new destinations this
43 * function created.
45 * Does not unlink the instructions from the source block.
47 * Pre: The range [first,last) may not contain control flow
48 * instructions.
49 * Pre: blocks is in reverse postorder
51 void cloneToBlock(const BlockList& blocks,
52 IRUnit& unit,
53 Block::iterator first,
54 Block::iterator last,
55 Block* target);
58 * Move a range of IRInstructions to the front of a target block
59 * (immediately after its DefLabel, but before its Marker).
61 * The instructions are unlinked from their current source block.
63 * Pre: The range [first,last) may not contain control flow
64 * instructions.
66 void moveToBlock(Block::iterator first,
67 Block::iterator last,
68 Block* dst);
71 * Walk the cfg of the given unit, recomputing output types of all instructions
72 * from their inputs.
74 * The new types of any changed SSATmps must be related to their old
75 * types. However, notice that the new types may result in
76 * inconsistent operand types for instructions that are unreachable
77 * (but not yet removed from the IR unit).
79 void reflowTypes(IRUnit&);
82 * Recomputes the output type of each of inst's dests.
84 * Returns: true if any of the instruction's dest types were changed.
86 bool retypeDests(IRInstruction*, const IRUnit*);
89 * Small pass that inserts AssertTypes on the taken edges of CheckType blocks
90 * that may add type information about failing checks. This pass is probably
91 * worth running before refineTmps, because it may allow better types when
92 * checks fail.
94 * (Note: the supplied block list need not be RPO-sorted.)
96 void insertNegativeAssertTypes(IRUnit&, const BlockList&);
99 * Pass that walks over the dominator tree and replaces uses of SSATmps that
100 * have more-refined versions available with uses of the more refined versions.
101 * This basically fixes patterns like this:
103 * t1 = LdLoc<Cell>
104 * t2 = CheckType<Obj> t1 -> ...
105 * IncRef t1
107 * So that we can replace t1 with t2 in the parts of the code dominated by the
108 * definition of t2.
110 void refineTmps(IRUnit&, const BlockList&, const IdomVector&);
113 * Insert a phi for inputs in blk. none of blk's input edges may be
114 * critical, blk->numPreds() must be equal to inputs.size(), and
115 * inputs.size() must be greater than 1.
116 * If there's already a suitable phi, it will be returned.
118 SSATmp* insertPhi(IRUnit&, Block* blk, const jit::vector<SSATmp*>& inputs);
121 * Remove the i'th dest from `label' and all incoming Jmps, returning its
122 * SSATmp*. May leave the DefLabel with 0 dests, in which case the instruction
123 * may be deleted by the caller.
125 SSATmp* deletePhiDest(IRInstruction* label, unsigned i);
127 //////////////////////////////////////////////////////////////////////
131 #endif