@@ -100,7 +100,7 @@ class RISCVAsmPrinter : public AsmPrinter {
100
100
bool emitDirectiveOptionArch ();
101
101
102
102
private:
103
- void emitAttributes ();
103
+ void emitAttributes (const MCSubtargetInfo &SubtargetInfo );
104
104
105
105
void emitNTLHint (const MachineInstr *MI);
106
106
@@ -385,8 +385,32 @@ void RISCVAsmPrinter::emitStartOfAsmFile(Module &M) {
385
385
if (const MDString *ModuleTargetABI =
386
386
dyn_cast_or_null<MDString>(M.getModuleFlag (" target-abi" )))
387
387
RTS.setTargetABI (RISCVABI::getTargetABI (ModuleTargetABI->getString ()));
388
+
389
+ MCSubtargetInfo SubtargetInfo = *TM.getMCSubtargetInfo ();
390
+
391
+ // Use module flag to update feature bits.
392
+ if (auto *MD = dyn_cast_or_null<MDNode>(M.getModuleFlag (" riscv-isa" ))) {
393
+ for (auto &ISA : MD->operands ()) {
394
+ if (auto *ISAString = dyn_cast_or_null<MDString>(ISA)) {
395
+ auto ParseResult = llvm::RISCVISAInfo::parseArchString (
396
+ ISAString->getString (), /* EnableExperimentalExtension=*/ true ,
397
+ /* ExperimentalExtensionVersionCheck=*/ true );
398
+ if (!errorToBool (ParseResult.takeError ())) {
399
+ auto &ISAInfo = *ParseResult;
400
+ for (const auto &Feature : RISCVFeatureKV) {
401
+ if (ISAInfo->hasExtension (Feature.Key ) &&
402
+ !SubtargetInfo.hasFeature (Feature.Value ))
403
+ SubtargetInfo.ToggleFeature (Feature.Key );
404
+ }
405
+ }
406
+ }
407
+ }
408
+
409
+ RTS.setFlagsFromFeatures (SubtargetInfo);
410
+ }
411
+
388
412
if (TM.getTargetTriple ().isOSBinFormatELF ())
389
- emitAttributes ();
413
+ emitAttributes (SubtargetInfo );
390
414
}
391
415
392
416
void RISCVAsmPrinter::emitEndOfAsmFile (Module &M) {
@@ -398,13 +422,13 @@ void RISCVAsmPrinter::emitEndOfAsmFile(Module &M) {
398
422
EmitHwasanMemaccessSymbols (M);
399
423
}
400
424
401
- void RISCVAsmPrinter::emitAttributes () {
425
+ void RISCVAsmPrinter::emitAttributes (const MCSubtargetInfo &SubtargetInfo ) {
402
426
RISCVTargetStreamer &RTS =
403
427
static_cast <RISCVTargetStreamer &>(*OutStreamer->getTargetStreamer ());
404
428
// Use MCSubtargetInfo from TargetMachine. Individual functions may have
405
429
// attributes that differ from other functions in the module and we have no
406
430
// way to know which function is correct.
407
- RTS.emitTargetAttributes (*TM. getMCSubtargetInfo () , /* EmitStackAlign*/ true );
431
+ RTS.emitTargetAttributes (SubtargetInfo , /* EmitStackAlign*/ true );
408
432
}
409
433
410
434
void RISCVAsmPrinter::emitFunctionEntryLabel () {
0 commit comments