Skip to content

Commit 42896ee

Browse files
committed
[clang] -falign-loops=
1 parent 13f95cc commit 42896ee

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ CODEGENOPT(StackRealignment , 1, 0) ///< Control whether to force stack
293293
///< realignment.
294294
CODEGENOPT(UseInitArray , 1, 0) ///< Control whether to use .init_array or
295295
///< .ctors.
296+
VALUE_CODEGENOPT(LoopAlignment , 32, 0) ///< Overrides default loop
297+
///< alignment, if not 0.
296298
VALUE_CODEGENOPT(StackAlignment , 32, 0) ///< Overrides default stack
297299
///< alignment, if not 0.
298300
VALUE_CODEGENOPT(StackProbeSize , 32, 4096) ///< Overrides default stack

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ ENUM_LANGOPT(ClangABICompat, ClangABI, 4, ClangABI::Latest,
396396
"with")
397397

398398
COMPATIBLE_VALUE_LANGOPT(FunctionAlignment, 5, 0, "Default alignment for functions")
399+
COMPATIBLE_VALUE_LANGOPT(LoopAlignment, 4, 0, "Default alignment for loops")
399400

400401
LANGOPT(FixedPoint, 1, 0, "fixed point types")
401402
LANGOPT(PaddingOnUnsignedFixedPoint, 1, 0,

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,8 @@ defm access_control : BoolFOption<"access-control",
10641064
PosFlag<SetTrue>>;
10651065
def falign_functions : Flag<["-"], "falign-functions">, Group<f_Group>;
10661066
def falign_functions_EQ : Joined<["-"], "falign-functions=">, Group<f_Group>;
1067+
def falign_loops_EQ : Joined<["-"], "falign-loops=">, Group<f_Group>,
1068+
MarshallingInfoInt<CodeGenOpts<"LoopAlignment">>;
10671069
def fno_align_functions: Flag<["-"], "fno-align-functions">, Group<f_Group>;
10681070
defm allow_editor_placeholders : BoolFOption<"allow-editor-placeholders",
10691071
LangOpts<"AllowEditorPlaceholders">, DefaultFalse,
@@ -4293,7 +4295,6 @@ def ld_path_EQ : Joined<["--"], "ld-path=">, Group<Link_Group>;
42934295
defm align_labels : BooleanFFlag<"align-labels">, Group<clang_ignored_gcc_optimization_f_Group>;
42944296
def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group<clang_ignored_gcc_optimization_f_Group>;
42954297
defm align_loops : BooleanFFlag<"align-loops">, Group<clang_ignored_gcc_optimization_f_Group>;
4296-
def falign_loops_EQ : Joined<["-"], "falign-loops=">, Group<clang_ignored_gcc_optimization_f_Group>;
42974298
defm align_jumps : BooleanFFlag<"align-jumps">, Group<clang_ignored_gcc_optimization_f_Group>;
42984299
def falign_jumps_EQ : Joined<["-"], "falign-jumps=">, Group<clang_ignored_gcc_optimization_f_Group>;
42994300

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
581581
CodeGenOpts.ValueTrackingVariableLocations;
582582
Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex;
583583

584+
Options.LoopAlignment = CodeGenOpts.LoopAlignment;
585+
584586
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
585587
Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
586588
Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4720,6 +4720,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
47204720
CmdArgs.push_back(Args.MakeArgString(std::to_string(FunctionAlignment)));
47214721
}
47224722

4723+
if (const Arg *A = Args.getLastArg(options::OPT_falign_loops_EQ)) {
4724+
unsigned Value = 0;
4725+
if (StringRef(A->getValue()).getAsInteger(10, Value) || Value > 65536)
4726+
TC.getDriver().Diag(diag::err_drv_invalid_int_value)
4727+
<< A->getAsString(Args) << A->getValue();
4728+
Value = Value ? 1u << llvm::Log2_32_Ceil(std::min(Value, 65536u)) : 0;
4729+
CmdArgs.push_back(Args.MakeArgString("-falign-loops=" + Twine(Value)));
4730+
}
4731+
47234732
llvm::Reloc::Model RelocationModel;
47244733
unsigned PICLevel;
47254734
bool IsPIE;

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ namespace llvm {
328328
/// passed on the command line.
329329
std::string StackUsageOutput;
330330

331+
unsigned LoopAlignment = 0;
332+
331333
/// FloatABIType - This setting is set by -float-abi=xxx option is specfied
332334
/// on the command line. This setting may either be Default, Soft, or Hard.
333335
/// Default selects the target's default behavior. Soft selects the ABI for

0 commit comments

Comments
 (0)