1 //===-- Scalar.h - Scalar Transformations -----------------------*- 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 // 9 // This header file defines prototypes for accessor functions that expose passes 10 // in the Scalar transformations library. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_TRANSFORMS_SCALAR_H 15 #define LLVM_TRANSFORMS_SCALAR_H 16 17 #include "llvm/Transforms/Utils/SimplifyCFGOptions.h" 18 #include <functional> 19 20 namespace llvm { 21 22 class Function; 23 class FunctionPass; 24 class Pass; 25 26 //===----------------------------------------------------------------------===// 27 // 28 // RedundantDbgInstElimination - This pass removes redundant dbg intrinsics 29 // without modifying the CFG of the function. It is a FunctionPass. 30 // 31 Pass *createRedundantDbgInstEliminationPass(); 32 33 //===----------------------------------------------------------------------===// 34 // 35 // DeadCodeElimination - This pass is more powerful than DeadInstElimination, 36 // because it is worklist driven that can potentially revisit instructions when 37 // their other instructions become dead, to eliminate chains of dead 38 // computations. 39 // 40 FunctionPass *createDeadCodeEliminationPass(); 41 42 43 //===----------------------------------------------------------------------===// 44 // 45 // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic 46 // that (optimistically) combines multiple guards into one to have fewer checks 47 // at runtime. 48 // 49 FunctionPass *createGuardWideningPass(); 50 51 52 //===----------------------------------------------------------------------===// 53 // 54 // LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a 55 // single loop at a time for use within a LoopPassManager. Desired effect is 56 // to widen guards into preheader or a single guard within loop if that's not 57 // possible. 58 // 59 Pass *createLoopGuardWideningPass(); 60 61 62 //===----------------------------------------------------------------------===// 63 // 64 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values. 65 // 66 FunctionPass *createSROAPass(bool PreserveCFG = true); 67 68 //===----------------------------------------------------------------------===// 69 // 70 // LICM - This pass is a loop invariant code motion and memory promotion pass. 71 // 72 Pass *createLICMPass(); 73 74 //===----------------------------------------------------------------------===// 75 // 76 // LoopSink - This pass sinks invariants from preheader to loop body where 77 // frequency is lower than loop preheader. 78 // 79 Pass *createLoopSinkPass(); 80 81 //===----------------------------------------------------------------------===// 82 // 83 // LoopPredication - This pass does loop predication on guards. 84 // 85 Pass *createLoopPredicationPass(); 86 87 //===----------------------------------------------------------------------===// 88 // 89 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use 90 // a loop's canonical induction variable as one of their indices. 91 // 92 Pass *createLoopStrengthReducePass(); 93 94 //===----------------------------------------------------------------------===// 95 // 96 // LoopInstSimplify - This pass simplifies instructions in a loop's body. 97 // 98 Pass *createLoopInstSimplifyPass(); 99 100 //===----------------------------------------------------------------------===// 101 // 102 // LoopUnroll - This pass is a simple loop unrolling pass. 103 // 104 Pass *createLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false, 105 bool ForgetAllSCEV = false, int Threshold = -1, 106 int Count = -1, int AllowPartial = -1, 107 int Runtime = -1, int UpperBound = -1, 108 int AllowPeeling = -1); 109 110 //===----------------------------------------------------------------------===// 111 // 112 // LoopRotate - This pass is a simple loop rotating pass. 113 // 114 Pass *createLoopRotatePass(int MaxHeaderSize = -1, bool PrepareForLTO = false); 115 116 //===----------------------------------------------------------------------===// 117 // 118 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory 119 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg 120 // hacking easier. 121 // 122 FunctionPass *createDemoteRegisterToMemoryPass(); 123 extern char &DemoteRegisterToMemoryID; 124 125 //===----------------------------------------------------------------------===// 126 // 127 // Reassociate - This pass reassociates commutative expressions in an order that 128 // is designed to promote better constant propagation, GCSE, LICM, PRE... 129 // 130 // For example: 4 + (x + 5) -> x + (4 + 5) 131 // 132 FunctionPass *createReassociatePass(); 133 134 //===----------------------------------------------------------------------===// 135 // 136 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks, 137 // simplify terminator instructions, convert switches to lookup tables, etc. 138 // 139 FunctionPass *createCFGSimplificationPass( 140 SimplifyCFGOptions Options = SimplifyCFGOptions(), 141 std::function<bool(const Function &)> Ftor = nullptr); 142 143 //===----------------------------------------------------------------------===// 144 // 145 // FlattenCFG - flatten CFG, reduce number of conditional branches by using 146 // parallel-and and parallel-or mode, etc... 147 // 148 FunctionPass *createFlattenCFGPass(); 149 150 //===----------------------------------------------------------------------===// 151 // 152 // CFG Structurization - Remove irreducible control flow 153 // 154 /// 155 /// When \p SkipUniformRegions is true the structizer will not structurize 156 /// regions that only contain uniform branches. 157 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false); 158 159 //===----------------------------------------------------------------------===// 160 // 161 // TailCallElimination - This pass eliminates call instructions to the current 162 // function which occur immediately before return instructions. 163 // 164 FunctionPass *createTailCallEliminationPass(); 165 166 //===----------------------------------------------------------------------===// 167 // 168 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator 169 // tree. 170 // 171 FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false); 172 173 //===----------------------------------------------------------------------===// 174 // 175 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads 176 // are hoisted into the header, while stores sink into the footer. 177 // 178 FunctionPass *createMergedLoadStoreMotionPass(bool SplitFooterBB = false); 179 180 //===----------------------------------------------------------------------===// 181 // 182 // ConstantHoisting - This pass prepares a function for expensive constants. 183 // 184 FunctionPass *createConstantHoistingPass(); 185 186 //===----------------------------------------------------------------------===// 187 // 188 // Sink - Code Sinking 189 // 190 FunctionPass *createSinkingPass(); 191 192 //===----------------------------------------------------------------------===// 193 // 194 // LowerAtomic - Lower atomic intrinsics to non-atomic form 195 // 196 Pass *createLowerAtomicPass(); 197 198 //===----------------------------------------------------------------------===// 199 // 200 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow. 201 // 202 Pass *createLowerGuardIntrinsicPass(); 203 204 //===----------------------------------------------------------------------===// 205 // 206 // LowerWidenableCondition - Lower widenable condition to i1 true. 207 // 208 Pass *createLowerWidenableConditionPass(); 209 210 //===----------------------------------------------------------------------===// 211 // 212 // MergeICmps - Merge integer comparison chains into a memcmp 213 // 214 Pass *createMergeICmpsLegacyPass(); 215 216 //===----------------------------------------------------------------------===// 217 // 218 // InferAddressSpaces - Modify users of addrspacecast instructions with values 219 // in the source address space if using the destination address space is slower 220 // on the target. If AddressSpace is left to its default value, it will be 221 // obtained from the TargetTransformInfo. 222 // 223 FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u); 224 extern char &InferAddressSpacesID; 225 226 //===----------------------------------------------------------------------===// 227 // 228 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates 229 // "block_weights" metadata. 230 FunctionPass *createLowerExpectIntrinsicPass(); 231 232 //===----------------------------------------------------------------------===// 233 // 234 // TLSVariableHoist - This pass reduce duplicated TLS address call. 235 // 236 FunctionPass *createTLSVariableHoistPass(); 237 238 //===----------------------------------------------------------------------===// 239 // 240 // LowerConstantIntrinsicss - Expand any remaining llvm.objectsize and 241 // llvm.is.constant intrinsic calls, even for the unknown cases. 242 // 243 FunctionPass *createLowerConstantIntrinsicsPass(); 244 245 //===----------------------------------------------------------------------===// 246 // 247 // PartiallyInlineLibCalls - Tries to inline the fast path of library 248 // calls such as sqrt. 249 // 250 FunctionPass *createPartiallyInlineLibCallsPass(); 251 252 //===----------------------------------------------------------------------===// 253 // 254 // SeparateConstOffsetFromGEP - Split GEPs for better CSE 255 // 256 FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false); 257 258 //===----------------------------------------------------------------------===// 259 // 260 // SpeculativeExecution - Aggressively hoist instructions to enable 261 // speculative execution on targets where branches are expensive. 262 // 263 FunctionPass *createSpeculativeExecutionPass(); 264 265 // Same as createSpeculativeExecutionPass, but does nothing unless 266 // TargetTransformInfo::hasBranchDivergence() is true. 267 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass(); 268 269 //===----------------------------------------------------------------------===// 270 // 271 // StraightLineStrengthReduce - This pass strength-reduces some certain 272 // instruction patterns in straight-line code. 273 // 274 FunctionPass *createStraightLineStrengthReducePass(); 275 276 //===----------------------------------------------------------------------===// 277 // 278 // NaryReassociate - Simplify n-ary operations by reassociation. 279 // 280 FunctionPass *createNaryReassociatePass(); 281 282 //===----------------------------------------------------------------------===// 283 // 284 // LoopDataPrefetch - Perform data prefetching in loops. 285 // 286 FunctionPass *createLoopDataPrefetchPass(); 287 288 //===----------------------------------------------------------------------===// 289 // 290 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops, 291 // primarily to help other loop passes. 292 // 293 Pass *createLoopSimplifyCFGPass(); 294 295 //===----------------------------------------------------------------------===// 296 // 297 // This pass does instruction simplification on each 298 // instruction in a function. 299 // 300 FunctionPass *createInstSimplifyLegacyPass(); 301 302 303 //===----------------------------------------------------------------------===// 304 // 305 // createScalarizeMaskedMemIntrinPass - Replace masked load, store, gather 306 // and scatter intrinsics with scalar code when target doesn't support them. 307 // 308 FunctionPass *createScalarizeMaskedMemIntrinLegacyPass(); 309 } // End llvm namespace 310 311 #endif 312