Code Review for lateExp-2-hotspot

Prepared by:goetz on Tue Nov 12 17:15:47 CET 2013
Workspace:/net/usr.work/d045726/oJ/lateExp-2-hotspot
Compare against: http://hg.openjdk.java.net/ppc-aix-port/stage/hotspot
Compare against version:5660
Summary of changes: 622 lines changed: 580 ins; 0 del; 42 mod; 65650 unchg
Changeset: lateExp-2-hotspot.changeset
Author comments:

This change extends C2 by what we call lateExpand. LateExpand expands nodes after register allocation.

Some nodes can not be expanded during matching. E.g., register allocation might not be able to deal with the resulting pattern. To allow better scheduling in such cases, we introduce lateExpand which runs after register allocation. Whether and how nodes are expanded is specified in the ad-file. See block.cpp for a detailed documentation. We use this for some nodes on ppc, and extensively on ia64.

You can test this feature on sparc by applying this patch in addition to the webrev: Patch for sparc.ad file.

encode %{
  enc_class lateExpandIdiv_reg_reg(iRegI dst, iRegIsafe src1, iRegIsafe src2) %{
    MachNode *m1 = new (C) divI_reg_reg_SRANode();
    MachNode *m2 = new (C) divI_reg_reg_SRANode();
    MachNode *m3 = new (C) divI_reg_reg_SDIVXNode();

    m1->add_req(n_region, n_src1);
    m2->add_req(n_region, n_src2);
    m3->add_req(n_region, m1, m2);

    m1->_opnds[0] = _opnds[1]->clone(C);
    m1->_opnds[1] = _opnds[1]->clone(C);

    m2->_opnds[0] = _opnds[2]->clone(C);
    m2->_opnds[1] = _opnds[2]->clone(C);

    m3->_opnds[0] = _opnds[0]->clone(C);
    m3->_opnds[1] = _opnds[1]->clone(C);
    m3->_opnds[2] = _opnds[2]->clone(C);

    ra_->set1(m1->_idx, ra_->get_reg_first(n_src1));
    ra_->set1(m2->_idx, ra_->get_reg_first(n_src2));
    ra_->set1(m3->_idx, ra_->get_reg_first(this));

    nodes->push(m1);
    nodes->push(m2);
    nodes->push(m3);
  %}
%}

instruct divI_reg_reg_SRA(iRegIsafe dst) %{
  effect(USE_DEF dst);
  size(4);
  format %{ "SRA     $dst,0,$dst\n\t" %}
  ins_encode %{ __ sra($dst$$Register, 0, $dst$$Register); %}
  ins_pipe(ialu_reg_reg);
%}

instruct divI_reg_reg_SDIVX(iRegI dst, iRegIsafe src1, iRegIsafe src2) %{
  effect(DEF dst, USE src1, USE src2);
  size(4);
  format %{ "SDIVX   $src1,$src2,$dst\n\t" %}
  ins_encode %{ __ sdivx($dst$$Register, 0, $dst$$Register); %}
  ins_pipe(sdiv_reg_reg);
%}

instruct divI_reg_reg_Ex(iRegI dst, iRegIsafe src1, iRegIsafe src2) %{
  match(Set dst (DivI src1 src2));
  predicate(UseNewCode);
  ins_cost((2+71)*DEFAULT_COST);
  format %{ "SRA     $src2,0,$src2\n\t"
            "SRA     $src1,0,$src1\n\t"
            "SDIVX   $src1,$src2,$dst" %}
  lateExpand( lateExpandIdiv_reg_reg(src1, src2, dst) );
%}

Adlc will generate the following code:

class divI_reg_reg_ExNode : public MachNode { 
  // ...
  virtual bool           requires_late_expand() const { return true; }
  virtual void           lateExpand(GrowableArray  *nodes, PhaseRegAlloc *ra_);
  // ...
};


void  divI_reg_reg_ExNode::lateExpand(GrowableArray  *nodes, PhaseRegAlloc *ra_) {
  // Start at oper_input_base() and count operands
  unsigned idx0 = 1;
  unsigned idx1 = 1; 	// src1
  unsigned idx2 = idx1 + opnd_array(1)->num_edges(); 	// src2
  // Access to ins and operands for late expand.
  unsigned idx_dst   = idx1; 	// iRegI, 	src1
  unsigned idx_src1  = idx2; 	// iRegIsafe, 	src2
  unsigned idx_src2  = idx0; 	// iRegIsafe, 	dst
  Node    *n_region  = lookup(0);
  Node    *n_dst     = lookup(idx_dst);
  Node    *n_src1    = lookup(idx_src1);
  Node    *n_src2    = lookup(idx_src2);
  iRegIOper *op_dst = (iRegIOper *)opnd_array(1);
  iRegIsafeOper *op_src1 = (iRegIsafeOper *)opnd_array(2);
  iRegIsafeOper *op_src2 = (iRegIsafeOper *)opnd_array(0);
  Compile *C = ra_->C;
  {
#line 7461 "/net/usr.work/d045726/oJ/lateExp-hotspot/src/cpu/sparc/vm/sparc.ad"

    MachNode *m1 = new (C) divI_reg_reg_SRANode();
    MachNode *m2 = new (C) divI_reg_reg_SRANode();
    MachNode *m3 = new (C) divI_reg_reg_SDIVXNode();

    m1->add_req(n_region, n_src1);
    m2->add_req(n_region, n_src2);
    m3->add_req(n_region, m1, m2);

    m1->_opnds[0] = _opnds[1]->clone(C);
    m1->_opnds[1] = _opnds[1]->clone(C);

    m2->_opnds[0] = _opnds[2]->clone(C);
    m2->_opnds[1] = _opnds[2]->clone(C);

    m3->_opnds[0] = _opnds[0]->clone(C);
    m3->_opnds[1] = _opnds[1]->clone(C);
    m3->_opnds[2] = _opnds[2]->clone(C);

    ra_->set1(m1->_idx, ra_->get_reg_first(n_src1));
    ra_->set1(m2->_idx, ra_->get_reg_first(n_src2));
    ra_->set1(m3->_idx, ra_->get_reg_first(this));

    nodes->push(m1);
    nodes->push(m2);
    nodes->push(m3);
  
#line 11201 "../generated/adfiles/ad_sparc.cpp"
  }
}
Legend: Modified file
Deleted file
New file

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/cpu/sparc/vm/sparc.ad

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
8 lines changed: 8 ins; 0 del; 0 mod; 10956 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/cpu/x86/vm/x86_32.ad

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
8 lines changed: 8 ins; 0 del; 0 mod; 13299 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/cpu/x86/vm/x86_64.ad

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
8 lines changed: 8 ins; 0 del; 0 mod; 11810 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/adlc/adlparse.cpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
154 lines changed: 148 ins; 0 del; 6 mod; 5074 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/adlc/adlparse.hpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
3 lines changed: 2 ins; 0 del; 1 mod; 288 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/adlc/archDesc.hpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
2 lines changed: 2 ins; 0 del; 0 mod; 404 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/adlc/formssel.cpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
35 lines changed: 7 ins; 0 del; 28 mod; 4202 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/adlc/formssel.hpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
3 lines changed: 3 ins; 0 del; 0 mod; 1086 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/adlc/output_c.cpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
119 lines changed: 116 ins; 0 del; 3 mod; 4253 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/adlc/output_h.cpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
6 lines changed: 5 ins; 0 del; 1 mod; 2254 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/opto/block.cpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
232 lines changed: 231 ins; 0 del; 1 mod; 1463 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/opto/block.hpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
6 lines changed: 5 ins; 0 del; 1 mod; 875 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/opto/c2_globals.hpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
2 lines changed: 2 ins; 0 del; 0 mod; 657 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/opto/compile.cpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
5 lines changed: 5 ins; 0 del; 0 mod; 3886 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/opto/machnode.hpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
17 lines changed: 16 ins; 0 del; 1 mod; 920 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/opto/matcher.hpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
3 lines changed: 3 ins; 0 del; 0 mod; 494 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/opto/node.cpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
3 lines changed: 3 ins; 0 del; 0 mod; 2133 unchg

Cdiffs Udiffs Wdiffs Sdiffs Frames Old New ----- Raw src/share/vm/opto/node.hpp

rev 5661 : 8003854: PPC64 (part 115): Introduce lateExpand that expands nodes after register allocation.
8 lines changed: 8 ins; 0 del; 0 mod; 1596 unchg

This code review page was prepared using /sapmnt/home1/d045726/bin/webrev.ksh (vers 24.0-hg+jbs).