harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail Fursov" <mike.fur...@gmail.com>
Subject Re: [Drlvm][Opt]Some Questions about LIR expressions
Date Thu, 01 Feb 2007 09:34:54 GMT
Hi Zouqiong,
here are answers:

On 1/31/07, zouqiong <ustczz@gmail.com> wrote:
>
> Sorry, I still have two questions.
> 1.
>
> What is the difference between newOpnd, newImmOpnd and newMemOpnd?


Here is an extraction from sources that describes the difference:
Opnd * IRManager::newImmOpnd(Type * type, int64 immediate)
{
    Opnd * opnd = newOpnd(type);
    opnd->assignImmValue(immediate);
    return opnd;
}

Opnd * IRManager::newMemOpnd(Type * type, MemOpndKind k, Opnd * base, Opnd *
index, Opnd * scale, Opnd * displacement, RegName segReg)
{
    Opnd * opnd = newOpnd(type);
    opnd->assignMemLocation(k,base,index,scale,displacement);
        if (segReg != RegName_Null)
            opnd->setSegReg(segReg);
    return opnd;
}


So newImmOpnd and newMemOpnd are simple wrappers for newOpnd



Opnd* baseOpnd= irManager.newImmOpnd(typeManager.getUnmanagedPtrType(
>                         typeManager.getUIntPtrType()),
> (POINTER_SIZE_INT)&current_obj_acc_record_pointer);
> Opnd* RefOpnd = irManager.newMemOpnd(typeManager.getUIntPtrType(),
>                                 MemOpndKind_Heap,
> baseOpnd_current_obj_acc_record_pointer, NULL, NULL, NULL);
> appendInsts(irManager.newCopyPseudoInst(Mnemonic_MOV, RefOpnd,
> (Opnd*)elemBase));
>
>
> Opnd* memOpnd = irManager.newMemOpnd(typeManager.getUIntPtrType(),
>                          MemOpndKind_Heap,
> baseOpnd_current_obj_acc_record_pointer, NULL, NULL, NULL);
> appendInsts(irManager.newInst(Mnemonic_SUB,memOpnd, irManager.newImmOpnd(
> typeManager.getUInt32Type(), 16)));
>
>
> What's the difference between memOpnd and baseOpnd?


Mem-opnd contains up to 4 opnds: base,index,scale,and displacement. So
mem-opnd is used to support complex address form in LIR.


I look the code emitted as below,  It seems that they have no difference.
>
> mov 0xb40534, %esi
> mov %ebp, (%esi)
>
> mov 0xb40534, %ebp
> subl 0x10, 0x0(%ebp)
>
> 2. If I want to generate such code:
> mov 0xb400534, %esi
> mov (%esi), %esi
>
> How should I write the LIR?


If you want to preserve register, use newRegOpnd with the register name. It
will add additional constraint to opnd.
If you want save value by address, create new mem-opnd with a base opnd
contains address and use newCopyPseudoInst to put new value to the address
represented by mem-opnd.


Feel free to ask more if you have questions..
-- 
Mikhail Fursov

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message