• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- LICM.h - Loop Invariant Code Motion Pass -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass performs loop invariant code motion, attempting to remove as much
11 // code from the body of a loop as possible.  It does this by either hoisting
12 // code into the preheader block, or by sinking code to the exit blocks if it is
13 // safe.  This pass also promotes must-aliased memory locations in the loop to
14 // live in registers, thus hoisting and sinking "invariant" loads and stores.
15 //
16 // This pass uses alias analysis for two purposes:
17 //
18 //  1. Moving loop invariant loads and calls out of loops.  If we can determine
19 //     that a load or call inside of a loop never aliases anything stored to,
20 //     we can hoist it or sink it like any other instruction.
21 //  2. Scalar Promotion of Memory - If there is a store instruction inside of
22 //     the loop, we try to move the store to happen AFTER the loop instead of
23 //     inside of the loop.  This can only happen if a few conditions are true:
24 //       A. The pointer stored through is loop invariant
25 //       B. There are no stores or loads in the loop which _may_ alias the
26 //          pointer.  There are no calls in the loop which mod/ref the pointer.
27 //     If these conditions are true, we can promote the loads and stores in the
28 //     loop of the pointer to use a temporary alloca'd variable.  We then use
29 //     the SSAUpdater to construct the appropriate SSA form for the value.
30 //
31 //===----------------------------------------------------------------------===//
32 
33 #ifndef LLVM_TRANSFORMS_SCALAR_LICM_H
34 #define LLVM_TRANSFORMS_SCALAR_LICM_H
35 
36 #include "llvm/Analysis/LoopInfo.h"
37 #include "llvm/IR/PassManager.h"
38 
39 namespace llvm {
40 
41 /// Performs Loop Invariant Code Motion Pass.
42 class LICMPass : public PassInfoMixin<LICMPass> {
43 public:
44   PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM);
45 };
46 } // end namespace llvm
47 
48 #endif // LLVM_TRANSFORMS_SCALAR_LICM_H
49