llvm.org GIT mirror llvm / 399376b
Initial Checkin git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@896 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 18 years ago
1 changed file(s) with 58 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===- llvm/Transforms/ConstantMerge.h - Merge duplicate consts --*- C++ -*--=//
1 //
2 // This file defines the interface to a pass that merges duplicate global
3 // constants together into a single constant that is shared. This is useful
4 // because some passes (ie TraceValues) insert a lot of string constants into
5 // the program, regardless of whether or not they duplicate an existing string.
6 //
7 // Algorithm: ConstantMerge is designed to build up a map of available constants
8 // and elminate duplicates when it is initialized.
9 //
10 // The DynamicConstantMerge method is a superset of the ConstantMerge algorithm
11 // that checks for each method to see if constants have been added to the
12 // constant pool since it was last run... if so, it processes them.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TRANSFORMS_CONSTANTMERGE_H
17 #define LLVM_TRANSFORMS_CONSTANTMERGE_H
18
19 #include "llvm/Transforms/Pass.h"
20 #include
21 class ConstPoolVal;
22 class GlobalVariable;
23
24 class ConstantMerge : public Pass {
25 protected:
26 map Constants;
27 unsigned LastConstantSeen;
28 public:
29 inline ConstantMerge() : LastConstantSeen(0) {}
30
31 // mergeDuplicateConstants - Static accessor for clients that don't want to
32 // deal with passes.
33 //
34 static bool mergeDuplicateConstants(Module *M);
35
36 // doPassInitialization - For this pass, process all of the globals in the
37 // module, eliminating duplicate constants.
38 //
39 bool doPassInitialization(Module *M);
40
41 // doPassFinalization - Clean up internal state for this module
42 //
43 bool doPassFinalization(Module *M) {
44 LastConstantSeen = 0;
45 Constants.clear();
46 return false;
47 }
48 };
49
50 struct DynamicConstantMerge : public ConstantMerge {
51 // doPerMethodWork - Check to see if any globals have been added to the
52 // global list for the module. If so, eliminate them.
53 //
54 bool doPerMethodWork(Method *M);
55 };
56
57 #endif