]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Necessary infrastructure to support HInstrVec, HInstrSB into host_generic_regs.c
authorIvo Raisr <ivosh@ivosh.net>
Tue, 8 Aug 2017 08:59:08 +0000 (10:59 +0200)
committerIvo Raisr <ivosh@ivosh.net>
Mon, 28 Aug 2017 21:21:18 +0000 (23:21 +0200)
VEX/priv/host_generic_regs.c

index 67d2ea2eef9e29ceb97dca71be32bec40b546138..4d55c5b94db2a99408a816a3162a5302a897a582 100644 (file)
@@ -313,28 +313,110 @@ HReg lookupHRegRemap ( HRegRemap* map, HReg orig )
 /*--- Abstract instructions                             ---*/
 /*---------------------------------------------------------*/
 
-HInstrArray* newHInstrArray ( void )
+HInstrVec* newHInstrVec(void)
 {
-   HInstrArray* ha = LibVEX_Alloc_inline(sizeof(HInstrArray));
-   ha->arr_size = 4;
-   ha->arr_used = 0;
-   ha->arr      = LibVEX_Alloc_inline(ha->arr_size * sizeof(HInstr*));
-   ha->n_vregs  = 0;
-   return ha;
+   HInstrVec* hv  = LibVEX_Alloc_inline(sizeof(HInstrVec));
+   hv->insns_size = 4;
+   hv->insns_used = 0;
+   hv->insns      = LibVEX_Alloc_inline(hv->insns_size * sizeof(HInstr*));
+   return hv;
 }
 
 __attribute__((noinline))
-void addHInstr_SLOW ( HInstrArray* ha, HInstr* instr )
+void addHInstr_SLOW(HInstrVec* hv, HInstr* instr)
 {
-   vassert(ha->arr_used == ha->arr_size);
-   Int      i;
-   HInstr** arr2 = LibVEX_Alloc_inline(ha->arr_size * 2 * sizeof(HInstr*));
-   for (i = 0; i < ha->arr_size; i++) {
-      arr2[i] = ha->arr[i];
+   vassert(hv->insns_used == hv->insns_size);
+   HInstr** insns2 = LibVEX_Alloc_inline(hv->insns_size * 2 * sizeof(HInstr*));
+   for (UInt i = 0; i < hv->insns_size; i++) {
+      insns2[i] = hv->insns[i];
    }
-   ha->arr_size *= 2;
-   ha->arr = arr2;
-   addHInstr(ha, instr);
+   hv->insns_size *= 2;
+   hv->insns = insns2;
+   addHInstr(hv, instr);
+}
+
+HInstrIfThenElse* newHInstrIfThenElse(HCondCode condCode, HPhiNode* phi_nodes,
+                                      UInt n_phis)
+{
+   HInstrIfThenElse* hite = LibVEX_Alloc_inline(sizeof(HInstrIfThenElse));
+   hite->ccOOL            = condCode;
+   hite->fallThrough      = newHInstrVec();
+   hite->outOfLine        = newHInstrVec();
+   hite->phi_nodes        = phi_nodes;
+   hite->n_phis           = n_phis;
+   return hite;
+}
+
+static void print_depth(UInt depth) {
+   for (UInt i = 0; i < depth; i++) {
+      vex_printf("    ");
+   }
+}
+
+void ppHPhiNode(const HPhiNode* phi_node)
+{
+   ppHReg(phi_node->dst);
+   vex_printf(" = phi(");
+   ppHReg(phi_node->srcFallThrough);
+   vex_printf(",");
+   ppHReg(phi_node->srcOutOfLine);
+   vex_printf(")");
+}
+
+static void ppHInstrVec(const HInstrVec* code,
+                        HInstrIfThenElse* (*isIfThenElse)(const HInstr*),
+                        void (*ppInstr)(const HInstr*, Bool),
+                        void (*ppCondCode)(HCondCode),
+                        Bool mode64, UInt depth, UInt *insn_num)
+{
+   for (UInt i = 0; i < code->insns_used; i++) {
+      const HInstr* instr = code->insns[i];
+      const HInstrIfThenElse* hite = isIfThenElse(instr);
+      if (UNLIKELY(hite != NULL)) {
+         print_depth(depth);
+         vex_printf("      if (!");
+         ppCondCode(hite->ccOOL);
+         vex_printf(") then fall-through {\n");
+         ppHInstrVec(hite->fallThrough, isIfThenElse, ppInstr, ppCondCode,
+                     mode64, depth + 1, insn_num);
+         print_depth(depth);
+         vex_printf("      } else out-of-line {\n");
+         ppHInstrVec(hite->outOfLine, isIfThenElse, ppInstr, ppCondCode,
+                     mode64, depth + 1, insn_num);
+         print_depth(depth);
+         vex_printf("      }\n");
+
+         for (UInt j = 0; j < hite->n_phis; j++) {
+            print_depth(depth);
+            vex_printf("      ");
+            ppHPhiNode(&hite->phi_nodes[j]);
+            vex_printf("\n");
+         }
+      } else {
+         vex_printf("%3u   ", (*insn_num)++);
+         print_depth(depth);
+         ppInstr(instr, mode64);
+         vex_printf("\n");
+      }
+   }
+}
+
+HInstrSB* newHInstrSB(void)
+{
+   HInstrSB* hsb = LibVEX_Alloc_inline(sizeof(HInstrSB));
+   hsb->insns    = newHInstrVec();
+   hsb->n_vregs  = 0;
+   return hsb;
+}
+
+void ppHInstrSB(const HInstrSB* code,
+                HInstrIfThenElse* (*isIfThenElse)(const HInstr*),
+                void (*ppInstr)(const HInstr*, Bool),
+                void (*ppCondCode)(HCondCode), Bool mode64)
+{
+   UInt insn_num = 0;
+   ppHInstrVec(code->insns, isIfThenElse, ppInstr, ppCondCode, mode64, 0,
+               &insn_num);
 }