[LLVMdev] Implementing llvm.atomic.cmp.swap.i32 on PowerPC

Evan Cheng evan.cheng at apple.com
Mon Jun 30 14:14:29 PDT 2008


You need to insert new basic blocks and update CFG to accomplish this.  
There is a hackish way to do this right now.  Add a pseudo instruction  
to represent this operation and mark it usesCustomDAGSchedInserter.  
This means the intrinsic is mapped to a single (pseudo) node. But it  
is then expanded into instructions that can span multiple basic  
blocks. See PPCTargetLowering::EmitInstrWithCustomInserter().

Evan

On Jun 30, 2008, at 6:10 AM, Gary Benson wrote:

> Chris Lattner wrote:
>> On Jun 27, 2008, at 8:27 AM, Gary Benson wrote:
>>> def CMP_UNRESw : Pseudo<(outs), (ins GPRC:$rA, GPRC:$rB, i32imm:
>>> $label),
>>>                          "cmpw $rA, $rB\n\tbne- La${label}_exit",
>>>                          [(PPCcmp_unres GPRC:$rA, GPRC:$rB, imm:
>>> $label)]>;
>>> }
>>>
>>> ...and I can't figure out the syntax for that.  Any suggestions?
>>
>> You have to write custom encoding logic in C++ for this.  This
>> should go in PPCCodeEmitter::emitBasicBlock.  I admit this isn't
>> very elegant.  A better solution would be to fix the lowering to
>> produce two instructions instead of this pseudo instruction.
>
> Hi Chris,
>
> I'd prefer to fix the lowering if possible; the pseudo instructions
> are only used in three places, so it shouldn't be a huge change.
> I need to generate labels in PPCTargetLowering::LowerAtomicCMP_SWAP
> however: how do I do that?  FWIW the code it needs to emit is:
>
>  ; inputs: ptr, oldval, newval
>  loop:
>        lwarx $tmp, 0, $ptr
>        cmpw $oldval, $tmp
>        bne- exit
>        stwcx. $newval, 0, $ptr
>        bne- loop
>  exit:
>        ...
>
>
> Cheers,
> Gary
>
> -- 
> http://gbenson.net/
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list