Scalar.h revision 360784
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 <functional> 18 19namespace llvm { 20 21class Function; 22class FunctionPass; 23class ModulePass; 24class Pass; 25class GetElementPtrInst; 26class PassInfo; 27class TargetLowering; 28class TargetMachine; 29 30//===----------------------------------------------------------------------===// 31// 32// ConstantPropagation - A worklist driven constant propagation pass 33// 34FunctionPass *createConstantPropagationPass(); 35 36//===----------------------------------------------------------------------===// 37// 38// AlignmentFromAssumptions - Use assume intrinsics to set load/store 39// alignments. 40// 41FunctionPass *createAlignmentFromAssumptionsPass(); 42 43//===----------------------------------------------------------------------===// 44// 45// SCCP - Sparse conditional constant propagation. 46// 47FunctionPass *createSCCPPass(); 48 49//===----------------------------------------------------------------------===// 50// 51// DeadInstElimination - This pass quickly removes trivially dead instructions 52// without modifying the CFG of the function. It is a FunctionPass. 53// 54Pass *createDeadInstEliminationPass(); 55 56//===----------------------------------------------------------------------===// 57// 58// RedundantDbgInstElimination - This pass removes redundant dbg intrinsics 59// without modifying the CFG of the function. It is a FunctionPass. 60// 61Pass *createRedundantDbgInstEliminationPass(); 62 63//===----------------------------------------------------------------------===// 64// 65// DeadCodeElimination - This pass is more powerful than DeadInstElimination, 66// because it is worklist driven that can potentially revisit instructions when 67// their other instructions become dead, to eliminate chains of dead 68// computations. 69// 70FunctionPass *createDeadCodeEliminationPass(); 71 72//===----------------------------------------------------------------------===// 73// 74// DeadStoreElimination - This pass deletes stores that are post-dominated by 75// must-aliased stores and are not loaded used between the stores. 76// 77FunctionPass *createDeadStoreEliminationPass(); 78 79 80//===----------------------------------------------------------------------===// 81// 82// CallSiteSplitting - This pass split call-site based on its known argument 83// values. 84FunctionPass *createCallSiteSplittingPass(); 85 86//===----------------------------------------------------------------------===// 87// 88// AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This 89// algorithm assumes instructions are dead until proven otherwise, which makes 90// it more successful are removing non-obviously dead instructions. 91// 92FunctionPass *createAggressiveDCEPass(); 93 94//===----------------------------------------------------------------------===// 95// 96// GuardWidening - An optimization over the @llvm.experimental.guard intrinsic 97// that (optimistically) combines multiple guards into one to have fewer checks 98// at runtime. 99// 100FunctionPass *createGuardWideningPass(); 101 102 103//===----------------------------------------------------------------------===// 104// 105// LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a 106// single loop at a time for use within a LoopPassManager. Desired effect is 107// to widen guards into preheader or a single guard within loop if that's not 108// possible. 109// 110Pass *createLoopGuardWideningPass(); 111 112 113//===----------------------------------------------------------------------===// 114// 115// BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to 116// remove computations of dead bits. 117// 118FunctionPass *createBitTrackingDCEPass(); 119 120//===----------------------------------------------------------------------===// 121// 122// SROA - Replace aggregates or pieces of aggregates with scalar SSA values. 123// 124FunctionPass *createSROAPass(); 125 126//===----------------------------------------------------------------------===// 127// 128// InductiveRangeCheckElimination - Transform loops to elide range checks on 129// linear functions of the induction variable. 130// 131Pass *createInductiveRangeCheckEliminationPass(); 132 133//===----------------------------------------------------------------------===// 134// 135// InductionVariableSimplify - Transform induction variables in a program to all 136// use a single canonical induction variable per loop. 137// 138Pass *createIndVarSimplifyPass(); 139 140//===----------------------------------------------------------------------===// 141// 142// LICM - This pass is a loop invariant code motion and memory promotion pass. 143// 144Pass *createLICMPass(); 145Pass *createLICMPass(unsigned LicmMssaOptCap, 146 unsigned LicmMssaNoAccForPromotionCap); 147 148//===----------------------------------------------------------------------===// 149// 150// LoopSink - This pass sinks invariants from preheader to loop body where 151// frequency is lower than loop preheader. 152// 153Pass *createLoopSinkPass(); 154 155//===----------------------------------------------------------------------===// 156// 157// LoopPredication - This pass does loop predication on guards. 158// 159Pass *createLoopPredicationPass(); 160 161//===----------------------------------------------------------------------===// 162// 163// LoopInterchange - This pass interchanges loops to provide a more 164// cache-friendly memory access patterns. 165// 166Pass *createLoopInterchangePass(); 167 168//===----------------------------------------------------------------------===// 169// 170// LoopStrengthReduce - This pass is strength reduces GEP instructions that use 171// a loop's canonical induction variable as one of their indices. 172// 173Pass *createLoopStrengthReducePass(); 174 175//===----------------------------------------------------------------------===// 176// 177// LoopUnswitch - This pass is a simple loop unswitching pass. 178// 179Pass *createLoopUnswitchPass(bool OptimizeForSize = false, 180 bool hasBranchDivergence = false); 181 182//===----------------------------------------------------------------------===// 183// 184// LoopInstSimplify - This pass simplifies instructions in a loop's body. 185// 186Pass *createLoopInstSimplifyPass(); 187 188//===----------------------------------------------------------------------===// 189// 190// LoopUnroll - This pass is a simple loop unrolling pass. 191// 192Pass *createLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false, 193 bool ForgetAllSCEV = false, int Threshold = -1, 194 int Count = -1, int AllowPartial = -1, 195 int Runtime = -1, int UpperBound = -1, 196 int AllowPeeling = -1); 197// Create an unrolling pass for full unrolling that uses exact trip count only. 198Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false, 199 bool ForgetAllSCEV = false); 200 201//===----------------------------------------------------------------------===// 202// 203// LoopUnrollAndJam - This pass is a simple loop unroll and jam pass. 204// 205Pass *createLoopUnrollAndJamPass(int OptLevel = 2); 206 207//===----------------------------------------------------------------------===// 208// 209// LoopReroll - This pass is a simple loop rerolling pass. 210// 211Pass *createLoopRerollPass(); 212 213//===----------------------------------------------------------------------===// 214// 215// LoopRotate - This pass is a simple loop rotating pass. 216// 217Pass *createLoopRotatePass(int MaxHeaderSize = -1); 218 219//===----------------------------------------------------------------------===// 220// 221// LoopIdiom - This pass recognizes and replaces idioms in loops. 222// 223Pass *createLoopIdiomPass(); 224 225//===----------------------------------------------------------------------===// 226// 227// LoopVersioningLICM - This pass is a loop versioning pass for LICM. 228// 229Pass *createLoopVersioningLICMPass(); 230 231//===----------------------------------------------------------------------===// 232// 233// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory 234// references. In basically undoes the PromoteMemoryToRegister pass to make cfg 235// hacking easier. 236// 237FunctionPass *createDemoteRegisterToMemoryPass(); 238extern char &DemoteRegisterToMemoryID; 239 240//===----------------------------------------------------------------------===// 241// 242// Reassociate - This pass reassociates commutative expressions in an order that 243// is designed to promote better constant propagation, GCSE, LICM, PRE... 244// 245// For example: 4 + (x + 5) -> x + (4 + 5) 246// 247FunctionPass *createReassociatePass(); 248 249//===----------------------------------------------------------------------===// 250// 251// JumpThreading - Thread control through mult-pred/multi-succ blocks where some 252// preds always go to some succ. Thresholds other than minus one override the 253// internal BB duplication default threshold. 254// 255FunctionPass *createJumpThreadingPass(int Threshold = -1); 256 257//===----------------------------------------------------------------------===// 258// 259// CFGSimplification - Merge basic blocks, eliminate unreachable blocks, 260// simplify terminator instructions, convert switches to lookup tables, etc. 261// 262FunctionPass *createCFGSimplificationPass( 263 unsigned Threshold = 1, bool ForwardSwitchCond = false, 264 bool ConvertSwitch = false, bool KeepLoops = true, bool SinkCommon = false, 265 std::function<bool(const Function &)> Ftor = nullptr); 266 267//===----------------------------------------------------------------------===// 268// 269// FlattenCFG - flatten CFG, reduce number of conditional branches by using 270// parallel-and and parallel-or mode, etc... 271// 272FunctionPass *createFlattenCFGPass(); 273 274//===----------------------------------------------------------------------===// 275// 276// CFG Structurization - Remove irreducible control flow 277// 278/// 279/// When \p SkipUniformRegions is true the structizer will not structurize 280/// regions that only contain uniform branches. 281Pass *createStructurizeCFGPass(bool SkipUniformRegions = false); 282 283//===----------------------------------------------------------------------===// 284// 285// TailCallElimination - This pass eliminates call instructions to the current 286// function which occur immediately before return instructions. 287// 288FunctionPass *createTailCallEliminationPass(); 289 290//===----------------------------------------------------------------------===// 291// 292// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator 293// tree. 294// 295FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false); 296 297//===----------------------------------------------------------------------===// 298// 299// GVNHoist - This pass performs a simple and fast GVN pass over the dominator 300// tree to hoist common expressions from sibling branches. 301// 302FunctionPass *createGVNHoistPass(); 303 304//===----------------------------------------------------------------------===// 305// 306// GVNSink - This pass uses an "inverted" value numbering to decide the 307// similarity of expressions and sinks similar expressions into successors. 308// 309FunctionPass *createGVNSinkPass(); 310 311//===----------------------------------------------------------------------===// 312// 313// MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads 314// are hoisted into the header, while stores sink into the footer. 315// 316FunctionPass *createMergedLoadStoreMotionPass(bool SplitFooterBB = false); 317 318//===----------------------------------------------------------------------===// 319// 320// GVN - This pass performs global value numbering and redundant load 321// elimination cotemporaneously. 322// 323FunctionPass *createNewGVNPass(); 324 325//===----------------------------------------------------------------------===// 326// 327// DivRemPairs - Hoist/decompose integer division and remainder instructions. 328// 329FunctionPass *createDivRemPairsPass(); 330 331//===----------------------------------------------------------------------===// 332// 333// MemCpyOpt - This pass performs optimizations related to eliminating memcpy 334// calls and/or combining multiple stores into memset's. 335// 336FunctionPass *createMemCpyOptPass(); 337 338//===----------------------------------------------------------------------===// 339// 340// LoopDeletion - This pass performs DCE of non-infinite loops that it 341// can prove are dead. 342// 343Pass *createLoopDeletionPass(); 344 345//===----------------------------------------------------------------------===// 346// 347// ConstantHoisting - This pass prepares a function for expensive constants. 348// 349FunctionPass *createConstantHoistingPass(); 350 351//===----------------------------------------------------------------------===// 352// 353// Sink - Code Sinking 354// 355FunctionPass *createSinkingPass(); 356 357//===----------------------------------------------------------------------===// 358// 359// LowerAtomic - Lower atomic intrinsics to non-atomic form 360// 361Pass *createLowerAtomicPass(); 362 363//===----------------------------------------------------------------------===// 364// 365// LowerGuardIntrinsic - Lower guard intrinsics to normal control flow. 366// 367Pass *createLowerGuardIntrinsicPass(); 368 369//===----------------------------------------------------------------------===// 370// 371// LowerMatrixIntrinsics - Lower matrix intrinsics to vector operations. 372// 373Pass *createLowerMatrixIntrinsicsPass(); 374 375//===----------------------------------------------------------------------===// 376// 377// LowerWidenableCondition - Lower widenable condition to i1 true. 378// 379Pass *createLowerWidenableConditionPass(); 380 381//===----------------------------------------------------------------------===// 382// 383// MergeICmps - Merge integer comparison chains into a memcmp 384// 385Pass *createMergeICmpsLegacyPass(); 386 387//===----------------------------------------------------------------------===// 388// 389// ValuePropagation - Propagate CFG-derived value information 390// 391Pass *createCorrelatedValuePropagationPass(); 392 393//===----------------------------------------------------------------------===// 394// 395// InferAddressSpaces - Modify users of addrspacecast instructions with values 396// in the source address space if using the destination address space is slower 397// on the target. If AddressSpace is left to its default value, it will be 398// obtained from the TargetTransformInfo. 399// 400FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u); 401extern char &InferAddressSpacesID; 402 403//===----------------------------------------------------------------------===// 404// 405// LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates 406// "block_weights" metadata. 407FunctionPass *createLowerExpectIntrinsicPass(); 408 409//===----------------------------------------------------------------------===// 410// 411// LowerConstantIntrinsicss - Expand any remaining llvm.objectsize and 412// llvm.is.constant intrinsic calls, even for the unknown cases. 413// 414FunctionPass *createLowerConstantIntrinsicsPass(); 415 416//===----------------------------------------------------------------------===// 417// 418// PartiallyInlineLibCalls - Tries to inline the fast path of library 419// calls such as sqrt. 420// 421FunctionPass *createPartiallyInlineLibCallsPass(); 422 423//===----------------------------------------------------------------------===// 424// 425// SeparateConstOffsetFromGEP - Split GEPs for better CSE 426// 427FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false); 428 429//===----------------------------------------------------------------------===// 430// 431// SpeculativeExecution - Aggressively hoist instructions to enable 432// speculative execution on targets where branches are expensive. 433// 434FunctionPass *createSpeculativeExecutionPass(); 435 436// Same as createSpeculativeExecutionPass, but does nothing unless 437// TargetTransformInfo::hasBranchDivergence() is true. 438FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass(); 439 440//===----------------------------------------------------------------------===// 441// 442// StraightLineStrengthReduce - This pass strength-reduces some certain 443// instruction patterns in straight-line code. 444// 445FunctionPass *createStraightLineStrengthReducePass(); 446 447//===----------------------------------------------------------------------===// 448// 449// PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any 450// safepoint polls (method entry, backedge) that might be required. This pass 451// does not generate explicit relocation sequences - that's handled by 452// RewriteStatepointsForGC which can be run at an arbitrary point in the pass 453// order following this pass. 454// 455FunctionPass *createPlaceSafepointsPass(); 456 457//===----------------------------------------------------------------------===// 458// 459// RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have 460// explicit relocations to include explicit relocations. 461// 462ModulePass *createRewriteStatepointsForGCLegacyPass(); 463 464//===----------------------------------------------------------------------===// 465// 466// Float2Int - Demote floats to ints where possible. 467// 468FunctionPass *createFloat2IntPass(); 469 470//===----------------------------------------------------------------------===// 471// 472// NaryReassociate - Simplify n-ary operations by reassociation. 473// 474FunctionPass *createNaryReassociatePass(); 475 476//===----------------------------------------------------------------------===// 477// 478// LoopDistribute - Distribute loops. 479// 480FunctionPass *createLoopDistributePass(); 481 482//===----------------------------------------------------------------------===// 483// 484// LoopFuse - Fuse loops. 485// 486FunctionPass *createLoopFusePass(); 487 488//===----------------------------------------------------------------------===// 489// 490// LoopLoadElimination - Perform loop-aware load elimination. 491// 492FunctionPass *createLoopLoadEliminationPass(); 493 494//===----------------------------------------------------------------------===// 495// 496// LoopVersioning - Perform loop multi-versioning. 497// 498FunctionPass *createLoopVersioningPass(); 499 500//===----------------------------------------------------------------------===// 501// 502// LoopDataPrefetch - Perform data prefetching in loops. 503// 504FunctionPass *createLoopDataPrefetchPass(); 505 506///===---------------------------------------------------------------------===// 507ModulePass *createNameAnonGlobalPass(); 508ModulePass *createCanonicalizeAliasesPass(); 509 510//===----------------------------------------------------------------------===// 511// 512// LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not 513// used. 514// 515FunctionPass *createLibCallsShrinkWrapPass(); 516 517//===----------------------------------------------------------------------===// 518// 519// LoopSimplifyCFG - This pass performs basic CFG simplification on loops, 520// primarily to help other loop passes. 521// 522Pass *createLoopSimplifyCFGPass(); 523 524//===----------------------------------------------------------------------===// 525// 526// WarnMissedTransformations - This pass emits warnings for leftover forced 527// transformations. 528// 529Pass *createWarnMissedTransformationsPass(); 530} // End llvm namespace 531 532#endif 533