Discussion:
vex: r3333 - in /branches/VEX_JIT_HACKS: priv/ir_defs.c useful/test_main.c
(too old to reply)
s***@valgrind.org
2017-03-28 05:33:58 UTC
Permalink
Raw Message
Author: iraisr
Date: Tue Mar 28 06:33:58 2017
New Revision: 3333

Log:
Implement the missing function in VEX/priv/ir_defs.c.

Modified:
branches/VEX_JIT_HACKS/priv/ir_defs.c
branches/VEX_JIT_HACKS/useful/test_main.c

Modified: branches/VEX_JIT_HACKS/priv/ir_defs.c
==============================================================================
--- branches/VEX_JIT_HACKS/priv/ir_defs.c (original)
+++ branches/VEX_JIT_HACKS/priv/ir_defs.c Tue Mar 28 06:33:58 2017
@@ -2604,10 +2604,6 @@

IRPhiVec* deepCopyIRPhiVec(const IRPhiVec* vec)
{
- if (vec == NULL) {
- return NULL;
- }
-
IRPhiVec* vec2 = LibVEX_Alloc_inline(sizeof(IRPhiVec));
vec2->phis_used = vec2->phis_size = vec->phis_used;
IRPhi **phis2 = LibVEX_Alloc_inline(vec2->phis_used * sizeof(IRPhi*));
@@ -2617,6 +2613,19 @@
return vec2;
}

+IRTempDefSet* deepCopyIRTempDefSet(const IRTempDefSet* def_set)
+{
+ IRTempDefSet* def_set2 = LibVEX_Alloc_inline(sizeof(IRTempDefSet));
+ def_set2->slots_used = def_set->slots_used;
+ def_set2->slots_size = def_set->slots_size;
+ UChar* set2 = LibVEX_Alloc_inline(def_set2->slots_used * sizeof(UChar));
+ for (UInt i = 0; i < def_set2->slots_used; i++) {
+ set2[i] = def_set->set[i];
+ }
+ def_set2->set = set2;
+ return def_set2;
+}
+
IRStmt* deepCopyIRStmt(const IRStmt* s, IRStmtVec* parent)
{
switch (s->tag) {

Modified: branches/VEX_JIT_HACKS/useful/test_main.c
==============================================================================
--- branches/VEX_JIT_HACKS/useful/test_main.c (original)
+++ branches/VEX_JIT_HACKS/useful/test_main.c Tue Mar 28 06:33:58 2017
@@ -387,7 +387,7 @@
addr = st->Ist.STle.addr;
assert(isIRAtom(data));
assert(isIRAtom(addr));
- sz = sizeofIRType(typeOfIRExpr(bb_in->stmts, data));
+ sz = sizeofIRType(typeOfIRExpr(bb_in->tyenv, data));
needSz = False;
switch (sz) {
case 4: helper = mkIRCallee(1, "ac_helperc_STORE4",
@@ -609,13 +609,13 @@
so far exists, allocate one. */
static IRTemp findShadowTmp ( MCEnv* mce, IRTemp orig )
{
- tl_assert(orig.index < mce->n_originalTmps);
- if (isIRTempInvalid(mce->tmpMap[orig.index])) {
- mce->tmpMap[orig.index]
- = newIRTemp(mce->bb->stmts->tyenv,
- shadowType(mce->bb->stmts->tyenv->types[orig.index]));
+ tl_assert(orig < mce->n_originalTmps);
+ if (mce->tmpMap[orig] == IRTemp_INVALID) {
+ mce->tmpMap[orig]
+ = newIRTemp(mce->bb->tyenv, mce->bb->stmts,
+ shadowType(mce->bb->tyenv->types[orig]));
}
- return mce->tmpMap[orig.index];
+ return mce->tmpMap[orig];
}

/* Allocate a new shadow for the given original tmp. This means any
@@ -626,10 +626,10 @@
and use that instead. */
static void newShadowTmp ( MCEnv* mce, IRTemp orig )
{
- tl_assert(orig.index < mce->n_originalTmps);
- mce->tmpMap[orig.index]
- = newIRTemp(mce->bb->stmts->tyenv,
- shadowType(mce->bb->stmts->tyenv->types[orig.index]));
+ tl_assert(orig < mce->n_originalTmps);
+ mce->tmpMap[orig]
+ = newIRTemp(mce->bb->tyenv, mce->bb->stmts,
+ shadowType(mce->bb->tyenv->types[orig]));
}


@@ -652,7 +652,7 @@
{
if (a1->tag == Iex_Const)
return True;
- if (a1->tag == Iex_RdTmp && a1->Iex.RdTmp.tmp.index < mce->n_originalTmps)
+ if (a1->tag == Iex_RdTmp && a1->Iex.RdTmp.tmp < mce->n_originalTmps)
return True;
return False;
}
@@ -663,7 +663,7 @@
{
if (a1->tag == Iex_Const)
return True;
- if (a1->tag == Iex_RdTmp && a1->Iex.RdTmp.tmp.index >= mce->n_originalTmps)
+ if (a1->tag == Iex_RdTmp && a1->Iex.RdTmp.tmp >= mce->n_originalTmps)
return True;
return False;
}
@@ -725,12 +725,12 @@
/*------------------------------------------------------------*/

/* assign value to tmp */
-#define assign(_stmts,_tmp,_expr) \
- addStmtToIRStmtVec((_stmts), IRStmt_WrTmp((_tmp),(_expr)))
+#define assign(_bb,_tmp,_expr) \
+ addStmtToIRStmtVec((_bb->stmts), IRStmt_WrTmp((_tmp),(_expr)))

/* add stmt to a bb */
-#define stmt(_stmts,_stmt) \
- addStmtToIRStmtVec((_stmts), (_stmt))
+#define stmt(_bb,_stmt) \
+ addStmtToIRStmtVec((_bb->stmts), (_stmt))

/* build various kinds of expressions */
#define binop(_op, _arg1, _arg2) IRExpr_Binop((_op),(_arg1),(_arg2))
@@ -746,8 +746,8 @@
temporary. This effectively converts an arbitrary expression into
an atom. */
static IRAtom* assignNew ( MCEnv* mce, IRType ty, IRExpr* e ) {
- IRTemp t = newIRTemp(mce->bb->stmts->tyenv, ty);
- assign(mce->bb->stmts, t, e);
+ IRTemp t = newIRTemp(mce->bb->tyenv, mce->bb->stmts, ty);
+ assign(mce->bb, t, e);
return mkexpr(t);
}

@@ -982,7 +982,7 @@
/* Note, dst_ty is a shadow type, not an original type. */
/* First of all, collapse vbits down to a single bit. */
tl_assert(isShadowAtom(mce,vbits));
- ty = typeOfIRExpr(mce->bb->stmts, vbits);
+ ty = typeOfIRExpr(mce->bb->tyenv, vbits);
tmp1 = NULL;
switch (ty) {
case Ity_I1:
@@ -1074,7 +1074,7 @@
tl_assert(isShadowAtom(mce, vatom));
tl_assert(sameKindedAtoms(atom, vatom));

- ty = typeOfIRExpr(mce->bb->stmts, vatom);
+ ty = typeOfIRExpr(mce->bb->tyenv, vatom);

/* sz is only used for constructing the error message */
sz = ty==Ity_I1 ? 0 : sizeofIRType(ty);
@@ -1114,7 +1114,7 @@
}
di->guard = cond;
setHelperAnns( mce, di );
- stmt( mce->bb->stmts, IRStmt_Dirty(di));
+ stmt( mce->bb, IRStmt_Dirty(di));

/* Set the shadow tmp to be defined. First, update the
orig->shadow tmp mapping to reflect the fact that this shadow is
@@ -1124,8 +1124,8 @@
if (vatom->tag == Iex_RdTmp) {
tl_assert(atom->tag == Iex_RdTmp);
newShadowTmp(mce, atom->Iex.RdTmp.tmp);
- assign(mce->bb->stmts, findShadowTmp(mce, atom->Iex.RdTmp.tmp),
- definedOfType(ty));
+ assign(mce->bb, findShadowTmp(mce, atom->Iex.RdTmp.tmp),
+ definedOfType(ty));
}
}

@@ -1184,7 +1184,7 @@
tl_assert(isShadowAtom(mce, vatom));
}

- ty = typeOfIRExpr(mce->bb->stmts, vatom);
+ ty = typeOfIRExpr(mce->bb->tyenv, vatom);
tl_assert(ty != Ity_I1);
if (isAlwaysDefd(mce, offset, sizeofIRType(ty))) {
/* later: no ... */
@@ -1192,7 +1192,7 @@
/* complainIfUndefined(mce, atom); */
} else {
/* Do a plain shadow Put. */
- stmt(mce->bb->stmts, IRStmt_Put(offset + mce->layout->total_sizeB, vatom));
+ stmt( mce->bb, IRStmt_Put( offset + mce->layout->total_sizeB, vatom ) );
}
}

@@ -1227,7 +1227,7 @@
IRRegArray* new_descr
= mkIRRegArray( descr->base + mce->layout->total_sizeB,
tyS, descr->nElems);
- stmt(mce->bb->stmts, IRStmt_PutI(mkIRPutI(new_descr, ix, bias, vatom)));
+ stmt( mce->bb, IRStmt_PutI( mkIRPutI( new_descr, ix, bias, vatom ) ));
}
}

@@ -2096,12 +2096,12 @@

/* We need to have a place to park the V bits we're just about to
read. */
- datavbits = newIRTemp(mce->bb->stmts->tyenv, ty);
+ datavbits = newIRTemp(mce->bb->tyenv, mce->bb->stmts, ty);
di = unsafeIRDirty_1_N( datavbits,
1/*regparms*/, hname, helper,
mkIRExprVec_1( addrAct ));
setHelperAnns( mce, di );
- stmt(mce->bb->stmts, IRStmt_Dirty(di));
+ stmt( mce->bb, IRStmt_Dirty(di) );

return mkexpr(datavbits);
}
@@ -2147,7 +2147,7 @@
vbitsC = expr2vbits(mce, cond);
vbits0 = expr2vbits(mce, iffalse);
vbits1 = expr2vbits(mce, iftrue);
- ty = typeOfIRExpr(mce->bb->stmts, vbits0);
+ ty = typeOfIRExpr(mce->bb->tyenv, vbits0);

return
mkUifU(mce, ty, assignNew(mce, ty, IRExpr_ITE(cond, vbits1, vbits0)),
@@ -2172,7 +2172,7 @@
return IRExpr_RdTmp( findShadowTmp(mce, e->Iex.RdTmp.tmp) );

case Iex_Const:
- return definedOfType(shadowType(typeOfIRExpr(mce->bb->stmts, e)));
+ return definedOfType(shadowType(typeOfIRExpr(mce->bb->tyenv, e)));

case Iex_Binop:
return expr2vbits_Binop(
@@ -2219,7 +2219,7 @@
/* vatom is vbits-value and as such can only have a shadow type. */
tl_assert(isShadowAtom(mce,vatom));

- ty = typeOfIRExpr(mce->bb->stmts, vatom);
+ ty = typeOfIRExpr(mce->bb->tyenv, vatom);
tyH = mce->hWordTy;

if (tyH == Ity_I32) {
@@ -2277,7 +2277,7 @@
tl_assert(isOriginalAtom(mce,addr));
tl_assert(isShadowAtom(mce,vdata));

- ty = typeOfIRExpr(mce->bb->stmts, vdata);
+ ty = typeOfIRExpr(mce->bb->tyenv, vdata);

/* First, emit a definedness test for the address. This also sets
the address (shadow) to 'defined' following the test. */
@@ -2322,8 +2322,8 @@

setHelperAnns( mce, diLo64 );
setHelperAnns( mce, diHi64 );
- stmt(mce->bb->stmts, IRStmt_Dirty(diLo64));
- stmt(mce->bb->stmts, IRStmt_Dirty(diHi64));
+ stmt( mce->bb, IRStmt_Dirty(diLo64) );
+ stmt( mce->bb, IRStmt_Dirty(diHi64) );

} else {

@@ -2350,7 +2350,7 @@
zwidenToHostWord( mce, vdata )));
}
setHelperAnns( mce, di );
- stmt(mce->bb->stmts, IRStmt_Dirty(di));
+ stmt( mce->bb, IRStmt_Dirty(di) );
}

}
@@ -2443,7 +2443,7 @@
tl_assert(d->mAddr);
complainIfUndefined(mce, d->mAddr);

- tyAddr = typeOfIRExpr(mce->bb->stmts, d->mAddr);
+ tyAddr = typeOfIRExpr(mce->bb->tyenv, d->mAddr);
tl_assert(tyAddr == Ity_I32 || tyAddr == Ity_I64);
tl_assert(tyAddr == mce->hWordTy); /* not really right */
}
@@ -2480,10 +2480,10 @@
results to all destinations. */

/* Outputs: the destination temporary, if there is one. */
- if (!isIRTempInvalid(d->tmp)) {
+ if (d->tmp != IRTemp_INVALID) {
dst = findShadowTmp(mce, d->tmp);
- tyDst = typeOfIRTemp(mce->bb->stmts, d->tmp);
- assign(mce->bb->stmts, dst, mkPCastTo(mce, tyDst, curr));
+ tyDst = typeOfIRTemp(mce->bb->tyenv, d->tmp);
+ assign( mce->bb, dst, mkPCastTo( mce, tyDst, curr) );
}

/* Outputs: guest state that we write or modify. */
@@ -2619,25 +2619,24 @@

/* Bool hasBogusLiterals = False; */

- Int first_stmt;
MCEnv mce;

/* Set up BB */
- IRSB* bb = emptyIRSB();
- bb->id_seq = bb_in->id_seq;
- bb->stmts->tyenv = deepCopyIRTypeEnv(bb_in->stmts->tyenv);
- bb->next = deepCopyIRExpr(bb_in->next);
- bb->jumpkind = bb_in->jumpkind;
+ IRSB* bb = emptyIRSB();
+ bb->tyenv = deepCopyIRTypeEnv(bb_in->tyenv);
+ bb->id_seq = bb_in->id_seq;
+ bb->next = deepCopyIRExpr(bb_in->next);
+ bb->jumpkind = bb_in->jumpkind;

/* Set up the running environment. Only .bb is modified as we go
along. */
mce.bb = bb;
mce.layout = layout;
- mce.n_originalTmps = bb->stmts->tyenv->types_used;
+ mce.n_originalTmps = bb->tyenv->used;
mce.hWordTy = hWordTy;
mce.tmpMap = LibVEX_Alloc(mce.n_originalTmps * sizeof(IRTemp));
for (UInt i = 0; i < mce.n_originalTmps; i++)
- mce.tmpMap[i] = IRTemp_INVALID();
+ mce.tmpMap[i] = IRTemp_INVALID;

tl_assert(isFlatIRSB(bb_in));

@@ -2657,7 +2656,7 @@
}
}
*/
- first_stmt = bb->stmts->stmts_used;
+ UInt first_stmt = bb->stmts->stmts_used;

if (verboze) {
ppIRStmt(st);
@@ -2667,8 +2666,8 @@
switch (st->tag) {

case Ist_WrTmp:
- assign(bb->stmts, findShadowTmp(&mce, st->Ist.WrTmp.tmp),
- expr2vbits( &mce, st->Ist.WrTmp.data));
+ assign( bb, findShadowTmp(&mce, st->Ist.WrTmp.tmp),
+ expr2vbits( &mce, st->Ist.WrTmp.data) );
break;

case Ist_Put:
@@ -2715,7 +2714,8 @@

if (verboze) {
for (UInt j = first_stmt; j < bb->stmts->stmts_used; j++) {
- ppIRStmt_wrk(bb->stmts->stmts[j], 1);
+ VG_(printf)(" ");
+ ppIRStmt(bb->stmts->stmts[j]);
VG_(printf)("\n");
}
VG_(printf)("\n");
@@ -2726,7 +2726,7 @@
}

/* Now we need to complain if the jump target is undefined. */
- first_stmt = bb->stmts->stmts_used;
+ UInt first_stmt = bb->stmts->stmts_used;

if (verboze) {
VG_(printf)("bb->next = ");
@@ -2738,7 +2738,8 @@

if (verboze) {
for (UInt j = first_stmt; j < bb->stmts->stmts_used; j++) {
- ppIRStmt_wrk(bb->stmts->stmts[j], 1);
+ VG_(printf)(" ");
+ ppIRStmt(bb->stmts->stmts[j]);
VG_(printf)("\n");
}
VG_(printf)("\n");

Loading...