@@ -67,11 +67,6 @@ static void getRISCFeaturesFromMcpu(const Driver &D, const Arg *A,
67
67
D.Diag (clang::diag::err_drv_unsupported_option_argument)
68
68
<< A->getSpelling () << Mcpu;
69
69
}
70
-
71
- if (llvm::RISCV::hasFastUnalignedAccess (Mcpu)) {
72
- Features.push_back (" +unaligned-scalar-mem" );
73
- Features.push_back (" +unaligned-vector-mem" );
74
- }
75
70
}
76
71
77
72
void riscv::getRISCVTargetFeatures (const Driver &D, const llvm::Triple &Triple,
@@ -82,6 +77,8 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
82
77
if (!getArchFeatures (D, MArch, Features, Args))
83
78
return ;
84
79
80
+ bool CPUFastUnaligned = false ;
81
+
85
82
// If users give march and mcpu, get std extension feature from MArch
86
83
// and other features (ex. mirco architecture feature) from mcpu
87
84
if (Arg *A = Args.getLastArg (options::OPT_mcpu_EQ)) {
@@ -90,6 +87,9 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
90
87
CPU = llvm::sys::getHostCPUName ();
91
88
92
89
getRISCFeaturesFromMcpu (D, A, Triple, CPU, Features);
90
+
91
+ if (llvm::RISCV::hasFastUnalignedAccess (CPU))
92
+ CPUFastUnaligned = true ;
93
93
}
94
94
95
95
// Handle features corresponding to "-ffixed-X" options
@@ -169,18 +169,23 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
169
169
Features.push_back (" -relax" );
170
170
}
171
171
172
- // Android requires fast unaligned access on RISCV64.
173
- if (Triple.isAndroid ()) {
172
+ // If -mstrict-align or -mno-strict-align is passed, use it. Otherwise, the
173
+ // unaligned-*-mem is enabled if the CPU supports it or the target is
174
+ // Android.
175
+ if (const Arg *A = Args.getLastArg (options::OPT_mno_strict_align,
176
+ options::OPT_mstrict_align)) {
177
+ if (A->getOption ().matches (options::OPT_mno_strict_align)) {
178
+ Features.push_back (" +unaligned-scalar-mem" );
179
+ Features.push_back (" +unaligned-vector-mem" );
180
+ } else {
181
+ Features.push_back (" -unaligned-scalar-mem" );
182
+ Features.push_back (" -unaligned-vector-mem" );
183
+ }
184
+ } else if (CPUFastUnaligned || Triple.isAndroid ()) {
174
185
Features.push_back (" +unaligned-scalar-mem" );
175
186
Features.push_back (" +unaligned-vector-mem" );
176
187
}
177
188
178
- // -mstrict-align is default, unless -mno-strict-align is specified.
179
- AddTargetFeature (Args, Features, options::OPT_mno_strict_align,
180
- options::OPT_mstrict_align, " unaligned-scalar-mem" );
181
- AddTargetFeature (Args, Features, options::OPT_mno_strict_align,
182
- options::OPT_mstrict_align, " unaligned-vector-mem" );
183
-
184
189
// Now add any that the user explicitly requested on the command line,
185
190
// which may override the defaults.
186
191
handleTargetFeaturesGroup (D, Triple, Args, Features,
0 commit comments