llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-loongarch Author: Matt Arsenault (arsenm) <details> <summary>Changes</summary> The target streamer read the ABI from MCTargetOptions when constructed, so the e_flags recorded the command line -target-abi and ignored the module flag. Co-Authored-By: Claude Opus 5 <noreply@<!-- -->anthropic.com> --- Full diff: https://github.com/llvm/llvm-project/pull/226498.diff 3 Files Affected: - (modified) llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp (+10) - (modified) llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h (+2) - (added) llvm/test/CodeGen/LoongArch/module-target-abi.ll (+13) ``````````diff diff --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp index 52afb2a8af199..38ee358a4de6c 100644 --- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp +++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp @@ -21,6 +21,7 @@ #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/CodeGen/MachineModuleInfoImpls.h" +#include "llvm/IR/Module.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCInstBuilder.h" @@ -47,6 +48,15 @@ LoongArchTargetStreamer &LoongArchAsmPrinter::getTargetStreamer() const { *OutStreamer->getTargetStreamer()); } +void LoongArchAsmPrinter::emitStartOfAsmFile(Module &M) { + StringRef ABIName = M.getTargetABIFromMD(); + if (!ABIName.empty()) { + getTargetStreamer().setTargetABI(LoongArchABI::computeTargetABI( + TM.getTargetTriple(), TM.getMCSubtargetInfo().getFeatureBits(), + ABIName)); + } +} + void LoongArchAsmPrinter::emitInstruction(const MachineInstr *MI) { LoongArch_MC::verifyInstructionPredicates( MI->getOpcode(), getSubtargetInfo().getFeatureBits()); diff --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h index bc8145386474d..09d8a36b86d9c 100644 --- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h +++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h @@ -43,6 +43,8 @@ class LLVM_LIBRARY_VISIBILITY LoongArchAsmPrinter : public AsmPrinter { bool runOnMachineFunction(MachineFunction &MF) override; + void emitStartOfAsmFile(Module &M) override; + void emitInstruction(const MachineInstr *MI) override; bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, diff --git a/llvm/test/CodeGen/LoongArch/module-target-abi.ll b/llvm/test/CodeGen/LoongArch/module-target-abi.ll new file mode 100644 index 0000000000000..306ca8b650a23 --- /dev/null +++ b/llvm/test/CodeGen/LoongArch/module-target-abi.ll @@ -0,0 +1,13 @@ +; The "target-abi" module flag selects the ABI used for codegen, and must also +; drive the ABI recorded in the ELF header e_flags. +; RUN: llc --mtriple=loongarch64 --mattr=+d --filetype=obj < %s -o %t.o +; RUN: llvm-readobj -h %t.o | FileCheck %s + +; CHECK: EF_LOONGARCH_ABI_SOFT_FLOAT + +define void @nothing() nounwind { + ret void +} + +!llvm.module.flags = !{!0} +!0 = !{i32 1, !"target-abi", !"lp64s"} `````````` </details> https://github.com/llvm/llvm-project/pull/226498 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
