8318959: C2: define MachNode::fill_new_machnode() statically

Reviewed-by: kvn, thartmann
This commit is contained in:
Roberto Castañeda Lozano 2023-11-06 09:08:56 +00:00
parent c146685ca9
commit 377138c7b5
4 changed files with 28 additions and 52 deletions

View File

@ -257,7 +257,7 @@ public:
void set_cisc_reg_mask_name(const char *rm_name) { _cisc_reg_mask_name = rm_name; }
// Output cisc-method prototypes and method bodies
void declare_cisc_version(ArchDesc &AD, FILE *fp_cpp);
bool define_cisc_version (ArchDesc &AD, FILE *fp_cpp);
void define_cisc_version(ArchDesc& AD, FILE* fp_cpp);
bool check_branch_variant(ArchDesc &AD, InstructForm *short_branch);
@ -273,7 +273,7 @@ public:
bool has_short_branch_form() { return _short_branch_form != nullptr; }
// Output short branch prototypes and method bodies
void declare_short_branch_methods(FILE *fp_cpp);
bool define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp);
void define_short_branch_methods(ArchDesc& AD, FILE* fp_cpp);
uint alignment() { return _alignment; }
void set_alignment(uint val) { _alignment = val; }

View File

@ -3099,42 +3099,6 @@ void ArchDesc::define_oper_interface(FILE *fp, OperandForm &oper, FormDict &glob
}
}
//
// Construct the method to copy _idx, inputs and operands to new node.
static void define_fill_new_machnode(bool used, FILE *fp_cpp) {
fprintf(fp_cpp, "\n");
fprintf(fp_cpp, "// Copy _idx, inputs and operands to new node\n");
fprintf(fp_cpp, "void MachNode::fill_new_machnode(MachNode* node) const {\n");
if( !used ) {
fprintf(fp_cpp, " // This architecture does not have cisc or short branch instructions\n");
fprintf(fp_cpp, " ShouldNotCallThis();\n");
fprintf(fp_cpp, "}\n");
} else {
// New node must use same node index for access through allocator's tables
fprintf(fp_cpp, " // New node must use same node index\n");
fprintf(fp_cpp, " node->set_idx( _idx );\n");
// Copy machine-independent inputs
fprintf(fp_cpp, " // Copy machine-independent inputs\n");
fprintf(fp_cpp, " for( uint j = 0; j < req(); j++ ) {\n");
fprintf(fp_cpp, " node->add_req(in(j));\n");
fprintf(fp_cpp, " }\n");
// Copy machine operands to new MachNode
fprintf(fp_cpp, " // Copy my operands, except for cisc position\n");
fprintf(fp_cpp, " int nopnds = num_opnds();\n");
fprintf(fp_cpp, " assert( node->num_opnds() == (uint)nopnds, \"Must have same number of operands\");\n");
fprintf(fp_cpp, " MachOper **to = node->_opnds;\n");
fprintf(fp_cpp, " for( int i = 0; i < nopnds; i++ ) {\n");
fprintf(fp_cpp, " if( i != cisc_operand() ) \n");
fprintf(fp_cpp, " to[i] = _opnds[i]->clone();\n");
fprintf(fp_cpp, " }\n");
fprintf(fp_cpp, " // Do not increment node index counter, since node reuses my index\n");
fprintf(fp_cpp, " Compile* C = Compile::current();\n");
fprintf(fp_cpp, " C->set_unique(C->unique() - 1);\n");
fprintf(fp_cpp, "}\n");
}
fprintf(fp_cpp, "\n");
}
//------------------------------defineClasses----------------------------------
// Define members of MachNode and MachOper classes based on
// operand and instruction lists
@ -3230,7 +3194,6 @@ void ArchDesc::defineClasses(FILE *fp) {
defineOut_RegMask(_CPP_MISC_file._fp, instr->_ident, reg_mask(*instr));
}
bool used = false;
// Output the definitions for expand rules & peephole rules
_instructions.reset();
for( ; (instr = (InstructForm*)_instructions.iter()) != nullptr; ) {
@ -3249,15 +3212,12 @@ void ArchDesc::defineClasses(FILE *fp) {
definePeephole(_CPP_PEEPHOLE_file._fp, instr);
// Output code to convert to the cisc version, if applicable
used |= instr->define_cisc_version(*this, fp);
instr->define_cisc_version(*this, fp);
// Output code to convert to the short branch version, if applicable
used |= instr->define_short_branch_methods(*this, fp);
instr->define_short_branch_methods(*this, fp);
}
// Construct the method called by cisc_version() to copy inputs and operands.
define_fill_new_machnode(used, fp);
// Output the definitions for labels
_instructions.reset();
while( (instr = (InstructForm*)_instructions.iter()) != nullptr ) {
@ -4074,7 +4034,7 @@ void InstructForm::declare_cisc_version(ArchDesc &AD, FILE *fp_hpp) {
//---------------------------define_cisc_version-------------------------------
// Build CISC version of this instruction
bool InstructForm::define_cisc_version(ArchDesc &AD, FILE *fp_cpp) {
void InstructForm::define_cisc_version(ArchDesc& AD, FILE* fp_cpp) {
InstructForm *inst_cisc = this->cisc_spill_alternate();
if( AD.can_cisc_spill() && (inst_cisc != nullptr) ) {
const char *name = inst_cisc->_ident;
@ -4120,9 +4080,7 @@ bool InstructForm::define_cisc_version(ArchDesc &AD, FILE *fp_cpp) {
fprintf(fp_cpp, " return node;\n");
fprintf(fp_cpp, "}\n");
fprintf(fp_cpp, "\n");
return true;
}
return false;
}
//---------------------------declare_short_branch_methods----------------------
@ -4135,7 +4093,7 @@ void InstructForm::declare_short_branch_methods(FILE *fp_hpp) {
//---------------------------define_short_branch_methods-----------------------
// Build definitions for short branch methods
bool InstructForm::define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp) {
void InstructForm::define_short_branch_methods(ArchDesc& AD, FILE* fp_cpp) {
if (has_short_branch_form()) {
InstructForm *short_branch = short_branch_form();
const char *name = short_branch->_ident;
@ -4164,9 +4122,7 @@ bool InstructForm::define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp) {
fprintf(fp_cpp, " return node;\n");
fprintf(fp_cpp, "}\n");
fprintf(fp_cpp,"\n");
return true;
}
return false;
}

View File

@ -183,6 +183,27 @@ bool MachNode::cmp( const Node &node ) const {
return true; // match
}
void MachNode::fill_new_machnode(MachNode* node) const {
// New node must use same node index
node->set_idx(_idx);
// Copy machine-independent inputs
for (uint j = 0; j < req(); j++) {
node->add_req(in(j));
}
// Copy my operands, except for cisc position
int nopnds = num_opnds();
assert(node->num_opnds() == (uint)nopnds, "Must have same number of operands");
MachOper** to = node->_opnds;
for (int i = 0; i < nopnds; i++) {
if (i != cisc_operand()) {
to[i] = _opnds[i]->clone();
}
}
// Do not increment node index counter, since node reuses my index
Compile* C = Compile::current();
C->set_unique(C->unique() - 1);
}
// Return an equivalent instruction using memory for cisc_operand position
MachNode *MachNode::cisc_version(int offset) {
ShouldNotCallThis();

View File

@ -229,9 +229,8 @@ public:
uint8_t barrier_data() const { return _barrier; }
void set_barrier_data(uint8_t data) { _barrier = data; }
// Copy inputs and operands to new node of instruction.
// Copy index, inputs, and operands to a new version of the instruction.
// Called from cisc_version() and short_branch_version().
// !!!! The method's body is defined in ad_<arch>.cpp file.
void fill_new_machnode(MachNode *n) const;
// Return an equivalent instruction using memory for cisc_operand position