aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Optimizations/LevelChange.h
blob: 745b893d84a14c02d5f059b8648df9ccf5ec9cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//===-- LevelChange.h - Functions for raising/lowering methods ---*- C++ -*--=//
//
// This family of functions is useful for changing the 'level' of a method.  
// This can either be raising (converting direct addressing to use getelementptr
// for structs and arrays), or lowering (for instruction selection).
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_OPT_LEVELCHANGE_H
#define LLVM_OPT_LEVELCHANGE_H

#include "llvm/Module.h"
#include "llvm/Method.h"

namespace opt {
  struct Level {      // Define a namespace to contain the enum
    enum ID {    // Define an enum of levels to change into
      Lowest,           // The lowest level: ...
      //...

      Normal,           // The level LLVM is assumed to be in

      Simplified,       // Elminate silly things like unnecesary casts

      StructureAccess,  // Convert pointer addressing to structure getelementptr
                        // instructions.

      ArrayAccess,      // Simple direct access through pointers is converted to
                        // array accessors

      InductionVars,    // Auxillary induction variables are eliminated by
                        // introducing a cannonical indvar, and making all
                        // others use it.  This creates more opportunites to
                        // apply the previous optimizations.

      Highest = InductionVars,
    };
  };

  // DoRaiseRepresentation - Raise a method representation to a higher level.
  // The specific features to add are specified with the ToLevel argument.
  //
  bool DoRaiseRepresentation(Method *M, Level::ID ToLevel);
  bool DoRaiseRepresentation(Module *M, Level::ID ToLevel);
  static inline bool DoRaiseRepresentation(Method *M) {
    return DoRaiseRepresentation(M, Level::Highest);
  }
  bool DoRaiseRepresentation(Module *M, Level::ID ToLevel);
  static inline bool DoRaiseRepresentation(Module *M) {
    return DoRaiseRepresentation(M, Level::Highest);
  }

  // DoEliminateAuxillaryInductionVariables - Eliminate all aux indvars.  This
  // is one of the transformations performed by DoRaiseRepresentation, that
  // converts all induction variables to reference a cannonical induction
  // variable (which starts at 0 and counts by 1).
  //
  bool DoEliminateAuxillaryInductionVariables(Method *M);
  static inline bool DoEliminateAuxillaryInductionVariables(Module *M) {
    return M->reduceApply(DoEliminateAuxillaryInductionVariables);
  }


  // DoLowerRepresentation - Lower a method representation to a lower level.
  // The specific features to eliminate are specified with the ToLevel argument.
  //
  bool DoLowerRepresentation(Method *M, Level::ID ToLevel);
  bool DoLowerRepresentation(Module *M, Level::ID ToLevel);
  static inline bool DoLowerRepresentation(Module *M) {
    return DoLowerRepresentation(M, Level::Lowest);
  }
  static inline bool DoLowerRepresentation(Method *M) {
    return DoLowerRepresentation(M, Level::Lowest);
  }
}  // End namespace opt

#endif