Index: lib/Target/AAP/CMakeLists.txt =================================================================== --- lib/Target/AAP/CMakeLists.txt +++ lib/Target/AAP/CMakeLists.txt @@ -3,6 +3,7 @@ tablegen(LLVM AAPGenRegisterInfo.inc -gen-register-info) tablegen(LLVM AAPGenInstrInfo.inc -gen-instr-info) tablegen(LLVM AAPGenMCCodeEmitter.inc -gen-emitter) +tablegen(LLVM AAPGenAsmWriter.inc -gen-asm-writer) tablegen(LLVM AAPGenAsmMatcher.inc -gen-asm-matcher) add_public_tablegen_target(AAPCommonTableGen) @@ -10,6 +11,7 @@ AAPTargetMachine.cpp ) +add_subdirectory(InstPrinter) add_subdirectory(MCTargetDesc) add_subdirectory(TargetInfo) add_subdirectory(AsmParser) Index: lib/Target/AAP/InstPrinter/AAPInstPrinter.h =================================================================== --- /dev/null +++ lib/Target/AAP/InstPrinter/AAPInstPrinter.h @@ -0,0 +1,57 @@ +//= AAPInstPrinter.h - Convert AAP MCInst to assembly syntax -------*- C++ -*-// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This class prints a AAP MCInst to a .s file. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_AAP_INSTPRINTER_AAPINSTPRINTER_H +#define LLVM_LIB_TARGET_AAP_INSTPRINTER_AAPINSTPRINTER_H + +#include "llvm/MC/MCInstPrinter.h" + +namespace llvm { +class MCOperand; + +class AAPInstPrinter : public MCInstPrinter { +public: + AAPInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, + const MCRegisterInfo &MRI) + : MCInstPrinter(MAI, MII, MRI) {} + + void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot, + const MCSubtargetInfo &STI) override; + + // Autogenerated by tblgen. + void printInstruction(const MCInst *MI, raw_ostream &O); + static const char *getRegisterName(unsigned RegNo); + + void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O, + const char *Modifier = nullptr); + + void printPCRelImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O, + const char *Modifier = nullptr); + + void printMemSrcOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O, + const char *Modifier = nullptr, + bool WithPreDec = false, bool WithPostInc = false); + + void printMemSrcPostIncOperand(const MCInst *MI, unsigned OpNo, + raw_ostream &O, + const char *Modifier = nullptr); + + void printMemSrcPreDecOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O, + const char *Modifier = nullptr); + +private: + void printRegister(unsigned RegNo, raw_ostream &O) const; +}; +} + +#endif Index: lib/Target/AAP/InstPrinter/AAPInstPrinter.cpp =================================================================== --- /dev/null +++ lib/Target/AAP/InstPrinter/AAPInstPrinter.cpp @@ -0,0 +1,103 @@ +//===-- AAPInstPrinter.cpp - Convert AAP MCInst to assembly syntax --------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This class prints an AAP MCInst to a .s file. +// +//===----------------------------------------------------------------------===// + +#include "AAPInstPrinter.h" +#include "AAP.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCInst.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FormattedStream.h" +using namespace llvm; + +#define DEBUG_TYPE "asm-printer" + +// Include the auto-generated portion of the assembly writer. +#include "AAPGenAsmWriter.inc" + +void AAPInstPrinter::printInst(const MCInst *MI, raw_ostream &O, + StringRef Annot, const MCSubtargetInfo &STI) { + printInstruction(MI, O); + printAnnotation(O, Annot); +} + +void AAPInstPrinter::printRegister(unsigned RegNo, raw_ostream &O) const { + O << '$' << getRegisterName(RegNo); +} + +void AAPInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, + raw_ostream &O, const char *Modifier) { + assert((Modifier == nullptr || Modifier[0] == 0) && "No modifiers supported"); + const MCOperand &Op = MI->getOperand(OpNo); + if (Op.isReg()) { + printRegister(Op.getReg(), O); + } else if (Op.isImm()) { + O << Op.getImm(); + } else { + assert(Op.isExpr() && "unknown operand kind in printOperand"); + O << *Op.getExpr(); + } +} + +void AAPInstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo, + raw_ostream &O, + const char *Modifier) { + const MCOperand &Op = MI->getOperand(OpNo); + if (Op.isImm()) { + O << Op.getImm(); + } else { + assert(Op.isExpr() && "unknown pcrel immediate operand"); + O << *Op.getExpr(); + } +} + +void AAPInstPrinter::printMemSrcOperand(const MCInst *MI, unsigned OpNo, + raw_ostream &O, const char *Modifier, + bool WithPreDec, bool WithPostInc) { + const MCOperand &Base = MI->getOperand(OpNo); + const MCOperand &Offset = MI->getOperand(OpNo + 1); + + if (WithPreDec) { + O << '-'; + } + + // Print register base field + if (Base.getReg()) { + printRegister(Base.getReg(), O); + } + + if (WithPostInc) { + O << '+'; + } + + O << ", "; + if (Offset.isImm()) { + O << Offset.getImm(); + } else if (Offset.isExpr()) { + O << *Offset.getExpr(); + } else { + llvm_unreachable("Expected immediate/expression in offset field"); + } +} + +void AAPInstPrinter::printMemSrcPostIncOperand(const MCInst *MI, unsigned OpNo, + raw_ostream &O, + const char *Modifier) { + printMemSrcOperand(MI, OpNo, O, Modifier, false, true); +} + +void AAPInstPrinter::printMemSrcPreDecOperand(const MCInst *MI, unsigned OpNo, + raw_ostream &O, + const char *Modifier) { + printMemSrcOperand(MI, OpNo, O, Modifier, true, false); +} Index: lib/Target/AAP/InstPrinter/CMakeLists.txt =================================================================== --- /dev/null +++ lib/Target/AAP/InstPrinter/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_library(LLVMAAPAsmPrinter + AAPInstPrinter.cpp + ) Index: lib/Target/AAP/InstPrinter/LLVMBuild.txt =================================================================== --- /dev/null +++ lib/Target/AAP/InstPrinter/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./lib/Target/AAP/InstPrinter/LLVMBuild.txt ---------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = AAPAsmPrinter +parent = AAP +required_libraries = MC Support +add_to_library_groups = AAP Index: lib/Target/AAP/LLVMBuild.txt =================================================================== --- lib/Target/AAP/LLVMBuild.txt +++ lib/Target/AAP/LLVMBuild.txt @@ -16,18 +16,18 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = AsmParser MCTargetDesc TargetInfo +subdirectories = AsmParser InstPrinter MCTargetDesc TargetInfo [component_0] type = TargetGroup name = AAP parent = Target -has_asmprinter = 0 +has_asmprinter = 1 has_asmparser = 1 [component_1] type = Library name = AAPCodeGen parent = AAP -required_libraries = AsmPrinter CodeGen Core MC SelectionDAG Support Target AAPInfo +required_libraries = AsmPrinter CodeGen Core MC SelectionDAG Support Target AAPAsmPrinter AAPInfo add_to_library_groups = AAP Index: lib/Target/AAP/MCTargetDesc/AAPMCTargetDesc.cpp =================================================================== --- lib/Target/AAP/MCTargetDesc/AAPMCTargetDesc.cpp +++ lib/Target/AAP/MCTargetDesc/AAPMCTargetDesc.cpp @@ -13,6 +13,7 @@ #include "AAPMCTargetDesc.h" #include "AAPMCAsmInfo.h" +#include "InstPrinter/AAPInstPrinter.h" #include "llvm/ADT/STLExtras.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" @@ -44,6 +45,16 @@ return; } +static MCInstPrinter *createAAPMCInstPrinter(const Triple &T, + unsigned SyntaxVariant, + const MCAsmInfo &MAI, + const MCInstrInfo &MII, + const MCRegisterInfo &MRI) { + if (SyntaxVariant == 0) + return new AAPInstPrinter(MAI, MII, MRI); + return nullptr; +} + extern "C" void LLVMInitializeAAPTargetMC() { // Register the MC asm info. RegisterMCAsmInfo X(TheAAPTarget); @@ -60,6 +71,9 @@ // Register the MC Code Emitter TargetRegistry::RegisterMCCodeEmitter(TheAAPTarget, createAAPMCCodeEmitter); + // Register the MCInstPrinter. + TargetRegistry::RegisterMCInstPrinter(TheAAPTarget, createAAPMCInstPrinter); + // Register the asm backend TargetRegistry::RegisterMCAsmBackend(TheAAPTarget, createAAPAsmBackend); } Index: lib/Target/AAP/MCTargetDesc/LLVMBuild.txt =================================================================== --- lib/Target/AAP/MCTargetDesc/LLVMBuild.txt +++ lib/Target/AAP/MCTargetDesc/LLVMBuild.txt @@ -19,5 +19,5 @@ type = Library name = AAPDesc parent = AAP -required_libraries = MC Support AAPInfo +required_libraries = MC Support AAPAsmPrinter AAPInfo add_to_library_groups = AAP Index: test/MC/AAP/alu.s =================================================================== --- /dev/null +++ test/MC/AAP/alu.s @@ -0,0 +1,90 @@ +; RUN: llvm-mc -triple=aap -show-encoding %s | FileCheck %s + +; Basic tests to check that we always pick the correct (and shortest) +; alu operations. + + +; ALU operations with registers +add $r0, $r0, $r0 ;CHECK: add $r0, $r0, $r0 ; encoding: [0x00,0x02] +add $r1, $r2, $r7 ;CHECK: add $r1, $r2, $r7 ; encoding: [0x57,0x02] +add $r7, $r7, $r7 ;CHECK: add $r7, $r7, $r7 ; encoding: [0xff,0x03] +add $r8, $r0, $r5 ;CHECK: add $r8, $r0, $r5 ; encoding: [0x05,0x82,0x40,0x00] +add $r8, $r8, $r12 ;CHECK: add $r8, $r8, $r12 ; encoding: [0x04,0x82,0x49,0x00] +add $r2, $r54, $r8 ;CHECK: add $r2, $r54, $r8 ; encoding: [0xb0,0x82,0x31,0x00] +add $r1, $r32, $r12 ;CHECK: add $r1, $r32, $r12 ; encoding: [0x44,0x82,0x21,0x00] + +xor $r0, $r0, $r0 ;CHECK: xor $r0, $r0, $r0 ; encoding: [0x00,0x0a] +and $r1, $r2, $r7 ;CHECK: and $r1, $r2, $r7 ; encoding: [0x57,0x06] +or $r7, $r7, $r1 ;CHECK: or $r7, $r7, $r1 ; encoding: [0xf9,0x09] +sub $r9, $r1, $r5 ;CHECK: sub $r9, $r1, $r5 ; encoding: [0x4d,0x84,0x40,0x00] +addc $r9, $r9, $r12 ;CHECK: addc $r9, $r9, $r12 ; encoding: [0x4c,0x82,0x49,0x02] +subc $r4, $r55, $r8 ;CHECK: subc $r4, $r55, $r8 ; encoding: [0x38,0x85,0x31,0x02] +asr $r4, $r33, $r12 ;CHECK: asr $r4, $r33, $r12 ; encoding: [0x0c,0x8d,0x21,0x00] +lsr $r15, $r3, $r8 ;CHECK: lsr $r15, $r3, $r8 ; encoding: [0xd8,0x91,0x41,0x00] +lsl $r11, $r10, $r12 ;CHECK: lsl $r11, $r10, $r12 ; encoding: [0xd4,0x8e,0x49,0x00] + + +; Add/Sub with immediates +addi $r6, $r4, 0 ;CHECK: addi $r6, $r4, 0 ; encoding: [0xa0,0x15] +addi $r7, $r2, 1 ;CHECK: addi $r7, $r2, 1 ; encoding: [0xd1,0x15] +subi $r0, $r5, 3 ;CHECK: subi $r0, $r5, 3 ; encoding: [0x2b,0x16] +subi $r8, $r8, 7 ;CHECK: subi $r8, $r8, 7 ; encoding: [0x07,0x96,0x48,0x00] +addi $r7, $r7, 1023 ;CHECK: addi $r7, $r7, 1023 ; encoding: [0xff,0x95,0x07,0x1e] + +; Add/Sub with expressions +addi $r0, $r0, (0 + 0) ;CHECK: addi $r0, $r0, 0 ; encoding: [0x00,0x14] +subi $r7, $r7, (1024 - 1023) ;CHECK: subi $r7, $r7, 1 ; encoding: [0xf9,0x17] +addi $r1, $r5, (8 - 1) ;CHECK: addi $r1, $r5, 7 ; encoding: [0x6f,0x14] +subi $r3, $r0, (7 + 1) ;CHECK: subi $r3, $r0, 8 ; encoding: [0xc0,0x96,0x01,0x00] + +; Add/Sub with relocs +addi $r5, $r2, a ;CHECK: addi $r5, $r2, a ; encoding: [0b01010AAA,0x95,0x00,0x00] +subi $r7, $r0, b ;CHECK: subi $r7, $r0, b ; encoding: [0b11000AAA,0x97,0x00,0x00] + + +; Logical operation with immediates +andi $r0, $r2, 7 ;CHECK: andi $r0, $r2, 7 ; encoding: [0x17,0x86,0x00,0x02] +ori $r1, $r5, 0 ;CHECK: ori $r1, $r5, 0 ; encoding: [0x68,0x88,0x00,0x02] +xori $r6, $r7, 6 ;CHECK: xori $r6, $r7, 6 ; encoding: [0xbe,0x8b,0x00,0x02] +andi $r8, $r0, 123 ;CHECK: andi $r8, $r0, 123 ; encoding: [0x03,0x86,0x47,0x06] +ori $r5, $r8, 12 ;CHECK: ori $r5, $r8, 12 ; encoding: [0x44,0x89,0x09,0x02] +xori $r15, $r54, 15 ;CHECK: xori $r15, $r54, 15 ; encoding: [0xf7,0x8b,0x71,0x02] +andi $r9, $r14, 511 ;CHECK: andi $r9, $r14, 511 ; encoding: [0x77,0x86,0x4f,0x1e] + +; Logical operations with expressions +andi $r0, $r1, (5 - 3) ;CHECK: andi $r0, $r1, 2 ; encoding: [0x0a,0x86,0x00,0x02] +xori $r15, $r12, (0 - 0) ;CHECK: xori $r15, $r12, 0 ; encoding: [0xe0,0x8b,0x48,0x02] +ori $r43, $r19, (15 + 48) ;CHECK: ori $r43, $r19, 63 ; encoding: [0xdf,0x88,0x57,0x03] + +; Logical operations with relocations +andi $r5, $r1, a ;CHECK: andi $r5, $r1, a ; encoding: [0b01001AAA,0x87,0x00,0x02] +xori $r11, $r5, a+b ;CHECK: xori $r11, $r5, a+b ; encoding: [0b11101AAA,0x8a,0x40,0x02] +ori $r0, $r0, c-a ;CHECK: ori $r0, $r0, c-a ; encoding: [0b00000AAA,0x88,0x00,0x02] + + +; Shift operations with immediates +lsli $r0, $r0, 1 ;CHECK: lsli $r0, $r0, 1 ; encoding: [0x00,0x1a] +lsri $r4, $r0, 2 ;CHECK: lsri $r4, $r0, 2 ; encoding: [0x01,0x1d] +asri $r7, $r1, 8 ;CHECK: asri $r7, $r1, 8 ; encoding: [0xcf,0x19] +asri $r7, $r3, 5 ;CHECK: asri $r7, $r3, 5 ; encoding: [0xdc,0x19] + +lsli $r0, $r8, 1 ;CHECK: lsli $r0, $r8, 1 ; encoding: [0x00,0x9a,0x08,0x00] +lsli $r8, $r5, 3 ;CHECK: lsli $r8, $r5, 3 ; encoding: [0x2a,0x9a,0x40,0x00] +lsri $r31, $r15, 4 ;CHECK: lsri $r31, $r15, 4 ; encoding: [0xfb,0x9d,0xc8,0x00] +asri $r7, $r35, 1 ;CHECK: asri $r7, $r35, 1 ; encoding: [0xd8,0x99,0x20,0x00] + +lsli $r2, $r4, 9 ;CHECK: lsli $r2, $r4, 9 ; encoding: [0xa0,0x9a,0x01,0x00] +lsri $r8, $r0, 12 ;CHECK: lsri $r8, $r0, 12 ; encoding: [0x03,0x9c,0x41,0x00] +asri $r7, $r1, 34 ;CHECK: asri $r7, $r1, 34 ; encoding: [0xc9,0x99,0x04,0x00] +asri $r7, $r3, 63 ;CHECK: asri $r7, $r3, 63 ; encoding: [0xde,0x99,0x07,0x00] + +; Shift operations with expressions +lsri $r4, $r2, (3 + 2) ;CHECK: lsri $r4, $r2, 5 ; encoding: [0x14,0x1d] +asri $r1, $r1, (1 + 0) ;CHECK: asri $r1, $r1, 1 ; encoding: [0x48,0x18] +lsli $r2, $r7, (128 - 65) ;CHECK: lsli $r2, $r7, 63 ; encoding: [0xbe,0x9a,0x07,0x00] +lsri $r8, $r0, (1 + 2) ;CHECK: lsri $r8, $r0, 3 ; encoding: [0x02,0x9c,0x40,0x00] + +; Shift operations with relocations +lsli $r0, $r5, a ;CHECK: lsli $r0, $r5, a ; encoding: [0b00101AAA,0x9a,0x00,0x00] +lsri $r0, $r5, b ;CHECK: lsri $r0, $r5, b ; encoding: [0b00101AAA,0x9c,0x00,0x00] +asri $r0, $r5, c ;CHECK: asri $r0, $r5, c ; encoding: [0b00101AAA,0x98,0x00,0x00] Index: test/MC/AAP/branch.s =================================================================== --- /dev/null +++ test/MC/AAP/branch.s @@ -0,0 +1,22 @@ +; RUN: llvm-mc -triple=aap -show-encoding %s | FileCheck %s + +; Basic tests to check that we always pick the correct (and shorest) +; branch instructions +; Short branch instructions are never assembled + +beq 511, $r0, $r1 ;CHECK: beq 511, $r0, $r1 ; encoding: [0xc1,0xc5,0xc0,0x0f] +bne -512, $r7, $r0 ;CHECK: bne -512, $r7, $r0 ; encoding: [0x38,0xc6,0x00,0x10] +blts 15, $r13, $r61 ;CHECK: blts 15, $r13, $r61 ; encoding: [0xed,0xc9,0x4f,0x00] +bles 32, $r9, $r8 ;CHECK: bles 32, $r9, $r8 ; encoding: [0x08,0xca,0x09,0x01] +bltu 186, $r11, $r12 ;CHECK: bltu 186, $r11, $r12 ; encoding: [0x9c,0xcc,0xc9,0x05] +bleu -1, $r17, $r19 ;CHECK: bleu -1, $r17, $r19 ; encoding: [0xcb,0xcf,0xd2,0x1f] + +bra 123 ;CHECK: bra 123 ; encoding: [0x7b,0xc0,0x00,0x00] +bra -6810 ;CHECK: bra -6810 ; encoding: [0x66,0xc1,0xf2,0x1f] +bra -131072 ;CHECK: bra -131072 ; encoding: [0x00,0xc0,0x00,0x1f] +bra 131071 ;CHECK: bra 131071 ; encoding: [0xff,0xc1,0xff,0x00] + +bal 481, $r14 ;CHECK: bal 481, $r14 ; encoding: [0x0e,0xc3,0x39,0x00] +bal -1892, $r58 ;CHECK: bal -1892, $r58 ; encoding: [0xe2,0xc2,0x17,0x1f] +bal 32767, $r0 ;CHECK: bal 32767, $r0 ; encoding: [0xf8,0xc3,0xf8,0x0f] +bal -32768, $r15 ;CHECK: bal -32768, $r15 ; encoding: [0x07,0xc2,0x01,0x10] Index: test/MC/AAP/lit.local.cfg =================================================================== --- /dev/null +++ test/MC/AAP/lit.local.cfg @@ -0,0 +1,3 @@ +if not 'AAP' in config.root.targets: + config.unsupported = True + Index: test/MC/AAP/load.s =================================================================== --- /dev/null +++ test/MC/AAP/load.s @@ -0,0 +1,102 @@ +; RUN: llvm-mc -triple=aap -show-encoding %s | FileCheck %s + +; Basic tests to check that we always pick the correct (and shortest) +; load instructions. + +; Byte loads with immediates +ldb $r7, [$r1, 0] ;CHECK: ldb $r7, [$r1, 0] ; encoding: [0xc8,0x21] +ldb $r0, [$r0, 2] ;CHECK: ldb $r0, [$r0, 2] ; encoding: [0x02,0x20] +ldb $r7, [$r7, 3] ;CHECK: ldb $r7, [$r7, 3] ; encoding: [0xfb,0x21] +ldb $r4, [$r1, -1] ;CHECK: ldb $r4, [$r1, -1] ; encoding: [0x0f,0x21] +ldb $r6, [$r0, -4] ;CHECK: ldb $r6, [$r0, -4] ; encoding: [0x84,0x21] +ldb $r5, [$r8, 0] ;CHECK: ldb $r5, [$r8, 0] ; encoding: [0x40,0xa1,0x08,0x00] +ldb $r16, [$r1, 2] ;CHECK: ldb $r16, [$r1, 2] ; encoding: [0x0a,0xa0,0x80,0x00] +ldb $r1, [$r2, 4] ;CHECK: ldb $r1, [$r2, 4] ; encoding: [0x54,0xa0,0x00,0x00] +ldb $r6, [$r3, -5] ;CHECK: ldb $r6, [$r3, -5] ; encoding: [0x9b,0xa1,0x07,0x1e] +ldb $r43, [$r56, 12] ;CHECK: ldb $r43, [$r56, 12] ; encoding: [0xc4,0xa0,0x79,0x01] +ldb $r11, [$r11, 511] ;CHECK: ldb $r11, [$r11, 511] ; encoding: [0xdf,0xa0,0x4f,0x0e] +ldb $r53, [$r63, -512] ;CHECK: ldb $r53, [$r63, -512] ; encoding: [0x78,0xa1,0xb8,0x11] + +; Byte loads with expressions +ldb $r0, [$r4, (5 - 3)] ;CHECK: ldb $r0, [$r4, 2] ; encoding: [0x22,0x20] +ldb $r5, [$r7, (81726 - 81727)] ;CHECK: ldb $r5, [$r7, -1] ; encoding: [0x7f,0x21] +ldb $r2, [$r6, (-5 + 1)] ;CHECK: ldb $r2, [$r6, -4] ; encoding: [0xb4,0x20] +ldb $r15, [$r34, (0 + 0)] ;CHECK: ldb $r15, [$r34, 0] ; encoding: [0xd0,0xa1,0x60,0x00] +ldb $r45, [$r0, (5 - 2)] ;CHECK: ldb $r45, [$r0, 3] ; encoding: [0x43,0xa1,0x40,0x01] +ldb $r0, [$r61, (11 - 9)] ;CHECK: ldb $r0, [$r61, 2] ; encoding: [0x2a,0xa0,0x38,0x00] +ldb $r5, [$r1, (256 + 255)] ;CHECK: ldb $r5, [$r1, 511] ; encoding: [0x4f,0xa1,0x07,0x0e] +ldb $r43, [$r17, (-256 - 256)] ;CHECK: ldb $r43, [$r17, -512] ; encoding: [0xc8,0xa0,0x50,0x11] + +; Byte loads with relocations +ldb $r0, [$r5, a] ;CHECK: ldb $r0, [$r5, a] ; encoding: [0b00101AAA,0xa0,0x00,0x00] +ldb $r1, [$r3, b] ;CHECK: ldb $r1, [$r3, b] ; encoding: [0b01011AAA,0xa0,0x00,0x00] +ldb $r17, [$r39, b] ;CHECK: ldb $r17, [$r39, b] ; encoding: [0b01111AAA,0xa0,0xa0,0x00] +ldb $r15, [$r11, (a - b)] ;CHECK: ldb $r15, [$r11, a-b] ; encoding: [0b11011AAA,0xa1,0x48,0x00] + +; Postinc/Predec bytes loads with immediate +ldb $r5, [$r4+, 0] ;CHECK: ldb $r5, [$r4+, 0] ; encoding: [0x60,0x23] +ldb $r0, [$r2+, 2] ;CHECK: ldb $r0, [$r2+, 2] ; encoding: [0x12,0x22] +ldb $r1, [-$r6, 2] ;CHECK: ldb $r1, [-$r6, 2] ; encoding: [0x72,0x24] +ldb $r7, [-$r2, -2] ;CHECK: ldb $r7, [-$r2, -2] ; encoding: [0xd6,0x25] +ldb $r1, [-$r7, -4] ;CHECK: ldb $r1, [-$r7, -4] ; encoding: [0x7c,0x24] +ldb $r5, [$r8+, 3] ;CHECK: ldb $r5, [$r8+, 3] ; encoding: [0x43,0xa3,0x08,0x00] +ldb $r11, [$r1+, 1] ;CHECK: ldb $r11, [$r1+, 1] ; encoding: [0xc9,0xa2,0x40,0x00] +ldb $r3, [-$r5, 5] ;CHECK: ldb $r3, [-$r5, 5] ; encoding: [0xed,0xa4,0x00,0x00] +ldb $r2, [-$r3, -5] ;CHECK: ldb $r2, [-$r3, -5] ; encoding: [0x9b,0xa4,0x07,0x1e] +ldb $r41, [$r56+, 12] ;CHECK: ldb $r41, [$r56+, 12] ; encoding: [0x44,0xa2,0x79,0x01] +ldb $r34, [$r11+, 511] ;CHECK: ldb $r34, [$r11+, 511] ; encoding: [0x9f,0xa2,0x0f,0x0f] +ldb $r60, [$r63+, -512] ;CHECK: ldb $r60, [$r63+, -512] ; encoding: [0x38,0xa3,0xf8,0x11] + +; Postinc/Predec byte loads with expressions +ldb $r1, [$r7+, (5 - 3)] ;CHECK: ldb $r1, [$r7+, 2] ; encoding: [0x7a,0x22] +ldb $r5, [-$r1, (81726 - 81727)] ;CHECK: ldb $r5, [-$r1, -1] ; encoding: [0x4f,0x25] +ldb $r7, [-$r6, (-5 + 1)] ;CHECK: ldb $r7, [-$r6, -4] ; encoding: [0xf4,0x25] +ldb $r29, [$r34+, (0 + 0)] ;CHECK: ldb $r29, [$r34+, 0] ; encoding: [0x50,0xa3,0xe0,0x00] +ldb $r40, [-$r1, (5 - 2)] ;CHECK: ldb $r40, [-$r1, 3] ; encoding: [0x0b,0xa4,0x40,0x01] +ldb $r0, [$r61+, (11 - 9)] ;CHECK: ldb $r0, [$r61+, 2] ; encoding: [0x2a,0xa2,0x38,0x00] +ldb $r5, [$r1+, (256 + 255)] ;CHECK: ldb $r5, [$r1+, 511] ; encoding: [0x4f,0xa3,0x07,0x0e] +ldb $r43, [$r17+, (-256 - 256)] ;CHECK: ldb $r43, [$r17+, -512] ; encoding: [0xc8,0xa2,0x50,0x11] + +; Postinc/Predec byte loads with relocations +ldb $r0, [$r5+, a] ;CHECK: ldb $r0, [$r5+, a] ; encoding: [0b00101AAA,0xa2,0x00,0x00] +ldb $r1, [-$r3, b] ;CHECK: ldb $r1, [-$r3, b] ; encoding: [0b01011AAA,0xa4,0x00,0x00] +ldb $r17, [$r39+, b] ;CHECK: ldb $r17, [$r39+, b] ; encoding: [0b01111AAA,0xa2,0xa0,0x00] +ldb $r15, [-$r11, (a - b)] ;CHECK: ldb $r15, [-$r11, a-b] ; encoding: [0b11011AAA,0xa5,0x48,0x00] + + +; Word loads with immediates +ldw $r7, [$r1, 0] ;CHECK: ldw $r7, [$r1, 0] ; encoding: [0xc8,0x29] +ldw $r4, [$r1, -1] ;CHECK: ldw $r4, [$r1, -1] ; encoding: [0x0f,0x29] +ldw $r6, [$r0, -4] ;CHECK: ldw $r6, [$r0, -4] ; encoding: [0x84,0x29] +ldw $r5, [$r8, 0] ;CHECK: ldw $r5, [$r8, 0] ; encoding: [0x40,0xa9,0x08,0x00] +ldw $r6, [$r3, -5] ;CHECK: ldw $r6, [$r3, -5] ; encoding: [0x9b,0xa9,0x07,0x1e] +ldw $r53, [$r63, -512] ;CHECK: ldw $r53, [$r63, -512] ; encoding: [0x78,0xa9,0xb8,0x11] + +; Word loads with expressions +ldw $r0, [$r4, (5 - 3)] ;CHECK: ldw $r0, [$r4, 2] ; encoding: [0x22,0x28] +ldw $r5, [$r7, (81726 - 81727)] ;CHECK: ldw $r5, [$r7, -1] ; encoding: [0x7f,0x29] +ldw $r15, [$r34, (0 + 0)] ;CHECK: ldw $r15, [$r34, 0] ; encoding: [0xd0,0xa9,0x60,0x00] +ldw $r43, [$r17, (-256 - 256)] ;CHECK: ldw $r43, [$r17, -512] ; encoding: [0xc8,0xa8,0x50,0x11] + +; Word loads with relocations +ldw $r17, [$r39, b] ;CHECK: ldw $r17, [$r39, b] ; encoding: [0b01111AAA,0xa8,0xa0,0x00] +ldw $r15, [$r11, (a - b)] ;CHECK: ldw $r15, [$r11, a-b] ; encoding: [0b11011AAA,0xa9,0x48,0x00] + +; Postinc/Predec word loads with immediates +ldw $r0, [$r2+, 2] ;CHECK: ldw $r0, [$r2+, 2] ; encoding: [0x12,0x2a] +ldw $r7, [-$r2, -2] ;CHECK: ldw $r7, [-$r2, -2] ; encoding: [0xd6,0x2d] +ldw $r1, [-$r7, -4] ;CHECK: ldw $r1, [-$r7, -4] ; encoding: [0x7c,0x2c] +ldw $r11, [$r1+, 1] ;CHECK: ldw $r11, [$r1+, 1] ; encoding: [0xc9,0xaa,0x40,0x00] +ldw $r2, [-$r3, -5] ;CHECK: ldw $r2, [-$r3, -5] ; encoding: [0x9b,0xac,0x07,0x1e] +ldw $r60, [$r63+, -512] ;CHECK: ldw $r60, [$r63+, -512] ; encoding: [0x38,0xab,0xf8,0x11] + +; Postinc/Predec word loads with expressions +ldw $r1, [$r7+, (5 - 3)] ;CHECK: ldw $r1, [$r7+, 2] ; encoding: [0x7a,0x2a] +ldw $r7, [-$r6, (-5 + 1)] ;CHECK: ldw $r7, [-$r6, -4] ; encoding: [0xf4,0x2d] +ldw $r29, [$r34+, (0 + 0)] ;CHECK: ldw $r29, [$r34+, 0] ; encoding: [0x50,0xab,0xe0,0x00] +ldw $r40, [-$r1, (5 - 2)] ;CHECK: ldw $r40, [-$r1, 3] ; encoding: [0x0b,0xac,0x40,0x01] +ldw $r43, [$r17+, (-256 - 256)] ;CHECK: ldw $r43, [$r17+, -512] ; encoding: [0xc8,0xaa,0x50,0x11] + +; Postinc/Predec word loads with relocations +ldw $r17, [$r39+, b] ;CHECK: ldw $r17, [$r39+, b] ; encoding: [0b01111AAA,0xaa,0xa0,0x00] +ldw $r15, [-$r11, (a - b)] ;CHECK: ldw $r15, [-$r11, a-b] ; encoding: [0b11011AAA,0xad,0x48,0x00] Index: test/MC/AAP/move.s =================================================================== --- /dev/null +++ test/MC/AAP/move.s @@ -0,0 +1,38 @@ +; RUN: llvm-mc -triple=aap -show-encoding %s | FileCheck %s + +; Basic tests to check that we always pick the correct (and shortest) +; move instructions. + +; Moves with registers +mov $r0, $r0 ;CHECK: mov $r0, $r0 ; encoding: [0x00,0x12] +mov $r7, $r7 ;CHECK: mov $r7, $r7 ; encoding: [0xf8,0x13] +mov $r8, $r8 ;CHECK: mov $r8, $r8 ; encoding: [0x00,0x92,0x48,0x00] +mov $r15, $r1 ;CHECK: mov $r15, $r1 ; encoding: [0xc8,0x93,0x40,0x00] +mov $r3, $r11 ;CHECK: mov $r3, $r11 ; encoding: [0xd8,0x92,0x08,0x00] + +; Moves with immediates +movi $r0, 0 ;CHECK: movi $r0, 0 ; encoding: [0x00,0x1e] +movi $r5, -0 ;CHECK: movi $r5, 0 ; encoding: [0x40,0x1f] +movi $r7, +0 ;CHECK: movi $r7, 0 ; encoding: [0xc0,0x1f] +movi $r2, 13 ;CHECK: movi $r2, 13 ; encoding: [0x8d,0x1e] +movi $r3, 63 ;CHECK: movi $r3, 63 ; encoding: [0xff,0x1e] +movi $r3, 0x12 ;CHECK: movi $r3, 18 ; encoding: [0xd2,0x1e] +movi $r4, 64 ;CHECK: movi $r4, 64 ; encoding: [0x00,0x9f,0x01,0x00] +movi $r10, 0 ;CHECK: movi $r10, 0 ; encoding: [0x80,0x9e,0x40,0x00] +movi $r8, 123 ;CHECK: movi $r8, 123 ; encoding: [0x3b,0x9e,0x41,0x00] +movi $r9, 65535 ;CHECK: movi $r9, 65535 ; encoding: [0x7f,0x9e,0x7f,0x1e] +movi $r1, -1 ;CHECK: movi $r1, -1 ; encoding: [0x7f,0x9e,0x3f,0x1e] +movi $r9, -32768 ;CHECK: movi $r9, -32768 ; encoding: [0x40,0x9e,0x40,0x10] +movi $r16, 0xdead ;CHECK: movi $r16, 57005 ; encoding: [0x2d,0x9e,0xba,0x1a] +movi $r63, -0x1 ;CHECK: movi $r63, -1 ; encoding: [0xff,0x9f,0xff,0x1f] +movi $r63, -0x7fff ;CHECK: movi $r63, -32767 ; encoding: [0xc1,0x9f,0xc0,0x11] + +; Moves with expressions +movi $r2, (5 + 5) ;CHECK: movi $r2, 10 ; encoding: [0x8a,0x1e] +movi $r4, (65 - 10) ;CHECK: movi $r4, 55 ; encoding: [0x37,0x1f] +movi $r12, (0xdead - 0xbeef) ;CHECK: movi $r12, 8126 ; encoding: [0x3e,0x9f,0x7e,0x02] + +; Moves with relocations. These should always assemble to long instructions +movi $r0, a ;CHECK: movi $r0, a ; encoding: [0b00AAAAAA,0x9e,0x00,0x00] +movi $r8, b ;CHECK: movi $r8, b ; encoding: [0b00AAAAAA,0x9e,0x40,0x00] +movi $r16, (a + b) ;CHECK: movi $r16, a+b ; encoding: [0b00AAAAAA,0x9e,0x80,0x00] Index: test/MC/AAP/noop.s =================================================================== --- /dev/null +++ test/MC/AAP/noop.s @@ -0,0 +1,10 @@ +; RUN: llvm-mc -triple=aap -show-encoding %s | FileCheck %s + +; Basic tests to check that we always pick the correct (and shortest) +; noop instruction. + +nop $r0, 5 ;CHECK: nop $r0, 5 ; encoding: [0x05,0x00] +nop $r7, 63 ;CHECK: nop $r7, 63 ; encoding: [0xff,0x01] +nop $r8, 53 ;CHECK: nop $r8, 53 ; encoding: [0x35,0x80,0x40,0x00] +nop $r4, 64 ;CHECK: nop $r4, 64 ; encoding: [0x00,0x81,0x01,0x00] +nop $r63, a ;CHECK: nop $r63, a ; encoding: [0b11AAAAAA,0x81,0xc0,0x01] Index: test/MC/AAP/store.s =================================================================== --- /dev/null +++ test/MC/AAP/store.s @@ -0,0 +1,98 @@ +; RUN: llvm-mc -triple=aap -show-encoding %s | FileCheck %s + +; Basic tests to check that we always pick the correct (and shortest) +; store instructions. + +; Byte stores with immediates +stb [$r0, 0], $r0 ;CHECK: stb [$r0, 0], $r0 ; encoding: [0x00,0x30] +stb [$r1, 2], $r1 ;CHECK: stb [$r1, 2], $r1 ; encoding: [0x4a,0x30] +stb [$r7, 3], $r3 ;CHECK: stb [$r7, 3], $r3 ; encoding: [0xdb,0x31] +stb [$r1, -1], $r7 ;CHECK: stb [$r1, -1], $r7 ; encoding: [0x7f,0x30] +stb [$r5, -4], $r5 ;CHECK: stb [$r5, -4], $r5 ; encoding: [0x6c,0x31] +stb [$r8, 0], $r0 ;CHECK: stb [$r8, 0], $r0 ; encoding: [0x00,0xb0,0x40,0x00] +stb [$r1, 4], $r0 ;CHECK: stb [$r1, 4], $r0 ; encoding: [0x44,0xb0,0x00,0x00] +stb [$r7, 3], $r8 ;CHECK: stb [$r7, 3], $r8 ; encoding: [0xc3,0xb1,0x08,0x00] +stb [$r15, -1], $r7 ;CHECK: stb [$r15, -1], $r7 ; encoding: [0xff,0xb1,0x47,0x1e] +stb [$r6, -5], $r2 ;CHECK: stb [$r6, -5], $r2 ; encoding: [0x93,0xb1,0x07,0x1e] +stb [$r63, 2], $r7 ;CHECK: stb [$r63, 2], $r7 ; encoding: [0xfa,0xb1,0xc0,0x01] +stb [$r5, 1], $r26 ;CHECK: stb [$r5, 1], $r26 ; encoding: [0x51,0xb1,0x18,0x00] +stb [$r63, 511], $r19 ;CHECK: stb [$r63, 511], $r19 ; encoding: [0xdf,0xb1,0xd7,0x0f] +stb [$r52, -512], $r14 ;CHECK: stb [$r52, -512], $r14 ; encoding: [0x30,0xb1,0x88,0x11] + +; Byte stores with expressions +stb [$r1, (-(3 - 2))], $r2 ;CHECK: stb [$r1, -1], $r2 ; encoding: [0x57,0x30] +stb [$r4, (1234 - 1233)], $r7 ;CHECK: stb [$r4, 1], $r7 ; encoding: [0x39,0x31] +stb [$r6, (-2 + 1)], $r2 ;CHECK: stb [$r6, -1], $r2 ; encoding: [0x97,0x31] +stb [$r1, (1024 - 513)], $r0 ;CHECK: stb [$r1, 511], $r0 ; encoding: [0x47,0xb0,0x07,0x0e] +stb [$r40, (-256 + 123)], $r16 ;CHECK: stb [$r40, -133], $r16 ; encoding: [0x03,0xb0,0x57,0x1b] +stb [$r18, (0xdead - 0xdeaf)], $r8 ;CHECK: stb [$r18, -2], $r8 ; encoding: [0x86,0xb0,0x8f,0x1e] + +; Byte stores with relocations +stb [$r0, a], $r1 ;CHECK: stb [$r0, a], $r1 ; encoding: [0b00001AAA,0xb0,0x00,0x00] +stb [$r7, b], $r2 ;CHECK: stb [$r7, b], $r2 ; encoding: [0b11010AAA,0xb1,0x00,0x00] +stb [$r1, (c - a)], $r50 ;CHECK: stb [$r1, c-a], $r50 ; encoding: [0b01010AAA,0xb0,0x30,0x00] + +; Postinc/Predec byte stores with immediates +stb [$r5+, 1], $r0 ;CHECK: stb [$r5+, 1], $r0 ; encoding: [0x41,0x33] +stb [$r6+, 3], $r2 ;CHECK: stb [$r6+, 3], $r2 ; encoding: [0x93,0x33] +stb [-$r7, 2], $r7 ;CHECK: stb [-$r7, 2], $r7 ; encoding: [0xfa,0x35] +stb [-$r1, -1], $r7 ;CHECK: stb [-$r1, -1], $r7 ; encoding: [0x7f,0x34] +stb [$r2+, -4], $r2 ;CHECK: stb [$r2+, -4], $r2 ; encoding: [0x94,0x32] +stb [$r9+, 1], $r8 ;CHECK: stb [$r9+, 1], $r8 ; encoding: [0x41,0xb2,0x48,0x00] +stb [$r1+, 4], $r0 ;CHECK: stb [$r1+, 4], $r0 ; encoding: [0x44,0xb2,0x00,0x00] +stb [-$r7, -5], $r8 ;CHECK: stb [-$r7, -5], $r8 ; encoding: [0xc3,0xb5,0x0f,0x1e] +stb [-$r12, -1], $r7 ;CHECK: stb [-$r12, -1], $r7 ; encoding: [0x3f,0xb5,0x47,0x1e] +stb [-$r61, -5], $r2 ;CHECK: stb [-$r61, -5], $r2 ; encoding: [0x53,0xb5,0xc7,0x1f] +stb [$r25+, 2], $r7 ;CHECK: stb [$r25+, 2], $r7 ; encoding: [0x7a,0xb2,0xc0,0x00] +stb [$r1+, 1], $r29 ;CHECK: stb [$r1+, 1], $r29 ; encoding: [0x69,0xb2,0x18,0x00] +stb [-$r27, 511], $r19 ;CHECK: stb [-$r27, 511], $r19 ; encoding: [0xdf,0xb4,0xd7,0x0e] +stb [$r52+, -512], $r44 ;CHECK: stb [$r52+, -512], $r44 ; encoding: [0x20,0xb3,0xa8,0x11] + +; Postinc/Predec byte stores with expressions +stb [$r0+, (-(-5 + 4))], $r0 ;CHECK: stb [$r0+, 1], $r0 ; encoding: [0x01,0x32] +stb [-$r2, (91 - 95)], $r2 ;CHECK: stb [-$r2, -4], $r2 ; encoding: [0x94,0x34] +stb [$r6+, (2 - 1)], $r2 ;CHECK: stb [$r6+, 1], $r2 ; encoding: [0x91,0x33] +stb [-$r1, (1024 - 513)], $r8 ;CHECK: stb [-$r1, 511], $r8 ; encoding: [0x47,0xb4,0x0f,0x0e] +stb [$r40+, (-256 + 256)], $r16 ;CHECK: stb [$r40+, 0], $r16 ; encoding: [0x00,0xb2,0x50,0x01] +stb [-$r18, (0xdead - 0xdead)], $r8 ;CHECK: stb [-$r18, 0], $r8 ; encoding: [0x80,0xb4,0x88,0x00] + +; Postinc/Predec byte stores with relocations +stb [$r7+, a], $r6 ;CHECK: stb [$r7+, a], $r6 ; encoding: [0b11110AAA,0xb3,0x00,0x00] +stb [-$r0, b], $r3 ;CHECK: stb [-$r0, b], $r3 ; encoding: [0b00011AAA,0xb4,0x00,0x00] +stb [$r1+, (b + a)], $r8 ;CHECK: stb [$r1+, b+a], $r8 ; encoding: [0b01000AAA,0xb2,0x08,0x00] + + +; Word stores with immediates +stw [$r1, 2], $r1 ;CHECK: stw [$r1, 2], $r1 ; encoding: [0x4a,0x38] +stw [$r7, 3], $r3 ;CHECK: stw [$r7, 3], $r3 ; encoding: [0xdb,0x39] +stw [$r8, 0], $r0 ;CHECK: stw [$r8, 0], $r0 ; encoding: [0x00,0xb8,0x40,0x00] +stw [$r6, -5], $r2 ;CHECK: stw [$r6, -5], $r2 ; encoding: [0x93,0xb9,0x07,0x1e] +stw [$r5, 1], $r26 ;CHECK: stw [$r5, 1], $r26 ; encoding: [0x51,0xb9,0x18,0x00] + +; Word stores with expressions +stw [$r4, (1234 - 1233)], $r7 ;CHECK: stw [$r4, 1], $r7 ; encoding: [0x39,0x39] +stw [$r6, (-2 + 1)], $r2 ;CHECK: stw [$r6, -1], $r2 ; encoding: [0x97,0x39] +stw [$r1, (1024 - 513)], $r0 ;CHECK: stw [$r1, 511], $r0 ; encoding: [0x47,0xb8,0x07,0x0e] +stw [$r18, (0xdead - 0xdeaf)], $r8 ;CHECK: stw [$r18, -2], $r8 ; encoding: [0x86,0xb8,0x8f,0x1e] + +; Word stores with relocations +stw [$r7, b], $r2 ;CHECK: stw [$r7, b], $r2 ; encoding: [0b11010AAA,0xb9,0x00,0x00] +stw [$r1, (c - a)], $r50 ;CHECK: stw [$r1, c-a], $r50 ; encoding: [0b01010AAA,0xb8,0x30,0x00] + +; Postinc/Predec word stores with immediates +stw [-$r7, 2], $r7 ;CHECK: stw [-$r7, 2], $r7 ; encoding: [0xfa,0x3d] +stw [$r2+, -4], $r2 ;CHECK: stw [$r2+, -4], $r2 ; encoding: [0x94,0x3a] +stw [$r9+, 1], $r8 ;CHECK: stw [$r9+, 1], $r8 ; encoding: [0x41,0xba,0x48,0x00] +stw [-$r7, -5], $r8 ;CHECK: stw [-$r7, -5], $r8 ; encoding: [0xc3,0xbd,0x0f,0x1e] +stw [-$r61, -5], $r2 ;CHECK: stw [-$r61, -5], $r2 ; encoding: [0x53,0xbd,0xc7,0x1f] +stw [$r25+, 2], $r7 ;CHECK: stw [$r25+, 2], $r7 ; encoding: [0x7a,0xba,0xc0,0x00] + +; Postinc/Predec word stores with expressions +stw [-$r2, (91 - 95)], $r2 ;CHECK: stw [-$r2, -4], $r2 ; encoding: [0x94,0x3c] +stw [$r6+, (2 - 1)], $r2 ;CHECK: stw [$r6+, 1], $r2 ; encoding: [0x91,0x3b] +stw [$r40+, (-256 + 256)], $r16 ;CHECK: stw [$r40+, 0], $r16 ; encoding: [0x00,0xba,0x50,0x01] +stw [-$r18, (0xdead - 0xdead)], $r8 ;CHECK: stw [-$r18, 0], $r8 ; encoding: [0x80,0xbc,0x88,0x00] + +; Postinc/Predec word stores with relocations +stw [$r7+, a], $r6 ;CHECK: stw [$r7+, a], $r6 ; encoding: [0b11110AAA,0xbb,0x00,0x00] +stw [-$r0, b], $r3 ;CHECK: stw [-$r0, b], $r3 ; encoding: [0b00011AAA,0xbc,0x00,0x00]