From eaf039a94b6a84035735109165f9e262e36f054b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 18 Oct 2001 20:05:30 +0000 Subject: [PATCH] Initial Checkin llvm-svn: 896 --- .../llvm/Transforms/IPO/ConstantMerge.h | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 llvm/include/llvm/Transforms/IPO/ConstantMerge.h diff --git a/llvm/include/llvm/Transforms/IPO/ConstantMerge.h b/llvm/include/llvm/Transforms/IPO/ConstantMerge.h new file mode 100644 index 000000000000..e98e375f084e --- /dev/null +++ b/llvm/include/llvm/Transforms/IPO/ConstantMerge.h @@ -0,0 +1,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/Transforms/Pass.h" +#include +class ConstPoolVal; +class GlobalVariable; + +class ConstantMerge : public Pass { +protected: + map 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