/* * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// FORMS.CPP - Definitions for ADL Parser Forms Classes #include"adlc.hpp"
bool InstructForm::has_temps() { if (_matrule) { // Examine each component to see if it is a TEMP
_components.reset(); // Skip the first component, if already handled as (SET dst (...))
Component *comp = NULL; if (sets_result()) comp = _components.iter(); while ((comp = _components.iter()) != NULL) { if (comp->isa(Component::TEMP)) { returntrue;
}
}
}
// This instruction has an expand rule? bool InstructForm::expands() const { return ( _exprule != NULL );
}
// This instruction has a late expand rule? bool InstructForm::postalloc_expands() const { return _is_postalloc_expand;
}
// This instruction has a peephole rule?
Peephole *InstructForm::peepholes() const { return _peephole;
}
// This instruction has a peephole rule? void InstructForm::append_peephole(Peephole *peephole) { if( _peephole == NULL ) {
_peephole = peephole;
} else {
_peephole->append_peephole(peephole);
}
}
// ideal opcode enumeration constchar *InstructForm::ideal_Opcode( FormDict &globalNames ) const { if( !_matrule ) return"Node"; // Something weird // Chain rules do not really have ideal Opcodes; use their source // operand ideal Opcode instead. if( is_simple_chain_rule(globalNames) ) { constchar *src = _matrule->_rChild->_opType;
OperandForm *src_op = globalNames[src]->is_operand();
assert( src_op, "Not operand class of chain rule" ); if( !src_op->_matrule ) return"Node"; return src_op->_matrule->_opType;
} // Operand chain rules do not really have ideal Opcodes if( _matrule->is_chain_rule(globalNames) ) return"Node"; return strcmp(_matrule->_opType,"Set")
? _matrule->_opType
: _matrule->_rChild->_opType;
}
// Recursive check on all operands' match rules in my match rule bool InstructForm::is_pinned(FormDict &globals) { if ( ! _matrule) returnfalse;
int index = 0; if (_matrule->find_type("Goto", index)) returntrue; if (_matrule->find_type("If", index)) returntrue; if (_matrule->find_type("CountedLoopEnd",index)) returntrue; if (_matrule->find_type("Return", index)) returntrue; if (_matrule->find_type("Rethrow", index)) returntrue; if (_matrule->find_type("TailCall", index)) returntrue; if (_matrule->find_type("TailJump", index)) returntrue; if (_matrule->find_type("Halt", index)) returntrue; if (_matrule->find_type("Jump", index)) returntrue;
return is_parm(globals);
}
// Recursive check on all operands' match rules in my match rule bool InstructForm::is_projection(FormDict &globals) { if ( ! _matrule) returnfalse;
int index = 0; if (_matrule->find_type("Goto", index)) returntrue; if (_matrule->find_type("Return", index)) returntrue; if (_matrule->find_type("Rethrow", index)) returntrue; if (_matrule->find_type("TailCall",index)) returntrue; if (_matrule->find_type("TailJump",index)) returntrue; if (_matrule->find_type("Halt", index)) returntrue;
returnfalse;
}
// Recursive check on all operands' match rules in my match rule bool InstructForm::is_parm(FormDict &globals) { if ( ! _matrule) returnfalse;
int index = 0; if (_matrule->find_type("Parm",index)) returntrue;
// Return 'true' if this instruction matches an ideal 'Copy*' node int InstructForm::is_ideal_copy() const { return _matrule ? _matrule->is_ideal_copy() : 0;
}
// Return 'true' if this instruction is too complex to rematerialize. int InstructForm::is_expensive() const { // We can prove it is cheap if it has an empty encoding. // This helps with platform-specific nops like ThreadLocal and RoundFloat. if (is_empty_encoding()) return 0;
if (is_tls_instruction()) return 1;
if (_matrule == NULL) return 0;
return _matrule->is_expensive();
}
// Has an empty encoding if _size is a constant zero or there // are no ins_encode tokens. int InstructForm::is_empty_encoding() const { if (_insencode != NULL) {
_insencode->reset(); if (_insencode->encode_class_iter() == NULL) { return 1;
}
} if (_size != NULL && strcmp(_size, "0") == 0) { return 1;
} return 0;
}
// Return 'true' if this instruction matches an ideal 'Return' node bool InstructForm::is_ideal_return() const { if( _matrule == NULL ) returnfalse;
// Check MatchRule to see if the first entry is the ideal "Return" node int index = 0; if (_matrule->find_type("Return",index)) returntrue; if (_matrule->find_type("Rethrow",index)) returntrue; if (_matrule->find_type("TailCall",index)) returntrue; if (_matrule->find_type("TailJump",index)) returntrue;
returnfalse;
}
// Return 'true' if this instruction matches an ideal 'Halt' node bool InstructForm::is_ideal_halt() const { int index = 0; return _matrule && _matrule->find_type("Halt",index);
}
// Return 'true' if this instruction matches an ideal 'SafePoint' node bool InstructForm::is_ideal_safepoint() const { int index = 0; return _matrule && _matrule->find_type("SafePoint",index);
}
// Return 'true' if this instruction matches an ideal 'Call' node
Form::CallType InstructForm::is_ideal_call() const { if( _matrule == NULL ) return Form::invalid_type;
// Check MatchRule to see if the first entry is the ideal "Call" node int idx = 0; if(_matrule->find_type("CallStaticJava",idx)) return Form::JAVA_STATIC;
idx = 0; if(_matrule->find_type("Lock",idx)) return Form::JAVA_STATIC;
idx = 0; if(_matrule->find_type("Unlock",idx)) return Form::JAVA_STATIC;
idx = 0; if(_matrule->find_type("CallDynamicJava",idx)) return Form::JAVA_DYNAMIC;
idx = 0; if(_matrule->find_type("CallRuntime",idx)) return Form::JAVA_RUNTIME;
idx = 0; if(_matrule->find_type("CallLeaf",idx)) return Form::JAVA_LEAF;
idx = 0; if(_matrule->find_type("CallLeafNoFP",idx)) return Form::JAVA_LEAF;
idx = 0; if(_matrule->find_type("CallLeafVector",idx)) return Form::JAVA_LEAF;
idx = 0;
return Form::invalid_type;
}
// Return 'true' if this instruction matches an ideal 'Load?' node
Form::DataType InstructForm::is_ideal_load() const { if( _matrule == NULL ) return Form::none;
return _matrule->is_ideal_load();
}
// Return 'true' if this instruction matches an ideal 'LoadKlass' node bool InstructForm::skip_antidep_check() const { if( _matrule == NULL ) returnfalse;
return _matrule->skip_antidep_check();
}
// Return 'true' if this instruction matches an ideal 'Load?' node
Form::DataType InstructForm::is_ideal_store() const { if( _matrule == NULL ) return Form::none;
return _matrule->is_ideal_store();
}
// Return 'true' if this instruction matches an ideal vector node bool InstructForm::is_vector() const { if( _matrule == NULL ) returnfalse;
return _matrule->is_vector();
}
// Return the input register that must match the output register // If this is not required, return 0
uint InstructForm::two_address(FormDict &globals) {
uint matching_input = 0; if(_components.count() == 0) return 0;
_components.reset();
Component *comp = _components.iter(); // Check if there is a DEF if( comp->isa(Component::DEF) ) { // Check that this is a register constchar *def_type = comp->_type; const Form *form = globals[def_type];
OperandForm *op = form->is_operand(); if( op ) { if( op->constrained_reg_class() != NULL &&
op->interface_type(globals) == Form::register_interface ) { // Remember the local name for equality test later constchar *def_name = comp->_name; // Check if a component has the same name and is a USE do { if( comp->isa(Component::USE) && strcmp(comp->_name,def_name)==0 ) { return operand_position_format(def_name);
}
} while( (comp = _components.iter()) != NULL);
}
}
}
return 0;
}
// when chaining a constant to an instruction, returns 'true' and sets opType
Form::DataType InstructForm::is_chain_of_constant(FormDict &globals) { constchar *dummy = NULL; constchar *dummy2 = NULL; return is_chain_of_constant(globals, dummy, dummy2);
}
Form::DataType InstructForm::is_chain_of_constant(FormDict &globals, constchar * &opTypeParam) { constchar *result = NULL;
// !!!!! // The source of the chain rule is 'position = 1'
uint position = 1; constchar *result = NULL; constchar *name = NULL; constchar *opType = NULL; // Here base_operand is looking for an ideal type to be returned (opType). if ( _matrule->is_chain_rule(globals)
&& _matrule->base_operand(position, globals, result, name, opType) ) {
data_type = ideal_to_const_type(opType);
// if it isn't an ideal constant type, just return if ( data_type == Form::none ) return data_type;
// Ideal constant types also adjust the opType parameter.
resultParam = result;
opTypeParam = opType; return data_type;
}
// Pseudo-constants (values easily available to the runtime) if (is_empty_encoding() && is_tls_instruction())
rematerialize = true;
// 1-input, 1-output, such as copies or increments. if( _components.count() == 2 &&
_components[0]->is(Component::DEF) &&
_components[1]->isa(Component::USE) )
rematerialize = true;
// Check for an ideal 'Load?' and eliminate rematerialize option if ( is_ideal_load() != Form::none || // Ideal load? Do not rematerialize
is_ideal_copy() != Form::none || // Ideal copy? Do not rematerialize
is_expensive() != Form::none) { // Expensive? Do not rematerialize
rematerialize = false;
}
// Always rematerialize the flags. They are more expensive to save & // restore than to recompute (and possibly spill the compare's inputs). if( _components.count() >= 1 ) {
Component *c = _components[0]; const Form *form = globals[c->_type];
OperandForm *opform = form->is_operand(); if( opform ) { // Avoid the special stack_slots register classes constchar *rc_name = opform->constrained_reg_class(); if( rc_name ) { if( strcmp(rc_name,"stack_slots") ) { // Check for ideal_type of RegFlags constchar *type = opform->ideal_type( globals, registers ); if( (type != NULL) && !strcmp(type, "RegFlags") )
rematerialize = true;
} else
rematerialize = false; // Do not rematerialize things target stk
}
}
}
return rematerialize;
}
// loads from memory, so must check for anti-dependence bool InstructForm::needs_anti_dependence_check(FormDict &globals) const { if ( skip_antidep_check() ) returnfalse;
// Machine independent loads must be checked for anti-dependences if( is_ideal_load() != Form::none ) returntrue;
// String.(compareTo/equals/indexOf) and Arrays.equals use many memorys edges, // but writes none if( _matrule && _matrule->_rChild &&
( strcmp(_matrule->_rChild->_opType,"StrComp" )==0 ||
strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 ||
strcmp(_matrule->_rChild->_opType,"StrIndexOf" )==0 ||
strcmp(_matrule->_rChild->_opType,"StrIndexOfChar" )==0 ||
strcmp(_matrule->_rChild->_opType,"CountPositives" )==0 ||
strcmp(_matrule->_rChild->_opType,"AryEq" )==0 )) returntrue;
// Check if instruction has a USE of a memory operand class, but no defs bool USE_of_memory = false; bool DEF_of_memory = false;
Component *comp = NULL;
ComponentList &components = (ComponentList &)_components;
int InstructForm::memory_operand(FormDict &globals) const { // Machine independent loads must be checked for anti-dependences // Check if instruction has a USE of a memory operand class, or a def. int USE_of_memory = 0; int DEF_of_memory = 0; constchar* last_memory_DEF = NULL; // to test DEF/USE pairing in asserts constchar* last_memory_USE = NULL;
Component *unique = NULL;
Component *comp = NULL;
ComponentList &components = (ComponentList &)_components;
components.reset(); while( (comp = components.iter()) != NULL ) { const Form *form = globals[comp->_type]; if( !form ) continue;
OpClassForm *op = form->is_opclass(); if( !op ) continue; if( op->stack_slots_only(globals) ) continue; if( form->interface_type(globals) == Form::memory_interface ) { if( comp->isa(Component::DEF) ) {
last_memory_DEF = comp->_name;
DEF_of_memory++;
unique = comp;
} elseif( comp->isa(Component::USE) ) { if( last_memory_DEF != NULL ) {
assert(0 == strcmp(last_memory_DEF, comp->_name), "every memory DEF is followed by a USE of the same name");
last_memory_DEF = NULL;
} // Handles same memory being used multiple times in the case of BMI1 instructions. if (last_memory_USE != NULL) { if (strcmp(comp->_name, last_memory_USE) != 0) {
USE_of_memory++;
}
} else {
USE_of_memory++;
}
last_memory_USE = comp->_name;
if (DEF_of_memory == 0) // defs take precedence
unique = comp;
} else {
assert(last_memory_DEF == NULL, "unpaired memory DEF");
}
}
}
assert(last_memory_DEF == NULL, "unpaired memory DEF");
assert(USE_of_memory >= DEF_of_memory, "unpaired memory DEF");
USE_of_memory -= DEF_of_memory; // treat paired DEF/USE as one occurrence if( (USE_of_memory + DEF_of_memory) > 0 ) { if( is_simple_chain_rule(globals) ) { //fprintf(stderr, "Warning: chain rule is not really a memory user.\n"); //((InstructForm*)this)->dump(); // Preceding code prints nothing on sparc and these insns on intel: // leaP8 leaP32 leaPIdxOff leaPIdxScale leaPIdxScaleOff leaP8 leaP32 // leaPIdxOff leaPIdxScale leaPIdxScaleOff return NO_MEMORY_OPERAND;
}
if( DEF_of_memory == 1 ) {
assert(unique != NULL, ""); if( USE_of_memory == 0 ) { // unique def, no uses
} else { // // unique def, some uses // // must return bottom unless all uses match def // unique = NULL; #ifdef S390 // This case is important for move instructions on s390x. // On other platforms (e.g. x86), all uses always match the def.
unique = NULL; #endif
}
} elseif( DEF_of_memory > 0 ) { // multiple defs, don't care about uses
unique = NULL;
} elseif( USE_of_memory == 1) { // unique use, no defs
assert(unique != NULL, "");
} elseif( USE_of_memory > 0 ) { // multiple uses, no defs
unique = NULL;
} else {
assert(false, "bad case analysis");
} // process the unique DEF or USE, if there is one if( unique == NULL ) { return MANY_MEMORY_OPERANDS;
} else { int pos = components.operand_position(unique->_name); if( unique->isa(Component::DEF) ) {
pos += 1; // get corresponding USE from DEF
}
assert(pos >= 1, "I was just looking at it!"); return pos;
}
}
// missed the memory op?? if( true ) { // %%% should not be necessary if( is_ideal_store() != Form::none ) {
fprintf(stderr, "Warning: cannot find memory opnd in instr.\n");
((InstructForm*)this)->dump(); // pretend it has multiple defs and uses return MANY_MEMORY_OPERANDS;
} if( is_ideal_load() != Form::none ) {
fprintf(stderr, "Warning: cannot find memory opnd in instr.\n");
((InstructForm*)this)->dump(); // pretend it has multiple uses and no defs return MANY_MEMORY_OPERANDS;
}
}
return NO_MEMORY_OPERAND;
}
// This instruction captures the machine-independent bottom_type // Expected use is for pointer vs oop determination for LoadP bool InstructForm::captures_bottom_type(FormDict &globals) const { if (_matrule && _matrule->_rChild &&
(!strcmp(_matrule->_rChild->_opType,"CastPP") || // new result type
!strcmp(_matrule->_rChild->_opType,"CastDD") ||
!strcmp(_matrule->_rChild->_opType,"CastFF") ||
!strcmp(_matrule->_rChild->_opType,"CastII") ||
!strcmp(_matrule->_rChild->_opType,"CastLL") ||
!strcmp(_matrule->_rChild->_opType,"CastVV") ||
!strcmp(_matrule->_rChild->_opType,"CastX2P") || // new result type
!strcmp(_matrule->_rChild->_opType,"DecodeN") ||
!strcmp(_matrule->_rChild->_opType,"EncodeP") ||
!strcmp(_matrule->_rChild->_opType,"DecodeNKlass") ||
!strcmp(_matrule->_rChild->_opType,"EncodePKlass") ||
!strcmp(_matrule->_rChild->_opType,"LoadN") ||
!strcmp(_matrule->_rChild->_opType,"LoadNKlass") ||
!strcmp(_matrule->_rChild->_opType,"CreateEx") || // type of exception
!strcmp(_matrule->_rChild->_opType,"CheckCastPP") ||
!strcmp(_matrule->_rChild->_opType,"GetAndSetP") ||
!strcmp(_matrule->_rChild->_opType,"GetAndSetN") ||
!strcmp(_matrule->_rChild->_opType,"RotateLeft") ||
!strcmp(_matrule->_rChild->_opType,"RotateRight") || #if INCLUDE_SHENANDOAHGC
!strcmp(_matrule->_rChild->_opType,"ShenandoahCompareAndExchangeP") ||
!strcmp(_matrule->_rChild->_opType,"ShenandoahCompareAndExchangeN") || #endif
!strcmp(_matrule->_rChild->_opType,"StrInflatedCopy") ||
!strcmp(_matrule->_rChild->_opType,"VectorCmpMasked")||
!strcmp(_matrule->_rChild->_opType,"VectorMaskGen")||
!strcmp(_matrule->_rChild->_opType,"CompareAndExchangeP") ||
!strcmp(_matrule->_rChild->_opType,"CompareAndExchangeN"))) returntrue; elseif ( is_ideal_load() == Form::idealP ) returntrue; elseif ( is_ideal_store() != Form::none ) returntrue;
if (needs_base_oop_edge(globals)) returntrue;
if (is_vector()) returntrue; if (is_mach_constant()) returntrue;
returnfalse;
}
// Access instr_cost attribute or return NULL. constchar* InstructForm::cost() { for (Attribute* cur = _attribs; cur != NULL; cur = (Attribute*)cur->_next) { if( strcmp(cur->_ident,AttributeForm::_ins_cost) == 0 ) { return cur->_val;
}
} return NULL;
}
// Return count of top-level operands.
uint InstructForm::num_opnds() { int num_opnds = _components.num_operands();
// Need special handling for matching some ideal nodes // i.e. Matching a return node /* if( _matrule ) { if( strcmp(_matrule->_opType,"Return" )==0 || strcmp(_matrule->_opType,"Halt" )==0 ) return 3; }
*/ return num_opnds;
}
// Return the number of leaves below this complex operand
uint InstructForm::num_consts(FormDict &globals) const { if ( ! _matrule) return 0;
// This is a recursive invocation on all operands in the matchrule return _matrule->num_consts(globals);
}
// Constants in match rule with specified type
uint InstructForm::num_consts(FormDict &globals, Form::DataType type) const { if ( ! _matrule) return 0;
// This is a recursive invocation on all operands in the matchrule return _matrule->num_consts(globals, type);
}
// Return the register class associated with 'leaf'. constchar *InstructForm::out_reg_class(FormDict &globals) {
assert( false, "InstructForm::out_reg_class(FormDict &globals); Not Implemented");
return NULL;
}
// Lookup the starting position of inputs we are interested in wrt. ideal nodes
uint InstructForm::oper_input_base(FormDict &globals) { if( !_matrule ) return 1; // Skip control for most nodes
// Need special handling for matching some ideal nodes // i.e. Matching a return node if( strcmp(_matrule->_opType,"Return" )==0 ||
strcmp(_matrule->_opType,"Rethrow" )==0 ||
strcmp(_matrule->_opType,"TailCall" )==0 ||
strcmp(_matrule->_opType,"TailJump" )==0 ||
strcmp(_matrule->_opType,"SafePoint" )==0 ||
strcmp(_matrule->_opType,"Halt" )==0 ) return AdlcVMDeps::Parms; // Skip the machine-state edges
if( _matrule->_rChild &&
( strcmp(_matrule->_rChild->_opType,"AryEq" )==0 ||
strcmp(_matrule->_rChild->_opType,"StrComp" )==0 ||
strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 ||
strcmp(_matrule->_rChild->_opType,"StrInflatedCopy" )==0 ||
strcmp(_matrule->_rChild->_opType,"StrCompressedCopy" )==0 ||
strcmp(_matrule->_rChild->_opType,"StrIndexOf")==0 ||
strcmp(_matrule->_rChild->_opType,"StrIndexOfChar")==0 ||
strcmp(_matrule->_rChild->_opType,"CountPositives")==0 ||
strcmp(_matrule->_rChild->_opType,"EncodeISOArray")==0)) { // String.(compareTo/equals/indexOf) and Arrays.equals // and sun.nio.cs.iso8859_1$Encoder.EncodeISOArray // take 1 control and 1 memory edges. // Also String.(compressedCopy/inflatedCopy). return 2;
}
// Check for handling of 'Memory' input/edge in the ideal world. // The AD file writer is shielded from knowledge of these edges. int base = 1; // Skip control
base += _matrule->needs_ideal_memory_edge(globals);
// Also skip the base-oop value for uses of derived oops. // The AD file writer is shielded from knowledge of these edges.
base += needs_base_oop_edge(globals);
return base;
}
// This function determines the order of the MachOper in _opnds[] // by writing the operand names into the _components list. // // Implementation does not modify state of internal structures void InstructForm::build_components() { // Add top-level operands to the components if (_matrule) _matrule->append_components(_localNames, _components);
// Add parameters that "do not appear in match rule". bool has_temp = false; constchar *name; constchar *kill_name = NULL; for (_parameters.reset(); (name = _parameters.iter()) != NULL;) {
OpClassForm *opForm = _localNames[name]->is_opclass();
assert(opForm != NULL, "sanity");
Effect* e = NULL;
{ const Form* form = _effects[name];
e = form ? form->is_effect() : NULL;
}
if (e != NULL) {
has_temp |= e->is(Component::TEMP);
// KILLs must be declared after any TEMPs because TEMPs are real // uses so their operand numbering must directly follow the real // inputs from the match rule. Fixing the numbering seems // complex so simply enforce the restriction during parse. if (kill_name != NULL &&
e->isa(Component::TEMP) && !e->isa(Component::DEF)) {
OpClassForm* kill = _localNames[kill_name]->is_opclass();
assert(kill != NULL, "sanity");
globalAD->syntax_err(_linenum, "%s: %s %s must be at the end of the argument list\n",
_ident, kill->_ident, kill_name);
} elseif (e->isa(Component::KILL) && !e->isa(Component::USE)) {
kill_name = name;
}
}
const Component *component = _components.search(name); if ( component == NULL ) { if (e) {
_components.insert(name, opForm->_ident, e->_use_def, false);
component = _components.search(name); if (component->isa(Component::USE) && !component->isa(Component::TEMP) && _matrule) { const Form *form = globalAD->globalNames()[component->_type];
assert( form, "component type must be a defined form");
OperandForm *op = form->is_operand(); if (op->_interface && op->_interface->is_RegInterface()) {
globalAD->syntax_err(_linenum, "%s: illegal USE of non-input: %s %s\n",
_ident, opForm->_ident, name);
}
}
} else { // This would be a nice warning but it triggers in a few places in a benign way // if (_matrule != NULL && !expands()) { // globalAD->syntax_err(_linenum, "%s: %s %s not mentioned in effect or match rule\n", // _ident, opForm->_ident, name); // }
_components.insert(name, opForm->_ident, Component::INVALID, false);
}
} elseif (e) { // Component was found in the list // Check if there is a new effect that requires an extra component. // This happens when adding 'USE' to a component that is not yet one. if ((!component->isa( Component::USE) && ((e->_use_def & Component::USE) != 0))) { if (component->isa(Component::USE) && _matrule) { const Form *form = globalAD->globalNames()[component->_type];
assert( form, "component type must be a defined form");
OperandForm *op = form->is_operand(); if (op->_interface && op->_interface->is_RegInterface()) {
globalAD->syntax_err(_linenum, "%s: illegal USE of non-input: %s %s\n",
_ident, opForm->_ident, name);
}
}
_components.insert(name, opForm->_ident, e->_use_def, false);
} else {
Component *comp = (Component*)component;
comp->promote_use_def_info(e->_use_def);
} // Component positions are zero based. int pos = _components.operand_position(name);
assert( ! (component->isa(Component::DEF) && (pos >= 1)), "Component::DEF can only occur in the first position");
}
}
// Resolving the interactions between expand rules and TEMPs would // be complex so simply disallow it. if (_matrule == NULL && has_temp) {
globalAD->syntax_err(_linenum, "%s: TEMPs without match rule isn't supported\n", _ident);
}
return;
}
// Return zero-based position in component list; -1 if not in list. int InstructForm::operand_position(constchar *name, int usedef) { return unique_opnds_idx(_components.operand_position(name, usedef, this));
}
int InstructForm::operand_position_format(constchar *name) { return unique_opnds_idx(_components.operand_position_format(name, this));
}
// Return zero-based position in component list; -1 if not in list. int InstructForm::label_position() { return unique_opnds_idx(_components.label_position());
}
int InstructForm::method_position() { return unique_opnds_idx(_components.method_position());
}
// Return number of relocation entries needed for this instruction.
uint InstructForm::reloc(FormDict &globals) {
uint reloc_entries = 0; // Check for "Call" nodes if ( is_ideal_call() ) ++reloc_entries; if ( is_ideal_return() ) ++reloc_entries; if ( is_ideal_safepoint() ) ++reloc_entries;
// Check if operands MAYBE oop pointers, by checking for ConP elements // Proceed through the leaves of the match-tree and check for ConPs if ( _matrule != NULL ) {
uint position = 0; constchar *result = NULL; constchar *name = NULL; constchar *opType = NULL; while (_matrule->base_operand(position, globals, result, name, opType)) { if ( strcmp(opType,"ConP") == 0 ) {
++reloc_entries;
}
++position;
}
}
// Above is only a conservative estimate // because it did not check contents of operand classes. // !!!!! !!!!! // Add 1 to reloc info for each operand class in the component list.
Component *comp;
_components.reset(); while ( (comp = _components.iter()) != NULL ) { const Form *form = globals[comp->_type];
assert( form, "Did not find component's type in global names"); const OpClassForm *opc = form->is_opclass(); const OperandForm *oper = form->is_operand(); if ( opc && (oper == NULL) ) {
++reloc_entries;
} elseif ( oper ) { // floats and doubles loaded out of method's constant pool require reloc info
Form::DataType type = oper->is_base_constant(globals); if ( (type == Form::idealF) || (type == Form::idealD) ) {
++reloc_entries;
}
}
}
// Float and Double constants may come from the CodeBuffer table // and require relocatable addresses for access // !!!!! // Check for any component being an immediate float or double.
Form::DataType data_type = is_chain_of_constant(globals); if( data_type==idealD || data_type==idealF ) {
reloc_entries++;
}
return reloc_entries;
}
// Utility function defined in archDesc.cpp externbool is_def(int usedef);
// Return the result of reducing an instruction constchar *InstructForm::reduce_result() { constchar* result = "Universe"; // default
_components.reset();
Component *comp = _components.iter(); if (comp != NULL && comp->isa(Component::DEF)) {
result = comp->_type; // Override this if the rule is a store operation: if (_matrule && _matrule->_rChild &&
is_store_to_memory(_matrule->_rChild->_opType))
result = "Universe";
} return result;
}
// Return the name of the operand on the right hand side of the binary match // Return NULL if there is no right hand side constchar *InstructForm::reduce_right(FormDict &globals) const { if( _matrule == NULL ) return NULL; return _matrule->reduce_right(globals);
}
// Similar for left constchar *InstructForm::reduce_left(FormDict &globals) const { if( _matrule == NULL ) return NULL; return _matrule->reduce_left(globals);
}
// Compare the instruction predicates for textual equality bool equivalent_predicates( const InstructForm *instr1, const InstructForm *instr2 ) { const Predicate *pred1 = instr1->_predicate; const Predicate *pred2 = instr2->_predicate; if( pred1 == NULL && pred2 == NULL ) { // no predicates means they are identical returntrue;
} if( pred1 != NULL && pred2 != NULL ) { // compare the predicates if (ADLParser::equivalent_expressions(pred1->_pred, pred2->_pred)) { returntrue;
}
}
returnfalse;
}
// Check if this instruction can cisc-spill to 'alternate' bool InstructForm::cisc_spills_to(ArchDesc &AD, InstructForm *instr) {
assert( _matrule != NULL && instr->_matrule != NULL, "must have match rules"); // Do not replace if a cisc-version has been found. if( cisc_spill_operand() != Not_cisc_spillable ) returnfalse;
int cisc_spill_operand = Maybe_cisc_spillable; char *result = NULL; char *result2 = NULL; constchar *op_name = NULL; constchar *reg_type = NULL;
FormDict &globals = AD.globalNames();
cisc_spill_operand = _matrule->matchrule_cisc_spill_match(globals, AD.get_registers(), instr->_matrule, op_name, reg_type); if( (cisc_spill_operand != Not_cisc_spillable) && (op_name != NULL) && equivalent_predicates(this, instr) ) {
cisc_spill_operand = operand_position(op_name, Component::USE); int def_oper = operand_position(op_name, Component::DEF); if( def_oper == NameList::Not_in_list && instr->num_opnds() == num_opnds()) { // Do not support cisc-spilling for destination operands and // make sure they have the same number of operands.
_cisc_spill_alternate = instr;
instr->set_cisc_alternate(true); if( AD._cisc_spill_debug ) {
fprintf(stderr, "Instruction %s cisc-spills-to %s\n", _ident, instr->_ident);
fprintf(stderr, " using operand %s %s at index %d\n", reg_type, op_name, cisc_spill_operand);
} // Record that a stack-version of the reg_mask is needed // !!!!!
OperandForm *oper = (OperandForm*)(globals[reg_type]->is_operand());
assert( oper != NULL, "cisc-spilling non operand"); constchar *reg_class_name = oper->constrained_reg_class();
AD.set_stack_or_reg(reg_class_name); constchar *reg_mask_name = AD.reg_mask(*oper);
set_cisc_reg_mask_name(reg_mask_name); constchar *stack_or_reg_mask_name = AD.stack_or_reg_mask(*oper);
} else {
cisc_spill_operand = Not_cisc_spillable;
}
} else {
cisc_spill_operand = Not_cisc_spillable;
}
// Check to see if this instruction can be replaced with the short branch // instruction `short-branch' bool InstructForm::check_branch_variant(ArchDesc &AD, InstructForm *short_branch) { if (_matrule != NULL && this != short_branch && // Don't match myself
!is_short_branch() && // Don't match another short branch variant
reduce_result() != NULL &&
strstr(_ident, "restoreMask") == NULL && // Don't match side effects
strcmp(reduce_result(), short_branch->reduce_result()) == 0 &&
_matrule->equivalent(AD.globalNames(), short_branch->_matrule)) { // The instructions are equivalent.
// Now verify that both instructions have the same parameters and // the same effects. Both branch forms should have the same inputs // and resulting projections to correctly replace a long branch node // with corresponding short branch node during code generation.
bool different = false; if (short_branch->_components.count() != _components.count()) {
different = true;
} elseif (_components.count() > 0) {
short_branch->_components.reset();
_components.reset();
Component *comp; while ((comp = _components.iter()) != NULL) {
Component *short_comp = short_branch->_components.iter(); if (short_comp == NULL ||
short_comp->_type != comp->_type ||
short_comp->_usedef != comp->_usedef) {
different = true; break;
}
} if (short_branch->_components.iter() != NULL)
different = true;
} if (different) {
globalAD->syntax_err(short_branch->_linenum, "Instruction %s and its short form %s have different parameters\n", _ident, short_branch->_ident);
} if (AD._adl_debug > 1 || AD._short_branch_debug) {
fprintf(stderr, "Instruction %s has short form %s\n", _ident, short_branch->_ident);
}
_short_branch_form = short_branch; returntrue;
} returnfalse;
}
// --------------------------- FILE *output_routines // // Generate the format call for the replacement variable void InstructForm::rep_var_format(FILE *fp, constchar *rep_var) { // Handle special constant table variables. if (strcmp(rep_var, "constanttablebase") == 0) {
fprintf(fp, "char reg[128]; ra->dump_register(in(mach_constant_base_node_input()), reg);\n");
fprintf(fp, " st->print(\"%%s\", reg);\n"); return;
} if (strcmp(rep_var, "constantoffset") == 0) {
fprintf(fp, "st->print(\"#%%d\", constant_offset_unchecked());\n"); return;
} if (strcmp(rep_var, "constantaddress") == 0) {
fprintf(fp, "st->print(\"constant table base + #%%d\", constant_offset_unchecked());\n"); return;
}
// Find replacement variable's type const Form *form = _localNames[rep_var]; if (form == NULL) {
globalAD->syntax_err(_linenum, "Unknown replacement variable %s in format statement of %s.",
rep_var, _ident); return;
}
OpClassForm *opc = form->is_opclass();
assert( opc, "replacement variable was not found in local names"); // Lookup the index position of the replacement variable int idx = operand_position_format(rep_var); if ( idx == -1 ) {
globalAD->syntax_err(_linenum, "Could not find replacement variable %s in format statement of %s.\n",
rep_var, _ident);
assert(strcmp(opc->_ident, "label") == 0, "Unimplemented"); return;
}
if (is_noninput_operand(idx)) { // This component isn't in the input array. Print out the static // name of the register.
OperandForm* oper = form->is_operand(); if (oper != NULL && oper->is_bound_register()) { const RegDef* first = oper->get_RegClass()->find_first_elem();
fprintf(fp, " st->print_raw(\"%s\");\n", first->_regname);
} else {
globalAD->syntax_err(_linenum, "In %s can't find format for %s %s", _ident, opc->_ident, rep_var);
}
} else { // Output the format call for this operand
fprintf(fp,"opnd_array(%d)->",idx); if (idx == 0)
fprintf(fp,"int_format(ra, this, st); // %s\n", rep_var); else
fprintf(fp,"ext_format(ra, this,idx%d, st); // %s\n", idx, rep_var );
}
}
// Search through operands to determine parameters unique positions. void InstructForm::set_unique_opnds() {
uint* uniq_idx = NULL;
uint nopnds = num_opnds();
uint num_uniq = nopnds;
uint i;
_uniq_idx_length = 0; if (nopnds > 0) { // Allocate index array. Worst case we're mapping from each // component back to an index and any DEF always goes at 0 so the // length of the array has to be the number of components + 1.
_uniq_idx_length = _components.count() + 1;
uniq_idx = (uint*) AdlAllocateHeap(sizeof(uint) * _uniq_idx_length); for (i = 0; i < _uniq_idx_length; i++) {
uniq_idx[i] = i;
}
} // Do it only if there is a match rule and no expand rule. With an // expand rule it is done by creating new mach node in Expand() // method. if (nopnds > 0 && _matrule != NULL && _exprule == NULL) { constchar *name;
uint count; bool has_dupl_use = false;
_parameters.reset(); while ((name = _parameters.iter()) != NULL) {
count = 0;
uint position = 0;
uint uniq_position = 0;
_components.reset();
Component *comp = NULL; if (sets_result()) {
comp = _components.iter();
position++;
} // The next code is copied from the method operand_position(). for (; (comp = _components.iter()) != NULL; ++position) { // When the first component is not a DEF, // leave space for the result operand! if (position==0 && (!comp->isa(Component::DEF))) {
++position;
} if (strcmp(name, comp->_name) == 0) { if (++count > 1) {
assert(position < _uniq_idx_length, "out of bounds");
uniq_idx[position] = uniq_position;
has_dupl_use = true;
} else {
uniq_position = position;
}
} if (comp->isa(Component::DEF) && comp->isa(Component::USE)) {
++position; if (position != 1)
--position; // only use two slots for the 1st USE_DEF
}
}
} if (has_dupl_use) { for (i = 1; i < nopnds; i++) { if (i != uniq_idx[i]) { break;
}
}
uint j = i; for (; i < nopnds; i++) { if (i == uniq_idx[i]) {
uniq_idx[i] = j++;
}
}
num_uniq = j;
}
}
_uniq_idx = uniq_idx;
_num_uniq = num_uniq;
}
// Generate index values needed for determining the operand position void InstructForm::index_temps(FILE *fp, FormDict &globals, constchar *prefix, constchar *receiver) {
uint idx = 0; // position of operand in match rule int cur_num_opnds = num_opnds();
// Compute the index into vector of operand pointers: // idx0=0 is used to indicate that info comes from this same node, not from input edge. // idx1 starts at oper_input_base() if ( cur_num_opnds >= 1 ) {
fprintf(fp," // Start at oper_input_base() and count operands\n");
fprintf(fp," unsigned %sidx0 = %d;\n", prefix, oper_input_base(globals));
fprintf(fp," unsigned %sidx1 = %d;", prefix, oper_input_base(globals));
fprintf(fp," \t// %s\n", unique_opnd_ident(1));
// Generate starting points for other unique operands if they exist for ( idx = 2; idx < num_unique_opnds(); ++idx ) { if( *receiver == 0 ) {
fprintf(fp," unsigned %sidx%d = %sidx%d + opnd_array(%d)->num_edges();",
prefix, idx, prefix, idx-1, idx-1 );
} else {
fprintf(fp," unsigned %sidx%d = %sidx%d + %s_opnds[%d]->num_edges();",
prefix, idx, prefix, idx-1, receiver, idx-1 );
}
fprintf(fp," \t// %s\n", unique_opnd_ident(idx));
}
} if( *receiver != 0 ) { // This value is used by generate_peepreplace when copying a node. // Don't emit it in other cases since it can hide bugs with the // use invalid idx's.
fprintf(fp," unsigned %sidx%d = %sreq(); \n", prefix, idx, receiver);
}
}
// --------------------------- bool InstructForm::verify() { // !!!!! !!!!! // Check that a "label" operand occurs last in the operand list, if present returntrue;
}
void InstructForm::dump() {
output(stderr);
}
void InstructForm::output(FILE *fp) {
fprintf(fp,"\nInstruction: %s\n", (_ident?_ident:"")); if (_matrule) _matrule->output(fp); if (_insencode) _insencode->output(fp); if (_constant) _constant->output(fp); if (_opcode) _opcode->output(fp); if (_attribs) _attribs->output(fp); if (_predicate) _predicate->output(fp); if (_effects.Size()) {
fprintf(fp,"Effects\n");
_effects.dump();
} if (_exprule) _exprule->output(fp); if (_rewrule) _rewrule->output(fp); if (_format) _format->output(fp); if (_peephole) _peephole->output(fp);
}
//------------------------------build_predicate-------------------------------- // Build instruction predicates. If the user uses the same operand name // twice, we need to check that the operands are pointer-eequivalent in // the DFA during the labeling process.
Predicate *InstructForm::build_predicate() { constint buflen = 1024; char buf[buflen], *s=buf;
Dict names(cmpstr,hashstr,Form::arena); // Map Names to counts
// record a new register class
EncClass *EncodeForm::add_EncClass(constchar *className) {
EncClass *encClass = new EncClass(className);
_eclasses.addName(className);
_encClass.Insert(className,encClass); return encClass;
}
// Lookup the function body for an encoding class
EncClass *EncodeForm::encClass(constchar *className) {
assert( className != NULL, "Must provide a defined encoding name");
// Lookup the function body for an encoding class constchar *EncodeForm::encClassBody(constchar *className) { if( className == NULL ) return NULL;
EncClass *encClass = (EncClass*)_encClass[className];
assert( encClass != NULL, "Encode Class is missing.");
encClass->_code.reset(); constchar *code = (constchar*)encClass->_code.iter();
assert( code != NULL, "Found an empty encode class body.");
return code;
}
// Lookup the function body for an encoding class constchar *EncodeForm::encClassPrototype(constchar *className) {
assert( className != NULL, "Encode class name must be non NULL.");
// Verify operand types in parameter list bool EncClass::check_parameter_types(FormDict &globals) { // !!!!! returnfalse;
}
// Add the decomposed "code" sections of an encoding's code-block void EncClass::add_code(constchar *code) {
_code.addName(code);
}
// Add the decomposed "replacement variables" of an encoding's code-block void EncClass::add_rep_var(char *replacement_var) {
_code.addName(NameList::_signal);
_rep_vars.addName(replacement_var);
}
// Lookup the function body for an encoding class int EncClass::rep_var_index(constchar *rep_var) {
uint position = 0; constchar *name = NULL;
_parameter_name.reset(); while ( (name = _parameter_name.iter()) != NULL ) { if ( strcmp(rep_var,name) == 0 ) return position;
++position;
}
return -1;
}
// Check after parsing bool EncClass::verify() { // 1!!!! // Check that each replacement variable, '$name' in architecture description // is actually a local variable for this encode class, or a reserved name // "primary, secondary, tertiary" returntrue;
}
void EncClass::dump() {
output(stderr);
}
// Write info to output files void EncClass::output(FILE *fp) {
fprintf(fp,"EncClass: %s", (_name ? _name : ""));
// Add "encode class name" and its parameters
NameAndList *InsEncode::add_encode(char *encoding) {
assert( encoding != NULL, "Must provide name for encoding");
// add_parameter(NameList::_signal);
NameAndList *encode = new NameAndList(encoding);
_encoding.addName((char*)encode);
return encode;
}
// Access the list of encodings void InsEncode::reset() {
_encoding.reset(); // _parameter.reset();
} constchar* InsEncode::encode_class_iter() {
NameAndList *encode_class = (NameAndList*)_encoding.iter(); return ( encode_class != NULL ? encode_class->name() : NULL );
} // Obtain parameter name from zero based index constchar *InsEncode::rep_var_name(InstructForm &inst, uint param_no) {
NameAndList *params = (NameAndList*)_encoding.current();
assert( params != NULL, "Internal Error"); constchar *param = (*params)[param_no];
// True if this component is equal to the parameter. bool Effect::is(int use_def_kill_enum) const { return (_use_def == use_def_kill_enum ? true : false);
} // True if this component is used/def'd/kill'd as the parameter suggests. bool Effect::isa(int use_def_kill_enum) const { return (_use_def & use_def_kill_enum) == use_def_kill_enum;
}
void Effect::dump() {
output(stderr);
}
void Effect::output(FILE *fp) { // Write info to output files
fprintf(fp,"Effect: %s\n", (_name?_name:""));
}
// Check that my operands have the same interface type
Form::InterfaceType interface; bool first = true;
NameList &op_list = (NameList &)_oplst;
op_list.reset(); constchar *op_name; while( (op_name = op_list.iter()) != NULL ) { const Form *form = globals[op_name];
OperandForm *operand = form->is_operand();
assert( operand, "Entry in operand class that is not an operand"); if( first ) {
first = false;
interface = operand->interface_type(globals);
} else {
interface = (interface == operand->interface_type(globals) ? interface : Form::no_interface);
}
} return interface;
}
// Access op_cost attribute or return NULL. constchar* OperandForm::cost() { for (Attribute* cur = _attribs; cur != NULL; cur = (Attribute*)cur->_next) { if( strcmp(cur->_ident,AttributeForm::_op_cost) == 0 ) { return cur->_val;
}
} return NULL;
}
// Return the number of leaves below this complex operand
uint OperandForm::num_leaves() const { if ( ! _matrule) return 0;
int num_leaves = _matrule->_numleaves; return num_leaves;
}
// Return the number of constants contained within this complex operand
uint OperandForm::num_consts(FormDict &globals) const { if ( ! _matrule) return 0;
// This is a recursive invocation on all operands in the matchrule return _matrule->num_consts(globals);
}
// Return the number of constants in match rule with specified type
uint OperandForm::num_consts(FormDict &globals, Form::DataType type) const { if ( ! _matrule) return 0;
// This is a recursive invocation on all operands in the matchrule return _matrule->num_consts(globals, type);
}
// Return the number of pointer constants contained within this complex operand
uint OperandForm::num_const_ptrs(FormDict &globals) const { if ( ! _matrule) return 0;
// This is a recursive invocation on all operands in the matchrule return _matrule->num_const_ptrs(globals);
}
// Return ideal type, if there is a single ideal type for this operand constchar *OperandForm::ideal_type(FormDict &globals, RegisterForm *registers) const { constchar *type = NULL; if (ideal_only()) type = _ident; elseif( _matrule == NULL ) { // Check for condition code register constchar *rc_name = constrained_reg_class(); // !!!!! if (rc_name == NULL) return NULL; // !!!!! !!!!! // Check constraints on result's register class if( registers ) {
RegClass *reg_class = registers->getRegClass(rc_name);
assert( reg_class != NULL, "Register class is not defined");
// Check for ideal type of entries in register class, all are the same type
reg_class->reset();
RegDef *reg_def = reg_class->RegDef_iter();
assert( reg_def != NULL, "No entries in register class");
assert( reg_def->_idealtype != NULL, "Did not define ideal type for register"); // Return substring that names the register's ideal type
type = reg_def->_idealtype + 3;
assert( *(reg_def->_idealtype + 0) == 'O', "Expect Op_ prefix");
assert( *(reg_def->_idealtype + 1) == 'p', "Expect Op_ prefix");
assert( *(reg_def->_idealtype + 2) == '_', "Expect Op_ prefix");
}
} elseif( _matrule->_lChild == NULL && _matrule->_rChild == NULL ) { // This operand matches a single type, at the top level. // Check for ideal type
type = _matrule->_opType; if( strcmp(type,"Bool") == 0 ) return"Bool"; // transitive lookup const Form *frm = globals[type];
OperandForm *op = frm->is_operand();
type = op->ideal_type(globals, registers);
} return type;
}
// If there is a single ideal type for this interface field, return it. constchar *OperandForm::interface_ideal_type(FormDict &globals, constchar *field) const { constchar *ideal_type = NULL; constchar *value = NULL;
// Check if "field" is valid for this operand's interface if ( ! is_interface_field(field, value) ) return ideal_type;
// !!!!! !!!!! !!!!! // If a valid field has a constant value, identify "ConI" or "ConP" or ...
// Else, lookup type of field's replacement variable
constchar* name = ideal_type(globalAD->globalNames()); if (name == NULL) { returnfalse;
}
uint size = 0; if (strcmp(name, "RegFlags") == 0) size = 1; if (strcmp(name, "RegI") == 0) size = 1; if (strcmp(name, "RegF") == 0) size = 1; if (strcmp(name, "RegD") == 0) size = 2; if (strcmp(name, "RegL") == 0) size = 2; if (strcmp(name, "RegN") == 0) size = 1; if (strcmp(name, "RegVectMask") == 0) size = globalAD->get_preproc_def("AARCH64") ? 1 : 2; if (strcmp(name, "VecX") == 0) size = 4; if (strcmp(name, "VecY") == 0) size = 8; if (strcmp(name, "VecZ") == 0) size = 16; if (strcmp(name, "RegP") == 0) size = globalAD->get_preproc_def("_LP64") ? 2 : 1; if (size == 0) { returnfalse;
} return size == reg_class->size();
}
// Check if this is a valid field for this operand, // Return 'true' if valid, and set the value to the string the user provided. bool OperandForm::is_interface_field(constchar *field, constchar * &value) const { returnfalse;
}
// Return register class name if a constraint specifies the register class. constchar *OperandForm::constrained_reg_class() const { constchar *reg_class = NULL; if ( _constraint ) { // !!!!!
Constraint *constraint = _constraint; if ( strcmp(_constraint->_func,"ALLOC_IN_RC") == 0 ) {
reg_class = _constraint->_arg;
}
}
return reg_class;
}
// Return the register class associated with 'leaf'. constchar *OperandForm::in_reg_class(uint leaf, FormDict &globals) { constchar *reg_class = NULL; // "RegMask::Empty";
if((_matrule == NULL) || (_matrule->is_chain_rule(globals))) {
reg_class = constrained_reg_class(); return reg_class;
} constchar *result = NULL; constchar *name = NULL; constchar *type = NULL; // iterate through all base operands // until we reach the register that corresponds to "leaf" // This function is not looking for an ideal type. It needs the first // level user type associated with the leaf. for(uint idx = 0;_matrule->base_operand(idx,globals,result,name,type);++idx) { const Form *form = (_localNames[name] ? _localNames[name] : globals[result]);
OperandForm *oper = form ? form->is_operand() : NULL; if( oper ) {
reg_class = oper->constrained_reg_class(); if( reg_class ) {
reg_class = reg_class;
} else { // ShouldNotReachHere();
}
} else { // ShouldNotReachHere();
}
// Increment our target leaf position if current leaf is not a candidate. if( reg_class == NULL) ++leaf; // Exit the loop with the value of reg_class when at the correct index if( idx == leaf ) break; // May iterate through all base operands if reg_class for 'leaf' is NULL
} return reg_class;
}
// Recursive call to construct list of top-level operands. // Implementation does not modify state of internal structures void OperandForm::build_components() { if (_matrule) _matrule->append_components(_localNames, _components);
// Add parameters that "do not appear in match rule". constchar *name; for (_parameters.reset(); (name = _parameters.iter()) != NULL;) {
OpClassForm *opForm = _localNames[name]->is_opclass();
assert(opForm != NULL, "sanity");
int OperandForm::operand_position(constchar *name, int usedef) { return _components.operand_position(name, usedef, this);
}
// Return zero-based position in component list, only counting constants; // Return -1 if not in list. int OperandForm::constant_position(FormDict &globals, const Component *last) { // Iterate through components and count constants preceding 'constant' int position = 0;
Component *comp;
_components.reset(); while( (comp = _components.iter()) != NULL && (comp != last) ) { // Special case for operands that take a single user-defined operand // Skip the initial definition in the component list. if( strcmp(comp->_name,this->_ident) == 0 ) continue;
constchar *type = comp->_type; // Lookup operand form for replacement variable's type const Form *form = globals[type];
assert( form != NULL, "Component's type not found");
OperandForm *oper = form ? form->is_operand() : NULL; if( oper ) { if( oper->_matrule->is_base_constant(globals) != Form::none ) {
++position;
}
}
}
// Check for being passed a component that was not in the list if( comp != last ) position = -1;
return position;
} // Provide position of constant by "name" int OperandForm::constant_position(FormDict &globals, constchar *name) { const Component *comp = _components.search(name); int idx = constant_position( globals, comp );
return idx;
}
// Return zero-based position in component list, only counting constants; // Return -1 if not in list. int OperandForm::register_position(FormDict &globals, constchar *reg_name) { // Iterate through components and count registers preceding 'last'
uint position = 0;
Component *comp;
_components.reset(); while( (comp = _components.iter()) != NULL
&& (strcmp(comp->_name,reg_name) != 0) ) { // Special case for operands that take a single user-defined operand // Skip the initial definition in the component list. if( strcmp(comp->_name,this->_ident) == 0 ) continue;
constchar *type = comp->_type; // Lookup operand form for component's type const Form *form = globals[type];
assert( form != NULL, "Component's type not found");
OperandForm *oper = form ? form->is_operand() : NULL; if( oper ) { if( oper->_matrule->is_base_register(globals) ) {
++position;
}
}
}
return position;
}
constchar *OperandForm::reduce_result() const { return _ident;
} // Return the name of the operand on the right hand side of the binary match // Return NULL if there is no right hand side constchar *OperandForm::reduce_right(FormDict &globals) const { return ( _matrule ? _matrule->reduce_right(globals) : NULL );
}
// Similar for left constchar *OperandForm::reduce_left(FormDict &globals) const { return ( _matrule ? _matrule->reduce_left(globals) : NULL );
}
// --------------------------- FILE *output_routines // // Output code for disp_is_oop, if true. void OperandForm::disp_is_oop(FILE *fp, FormDict &globals) { // Check it is a memory interface with a non-user-constant disp field if ( this->_interface == NULL ) return;
MemInterface *mem_interface = this->_interface->is_MemInterface(); if ( mem_interface == NULL ) return; constchar *disp = mem_interface->_disp; if ( *disp != '$' ) return;
// Lookup replacement variable in operand's component list constchar *rep_var = disp + 1; const Component *comp = this->_components.search(rep_var);
assert( comp != NULL, "Replacement variable not found in components"); // Lookup operand form for replacement variable's type constchar *type = comp->_type;
Form *form = (Form*)globals[type];
assert( form != NULL, "Replacement variable's type not found");
OperandForm *op = form->is_operand();
assert( op, "Memory Interface 'disp' can only emit an operand form"); // Check if this is a ConP, which may require relocation if ( op->is_base_constant(globals) == Form::idealP ) { // Find the constant's index: _c0, _c1, _c2, ... , _cN
uint idx = op->constant_position( globals, rep_var);
fprintf(fp," virtual relocInfo::relocType disp_reloc() const {");
fprintf(fp, " return _c%d->reloc();", idx);
fprintf(fp, " }\n");
}
}
// Generate code for internal and external format methods // // internal access to reg# node->_idx // access to subsumed constant _c0, _c1, void OperandForm::int_format(FILE *fp, FormDict &globals, uint index) {
Form::DataType dtype; if (_matrule && (_matrule->is_base_register(globals) ||
strcmp(ideal_type(globalAD->globalNames()), "RegFlags") == 0)) { // !!!!! !!!!!
fprintf(fp," { char reg_str[128];\n");
fprintf(fp," ra->dump_register(node,reg_str);\n");
fprintf(fp," st->print(\"%cs\",reg_str);\n",'%');
fprintf(fp," }\n");
} elseif (_matrule && (dtype = _matrule->is_base_constant(globals)) != Form::none) {
format_constant( fp, index, dtype );
} elseif (ideal_to_sReg_type(_ident) != Form::none) { // Special format for Stack Slot Register
fprintf(fp," { char reg_str[128];\n");
fprintf(fp," ra->dump_register(node,reg_str);\n");
fprintf(fp," st->print(\"%cs\",reg_str);\n",'%');
fprintf(fp," }\n");
} else {
fprintf(fp," st->print(\"No format definedfor %s\n\");\n", _ident);
fflush(fp);
fprintf(stderr,"No format defined for %s\n", _ident);
dump();
assert( false,"Internal error:\n output_internal_operand() attempting to output other than a Register or Constant");
}
}
// Similar to "int_format" but for cases where data is external to operand // external access to reg# node->in(idx)->_idx, void OperandForm::ext_format(FILE *fp, FormDict &globals, uint index) {
Form::DataType dtype; if (_matrule && (_matrule->is_base_register(globals) ||
strcmp(ideal_type(globalAD->globalNames()), "RegFlags") == 0)) {
fprintf(fp," { char reg_str[128];\n");
fprintf(fp," ra->dump_register(node->in(idx"); if ( index != 0 ) fprintf(fp, "+%d",index);
fprintf(fp, "),reg_str);\n");
fprintf(fp," st->print(\"%cs\",reg_str);\n",'%');
fprintf(fp," }\n");
} elseif (_matrule && (dtype = _matrule->is_base_constant(globals)) != Form::none) {
format_constant( fp, index, dtype );
} elseif (ideal_to_sReg_type(_ident) != Form::none) { // Special format for Stack Slot Register
fprintf(fp," { char reg_str[128];\n");
fprintf(fp," ra->dump_register(node->in(idx"); if ( index != 0 ) fprintf(fp, "+%d",index);
fprintf(fp, "),reg_str);\n");
fprintf(fp," st->print(\"%cs\",reg_str);\n",'%');
fprintf(fp," }\n");
} else {
fprintf(fp," st->print(\"No format definedfor %s\n\");\n", _ident);
assert( false,"Internal error:\n output_external_operand() attempting to output other than a Register or Constant");
}
}
void OperandForm::format_constant(FILE *fp, uint const_index, uint const_type) { switch(const_type) { case Form::idealI: fprintf(fp," st->print(\"#%%d\", _c%d);\n", const_index); break; case Form::idealP: fprintf(fp," if (_c%d) _c%d->dump_on(st);\n", const_index, const_index); break; case Form::idealNKlass: case Form::idealN: fprintf(fp," if (_c%d) _c%d->dump_on(st);\n", const_index, const_index); break; case Form::idealL: fprintf(fp," st->print(\"#\" INT64_FORMAT, (int64_t)_c%d);\n", const_index); break; case Form::idealF: fprintf(fp," st->print(\"#%%f\", _c%d);\n", const_index); break; case Form::idealD: fprintf(fp," st->print(\"#%%f\", _c%d);\n", const_index); break; default:
assert( false, "ShouldNotReachHere()");
}
}
// Return the operand form corresponding to the given index, else NULL.
OperandForm *OperandForm::constant_operand(FormDict &globals,
uint index) { // !!!!! // Check behavior on complex operands
uint n_consts = num_consts(globals); if( n_consts > 0 ) {
uint i = 0; constchar *type;
Component *comp;
_components.reset(); if ((comp = _components.iter()) == NULL) {
assert(n_consts == 1, "Bad component list detected.\n"); // Current operand is THE operand if ( index == 0 ) { returnthis;
}
} // end if NULL else { // Skip the first component, it can not be a DEF of a constant do {
type = comp->base_type(globals); // Check that "type" is a 'ConI', 'ConP', ... if ( ideal_to_const_type(type) != Form::none ) { // When at correct component, get corresponding Operand if ( index == 0 ) { return globals[comp->_type]->is_operand();
} // Decrement number of constants to go
--index;
}
} while((comp = _components.iter()) != NULL);
}
}
// Did not find a constant for this index. return NULL;
}
// If this operand has a single ideal type, return its type
Form::DataType OperandForm::simple_type(FormDict &globals) const { constchar *type_name = ideal_type(globals);
Form::DataType type = type_name ? ideal_to_const_type( type_name )
: Form::none; return type;
}
// "true" if this operand is a simple type that is swallowed bool OperandForm::swallowed(FormDict &globals) const {
Form::DataType type = simple_type(globals); if( type != Form::none ) { returntrue;
}
returnfalse;
}
// Output code to access the value of the index'th constant void OperandForm::access_constant(FILE *fp, FormDict &globals,
uint const_index) {
OperandForm *oper = constant_operand(globals, const_index);
assert( oper, "Index exceeds number of constants in operand");
Form::DataType dtype = oper->is_base_constant(globals);
switch(dtype) { case idealI: fprintf(fp,"_c%d", const_index); break; case idealP: fprintf(fp,"_c%d->get_con()",const_index); break; case idealL: fprintf(fp,"_c%d", const_index); break; case idealF: fprintf(fp,"_c%d", const_index); break; case idealD: fprintf(fp,"_c%d", const_index); break; default:
assert( false, "ShouldNotReachHere()");
}
}
void OperandForm::dump() {
output(stderr);
}
void OperandForm::output(FILE *fp) {
fprintf(fp,"\nOperand: %s\n", (_ident?_ident:"")); if (_matrule) _matrule->dump(); if (_interface) _interface->dump(); if (_attribs) _attribs->dump(); if (_predicate) _predicate->dump(); if (_constraint) _constraint->dump(); if (_construct) _construct->dump(); if (_format) _format->dump();
}
//------------------------------Constraint-------------------------------------
Constraint::Constraint(constchar *func, constchar *arg)
: _func(func), _arg(arg) {
}
Constraint::~Constraint() { /* not owner of char* */
}
// True if this component is equal to the parameter. bool Component::is(int use_def_kill_enum) const { return (_usedef == use_def_kill_enum ? true : false);
} // True if this component is used/def'd/kill'd as the parameter suggests. bool Component::isa(int use_def_kill_enum) const { return (_usedef & use_def_kill_enum) == use_def_kill_enum;
}
// Extend this component with additional use/def/kill behavior int Component::promote_use_def_info(int new_use_def) {
_usedef |= new_use_def;
return _usedef;
}
// Check the base type of this component, if it has one constchar *Component::base_type(FormDict &globals) { const Form *frm = globals[_type]; if (frm == NULL) return NULL;
OperandForm *op = frm->is_operand(); if (op == NULL) return NULL; if (op->ideal_only()) return op->_ident; return (char *)op->ideal_type(globals);
}
//------------------------------ComponentList---------------------------------
ComponentList::ComponentList() : NameList(), _matchcnt(0) {
}
ComponentList::~ComponentList() { // // This list may not own its elements if copied via assignment // Component *component; // for (reset(); (component = iter()) != NULL;) { // delete component; // }
}
Component *ComponentList::operator[](int position) { // Shortcut complete iteration if there are not enough entries if (position >= count()) return NULL;
int index = 0;
Component *component = NULL; for (reset(); (component = iter()) != NULL;) { if (index == position) { return component;
}
++index;
}
// Return number of USEs + number of DEFs // When there are no components, or the first component is a USE, // then we add '1' to hold a space for the 'result' operand. int ComponentList::num_operands() {
PreserveIter pi(this);
uint count = 1; // result operand
uint position = 0;
// Return zero-based position of operand 'name' in list; -1 if not in list. // if parameter 'usedef' is ::USE, it will match USE, USE_DEF, ... int ComponentList::operand_position(constchar *name, int usedef, Form *fm) {
PreserveIter pi(this); int position = 0; int num_opnds = num_operands();
Component *component;
Component* preceding_non_use = NULL;
Component* first_def = NULL; for (reset(); (component = iter()) != NULL; ++position) { // When the first component is not a DEF, // leave space for the result operand! if ( position==0 && (! component->isa(Component::DEF)) ) {
++position;
++num_opnds;
} if (strcmp(name, component->_name)==0 && (component->isa(usedef))) { // When the first entry in the component list is a DEF and a USE // Treat them as being separate, a DEF first, then a USE if( position==0
&& usedef==Component::USE && component->isa(Component::DEF) ) {
assert(position+1 < num_opnds, "advertised index in bounds"); return position+1;
} else { if( preceding_non_use && strcmp(component->_name, preceding_non_use->_name) ) {
fprintf(stderr, "the name '%s(%s)' should not precede the name '%s(%s)'",
preceding_non_use->_name, preceding_non_use->getUsedefName(),
name, component->getUsedefName()); if (fm && fm->is_instruction()) fprintf(stderr, "in form '%s'", fm->is_instruction()->_ident); if (fm && fm->is_operand()) fprintf(stderr, "in form '%s'", fm->is_operand()->_ident);
fprintf(stderr, "\n");
} if( position >= num_opnds ) {
fprintf(stderr, "the name '%s' is too late in its name list", name); if (fm && fm->is_instruction()) fprintf(stderr, "in form '%s'", fm->is_instruction()->_ident); if (fm && fm->is_operand()) fprintf(stderr, "in form '%s'", fm->is_operand()->_ident);
fprintf(stderr, "\n");
}
assert(position < num_opnds, "advertised index in bounds"); return position;
}
} if( component->isa(Component::DEF)
&& component->isa(Component::USE) ) {
++position; if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
} if( component->isa(Component::DEF) && !first_def ) {
first_def = component;
} if( !component->isa(Component::USE) && component != first_def ) {
preceding_non_use = component;
} elseif( preceding_non_use && !strcmp(component->_name, preceding_non_use->_name) ) {
preceding_non_use = NULL;
}
} return Not_in_list;
}
// Find position for this name, regardless of use/def information int ComponentList::operand_position(constchar *name) {
PreserveIter pi(this); int position = 0;
Component *component; for (reset(); (component = iter()) != NULL; ++position) { // When the first component is not a DEF, // leave space for the result operand! if ( position==0 && (! component->isa(Component::DEF)) ) {
++position;
} if (strcmp(name, component->_name)==0) { return position;
} if( component->isa(Component::DEF)
&& component->isa(Component::USE) ) {
++position; if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
}
} return Not_in_list;
}
int ComponentList::operand_position_format(constchar *name, Form *fm) {
PreserveIter pi(this); int first_position = operand_position(name); int use_position = operand_position(name, Component::USE, fm);
int ComponentList::label_position() {
PreserveIter pi(this); int position = 0;
reset(); for( Component *comp; (comp = iter()) != NULL; ++position) { // When the first component is not a DEF, // leave space for the result operand! if ( position==0 && (! comp->isa(Component::DEF)) ) {
++position;
} if (strcmp(comp->_type, "label")==0) { return position;
} if( comp->isa(Component::DEF)
&& comp->isa(Component::USE) ) {
++position; if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
}
}
return -1;
}
int ComponentList::method_position() {
PreserveIter pi(this); int position = 0;
reset(); for( Component *comp; (comp = iter()) != NULL; ++position) { // When the first component is not a DEF, // leave space for the result operand! if ( position==0 && (! comp->isa(Component::DEF)) ) {
++position;
} if (strcmp(comp->_type, "method")==0) { return position;
} if( comp->isa(Component::DEF)
&& comp->isa(Component::USE) ) {
++position; if( position != 1 ) --position; // only use two slots for the 1st USE_DEF
}
}
MatchNode::MatchNode(ArchDesc &ad, MatchNode& mnode, int clone)
: _AD(ad), _result(mnode._result), _name(mnode._name),
_opType(mnode._opType),
_internalop(0), _numleaves(mnode._numleaves),
_commutative_id(mnode._commutative_id) { if (mnode._lChild) {
_lChild = new MatchNode(ad, *mnode._lChild, clone);
} else {
_lChild = NULL;
} if (mnode._rChild) {
_rChild = new MatchNode(ad, *mnode._rChild, clone);
} else {
_rChild = NULL;
}
}
MatchNode::~MatchNode() { // // This node may not own its children if copied via assignment // if( _lChild ) delete _lChild; // if( _rChild ) delete _rChild;
}
bool MatchNode::find_type(constchar *type, int &position) const { if ( (_lChild != NULL) && (_lChild->find_type(type, position)) ) returntrue; if ( (_rChild != NULL) && (_rChild->find_type(type, position)) ) returntrue;
// Recursive call collecting info on top-level operands, not transitive. // Implementation does not modify state of internal structures. void MatchNode::append_components(FormDict& locals, ComponentList& components, bool def_flag) const { int usedef = def_flag ? Component::DEF : Component::USE;
FormDict &globals = _AD.globalNames();
assert (_name != NULL, "MatchNode::build_components encountered empty node\n"); // Base case if (_lChild==NULL && _rChild==NULL) { // If _opType is not an operation, do not build a component for it ##### const Form *f = globals[_opType]; if( f != NULL ) { // Add non-ideals that are operands, operand-classes, if( ! f->ideal_only()
&& (f->is_opclass() || f->is_operand()) ) {
components.insert(_name, _opType, usedef, true);
}
} return;
} // Promote results of "Set" to DEF bool tmpdef_flag = (!strcmp(_opType, "Set")) ? true : false; if (_lChild) _lChild->append_components(locals, components, tmpdef_flag);
tmpdef_flag = false; // only applies to component immediately following 'Set' if (_rChild) _rChild->append_components(locals, components, tmpdef_flag);
}
// Find the n'th base-operand in the match node, // recursively investigates match rules of user-defined operands. // // Implementation does not modify state of internal structures since they // can be shared. bool MatchNode::base_operand(uint &position, FormDict &globals, constchar * &result, constchar * &name, constchar * &opType) const {
assert (_name != NULL, "MatchNode::base_operand encountered empty node\n"); // Base case if (_lChild==NULL && _rChild==NULL) { // Check for special case: "Universe", "label" if (strcmp(_opType,"Universe") == 0 || strcmp(_opType,"label")==0 ) { if (position == 0) {
result = _result;
name = _name;
opType = _opType; return 1;
} else {
-- position; return 0;
}
}
const Form *form = globals[_opType];
MatchNode *matchNode = NULL; // Check for user-defined type if (form) { // User operand or instruction?
OperandForm *opForm = form->is_operand();
InstructForm *inForm = form->is_instruction(); if ( opForm ) {
matchNode = (MatchNode*)opForm->_matrule;
} elseif ( inForm ) {
matchNode = (MatchNode*)inForm->_matrule;
}
} // if this is user-defined, recurse on match rule // User-defined operand and instruction forms have a match-rule. if (matchNode) { return (matchNode->base_operand(position,globals,result,name,opType));
} else { // Either not a form, or a system-defined form (no match rule). if (position==0) {
result = _result;
name = _name;
opType = _opType; return 1;
} else {
--position; return 0;
}
}
} else { // Examine the left child and right child as well if (_lChild) { if (_lChild->base_operand(position, globals, result, name, opType)) return 1;
}
if (_rChild) { if (_rChild->base_operand(position, globals, result, name, opType)) return 1;
}
}
return 0;
}
// Recursive call on all operands' match rules in my match rule.
uint MatchNode::num_consts(FormDict &globals) const {
uint index = 0;
uint num_consts = 0; constchar *result; constchar *name; constchar *opType;
for (uint position = index;
base_operand(position,globals,result,name,opType); position = index) {
++index; if( ideal_to_const_type(opType) ) num_consts++;
}
return num_consts;
}
// Recursive call on all operands' match rules in my match rule. // Constants in match rule subtree with specified type
uint MatchNode::num_consts(FormDict &globals, Form::DataType type) const {
uint index = 0;
uint num_consts = 0; constchar *result; constchar *name; constchar *opType;
for (uint position = index;
base_operand(position,globals,result,name,opType); position = index) {
++index; if( ideal_to_const_type(opType) == type ) num_consts++;
}
return num_consts;
}
// Recursive call on all operands' match rules in my match rule.
uint MatchNode::num_const_ptrs(FormDict &globals) const { return num_consts( globals, Form::idealP );
}
constchar *MatchNode::reduce_right(FormDict &globals) const { // If there is no right reduction, return NULL. constchar *rightStr = NULL;
// If we are a "Set", start from the right child. const MatchNode *const mnode = sets_result() ?
(const MatchNode *)this->_rChild :
(const MatchNode *)this;
// If our right child exists, it is the right reduction if ( mnode->_rChild ) {
rightStr = mnode->_rChild->_internalop ? mnode->_rChild->_internalop
: mnode->_rChild->_opType;
} // Else, May be simple chain rule: (Set dst operand_form), rightStr=NULL; return rightStr;
}
constchar *MatchNode::reduce_left(FormDict &globals) const { // If there is no left reduction, return NULL. constchar *leftStr = NULL;
// If we are a "Set", start from the right child. const MatchNode *const mnode = sets_result() ?
(const MatchNode *)this->_rChild :
(const MatchNode *)this;
// If our left child exists, it is the left reduction if ( mnode->_lChild ) {
leftStr = mnode->_lChild->_internalop ? mnode->_lChild->_internalop
: mnode->_lChild->_opType;
} else { // May be simple chain rule: (Set dst operand_form_source) if ( sets_result() ) {
OperandForm *oper = globals[mnode->_opType]->is_operand(); if( oper ) {
leftStr = mnode->_opType;
}
}
} return leftStr;
}
//------------------------------count_instr_names------------------------------ // Count occurrences of operands names in the leaves of the instruction // match rule. void MatchNode::count_instr_names( Dict &names ) { if( _lChild ) _lChild->count_instr_names(names); if( _rChild ) _rChild->count_instr_names(names); if( !_lChild && !_rChild ) {
uintptr_t cnt = (uintptr_t)names[_name];
cnt++; // One more name found
names.Insert(_name,(void*)cnt);
}
}
//------------------------------build_instr_pred------------------------------- // Build a path to 'name' in buf. Actually only build if cnt is zero, so we // can skip some leading instances of 'name'. int MatchNode::build_instr_pred( char *buf, constchar *name, int cnt, int path_bitmask, int level) { if( _lChild ) {
cnt = _lChild->build_instr_pred(buf, name, cnt, path_bitmask, level+1); if( cnt < 0 ) { return cnt; // Found it, all done
}
} if( _rChild ) {
path_bitmask |= 1 << level;
cnt = _rChild->build_instr_pred( buf, name, cnt, path_bitmask, level+1); if( cnt < 0 ) { return cnt; // Found it, all done
}
} if( !_lChild && !_rChild ) { // Found a leaf // Wrong name? Give up... if( strcmp(name,_name) ) return cnt; if( !cnt ) { for(int i = 0; i < level; i++) { int kid = path_bitmask & (1 << i); if (0 == kid) {
strcpy( buf, "_kids[0]->" );
} else {
strcpy( buf, "_kids[1]->" );
}
buf += 10;
}
strcpy( buf, "_leaf" );
} return cnt-1;
} return cnt;
}
//------------------------------build_internalop------------------------------- // Build string representation of subtree void MatchNode::build_internalop( ) { char *iop, *subtree; constchar *lstr, *rstr; // Build string representation of subtree // Operation lchildType rchildType int len = (int)strlen(_opType) + 4;
lstr = (_lChild) ? ((_lChild->_internalop) ?
_lChild->_internalop : _lChild->_opType) : "";
rstr = (_rChild) ? ((_rChild->_internalop) ?
_rChild->_internalop : _rChild->_opType) : "";
len += (int)strlen(lstr) + (int)strlen(rstr);
subtree = (char *)AdlAllocateHeap(len);
sprintf(subtree,"_%s_%s_%s", _opType, lstr, rstr); // Hash the subtree string in _internalOps; if a name exists, use it
iop = (char *)_AD._internalOps[subtree]; // Else create a unique name, and add it to the hash table if (iop == NULL) {
iop = subtree;
_AD._internalOps.Insert(subtree, iop);
_AD._internalOpNames.addName(iop);
_AD._internalMatch.Insert(iop, this);
} // Add the internal operand name to the MatchNode
_internalop = iop;
_result = iop;
}
// TRUE if defines a derived oop, and so needs a base oop edge present // post-matching. int MatchNode::needs_base_oop_edge() const { if( !strcmp(_opType,"AddP") ) return 1; if( strcmp(_opType,"Set") ) return 0; return !strcmp(_rChild->_opType,"AddP");
}
//-------------------------cisc spilling methods------------------------------- // helper routines and methods for detecting cisc-spilling instructions //-------------------------cisc_spill_merge------------------------------------ int MatchNode::cisc_spill_merge(int left_spillable, int right_spillable) { int cisc_spillable = Maybe_cisc_spillable;
// Combine results of left and right checks if( (left_spillable == Maybe_cisc_spillable) && (right_spillable == Maybe_cisc_spillable) ) { // neither side is spillable, nor prevents cisc spilling
cisc_spillable = Maybe_cisc_spillable;
} elseif( (left_spillable == Maybe_cisc_spillable) && (right_spillable > Maybe_cisc_spillable) ) { // right side is spillable
cisc_spillable = right_spillable;
} elseif( (right_spillable == Maybe_cisc_spillable) && (left_spillable > Maybe_cisc_spillable) ) { // left side is spillable
cisc_spillable = left_spillable;
} elseif( (left_spillable == Not_cisc_spillable) || (right_spillable == Not_cisc_spillable) ) { // left or right prevents cisc spilling this instruction
cisc_spillable = Not_cisc_spillable;
} else { // Only allow one to spill
cisc_spillable = Not_cisc_spillable;
}
return cisc_spillable;
}
//-------------------------root_ops_match-------------------------------------- boolstatic root_ops_match(FormDict &globals, constchar *op1, constchar *op2) { // Base Case: check that the current operands/operations match
assert( op1, "Must have op's name");
assert( op2, "Must have op's name"); const Form *form1 = globals[op1]; const Form *form2 = globals[op2];
return (form1 == form2);
}
//-------------------------cisc_spill_match_node------------------------------- // Recursively check two MatchRules for legal conversion via cisc-spilling int MatchNode::cisc_spill_match(FormDict& globals, RegisterForm* registers, MatchNode* mRule2, constchar* &operand, constchar* ®_type) { int cisc_spillable = Maybe_cisc_spillable; int left_spillable = Maybe_cisc_spillable; int right_spillable = Maybe_cisc_spillable;
// Check that each has same number of operands at this level if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable;
// Base Case: check that the current operands/operations match // or are CISC spillable
assert( _opType, "Must have _opType");
assert( mRule2->_opType, "Must have _opType"); const Form *form = globals[_opType]; const Form *form2 = globals[mRule2->_opType]; if( form == form2 ) {
cisc_spillable = Maybe_cisc_spillable;
} else { const InstructForm *form2_inst = form2 ? form2->is_instruction() : NULL; constchar *name_left = mRule2->_lChild ? mRule2->_lChild->_opType : NULL; constchar *name_right = mRule2->_rChild ? mRule2->_rChild->_opType : NULL;
DataType data_type = Form::none; if (form->is_operand()) { // Make sure the loadX matches the type of the reg
data_type = form->ideal_to_Reg_type(form->is_operand()->ideal_type(globals));
} // Detect reg vs (loadX memory) if( form->is_cisc_reg(globals)
&& form2_inst
&& data_type != Form::none
&& (is_load_from_memory(mRule2->_opType) == data_type) // reg vs. (load memory)
&& (name_left != NULL) // NOT (load)
&& (name_right == NULL) ) { // NOT (load memory foo) const Form *form2_left = globals[name_left]; if( form2_left && form2_left->is_cisc_mem(globals) ) {
cisc_spillable = Is_cisc_spillable;
operand = _name;
reg_type = _result; return Is_cisc_spillable;
} else {
cisc_spillable = Not_cisc_spillable;
}
} // Detect reg vs memory elseif (form->is_cisc_reg(globals) && form2 != NULL && form2->is_cisc_mem(globals)) {
cisc_spillable = Is_cisc_spillable;
operand = _name;
reg_type = _result; return Is_cisc_spillable;
} else {
cisc_spillable = Not_cisc_spillable;
}
}
// If cisc is still possible, check rest of tree if( cisc_spillable == Maybe_cisc_spillable ) { // Check that each has same number of operands at this level if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable;
// Combine results of left and right checks
cisc_spillable = cisc_spill_merge(left_spillable, right_spillable);
}
return cisc_spillable;
}
//---------------------------cisc_spill_match_rule------------------------------ // Recursively check two MatchRules for legal conversion via cisc-spilling // This method handles the root of Match tree, // general recursive checks done in MatchNode int MatchRule::matchrule_cisc_spill_match(FormDict& globals, RegisterForm* registers,
MatchRule* mRule2, constchar* &operand, constchar* ®_type) { int cisc_spillable = Maybe_cisc_spillable; int left_spillable = Maybe_cisc_spillable; int right_spillable = Maybe_cisc_spillable;
// Check that each sets a result if( !(sets_result() && mRule2->sets_result()) ) return Not_cisc_spillable; // Check that each has same number of operands at this level if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable;
// Check left operands: at root, must be target of 'Set' if( (_lChild == NULL) || (mRule2->_lChild == NULL) ) {
left_spillable = Not_cisc_spillable;
} else { // Do not support cisc-spilling instruction's target location if( root_ops_match(globals, _lChild->_opType, mRule2->_lChild->_opType) ) {
left_spillable = Maybe_cisc_spillable;
} else {
left_spillable = Not_cisc_spillable;
}
}
// Check right operands: recursive walk to identify reg->mem operand if (_rChild == NULL) { if (mRule2->_rChild == NULL) {
right_spillable = Maybe_cisc_spillable;
} else {
assert(0, "_rChild should not be NULL");
}
} else {
right_spillable = _rChild->cisc_spill_match(globals, registers, mRule2->_rChild, operand, reg_type);
}
// Combine results of left and right checks
cisc_spillable = cisc_spill_merge(left_spillable, right_spillable);
return cisc_spillable;
}
//----------------------------- equivalent ------------------------------------ // Recursively check to see if two match rules are equivalent. // This rule handles the root. bool MatchRule::equivalent(FormDict &globals, MatchNode *mRule2) { // Check that each sets a result if (sets_result() != mRule2->sets_result()) { returnfalse;
}
// Check that the current operands/operations match
assert( _opType, "Must have _opType");
assert( mRule2->_opType, "Must have _opType"); const Form *form = globals[_opType]; const Form *form2 = globals[mRule2->_opType]; if( form != form2 ) { returnfalse;
}
if (_lChild ) { if( !_lChild->equivalent(globals, mRule2->_lChild) ) returnfalse;
} elseif (mRule2->_lChild) { returnfalse; // I have NULL left child, mRule2 has non-NULL left child.
}
if (_rChild ) { if( !_rChild->equivalent(globals, mRule2->_rChild) ) returnfalse;
} elseif (mRule2->_rChild) { returnfalse; // I have NULL right child, mRule2 has non-NULL right child.
}
// We've made it through the gauntlet. returntrue;
}
//----------------------------- equivalent ------------------------------------ // Recursively check to see if two match rules are equivalent. // This rule handles the operands. bool MatchNode::equivalent(FormDict &globals, MatchNode *mNode2) { if( !mNode2 ) returnfalse;
// Check that the current operands/operations match
assert( _opType, "Must have _opType");
assert( mNode2->_opType, "Must have _opType"); const Form *form = globals[_opType]; const Form *form2 = globals[mNode2->_opType]; if( form != form2 ) { returnfalse;
}
// Check that their children also match if (_lChild ) { if( !_lChild->equivalent(globals, mNode2->_lChild) ) returnfalse;
} elseif (mNode2->_lChild) { returnfalse; // I have NULL left child, mNode2 has non-NULL left child.
}
if (_rChild ) { if( !_rChild->equivalent(globals, mNode2->_rChild) ) returnfalse;
} elseif (mNode2->_rChild) { returnfalse; // I have NULL right child, mNode2 has non-NULL right child.
}
// We've made it through the gauntlet. returntrue;
}
//-------------------------- count_commutative_op ------------------------------- // Recursively check for commutative operations with subtree operands // which could be swapped. void MatchNode::count_commutative_op(int& count) { staticconstchar *commut_op_list[] = { "AddI","AddL","AddF","AddD", "AndI","AndL", "MaxI","MinI","MaxF","MinF","MaxD","MinD", "MulI","MulL","MulF","MulD", "OrI","OrL", "XorI","XorL"
};
if (_lChild && _rChild && (_lChild->_lChild || _rChild->_lChild)) { // Don't swap if right operand is an immediate constant. bool is_const = false; if (_rChild->_lChild == NULL && _rChild->_rChild == NULL) {
FormDict &globals = _AD.globalNames(); const Form *form = globals[_rChild->_opType]; if (form) {
OperandForm *oper = form->is_operand(); if (oper && oper->interface_type(globals) == Form::constant_interface)
is_const = true;
}
}
if (!is_const) { int scalar_cnt = sizeof(commut_op_list)/sizeof(char*); int vector_cnt = sizeof(commut_vector_op_list)/sizeof(char*); bool matched = false;
// Check the commutative vector op first. It's noncommutative if // the current node is a masked vector op, since a mask value // is added to the original vector node's input list and the original // first two inputs are packed into one BinaryNode. So don't swap // if one of the operands is a BinaryNode. for (int i = 0; i < vector_cnt; i++) { if (strcmp(_opType, commut_vector_op_list[i]) == 0) { if (strcmp(_lChild->_opType, "Binary") != 0 &&
strcmp(_rChild->_opType, "Binary") != 0) {
count++;
_commutative_id = count; // id should be > 0
}
matched = true; break;
}
}
// Then check the scalar op if the current op is not in // the commut_vector_op_list. if (!matched) { for (int i = 0; i < scalar_cnt; i++) { if (strcmp(_opType, commut_op_list[i]) == 0) {
count++;
_commutative_id = count; // id should be > 0 break;
}
}
}
}
} if (_lChild)
_lChild->count_commutative_op(count); if (_rChild)
_rChild->count_commutative_op(count);
}
//-------------------------- swap_commutative_op ------------------------------ // Recursively swap specified commutative operation with subtree operands. void MatchNode::swap_commutative_op(bool atroot, int id) { if( _commutative_id == id ) { // id should be > 0
assert(_lChild && _rChild && (_lChild->_lChild || _rChild->_lChild ), "not swappable operation");
MatchNode* tmp = _lChild;
_lChild = _rChild;
_rChild = tmp; // Don't exit here since we need to build internalop.
}
// Recursive call collecting info on top-level operands, not transitive. // Implementation does not modify state of internal structures. void MatchRule::append_components(FormDict& locals, ComponentList& components, bool def_flag) const {
assert (_name != NULL, "MatchNode::build_components encountered empty node\n");
MatchNode::append_components(locals, components, false/* not necessarily a def */);
}
// Recursive call on all operands' match rules in my match rule. // Implementation does not modify state of internal structures since they // can be shared. // The MatchNode that is called first treats its bool MatchRule::base_operand(uint &position0, FormDict &globals, constchar *&result, constchar * &name, constchar * &opType)const{
uint position = position0;
// Check for chain rule, and do not generate a match list for it if ((_lChild == NULL) && (_rChild == NULL) ) { const Form *form = globals[_opType]; // If this is ideal, then it is a base match, not a chain rule. if ( form && form->is_operand() && (!form->ideal_only())) { returntrue;
}
} // Check for "Set" form of chain rule, and do not generate a match list if (_rChild) { constchar *rch = _rChild->_opType; const Form *form = globals[rch]; if ((!strcmp(_opType,"Set") &&
((form) && form->is_operand()))) { returntrue;
}
} returnfalse;
}
bool MatchRule::skip_antidep_check() const { // Some loads operate on what is effectively immutable memory so we // should skip the anti dep computations. For some of these nodes // the rewritable field keeps the anti dep logic from triggering but // for certain kinds of LoadKlass it does not since they are // actually reading memory which could be rewritten by the runtime, // though never by generated code. This disables it uniformly for // the nodes that behave like this: LoadKlass, LoadNKlass and // LoadRange. if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) { constchar *opType = _rChild->_opType; if (strcmp("LoadKlass", opType) == 0 ||
strcmp("LoadNKlass", opType) == 0 ||
strcmp("LoadRange", opType) == 0) { returntrue;
}
}
int Attribute::int_val(ArchDesc &ad) { // Make sure it is an integer constant: int result = 0; if (!_val || !ADLParser::is_int_token(_val, result)) {
ad.syntax_err(0, "Attribute %s must have an integer value: %s",
_ident, _val ? _val : "");
} return result;
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.74Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-04-30)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.