[PATCH] D159399: [RISCV] Only emit .option when extension is supported
Piyou Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 2 04:00:05 PDT 2023
BeMg created this revision.
Herald added subscribers: jobnoorman, luke, sunshaoce, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
BeMg requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159399
Files:
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
llvm/test/CodeGen/RISCV/riscv-func-target-feature.ll
Index: llvm/test/CodeGen/RISCV/riscv-func-target-feature.ll
===================================================================
--- llvm/test/CodeGen/RISCV/riscv-func-target-feature.ll
+++ llvm/test/CodeGen/RISCV/riscv-func-target-feature.ll
@@ -35,10 +35,10 @@
ret void
}
-; CHECK: .option push
+; CHECK-NOT: .option push
define void @test5() "target-features"="+unaligned-scalar-mem" {
; CHECK-LABEL: test5
-; CHECK: .option pop
+; CHECK-NOT: .option pop
entry:
ret void
}
Index: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -89,7 +89,7 @@
void emitFunctionEntryLabel() override;
void emitDirectiveOptionArch();
- bool isSameAttribute();
+ bool isSameSupportedAttribute();
private:
void emitAttributes();
@@ -272,16 +272,25 @@
RTS.emitDirectiveOptionArch(NeedEmitStdOptionArgs);
}
-bool RISCVAsmPrinter::isSameAttribute() {
+bool RISCVAsmPrinter::isSameSupportedAttribute() {
const MCSubtargetInfo &MCSTI = *TM.getMCSubtargetInfo();
- return MCSTI.getFeatureBits() == STI->getFeatureBits();
+ for (const auto &Feature : RISCVFeatureKV) {
+ if (STI->hasFeature(Feature.Value) == MCSTI.hasFeature(Feature.Value))
+ continue;
+
+ if (!llvm::RISCVISAInfo::isSupportedExtensionFeature(Feature.Key))
+ continue;
+
+ return false;
+ }
+ return true;
}
bool RISCVAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
STI = &MF.getSubtarget<RISCVSubtarget>();
RISCVTargetStreamer &RTS =
static_cast<RISCVTargetStreamer &>(*OutStreamer->getTargetStreamer());
- if (!isSameAttribute()) {
+ if (!isSameSupportedAttribute()) {
RTS.emitDirectiveOptionPush();
emitDirectiveOptionArch();
}
@@ -289,7 +298,7 @@
SetupMachineFunction(MF);
emitFunctionBody();
- if (!isSameAttribute())
+ if (!isSameSupportedAttribute())
RTS.emitDirectiveOptionPop();
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159399.555579.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230902/be5b635f/attachment.bin>
More information about the llvm-commits
mailing list