@@ -343,6 +343,28 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple,
343343 AddTargetFeature (Args, Features, options::OPT_mno_madd4, options::OPT_mmadd4,
344344 " nomadd4" );
345345 AddTargetFeature (Args, Features, options::OPT_mmt, options::OPT_mno_mt, " mt" );
346+
347+ if (Arg *A = Args.getLastArg (options::OPT_mindirect_jump_EQ)) {
348+ StringRef Val = StringRef (A->getValue ());
349+ if (Val == " hazard" ) {
350+ Arg *B =
351+ Args.getLastArg (options::OPT_mmicromips, options::OPT_mno_micromips);
352+ Arg *C = Args.getLastArg (options::OPT_mips16, options::OPT_mno_mips16);
353+
354+ if (B && B->getOption ().matches (options::OPT_mmicromips))
355+ D.Diag (diag::err_drv_unsupported_indirect_jump_opt)
356+ << " hazard" << " micromips" ;
357+ else if (C && C->getOption ().matches (options::OPT_mips16))
358+ D.Diag (diag::err_drv_unsupported_indirect_jump_opt)
359+ << " hazard" << " mips16" ;
360+ else if (mips::supportsIndirectJumpHazardBarrier (CPUName))
361+ Features.push_back (" +use-indirect-jump-hazard" );
362+ else
363+ D.Diag (diag::err_drv_unsupported_indirect_jump_opt)
364+ << " hazard" << CPUName;
365+ } else
366+ D.Diag (diag::err_drv_unknown_indirect_jump_opt) << Val;
367+ }
346368}
347369
348370mips::IEEE754Standard mips::getIEEE754Standard (StringRef &CPU) {
@@ -447,3 +469,20 @@ bool mips::shouldUseFPXX(const ArgList &Args, const llvm::Triple &Triple,
447469
448470 return UseFPXX;
449471}
472+
473+ bool mips::supportsIndirectJumpHazardBarrier (StringRef &CPU) {
474+ // Supporting the hazard barrier method of dealing with indirect
475+ // jumps requires MIPSR2 support.
476+ return llvm::StringSwitch<bool >(CPU)
477+ .Case (" mips32r2" , true )
478+ .Case (" mips32r3" , true )
479+ .Case (" mips32r5" , true )
480+ .Case (" mips32r6" , true )
481+ .Case (" mips64r2" , true )
482+ .Case (" mips64r3" , true )
483+ .Case (" mips64r5" , true )
484+ .Case (" mips64r6" , true )
485+ .Case (" octeon" , true )
486+ .Case (" p5600" , true )
487+ .Default (false );
488+ }
0 commit comments