0N/A/*
2273N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. 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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "opto/c2compiler.hpp"
1879N/A#include "opto/runtime.hpp"
1879N/A#ifdef TARGET_ARCH_MODEL_x86_32
1879N/A# include "adfiles/ad_x86_32.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_x86_64
1879N/A# include "adfiles/ad_x86_64.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_sparc
1879N/A# include "adfiles/ad_sparc.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_MODEL_zero
1879N/A# include "adfiles/ad_zero.hpp"
1879N/A#endif
2073N/A#ifdef TARGET_ARCH_MODEL_arm
2073N/A# include "adfiles/ad_arm.hpp"
2073N/A#endif
2073N/A#ifdef TARGET_ARCH_MODEL_ppc
2073N/A# include "adfiles/ad_ppc.hpp"
2073N/A#endif
0N/A
0N/A
0N/Avolatile int C2Compiler::_runtimes = uninitialized;
0N/A
0N/A// register information defined by ADLC
0N/Aextern const char register_save_policy[];
0N/Aextern const int register_save_type[];
0N/A
0N/Aconst char* C2Compiler::retry_no_subsuming_loads() {
0N/A return "retry without subsuming loads";
0N/A}
38N/Aconst char* C2Compiler::retry_no_escape_analysis() {
38N/A return "retry without escape analysis";
38N/A}
0N/Avoid C2Compiler::initialize_runtime() {
0N/A
0N/A // Check assumptions used while running ADLC
0N/A Compile::adlc_verification();
0N/A assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
0N/A
0N/A for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
0N/A OptoReg::vm2opto[i] = OptoReg::Bad;
0N/A }
0N/A
0N/A for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
0N/A VMReg r = OptoReg::as_VMReg(i);
0N/A if (r->is_valid()) {
0N/A OptoReg::vm2opto[r->value()] = i;
0N/A }
0N/A }
0N/A
0N/A // Check that runtime and architecture description agree on callee-saved-floats
0N/A bool callee_saved_floats = false;
0N/A for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
0N/A // Is there a callee-saved float or double?
0N/A if( register_save_policy[i] == 'E' /* callee-saved */ &&
0N/A (register_save_type[i] == Op_RegF || register_save_type[i] == Op_RegD) ) {
0N/A callee_saved_floats = true;
0N/A }
0N/A }
0N/A
0N/A DEBUG_ONLY( Node::init_NodeProperty(); )
0N/A
0N/A Compile::pd_compiler2_init();
0N/A
0N/A CompilerThread* thread = CompilerThread::current();
0N/A
0N/A HandleMark handle_mark(thread);
0N/A
0N/A OptoRuntime::generate(thread->env());
0N/A
0N/A}
0N/A
0N/A
0N/Avoid C2Compiler::initialize() {
0N/A
0N/A // This method can only be called once per C2Compiler object
0N/A // The first compiler thread that gets here will initialize the
0N/A // small amount of global state (and runtime stubs) that c2 needs.
0N/A
0N/A // There is a race possible once at startup and then we're fine
0N/A
0N/A // Note that this is being called from a compiler thread not the
0N/A // main startup thread.
0N/A
0N/A if (_runtimes != initialized) {
0N/A initialize_runtimes( initialize_runtime, &_runtimes);
0N/A }
0N/A
0N/A // Mark this compiler object as ready to roll
0N/A mark_initialized();
0N/A}
0N/A
0N/Avoid C2Compiler::compile_method(ciEnv* env,
0N/A ciMethod* target,
0N/A int entry_bci) {
0N/A if (!is_initialized()) {
0N/A initialize();
0N/A }
1605N/A bool subsume_loads = SubsumeLoads;
818N/A bool do_escape_analysis = DoEscapeAnalysis &&
1397N/A !env->jvmti_can_access_local_variables();
0N/A while (!env->failing()) {
0N/A // Attempt to compile while subsuming loads into machine instructions.
38N/A Compile C(env, this, target, entry_bci, subsume_loads, do_escape_analysis);
0N/A
1605N/A
0N/A // Check result and retry if appropriate.
0N/A if (C.failure_reason() != NULL) {
38N/A if (C.failure_reason_is(retry_no_subsuming_loads())) {
0N/A assert(subsume_loads, "must make progress");
0N/A subsume_loads = false;
0N/A continue; // retry
0N/A }
38N/A if (C.failure_reason_is(retry_no_escape_analysis())) {
38N/A assert(do_escape_analysis, "must make progress");
38N/A do_escape_analysis = false;
38N/A continue; // retry
38N/A }
0N/A // Pass any other failure reason up to the ciEnv.
0N/A // Note that serious, irreversible failures are already logged
0N/A // on the ciEnv via env->record_method_not_compilable().
0N/A env->record_failure(C.failure_reason());
0N/A }
1605N/A if (StressRecompilation) {
1605N/A if (subsume_loads) {
1605N/A subsume_loads = false;
1605N/A continue; // retry
1605N/A }
1605N/A if (do_escape_analysis) {
1605N/A do_escape_analysis = false;
1605N/A continue; // retry
1605N/A }
1605N/A }
0N/A
0N/A // No retry; just break the loop.
0N/A break;
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid C2Compiler::print_timers() {
0N/A // do nothing
0N/A}