llvm.org GIT mirror llvm / 4e9485d
Add 'lock' prefix output support in assembly printer - Instead of embedding 'lock' into each mnemonic of atomic instructions except 'xchg', we teach X86 assembly printer to output 'lock' prefix similar to or consistent with code emitter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164659 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Liao 8 years ago
3 changed file(s) with 38 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
1414 #define DEBUG_TYPE "asm-printer"
1515 #include "X86ATTInstPrinter.h"
1616 #include "X86InstComments.h"
17 #include "MCTargetDesc/X86BaseInfo.h"
1718 #include "MCTargetDesc/X86MCTargetDesc.h"
1819 #include "llvm/MC/MCInst.h"
1920 #include "llvm/MC/MCAsmInfo.h"
3738
3839 void X86ATTInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
3940 StringRef Annot) {
41 const MCInstrDesc &Desc = MII.get(MI->getOpcode());
42 uint64_t TSFlags = Desc.TSFlags;
43
44 if (TSFlags & X86II::LOCK)
45 OS << "\tlock\n";
46
4047 // Try to print any aliases first.
4148 if (!printAliasInstr(MI, OS))
4249 printInstruction(MI, OS);
1414 #define DEBUG_TYPE "asm-printer"
1515 #include "X86IntelInstPrinter.h"
1616 #include "X86InstComments.h"
17 #include "MCTargetDesc/X86BaseInfo.h"
1718 #include "MCTargetDesc/X86MCTargetDesc.h"
1819 #include "llvm/MC/MCInst.h"
1920 #include "llvm/MC/MCExpr.h"
3132
3233 void X86IntelInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
3334 StringRef Annot) {
35 const MCInstrDesc &Desc = MII.get(MI->getOpcode());
36 uint64_t TSFlags = Desc.TSFlags;
37
38 if (TSFlags & X86II::LOCK)
39 OS << "\tlock\n";
40
3441 printInstruction(MI, OS);
3542
3643 // Next always print the annotation.
560560 // TODO: Get this to fold the constant into the instruction.
561561 let isCodeGenOnly = 1, Defs = [EFLAGS] in
562562 def OR32mrLocked : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$zero),
563 "lock\n\t"
564563 "or{l}\t{$zero, $dst|$dst, $zero}",
565564 [], IIC_ALU_MEM>, Requires<[In32BitMode]>, LOCK;
566565
580579 def #NAME#8mr : I<{RegOpc{7}, RegOpc{6}, RegOpc{5}, RegOpc{4},
581580 RegOpc{3}, RegOpc{2}, RegOpc{1}, 0 },
582581 MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
583 !strconcat("lock\n\t", mnemonic, "{b}\t",
582 !strconcat(mnemonic, "{b}\t",
584583 "{$src2, $dst|$dst, $src2}"),
585584 [], IIC_ALU_NONMEM>, LOCK;
586585 def #NAME#16mr : I<{RegOpc{7}, RegOpc{6}, RegOpc{5}, RegOpc{4},
587586 RegOpc{3}, RegOpc{2}, RegOpc{1}, 1 },
588587 MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
589 !strconcat("lock\n\t", mnemonic, "{w}\t",
588 !strconcat(mnemonic, "{w}\t",
590589 "{$src2, $dst|$dst, $src2}"),
591590 [], IIC_ALU_NONMEM>, OpSize, LOCK;
592591 def #NAME#32mr : I<{RegOpc{7}, RegOpc{6}, RegOpc{5}, RegOpc{4},
593592 RegOpc{3}, RegOpc{2}, RegOpc{1}, 1 },
594593 MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
595 !strconcat("lock\n\t", mnemonic, "{l}\t",
594 !strconcat(mnemonic, "{l}\t",
596595 "{$src2, $dst|$dst, $src2}"),
597596 [], IIC_ALU_NONMEM>, LOCK;
598597 def #NAME#64mr : RI<{RegOpc{7}, RegOpc{6}, RegOpc{5}, RegOpc{4},
599598 RegOpc{3}, RegOpc{2}, RegOpc{1}, 1 },
600599 MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
601 !strconcat("lock\n\t", mnemonic, "{q}\t",
600 !strconcat(mnemonic, "{q}\t",
602601 "{$src2, $dst|$dst, $src2}"),
603602 [], IIC_ALU_NONMEM>, LOCK;
604603
605604 def #NAME#8mi : Ii8<{ImmOpc{7}, ImmOpc{6}, ImmOpc{5}, ImmOpc{4},
606605 ImmOpc{3}, ImmOpc{2}, ImmOpc{1}, 0 },
607606 ImmMod, (outs), (ins i8mem :$dst, i8imm :$src2),
608 !strconcat("lock\n\t", mnemonic, "{b}\t",
607 !strconcat(mnemonic, "{b}\t",
609608 "{$src2, $dst|$dst, $src2}"),
610609 [], IIC_ALU_MEM>, LOCK;
611610
612611 def #NAME#16mi : Ii16<{ImmOpc{7}, ImmOpc{6}, ImmOpc{5}, ImmOpc{4},
613612 ImmOpc{3}, ImmOpc{2}, ImmOpc{1}, 1 },
614613 ImmMod, (outs), (ins i16mem :$dst, i16imm :$src2),
615 !strconcat("lock\n\t", mnemonic, "{w}\t",
614 !strconcat(mnemonic, "{w}\t",
616615 "{$src2, $dst|$dst, $src2}"),
617616 [], IIC_ALU_MEM>, OpSize, LOCK;
618617
619618 def #NAME#32mi : Ii32<{ImmOpc{7}, ImmOpc{6}, ImmOpc{5}, ImmOpc{4},
620619 ImmOpc{3}, ImmOpc{2}, ImmOpc{1}, 1 },
621620 ImmMod, (outs), (ins i32mem :$dst, i32imm :$src2),
622 !strconcat("lock\n\t", mnemonic, "{l}\t",
621 !strconcat(mnemonic, "{l}\t",
623622 "{$src2, $dst|$dst, $src2}"),
624623 [], IIC_ALU_MEM>, LOCK;
625624
626625 def #NAME#64mi32 : RIi32<{ImmOpc{7}, ImmOpc{6}, ImmOpc{5}, ImmOpc{4},
627626 ImmOpc{3}, ImmOpc{2}, ImmOpc{1}, 1 },
628627 ImmMod, (outs), (ins i64mem :$dst, i64i32imm :$src2),
629 !strconcat("lock\n\t", mnemonic, "{q}\t",
628 !strconcat(mnemonic, "{q}\t",
630629 "{$src2, $dst|$dst, $src2}"),
631630 [], IIC_ALU_MEM>, LOCK;
632631
633632 def #NAME#16mi8 : Ii8<{ImmOpc8{7}, ImmOpc8{6}, ImmOpc8{5}, ImmOpc8{4},
634633 ImmOpc8{3}, ImmOpc8{2}, ImmOpc8{1}, 1 },
635634 ImmMod, (outs), (ins i16mem :$dst, i16i8imm :$src2),
636 !strconcat("lock\n\t", mnemonic, "{w}\t",
635 !strconcat(mnemonic, "{w}\t",
637636 "{$src2, $dst|$dst, $src2}"),
638637 [], IIC_ALU_MEM>, OpSize, LOCK;
639638 def #NAME#32mi8 : Ii8<{ImmOpc8{7}, ImmOpc8{6}, ImmOpc8{5}, ImmOpc8{4},
640639 ImmOpc8{3}, ImmOpc8{2}, ImmOpc8{1}, 1 },
641640 ImmMod, (outs), (ins i32mem :$dst, i32i8imm :$src2),
642 !strconcat("lock\n\t", mnemonic, "{l}\t",
641 !strconcat(mnemonic, "{l}\t",
643642 "{$src2, $dst|$dst, $src2}"),
644643 [], IIC_ALU_MEM>, LOCK;
645644 def #NAME#64mi8 : RIi8<{ImmOpc8{7}, ImmOpc8{6}, ImmOpc8{5}, ImmOpc8{4},
646645 ImmOpc8{3}, ImmOpc8{2}, ImmOpc8{1}, 1 },
647646 ImmMod, (outs), (ins i64mem :$dst, i64i8imm :$src2),
648 !strconcat("lock\n\t", mnemonic, "{q}\t",
647 !strconcat(mnemonic, "{q}\t",
649648 "{$src2, $dst|$dst, $src2}"),
650649 [], IIC_ALU_MEM>, LOCK;
651650
665664 let Defs = [EFLAGS], mayLoad = 1, mayStore = 1, isCodeGenOnly = 1 in {
666665
667666 def #NAME#8m : I
668 !strconcat("lock\n\t", mnemonic, "{b}\t$dst"),
667 !strconcat(mnemonic, "{b}\t$dst"),
669668 [], IIC_UNARY_MEM>, LOCK;
670669 def #NAME#16m : I
671 !strconcat("lock\n\t", mnemonic, "{w}\t$dst"),
670 !strconcat(mnemonic, "{w}\t$dst"),
672671 [], IIC_UNARY_MEM>, OpSize, LOCK;
673672 def #NAME#32m : I
674 !strconcat("lock\n\t", mnemonic, "{l}\t$dst"),
673 !strconcat(mnemonic, "{l}\t$dst"),
675674 [], IIC_UNARY_MEM>, LOCK;
676675 def #NAME#64m : RI
677 !strconcat("lock\n\t", mnemonic, "{q}\t$dst"),
676 !strconcat(mnemonic, "{q}\t$dst"),
678677 [], IIC_UNARY_MEM>, LOCK;
679678 }
680679 }
688687 InstrItinClass itin> {
689688 let isCodeGenOnly = 1 in {
690689 def #NAME# : I
691 !strconcat("lock\n\t", mnemonic, "\t$ptr"),
690 !strconcat(mnemonic, "\t$ptr"),
692691 [(frag addr:$ptr)], itin>, TB, LOCK;
693692 }
694693 }
699698 let isCodeGenOnly = 1 in {
700699 let Defs = [AL, EFLAGS], Uses = [AL] in
701700 def #NAME#8 : I
702 !strconcat("lock\n\t", mnemonic,
703 "{b}\t{$swap, $ptr|$ptr, $swap}"),
701 !strconcat(mnemonic, "{b}\t{$swap, $ptr|$ptr, $swap}"),
704702 [(frag addr:$ptr, GR8:$swap, 1)], itin8>, TB, LOCK;
705703 let Defs = [AX, EFLAGS], Uses = [AX] in
706704 def #NAME#16 : I
707 !strconcat("lock\n\t", mnemonic,
708 "{w}\t{$swap, $ptr|$ptr, $swap}"),
705 !strconcat(mnemonic, "{w}\t{$swap, $ptr|$ptr, $swap}"),
709706 [(frag addr:$ptr, GR16:$swap, 2)], itin>, TB, OpSize, LOCK;
710707 let Defs = [EAX, EFLAGS], Uses = [EAX] in
711708 def #NAME#32 : I
712 !strconcat("lock\n\t", mnemonic,
713 "{l}\t{$swap, $ptr|$ptr, $swap}"),
709 !strconcat(mnemonic, "{l}\t{$swap, $ptr|$ptr, $swap}"),
714710 [(frag addr:$ptr, GR32:$swap, 4)], itin>, TB, LOCK;
715711 let Defs = [RAX, EFLAGS], Uses = [RAX] in
716712 def #NAME#64 : RI
717 !strconcat("lock\n\t", mnemonic,
718 "{q}\t{$swap, $ptr|$ptr, $swap}"),
713 !strconcat(mnemonic, "{q}\t{$swap, $ptr|$ptr, $swap}"),
719714 [(frag addr:$ptr, GR64:$swap, 8)], itin>, TB, LOCK;
720715 }
721716 }
743738 let Constraints = "$val = $dst", Defs = [EFLAGS], isCodeGenOnly = 1 in {
744739 def #NAME#8 : I
745740 (ins GR8:$val, i8mem:$ptr),
746 !strconcat("lock\n\t", mnemonic,
747 "{b}\t{$val, $ptr|$ptr, $val}"),
741 !strconcat(mnemonic, "{b}\t{$val, $ptr|$ptr, $val}"),
748742 [(set GR8:$dst,
749743 (!cast(frag # "_8") addr:$ptr, GR8:$val))],
750744 itin8>;
751745 def #NAME#16 : I
752746 (ins GR16:$val, i16mem:$ptr),
753 !strconcat("lock\n\t", mnemonic,
754 "{w}\t{$val, $ptr|$ptr, $val}"),
747 !strconcat(mnemonic, "{w}\t{$val, $ptr|$ptr, $val}"),
755748 [(set
756749 GR16:$dst,
757750 (!cast(frag # "_16") addr:$ptr, GR16:$val))],
758751 itin>, OpSize;
759752 def #NAME#32 : I
760753 (ins GR32:$val, i32mem:$ptr),
761 !strconcat("lock\n\t", mnemonic,
762 "{l}\t{$val, $ptr|$ptr, $val}"),
754 !strconcat(mnemonic, "{l}\t{$val, $ptr|$ptr, $val}"),
763755 [(set
764756 GR32:$dst,
765757 (!cast(frag # "_32") addr:$ptr, GR32:$val))],
766758 itin>;
767759 def #NAME#64 : RI
768760 (ins GR64:$val, i64mem:$ptr),
769 !strconcat("lock\n\t", mnemonic,
770 "{q}\t{$val, $ptr|$ptr, $val}"),
761 !strconcat(mnemonic, "{q}\t{$val, $ptr|$ptr, $val}"),
771762 [(set
772763 GR64:$dst,
773764 (!cast(frag # "_64") addr:$ptr, GR64:$val))],