summaryrefslogtreecommitdiff
path: root/src/jit
diff options
context:
space:
mode:
authorBruce Forstall <brucefo@microsoft.com>2016-11-26 20:40:13 -0800
committerBruce Forstall <brucefo@microsoft.com>2016-11-28 09:58:14 -0800
commitd20a00d37cd833cec3bd5e46c66dcde07dd28f32 (patch)
tree732aea06b1ccf82ee22561c3d152de47c9db45f8 /src/jit
parent0c0e872d4ff27f37eecb8e24e1da89fa34975370 (diff)
downloadcoreclr-d20a00d37cd833cec3bd5e46c66dcde07dd28f32.tar.gz
coreclr-d20a00d37cd833cec3bd5e46c66dcde07dd28f32.tar.bz2
coreclr-d20a00d37cd833cec3bd5e46c66dcde07dd28f32.zip
Factor out common stack adjustment code
Diffstat (limited to 'src/jit')
-rw-r--r--src/jit/emitxarch.cpp234
-rw-r--r--src/jit/emitxarch.h12
2 files changed, 81 insertions, 165 deletions
diff --git a/src/jit/emitxarch.cpp b/src/jit/emitxarch.cpp
index 7c384aa762..cb81370c4a 100644
--- a/src/jit/emitxarch.cpp
+++ b/src/jit/emitxarch.cpp
@@ -3363,22 +3363,7 @@ void emitter::emitIns_R(instruction ins, emitAttr attr, regNumber reg)
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_pop)
- {
- emitCurStackLvl -= emitCntStackDepth;
- assert((int)emitCurStackLvl >= 0);
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
/*****************************************************************************
@@ -3516,34 +3501,10 @@ void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
if (reg == REG_ESP)
{
- if (emitCntStackDepth)
- {
- if (ins == INS_sub)
- {
- S_UINT32 newStackLvl(emitCurStackLvl);
- newStackLvl += S_UINT32(val);
- noway_assert(!newStackLvl.IsOverflow());
-
- emitCurStackLvl = newStackLvl.Value();
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_add)
- {
- S_UINT32 newStackLvl = S_UINT32(emitCurStackLvl) - S_UINT32(val);
- noway_assert(!newStackLvl.IsOverflow());
-
- emitCurStackLvl = newStackLvl.Value();
- }
- }
+ emitAdjustStackDepth(ins, val);
}
-
-#endif // !FEATURE_FIXED_OUT_ARGS
}
/*****************************************************************************
@@ -3596,17 +3557,7 @@ void emitter::emitIns_I(instruction ins, emitAttr attr, int val)
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
/*****************************************************************************
@@ -3705,22 +3656,7 @@ void emitter::emitIns_C(instruction ins, emitAttr attr, CORINFO_FIELD_HANDLE fld
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_pop)
- {
- emitCurStackLvl -= emitCntStackDepth;
- assert((int)emitCurStackLvl >= 0);
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
/*****************************************************************************
@@ -4399,22 +4335,7 @@ void emitter::emitIns_AR_R(
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_pop)
- {
- emitCurStackLvl -= emitCntStackDepth;
- assert((int)emitCurStackLvl >= 0);
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
void emitter::emitIns_AI_R(instruction ins, emitAttr attr, regNumber ireg, ssize_t disp)
@@ -4455,22 +4376,7 @@ void emitter::emitIns_AI_R(instruction ins, emitAttr attr, regNumber ireg, ssize
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_pop)
- {
- emitCurStackLvl -= emitCntStackDepth;
- assert((int)emitCurStackLvl >= 0);
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
void emitter::emitIns_I_ARR(instruction ins, emitAttr attr, int val, regNumber reg, regNumber rg2, int disp)
@@ -4587,22 +4493,7 @@ void emitter::emitIns_ARR_R(instruction ins, emitAttr attr, regNumber ireg, regN
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_pop)
- {
- emitCurStackLvl -= emitCntStackDepth;
- assert((int)emitCurStackLvl >= 0);
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
void emitter::emitIns_I_ARX(
@@ -4723,22 +4614,7 @@ void emitter::emitIns_ARX_R(
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_pop)
- {
- emitCurStackLvl -= emitCntStackDepth;
- assert((int)emitCurStackLvl >= 0);
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
void emitter::emitIns_I_AX(instruction ins, emitAttr attr, int val, regNumber reg, unsigned mul, int disp)
@@ -4854,22 +4730,7 @@ void emitter::emitIns_AX_R(instruction ins, emitAttr attr, regNumber ireg, regNu
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_pop)
- {
- emitCurStackLvl -= emitCntStackDepth;
- assert((int)emitCurStackLvl >= 0);
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
/*****************************************************************************
@@ -4913,22 +4774,7 @@ void emitter::emitIns_S(instruction ins, emitAttr attr, int varx, int offs)
dispIns(id);
emitCurIGsize += sz;
-#if !FEATURE_FIXED_OUT_ARGS
-
- if (ins == INS_push)
- {
- emitCurStackLvl += emitCntStackDepth;
-
- if (emitMaxStackDepth < emitCurStackLvl)
- emitMaxStackDepth = emitCurStackLvl;
- }
- else if (ins == INS_pop)
- {
- emitCurStackLvl -= emitCntStackDepth;
- assert((int)emitCurStackLvl >= 0);
- }
-
-#endif // !FEATURE_FIXED_OUT_ARGS
+ emitAdjustStackDepthPushPop(ins);
}
void emitter::emitIns_S_R(instruction ins, emitAttr attr, regNumber ireg, int varx, int offs)
@@ -5209,8 +5055,23 @@ void emitter::emitIns_J(instruction ins, BasicBlock* dst, int instrCount /* = 0
dispIns(id);
emitCurIGsize += sz;
+ emitAdjustStackDepthPushPop(ins);
+}
+
#if !FEATURE_FIXED_OUT_ARGS
+//------------------------------------------------------------------------
+// emitAdjustStackDepthPushPop: Adjust the current and maximum stack depth.
+//
+// Arguments:
+// ins - the instruction. Only INS_push and INS_pop adjust the stack depth.
+//
+// Notes:
+// 1. Alters emitCurStackLvl and possibly emitMaxStackDepth.
+// 2. emitCntStackDepth must be set (0 in prolog/epilog, one DWORD elsewhere)
+//
+void emitter::emitAdjustStackDepthPushPop(instruction ins)
+{
if (ins == INS_push)
{
emitCurStackLvl += emitCntStackDepth;
@@ -5218,10 +5079,53 @@ void emitter::emitIns_J(instruction ins, BasicBlock* dst, int instrCount /* = 0
if (emitMaxStackDepth < emitCurStackLvl)
emitMaxStackDepth = emitCurStackLvl;
}
+ else if (ins == INS_pop)
+ {
+ emitCurStackLvl -= emitCntStackDepth;
+ assert((int)emitCurStackLvl >= 0);
+ }
+}
-#endif // !FEATURE_FIXED_OUT_ARGS
+//------------------------------------------------------------------------
+// emitAdjustStackDepth: Adjust the current and maximum stack depth.
+//
+// Arguments:
+// ins - the instruction. Only INS_add and INS_sub adjust the stack depth.
+// It is assumed that the add/sub is on the stack pointer.
+// val - the number of bytes to add to or subtract from the stack pointer.
+//
+// Notes:
+// 1. Alters emitCurStackLvl and possibly emitMaxStackDepth.
+// 2. emitCntStackDepth must be set (0 in prolog/epilog, one DWORD elsewhere)
+//
+void emitter::emitAdjustStackDepth(instruction ins, ssize_t val)
+{
+ // If we're in the prolog or epilog, or otherwise not tracking the stack depth, just return.
+ if (emitCntStackDepth == 0)
+ return;
+
+ if (ins == INS_sub)
+ {
+ S_UINT32 newStackLvl(emitCurStackLvl);
+ newStackLvl += S_UINT32(val);
+ noway_assert(!newStackLvl.IsOverflow());
+
+ emitCurStackLvl = newStackLvl.Value();
+
+ if (emitMaxStackDepth < emitCurStackLvl)
+ emitMaxStackDepth = emitCurStackLvl;
+ }
+ else if (ins == INS_add)
+ {
+ S_UINT32 newStackLvl = S_UINT32(emitCurStackLvl) - S_UINT32(val);
+ noway_assert(!newStackLvl.IsOverflow());
+
+ emitCurStackLvl = newStackLvl.Value();
+ }
}
+#endif // EMIT_TRACK_STACK_DEPTH
+
/*****************************************************************************
*
* Add a call instruction (direct or indirect).
diff --git a/src/jit/emitxarch.h b/src/jit/emitxarch.h
index dfd7e6ec50..0cc3e9fb70 100644
--- a/src/jit/emitxarch.h
+++ b/src/jit/emitxarch.h
@@ -226,6 +226,18 @@ bool emitVerifyEncodable(instruction ins, emitAttr size, regNumber reg1, regNumb
bool emitInsCanOnlyWriteSSE2OrAVXReg(instrDesc* id);
+#if FEATURE_FIXED_OUT_ARGS
+void emitAdjustStackDepthPushPop(instruction ins)
+{
+}
+void emitAdjustStackDepth(instruction ins, ssize_t val)
+{
+}
+#else // !FEATURE_FIXED_OUT_ARGS
+void emitAdjustStackDepthPushPop(instruction ins);
+void emitAdjustStackDepth(instruction ins, ssize_t val);
+#endif // !FEATURE_FIXED_OUT_ARGS
+
/*****************************************************************************
*
* Convert between an index scale in bytes to a smaller encoding used for