This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] emit .option directive for functions with target features which differ from module default
ClosedPublic

Authored by BeMg on Jul 12 2023, 11:10 PM.

Details

Summary

When function has different attributes from module, emit the .option <attribute> before the function body. This allows non-integrated assemblers to properly assemble the functions (which may contain instructions dependent on the extra target features).

Diff Detail

Event Timeline

BeMg created this revision.Jul 12 2023, 11:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2023, 11:10 PM
BeMg requested review of this revision.Jul 12 2023, 11:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2023, 11:10 PM
BeMg edited the summary of this revision. (Show Details)Jul 12 2023, 11:20 PM

You need testcase I think?

BeMg updated this revision to Diff 539904.Jul 13 2023, 2:21 AM

move riscv-func-attr-target.ll to this patch

asb added inline comments.Jul 13 2023, 7:12 AM
llvm/test/CodeGen/RISCV/riscv-func-attr-target.ll
2 ↗(On Diff #539904)

I think you want a test function that _doesn't_ have any additional target-features, and you can then verify that .option arch isn't blindly emitted for every function (rather than just those where it differs to the module).

reames retitled this revision from [RISCV] emit .option directive when attribute different to [RISCV] emit .option directive for functions with target features which differ from module default.Jul 13 2023, 8:09 AM
reames edited the summary of this revision. (Show Details)
reames added inline comments.Jul 13 2023, 8:16 AM
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
256

Suggestion:

if (STI->hasFeature(Feature.Value) == MCSTI.hasFeature(Feature.Value))
  continue;
auto Delta = STI->hasFeature(Feature.Value) ?  RISCVOptionArchArgType::Plus : RISCVOptionArchArgType::Minus;   
NeedEmitStdOptionArgs.emplace_back(Delta, Feature.Key);
llvm/test/CodeGen/RISCV/riscv-func-attr-target.ll
1 ↗(On Diff #539904)

Change the test name to riscv-func-target-feature.ll

BeMg updated this revision to Diff 540320.Jul 14 2023, 1:42 AM
BeMg edited the summary of this revision. (Show Details)
  1. Update test
  2. Use another way to select the feature need to be emitted
craig.topper added inline comments.Jul 26 2023, 10:12 AM
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
257

Please use STI->hasFeature(Feature.Value) == MCSTI.hasFeature(Feature.Value) here

265

NeedEmitStdOptionArgs can be empty here. emitDirectiveOptionArch does not handle an empty list gracefully.

BeMg updated this revision to Diff 544592.Jul 26 2023, 9:38 PM
BeMg marked 3 inline comments as done.
  1. Update condition
  2. Check whether NeedEmitStdOptionArgs is empty
BeMg marked 2 inline comments as done.Jul 26 2023, 9:39 PM
reames accepted this revision.Jul 31 2023, 9:15 AM

LGTM

This revision is now accepted and ready to land.Jul 31 2023, 9:15 AM
craig.topper added inline comments.Jul 31 2023, 12:36 PM
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
257

Should we check this condition first? It's probably cheaper than RISCVISAInfo::isSupportedExtensionFeature

llvm/test/CodeGen/RISCV/riscv-func-target-feature.ll
2

I don't see any tests for disabling an extension?

BeMg updated this revision to Diff 546310.Aug 1 2023, 9:01 PM
  1. reorder hasFeature and isSupportedExtensionFeature
  2. Add disabling extension directive test and remove some testcase