1 //===- llvm/Transforms/ConstantMerge.h - Merge duplicate consts --*- C++ -*--=//
3 // This file defines the interface to a pass that merges duplicate global
4 // constants together into a single constant that is shared. This is useful
5 // because some passes (ie TraceValues) insert a lot of string constants into
6 // the program, regardless of whether or not they duplicate an existing string.
8 // Algorithm: ConstantMerge is designed to build up a map of available constants
9 // and elminate duplicates when it is initialized.
11 // The DynamicConstantMerge method is a superset of the ConstantMerge algorithm
12 // that checks for each method to see if constants have been added to the
13 // constant pool since it was last run... if so, it processes them.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TRANSFORMS_CONSTANTMERGE_H
18 #define LLVM_TRANSFORMS_CONSTANTMERGE_H
20 #include "llvm/Pass.h"
24 // FIXME: ConstantMerge should not be a methodPass!!!
25 class ConstantMerge : public MethodPass {
27 std::map<Constant*, GlobalVariable*> Constants;
28 unsigned LastConstantSeen;
30 inline ConstantMerge() : LastConstantSeen(0) {}
32 // mergeDuplicateConstants - Static accessor for clients that don't want to
35 static bool mergeDuplicateConstants(Module *M);
37 // doInitialization - For this pass, process all of the globals in the
38 // module, eliminating duplicate constants.
40 bool doInitialization(Module *M);
42 bool runOnMethod(Method*) { return false; }
44 // doFinalization - Clean up internal state for this module
46 bool doFinalization(Module *M) {
53 struct DynamicConstantMerge : public ConstantMerge {
54 // doPerMethodWork - Check to see if any globals have been added to the
55 // global list for the module. If so, eliminate them.
57 bool runOnMethod(Method *M);