This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] move `isFaultFirstLoad` into `RISCVInstrInfo`
ClosedPublic

Authored by sunshaoce on Jun 10 2022, 12:58 AM.

Details

Summary

Fix build errors in D126794

ld.lld: error: undefined symbol: llvm::MachineInstr::getNumExplicitDefs() const
>>> referenced by RISCVBaseInfo.cpp
>>>               RISCVBaseInfo.cpp.o:(llvm::isFaultFirstLoad(llvm::MachineInstr const&)) in archive lib/libLLVMRISCVDesc.a

ld.lld: error: undefined symbol: llvm::MachineInstr::findRegisterDefOperandIdx(llvm::Register, bool, bool, llvm::TargetRegisterInfo const*) const
>>> referenced by RISCVBaseInfo.cpp
>>>               RISCVBaseInfo.cpp.o:(llvm::isFaultFirstLoad(llvm::MachineInstr const&)) in archive lib/libLLVMRISCVDesc.a
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

Diff Detail

Event Timeline

sunshaoce created this revision.Jun 10 2022, 12:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2022, 12:58 AM
sunshaoce requested review of this revision.Jun 10 2022, 12:58 AM
sunshaoce edited the summary of this revision. (Show Details)Jun 10 2022, 1:02 AM
fakepaper56 added inline comments.Jun 10 2022, 1:17 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
436

Maybe we could add inline static in a header file, like here?

I am sorry to create the trouble, but I didn't encounter this problem in my local. Could you provide me your cmake command?
My cmake command:

cmake -G "Ninja" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_BUILD_EXAMPLES=False -DLLVM_PARALLEL_LINK_JOBS=2 -DCMAKE_BUILD_TYPE=Debug ../llvm
fakepaper56 added inline comments.Jun 10 2022, 1:24 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
436

I mean you could rewrite to in a header file.

inline static bool isFaultFirstLoad(const MachineInstr &MI) {
  return MI.getNumExplicitDefs() == 2 && MI.modifiesRegister(RISCV::VL) &&
       !MI.isInlineAsm();
}
sunshaoce marked an inline comment as done.EditedJun 10 2022, 1:33 AM

I am sorry to create the trouble, but I didn't encounter this problem in my local. Could you provide me your cmake command?
My cmake command:

cmake -G "Ninja" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_BUILD_EXAMPLES=False -DLLVM_PARALLEL_LINK_JOBS=2 -DCMAKE_BUILD_TYPE=Debug ../llvm
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_TARGETS_TO_BUILD="X86;RISCV" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_USE_LINKER=lld ../llvm
ninja clang-tidy
sunshaoce added inline comments.Jun 10 2022, 1:36 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
436

It works. Should we move isFaultFirstLoad into a LLVM::RISCV* namespace?

fakepaper56 added inline comments.Jun 10 2022, 1:42 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
436

Should we move isFaultFirstLoad into a LLVM::RISCV* namespace?

I think the idea is great.

This comment was removed by fakepaper56.

Thank you for providing your cmake command.

sunshaoce updated this revision to Diff 435839.Jun 10 2022, 1:55 AM

Address comments.

fakepaper56 added inline comments.Jun 10 2022, 2:10 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
435

RISCVVInstInfo is similar as RISCVInstInfo. Maybe you could write it as static function in RISCVInstInfo. Sorry I ignoring it.

fakepaper56 added inline comments.Jun 10 2022, 2:13 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
435

Fix typo. Suggest declare as a static function of class RISCVInstrInfo.

fakepaper56 accepted this revision.Jun 10 2022, 2:26 AM
This revision is now accepted and ready to land.Jun 10 2022, 2:26 AM

LGTM. It's fine to me that not declare isFaultFirstLoad as a static function of class RISCVInstrInfo, although I prefer this method.

This revision was landed with ongoing or failed builds.Jun 10 2022, 6:04 AM
This revision was automatically updated to reflect the committed changes.
craig.topper added inline comments.Jun 10 2022, 8:28 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
18–19

CodeGen header should not be included in this file. This is an MC layer file.

435

This file should not refererence MachineInstr.

sunshaoce reopened this revision.Jun 10 2022, 8:50 AM
sunshaoce marked 5 inline comments as done.
This revision is now accepted and ready to land.Jun 10 2022, 8:50 AM

Please revert both this and the original change. There are unresolved concerns, and usual practice is to revert, and then reintroduce a revised patch - possibly after review if needed.

sunshaoce updated this revision to Diff 435937.Jun 10 2022, 9:12 AM

Address @reames's comment.

This revision was landed with ongoing or failed builds.Jun 10 2022, 9:28 AM
This revision was automatically updated to reflect the committed changes.

I am sorry that giving wrong comments made @sunshaoce rewrite and commit the code repeatedly. I promise I will review code more carefully and be more familiar with llvm.