Skip to content

Commit fe69556

Browse files
committed
combine 34bit print with 32bit
1 parent 5d45a87 commit fe69556

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -430,29 +430,18 @@ void PPCInstPrinter::printS16ImmOperand(const MCInst *MI, unsigned OpNo,
430430
printOperand(MI, OpNo, STI, O);
431431
}
432432

433-
void PPCInstPrinter::printS32ImmOperand(const MCInst *MI, unsigned OpNo,
433+
template<uint64_t N>
434+
void PPCInstPrinter::printSImmOperand(const MCInst *MI, unsigned OpNo,
434435
const MCSubtargetInfo &STI,
435436
raw_ostream &O) {
436437
if (MI->getOperand(OpNo).isImm()) {
437-
long long Value = MI->getOperand(OpNo).getImm();
438-
assert(isInt<32>(Value) && "Invalid s32imm argument!");
439-
O << (long long)Value;
438+
int64_t Value = MI->getOperand(OpNo).getImm();
439+
assert(isInt<N>(Value) && "Invalid imm argument!");
440+
O << (int64_t)Value;
440441
} else
441442
printOperand(MI, OpNo, STI, O);
442443
}
443444

444-
void PPCInstPrinter::printS34ImmOperand(const MCInst *MI, unsigned OpNo,
445-
const MCSubtargetInfo &STI,
446-
raw_ostream &O) {
447-
if (MI->getOperand(OpNo).isImm()) {
448-
long long Value = MI->getOperand(OpNo).getImm();
449-
assert(isInt<34>(Value) && "Invalid s34imm argument!");
450-
O << (long long)Value;
451-
}
452-
else
453-
printOperand(MI, OpNo, STI, O);
454-
}
455-
456445
void PPCInstPrinter::printU16ImmOperand(const MCInst *MI, unsigned OpNo,
457446
const MCSubtargetInfo &STI,
458447
raw_ostream &O) {
@@ -543,7 +532,7 @@ void PPCInstPrinter::printMemRegImmHash(const MCInst *MI, unsigned OpNo,
543532
void PPCInstPrinter::printMemRegImm34PCRel(const MCInst *MI, unsigned OpNo,
544533
const MCSubtargetInfo &STI,
545534
raw_ostream &O) {
546-
printS34ImmOperand(MI, OpNo, STI, O);
535+
printSImmOperand<34>(MI, OpNo, STI, O);
547536
O << '(';
548537
printImmZeroOperand(MI, OpNo + 1, STI, O);
549538
O << ')';
@@ -552,7 +541,7 @@ void PPCInstPrinter::printMemRegImm34PCRel(const MCInst *MI, unsigned OpNo,
552541
void PPCInstPrinter::printMemRegImm34(const MCInst *MI, unsigned OpNo,
553542
const MCSubtargetInfo &STI,
554543
raw_ostream &O) {
555-
printS34ImmOperand(MI, OpNo, STI, O);
544+
printSImmOperand<34>(MI, OpNo, STI, O);
556545
O << '(';
557546
printOperand(MI, OpNo + 1, STI, O);
558547
O << ')';

llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ class PPCInstPrinter : public MCInstPrinter {
8080
const MCSubtargetInfo &STI, raw_ostream &O);
8181
void printS16ImmOperand(const MCInst *MI, unsigned OpNo,
8282
const MCSubtargetInfo &STI, raw_ostream &O);
83-
void printS32ImmOperand(const MCInst *MI, unsigned OpNo,
84-
const MCSubtargetInfo &STI, raw_ostream &O);
85-
void printS34ImmOperand(const MCInst *MI, unsigned OpNo,
83+
template<uint64_t N>
84+
void printSImmOperand(const MCInst *MI, unsigned OpNo,
8685
const MCSubtargetInfo &STI, raw_ostream &O);
8786
void printU16ImmOperand(const MCInst *MI, unsigned OpNo,
8887
const MCSubtargetInfo &STI, raw_ostream &O);

llvm/lib/Target/PowerPC/PPCRegisterInfo.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,14 +814,14 @@ def PPCS32ImmAsmOperand : AsmOperandClass {
814814
let RenderMethod = "addImmOperands";
815815
}
816816
def s32imm : Operand<i64> {
817-
let PrintMethod = "printS32ImmOperand";
817+
let PrintMethod = "printSImmOperand<32>";
818818
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_imm32>";
819819
let ParserMatchClass = PPCS32ImmAsmOperand;
820820
let DecoderMethod = "decodeSImmOperand<32>";
821821
let OperandType = "OPERAND_IMMEDIATE";
822822
}
823823
def s32imm_pcrel : Operand<i64> {
824-
let PrintMethod = "printS32ImmOperand";
824+
let PrintMethod = "printSImmOperand<32>";
825825
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_pcrel32>";
826826
let ParserMatchClass = PPCS32ImmAsmOperand;
827827
let DecoderMethod = "decodeSImmOperand<32>";
@@ -833,14 +833,14 @@ def PPCS34ImmAsmOperand : AsmOperandClass {
833833
let RenderMethod = "addImmOperands";
834834
}
835835
def s34imm : Operand<i64> {
836-
let PrintMethod = "printS34ImmOperand";
836+
let PrintMethod = "printSImmOperand<34>";
837837
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_imm34>";
838838
let ParserMatchClass = PPCS34ImmAsmOperand;
839839
let DecoderMethod = "decodeSImmOperand<34>";
840840
let OperandType = "OPERAND_IMMEDIATE";
841841
}
842842
def s34imm_pcrel : Operand<i64> {
843-
let PrintMethod = "printS34ImmOperand";
843+
let PrintMethod = "printSImmOperand<34>";
844844
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_pcrel34>";
845845
let ParserMatchClass = PPCS34ImmAsmOperand;
846846
let DecoderMethod = "decodeSImmOperand<34>";

0 commit comments

Comments
 (0)