duke@435: /* xdono@631: * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_c2compiler.cpp.incl" duke@435: duke@435: duke@435: volatile int C2Compiler::_runtimes = uninitialized; duke@435: duke@435: // register information defined by ADLC duke@435: extern const char register_save_policy[]; duke@435: extern const int register_save_type[]; duke@435: duke@435: const char* C2Compiler::retry_no_subsuming_loads() { duke@435: return "retry without subsuming loads"; duke@435: } kvn@473: const char* C2Compiler::retry_no_escape_analysis() { kvn@473: return "retry without escape analysis"; kvn@473: } duke@435: void C2Compiler::initialize_runtime() { duke@435: duke@435: // Check assumptions used while running ADLC duke@435: Compile::adlc_verification(); duke@435: assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts"); duke@435: duke@435: for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) { duke@435: OptoReg::vm2opto[i] = OptoReg::Bad; duke@435: } duke@435: duke@435: for( OptoReg::Name i=OptoReg::Name(0); iis_valid()) { duke@435: OptoReg::vm2opto[r->value()] = i; duke@435: } duke@435: } duke@435: duke@435: // Check that runtime and architecture description agree on callee-saved-floats duke@435: bool callee_saved_floats = false; duke@435: for( OptoReg::Name i=OptoReg::Name(0); ienv()); duke@435: duke@435: } duke@435: duke@435: duke@435: void C2Compiler::initialize() { duke@435: duke@435: // This method can only be called once per C2Compiler object duke@435: // The first compiler thread that gets here will initialize the duke@435: // small amount of global state (and runtime stubs) that c2 needs. duke@435: duke@435: // There is a race possible once at startup and then we're fine duke@435: duke@435: // Note that this is being called from a compiler thread not the duke@435: // main startup thread. duke@435: duke@435: if (_runtimes != initialized) { duke@435: initialize_runtimes( initialize_runtime, &_runtimes); duke@435: } duke@435: duke@435: // Mark this compiler object as ready to roll duke@435: mark_initialized(); duke@435: } duke@435: duke@435: void C2Compiler::compile_method(ciEnv* env, duke@435: ciMethod* target, duke@435: int entry_bci) { duke@435: if (!is_initialized()) { duke@435: initialize(); duke@435: } duke@435: bool subsume_loads = true; kvn@473: bool do_escape_analysis = DoEscapeAnalysis; duke@435: while (!env->failing()) { duke@435: // Attempt to compile while subsuming loads into machine instructions. kvn@473: Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis); duke@435: duke@435: // Check result and retry if appropriate. duke@435: if (C.failure_reason() != NULL) { kvn@473: if (C.failure_reason_is(retry_no_subsuming_loads())) { duke@435: assert(subsume_loads, "must make progress"); duke@435: subsume_loads = false; duke@435: continue; // retry duke@435: } kvn@473: if (C.failure_reason_is(retry_no_escape_analysis())) { kvn@473: assert(do_escape_analysis, "must make progress"); kvn@473: do_escape_analysis = false; kvn@473: continue; // retry kvn@473: } duke@435: // Pass any other failure reason up to the ciEnv. duke@435: // Note that serious, irreversible failures are already logged duke@435: // on the ciEnv via env->record_method_not_compilable(). duke@435: env->record_failure(C.failure_reason()); duke@435: } duke@435: duke@435: // No retry; just break the loop. duke@435: break; duke@435: } duke@435: } duke@435: duke@435: duke@435: void C2Compiler::print_timers() { duke@435: // do nothing duke@435: }