2 +----------------------------------------------------------------------+
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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_HHBBC_OPTIONS_H_
17 #define incl_HPHP_HHBBC_OPTIONS_H_
22 #include "hphp/util/hash-map.h"
23 #include "hphp/util/hash-set.h"
24 #include "hphp/util/hash.h"
28 enum class Op
: uint16_t;
30 size_t operator()(Op op
) const {
31 return hash_int64(static_cast<uint16_t>(op
));
37 using MethodMap
= hphp_fast_string_imap
<hphp_fast_string_iset
>;
38 using OpcodeSet
= hphp_fast_set
<Op
,OpHash
>;
40 //////////////////////////////////////////////////////////////////////
43 * Publically-settable options that control compilation.
47 * When debugging, it can be useful to ask for certain functions to be traced
48 * at a higher level than the rest of the program.
50 MethodMap TraceFunctions
;
53 * When debugging, it can be useful to ask for a list of functions
54 * that use particular bytecodes.
56 OpcodeSet TraceBytecodes
;
59 * If non-empty, dump jemalloc memory profiles at key points during
60 * the build, using this as a prefix.
62 std::string profileMemory
;
64 //////////////////////////////////////////////////////////////////////
67 * Flags for various limits on when to perform widening operations.
68 * See analyze.cpp for details.
70 uint32_t analyzeFuncWideningLimit
= 12;
71 uint32_t analyzeClassWideningLimit
= 6;
74 * When to stop refining return types.
76 * This needs to be limited because types can walk downwards in our
77 * type lattice indefinitely. The index never contains incorrect
78 * return types, since the return types only shrink, which means we
79 * can just stop refining a return type whenever we want to without
82 * For an example of where this can occur, imagine the analysis of the
85 * function foo() { return array('x' => foo()); }
87 * Each time we visit `foo', we'll discover a slightly smaller return
88 * type, in a downward-moving sequence that would never terminate:
90 * InitCell, CArrN(x:InitCell), CArrN(x:CArrN(x:InitCell)), ...
92 uint32_t returnTypeRefineLimit
= 15;
95 * Limit public static property refinement for the same reason.
97 uint32_t publicSPropRefineLimit
= 15;
100 * Whether to produce extended stats information. (Takes extra
103 bool extendedStats
= false;
105 //////////////////////////////////////////////////////////////////////
108 * If true, all optimizations are disabled, and analysis isn't even
111 bool NoOptimizations
= false;
114 * If true, analyze calls to functions in a context-sensitive way.
116 * Disabled by default because its slow, with very little gain.
118 bool ContextSensitiveInterp
= false;
121 * If true, completely remove jumps to blocks that are inferred to be dead.
122 * When false, dead blocks are replaced with Fatal bytecodes.
124 bool RemoveDeadBlocks
= true;
127 * Whether to propagate constant values by replacing instructions which are
128 * known to always produce a constant with instructions that produce that
131 bool ConstantProp
= true;
134 * Whether we should evaluate side-effect free builtins at compile time when
135 * they have compile-time constant arguments.
137 bool ConstantFoldBuiltins
= true;
140 * Whether to perform local or global dead code elimination. This removes
141 * unnecessary instructions within a single block, or across blocks,
144 bool LocalDCE
= true;
145 bool GlobalDCE
= true;
148 * Whether to remove completely unused local variables. This requires
151 bool RemoveUnusedLocals
= true;
154 * Whether to remove completely unused class-ref slots. This requires
157 bool RemoveUnusedClsRefSlots
= true;
160 * If true, insert opcodes that assert inferred types, so we can assume them
163 bool InsertAssertions
= true;
164 bool InsertStackAssertions
= true;
167 * If true, try to filter asserts out that are "obvious" (this is a code size
168 * optimization). It can be useful to turn this option off for debugging.
170 * Has no effect if !InsertStackAssertions.
172 bool FilterAssertions
= true;
175 * Whether to replace bytecode with less expensive bytecodes when we can.
176 * E.g. InstanceOf -> InstanceOfD or FPushFunc -> FPushFuncD.
178 bool StrengthReduce
= true;
181 * Whether to enable 'FuncFamily' method resolution.
183 * This allows possible overrides of a method to be resolved as a
184 * set of candidates when we aren't sure which one it would be.
186 bool FuncFamilies
= true;
189 * Whether or not hhbbc should attempt to do anything intelligent to
192 bool AnalyzePseudomains
= true;
195 * Should we do an extra whole-program pass to try to determine the types of
196 * public static properties. This will not yield any useful information for
197 * programs that contain any sets to static properties with both a dynamic
198 * property name and an unknown class type.
200 bool AnalyzePublicStatics
= true;
202 //////////////////////////////////////////////////////////////////////
203 // Flags below this line perform optimizations that intentionally
204 // may have user-visible changes to program behavior.
205 //////////////////////////////////////////////////////////////////////
208 * If true, we'll propagate global defined constants, class constants, and
209 * constant static class properties "unsoundly". I.e., it is visible to the
210 * user that we may not invoke autoload at places where we would have without
213 bool HardConstProp
= true;
216 * If true, we'll try to infer the types of declared private class
219 * This is in the can-potentially-change-program-behavior section
220 * because if you unserialize specially-constructed strings you
221 * could create instances with private properties that don't follow
222 * the inferred types. HHVM tracks the types that were inferred,
223 * and if an unserialize happens that would violate what we've
224 * inferred, we'll raise a notice and unserialize() returns false.
226 bool HardPrivatePropInference
= true;
229 * If true, we'll perform optimizations which can remove invocations of the
230 * autoloader, if it can be proven the invocation would not find a viable
233 bool ElideAutoloadInvokes
= true;
236 * Whether to flatten trait methods and properties into the classes
239 bool FlattenTraits
= true;
242 * The filepath where to save the stats file. If the path is empty, then we
243 * save the stats file to a temporary file.
245 std::string stats_file
;
247 extern Options options
;