From 02aa9676944504f74cb5f0ef908141afa9f92527 Mon Sep 17 00:00:00 2001 From: Alexander Astapchuk Date: Fri, 23 Mar 2007 12:06:58 +0600 Subject: [PATCH] [drlvm][opt]Code quality improvement, allows to address memory as [imm32] on IA32 --- vm/jitrino/src/codegenerator/ia32/Ia32Inst.cpp | 28 +++++++++++++++++++++-- vm/jitrino/src/codegenerator/ia32/Ia32Inst.h | 6 ++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/vm/jitrino/src/codegenerator/ia32/Ia32Inst.cpp b/vm/jitrino/src/codegenerator/ia32/Ia32Inst.cpp index fa2a6a1..c8cc1f0 100644 --- a/vm/jitrino/src/codegenerator/ia32/Ia32Inst.cpp +++ b/vm/jitrino/src/codegenerator/ia32/Ia32Inst.cpp @@ -16,7 +16,6 @@ */ /** * @author Vyacheslav P. Shakin - * @version $Revision: 1.14.12.1.4.4 $ */ #include "Ia32Inst.h" @@ -101,11 +100,15 @@ bool Opnd::replaceMemOpndSubOpnd(Opnd * opndOld, Opnd * opndNew) bool replaced = false; if (memOpndKind != MemOpndKind_Null){ assert(isPlacedIn(OpndKind_Mem)); - for (uint32 i=0; iid]!=NULL){ setMemOpndSubOpnd((MemOpndSubOpndKind)i, opndMap[memOpndSubOpnds[i]->id]); replaced = true; } + } + if (replaced) { + normalizeMemSubOpnds(); + } } return replaced; } +void Opnd::normalizeMemSubOpnds(void) +{ + if (!isPlacedIn(OpndKind_Mem)) { + return; + } + Opnd* base = getMemOpndSubOpnd(MemOpndSubOpndKind_Base); + Opnd* disp = getMemOpndSubOpnd(MemOpndSubOpndKind_Displacement); + if (base != NULL && base->isPlacedIn(OpndKind_Imm)) { + assert(disp == NULL || !disp->isPlacedIn(OpndKind_Imm)); + // can't call setMemOpndSubOpnd() as it fights against zero opnd. + memOpndSubOpnds[MemOpndSubOpndKind_Displacement] = base;//== setMemOpndSubOpnd(MemOpndSubOpndKind_Displacement, base); + memOpndSubOpnds[MemOpndSubOpndKind_Base] = disp; //==setMemOpndSubOpnd(MemOpndSubOpndKind_Base, disp); + } +} + #ifdef _DEBUG //_________________________________________________________________________________________________ void Opnd::checkConstraints() diff --git a/vm/jitrino/src/codegenerator/ia32/Ia32Inst.h b/vm/jitrino/src/codegenerator/ia32/Ia32Inst.h index c4ec267..252f034 100644 --- a/vm/jitrino/src/codegenerator/ia32/Ia32Inst.h +++ b/vm/jitrino/src/codegenerator/ia32/Ia32Inst.h @@ -16,7 +16,6 @@ */ /** * @author Vyacheslav P. Shakin - * @version $Revision: 1.18.12.2.4.3 $ */ #ifndef _IA32_INST_H_ @@ -325,6 +324,11 @@ public: protected: bool replaceMemOpndSubOpnd(Opnd * opndOld, Opnd * opndNew); bool replaceMemOpndSubOpnds(Opnd * const * opndMap); + /** + * 'Normalizes' memory sub opnds. That is ensures that an immediate is + * placed at the displacement, and a register gets placed ad the base. + */ + void normalizeMemSubOpnds(void); void addRefCount(uint32& index, uint32 blockExecCount); -- 1.5.0.rc4