llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-regalloc Author: Fangrui Song (MaskRay) <details> <summary>Changes</summary> Move the cl::opts of TargetPassConfig.cpp and CodeGenPrepare.cpp into CodeGenOptions.td, private to lib/CodeGen; other files will follow. -enable-machine-outliner (cl::ValueOptional) and -regalloc (RegisterPassParser) stay cl::opt. CodeGenPrepare and its addressing-mode helpers hold `const CodeGenOptions &Opts`; TargetPassConfig functions read CodeGenOptions::Global. getCGPassBuilderOption() converts std::optional<bool> members to the cl::boolOrDefault fields of the public CGPassBuilderOption. -basic-block-section-match-infer, which was not cl::Hidden, is now listed by -help-hidden only. Aided by Opus 5.5 --- <sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub> --- Patch is 85.08 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/228729.diff 9 Files Affected: - (modified) llvm/lib/CodeGen/CMakeLists.txt (+8) - (added) llvm/lib/CodeGen/CodeGenOptions.cpp (+15) - (added) llvm/lib/CodeGen/CodeGenOptions.h (+19) - (added) llvm/lib/CodeGen/CodeGenOptions.td (+200) - (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+95-220) - (modified) llvm/lib/CodeGen/RegisterUsageInfo.cpp (+2-5) - (modified) llvm/lib/CodeGen/TargetPassConfig.cpp (+142-318) - (modified) llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn (+10) - (modified) utils/bazel/llvm-project-overlay/llvm/BUILD.bazel (+11) ``````````diff diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt index 7db7c1ca93243..211ce644a4162 100644 --- a/llvm/lib/CodeGen/CMakeLists.txt +++ b/llvm/lib/CodeGen/CMakeLists.txt @@ -33,6 +33,11 @@ elseif (DEFINED LLVM_HAVE_TF_AOT OR LLVM_HAVE_TFLITE) endif() endif() +set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS) +set(LLVM_TARGET_DEFINITIONS CodeGenOptions.td) +tablegen(LLVM CodeGenOptions.inc -gen-opt-parser-defs) +add_public_tablegen_target(CodeGenOptionsTableGen) + add_llvm_component_library(LLVMCodeGen AggressiveAntiDepBreaker.cpp AllocationOrder.cpp @@ -54,6 +59,7 @@ add_llvm_component_library(LLVMCodeGen CFIInstrInserter.cpp CodeGen.cpp CodeGenCommonISel.cpp + CodeGenOptions.cpp CodeGenPrepare.cpp CommandFlags.cpp ComplexDeinterleavingPass.cpp @@ -284,6 +290,7 @@ add_llvm_component_library(LLVMCodeGen LINK_LIBS ${LLVM_PTHREAD_LIB} ${MLLinkDeps} DEPENDS + CodeGenOptionsTableGen intrinsics_gen vt_gen ${MLDeps} @@ -297,6 +304,7 @@ add_llvm_component_library(LLVMCodeGen Core MC ObjCARC + Option ProfileData Scalar Support diff --git a/llvm/lib/CodeGen/CodeGenOptions.cpp b/llvm/lib/CodeGen/CodeGenOptions.cpp new file mode 100644 index 0000000000000..31cb2dafa020b --- /dev/null +++ b/llvm/lib/CodeGen/CodeGenOptions.cpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CodeGenOptions.h" +#include "llvm/Option/LibraryOptions.h" + +#define OPTIONS_STRUCT_DEFS +#include "CodeGenOptions.inc" + +static llvm::opt::RegisterLibraryOptions<llvm::CodeGenOptions> Registration; diff --git a/llvm/lib/CodeGen/CodeGenOptions.h b/llvm/lib/CodeGen/CodeGenOptions.h new file mode 100644 index 0000000000000..657850dcbe5df --- /dev/null +++ b/llvm/lib/CodeGen/CodeGenOptions.h @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_CODEGEN_CODEGENOPTIONS_H +#define LLVM_LIB_CODEGEN_CODEGENOPTIONS_H + +#include "llvm/Target/TargetOptions.h" +#include <cstdint> +#include <optional> + +#define OPTIONS_STRUCT_DECL +#include "CodeGenOptions.inc" + +#endif // LLVM_LIB_CODEGEN_CODEGENOPTIONS_H diff --git a/llvm/lib/CodeGen/CodeGenOptions.td b/llvm/lib/CodeGen/CodeGenOptions.td new file mode 100644 index 0000000000000..02e22f778a01f --- /dev/null +++ b/llvm/lib/CodeGen/CodeGenOptions.td @@ -0,0 +1,200 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +include "llvm/Option/LibraryOptions.td" + +def CodeGenOptions : OptionsStruct; + +defm : BoolField<"addr-sink-combine-base-gv", "true", + "Allow combining of BaseGV field in Address sinking">; +defm : BoolField<"addr-sink-combine-base-offs", "true", + "Allow combining of BaseOffs field in Address sinking">; +defm : BoolField<"addr-sink-combine-base-reg", "true", + "Allow combining of BaseReg field in Address sinking">; +defm : BoolField<"addr-sink-combine-scaled-reg", "true", + "Allow combining of ScaledReg field in Address sinking">; +defm : BoolField<"addr-sink-new-phis", "false", + "Allow creation of Phis in Address sinking">; +defm : BoolField<"addr-sink-new-select", "true", + "Allow creation of selects in Address sinking">; +defm : OptionalBoolField<"addr-sink-using-gep", + "Address sinking in CGP using GEPs">; +defm : BoolField<"basic-block-section-match-infer", "false", + "Enable matching and inference when generating basic block sections">; +defm : BoolField<"bbsections-guided-section-prefix", "true", + "Use the basic-block-sections profile to determine the text section prefix for hot functions. " + "Functions with basic-block-sections profile will be placed in `.text.hot` regardless of their FDO profile info. " + "Other functions won't be impacted, i.e., their prefixes will be decided by FDO/sampleFDO profiles">; +defm : ValueField<"cgp-freq-ratio-to-skip-merge", "uint64_t", "2", + "Skip merging empty blocks if (frequency of empty block) / (frequency of destination block) is greater than this ratio">; +defm : BoolField<"cgp-icmp-eq2icmp-st", "false", + "Enable ICMP_EQ to ICMP_S(L|G)T conversion">; +defm : ValueField<"cgp-max-address-users-to-scan", "unsigned", "100", + "Max number of address users to look at">; +defm : BoolField<"cgp-optimize-phi-types", "true", + "Enable converting phi types in CodeGenPrepare">; +defm : BoolField<"cgp-split-large-offset-gep", "true", + "Enable splitting large offset of GEP">; +defm : BoolField<"cgp-type-promotion-merge", "true", + "Enable merging of redundant sexts when one is dominating the other">; +defm : BoolField<"cgp-verify-bfi-updates", "false", + "Enable BFI update verification for CodeGenPrepare">; +defm : ValueField<"cgpp-huge-func", "unsigned", "10000", + "Least BB number of huge function">; +defm : BoolField<"codegen-pipeline-trigger-crash", "false", + "Trigger crash in codegen pipeline">; +defm : OptionalBoolField<"debugify-and-strip-all-safe", + "Debugify MIR before and Strip debug after each pass except those known to be unsafe when debug info is present">; +defm : OptionalBoolField<"debugify-check-and-strip-all-safe", + "Debugify MIR before, by checking and stripping the debug info after, each pass except those known to be unsafe when debug info is present">; +defm : BoolField<"disable-atexit-based-global-dtor-lowering", "false", + "For MachO, disable atexit()-based global destructor lowering">; +defm : BoolField<"disable-block-placement", "false", + "Disable probability-driven block placement">; +defm : BoolField<"disable-branch-fold", "false", + "Disable branch folding">; +// Disable the pass to fix unwind information. Whether the pass is included in +// the pipeline is controlled via the target options, this option serves as +// manual override. +defm : BoolField<"disable-cfi-fixup", "false", + "Disable the CFI fixup pass">; +defm : BoolField<"disable-cgp", "false", + "Disable Codegen Prepare">; +defm : BoolField<"disable-cgp-branch-opts", "false", + "Disable branch optimizations in CodeGenPrepare">; +defm : BoolField<"disable-cgp-delete-phis", "false", + "Disable elimination of dead PHI nodes">; +defm : BoolField<"disable-cgp-ext-ld-promotion", "false", + "Disable ext(promotable(ld)) -> promoted(ext(ld)) optimization in CodeGenPrepare">; +defm : BoolField<"disable-cgp-gc-opts", "false", + "Disable GC optimizations in CodeGenPrepare">; +defm : BoolField<"disable-cgp-select2branch", "false", + "Disable select to branch conversion">; +defm : BoolField<"disable-cgp-store-extract", "false", + "Disable store(extract) optimizations in CodeGenPrepare">; +defm : BoolField<"disable-complex-addr-modes", "false", + "Disables combining addressing modes with different parts in optimizeMemoryInst">; +defm : BoolField<"disable-constant-hoisting", "false", + "Disable ConstantHoisting">; +defm : BoolField<"disable-copyprop", "false", + "Disable Copy Propagation pass">; +defm : BoolField<"disable-early-ifcvt", "false", + "Disable Early If-conversion">; +defm : BoolField<"disable-early-taildup", "false", + "Disable pre-register allocation tail duplication">; +defm : BoolField<"disable-expand-reductions", "false", + "Disable the expand reduction intrinsics pass from running">; +// Disable MIRProfileLoader before BlockPlacement. This is for debugging and +// tuning purpose. +defm : BoolField<"disable-layout-fsprofile-loader", "false", + "Disable MIRProfileLoader before BlockPlacement">; +defm : BoolField<"disable-lsr", "false", + "Disable Loop Strength Reduction Pass">; +defm : BoolField<"disable-machine-cse", "false", + "Disable Machine Common Subexpression Elimination">; +defm : BoolField<"disable-machine-dce", "false", + "Disable Machine Dead Code Elimination">; +defm : BoolField<"disable-machine-licm", "false", + "Disable Machine LICM">; +defm : BoolField<"disable-machine-sink", "false", + "Disable Machine Sinking">; +defm : BoolField<"disable-partial-libcall-inlining", "false", + "Disable Partial Libcall Inlining">; +defm : BoolField<"disable-post-ra", "false", + "Disable Post Regalloc Scheduler">; +defm : BoolField<"disable-postra-machine-licm", "false", + "Disable Machine LICM">; +defm : BoolField<"disable-postra-machine-sink", "false", + "Disable PostRA Machine Sinking">; +defm : BoolField<"disable-preheader-prot", "false", + "Disable protection against removing loop preheaders">; +// Disable MIRProfileLoader before RegAlloc. This is for debugging and tuning +// purpose. +defm : BoolField<"disable-ra-fsprofile-loader", "false", + "Disable MIRProfileLoader before RegAlloc">; +defm : BoolField<"disable-replace-with-vec-lib", "false", + "Disable replace with vector math call pass">; +defm : BoolField<"disable-select-optimize", "true", + "Disable the select-optimization pass from running">; +defm : BoolField<"disable-ssc", "false", + "Disable Stack Slot Coloring">; +defm : BoolField<"disable-tail-duplicate", "false", + "Disable tail duplication">; +defm : BoolField<"enable-andcmp-sinking", "true", + "Enable sinking and/cmp into branches">; +defm : BoolField<"enable-block-placement-stats", "false", + "Collect probability-driven block placement stats">; +defm : BoolField<"enable-gc-empty-basic-blocks", "false", + "Enable garbage-collecting empty basic blocks">; +defm : BoolField<"enable-global-merge-func", "false", + "Enable global merge functions that are based on hash function">; +defm : BoolField<"enable-implicit-null-checks", "false", + "Fold null checks into faulting memory operations">; +defm : OptionalBoolField<"enable-ipra", + "Enable interprocedural register allocation to reduce load/store at procedure calls">; +defm : BoolField<"enable-split-machine-functions", "false", + "Split out cold blocks from machine functions based on profile information">; +// Enable or disable FastISel. Both options are needed, because +// FastISel is enabled by default with -fast, and we wish to be +// able to enable or disable fast-isel independently from -O0. +defm : OptionalBoolField<"fast-isel", + "Enable the \"fast\" instruction selector">; +defm : BoolField<"force-split-store", "false", + "Force store splitting no matter what the target query says">; +let MetaVarName = "<filename>" in +defm : ValueField<"fs-profile-file", "StringRef", "\"\"", + "Flow Sensitive profile file name">; +let MetaVarName = "<filename>" in +defm : ValueField<"fs-remapping-file", "StringRef", "\"\"", + "Flow Sensitive profile remapping file name">; +defm : OptionalBoolField<"global-isel", + "Enable the \"global\" instruction selector">; +defm : EnumField<"global-isel-abort", "std::optional<GlobalISelAbortMode>", "std::nullopt", + "0,1,2", ["GlobalISelAbortMode::Disable", "GlobalISelAbortMode::Enable", + "GlobalISelAbortMode::DisableWithDiag"], + "Enable abort calls when \"global\" instruction selection fails to lower/select an instruction">; +// Temporary option to allow experimenting with MachineScheduler as a post-RA +// scheduler. Targets can "properly" enable this with +// substitutePass(&PostRASchedulerID, &PostMachineSchedulerID). +// Targets can return true in targetSchedulesPostRAScheduling() and +// insert a PostRA scheduling pass wherever it wants. +defm : BoolField<"misched-postra", "false", + "Run MachineScheduler post regalloc (independent of preRA sched)">; +// FIXME: remove this after switching to NPM or GlobalISel, whichever gets there +// first... +defm : BoolField<"print-after-isel", "false", + "Print machine instrs after ISel">; +defm : BoolField<"print-isel-input", "false", + "Print LLVM IR input to isel pass">; +defm : BoolField<"print-regusage", "false", + "Print register usage details collected for IPRA">; +defm : BoolField<"profile-guided-section-prefix", "true", + "Use profile info to add section prefix for hot/cold functions">; +defm : BoolField<"profile-unknown-in-special-section", "false", + "In profiling mode like sampleFDO, if a function doesn't have profile, we cannot tell the function is cold for sure because it may be a function newly added without ever being sampled. " + "With the flag enabled, compiler can put such profile unknown functions into a special section, so runtime system can choose to handle it in a different way than .text section, to save RAM for example">; +defm : BoolField<"split-static-data", "false", + "Split static data sections into hot and cold sections using profile information">; +let MetaVarName = "<pass-name>" in +defm : ValueField<"start-after", "StringRef", "\"\"", + "Resume compilation after a specific pass">; +let MetaVarName = "<pass-name>" in +defm : ValueField<"start-before", "StringRef", "\"\"", + "Resume compilation before a specific pass">; +let MetaVarName = "<pass-name>" in +defm : ValueField<"stop-after", "StringRef", "\"\"", + "Stop compilation after a specific pass">; +let MetaVarName = "<pass-name>" in +defm : ValueField<"stop-before", "StringRef", "\"\"", + "Stop compilation before a specific pass">; +defm : BoolField<"stress-cgp-ext-ld-promotion", "false", + "Stress test ext(promotable(ld)) -> promoted(ext(ld)) optimization in CodeGenPrepare">; +defm : BoolField<"stress-cgp-store-extract", "false", + "Stress test store(extract) optimizations in CodeGenPrepare">; +defm : OptionalBoolField<"verify-machineinstrs", + "Verify generated machine code">; diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 0b96c77ff33ea..042094c817a46 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/CodeGenPrepare.h" +#include "CodeGenOptions.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" @@ -137,147 +138,6 @@ STATISTIC(NumDbgValueMoved, "Number of debug value instructions moved"); STATISTIC(NumSelectsExpanded, "Number of selects turned into branches"); STATISTIC(NumStoreExtractExposed, "Number of store(extractelement) exposed"); -static cl::opt<bool> DisableBranchOpts( - "disable-cgp-branch-opts", cl::Hidden, cl::init(false), - cl::desc("Disable branch optimizations in CodeGenPrepare")); - -static cl::opt<bool> - DisableGCOpts("disable-cgp-gc-opts", cl::Hidden, cl::init(false), - cl::desc("Disable GC optimizations in CodeGenPrepare")); - -static cl::opt<bool> - DisableSelectToBranch("disable-cgp-select2branch", cl::Hidden, - cl::init(false), - cl::desc("Disable select to branch conversion.")); - -static cl::opt<bool> - AddrSinkUsingGEPs("addr-sink-using-gep", cl::Hidden, cl::init(true), - cl::desc("Address sinking in CGP using GEPs.")); - -static cl::opt<bool> - EnableAndCmpSinking("enable-andcmp-sinking", cl::Hidden, cl::init(true), - cl::desc("Enable sinking and/cmp into branches.")); - -static cl::opt<bool> DisableStoreExtract( - "disable-cgp-store-extract", cl::Hidden, cl::init(false), - cl::desc("Disable store(extract) optimizations in CodeGenPrepare")); - -static cl::opt<bool> StressStoreExtract( - "stress-cgp-store-extract", cl::Hidden, cl::init(false), - cl::desc("Stress test store(extract) optimizations in CodeGenPrepare")); - -static cl::opt<bool> DisableExtLdPromotion( - "disable-cgp-ext-ld-promotion", cl::Hidden, cl::init(false), - cl::desc("Disable ext(promotable(ld)) -> promoted(ext(ld)) optimization in " - "CodeGenPrepare")); - -static cl::opt<bool> StressExtLdPromotion( - "stress-cgp-ext-ld-promotion", cl::Hidden, cl::init(false), - cl::desc("Stress test ext(promotable(ld)) -> promoted(ext(ld)) " - "optimization in CodeGenPrepare")); - -static cl::opt<bool> DisablePreheaderProtect( - "disable-preheader-prot", cl::Hidden, cl::init(false), - cl::desc("Disable protection against removing loop preheaders")); - -static cl::opt<bool> ProfileGuidedSectionPrefix( - "profile-guided-section-prefix", cl::Hidden, cl::init(true), - cl::desc("Use profile info to add section prefix for hot/cold functions")); - -static cl::opt<bool> ProfileUnknownInSpecialSection( - "profile-unknown-in-special-section", cl::Hidden, - cl::desc("In profiling mode like sampleFDO, if a function doesn't have " - "profile, we cannot tell the function is cold for sure because " - "it may be a function newly added without ever being sampled. " - "With the flag enabled, compiler can put such profile unknown " - "functions into a special section, so runtime system can choose " - "to handle it in a different way than .text section, to save " - "RAM for example. ")); - -static cl::opt<bool> BBSectionsGuidedSectionPrefix( - "bbsections-guided-section-prefix", cl::Hidden, cl::init(true), - cl::desc("Use the basic-block-sections profile to determine the text " - "section prefix for hot functions. Functions with " - "basic-block-sections profile will be placed in `.text.hot` " - "regardless of their FDO profile info. Other functions won't be " - "impacted, i.e., their prefixes will be decided by FDO/sampleFDO " - "profiles.")); - -static cl::opt<uint64_t> FreqRatioToSkipMerge( - "cgp-freq-ratio-to-skip-merge", cl::Hidden, cl::init(2), - cl::desc("Skip merging empty blocks if (frequency of empty block) / " - "(frequency of destination block) is greater than this ratio")); - -static cl::opt<bool> ForceSplitStore( - "force-split-store", cl::Hidden, cl::init(false), - cl::desc("Force store splitting no matter what the target query says.")); - -static cl::opt<bool> EnableTypePromotionMerge( - "cgp-type-promotion-merge", cl::Hidden, - cl::desc("Enable merging of redundant sexts when one is dominating" - " the other."), - cl::init(true)); - -static cl::opt<bool> DisableComplexAddrModes( - "disable-complex-addr-modes", cl::Hidden, cl::init(false), - cl::desc("Disables combining addressing modes with different parts " - "in optimizeMemoryInst.")); - -static cl::opt<bool> - AddrSinkNewPhis("addr-sink-new-phis", cl::Hidden, cl::init(false), - cl::desc("Allow creation of Phis in Address sinking.")); - -static cl::opt<bool> AddrSinkNewSelects( - "addr-sink-new-select", cl::Hidden, cl::init(true), - cl::desc("Allow creation of selects in Address sinking.")); - -static cl::opt<bool> AddrSinkCombineBaseReg( - "addr-sink-combine-base-reg", cl::Hidden, cl::init(true), - cl::desc("Allow combining of BaseReg field in Address sinking.")); - -static cl::opt<bool> AddrSinkCombineBaseGV( - "addr-sink-combine-base-gv", cl::Hidden, cl::init(true), - cl::desc("Allow combining of BaseGV field in Address sinking.")); - -static cl::opt<bool> AddrSinkCombineBaseOffs( - "addr-sink-combine-base-offs", cl::Hidden, cl::init(true), - cl::desc("Allow combining of BaseOffs field in Address sinking.")); - -static cl::opt<bool> AddrSinkCombineScaledReg( - "addr-sink-combine-scaled-reg", cl::Hidden, cl::init(true), - cl::desc("Allow combining of ScaledReg field in Address sinking.")); - -static cl::opt<bool> - EnableGEPOffsetSplit("cgp-split-large-offset-gep", cl::Hidden, - cl::init(true), - cl::desc("Enable splitting large offset of GEP.")); - -static cl::opt<bool> EnableICMP_EQToICMP_ST( - "cgp-icmp-eq2icmp-st", cl::Hidden, cl::ini... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/228729 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
