Discussion:
Valgrind: r16283 - /branches/VALGRIND_JIT_HACKS/memcheck/mc_translate.c
(too old to reply)
s***@valgrind.org
2017-03-23 17:12:48 UTC
Permalink
Raw Message
Author: iraisr
Date: Thu Mar 23 17:12:48 2017
New Revision: 16283

Log:
Use iteration rathen than recursion for accessing parent stuff.

Modified:
branches/VALGRIND_JIT_HACKS/memcheck/mc_translate.c

Modified: branches/VALGRIND_JIT_HACKS/memcheck/mc_translate.c
==============================================================================
--- branches/VALGRIND_JIT_HACKS/memcheck/mc_translate.c (original)
+++ branches/VALGRIND_JIT_HACKS/memcheck/mc_translate.c Thu Mar 23 17:12:48 2017
@@ -277,24 +277,26 @@
so far exists, allocate one. */
static IRTemp findShadowTmpV ( MCEnv* mce, IRTemp orig )
{
- if (mce->id == orig.id) {
- /* VG_(indexXA) range-checks 'orig', hence no need to check here. */
- TempMapEnt* ent = (TempMapEnt*) VG_(indexXA)(mce->tmpMap, orig.index);
+ while (mce->id != orig.id) {
+ mce = mce->parent;
+ tl_assert(mce != NULL);
+ }
+ tl_assert(mce->id == orig.id);
+
+ /* VG_(indexXA) range-checks 'orig', hence no need to check here. */
+ TempMapEnt* ent = (TempMapEnt*) VG_(indexXA)(mce->tmpMap, orig.index);
+ tl_assert(ent->kind == Orig);
+ if (isIRTempInvalid(ent->shadowV)) {
+ IRTemp tmpV = newTemp(mce, shadowTypeV(mce->tyenv->types[orig.index]),
+ VSh);
+ /* newTemp may cause mce->tmpMap to resize, hence previous results
+ from VG_(indexXA) are invalid. */
+ ent = (TempMapEnt*) VG_(indexXA)(mce->tmpMap, orig.index);
tl_assert(ent->kind == Orig);
- if (isIRTempInvalid(ent->shadowV)) {
- IRTemp tmpV = newTemp(mce, shadowTypeV(mce->tyenv->types[orig.index]),
- VSh);
- /* newTemp may cause mce->tmpMap to resize, hence previous results
- from VG_(indexXA) are invalid. */
- ent = (TempMapEnt*) VG_(indexXA)(mce->tmpMap, orig.index);
- tl_assert(ent->kind == Orig);
- tl_assert(isIRTempInvalid(ent->shadowV));
- ent->shadowV = tmpV;
- }
- return ent->shadowV;
- } else {
- return findShadowTmpV(mce->parent, orig);
+ tl_assert(isIRTempInvalid(ent->shadowV));
+ ent->shadowV = tmpV;
}
+ return ent->shadowV;
}

/* Allocate a new shadow for the given original tmp. This means any
@@ -384,12 +386,14 @@
if (a1->tag == Iex_Const)
return True;
if (a1->tag == Iex_RdTmp) {
- if (mce->id == a1->Iex.RdTmp.tmp.id) {
- TempMapEnt* ent = VG_(indexXA)(mce->tmpMap, a1->Iex.RdTmp.tmp.index);
- return ent->kind == Orig;
- } else {
- return isOriginalAtom(mce->parent, a1);
+ while (mce->id != a1->Iex.RdTmp.tmp.id) {
+ mce = mce->parent;
+ tl_assert(mce != NULL);
}
+ tl_assert(mce->id == a1->Iex.RdTmp.tmp.id);
+
+ TempMapEnt* ent = VG_(indexXA)(mce->tmpMap, a1->Iex.RdTmp.tmp.index);
+ return ent->kind == Orig;
}
return False;
}
@@ -401,12 +405,14 @@
if (a1->tag == Iex_Const)
return True;
if (a1->tag == Iex_RdTmp) {
- if (mce->id == a1->Iex.RdTmp.tmp.id) {
- TempMapEnt* ent = VG_(indexXA)(mce->tmpMap, a1->Iex.RdTmp.tmp.index);
- return ent->kind == VSh || ent->kind == BSh;
- } else {
- return isShadowAtom(mce->parent, a1);
+ while (mce->id != a1->Iex.RdTmp.tmp.id) {
+ mce = mce->parent;
+ tl_assert(mce != NULL);
}
+ tl_assert(mce->id == a1->Iex.RdTmp.tmp.id);
+
+ TempMapEnt* ent = VG_(indexXA)(mce->tmpMap, a1->Iex.RdTmp.tmp.index);
+ return ent->kind == VSh || ent->kind == BSh;
}
return False;
}
@@ -7045,23 +7051,25 @@
/* Almost identical to findShadowTmpV. */
static IRTemp findShadowTmpB ( MCEnv* mce, IRTemp orig )
{
- if (mce->id == orig.id) {
- /* VG_(indexXA) range-checks 'orig', hence no need to check here. */
- TempMapEnt* ent = (TempMapEnt*) VG_(indexXA)(mce->tmpMap, orig.index);
+ while (mce->id != orig.id) {
+ mce = mce->parent;
+ tl_assert(mce != NULL);
+ }
+ tl_assert(mce->id == orig.id);
+
+ /* VG_(indexXA) range-checks 'orig', hence no need to check here. */
+ TempMapEnt* ent = (TempMapEnt*) VG_(indexXA)(mce->tmpMap, orig.index);
+ tl_assert(ent->kind == Orig);
+ if (isIRTempInvalid(ent->shadowB)) {
+ IRTemp tmpB = newTemp( mce, Ity_I32, BSh );
+ /* newTemp may cause mce->tmpMap to resize, hence previous results
+ from VG_(indexXA) are invalid. */
+ ent = (TempMapEnt*) VG_(indexXA)(mce->tmpMap, orig.index);
tl_assert(ent->kind == Orig);
- if (isIRTempInvalid(ent->shadowB)) {
- IRTemp tmpB = newTemp( mce, Ity_I32, BSh );
- /* newTemp may cause mce->tmpMap to resize, hence previous results
- from VG_(indexXA) are invalid. */
- ent = (TempMapEnt*) VG_(indexXA)(mce->tmpMap, orig.index);
- tl_assert(ent->kind == Orig);
- tl_assert(isIRTempInvalid(ent->shadowB));
- ent->shadowB = tmpB;
- }
- return ent->shadowB;
- } else {
- return findShadowTmpB(mce->parent, orig);
+ tl_assert(isIRTempInvalid(ent->shadowB));
+ ent->shadowB = tmpB;
}
+ return ent->shadowB;
}

static IRAtom* gen_maxU32 ( MCEnv* mce, IRAtom* b1, IRAtom* b2 )

Loading...