1 //===- llvm/CodeGen/GlobalISel/CombinerInfo.h ------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// \file 9 /// Option class for Targets to specify which operations are combined how and 10 /// when. 11 /// 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CODEGEN_GLOBALISEL_COMBINERINFO_H 15 #define LLVM_CODEGEN_GLOBALISEL_COMBINERINFO_H 16 17 #include <cassert> 18 namespace llvm { 19 20 class LegalizerInfo; 21 22 // Contains information relevant to enabling/disabling various combines for a 23 // pass. 24 struct CombinerInfo { CombinerInfoCombinerInfo25 CombinerInfo(bool AllowIllegalOps, bool ShouldLegalizeIllegal, 26 const LegalizerInfo *LInfo, bool OptEnabled, bool OptSize, 27 bool MinSize) 28 : IllegalOpsAllowed(AllowIllegalOps), 29 LegalizeIllegalOps(ShouldLegalizeIllegal), LInfo(LInfo), 30 EnableOpt(OptEnabled), EnableOptSize(OptSize), EnableMinSize(MinSize) { 31 assert(((AllowIllegalOps || !LegalizeIllegalOps) || LInfo) && 32 "Expecting legalizerInfo when illegalops not allowed"); 33 } 34 virtual ~CombinerInfo() = default; 35 /// If \p IllegalOpsAllowed is false, the CombinerHelper will make use of 36 /// the legalizerInfo to check for legality before each transformation. 37 bool IllegalOpsAllowed; // TODO: Make use of this. 38 39 /// If \p LegalizeIllegalOps is true, the Combiner will also legalize the 40 /// illegal ops that are created. 41 bool LegalizeIllegalOps; // TODO: Make use of this. 42 const LegalizerInfo *LInfo; 43 44 /// Whether optimizations should be enabled. This is to distinguish between 45 /// uses of the combiner unconditionally and only when optimizations are 46 /// specifically enabled/ 47 bool EnableOpt; 48 /// Whether we're optimizing for size. 49 bool EnableOptSize; 50 /// Whether we're optimizing for minsize (-Oz). 51 bool EnableMinSize; 52 53 /// The maximum number of times the Combiner will iterate over the 54 /// MachineFunction. Setting this to 0 enables fixed-point iteration. 55 unsigned MaxIterations = 0; 56 57 enum class ObserverLevel { 58 /// Only retry combining created/changed instructions. 59 /// This replicates the legacy default Observer behavior for use with 60 /// fixed-point iteration. 61 Basic, 62 /// Enables Observer-based detection of dead instructions. This can save 63 /// some compile-time if full disabling of fixed-point iteration is not 64 /// desired. If the input IR doesn't contain dead instructions, consider 65 /// disabling \p EnableFullDCE. 66 DCE, 67 /// Enables Observer-based DCE and additional heuristics that retry 68 /// combining defined and used instructions of modified instructions. 69 /// This provides a good balance between compile-time and completeness of 70 /// combining without needing fixed-point iteration. 71 SinglePass, 72 }; 73 74 /// Select how the Combiner acts on MIR changes. 75 ObserverLevel ObserverLvl = ObserverLevel::Basic; 76 77 /// Whether dead code elimination is performed before each Combiner iteration. 78 /// If Observer-based DCE is enabled, this controls if a full DCE pass is 79 /// performed before the first Combiner iteration. 80 bool EnableFullDCE = true; 81 }; 82 } // namespace llvm 83 84 #endif 85