aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Transforms/IPO/ConstantMerge.h
blob: 4ebbfd3d93062b5ecdf84de52f85581981a73f3d (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
//===- llvm/Transforms/ConstantMerge.h - Merge duplicate consts --*- C++ -*--=//
//
// This file defines the interface to a pass that merges duplicate global
// constants together into a single constant that is shared.  This is useful
// because some passes (ie TraceValues) insert a lot of string constants into
// the program, regardless of whether or not they duplicate an existing string.
//
// Algorithm: ConstantMerge is designed to build up a map of available constants
// and elminate duplicates when it is initialized.
//
// The DynamicConstantMerge method is a superset of the ConstantMerge algorithm
// that checks for each method to see if constants have been added to the
// constant pool since it was last run... if so, it processes them.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TRANSFORMS_CONSTANTMERGE_H
#define LLVM_TRANSFORMS_CONSTANTMERGE_H

#include "llvm/Pass.h"
#include <map>
class ConstPoolVal;
class GlobalVariable;

class ConstantMerge : public Pass {
protected:
  map<ConstPoolVal*, GlobalVariable*> Constants;
  unsigned LastConstantSeen;
public:
  inline ConstantMerge() : LastConstantSeen(0) {}

  // mergeDuplicateConstants - Static accessor for clients that don't want to
  // deal with passes.
  //
  static bool mergeDuplicateConstants(Module *M);

  // doPassInitialization - For this pass, process all of the globals in the
  // module, eliminating duplicate constants.
  //
  bool doPassInitialization(Module *M);

  // doPassFinalization - Clean up internal state for this module
  //
  bool doPassFinalization(Module *M) {
    LastConstantSeen = 0;
    Constants.clear();
    return false;
  }
};

struct DynamicConstantMerge : public ConstantMerge {
  // doPerMethodWork - Check to see if any globals have been added to the 
  // global list for the module.  If so, eliminate them.
  //
  bool doPerMethodWork(Method *M);
};

#endif