Skip to content

Commit 75bff89

Browse files
committed
[Sparc] Add return/rett instruction to Sparc backend.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202666 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 361542a commit 75bff89

File tree

7 files changed

+54
-0
lines changed

7 files changed

+54
-0
lines changed

lib/Target/Sparc/AsmParser/SparcAsmParser.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc)
446446
return Error(StartLoc, "invalid register name");
447447
}
448448

449+
static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
450+
unsigned VariantID);
451+
449452
bool SparcAsmParser::
450453
ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
451454
SMLoc NameLoc,
@@ -455,6 +458,9 @@ ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
455458
// First operand in MCInst is instruction mnemonic.
456459
Operands.push_back(SparcOperand::CreateToken(Name, NameLoc));
457460

461+
// apply mnemonic aliases, if any, so that we can parse operands correctly.
462+
applyMnemonicAliases(Name, getAvailableFeatures(), 0);
463+
458464
if (getLexer().isNot(AsmToken::EndOfStatement)) {
459465
// Read the first operand.
460466
if (getLexer().is(AsmToken::Comma)) {

lib/Target/Sparc/Disassembler/SparcDisassembler.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ static DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn,
209209
uint64_t Address, const void *Decoder);
210210
static DecodeStatus DecodeJMPL(MCInst &Inst, unsigned insn, uint64_t Address,
211211
const void *Decoder);
212+
static DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address,
213+
const void *Decoder);
212214

213215
#include "SparcGenDisassemblerTables.inc"
214216

@@ -415,3 +417,31 @@ static DecodeStatus DecodeJMPL(MCInst &MI, unsigned insn, uint64_t Address,
415417
}
416418
return MCDisassembler::Success;
417419
}
420+
421+
static DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address,
422+
const void *Decoder) {
423+
424+
unsigned rs1 = fieldFromInstruction(insn, 14, 5);
425+
unsigned isImm = fieldFromInstruction(insn, 13, 1);
426+
unsigned rs2 = 0;
427+
unsigned simm13 = 0;
428+
if (isImm)
429+
simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
430+
else
431+
rs2 = fieldFromInstruction(insn, 0, 5);
432+
433+
// Decode RS1.
434+
DecodeStatus status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
435+
if (status != MCDisassembler::Success)
436+
return status;
437+
438+
// Decode RS2 | SIMM13.
439+
if (isImm)
440+
MI.addOperand(MCOperand::CreateImm(simm13));
441+
else {
442+
status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
443+
if (status != MCDisassembler::Success)
444+
return status;
445+
}
446+
return MCDisassembler::Success;
447+
}

lib/Target/Sparc/SparcInstrAliases.td

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ def : InstAlias<"mov $simm13, $rd", (ORri IntRegs:$rd, G0, i32imm:$simm13)>;
249249
// restore -> restore %g0, %g0, %g0
250250
def : InstAlias<"restore", (RESTORErr G0, G0, G0)>;
251251

252+
def : MnemonicAlias<"return", "rett">, Requires<[HasV9]>;
253+
252254
def : MnemonicAlias<"addc", "addx">, Requires<[HasV9]>;
253255
def : MnemonicAlias<"addccc", "addxcc">, Requires<[HasV9]>;
254256

lib/Target/Sparc/SparcInstrInfo.td

+8
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@ let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, isBarrier = 1,
406406
"jmp %i7+$val", []>;
407407
}
408408

409+
let isReturn = 1, isTerminator = 1, hasDelaySlot = 1,
410+
isBarrier = 1, rd = 0, DecoderMethod = "DecodeReturn" in {
411+
def RETTrr : F3_1<2, 0b111001, (outs), (ins MEMrr:$addr),
412+
"rett $addr", []>;
413+
def RETTri : F3_2<2, 0b111001, (outs), (ins MEMri:$addr),
414+
"rett $addr", []>;
415+
}
416+
409417
// Section B.1 - Load Integer Instructions, p. 90
410418
let DecoderMethod = "DecodeLoadInt" in {
411419
defm LDSB : Load<"ldsb", 0b001001, sextloadi8, IntRegs, i32>;

test/MC/Disassembler/Sparc/sparc.txt

+3
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,6 @@
197197

198198
# CHECK: ret
199199
0x81,0xc7,0xe0,0x08
200+
201+
# CHECK: rett %i7+8
202+
0x81 0xcf 0xe0 0x08

test/MC/Sparc/sparc-ctrl-instructions.s

+2
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,5 @@
274274
! CHECK-NEXT: ! fixup A - offset: 0, value: .BB0, kind: fixup_sparc_br22
275275
fbo,a .BB0
276276

277+
! CHECK: rett %i7+8 ! encoding: [0x81,0xcf,0xe0,0x08]
278+
rett %i7 + 8

test/MC/Sparc/sparc64-ctrl-instructions.s

+3
Original file line numberDiff line numberDiff line change
@@ -1214,3 +1214,6 @@
12141214
fmovrsnz %g1, %f2, %f3
12151215
fmovrsgz %g1, %f2, %f3
12161216
fmovrsgez %g1, %f2, %f3
1217+
1218+
! CHECK: rett %i7+8 ! encoding: [0x81,0xcf,0xe0,0x08]
1219+
return %i7 + 8

0 commit comments

Comments
 (0)