[PATCH] D142170: [AVR][NFC] Refactor 'AVRAsmPrinter::PrintAsmOperand'
Ben Shi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 19 18:38:06 PST 2023
benshi001 created this revision.
benshi001 added reviewers: aykevl, dylanmckay.
Herald added subscribers: Jim, hiraditya.
Herald added a project: All.
benshi001 requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142170
Files:
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
Index: llvm/lib/Target/AVR/AVRAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/AVR/AVRAsmPrinter.cpp
+++ llvm/lib/Target/AVR/AVRAsmPrinter.cpp
@@ -101,56 +101,51 @@
const char *ExtraCode, raw_ostream &O) {
// Default asm printer can only deal with some extra codes,
// so try it first.
- bool Error = AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
-
- if (Error && ExtraCode && ExtraCode[0]) {
- if (ExtraCode[1] != 0)
- return true; // Unknown modifier.
+ if (!AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O))
+ return false;
- if (ExtraCode[0] >= 'A' && ExtraCode[0] <= 'Z') {
- const MachineOperand &RegOp = MI->getOperand(OpNum);
+ const MachineOperand &MO = MI->getOperand(OpNum);
- assert(RegOp.isReg() && "Operand must be a register when you're"
- "using 'A'..'Z' operand extracodes.");
- Register Reg = RegOp.getReg();
+ if (ExtraCode && ExtraCode[0]) {
+ // Unknown extra code.
+ if (ExtraCode[1] != 0 || ExtraCode[0] < 'A' || ExtraCode[0] > 'Z')
+ return true;
- unsigned ByteNumber = ExtraCode[0] - 'A';
+ // Operand must be a register when using 'A' ~ 'Z' extra code.
+ if (!MO.isReg())
+ return true;
- unsigned OpFlags = MI->getOperand(OpNum - 1).getImm();
- unsigned NumOpRegs = InlineAsm::getNumOperandRegisters(OpFlags);
- (void)NumOpRegs;
+ Register Reg = MO.getReg();
- const AVRSubtarget &STI = MF->getSubtarget<AVRSubtarget>();
- const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
+ unsigned ByteNumber = ExtraCode[0] - 'A';
+ unsigned OpFlags = MI->getOperand(OpNum - 1).getImm();
+ unsigned NumOpRegs = InlineAsm::getNumOperandRegisters(OpFlags);
- const TargetRegisterClass *RC = TRI.getMinimalPhysRegClass(Reg);
- unsigned BytesPerReg = TRI.getRegSizeInBits(*RC) / 8;
- assert(BytesPerReg <= 2 && "Only 8 and 16 bit regs are supported.");
+ const AVRSubtarget &STI = MF->getSubtarget<AVRSubtarget>();
+ const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
- unsigned RegIdx = ByteNumber / BytesPerReg;
- if (RegIdx >= NumOpRegs)
- return true;
- Reg = MI->getOperand(OpNum + RegIdx).getReg();
+ const TargetRegisterClass *RC = TRI.getMinimalPhysRegClass(Reg);
+ unsigned BytesPerReg = TRI.getRegSizeInBits(*RC) / 8;
+ assert(BytesPerReg <= 2 && "Only 8 and 16 bit regs are supported.");
- if (BytesPerReg == 2) {
- Reg = TRI.getSubReg(Reg, ByteNumber % BytesPerReg ? AVR::sub_hi
- : AVR::sub_lo);
- }
+ unsigned RegIdx = ByteNumber / BytesPerReg;
+ if (RegIdx >= NumOpRegs)
+ return true;
+ Reg = MI->getOperand(OpNum + RegIdx).getReg();
- O << AVRInstPrinter::getPrettyRegisterName(Reg, MRI);
- return false;
+ if (BytesPerReg == 2) {
+ Reg = TRI.getSubReg(Reg,
+ ByteNumber % BytesPerReg ? AVR::sub_hi : AVR::sub_lo);
}
- }
- // Print global symbols.
- const auto &MO = MI->getOperand(OpNum);
- if (Error && MO.getType() == MachineOperand::MO_GlobalAddress) {
- PrintSymbolOperand(MO, O);
+ O << AVRInstPrinter::getPrettyRegisterName(Reg, MRI);
return false;
}
- if (Error)
- printOperand(MI, OpNum, O);
+ if (MO.getType() == MachineOperand::MO_GlobalAddress)
+ PrintSymbolOperand(MO, O); // Print global symbols.
+ else
+ printOperand(MI, OpNum, O); // Fallback to ordinary cases.
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142170.490697.patch
Type: text/x-patch
Size: 3615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230120/b1f3f975/attachment-0001.bin>
More information about the llvm-commits
mailing list