Path: blob/master/src/hotspot/share/c1/c1_IR.hpp
40930 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_C1_C1_IR_HPP25#define SHARE_C1_C1_IR_HPP2627#include "c1/c1_Instruction.hpp"28#include "ci/ciExceptionHandler.hpp"29#include "ci/ciMethod.hpp"30#include "ci/ciStreams.hpp"31#include "memory/allocation.hpp"3233// An XHandler is a C1 internal description for an exception handler3435class XHandler: public CompilationResourceObj {36private:37ciExceptionHandler* _desc;3839BlockBegin* _entry_block; // Entry block of xhandler40LIR_List* _entry_code; // LIR-operations that must be executed before jumping to entry_block41int _entry_pco; // pco where entry_code (or entry_block if no entry_code) starts42int _phi_operand; // For resolving of phi functions at begin of entry_block43int _scope_count; // for filling ExceptionRangeEntry::scope_count4445#ifdef ASSERT46int _lir_op_id; // op_id of the LIR-operation throwing to this handler47#endif4849public:50// creation51XHandler(ciExceptionHandler* desc)52: _desc(desc)53, _entry_block(NULL)54, _entry_code(NULL)55, _entry_pco(-1)56, _phi_operand(-1)57, _scope_count(-1)58#ifdef ASSERT59, _lir_op_id(-1)60#endif61{ }6263XHandler(XHandler* other)64: _desc(other->_desc)65, _entry_block(other->_entry_block)66, _entry_code(other->_entry_code)67, _entry_pco(other->_entry_pco)68, _phi_operand(other->_phi_operand)69, _scope_count(other->_scope_count)70#ifdef ASSERT71, _lir_op_id(other->_lir_op_id)72#endif73{ }7475// accessors for data of ciExceptionHandler76int beg_bci() const { return _desc->start(); }77int end_bci() const { return _desc->limit(); }78int handler_bci() const { return _desc->handler_bci(); }79bool is_catch_all() const { return _desc->is_catch_all(); }80int catch_type() const { return _desc->catch_klass_index(); }81ciInstanceKlass* catch_klass() const { return _desc->catch_klass(); }82bool covers(int bci) const { return beg_bci() <= bci && bci < end_bci(); }8384// accessors for additional fields85BlockBegin* entry_block() const { return _entry_block; }86LIR_List* entry_code() const { return _entry_code; }87int entry_pco() const { return _entry_pco; }88int phi_operand() const { assert(_phi_operand != -1, "not set"); return _phi_operand; }89int scope_count() const { assert(_scope_count != -1, "not set"); return _scope_count; }90DEBUG_ONLY(int lir_op_id() const { return _lir_op_id; });9192void set_entry_block(BlockBegin* entry_block) {93assert(entry_block->is_set(BlockBegin::exception_entry_flag), "must be an exception handler entry");94assert(entry_block->bci() == handler_bci(), "bci's must correspond");95_entry_block = entry_block;96}97void set_entry_code(LIR_List* entry_code) { _entry_code = entry_code; }98void set_entry_pco(int entry_pco) { _entry_pco = entry_pco; }99void set_phi_operand(int phi_operand) { _phi_operand = phi_operand; }100void set_scope_count(int scope_count) { _scope_count = scope_count; }101DEBUG_ONLY(void set_lir_op_id(int lir_op_id) { _lir_op_id = lir_op_id; });102103bool equals(XHandler* other) const;104};105106typedef GrowableArray<XHandler*> _XHandlerList;107108// XHandlers is the C1 internal list of exception handlers for a method109class XHandlers: public CompilationResourceObj {110private:111_XHandlerList _list;112113public:114// creation115XHandlers() : _list() { }116XHandlers(ciMethod* method);117XHandlers(XHandlers* other);118119// accessors120int length() const { return _list.length(); }121XHandler* handler_at(int i) const { return _list.at(i); }122bool has_handlers() const { return _list.length() > 0; }123void append(XHandler* h) { _list.append(h); }124XHandler* remove_last() { return _list.pop(); }125126bool could_catch(ciInstanceKlass* klass, bool type_is_exact) const;127bool equals(XHandlers* others) const;128};129130131class IRScope;132typedef GrowableArray<IRScope*> IRScopeList;133134class Compilation;135class IRScope: public CompilationResourceObj {136private:137// hierarchy138Compilation* _compilation; // the current compilation139IRScope* _caller; // the caller scope, or NULL140int _level; // the inlining level141ciMethod* _method; // the corresponding method142IRScopeList _callees; // the inlined method scopes143144// graph145XHandlers* _xhandlers; // the exception handlers146int _number_of_locks; // the number of monitor lock slots needed147bool _monitor_pairing_ok; // the monitor pairing info148bool _wrote_final; // has written final field149bool _wrote_fields; // has written fields150bool _wrote_volatile; // has written volatile field151BlockBegin* _start; // the start block, successsors are method entries152153ResourceBitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable154155// helper functions156BlockBegin* build_graph(Compilation* compilation, int osr_bci);157158public:159// creation160IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph = false);161162// accessors163Compilation* compilation() const { return _compilation; }164IRScope* caller() const { return _caller; }165int level() const { return _level; }166ciMethod* method() const { return _method; }167int max_stack() const; // NOTE: expensive168BitMap& requires_phi_function() { return _requires_phi_function; }169170// hierarchy171bool is_top_scope() const { return _caller == NULL; }172void add_callee(IRScope* callee) { _callees.append(callee); }173int number_of_callees() const { return _callees.length(); }174IRScope* callee_no(int i) const { return _callees.at(i); }175176// accessors, graph177bool is_valid() const { return start() != NULL; }178XHandlers* xhandlers() const { return _xhandlers; }179int number_of_locks() const { return _number_of_locks; }180void set_min_number_of_locks(int n) { if (n > _number_of_locks) _number_of_locks = n; }181bool monitor_pairing_ok() const { return _monitor_pairing_ok; }182BlockBegin* start() const { return _start; }183void set_wrote_final() { _wrote_final = true; }184bool wrote_final () const { return _wrote_final; }185void set_wrote_fields() { _wrote_fields = true; }186bool wrote_fields () const { return _wrote_fields; }187void set_wrote_volatile() { _wrote_volatile = true; }188bool wrote_volatile () const { return _wrote_volatile; }189};190191192//193// IRScopeDebugInfo records the debug information for a particular IRScope194// in a particular CodeEmitInfo. This allows the information to be computed195// once early enough for the OopMap to be available to the LIR and also to be196// reemited for different pcs using the same CodeEmitInfo without recomputing197// everything.198//199200class IRScopeDebugInfo: public CompilationResourceObj {201private:202IRScope* _scope;203int _bci;204GrowableArray<ScopeValue*>* _locals;205GrowableArray<ScopeValue*>* _expressions;206GrowableArray<MonitorValue*>* _monitors;207IRScopeDebugInfo* _caller;208209public:210IRScopeDebugInfo(IRScope* scope,211int bci,212GrowableArray<ScopeValue*>* locals,213GrowableArray<ScopeValue*>* expressions,214GrowableArray<MonitorValue*>* monitors,215IRScopeDebugInfo* caller):216_scope(scope)217, _bci(bci)218, _locals(locals)219, _expressions(expressions)220, _monitors(monitors)221, _caller(caller) {}222223224IRScope* scope() { return _scope; }225int bci() { return _bci; }226GrowableArray<ScopeValue*>* locals() { return _locals; }227GrowableArray<ScopeValue*>* expressions() { return _expressions; }228GrowableArray<MonitorValue*>* monitors() { return _monitors; }229IRScopeDebugInfo* caller() { return _caller; }230231//Whether we should reexecute this bytecode for deopt232bool should_reexecute();233234void record_debug_info(DebugInformationRecorder* recorder, int pc_offset, bool topmost, bool is_method_handle_invoke = false) {235if (caller() != NULL) {236// Order is significant: Must record caller first.237caller()->record_debug_info(recorder, pc_offset, false/*topmost*/);238}239DebugToken* locvals = recorder->create_scope_values(locals());240DebugToken* expvals = recorder->create_scope_values(expressions());241DebugToken* monvals = recorder->create_monitor_values(monitors());242// reexecute allowed only for the topmost frame243bool reexecute = topmost ? should_reexecute() : false;244bool return_oop = false; // This flag will be ignored since it used only for C2 with escape analysis.245bool rethrow_exception = false;246bool is_opt_native = false;247bool has_ea_local_in_scope = false;248bool arg_escape = false;249recorder->describe_scope(pc_offset, methodHandle(), scope()->method(), bci(),250reexecute, rethrow_exception, is_method_handle_invoke, is_opt_native, return_oop,251has_ea_local_in_scope, arg_escape, locvals, expvals, monvals);252}253};254255256class CodeEmitInfo: public CompilationResourceObj {257friend class LinearScan;258private:259IRScopeDebugInfo* _scope_debug_info;260IRScope* _scope;261XHandlers* _exception_handlers;262OopMap* _oop_map;263ValueStack* _stack; // used by deoptimization (contains also monitors264bool _is_method_handle_invoke; // true if the associated call site is a MethodHandle call site.265bool _deoptimize_on_exception;266267FrameMap* frame_map() const { return scope()->compilation()->frame_map(); }268Compilation* compilation() const { return scope()->compilation(); }269270public:271272// use scope from ValueStack273CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers, bool deoptimize_on_exception = false);274275// make a copy276CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack = NULL);277278// accessors279OopMap* oop_map() { return _oop_map; }280ciMethod* method() const { return _scope->method(); }281IRScope* scope() const { return _scope; }282XHandlers* exception_handlers() const { return _exception_handlers; }283ValueStack* stack() const { return _stack; }284bool deoptimize_on_exception() const { return _deoptimize_on_exception; }285286void add_register_oop(LIR_Opr opr);287void record_debug_info(DebugInformationRecorder* recorder, int pc_offset);288289bool is_method_handle_invoke() const { return _is_method_handle_invoke; }290void set_is_method_handle_invoke(bool x) { _is_method_handle_invoke = x; }291292int interpreter_frame_size() const;293};294295296class IR: public CompilationResourceObj {297private:298Compilation* _compilation; // the current compilation299IRScope* _top_scope; // the root of the scope hierarchy300int _num_loops; // Total number of loops301BlockList* _code; // the blocks in code generation order w/ use counts302303public:304// creation305IR(Compilation* compilation, ciMethod* method, int osr_bci);306307// accessors308bool is_valid() const { return top_scope()->is_valid(); }309Compilation* compilation() const { return _compilation; }310IRScope* top_scope() const { return _top_scope; }311int number_of_locks() const { return top_scope()->number_of_locks(); }312ciMethod* method() const { return top_scope()->method(); }313BlockBegin* start() const { return top_scope()->start(); }314BlockBegin* std_entry() const { return start()->end()->as_Base()->std_entry(); }315BlockBegin* osr_entry() const { return start()->end()->as_Base()->osr_entry(); }316BlockList* code() const { return _code; }317int num_loops() const { return _num_loops; }318int max_stack() const { return top_scope()->max_stack(); } // expensive319320// ir manipulation321void optimize_blocks();322void eliminate_null_checks();323void compute_predecessors();324void split_critical_edges();325void compute_code();326void compute_use_counts();327328// The linear-scan order and the code emission order are equal, but329// this may change in future330BlockList* linear_scan_order() { assert(_code != NULL, "not computed"); return _code; }331332// iteration333void iterate_preorder (BlockClosure* closure);334void iterate_postorder (BlockClosure* closure);335void iterate_linear_scan_order(BlockClosure* closure);336337// debugging338static void print(BlockBegin* start, bool cfg_only, bool live_only = false) PRODUCT_RETURN;339void print(bool cfg_only, bool live_only = false) PRODUCT_RETURN;340void verify() PRODUCT_RETURN;341};342343344// Globally do instruction substitution and remove substituted345// instructions from the instruction list.346//347348class SubstitutionResolver: public BlockClosure, ValueVisitor {349virtual void visit(Value* v);350351public:352SubstitutionResolver(IR* hir) {353hir->iterate_preorder(this);354}355356SubstitutionResolver(BlockBegin* block) {357block->iterate_preorder(this);358}359360virtual void block_do(BlockBegin* block);361};362363#endif // SHARE_C1_C1_IR_HPP364365366