#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
-#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
-#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
/// Collect every variables marked as "used"
void collectUsedGlobalVariables(Module &M);
- /// Keep track of the GlobalVariable that are marked as "used"
+ /// Keep track of the GlobalVariable that must not be merged away
SmallPtrSet<const GlobalVariable *, 16> MustKeepGlobalVariables;
public:
virtual bool doInitialization(Module &M);
virtual bool runOnFunction(Function &F);
+ virtual bool doFinalization(Module &M);
const char *getPassName() const {
return "Merge internal globals";
}
void GlobalMerge::setMustKeepGlobalVariables(Module &M) {
- // If we already processed a Module, UsedGlobalVariables may have been
- // populated. Reset the information for this module.
- MustKeepGlobalVariables.clear();
collectUsedGlobalVariables(M);
for (Module::iterator IFn = M.begin(), IEndFn = M.end(); IFn != IEndFn;
continue;
// Ignore all "required" globals:
- // - the ones used for EH
- // - the ones marked with "used" attribute
if (isMustKeepGlobalVariable(I))
continue;
return false;
}
+bool GlobalMerge::doFinalization(Module &M) {
+ MustKeepGlobalVariables.clear();
+ return false;
+}
+
Pass *llvm::createGlobalMergePass(const TargetLowering *tli) {
return new GlobalMerge(tli);
}