You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by va...@apache.org on 2006/11/21 07:23:40 UTC

svn commit: r477525 [1/2] - in /harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf: ./ include/

Author: varlax
Date: Mon Nov 20 22:23:40 2006
New Revision: 477525

URL: http://svn.apache.org/viewvc?view=rev&rev=477525
Log:
Applied HARMONY-2207 [drlvm][ipf] auto constants folding/propagation and few minor low level optimizations.

Modified:
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeGenerator.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeLayouter.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEmitter.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEncoder.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfInstCodeSelector.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfIrPrinter.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfOpndManager.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfType.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfVerifier.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/include/IpfCfg.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/include/IpfEmitter.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/include/IpfOpndManager.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/include/IpfType.h

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeGenerator.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeGenerator.cpp?view=diff&rev=477525&r1=477524&r2=477525
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeGenerator.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeGenerator.cpp Mon Nov 20 22:23:40 2006
@@ -33,7 +33,7 @@
 #include "IpfPrologEpilogGenerator.h"
 #include "IpfRuntimeSupport.h"
 #include "IpfCfgVerifier.h"
-#include "IpfInstrumentator.h"
+//#include "IpfInstrumentator.h"
 
 namespace Jitrino {
 namespace IPF {

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeLayouter.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeLayouter.cpp?view=diff&rev=477525&r1=477524&r2=477525
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeLayouter.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfCodeLayouter.cpp Mon Nov 20 22:23:40 2006
@@ -537,7 +537,7 @@
     // Add branch to through edge target
     Opnd    *p0         = cfg.getOpndManager()->getP0();
     NodeRef *targetNode = cfg.getOpndManager()->newNodeRef(target);
-    node->addInst(new(mm) Inst(mm, INST_BR, CMPLT_WH_SPTK, CMPLT_PH_FEW, p0, targetNode));
+    node->addInst(new(mm) Inst(mm, INST_BR, CMPLT_WH_SPTK, CMPLT_PH_MANY, p0, targetNode));
     
     throughEdge->setEdgeKind(EDGE_BRANCH);
     IPF_LOG << " branch on node" << target->getId() << " added" << endl;

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEmitter.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEmitter.cpp?view=diff&rev=477525&r1=477524&r2=477525
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEmitter.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEmitter.cpp Mon Nov 20 22:23:40 2006
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-                                                                                                            
+
 /**
  * @author Intel, Konstantin M. Anisimov, Igor V. Chebykin
  * @version $Revision$
@@ -43,24 +43,24 @@
     struct sigaction signal_action;
     struct ucontext * signal_ucontext;
     int saved_errno = errno;
-    
+
     if (sn==SIGILL && si->si_code==ILL_BREAK && si->si_imm==INST_BREAKPOINT_IMM_VALUE) {
         signal_ucontext = (struct ucontext *)_sc;
-    
+
         if ( (signal_ucontext->_u._mc.sc_ip & 0x03)==2 ) {
             signal_ucontext->_u._mc.sc_ip = (signal_ucontext->_u._mc.sc_ip & ~0x03) + 0x10;
         } else {
             signal_ucontext->_u._mc.sc_ip++;
         }
         //printf("-- sighandler() for signal %d, si_code %d, si_imm %x\n", sn, si->si_code, si->si_imm);
-    
+
         signal_action.sa_flags = SA_SIGINFO;
         signal_action.sa_sigaction = sighandler;
         if (sigaction(SIGILL, &signal_action, NULL)) {
             printf("Sigaction returned error = %d\n", errno);
         }
     }
-    
+
     errno = saved_errno;
     return;
 }
@@ -71,37 +71,161 @@
 namespace IPF {
 
 //============================================================================//
+const BundleDescription Bundle::BundleDesc[TEMPLATES_COUNT] = {
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_I), 0x0, 0x00 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_I), 0x4, 0x01 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_I), 0x2, 0x02 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_I), 0x6, 0x03 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_L) | IT_SLOT2(IT_X), 0x0, 0x04 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_L) | IT_SLOT2(IT_X), 0x4, 0x05 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_I), 0x0, 0x08 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_I), 0x4, 0x09 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_I), 0x1, 0x0a },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_I), 0x5, 0x0b },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_F) | IT_SLOT2(IT_I), 0x0, 0x0c },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_F) | IT_SLOT2(IT_I), 0x4, 0x0d },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_F), 0x0, 0x0e },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_F), 0x4, 0x0f },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_B), 0x0, 0x10 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_B), 0x4, 0x11 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_B) | IT_SLOT2(IT_B), 0x0, 0x12 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_B) | IT_SLOT2(IT_B), 0x4, 0x13 },
+    { IT_SLOT0(IT_B) | IT_SLOT1(IT_B) | IT_SLOT2(IT_B), 0x0, 0x16 },
+    { IT_SLOT0(IT_B) | IT_SLOT1(IT_B) | IT_SLOT2(IT_B), 0x4, 0x17 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_B), 0x0, 0x18 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_B), 0x4, 0x19 },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_F) | IT_SLOT2(IT_B), 0x0, 0x1c },
+    { IT_SLOT0(IT_M) | IT_SLOT1(IT_F) | IT_SLOT2(IT_B), 0x4, 0x1d }
+};
+
+//============================================================================//
+
+const char Emitter::Itanium2_DualIssueBundles[30][30] = {
+    1, 1, 1, 1, 0, 0, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MII, 0x00
+    1, 1, 1, 1, 0, 0, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MII, 0x01
+    1, 1, 1, 1, 0, 0, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MII, 0x02
+    1, 1, 1, 1, 0, 0, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MII, 0x03
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MLX, 0x04
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MLX, 0x05
+    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MMI, 0x08
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MMI, 0x09
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MMI, 0x0a
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MMI, 0x0b
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MFI, 0x0c
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MFI, 0x0d
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MMF, 0x0e
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, // MMF, 0x0f
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, 0, 1, 1, -1, -1, 1, 1, // MIB, 0x10
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, 0, 1, 1, -1, -1, 1, 1, // MIB, 0x11
+    0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, // MBB, 0x12
+    0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, // MBB, 0x13
+    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, // BBB, 0x16
+    0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, // BBB, 0x17
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, 0, 1, 1, -1, -1, 1, 1, // MMB, 0x18
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, 0, 1, 1, -1, -1, 1, 1, // MMB, 0x19
+    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, 0, 1, 1, -1, -1, 1, 1, // MFB, 0x1c
+    1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, 0, 1, 1, -1, -1, 1, 1  // MFB, 0x1d
+};
+
+//============================================================================//
+
+void Emitter::checkForDualIssueBundles() {
+    EmitterBb *bb;
+    Bundle *bundle1, *bundle2;
+    uint32 tmpl1, tmpl2;
+    bool header_printed = false;
+
+    for (int bbindex=0 ; bbindex<(int)bbs->size() ; bbindex++) {
+        bb = bbs->at(bbindex);
+        BundleVector & bundles = *(bb->bundles);
+        for (int bi=0, bii=bundles.size()-1 ; bi<bii ; ) {
+            bundle1 = bundles[bi];
+            bundle2 = bundles[bi+1];
+            tmpl1 = bundle1->getTmpl();
+            tmpl2 = bundle2->getTmpl();
+            if (!bundle1->hasStop() && Itanium2_DualIssueBundles[tmpl1][tmpl2]==0) {
+                if (!header_printed) {
+                    header_printed = true;
+                    clog << "CHECK_DUAL_ISSUE: Method:"
+                        << " bundles=" << codesize/IPF_BUNDLE_SIZE
+                        << "; SIG="
+                        << compilationinterface.getMethodToCompile()->getParentType()->getName()
+                        << "." << compilationinterface.getMethodToCompile()->getName()
+                        << compilationinterface.getMethodToCompile()->getSignatureString()
+                        << "\n";
+                }
+                clog << "CHECK_DUAL_ISSUE: bbindex=" << bbindex
+                    << ", node_id=" << bb->node->getId()
+                    << "; bi=" << bi
+                    << "; tmpl1=0x" << hex << tmpl1
+                    << "; tmpl2=0x" << tmpl2 << dec
+                    << "\n";
+
+                bi += 1;
+                continue;
+            } else if (Itanium2_DualIssueBundles[tmpl1][tmpl2] == -1) {
+                if (!header_printed) {
+                    header_printed = true;
+                    clog << "Method:"
+                        << " bundles=" << codesize/IPF_BUNDLE_SIZE
+                        << "; SIG="
+                        << compilationinterface.getMethodToCompile()->getParentType()->getName()
+                        << "." << compilationinterface.getMethodToCompile()->getName()
+                        << compilationinterface.getMethodToCompile()->getSignatureString()
+                        << "\n";
+                }
+                clog << "BAD templates: " << tmpl1 << ", " << tmpl2
+                    << "\n";
+            }
+
+            if (bundle2->hasStop()) {
+                bi += 1;
+                continue;
+            } else {
+                bi += 2;
+                continue;
+            }
+        }
+    }
+
+}
+
+//============================================================================//
 
 Bundle::Bundle(Cfg& cfg, uint32 itmp, Inst *i0, Inst *i1, Inst *i2) {
-    indxtmpl = itmp;   // !!! THis is not template, but index in Emitter::BundleDesc[] !!!
-    
+    indxtmpl = itmp;   // !!! THis is not template, but index in Bundle::BundleDesc[] !!!
+
     MemoryManager& mm          = cfg.getMM();
     OpndManager*   opndManager = cfg.getOpndManager();
-    
+
     // slot 0
     if( i0==NULL ) {
-        slot[0] = new(mm) Inst(INST_NOP, PR(0), IMM(INST_BREAKPOINT_IMM_VALUE));
+        slot[0] = new(mm) Inst(mm, INST_NOP, PR(0), IMM(INST_BREAKPOINT_IMM_VALUE));
     } else {
         slot[0] = i0;
     }
- 
+
     // slot 1
     if( i1==NULL ) {
-        slot[1] = new(mm) Inst(INST_NOP, PR(0), IMM(INST_BREAKPOINT_IMM_VALUE));
+        slot[1] = new(mm) Inst(mm, INST_NOP, PR(0), IMM(INST_BREAKPOINT_IMM_VALUE));
     } else {
         slot[1] = i1;
     }
- 
+
     // slot 2
     if( i2==NULL ) {
-        slot[2] = new(mm) Inst(INST_NOP, PR(0), IMM(INST_BREAKPOINT_IMM_VALUE));
+        slot[2] = new(mm) Inst(mm, INST_NOP, PR(0), IMM(INST_BREAKPOINT_IMM_VALUE));
     } else {
         slot[2] = i2;
     }
 }
 
-uint32   Bundle::getTmpl() { return Emitter::BundleDesc[indxtmpl].tmpl; };
-
 //============================================================================//
 void Bundle::emitBundleGeneral(void *whereToEmit) {
     uint64 * p  = (uint64 *)whereToEmit;
@@ -111,10 +235,10 @@
     p[1] = 0;
 
     p[0]  = getTmpl();
-    
+
     s = getSlotBits(0);
     p[0] |= s << 5;
-    
+
     s = getSlotBits(1);
     p[0] |= s << 46;
     p[1]  = s >> 18;
@@ -132,14 +256,14 @@
     p[1] = 0;
 
     p[0]  = itmp;
-    
+
     if (itmp==0x16 || itmp==0x17) {
         s = getSlotBitsBranch(0, bundletarget[0]);
     } else {
         s = getSlotBits(0);
     }
     p[0] |= s << 5;
-    
+
     if (itmp>=0x12 && itmp<=0x17) {
         s = getSlotBitsBranch(1, bundletarget[1]);
     } else {
@@ -165,10 +289,10 @@
     p[1] = 0;
 
     p[0]  = getTmpl();
-    
+
     s = getSlotBits(0);
     p[0] |= s << 5;
-    
+
     getSlotBitsExtended(s12, whereToEmit);
     p[0] |= s12[0] << 46;
     p[1]  = s12[0] >> 18;
@@ -207,37 +331,9 @@
 }
 
 //============================================================================//
-const BundleDescription Emitter::BundleDesc[TEMPLATES_COUNT] = {
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_I), 0x0, 0x00 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_I), 0x4, 0x01 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_I), 0x2, 0x02 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_I), 0x6, 0x03 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_L) | IT_SLOT2(IT_X), 0x0, 0x04 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_L) | IT_SLOT2(IT_X), 0x4, 0x05 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_I), 0x0, 0x08 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_I), 0x4, 0x09 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_I), 0x1, 0x0a },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_I), 0x5, 0x0b },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_F) | IT_SLOT2(IT_I), 0x0, 0x0c },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_F) | IT_SLOT2(IT_I), 0x4, 0x0d },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_F), 0x0, 0x0e },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_F), 0x4, 0x0f },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_B), 0x0, 0x10 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_I) | IT_SLOT2(IT_B), 0x4, 0x11 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_B) | IT_SLOT2(IT_B), 0x0, 0x12 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_B) | IT_SLOT2(IT_B), 0x4, 0x13 },
-    { IT_SLOT0(IT_B) | IT_SLOT1(IT_B) | IT_SLOT2(IT_B), 0x0, 0x16 },
-    { IT_SLOT0(IT_B) | IT_SLOT1(IT_B) | IT_SLOT2(IT_B), 0x4, 0x17 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_B), 0x0, 0x18 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_M) | IT_SLOT2(IT_B), 0x4, 0x19 },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_F) | IT_SLOT2(IT_B), 0x0, 0x1c },
-    { IT_SLOT0(IT_M) | IT_SLOT1(IT_F) | IT_SLOT2(IT_B), 0x4, 0x1d }
-};
-
-//============================================================================//
 EmitterBb::EmitterBb(Cfg & cfg, CompilationInterface & compilationinterface
-        , BbNode  * node_, bool _break4cafe, bool _nop4cafe) : 
-    node(node_), 
+        , BbNode  * node_, bool _break4cafe, bool _nop4cafe) :
+    node(node_),
     insts(node->getInsts())
 {
     MemoryManager& mm=cfg.getMM();
@@ -255,39 +351,39 @@
     if (!_break4cafe) {
         if (_nop4cafe) {
             bundles->addBundle(0x01
-                , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
-                , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
-                , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
+                , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
         }
     } else {
 #ifdef SIGILL_BREAK_ACTION_HANDLER
         if (ipfEnableSigillBreakActionHandler) {
             struct sigaction signal_action;
-            
+
             signal_action.sa_flags = SA_SIGINFO;
             signal_action.sa_sigaction = sighandler;
             if (sigaction(SIGILL, &signal_action, NULL)) {
                 printf("Sigaction returned error = %d\n", errno);
             }
-    
+
             bundles->addBundle(0x01
-                , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
-                , new(mm) Inst(INST_BREAK, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
-                , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
+                , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                , new(mm) Inst(mm, INST_BREAK, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
         } else {
             if (_nop4cafe) {
                 bundles->addBundle(0x01
-                    , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
-                    , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
-                    , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
+                    , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                    , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                    , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
             }
         }
 #else
         if (_nop4cafe) {
             bundles->addBundle(0x01
-                , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
-                , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
-                , new(mm) Inst(INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
+                , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
         }
 #endif
     }
@@ -295,28 +391,29 @@
 };
 
 //============================================================================//
-Emitter::Emitter(Cfg & cfg_, CompilationInterface & compilationinterface_) : 
+Emitter::Emitter(Cfg & cfg_, CompilationInterface & compilationinterface_) :
         mm(cfg_.getMM()),
         cfg(cfg_),
         compilationinterface(compilationinterface_)
     {
 
     removeUselessInst(cfg, compilationinterface);
-    
+    removeIgnoreTypeInst(cfg, compilationinterface);
+
     (new(mm) IpfVerifier(cfg, compilationinterface))->verifyMethod();
 
     bbs = new(mm) vectorbb;
     BbNode  * node = (BbNode *)cfg.getEnterNode();
     EmitterBb * bbdesc;
-    bool break4cafe = ipfEnableSigillBreakActionHandler 
+    bool break4cafe = ipfEnableSigillBreakActionHandler
                 && (ipfEnableAutoSigillBreak
                     || isIpfBreakMethod(compilationinterface.getMethodToCompile()));
-    bool nop4cafe = true;
+    bool nop4cafe = false;
 
     do {
         // for debugging
         // tricking(node->getInsts(), mm, cfg);
-        
+
         if (isIpfBreakBb(node->getId())) {
             bbdesc = new(mm) EmitterBb(cfg, compilationinterface, node, true, nop4cafe);
         } else {
@@ -326,7 +423,7 @@
         if (!ipfSigillBreakAllBB) break4cafe = false;
         nop4cafe = false;
     } while( (node = node->getLayoutSucc()) != NULL );
-    
+
 };
 
 //============================================================================//
@@ -334,19 +431,19 @@
     BbNode  * node = (BbNode *)cfg.getEnterNode();
     int methoduseless = 0;
     int methodafter = 0;
-    
+
     do {
         InstVector &insts = node->getInsts();
         int i;
-        
-        for( i=0 ; i < (int)insts.size() ; i++ ) {
+
+        for( i=0 ; i < (int)insts.size() ; ) {
             Inst *inst = insts[i];
             InstCode icode = inst->getInstCode();
+            OpndVector &opnds = inst->getOpnds();
 
             if (icode==INST_MOV) {
                 if (inst->getNumOpnd()==3) {
-                    OpndVector &opnds = inst->getOpnds();
-                    if (opnds[1]->isReg() && opnds[2]->isReg() 
+                    if (((opnds[1]->isGReg() && opnds[2]->isGReg()) || (opnds[1]->isFReg() && opnds[2]->isFReg()))
                             && opnds[1]->getValue()==opnds[2]->getValue()) {
                         IPF_LOG << "USELESS: " << IrPrinter::toString(inst) << "\n";
                         insts.erase(insts.begin() + i);
@@ -355,10 +452,8 @@
                     }
                 }
             }
-        
             if (icode==INST_ADD || icode==INST_ADDS || icode==INST_ADDL) {
                 if (inst->getNumOpnd()==4) {
-                    OpndVector &opnds = inst->getOpnds();
                     if (opnds[2]->getValue()==0
                             && opnds[1]->getValue()==opnds[3]->getValue()) {
                         IPF_LOG << "USELESS: " << IrPrinter::toString(inst) << "\n";
@@ -368,31 +463,62 @@
                     }
                 }
             }
+
+            i++;
         }
         methodafter += i;
     } while( (node = node->getLayoutSucc()) != NULL );
-    
+
     /* statistical data */
     if (0 && (methoduseless > 0)) {
         static int alluseless = 0;
         static int allafter = 0;
         alluseless += methoduseless;
-        IPF_LOG << "USELESS: method: " << methoduseless 
-            << "(" << (((float)methoduseless)/(methoduseless + methodafter)) << "%) instructions\n";
-        IPF_LOG << "USELESS: all: " << alluseless 
-            << "(" << (((float)alluseless)/(alluseless + allafter)) << "%) instructions\n";
+        allafter += methodafter;
+        if (methoduseless > 0) {
+            IPF_LOG << "USELESS: method: " << methoduseless
+                << "(" << (((float)methoduseless)/(methoduseless + methodafter))*100 << "%) instructions\n";
+            IPF_LOG << "USELESS: all: " << alluseless
+                << "(" << (((float)alluseless)/(alluseless + allafter))*100 << "%) instructions\n";
+        }
     }
 
     if (methoduseless > 0) {
-        IPF_LOG << "USELESS: removed " << methoduseless 
-            << "(" << (((float)methoduseless)/(methoduseless + methodafter)) << "%) instructions\n";
+        IPF_LOG << "USELESS: removed " << methoduseless
+            << "(" << (((float)methoduseless)/(methoduseless + methodafter) * 100) << "%) instructions\n";
     }
     return methoduseless;
 }
 
 //============================================================================//
+int  Emitter::removeIgnoreTypeInst(Cfg & cfg, CompilationInterface & compilationinterface) {
+    BbNode  * node = (BbNode *)cfg.getEnterNode();
+    int ignoredcc = 0, i = 0;
+    do {
+        InstVector &insts = node->getInsts();
+
+        for( i=0 ; i < (int)insts.size() ; ) {
+            Inst *inst = insts[i];
+
+            if (Encoder::isIgnoreInst(inst)) {
+                IPF_LOG << "IGNORED: " << IrPrinter::toString(inst) << "\n";
+                insts.erase(insts.begin() + i);
+                continue;
+            }
+            i++;
+        }
+    } while( (node = node->getLayoutSucc()) != NULL );
+
+    if (ignoredcc>0 && i>0) {
+        IPF_LOG << "IGNORED: removed " << ignoredcc
+            << "(" << (((float)ignoredcc)/(ignoredcc + i) * 100) << "%) instructions\n";
+    }
+    return ignoredcc;
+}
+
+//============================================================================//
 InstructionType Emitter::getExecUnitType(int templateindex, int slotindex) {
-    return (InstructionType)((Emitter::BundleDesc[templateindex].slots >> (slotindex * 8)) & 0xFF);
+    return (InstructionType)((Bundle::BundleDesc[templateindex].slots >> (slotindex * 8)) & 0xFF);
 }
 
 //============================================================================//
@@ -403,14 +529,14 @@
         tmp.slots = IT_SLOT0(IT_ANY);
     }
     tmp.stops = (s0 ? 1 : 0);
-    
+
     if(i1!=NULL) {
         tmp.slots |= IT_SLOT1(Encoder::getInstType(i1));
     } else {
         tmp.slots |= IT_SLOT1(IT_ANY);
     }
     tmp.stops |= (s1 ? 2 : 0);
-    
+
     if( i2!=NULL ) {
         tmp.slots |= IT_SLOT2(Encoder::getInstType(i2));
     } else {
@@ -421,10 +547,10 @@
 
 int Emitter::findTmpl(const BundleDescription & tmp) {
     for( int j=0 ; j<TEMPLATES_COUNT ; j++ ) {
-        if( (BundleDesc[j].slots & tmp.slots)==BundleDesc[j].slots 
-                && (BundleDesc[j].stops & tmp.stops)==tmp.stops ) {
+        if( (Bundle::BundleDesc[j].slots & tmp.slots)==Bundle::BundleDesc[j].slots
+                && (Bundle::BundleDesc[j].stops == tmp.stops) ) {
             return j;
-        } 
+        }
     }
     return -1;
 }
@@ -507,7 +633,7 @@
         if (regs->GR.test(33)) {
             OpndManager * opndManager = cfg.getOpndManager();
             insts.insert(insts.begin() + i
-                , new(mm) Inst(INST_BREAK, opndManager->getP0(), opndManager->newImm(INST_BREAKPOINT_IMM_VALUE)));
+                , new(mm) Inst(mm, INST_BREAK, opndManager->getP0(), opndManager->newImm(INST_BREAKPOINT_IMM_VALUE)));
             i++;
         }
     }
@@ -517,12 +643,12 @@
 //============================================================================//
 bool Emitter::parsing() {
     bool ret = true;
-    
+
     datasize = 0;
     for (int bbindex=0, bbssize=(int)bbs->size() ; bbindex<bbssize ; bbindex++) {
         ret &= parsing(bbindex);
     }
-    
+
     return ret;
 }
 
@@ -543,11 +669,22 @@
         inst = insts[i];
         InstCode instCode = inst->getInstCode();
         OpndVector & opnds = inst->getOpnds();
-        
+
         if (instCode==INST_BR13 || instCode==INST_BRL13) {
             instCode = (instCode == INST_BR13 ? INST_BR : INST_BRL);
         }
-        
+
+        // if inst is branch and target is DATA_NODE_REF
+        // set istarget flag for target bb
+        if (instCode==INST_BR || instCode==INST_BRL) {
+            int is13 = (instCode==INST_BRL13 || instCode==INST_BR13 ? 1 : 0);  // must be 1 or 0
+            opnd = opnds[is13 + 1];
+            if (opnd->getDataKind() == DATA_NODE_REF)  {
+                int targetind = getBbNodeIndex(((NodeRef*) opnd)->getNode());
+                bbs->at(targetind)->istarget=true;
+            }
+        }
+
         // regs masks
         regs = new(mm) RegistersBitset();
         getWriteDpndBitset(inst, regs);
@@ -556,7 +693,7 @@
         regs = new(mm) RegistersBitset();
         getReadDpndBitset(inst, regs);
         rr->at(i) = regs;
-        
+
         // constants
         dstcount=inst->getNumDst();
         opndcount=inst->getNumOpnd();
@@ -576,17 +713,17 @@
             }
         }
     }
-    
+
     return true;
 }
 //============================================================================//
 bool Emitter::stopping() {
     bool ret = true;
-    
+
     for (int bbindex=0 ; bbindex<(int)bbs->size() ; bbindex++) {
         ret &= stopping(bbindex);
     }
-    
+
     return ret;
 }
 
@@ -595,7 +732,7 @@
     InstVector & insts = bb->insts;
     long sizebb = insts.size();
     if (sizebb==0) return true;
-    
+
     vectorbool * stops = bb->stops;
     vectorregs * wr = bb->wregs;
     vectorregs * rr = bb->rregs;
@@ -617,10 +754,10 @@
             }
             if (Encoder::isIgnoreInst(inst1)) continue;
             if (icode1 >= INST_ST_FIRST && icode1 <= INST_ST_LAST) continue;
-    
+
             regs1w = wr->at(i);
             if(!regs1w->any()) continue;
-    
+
             for (long j = i + 1; j < stop; j++) {
                 inst2 = insts[j];
                 icode2 = inst2->getInstCode();
@@ -628,14 +765,23 @@
                     if (j>0) stops->at(j-1) = true;
                 }
                 if (Encoder::isIgnoreInst(inst2)) continue;
-    
+
                 regs2w = wr->at(j);
                 regs2r = rr->at(j);
                 if(!regs2w->any() && !regs2r->any()) continue;
-    
-                if( (regs1w->GR & (regs2w->GR | regs2r->GR)).any() 
-                        || (regs1w->FR & (regs2w->FR | regs2r->FR)).any() 
-                        || (regs1w->PR & (regs2w->PR | regs2r->PR)).any() 
+
+                if (Encoder::isBranchInst(inst2)) {
+                    if( (Encoder::getInstType(icode1) & IT_F)
+                            && (regs1w->PR & (regs2w->PR | regs2r->PR)).any() ) {
+                        stop=j;
+                        break;
+                    }
+                    continue;
+                }
+
+                if( (regs1w->GR & (regs2w->GR | regs2r->GR)).any()
+                        || (regs1w->FR & (regs2w->FR | regs2r->FR)).any()
+                        || (regs1w->PR & (regs2w->PR | regs2r->PR)).any()
                         || (regs1w->BR & (regs2w->BR | regs2r->BR)).any() ) {
                     stop=j;
                     break;
@@ -648,14 +794,14 @@
             stop=sizebb;
         } else if( stop==sizebb ) {
             start++;
-        } else {         
+        } else {
             stops->at(stop-1) = true;
             start=stop;
             stop=sizebb;
         }
     }
     stops->at(stops->size()-1) = true;
-    
+
     return true;
 }
 
@@ -664,17 +810,36 @@
     EmitterBb * bb;
     char * off=0;
     bool ret = true;
-    
+
     for (int bbindex=0 ; bbindex<(int)bbs->size() ; bbindex++) {
         ret &= bundling(bbindex);
         bb = bbs->at(bbindex);
         bb->bsize = bb->bundles->size();
         bb->codeoff = off;
         bb->codesize = bb->bsize * IPF_BUNDLE_SIZE;
+        // align bb if istarget==true
+        if (false && bb->istarget) { // switch off aligning
+            uint16 bytes4align = (bb->codesize % IPF_CODE_ALIGNMENT) == 0
+                    ? 0
+                    : IPF_CODE_ALIGNMENT - (bb->codesize % IPF_CODE_ALIGNMENT);
+            if (bytes4align>0 && (bytes4align%IPF_BUNDLE_SIZE)==0) {
+                bb->codesize += bytes4align;
+                uint16 bundles4align = bytes4align/IPF_BUNDLE_SIZE;
+                OpndManager * opndManager = cfg.getOpndManager();
+                Opnd * p0 = opndManager->getP0();
+                for (uint16 i=0 ; i<bundles4align ; i++) {
+                    bb->bundles->addBundle(0x00
+                        , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                        , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE))
+                        , new(mm) Inst(mm, INST_NOP, p0, IMM(INST_BREAKPOINT_IMM_VALUE)));
+                }
+
+            }
+        }
         off = (char *)off + bb->codesize;
     }
     codesize = (long)((char *)off);
-    
+
     return ret;
 }
 bool Emitter::bundling(int bbindex) {
@@ -686,13 +851,13 @@
     vectorbool * stops = bb->stops;
     BundleVector * bundles = bb->bundles;
     BundleDescription tmp = {0,0,0};
-    int    iTmpl=-1;
-    Inst * inst0=NULL, * inst1=NULL, * inst2=NULL;
-    bool   stop0=false, stop1=false, stop2=false;
-    bool   stop0_f=false, stop1_f=false, stop2_f=false; // inst is first in group
-    bool   stop0_l=false, stop1_l=false, stop2_l=false; // inst is last in group
-    int    it0=0, it1=0, it2=0; // insts type
-    long   i0, i1, i2;
+    int   iTmpl=-1;
+    Inst *inst0=NULL, *inst1=NULL, *inst2=NULL, *inst3=NULL;
+    bool  stop0=false, stop1=false, stop2=false, stop3=false;
+    bool  stop0_f=false, stop1_f=false, stop2_f=false, stop3_f=false; // inst is first in group
+    bool  stop0_l=false, stop1_l=false, stop2_l=false; // inst is last in group
+    int   it0=0, it1=0, it2=0, it3=0; // insts type
+    long  i0, i1, i2, i3;
 
     for ( i0=0 ; i0 < sizebb ; ) {
         inst0=Encoder::resolvePseudo(cfg, insts[i0]);
@@ -714,10 +879,19 @@
             break;
         }
         if ( i2 >= sizebb ) { inst2=NULL; }
-        
+
+        for ( i3=i2+1 ; i3<sizebb ; ) {
+            inst3=Encoder::resolvePseudo(cfg, insts[i3]);
+            if (Encoder::isIgnoreInst(inst3)) { i3++; continue; }
+            stop3=stops->at(i3);
+            break;
+        }
+        if ( i3 >= sizebb ) { inst3=NULL; }
+
         it0 = Encoder::getInstType(inst0);
         it1 = Encoder::getInstType(inst1);
         it2 = Encoder::getInstType(inst2);
+        it3 = Encoder::getInstType(inst3);
 
         stop0_l = (it0 & IT_GL)==IT_GL;
         stop1_l = (it1 & IT_GL)==IT_GL;
@@ -725,10 +899,13 @@
         stop0_f = (it0 & IT_GF)==IT_GF;
         stop1_f = (it1 & IT_GF)==IT_GF;
         stop2_f = (it2 & IT_GF)==IT_GF;
+        stop3_f = (it3 & IT_GF)==IT_GF;
 
-        // Special case for br.call
-        // br.ret will return to next bundle, so
-        // all instructions after br.call must be nop
+        /*********************************************
+         * Special case for br.call
+         * br.ret will return to next bundle, so
+         * all instructions after br.call must be nop
+         *********************************************/
         if (inst0->getInstCode()==INST_BR || inst0->getInstCode()==INST_BR13) {
             CompVector & cmpls0 = inst0->getComps();
             if (cmpls0.size()>0 && cmpls0[0]==CMPLT_BTYPE_CALL) {
@@ -742,9 +919,47 @@
             }
         }
 
+        /*********************************************
+         * Special case for inst0==LX type (brl,...)
+         *********************************************/
+        if ( Encoder::getInstType(inst0->getInstCode()) & IT_L ) {
+            inst1=NULL;
+            inst2=NULL;
+            getTmpl(bbindex, tmp, NULL, inst0, NULL
+                , false, false, stop0 || stop0_l || stop1_f);
+            iTmpl=findTmpl(tmp);
+            if( iTmpl>=0 ) {
+                bundles->addBundle(iTmpl, NULL, inst0, NULL);
+                i0 += 1;
+                continue;
+            }
+            IPF_ERR << "BUNDLING ERROR: CAN'T FIND TEMPLATE !\n";
+            IPF_ERR << "BUNDLING ERROR: " << IrPrinter::toString(inst0) << "\n";
+            IPF_ASSERT(0);
+        }
+
+        /********************************
+         * Special case for inst1==LX type (brl,...)
+         ********************************/
+        if (inst1!=NULL && (Encoder::getInstType(inst1->getInstCode()) & IT_L)) {
+            inst2=NULL;
+            getTmpl(bbindex, tmp, inst0, inst1, NULL
+                , stop0 || stop0_l || stop1_f, false, stop1 || stop1_l || stop2_f);
+            iTmpl=findTmpl(tmp);
+            if( iTmpl>=0 ) {
+                bundles->addBundle(iTmpl, inst0, inst1, NULL);
+                i0 = i1 + 1;
+                continue;
+            }
+            inst1=NULL;
+        }
+
+        /********************************
+         * inst1!=NULL && inst2!=NULL
+         ********************************/
         if (inst1!=NULL && inst2!=NULL) {
             getTmpl(bbindex, tmp, inst0, inst1, inst2
-                , stop0 || stop0_l || stop1_f, stop1 || stop1_l || stop2_f, stop2 || stop2_l);
+                , stop0 || stop0_l || stop1_f, stop1 || stop1_l || stop2_f, stop2 || stop2_l || stop3_f);
             iTmpl=findTmpl(tmp);
             if( iTmpl>=0 ) {
                 bundles->addBundle(iTmpl, inst0, inst1, inst2);
@@ -752,33 +967,47 @@
                 continue;
             }
         }
-        
+
+        /********************************
+         * inst2==NULL && inst1!=LX type (brl,...)
+         ********************************/
         if (inst1!=NULL) {
-            getTmpl(bbindex, tmp, inst0, NULL, inst1
-                , stop0 || stop0_l, stop1_f, stop1 || stop1_l || stop2_f);
+            getTmpl(bbindex, tmp, inst0, inst1, NULL
+                , stop0 || stop0_l || stop1_f, stop1 || stop1_l || stop2_f, false);
             iTmpl=findTmpl(tmp);
             if( iTmpl>=0 ) {
-                bundles->addBundle(iTmpl, inst0, NULL, inst1);
+                bundles->addBundle(iTmpl, inst0, inst1, NULL);
+                i0 = i1 + 1;
+                continue;
+            }
+            getTmpl(bbindex, tmp, inst0, inst1, NULL
+                , stop0 || stop0_l || stop1_f, false, stop1 || stop1_l || stop2_f);
+            iTmpl=findTmpl(tmp);
+            if( iTmpl>=0 ) {
+                bundles->addBundle(iTmpl, inst0, inst1, NULL);
                 i0 = i1 + 1;
                 continue;
             }
 
-            if ( inst1!=NULL && Encoder::getInstType(inst1->getInstCode()) & IT_L ) {
-                getTmpl(bbindex, tmp, inst0, inst1, NULL
-                    , stop0 || stop0_l || stop1_f, false, stop1 || stop1_l || stop2_f);
-            } else {
-                getTmpl(bbindex, tmp, inst0, inst1, NULL
-                    , stop0 || stop0_l || stop1_f, stop1 || stop1_l, stop2_f);
+            getTmpl(bbindex, tmp, inst0, NULL, inst1
+                , stop0 || stop0_l || stop1_f, false, stop1 || stop1_l || stop2_f);
+            iTmpl=findTmpl(tmp);
+            if( iTmpl>=0 ) {
+                bundles->addBundle(iTmpl, inst0, NULL, inst1);
+                i0 = i1 + 1;
+                continue;
             }
+            getTmpl(bbindex, tmp, inst0, NULL, inst1
+                , false, stop0 || stop0_l || stop1_f, stop1 || stop1_l || stop2_f);
             iTmpl=findTmpl(tmp);
             if( iTmpl>=0 ) {
-                bundles->addBundle(iTmpl, inst0, inst1, NULL);
+                bundles->addBundle(iTmpl, inst0, NULL, inst1);
                 i0 = i1 + 1;
                 continue;
             }
-    
+
             getTmpl(bbindex, tmp, NULL, inst0, inst1
-                , stop0_f, stop0 || stop0_l || stop1_f, stop1 || stop1_l || stop2_f);
+                , false, stop0 || stop0_l || stop1_f, stop1 || stop1_l || stop2_f);
             iTmpl=findTmpl(tmp);
             if( iTmpl>=0 ) {
                 bundles->addBundle(iTmpl, NULL,inst0, inst1);
@@ -787,8 +1016,27 @@
             }
         }
 
+        /********************************
+         * inst1==NULL
+         ********************************/
+        getTmpl(bbindex, tmp, inst0, NULL, NULL
+            , stop0 || stop0_l || stop1_f, false, false);
+        iTmpl=findTmpl(tmp);
+        if( iTmpl>=0 ) {
+            bundles->addBundle(iTmpl, inst0, NULL, NULL);
+            i0 += 1;
+            continue;
+        }
         getTmpl(bbindex, tmp, inst0, NULL, NULL
-            , stop0 || stop0_l, false, stop1_f);
+            , false, stop0 || stop0_l || stop1_f, false);
+        iTmpl=findTmpl(tmp);
+        if( iTmpl>=0 ) {
+            bundles->addBundle(iTmpl, inst0, NULL, NULL);
+            i0 += 1;
+            continue;
+        }
+        getTmpl(bbindex, tmp, inst0, NULL, NULL
+            , false, false, stop0 || stop0_l || stop1_f);
         iTmpl=findTmpl(tmp);
         if( iTmpl>=0 ) {
             bundles->addBundle(iTmpl, inst0, NULL, NULL);
@@ -796,13 +1044,16 @@
             continue;
         }
 
-        if ( Encoder::getInstType(inst0->getInstCode()) & IT_L ) {
-            getTmpl(bbindex, tmp, NULL, inst0, NULL
-                , false, false, stop0 || stop0_l || stop1_f);
-        } else {
-            getTmpl(bbindex, tmp, NULL, inst0, NULL
-                , stop0_f, stop0 || stop0_l, stop1_f);
+        getTmpl(bbindex, tmp, NULL, inst0, NULL
+            , false, stop0 || stop0_l || stop1_f, false);
+        iTmpl=findTmpl(tmp);
+        if( iTmpl>=0 ) {
+            bundles->addBundle(iTmpl, NULL, inst0, NULL);
+            i0 += 1;
+            continue;
         }
+        getTmpl(bbindex, tmp, NULL, inst0, NULL
+            , false, false, stop0 || stop0_l || stop1_f);
         iTmpl=findTmpl(tmp);
         if( iTmpl>=0 ) {
             bundles->addBundle(iTmpl, NULL, inst0, NULL);
@@ -811,7 +1062,7 @@
         }
 
         getTmpl(bbindex, tmp, NULL, NULL, inst0
-            , false, stop0_f, stop0 || stop0_l || stop1_f);
+            , false, false, stop0 || stop0_l || stop1_f);
         iTmpl=findTmpl(tmp);
         if( iTmpl>=0 ) {
             bundles->addBundle(iTmpl, NULL, NULL, inst0);
@@ -824,21 +1075,21 @@
 
         i0++;
     }
-    
+
     return true;
 }
 
 //============================================================================//
 bool Emitter::emitData() {
     if (datasize==0) return true;
-        
+
     bool          ret = true;
     EmitterBb   * bb;
     char        * p;
     Opnd        * opnd;
 
     dataoff = (char *)compilationinterface.allocateDataBlock(datasize
-        , L2_CACHE_BANK_SIZE);
+        , L2_CACHE_LINE_SIZE);
     assert(dataoff != NULL);
     if ( dataoff == NULL ) return false;
 
@@ -851,7 +1102,7 @@
             if (opnd->isImm()) {
                 if ( opnd->getDataKind() == DATA_CONST_REF) {
                     Constant    * c;
-                    
+
                     c = ((ConstantRef *)opnd)->getConstant();
                     switch (c->getDataKind()) {
                     case DATA_I64:
@@ -859,12 +1110,12 @@
                         c->setAddress(p);
                         p = (char *)(++((int64 *)p));
                         break;
-                    case DATA_S:       
+                    case DATA_S:
                         *((float *)p) = ((FloatConstant *)c)->getValue();
                         c->setAddress(p);
                         p = (char *)(++((float *)p));
                         break;
-                    case DATA_D:       
+                    case DATA_D:
                         *((double *)p) = ((DoubleConstant *)c)->getValue();
                         c->setAddress(p);
                         p = (char *)(++((double *)p));
@@ -875,7 +1126,7 @@
                     }
                 } else if ( opnd->getDataKind() == DATA_SWITCH_REF) {
                     SwitchConstant    * c;
-                    
+
                     c = (SwitchConstant *)((ConstantRef *)opnd)->getConstant();
                     *((uint64 *)p) = (uint64)opnd;  // need to fill with actual
                                                     // values of node's addresses
@@ -889,7 +1140,7 @@
             }
         }
     }
-    
+
     return ret;
 }
 
@@ -897,7 +1148,7 @@
 bool Emitter::fixSwitchTables() {
     if ( datasize==0 ) return true;
     if ( dataoff == NULL ) return true;
-    
+
     bool          ret = true;
     EmitterBb   * bb;
     void        * p;
@@ -922,7 +1173,7 @@
             }
         }
     }
-    
+
     return ret;
 }
 
@@ -954,7 +1205,7 @@
                     inst = bundle->getSlot(si);
                     inst->setAddr((uint32)(off - bboff) + si);
                 }
-                
+
                 if ( isBranchBundle(bundle, codeoff, off, target) ) {
                     // bundle contains B type inst
                     bundle->emitBundleBranch(off, target);
@@ -982,7 +1233,7 @@
             }
         }
         IPF_LOG << "END code emitting: "
-            << compilationinterface.getMethodToCompile()->getParentType()->getName() 
+            << compilationinterface.getMethodToCompile()->getParentType()->getName()
             << "." << compilationinterface.getMethodToCompile()->getName()
             << compilationinterface.getMethodToCompile()->getSignatureString()
             << endl;
@@ -1000,8 +1251,8 @@
         Opnd   * opnd;
         InstCode     icode;
         unsigned int is13;  // must be 1 or 0
-        
-        for (int i=0 ; i<3 ; i++ ) {
+
+        for (int i=0 ; i<IPF_SLOTS_COUNT ; i++ ) {
             branchtargets[i] = 0;
             inst = bundle->getSlot(i);
             if(Encoder::isBranchInst(inst)) {
@@ -1027,17 +1278,26 @@
     return (char *)-1;
 }
 
+int Emitter::getBbNodeIndex(BbNode * node) {
+    for (int i=0 ; i<(int)bbs->size() ; i++) {
+        if (bbs->at(i)->node == node) {
+            return i;
+        }
+    }
+    return -1;
+}
+
 bool Emitter::emit() {
     bool ret = true;
 
-    // 0 pass: parsing insts 
-    //     - clear ignored insts 
-    //     - define registers read/write  masks 
+    // 0 pass: parsing insts
+    //     - clear ignored insts
+    //     - define registers read/write  masks
     //     - create vector of constants
     //     - create vector of brunches
     ret &= parsing();
     if (!ret) { IPF_ERR << "Bad results for parsing\n"; return ret; }
-    
+
     // 1 pass: emit data
     ret &= emitData();
     if (!ret) { IPF_ERR << "Bad results for emitData\n"; return ret; }
@@ -1058,10 +1318,12 @@
     ret = fixSwitchTables();
     if (!ret) { IPF_ERR << "Bad results for fixSwitchTables\n"; return ret; }
 
+    // checkForDualIssueBundles();
+
     if (LOG_ON) {
-//        printInsts(" Result of stopping() ");
-//        printBundles(" Result of bundling() ");
-        //printCodeBlock(" Result of emitting() ");
+        printInsts(" Result of stopping() ");
+        printBundles(" Result of bundling() ");
+        printCodeBlock(" Result of emitting() ");
         printDisasm(" Result of emitting(disasm) ");
     }
 
@@ -1082,12 +1344,12 @@
     BundleVector * bundles = bbs->at(bbindex)->bundles;
     Bundle * bndl;
 
-    IPF_LOG << ".L" << bbs->at(bbindex)->node->getId() 
+    IPF_LOG << ".L" << bbs->at(bbindex)->node->getId()
         << " (0x" << hex << bbs->at(bbindex)->node->getAddress() << dec << ")\n";
     for (long i = 0, ii=bundles->size() ; i < ii ; i++) {
         bndl = bundles->at(i);
         if( bndl==NULL ) {
-            IPF_LOG << i; 
+            IPF_LOG << i;
             IPF_LOG << "  \tNULL\n"
                       << "  \tNULL\n"
                       << "  \tNULL\n";
@@ -1130,7 +1392,7 @@
     char     printbuf[256];
     char   * off = codeoff;
     uint64 * p, tmpl, i0, i1, i2;
-    
+
     IPF_LOG << "\n-----------" << cap << "-----------------------------\n";
     sprintf(printbuf, "%-11.11s       %-11.11s       %-11.11s       %-8.8s\n", "slot2", "slot1", "slot0", "template");
     IPF_LOG << printbuf;
@@ -1141,7 +1403,7 @@
         i0 = (p[0] & 0x3FFFFFFFFFE0) >> 5;
         i1 = (((p[0] & ~0x1F) & ~0x3FFFFFFFFFE0) >> 46) | ((p[1] & 0x7FFFFF) << 18);
         i2 = (p[1] & ~0x7FFFFF) >> 23;
-        
+
         sprintf(printbuf, "%11.11llx       %11.11llx       %11.11llx       %2.2x      \n", i2, i1, i0, (unsigned)tmpl);
         IPF_LOG << printbuf;
         off += IPF_BUNDLE_SIZE;
@@ -1153,8 +1415,8 @@
 {
     InstCode     icode  = inst->getInstCode();
     unsigned int is13 = (icode==INST_BRL13 ? 1 : 0);  // must be 1 or 0
-    
-    assert((icode==INST_BRL || icode==INST_BRL13) 
+
+    assert((icode==INST_BRL || icode==INST_BRL13)
         && (inst->getComps())[0]==CMPLT_BTYPE_CALL);
     Opnd * target = (inst->getOpnds())[is13 + 2];
     assert(target->isImm() && target->getDataKind()==DATA_METHOD_REF);
@@ -1162,8 +1424,8 @@
 
     compilationinterface.setNotifyWhenMethodIsRecompiled(method, (void *)data);
     if (LOG_ON) {
-        IPF_LOG << "Registered call to " << method->getParentType()->getName() 
-            << "." << method->getName() 
+        IPF_LOG << "Registered call to " << method->getParentType()->getName()
+            << "." << method->getName()
             << " : data=0x" << hex << data << dec
             << " for recompiled method event" << endl;
     }
@@ -1171,7 +1433,7 @@
 
 #include <dlfcn.h>
 #include <libgen.h>
- 
+
 void Emitter::printDisasm(char * cap) {
     static bool load_done = false;
     static unsigned (*disasm)(const char *, char *, unsigned) = NULL;
@@ -1182,7 +1444,7 @@
         // Resolve full path to module
         string sz("");
         int len = 0;
-        
+
         len = readlink("/proc/self/exe", buf, sizeof(buf));
         if (len < 0) {
             buf[0]='.';
@@ -1206,7 +1468,7 @@
         disasm = (unsigned (*)(const char *, char *, unsigned))
             (handle == NULL ? NULL : dlsym(handle, "disasm"));
         load_done = true;
-    
+
         if (disasm==NULL) {
             std::cout << "CAN'T LOAD" << std::endl;
             return;
@@ -1217,21 +1479,21 @@
     if (disasm==NULL) {
         return;
     }
-    
+
     string str("");
     char buf[100];
     char * off = codeoff;
-    
+
     for (unsigned i=0 ; i<codesize ; off=codeoff+i) {
         unsigned l = disasm((const char*)off, buf, sizeof(buf)-1);
-        
+
         for (int bbindex=0 ; bbindex<(int)bbs->size() ; bbindex++) {
             EmitterBb *bb = bbs->at(bbindex);
             char * bboff = (char *)bb->node->getAddress();
-            
+
             if (bboff==off) {
                 char   bbid[64];
-                
+
                 sprintf(bbid, "%i (%p)", (int)bb->node->getId(), bboff);
                 str.append("\n.L");
                 str.append(bbid);
@@ -1251,7 +1513,7 @@
         }
         i += l;
     }
-    
+
     IPF_LOG << endl << "-----------" << cap << "-----------------------" << endl;
     IPF_LOG << str;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEncoder.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEncoder.cpp?view=diff&rev=477525&r1=477524&r2=477525
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEncoder.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ipf/IpfEncoder.cpp Mon Nov 20 22:23:40 2006
@@ -539,21 +539,21 @@
 
             if (opndsize == 3) {
                 if (okind1 == OPND_G_REG && opnds[2]->isImm(22)) {
-                    newinst = new(mm) Inst(INST_ADDL, opnds[0], opnds[1], opnds[2]
+                    newinst = new(mm) Inst(mm, INST_ADDL, opnds[0], opnds[1], opnds[2]
                             , cfg.getOpndManager()->getR0());
                 } else if (okind1 == OPND_G_REG && opnds[2]->isImm(64)) {
-                    newinst = new(mm) Inst(INST_MOVL, opnds[0], opnds[1], opnds[2]);
+                    newinst = new(mm) Inst(mm, INST_MOVL, opnds[0], opnds[1], opnds[2]);
                 } else if (okind1 == OPND_G_REG && okind2 == OPND_G_REG 
                          && cmpls.size()==0) {
-                    newinst = new(mm) Inst(INST_ADDS, opnds[0], opnds[1]
+                    newinst = new(mm) Inst(mm, INST_ADDS, opnds[0], opnds[1]
                             , opndManager->newImm(0), opnds[2]);
                 } else if (okind1 == OPND_F_REG && okind2 == OPND_F_REG) {
-                    newinst = new(mm) Inst(INST_FMERGE_S, opnds[0], opnds[1], opnds[2], opnds[2]);
+                    newinst = new(mm) Inst(mm, INST_FMERGE_S, opnds[0], opnds[1], opnds[2], opnds[2]);
                 } else if (okind1 == OPND_B_REG && okind2 == OPND_G_REG) {
-                    newinst = new(mm) Inst(INST_MOV, opnds[0], opnds[1], opnds[2]
+                    newinst = new(mm) Inst(mm, INST_MOV, opnds[0], opnds[1], opnds[2]
                            , opndManager->newImm(0));
                 } else if (okind1 == OPND_G_REG && okind2 == OPND_A_REG) {
-                    newinst = new(mm) Inst(INST_MOV_M, opnds[0], opnds[1], opnds[2]);
+                    newinst = new(mm) Inst(mm, INST_MOV_M, opnds[0], opnds[1], opnds[2]);
                 } else if (okind1 == OPND_G_REG && okind2 == OPND_B_REG) {
                     break;
                 } else if (okind1 == OPND_A_REG
@@ -680,11 +680,11 @@
             default: assert(0); break;
             }            
 
-            if (opnds[2]->isImm(14)) {
+            if (opnds[2]->isImm(8)) {
                 x4 += 0x8;
-                return A1(x4, x2b, opnds[3]->getValue(), opnds[2]->getValue(), opnds[1]->getValue(), qp);
-            } else {
                 return A3(x4, x2b, opnds[3]->getValue(), opnds[2]->getValue(), opnds[1]->getValue(), qp);
+            } else {
+                return A1(x4, x2b, opnds[3]->getValue(), opnds[2]->getValue(), opnds[1]->getValue(), qp);
             }
         }
     case INST_CMP: