1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
287
288 private:
289 // Helper methods for fold_compares
290 bool cmpi_folds(PhaseIterGVN* igvn);
291 bool is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn);
292 bool has_shared_region(ProjNode* proj, ProjNode*& success, ProjNode*& fail);
293 bool has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn);
294 Node* merge_uncommon_traps(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
295 static void improve_address_types(Node* l, Node* r, ProjNode* fail, PhaseIterGVN* igvn);
296 bool is_cmp_with_loadrange(ProjNode* proj);
297 bool is_null_check(ProjNode* proj, PhaseIterGVN* igvn);
298 bool is_side_effect_free_test(ProjNode* proj, PhaseIterGVN* igvn);
299 void reroute_side_effect_free_unc(ProjNode* proj, ProjNode* dom_proj, PhaseIterGVN* igvn);
300 ProjNode* uncommon_trap_proj(CallStaticJavaNode*& call) const;
301 bool fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
302 static bool is_dominator_unc(CallStaticJavaNode* dom_unc, CallStaticJavaNode* unc);
303
304 protected:
305 ProjNode* range_check_trap_proj(int& flip, Node*& l, Node*& r);
306 Node* Ideal_common(PhaseGVN *phase, bool can_reshape);
307 Node* dominated_by(Node* prev_dom, PhaseIterGVN* igvn);
308 Node* search_identical(int dist);
309
310 public:
311
312 // Degrees of branch prediction probability by order of magnitude:
313 // PROB_UNLIKELY_1e(N) is a 1 in 1eN chance.
314 // PROB_LIKELY_1e(N) is a 1 - PROB_UNLIKELY_1e(N)
315 #define PROB_UNLIKELY_MAG(N) (1e- ## N ## f)
316 #define PROB_LIKELY_MAG(N) (1.0f-PROB_UNLIKELY_MAG(N))
317
318 // Maximum and minimum branch prediction probabilties
319 // 1 in 1,000,000 (magnitude 6)
320 //
321 // Although PROB_NEVER == PROB_MIN and PROB_ALWAYS == PROB_MAX
322 // they are used to distinguish different situations:
323 //
324 // The name PROB_MAX (PROB_MIN) is for probabilities which correspond to
325 // very likely (unlikely) but with a concrete possibility of a rare
326 // contrary case. These constants would be used for pinning
327 // measurements, and as measures for assertions that have high
375 // Magic manifest probabilities such as 0.83, 0.7, ... can be found in
376 // gen_subtype_check() and catch_inline_exceptions().
377
378 float _prob; // Probability of true path being taken.
379 float _fcnt; // Frequency counter
380 IfNode( Node *control, Node *b, float p, float fcnt )
381 : MultiBranchNode(2), _prob(p), _fcnt(fcnt) {
382 init_class_id(Class_If);
383 init_req(0,control);
384 init_req(1,b);
385 }
386 virtual int Opcode() const;
387 virtual bool pinned() const { return true; }
388 virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
389 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
390 virtual const Type* Value(PhaseGVN* phase) const;
391 virtual int required_outcnt() const { return 2; }
392 virtual const RegMask &out_RegMask() const;
393 Node* fold_compares(PhaseIterGVN* phase);
394 static Node* up_one_dom(Node* curr, bool linear_only = false);
395
396 // Takes the type of val and filters it through the test represented
397 // by if_proj and returns a more refined type if one is produced.
398 // Returns NULL is it couldn't improve the type.
399 static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);
400
401 #ifndef PRODUCT
402 virtual void dump_spec(outputStream *st) const;
403 virtual void related(GrowableArray <Node *> *in_rel, GrowableArray <Node *> *out_rel, bool compact) const;
404 #endif
405 };
406
407 class RangeCheckNode : public IfNode {
408 private:
409 int is_range_check(Node* &range, Node* &index, jint &offset);
410
411 public:
412 RangeCheckNode(Node* control, Node *b, float p, float fcnt)
413 : IfNode(control, b, p, fcnt) {
414 init_class_id(Class_RangeCheck);
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
287
288 private:
289 // Helper methods for fold_compares
290 bool cmpi_folds(PhaseIterGVN* igvn);
291 bool is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn);
292 bool has_shared_region(ProjNode* proj, ProjNode*& success, ProjNode*& fail);
293 bool has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn);
294 Node* merge_uncommon_traps(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
295 static void improve_address_types(Node* l, Node* r, ProjNode* fail, PhaseIterGVN* igvn);
296 bool is_cmp_with_loadrange(ProjNode* proj);
297 bool is_null_check(ProjNode* proj, PhaseIterGVN* igvn);
298 bool is_side_effect_free_test(ProjNode* proj, PhaseIterGVN* igvn);
299 void reroute_side_effect_free_unc(ProjNode* proj, ProjNode* dom_proj, PhaseIterGVN* igvn);
300 ProjNode* uncommon_trap_proj(CallStaticJavaNode*& call) const;
301 bool fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
302 static bool is_dominator_unc(CallStaticJavaNode* dom_unc, CallStaticJavaNode* unc);
303
304 protected:
305 ProjNode* range_check_trap_proj(int& flip, Node*& l, Node*& r);
306 Node* Ideal_common(PhaseGVN *phase, bool can_reshape);
307 Node* search_identical(int dist);
308
309 public:
310
311 // Degrees of branch prediction probability by order of magnitude:
312 // PROB_UNLIKELY_1e(N) is a 1 in 1eN chance.
313 // PROB_LIKELY_1e(N) is a 1 - PROB_UNLIKELY_1e(N)
314 #define PROB_UNLIKELY_MAG(N) (1e- ## N ## f)
315 #define PROB_LIKELY_MAG(N) (1.0f-PROB_UNLIKELY_MAG(N))
316
317 // Maximum and minimum branch prediction probabilties
318 // 1 in 1,000,000 (magnitude 6)
319 //
320 // Although PROB_NEVER == PROB_MIN and PROB_ALWAYS == PROB_MAX
321 // they are used to distinguish different situations:
322 //
323 // The name PROB_MAX (PROB_MIN) is for probabilities which correspond to
324 // very likely (unlikely) but with a concrete possibility of a rare
325 // contrary case. These constants would be used for pinning
326 // measurements, and as measures for assertions that have high
374 // Magic manifest probabilities such as 0.83, 0.7, ... can be found in
375 // gen_subtype_check() and catch_inline_exceptions().
376
377 float _prob; // Probability of true path being taken.
378 float _fcnt; // Frequency counter
379 IfNode( Node *control, Node *b, float p, float fcnt )
380 : MultiBranchNode(2), _prob(p), _fcnt(fcnt) {
381 init_class_id(Class_If);
382 init_req(0,control);
383 init_req(1,b);
384 }
385 virtual int Opcode() const;
386 virtual bool pinned() const { return true; }
387 virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
388 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
389 virtual const Type* Value(PhaseGVN* phase) const;
390 virtual int required_outcnt() const { return 2; }
391 virtual const RegMask &out_RegMask() const;
392 Node* fold_compares(PhaseIterGVN* phase);
393 static Node* up_one_dom(Node* curr, bool linear_only = false);
394 Node* dominated_by(Node* prev_dom, PhaseIterGVN* igvn);
395
396 // Takes the type of val and filters it through the test represented
397 // by if_proj and returns a more refined type if one is produced.
398 // Returns NULL is it couldn't improve the type.
399 static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);
400
401 #ifndef PRODUCT
402 virtual void dump_spec(outputStream *st) const;
403 virtual void related(GrowableArray <Node *> *in_rel, GrowableArray <Node *> *out_rel, bool compact) const;
404 #endif
405 };
406
407 class RangeCheckNode : public IfNode {
408 private:
409 int is_range_check(Node* &range, Node* &index, jint &offset);
410
411 public:
412 RangeCheckNode(Node* control, Node *b, float p, float fcnt)
413 : IfNode(control, b, p, fcnt) {
414 init_class_id(Class_RangeCheck);
|