c1_IR.hpp revision 1253
0N/A/*
948N/A * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A// An XHandler is a C1 internal description for an exception handler
0N/A
0N/Aclass XHandler: public CompilationResourceObj {
0N/A private:
0N/A ciExceptionHandler* _desc;
0N/A
0N/A BlockBegin* _entry_block; // Entry block of xhandler
0N/A LIR_List* _entry_code; // LIR-operations that must be executed before jumping to entry_block
0N/A int _entry_pco; // pco where entry_code (or entry_block if no entry_code) starts
0N/A int _phi_operand; // For resolving of phi functions at begin of entry_block
0N/A int _scope_count; // for filling ExceptionRangeEntry::scope_count
0N/A
0N/A#ifdef ASSERT
0N/A int _lir_op_id; // op_id of the LIR-operation throwing to this handler
0N/A#endif
0N/A
0N/A public:
0N/A // creation
0N/A XHandler(ciExceptionHandler* desc)
0N/A : _desc(desc)
0N/A , _entry_block(NULL)
0N/A , _entry_code(NULL)
0N/A , _entry_pco(-1)
0N/A , _phi_operand(-1)
0N/A , _scope_count(-1)
0N/A#ifdef ASSERT
0N/A , _lir_op_id(-1)
0N/A#endif
0N/A { }
0N/A
0N/A XHandler(XHandler* other)
0N/A : _desc(other->_desc)
0N/A , _entry_block(other->_entry_block)
0N/A , _entry_code(other->_entry_code)
0N/A , _entry_pco(other->_entry_pco)
0N/A , _phi_operand(other->_phi_operand)
0N/A , _scope_count(other->_scope_count)
0N/A#ifdef ASSERT
0N/A , _lir_op_id(other->_lir_op_id)
0N/A#endif
0N/A { }
0N/A
0N/A // accessors for data of ciExceptionHandler
0N/A int beg_bci() const { return _desc->start(); }
0N/A int end_bci() const { return _desc->limit(); }
0N/A int handler_bci() const { return _desc->handler_bci(); }
0N/A bool is_catch_all() const { return _desc->is_catch_all(); }
0N/A int catch_type() const { return _desc->catch_klass_index(); }
0N/A ciInstanceKlass* catch_klass() const { return _desc->catch_klass(); }
0N/A bool covers(int bci) const { return beg_bci() <= bci && bci < end_bci(); }
0N/A
0N/A // accessors for additional fields
0N/A BlockBegin* entry_block() const { return _entry_block; }
0N/A LIR_List* entry_code() const { return _entry_code; }
0N/A int entry_pco() const { return _entry_pco; }
0N/A int phi_operand() const { assert(_phi_operand != -1, "not set"); return _phi_operand; }
0N/A int scope_count() const { assert(_scope_count != -1, "not set"); return _scope_count; }
0N/A DEBUG_ONLY(int lir_op_id() const { return _lir_op_id; });
0N/A
0N/A void set_entry_block(BlockBegin* entry_block) {
0N/A assert(entry_block->is_set(BlockBegin::exception_entry_flag), "must be an exception handler entry");
0N/A assert(entry_block->bci() == handler_bci(), "bci's must correspond");
0N/A _entry_block = entry_block;
0N/A }
0N/A void set_entry_code(LIR_List* entry_code) { _entry_code = entry_code; }
0N/A void set_entry_pco(int entry_pco) { _entry_pco = entry_pco; }
0N/A void set_phi_operand(int phi_operand) { _phi_operand = phi_operand; }
0N/A void set_scope_count(int scope_count) { _scope_count = scope_count; }
0N/A DEBUG_ONLY(void set_lir_op_id(int lir_op_id) { _lir_op_id = lir_op_id; });
0N/A
0N/A bool equals(XHandler* other) const;
0N/A};
0N/A
0N/Adefine_array(_XHandlerArray, XHandler*)
0N/Adefine_stack(_XHandlerList, _XHandlerArray)
0N/A
0N/A
0N/A// XHandlers is the C1 internal list of exception handlers for a method
0N/Aclass XHandlers: public CompilationResourceObj {
0N/A private:
0N/A _XHandlerList _list;
0N/A
0N/A public:
0N/A // creation
0N/A XHandlers() : _list() { }
0N/A XHandlers(ciMethod* method);
0N/A XHandlers(XHandlers* other);
0N/A
0N/A // accessors
0N/A int length() const { return _list.length(); }
0N/A XHandler* handler_at(int i) const { return _list.at(i); }
0N/A bool has_handlers() const { return _list.length() > 0; }
0N/A void append(XHandler* h) { _list.append(h); }
0N/A XHandler* remove_last() { return _list.pop(); }
0N/A
0N/A bool could_catch(ciInstanceKlass* klass, bool type_is_exact) const;
0N/A bool equals(XHandlers* others) const;
0N/A};
0N/A
0N/A
0N/Aclass IRScope;
0N/Adefine_array(IRScopeArray, IRScope*)
0N/Adefine_stack(IRScopeList, IRScopeArray)
0N/A
0N/Aclass Compilation;
0N/Aclass IRScope: public CompilationResourceObj {
0N/A private:
0N/A // hierarchy
0N/A Compilation* _compilation; // the current compilation
0N/A IRScope* _caller; // the caller scope, or NULL
0N/A int _caller_bci; // the caller bci of the corresponding (inlined) invoke, or < 0
0N/A ValueStack* _caller_state; // the caller state, or NULL
0N/A int _level; // the inlining level
0N/A ciMethod* _method; // the corresponding method
0N/A IRScopeList _callees; // the inlined method scopes
0N/A
0N/A // graph
0N/A XHandlers* _xhandlers; // the exception handlers
0N/A int _number_of_locks; // the number of monitor lock slots needed
0N/A bool _monitor_pairing_ok; // the monitor pairing info
0N/A BlockBegin* _start; // the start block, successsors are method entries
0N/A
0N/A // lock stack management
0N/A int _lock_stack_size; // number of expression stack elements which, if present,
0N/A // must be spilled to the stack because of exception
0N/A // handling inside inlined methods
0N/A
0N/A BitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable
0N/A
0N/A // helper functions
0N/A BlockBegin* header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state);
0N/A BlockBegin* build_graph(Compilation* compilation, int osr_bci);
0N/A
0N/A public:
0N/A // creation
0N/A IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph = false);
0N/A
0N/A // accessors
0N/A Compilation* compilation() const { return _compilation; }
0N/A IRScope* caller() const { return _caller; }
0N/A int caller_bci() const { return _caller_bci; }
0N/A ValueStack* caller_state() const { return _caller_state; }
0N/A int level() const { return _level; }
0N/A ciMethod* method() const { return _method; }
0N/A int max_stack() const; // NOTE: expensive
0N/A int lock_stack_size() const {
0N/A assert(_lock_stack_size != -1, "uninitialized");
0N/A return _lock_stack_size;
0N/A }
0N/A BitMap& requires_phi_function() { return _requires_phi_function; }
0N/A
0N/A // mutators
0N/A // Needed because caller state is not ready at time of IRScope construction
0N/A void set_caller_state(ValueStack* state) { _caller_state = state; }
0N/A // Needed because caller state changes after IRScope construction.
0N/A // Computes number of expression stack elements whose state must be
0N/A // preserved in the case of an exception; these may be seen by
0N/A // caller scopes. Zero when inlining of methods containing exception
0N/A // handlers is disabled, otherwise a conservative approximation.
0N/A void compute_lock_stack_size();
0N/A
0N/A // hierarchy
0N/A bool is_top_scope() const { return _caller == NULL; }
0N/A void add_callee(IRScope* callee) { _callees.append(callee); }
0N/A int number_of_callees() const { return _callees.length(); }
0N/A IRScope* callee_no(int i) const { return _callees.at(i); }
0N/A int top_scope_bci() const;
0N/A
0N/A // accessors, graph
0N/A bool is_valid() const { return start() != NULL; }
0N/A XHandlers* xhandlers() const { return _xhandlers; }
0N/A int number_of_locks() const { return _number_of_locks; }
0N/A void set_min_number_of_locks(int n) { if (n > _number_of_locks) _number_of_locks = n; }
0N/A bool monitor_pairing_ok() const { return _monitor_pairing_ok; }
0N/A BlockBegin* start() const { return _start; }
0N/A};
0N/A
0N/A
0N/A//
0N/A// IRScopeDebugInfo records the debug information for a particular IRScope
0N/A// in a particular CodeEmitInfo. This allows the information to be computed
0N/A// once early enough for the OopMap to be available to the LIR and also to be
0N/A// reemited for different pcs using the same CodeEmitInfo without recomputing
0N/A// everything.
0N/A//
0N/A
0N/Aclass IRScopeDebugInfo: public CompilationResourceObj {
0N/A private:
0N/A IRScope* _scope;
0N/A int _bci;
0N/A GrowableArray<ScopeValue*>* _locals;
0N/A GrowableArray<ScopeValue*>* _expressions;
0N/A GrowableArray<MonitorValue*>* _monitors;
0N/A IRScopeDebugInfo* _caller;
0N/A
0N/A public:
0N/A IRScopeDebugInfo(IRScope* scope,
0N/A int bci,
0N/A GrowableArray<ScopeValue*>* locals,
0N/A GrowableArray<ScopeValue*>* expressions,
0N/A GrowableArray<MonitorValue*>* monitors,
0N/A IRScopeDebugInfo* caller):
0N/A _scope(scope)
0N/A , _locals(locals)
0N/A , _bci(bci)
0N/A , _expressions(expressions)
0N/A , _monitors(monitors)
0N/A , _caller(caller) {}
0N/A
0N/A
0N/A IRScope* scope() { return _scope; }
0N/A int bci() { return _bci; }
0N/A GrowableArray<ScopeValue*>* locals() { return _locals; }
0N/A GrowableArray<ScopeValue*>* expressions() { return _expressions; }
0N/A GrowableArray<MonitorValue*>* monitors() { return _monitors; }
0N/A IRScopeDebugInfo* caller() { return _caller; }
0N/A
900N/A //Whether we should reexecute this bytecode for deopt
900N/A bool should_reexecute();
900N/A
900N/A void record_debug_info(DebugInformationRecorder* recorder, int pc_offset, bool topmost) {
0N/A if (caller() != NULL) {
0N/A // Order is significant: Must record caller first.
900N/A caller()->record_debug_info(recorder, pc_offset, false/*topmost*/);
0N/A }
0N/A DebugToken* locvals = recorder->create_scope_values(locals());
0N/A DebugToken* expvals = recorder->create_scope_values(expressions());
0N/A DebugToken* monvals = recorder->create_monitor_values(monitors());
900N/A // reexecute allowed only for the topmost frame
1135N/A bool reexecute = topmost ? should_reexecute() : false;
1135N/A bool is_method_handle_invoke = false;
1253N/A bool return_oop = false; // This flag will be ignored since it used only for C2 with escape analysis.
1253N/A recorder->describe_scope(pc_offset, scope()->method(), bci(), reexecute, is_method_handle_invoke, return_oop, locvals, expvals, monvals);
0N/A }
0N/A};
0N/A
0N/A
0N/Aclass CodeEmitInfo: public CompilationResourceObj {
0N/A friend class LinearScan;
0N/A private:
0N/A IRScopeDebugInfo* _scope_debug_info;
0N/A IRScope* _scope;
0N/A XHandlers* _exception_handlers;
0N/A OopMap* _oop_map;
0N/A ValueStack* _stack; // used by deoptimization (contains also monitors
0N/A int _bci;
0N/A CodeEmitInfo* _next;
0N/A int _id;
0N/A
0N/A FrameMap* frame_map() const { return scope()->compilation()->frame_map(); }
0N/A Compilation* compilation() const { return scope()->compilation(); }
0N/A
0N/A public:
0N/A
0N/A // use scope from ValueStack
0N/A CodeEmitInfo(int bci, ValueStack* stack, XHandlers* exception_handlers);
0N/A
0N/A // used by natives
0N/A CodeEmitInfo(IRScope* scope, int bci)
0N/A : _scope(scope)
0N/A , _bci(bci)
0N/A , _oop_map(NULL)
0N/A , _scope_debug_info(NULL)
0N/A , _stack(NULL)
0N/A , _exception_handlers(NULL)
0N/A , _next(NULL)
0N/A , _id(-1) {
0N/A }
0N/A
0N/A // make a copy
0N/A CodeEmitInfo(CodeEmitInfo* info, bool lock_stack_only = false);
0N/A
0N/A // accessors
0N/A OopMap* oop_map() { return _oop_map; }
0N/A ciMethod* method() const { return _scope->method(); }
0N/A IRScope* scope() const { return _scope; }
0N/A XHandlers* exception_handlers() const { return _exception_handlers; }
0N/A ValueStack* stack() const { return _stack; }
0N/A int bci() const { return _bci; }
0N/A
0N/A void add_register_oop(LIR_Opr opr);
0N/A void record_debug_info(DebugInformationRecorder* recorder, int pc_offset);
0N/A
0N/A CodeEmitInfo* next() const { return _next; }
0N/A void set_next(CodeEmitInfo* next) { _next = next; }
0N/A
0N/A int id() const { return _id; }
0N/A void set_id(int id) { _id = id; }
0N/A};
0N/A
0N/A
0N/Aclass IR: public CompilationResourceObj {
0N/A private:
0N/A Compilation* _compilation; // the current compilation
0N/A IRScope* _top_scope; // the root of the scope hierarchy
0N/A WordSize _locals_size; // the space required for all locals
0N/A int _num_loops; // Total number of loops
0N/A BlockList* _code; // the blocks in code generation order w/ use counts
0N/A
0N/A public:
0N/A // creation
0N/A IR(Compilation* compilation, ciMethod* method, int osr_bci);
0N/A
0N/A // accessors
0N/A bool is_valid() const { return top_scope()->is_valid(); }
0N/A Compilation* compilation() const { return _compilation; }
0N/A IRScope* top_scope() const { return _top_scope; }
0N/A int number_of_locks() const { return top_scope()->number_of_locks(); }
0N/A ciMethod* method() const { return top_scope()->method(); }
0N/A BlockBegin* start() const { return top_scope()->start(); }
0N/A BlockBegin* std_entry() const { return start()->end()->as_Base()->std_entry(); }
0N/A BlockBegin* osr_entry() const { return start()->end()->as_Base()->osr_entry(); }
0N/A WordSize locals_size() const { return _locals_size; }
0N/A int locals_size_in_words() const { return in_words(_locals_size); }
0N/A BlockList* code() const { return _code; }
0N/A int num_loops() const { return _num_loops; }
0N/A int max_stack() const { return top_scope()->max_stack(); } // expensive
0N/A
0N/A // ir manipulation
0N/A void optimize();
0N/A void compute_predecessors();
0N/A void split_critical_edges();
0N/A void compute_code();
0N/A void compute_use_counts();
0N/A
0N/A // The linear-scan order and the code emission order are equal, but
0N/A // this may change in future
0N/A BlockList* linear_scan_order() { assert(_code != NULL, "not computed"); return _code; }
0N/A
0N/A // iteration
0N/A void iterate_preorder (BlockClosure* closure);
0N/A void iterate_postorder (BlockClosure* closure);
0N/A void iterate_linear_scan_order(BlockClosure* closure);
0N/A
0N/A // debugging
0N/A static void print(BlockBegin* start, bool cfg_only, bool live_only = false) PRODUCT_RETURN;
0N/A void print(bool cfg_only, bool live_only = false) PRODUCT_RETURN;
0N/A void verify() PRODUCT_RETURN;
0N/A};
0N/A
0N/A
0N/A// Globally do instruction substitution and remove substituted
0N/A// instructions from the instruction list.
0N/A//
0N/A
0N/Aclass SubstitutionResolver: public BlockClosure {
0N/A static void substitute(Value* v);
0N/A
0N/A public:
0N/A SubstitutionResolver(IR* hir) {
0N/A hir->iterate_preorder(this);
0N/A }
0N/A
0N/A SubstitutionResolver(BlockBegin* block) {
0N/A block->iterate_preorder(this);
0N/A }
0N/A
0N/A virtual void block_do(BlockBegin* block);
0N/A};