in src/hotspot/share/adlc/output_h.cpp [1091:1982]
void ArchDesc::declareClasses(FILE *fp) {
// Declare an array containing the machine register names, strings.
declareRegNames(fp, _register);
// Declare an array containing the machine register encoding values
declareRegEncodes(fp, _register);
// Generate declarations for the total number of operands
fprintf(fp,"\n");
fprintf(fp,"// Total number of operands defined in architecture definition\n");
int num_operands = 0;
OperandForm *op;
for (_operands.reset(); (op = (OperandForm*)_operands.iter()) != nullptr; ) {
// Ensure this is a machine-world instruction
if (op->ideal_only()) continue;
++num_operands;
}
int first_operand_class = num_operands;
OpClassForm *opc;
for (_opclass.reset(); (opc = (OpClassForm*)_opclass.iter()) != nullptr; ) {
// Ensure this is a machine-world instruction
if (opc->ideal_only()) continue;
++num_operands;
}
fprintf(fp,"#define FIRST_OPERAND_CLASS %d\n", first_operand_class);
fprintf(fp,"#define NUM_OPERANDS %d\n", num_operands);
fprintf(fp,"\n");
// Generate declarations for the total number of instructions
fprintf(fp,"// Total number of instructions defined in architecture definition\n");
fprintf(fp,"#define NUM_INSTRUCTIONS %d\n",instructFormCount());
// Generate Machine Classes for each operand defined in AD file
fprintf(fp,"\n");
fprintf(fp,"//----------------------------Declare classes derived from MachOper----------\n");
// Iterate through all operands
_operands.reset();
OperandForm *oper;
for( ; (oper = (OperandForm*)_operands.iter()) != nullptr;) {
// Ensure this is a machine-world instruction
if (oper->ideal_only() ) continue;
// The declaration of labelOper is in machine-independent file: machnode
if ( strcmp(oper->_ident,"label") == 0 ) continue;
// The declaration of methodOper is in machine-independent file: machnode
if ( strcmp(oper->_ident,"method") == 0 ) continue;
// Build class definition for this operand
fprintf(fp,"\n");
fprintf(fp,"class %sOper : public MachOper { \n",oper->_ident);
fprintf(fp,"private:\n");
// Operand definitions that depend upon number of input edges
{
uint num_edges = oper->num_edges(_globalNames);
if( num_edges != 1 ) { // Use MachOper::num_edges() {return 1;}
fprintf(fp," virtual uint num_edges() const { return %d; }\n",
num_edges );
}
if( num_edges > 0 ) {
in_RegMask(fp);
}
}
// Support storing constants inside the MachOper
declareConstStorage(fp,_globalNames,oper);
// Support storage of the condition codes
if( oper->is_ideal_bool() ) {
fprintf(fp," virtual int ccode() const { \n");
fprintf(fp," switch (_c0) {\n");
fprintf(fp," case BoolTest::eq : return equal();\n");
fprintf(fp," case BoolTest::gt : return greater();\n");
fprintf(fp," case BoolTest::lt : return less();\n");
fprintf(fp," case BoolTest::ne : return not_equal();\n");
fprintf(fp," case BoolTest::le : return less_equal();\n");
fprintf(fp," case BoolTest::ge : return greater_equal();\n");
fprintf(fp," case BoolTest::overflow : return overflow();\n");
fprintf(fp," case BoolTest::no_overflow: return no_overflow();\n");
fprintf(fp," default : ShouldNotReachHere(); return 0;\n");
fprintf(fp," }\n");
fprintf(fp," };\n");
}
// Support storage of the condition codes
if( oper->is_ideal_bool() ) {
fprintf(fp," virtual void negate() { \n");
fprintf(fp," _c0 = (BoolTest::mask)((int)_c0^0x4); \n");
fprintf(fp," };\n");
}
// Declare constructor.
// Parameters start with condition code, then all other constants
//
// (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)
// (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }
//
Form::DataType constant_type = oper->simple_type(_globalNames);
defineConstructor(fp, oper->_ident, oper->num_consts(_globalNames),
oper->_components, oper->is_ideal_bool(),
constant_type, _globalNames);
// Clone function
fprintf(fp," virtual MachOper *clone() const;\n");
// Support setting a spill offset into a constant operand.
// We only support setting an 'int' offset, while in the
// LP64 build spill offsets are added with an AddP which
// requires a long constant. Thus we don't support spilling
// in frames larger than 4Gig.
if( oper->has_conI(_globalNames) ||
oper->has_conL(_globalNames) )
fprintf(fp, " virtual void set_con( jint c0 ) { _c0 = c0; }\n");
// virtual functions for encoding and format
// fprintf(fp," virtual void encode() const {\n %s }\n",
// (oper->_encrule)?(oper->_encrule->_encrule):"");
// Check the interface type, and generate the correct query functions
// encoding queries based upon MEMORY_INTER, REG_INTER, CONST_INTER.
fprintf(fp," virtual uint opcode() const { return %s; }\n",
machOperEnum(oper->_ident));
// virtual function to look up ideal return type of machine instruction
//
// (1) virtual const Type *type() const { return .....; }
//
if ((oper->_matrule) && (oper->_matrule->_lChild == nullptr) &&
(oper->_matrule->_rChild == nullptr)) {
unsigned int position = 0;
const char *opret, *opname, *optype;
oper->_matrule->base_operand(position,_globalNames,opret,opname,optype);
fprintf(fp," virtual const Type *type() const {");
const char *type = getIdealType(optype);
if( type != nullptr ) {
Form::DataType data_type = oper->is_base_constant(_globalNames);
// Check if we are an ideal pointer type
if( data_type == Form::idealP || data_type == Form::idealN || data_type == Form::idealNKlass ) {
// Return the ideal type we already have: <TypePtr *>
fprintf(fp," return _c0;");
} else {
// Return the appropriate bottom type
fprintf(fp," return %s;", getIdealType(optype));
}
} else {
fprintf(fp," ShouldNotCallThis(); return Type::BOTTOM;");
}
fprintf(fp," }\n");
} else {
// Check for user-defined stack slots, based upon sRegX
Form::DataType data_type = oper->is_user_name_for_sReg();
if( data_type != Form::none ){
const char *type = nullptr;
switch( data_type ) {
case Form::idealI: type = "TypeInt::INT"; break;
case Form::idealP: type = "TypePtr::BOTTOM";break;
case Form::idealF: type = "Type::FLOAT"; break;
case Form::idealD: type = "Type::DOUBLE"; break;
case Form::idealL: type = "TypeLong::LONG"; break;
case Form::idealH: type = "Type::HALF_FLOAT"; break;
case Form::none: // fall through
default:
assert( false, "No support for this type of stackSlot");
}
fprintf(fp," virtual const Type *type() const { return %s; } // stackSlotX\n", type);
}
}
//
// virtual functions for defining the encoding interface.
//
// Access the linearized ideal register mask,
// map to physical register encoding
if ( oper->_matrule && oper->_matrule->is_base_register(_globalNames) ) {
// Just use the default virtual 'reg' call
} else if ( oper->ideal_to_sReg_type(oper->_ident) != Form::none ) {
// Special handling for operand 'sReg', a Stack Slot Register.
// Map linearized ideal register mask to stack slot number
fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node) const {\n");
fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node));/* sReg */\n");
fprintf(fp," }\n");
fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {\n");
fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node->in(idx)));/* sReg */\n");
fprintf(fp," }\n");
}
// Output the operand specific access functions used by an enc_class
// These are only defined when we want to override the default virtual func
if (oper->_interface != nullptr) {
fprintf(fp,"\n");
// Check if it is a Memory Interface
if ( oper->_interface->is_MemInterface() != nullptr ) {
MemInterface *mem_interface = oper->_interface->is_MemInterface();
const char *base = mem_interface->_base;
if( base != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "base", base);
}
char *index = mem_interface->_index;
if( index != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "index", index);
}
const char *scale = mem_interface->_scale;
if( scale != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "scale", scale);
}
const char *disp = mem_interface->_disp;
if( disp != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "disp", disp);
oper->disp_is_oop(fp, _globalNames);
}
if( oper->stack_slots_only(_globalNames) ) {
// should not call this:
fprintf(fp," virtual int constant_disp() const { return Type::OffsetBot; }");
} else if ( disp != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "constant_disp", disp);
}
} // end Memory Interface
// Check if it is a Conditional Interface
else if (oper->_interface->is_CondInterface() != nullptr) {
CondInterface *cInterface = oper->_interface->is_CondInterface();
const char *equal = cInterface->_equal;
if( equal != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "equal", equal);
}
const char *not_equal = cInterface->_not_equal;
if( not_equal != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "not_equal", not_equal);
}
const char *less = cInterface->_less;
if( less != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "less", less);
}
const char *greater_equal = cInterface->_greater_equal;
if( greater_equal != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "greater_equal", greater_equal);
}
const char *less_equal = cInterface->_less_equal;
if( less_equal != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "less_equal", less_equal);
}
const char *greater = cInterface->_greater;
if( greater != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "greater", greater);
}
const char *overflow = cInterface->_overflow;
if( overflow != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "overflow", overflow);
}
const char *no_overflow = cInterface->_no_overflow;
if( no_overflow != nullptr ) {
define_oper_interface(fp, *oper, _globalNames, "no_overflow", no_overflow);
}
} // end Conditional Interface
// Check if it is a Constant Interface
else if (oper->_interface->is_ConstInterface() != nullptr ) {
assert( oper->num_consts(_globalNames) == 1,
"Must have one constant when using CONST_INTER encoding");
if (!strcmp(oper->ideal_type(_globalNames), "ConI")) {
// Access the locally stored constant
fprintf(fp," virtual intptr_t constant() const {");
fprintf(fp, " return (intptr_t)_c0;");
fprintf(fp," }\n");
}
else if (!strcmp(oper->ideal_type(_globalNames), "ConP")) {
// Access the locally stored constant
fprintf(fp," virtual intptr_t constant() const {");
fprintf(fp, " return _c0->get_con();");
fprintf(fp, " }\n");
// Generate query to determine if this pointer is an oop
fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");
fprintf(fp, " return _c0->reloc();");
fprintf(fp, " }\n");
}
else if (!strcmp(oper->ideal_type(_globalNames), "ConN")) {
// Access the locally stored constant
fprintf(fp," virtual intptr_t constant() const {");
fprintf(fp, " return _c0->get_ptrtype()->get_con();");
fprintf(fp, " }\n");
// Generate query to determine if this pointer is an oop
fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");
fprintf(fp, " return _c0->get_ptrtype()->reloc();");
fprintf(fp, " }\n");
}
else if (!strcmp(oper->ideal_type(_globalNames), "ConNKlass")) {
// Access the locally stored constant
fprintf(fp," virtual intptr_t constant() const {");
fprintf(fp, " return _c0->get_ptrtype()->get_con();");
fprintf(fp, " }\n");
// Generate query to determine if this pointer is an oop
fprintf(fp," virtual relocInfo::relocType constant_reloc() const {");
fprintf(fp, " return _c0->get_ptrtype()->reloc();");
fprintf(fp, " }\n");
}
else if (!strcmp(oper->ideal_type(_globalNames), "ConL")) {
fprintf(fp," virtual intptr_t constant() const {");
// We don't support addressing modes with > 4Gig offsets.
// Truncate to int.
fprintf(fp, " return (intptr_t)_c0;");
fprintf(fp, " }\n");
fprintf(fp," virtual jlong constantL() const {");
fprintf(fp, " return _c0;");
fprintf(fp, " }\n");
}
else if (!strcmp(oper->ideal_type(_globalNames), "ConH")) {
fprintf(fp," virtual intptr_t constant() const {");
fprintf(fp, " ShouldNotReachHere(); return 0; ");
fprintf(fp, " }\n");
fprintf(fp," virtual jshort constantH() const {");
fprintf(fp, " return (jshort)_c0;");
fprintf(fp, " }\n");
}
else if (!strcmp(oper->ideal_type(_globalNames), "ConF")) {
fprintf(fp," virtual intptr_t constant() const {");
fprintf(fp, " ShouldNotReachHere(); return 0; ");
fprintf(fp, " }\n");
fprintf(fp," virtual jfloat constantF() const {");
fprintf(fp, " return (jfloat)_c0;");
fprintf(fp, " }\n");
}
else if (!strcmp(oper->ideal_type(_globalNames), "ConD")) {
fprintf(fp," virtual intptr_t constant() const {");
fprintf(fp, " ShouldNotReachHere(); return 0; ");
fprintf(fp, " }\n");
fprintf(fp," virtual jdouble constantD() const {");
fprintf(fp, " return _c0;");
fprintf(fp, " }\n");
}
}
else if (oper->_interface->is_RegInterface() != nullptr) {
// make sure that a fixed format string isn't used for an
// operand which might be assigned to multiple registers.
// Otherwise the opto assembly output could be misleading.
if (oper->_format->_strings.count() != 0 && !oper->is_bound_register()) {
syntax_err(oper->_linenum,
"Only bound registers can have fixed formats: %s\n",
oper->_ident);
}
}
else {
assert( false, "ShouldNotReachHere();");
}
}
fprintf(fp,"\n");
// // Currently all XXXOper::hash() methods are identical (990820)
// declare_hash(fp);
// // Currently all XXXOper::Cmp() methods are identical (990820)
// declare_cmp(fp);
// Do not place dump_spec() and Name() into PRODUCT code
// int_format and ext_format are not needed in PRODUCT code either
fprintf(fp, "#ifndef PRODUCT\n");
// Declare int_format() and ext_format()
gen_oper_format(fp, _globalNames, *oper);
// Machine independent print functionality for debugging
// IF we have constants, create a dump_spec function for the derived class
//
// (1) virtual void dump_spec() const {
// (2) st->print("#%d", _c#); // Constant != ConP
// OR _c#->dump_on(st); // Type ConP
// ...
// (3) }
uint num_consts = oper->num_consts(_globalNames);
if( num_consts > 0 ) {
// line (1)
fprintf(fp, " virtual void dump_spec(outputStream *st) const {\n");
// generate format string for st->print
// Iterate over the component list & spit out the right thing
uint i = 0;
const char *type = oper->ideal_type(_globalNames);
Component *comp;
oper->_components.reset();
if ((comp = oper->_components.iter()) == nullptr) {
assert(num_consts == 1, "Bad component list detected.\n");
i = dump_spec_constant( fp, type, i, oper );
// Check that type actually matched
assert( i != 0, "Non-constant operand lacks component list.");
} // end if null
else {
// line (2)
// dump all components
oper->_components.reset();
while((comp = oper->_components.iter()) != nullptr) {
type = comp->base_type(_globalNames);
i = dump_spec_constant( fp, type, i, nullptr );
}
}
// finish line (3)
fprintf(fp," }\n");
}
fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",
oper->_ident);
fprintf(fp,"#endif\n");
// Close definition of this XxxMachOper
fprintf(fp,"};\n");
}
// Generate Machine Classes for each instruction defined in AD file
fprintf(fp,"\n");
fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n");
declare_pipe_classes(fp);
// Generate Machine Classes for each instruction defined in AD file
fprintf(fp,"\n");
fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n");
_instructions.reset();
InstructForm *instr;
for( ; (instr = (InstructForm*)_instructions.iter()) != nullptr; ) {
// Ensure this is a machine-world instruction
if ( instr->ideal_only() ) continue;
// Build class definition for this instruction
fprintf(fp,"\n");
fprintf(fp,"class %sNode : public %s { \n",
instr->_ident, instr->mach_base_class(_globalNames) );
fprintf(fp,"private:\n");
fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() );
if ( instr->is_ideal_jump() ) {
fprintf(fp, " GrowableArray<Label*> _index2label;\n");
}
fprintf(fp, "public:\n");
Attribute *att = instr->_attribs;
// Fields of the node specified in the ad file.
while (att != nullptr) {
if (strncmp(att->_ident, "ins_field_", 10) == 0) {
const char *field_name = att->_ident+10;
const char *field_type = att->_val;
fprintf(fp, " %s _%s;\n", field_type, field_name);
}
att = (Attribute *)att->_next;
}
fprintf(fp," MachOper *opnd_array(uint operand_index) const {\n");
fprintf(fp," assert(operand_index < _num_opnds, \"invalid _opnd_array index\");\n");
fprintf(fp," return _opnd_array[operand_index];\n");
fprintf(fp," }\n");
fprintf(fp," void set_opnd_array(uint operand_index, MachOper *operand) {\n");
fprintf(fp," assert(operand_index < _num_opnds, \"invalid _opnd_array index\");\n");
fprintf(fp," _opnd_array[operand_index] = operand;\n");
fprintf(fp," }\n");
fprintf(fp," virtual uint rule() const { return %s_rule; }\n",
instr->_ident);
fprintf(fp,"private:\n");
if ( instr->is_ideal_jump() ) {
fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n");
fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);\n");
fprintf(fp," }\n");
}
if( can_cisc_spill() && (instr->cisc_spill_alternate() != nullptr) ) {
fprintf(fp," const RegMask *_cisc_RegMask;\n");
}
out_RegMask(fp); // output register mask
// If this instruction contains a labelOper
// Declare Node::methods that set operand Label's contents
int label_position = instr->label_position();
if( label_position != -1 ) {
// Set/Save the label, stored in labelOper::_branch_label
fprintf(fp," virtual void label_set( Label* label, uint block_num );\n");
fprintf(fp," virtual void save_label( Label** label, uint* block_num );\n");
}
// If this instruction contains a methodOper
// Declare Node::methods that set operand method's contents
int method_position = instr->method_position();
if( method_position != -1 ) {
// Set the address method, stored in methodOper::_method
fprintf(fp," virtual void method_set( intptr_t method );\n");
}
// virtual functions for attributes
//
// Each instruction attribute results in a virtual call of same name.
// The ins_cost is not handled here.
Attribute *attr = instr->_attribs;
Attribute *avoid_back_to_back_attr = nullptr;
while (attr != nullptr) {
if (strcmp (attr->_ident, "ins_is_TrapBasedCheckNode") == 0) {
fprintf(fp, " virtual bool is_TrapBasedCheckNode() const { return %s; }\n", attr->_val);
} else if (strcmp (attr->_ident, "ins_is_late_expanded_null_check_candidate") == 0) {
fprintf(fp, " virtual bool is_late_expanded_null_check_candidate() const { return %s; }\n", attr->_val);
} else if (strcmp (attr->_ident, "ins_cost") != 0 &&
strncmp(attr->_ident, "ins_field_", 10) != 0 &&
// Must match function in node.hpp: return type bool, no prefix "ins_".
strcmp (attr->_ident, "ins_is_TrapBasedCheckNode") != 0 &&
strcmp (attr->_ident, "ins_short_branch") != 0) {
fprintf(fp, " virtual int %s() const { return %s; }\n", attr->_ident, attr->_val);
}
if (strcmp(attr->_ident, "ins_avoid_back_to_back") == 0) {
avoid_back_to_back_attr = attr;
}
attr = (Attribute *)attr->_next;
}
// virtual functions for encode and format
// Virtual function for evaluating the constant.
if (instr->is_mach_constant()) {
fprintf(fp," virtual void eval_constant(Compile* C);\n");
}
// Output the opcode function and the encode function here using the
// encoding class information in the _insencode slot.
if ( instr->_insencode ) {
if (instr->postalloc_expands()) {
fprintf(fp," virtual bool requires_postalloc_expand() const { return true; }\n");
fprintf(fp," virtual void postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_);\n");
} else {
fprintf(fp," virtual void emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const;\n");
}
}
// virtual function for getting the size of an instruction
if ( instr->_size ) {
fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n");
}
// Return the top-level ideal opcode.
// Use MachNode::ideal_Opcode() for nodes based on MachNode class
// if the ideal_Opcode == Op_Node.
if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 ||
strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {
fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n",
instr->ideal_Opcode(_globalNames) );
}
if (instr->needs_constant_base() &&
!instr->is_mach_constant()) { // These inherit the function from MachConstantNode.
fprintf(fp," virtual uint mach_constant_base_node_input() const { ");
if (instr->is_ideal_call() != Form::invalid_type &&
instr->is_ideal_call() != Form::JAVA_LEAF) {
// MachConstantBase goes behind arguments, but before jvms.
fprintf(fp,"assert(tf() && tf()->domain(), \"\"); return tf()->domain()->cnt();");
} else {
fprintf(fp,"return req()-1;");
}
fprintf(fp," }\n");
}
// Allow machine-independent optimization, invert the sense of the IF test
if( instr->is_ideal_if() ) {
fprintf(fp," virtual void negate() { \n");
// Identify which operand contains the negate(able) ideal condition code
int idx = 0;
instr->_components.reset();
for( Component *comp; (comp = instr->_components.iter()) != nullptr; ) {
// Check that component is an operand
Form *form = (Form*)_globalNames[comp->_type];
OperandForm *opForm = form ? form->is_operand() : nullptr;
if( opForm == nullptr ) continue;
// Lookup the position of the operand in the instruction.
if( opForm->is_ideal_bool() ) {
idx = instr->operand_position(comp->_name, comp->_usedef);
assert( idx != NameList::Not_in_list, "Did not find component in list that contained it.");
break;
}
}
fprintf(fp," opnd_array(%d)->negate();\n", idx);
fprintf(fp," _prob = 1.0f - _prob;\n");
fprintf(fp," };\n");
}
// Identify which input register matches the input register.
uint matching_input = instr->two_address(_globalNames);
// Generate the method if it returns != 0 otherwise use MachNode::two_adr()
if( matching_input != 0 ) {
fprintf(fp," virtual uint two_adr() const ");
fprintf(fp,"{ return oper_input_base()");
for( uint i = 2; i <= matching_input; i++ )
fprintf(fp," + opnd_array(%d)->num_edges()",i-1);
fprintf(fp,"; }\n");
}
// Declare cisc_version, if applicable
// MachNode *cisc_version( int offset /* ,... */ );
instr->declare_cisc_version(*this, fp);
// If there is an explicit peephole rule, build it
if ( instr->peepholes() != nullptr ) {
fprintf(fp," virtual int peephole(Block* block, int block_index, PhaseCFG* cfg_, PhaseRegAlloc* ra_);\n");
}
// Output the declaration for number of relocation entries
if ( instr->reloc(_globalNames) != 0 ) {
fprintf(fp," virtual int reloc() const;\n");
}
if (instr->alignment() != 1) {
fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment());
fprintf(fp," virtual int compute_padding(int current_offset) const;\n");
}
// Starting point for inputs matcher wants.
// Use MachNode::oper_input_base() for nodes based on MachNode class
// if the base == 1.
if ( instr->oper_input_base(_globalNames) != 1 ||
strcmp("MachNode", instr->mach_base_class(_globalNames)) != 0 ) {
fprintf(fp," virtual uint oper_input_base() const { return %d; }\n",
instr->oper_input_base(_globalNames));
}
// Make the constructor and following methods 'public:'
fprintf(fp,"public:\n");
// Constructor
if ( instr->is_ideal_jump() ) {
fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident);
} else {
fprintf(fp," %sNode() { ", instr->_ident);
if( can_cisc_spill() && (instr->cisc_spill_alternate() != nullptr) ) {
fprintf(fp,"_cisc_RegMask = nullptr; ");
}
}
fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds());
bool node_flags_set = false;
// flag: if this instruction matches an ideal 'Copy*' node
if ( instr->is_ideal_copy() != 0 ) {
fprintf(fp,"init_flags(Flag_is_Copy");
node_flags_set = true;
}
// Is an instruction is a constant? If so, get its type
Form::DataType data_type;
const char *opType = nullptr;
const char *result = nullptr;
data_type = instr->is_chain_of_constant(_globalNames, opType, result);
// Check if this instruction is a constant
if ( data_type != Form::none ) {
if ( node_flags_set ) {
fprintf(fp," | Flag_is_Con");
} else {
fprintf(fp,"init_flags(Flag_is_Con");
node_flags_set = true;
}
}
// flag: if this instruction is cisc alternate
if ( can_cisc_spill() && instr->is_cisc_alternate() ) {
if ( node_flags_set ) {
fprintf(fp," | Flag_is_cisc_alternate");
} else {
fprintf(fp,"init_flags(Flag_is_cisc_alternate");
node_flags_set = true;
}
}
// flag: if this instruction has short branch form
if ( instr->has_short_branch_form() ) {
if ( node_flags_set ) {
fprintf(fp," | Flag_may_be_short_branch");
} else {
fprintf(fp,"init_flags(Flag_may_be_short_branch");
node_flags_set = true;
}
}
// flag: if this instruction should not be generated back to back.
if (avoid_back_to_back_attr != nullptr) {
if (node_flags_set) {
fprintf(fp," | (%s)", avoid_back_to_back_attr->_val);
} else {
fprintf(fp,"init_flags((%s)", avoid_back_to_back_attr->_val);
node_flags_set = true;
}
}
// Check if machine instructions that USE memory, but do not DEF memory,
// depend upon a node that defines memory in machine-independent graph.
if ( instr->needs_anti_dependence_check(_globalNames) ) {
if ( node_flags_set ) {
fprintf(fp," | Flag_needs_anti_dependence_check");
} else {
fprintf(fp,"init_flags(Flag_needs_anti_dependence_check");
node_flags_set = true;
}
}
// flag: if this instruction is implemented with a call
if ( instr->_has_call ) {
if ( node_flags_set ) {
fprintf(fp," | Flag_has_call");
} else {
fprintf(fp,"init_flags(Flag_has_call");
node_flags_set = true;
}
}
if ( node_flags_set ) {
fprintf(fp,"); ");
}
fprintf(fp,"}\n");
// size_of, used by base class's clone to obtain the correct size.
fprintf(fp," virtual uint size_of() const {");
fprintf(fp, " return sizeof(%sNode);", instr->_ident);
fprintf(fp, " }\n");
// Virtual methods which are only generated to override base class
if( instr->expands() || instr->needs_projections() ||
instr->has_temps() ||
instr->is_mach_constant() ||
instr->needs_constant_base() ||
(instr->_matrule != nullptr &&
instr->num_opnds() != instr->num_unique_opnds()) ) {
fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list, Node* mem);\n");
}
if (instr->is_pinned(_globalNames)) {
fprintf(fp," virtual bool pinned() const { return ");
if (instr->is_parm(_globalNames)) {
fprintf(fp,"_in[0]->pinned();");
} else {
fprintf(fp,"true;");
}
fprintf(fp," }\n");
}
if (instr->is_projection(_globalNames)) {
fprintf(fp," virtual const Node *is_block_proj() const { return this; }\n");
}
if ( instr->num_post_match_opnds() != 0
|| instr->is_chain_of_constant(_globalNames) ) {
fprintf(fp," friend MachNode *State::MachNodeGenerator(int opcode);\n");
}
if ( instr->rematerialize(_globalNames, get_registers()) ) {
fprintf(fp," // Rematerialize %s\n", instr->_ident);
}
// Declare short branch methods, if applicable
instr->declare_short_branch_methods(fp);
// See if there is an "ins_pipe" declaration for this instruction
if (instr->_ins_pipe) {
fprintf(fp," static const Pipeline *pipeline_class();\n");
fprintf(fp," virtual const Pipeline *pipeline() const;\n");
}
// Generate virtual function for MachNodeX::bottom_type when necessary
//
// Note on accuracy: Pointer-types of machine nodes need to be accurate,
// or else alias analysis on the matched graph may produce bad code.
// Moreover, the aliasing decisions made on machine-node graph must be
// no less accurate than those made on the ideal graph, or else the graph
// may fail to schedule. (Reason: Memory ops which are reordered in
// the ideal graph might look interdependent in the machine graph,
// thereby removing degrees of scheduling freedom that the optimizer
// assumed would be available.)
//
// %%% We should handle many of these cases with an explicit ADL clause:
// instruct foo() %{ ... bottom_type(TypeRawPtr::BOTTOM); ... %}
if( data_type != Form::none ) {
// A constant's bottom_type returns a Type containing its constant value
// !!!!!
// Convert all ints, floats, ... to machine-independent TypeXs
// as is done for pointers
//
// Construct appropriate constant type containing the constant value.
fprintf(fp," virtual const class Type *bottom_type() const {\n");
switch( data_type ) {
case Form::idealI:
fprintf(fp," return TypeInt::make(opnd_array(1)->constant());\n");
break;
case Form::idealP:
case Form::idealN:
case Form::idealNKlass:
fprintf(fp," return opnd_array(1)->type();\n");
break;
case Form::idealD:
fprintf(fp," return TypeD::make(opnd_array(1)->constantD());\n");
break;
case Form::idealH:
fprintf(fp," return TypeH::make(opnd_array(1)->constantH());\n");
break;
case Form::idealF:
fprintf(fp," return TypeF::make(opnd_array(1)->constantF());\n");
break;
case Form::idealL:
fprintf(fp," return TypeLong::make(opnd_array(1)->constantL());\n");
break;
default:
assert( false, "Unimplemented()" );
break;
}
fprintf(fp," };\n");
}
/* else if ( instr->_matrule && instr->_matrule->_rChild &&
( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
|| strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
// !!!!! !!!!!
// Provide explicit bottom type for conversions to int
// On Intel the result operand is a stackSlot, untyped.
fprintf(fp," virtual const class Type *bottom_type() const {");
fprintf(fp, " return TypeInt::INT;");
fprintf(fp, " };\n");
}*/
else if( instr->is_ideal_copy() &&
!strcmp(instr->_matrule->_lChild->_opType,"stackSlotP") ) {
// !!!!!
// Special hack for ideal Copy of pointer. Bottom type is oop or not depending on input.
fprintf(fp," const Type *bottom_type() const { return in(1)->bottom_type(); } // Copy?\n");
}
else if( instr->is_ideal_loadPC() ) {
// LoadPCNode provides the return address of a call to native code.
// Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM
// since it is a pointer to an internal VM location and must have a zero offset.
// Allocation detects derived pointers, in part, by their non-zero offsets.
fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // LoadPC?\n");
}
else if( instr->is_ideal_box() ) {
// BoxNode provides the address of a stack slot.
// Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM
// This prevents raise_above_anti_dependences from complaining. It will
// complain if it sees that the pointer base is TypePtr::BOTTOM since
// it doesn't understand what that might alias.
fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // Box?\n");
}
else if (instr->_matrule && instr->_matrule->_rChild &&
(!strcmp(instr->_matrule->_rChild->_opType,"CMoveP") || !strcmp(instr->_matrule->_rChild->_opType,"CMoveN")) ) {
int offset = 1;
// Special special hack to see if the Cmp? has been incorporated in the conditional move
MatchNode *rl = instr->_matrule->_rChild->_lChild;
if (rl && !strcmp(rl->_opType, "Binary") && rl->_rChild && strncmp(rl->_rChild->_opType, "Cmp", 3) == 0) {
offset = 2;
fprintf(fp," const Type *bottom_type() const { if (req() == 3) return in(2)->bottom_type();\n\tconst Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // %s\n",
offset, offset+1, offset+1, instr->_matrule->_rChild->_opType);
} else {
// Special hack for ideal CMove; ideal type depends on inputs
fprintf(fp," const Type *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // %s\n",
offset, offset+1, offset+1, instr->_matrule->_rChild->_opType);
}
}
else if (instr->is_tls_instruction()) {
// Special hack for tlsLoadP
fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n");
}
else if ( instr->is_ideal_if() ) {
fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n");
}
else if ( instr->is_ideal_membar() ) {
fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n");
}
// Check where 'ideal_type' must be customized
/*
if ( instr->_matrule && instr->_matrule->_rChild &&
( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
|| strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n");
}*/
// Analyze machine instructions that either USE or DEF memory.
int memory_operand = instr->memory_operand(_globalNames);
if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {
if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) {
fprintf(fp," virtual const TypePtr *adr_type() const;\n");
}
fprintf(fp," virtual const MachOper *memory_operand() const;\n");
}
fprintf(fp, "#ifndef PRODUCT\n");
// virtual function for generating the user's assembler output
gen_inst_format(fp, _globalNames,*instr);
// Machine independent print functionality for debugging
fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",
instr->_ident);
fprintf(fp, "#endif\n");
// Close definition of this XxxMachNode
fprintf(fp,"};\n");
};
}