This is an archive of the discontinued LLVM Phabricator instance.

[AVR][NFC] Refactor 'AVRAsmPrinter::PrintAsmOperand'
ClosedPublic

Authored by benshi001 on Jan 19 2023, 6:38 PM.

Diff Detail

Event Timeline

benshi001 created this revision.Jan 19 2023, 6:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 6:38 PM
Herald added subscribers: Jim, hiraditya. · View Herald Transcript
benshi001 requested review of this revision.Jan 19 2023, 6:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 6:38 PM
benshi001 added inline comments.Jan 19 2023, 6:47 PM
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
113

We should not use assert here, since the case we checked is user illegal input, it would be better to return true and let the llvm framework to give the error message.

And I combine the check with the above if check.

benshi001 added a comment.EditedJan 19 2023, 6:49 PM

Though the title is refactor, actually the part of handling extra code is left unchanged. I only make the high run flow more clear.

benshi001 added inline comments.Jan 19 2023, 10:35 PM
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
112

These conditions are checked in https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/AVR/inline-asm/inline-asm-invalid.ll

But I can not compose tests for the following two cases:

  1. ExtraCode[1] != 0, which will trigger to a fatal error in llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  1. The operand is not a register but ExtraCode[0] is not empty. Maybe we treat it as an input error (return true) is better than an assert.
Chenbing.Zheng added inline comments.Jan 30 2023, 6:05 PM
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
111

It seems that ExtraCode[0] < 'A' || ExtraCode[0] > 'Z' will return false according to the original logic ?

benshi001 added inline comments.Jan 30 2023, 6:13 PM
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
111

The orginal logic is wrong. Returning false means success, while true means failure. This is the logic of https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/CodeGen/AsmPrinter.h#L787

This revision is now accepted and ready to land.Jan 30 2023, 6:19 PM
This revision was automatically updated to reflect the committed changes.