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

Gary Benson gbenson at redhat.com
Mon Jun 30 06:10:23 PDT 2008

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
        lwarx $tmp, 0, $ptr
        cmpw $oldval, $tmp
        bne- exit
        stwcx. $newval, 0, $ptr
        bne- loop



More information about the llvm-dev mailing list