[llvm-commits] [poolalloc] r132859 - in /poolalloc/trunk: include/assistDS/FuncSimplify.h lib/AssistDS/FuncSimplify.cpp

Arushi Aggarwal aggarwa4 at illinois.edu
Fri Jun 10 14:25:12 PDT 2011


Author: aggarwa4
Date: Fri Jun 10 16:25:12 2011
New Revision: 132859

URL: http://llvm.org/viewvc/llvm-project?rev=132859&view=rev
Log:
Replace all uses of aliases with the aliasee values.

Added:
    poolalloc/trunk/include/assistDS/FuncSimplify.h
    poolalloc/trunk/lib/AssistDS/FuncSimplify.cpp

Added: poolalloc/trunk/include/assistDS/FuncSimplify.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/assistDS/FuncSimplify.h?rev=132859&view=auto
==============================================================================
--- poolalloc/trunk/include/assistDS/FuncSimplify.h (added)
+++ poolalloc/trunk/include/assistDS/FuncSimplify.h Fri Jun 10 16:25:12 2011
@@ -0,0 +1,30 @@
+//===-------- ArgCast.cpp - Cast Arguments to Calls -----------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Instructions.h"
+#include "llvm/Module.h"
+#include "llvm/Pass.h"
+
+namespace llvm {
+  //
+  // Class: FuncSimplify
+  //
+  // Description:
+  //  Replace all internal aliases with the
+  //  aliasee value
+  //
+  class FuncSimplify : public ModulePass {
+  public:
+    static char ID;
+    FuncSimplify() : ModulePass(&ID) {}
+    virtual bool runOnModule(Module& M);
+  };
+}
+

Added: poolalloc/trunk/lib/AssistDS/FuncSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/FuncSimplify.cpp?rev=132859&view=auto
==============================================================================
--- poolalloc/trunk/lib/AssistDS/FuncSimplify.cpp (added)
+++ poolalloc/trunk/lib/AssistDS/FuncSimplify.cpp Fri Jun 10 16:25:12 2011
@@ -0,0 +1,72 @@
+//===-------- FuncSimplify.cpp - Replace Global Aliases -------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "func-simplify"
+
+#include "assistDS/FuncSimplify.h"
+#include "llvm/Attributes.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Debug.h"
+
+#include <set>
+#include <map>
+#include <vector>
+
+using namespace llvm;
+
+// Pass statistics
+STATISTIC(numChanged,   "Number of aliases deleted");
+
+//
+// Method: runOnModule()
+//
+// Description:
+//  Entry point for this LLVM pass.
+//  Replace all internal aliases with the
+//  aliasee value
+//
+// Inputs:
+//  M - A reference to the LLVM module to transform
+//
+// Outputs:
+//  M - The transformed LLVM module.
+//
+// Return value:
+//  true  - The module was modified.
+//  false - The module was not modified.
+//
+bool FuncSimplify::runOnModule(Module& M) {
+
+  std::vector<GlobalAlias*> toDelete;
+  for (Module::alias_iterator I = M.alias_begin(); I != M.alias_end(); ++I) {
+    if(!I->hasInternalLinkage())
+      continue;
+    I->replaceAllUsesWith(I->getAliasee());
+    toDelete.push_back(I);
+  }
+  numChanged += toDelete.size();
+
+  while(!toDelete.empty()) {
+    GlobalAlias *I = toDelete.back();
+    toDelete.pop_back();
+    I->eraseFromParent();
+  }
+
+
+  return true;
+}
+
+// Pass ID variable
+char FuncSimplify::ID = 0;
+
+// Register the pass
+static RegisterPass<FuncSimplify>
+X("func-simplify", "Delete Aliases");





More information about the llvm-commits mailing list