This is an archive of the discontinued LLVM Phabricator instance.

[MC] Use MCRegister instead of unsigned in MCInstPrinter (NFC)
ClosedPublic

Authored by barannikov88 on Dec 24 2022, 11:05 AM.

Diff Detail

Event Timeline

barannikov88 created this revision.Dec 24 2022, 11:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 24 2022, 11:05 AM
barannikov88 requested review of this revision.Dec 24 2022, 11:05 AM

Small naming fix

craig.topper added inline comments.
llvm/include/llvm/MC/MCInstPrinter.h
12

Can this be a forward reference?

barannikov88 added inline comments.Jan 15 2023, 12:50 AM
llvm/include/llvm/MC/MCInstPrinter.h
12

Nope, it is passed by value in printRegName below (and also in generated getRegisterName).

craig.topper added inline comments.Jan 15 2023, 1:15 AM
llvm/include/llvm/MC/MCInstPrinter.h
12

I thought the forward reference would be ok since only the declaration of printRegName is here. Isn’t it only needed for the definition and the call sites?

It’s late here so I might not be thinking clearly.

barannikov88 added inline comments.Jan 15 2023, 2:01 AM
llvm/include/llvm/MC/MCInstPrinter.h
12

You're right. This code compiles without errors:

class MCRegister;

class MCInstPrinter {
public:
  virtual void printRegName(MCRegister Reg);
};

class MCRegister {
public:
  MCRegister(unsigned);
};

int main() {
  MCInstPrinter P;
  P.printRegName(MCRegister(0));
}

That's a surprise to me. I thought it is only possible to do this with references and pointers.

Forward declare MCRegister
Update Xtensa target

barannikov88 marked 2 inline comments as done.EditedJan 15 2023, 2:36 AM

@craig.topper I've forward declared MCRegister and included MCRegister.h where absence of it caused compilation errors. This is not strictly IWYU; should I include it in other places too (it is sometimes transitively included by MCRegisterInfo.h / MCInstrInfo.h)?

craig.topper added inline comments.Jan 17 2023, 9:10 AM
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
46

Use Reg.id() here so we don't have to come back and fix it if ever get rid of operator unsigned?

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
43

Reg.id()

45

Reg.id()

barannikov88 added inline comments.Jan 17 2023, 9:12 AM
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
46

Good idea, will do.

Use Reg.id() where appropriate

barannikov88 marked 3 inline comments as done.Jan 17 2023, 10:27 AM
This revision is now accepted and ready to land.Jan 17 2023, 11:31 AM
This revision was landed with ongoing or failed builds.Jan 17 2023, 11:40 AM
This revision was automatically updated to reflect the committed changes.