[llvm-commits] [poolalloc] r132992 - in /poolalloc/trunk: include/assistDS/SimplifyLoad.h lib/AssistDS/SimplifyLoad.cpp
Arushi Aggarwal
aggarwa4 at illinois.edu
Tue Jun 14 07:44:26 PDT 2011
Author: aggarwa4
Date: Tue Jun 14 09:44:26 2011
New Revision: 132992
URL: http://llvm.org/viewvc/llvm-project?rev=132992&view=rev
Log:
Simplify some special cases.
Added:
poolalloc/trunk/include/assistDS/SimplifyLoad.h
poolalloc/trunk/lib/AssistDS/SimplifyLoad.cpp
Added: poolalloc/trunk/include/assistDS/SimplifyLoad.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/assistDS/SimplifyLoad.h?rev=132992&view=auto
==============================================================================
--- poolalloc/trunk/include/assistDS/SimplifyLoad.h (added)
+++ poolalloc/trunk/include/assistDS/SimplifyLoad.h Tue Jun 14 09:44:26 2011
@@ -0,0 +1,29 @@
+//===--------------- SimplifyLoad.cpp - Simplify load insts ---------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Derived from InstCombine
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Instructions.h"
+#include "llvm/Module.h"
+#include "llvm/Pass.h"
+
+namespace llvm {
+ //
+ // Class: SimplifyLoad
+ //
+ class SimplifyLoad : public ModulePass {
+ public:
+ static char ID;
+ SimplifyLoad() : ModulePass(&ID) {}
+ virtual bool runOnModule(Module& M);
+ };
+}
+
Added: poolalloc/trunk/lib/AssistDS/SimplifyLoad.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/SimplifyLoad.cpp?rev=132992&view=auto
==============================================================================
--- poolalloc/trunk/lib/AssistDS/SimplifyLoad.cpp (added)
+++ poolalloc/trunk/lib/AssistDS/SimplifyLoad.cpp Tue Jun 14 09:44:26 2011
@@ -0,0 +1,90 @@
+//===--------------- SimplifyLoad.cpp - Simplify load insts ---------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Derived from InstCombine
+//
+//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "simplifyload"
+
+#include "assistDS/SimplifyLoad.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/PatternMatch.h"
+#include "llvm/Target/TargetData.h"
+
+#include <set>
+#include <map>
+#include <vector>
+
+using namespace llvm;
+
+// Pass statistic
+STATISTIC(numErased, "Number of Instructions Deleted");
+
+//
+// Method: runOnModule()
+//
+// Description:
+// Entry point for this LLVM pass. Search for insert/extractvalue instructions
+// that can be simplified.
+//
+// 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 SimplifyLoad::runOnModule(Module& M) {
+ // Repeat till no change
+ bool changed;
+ do {
+ changed = false;
+ for (Module::iterator F = M.begin(); F != M.end(); ++F) {
+ for (Function::iterator B = F->begin(), FE = F->end(); B != FE; ++B) {
+ for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE;) {
+ LoadInst *LI = dyn_cast<LoadInst>(I++);
+ if(!LI)
+ continue;
+ if(LI->getNumUses() == 1) {
+ if(CastInst *CI = dyn_cast<CastInst>(LI->use_begin())) {
+ if(LI->getType()->isPointerTy()) {
+ if(ConstantExpr *CE = dyn_cast<ConstantExpr>(LI->getOperand(0))) {
+ if(const PointerType *PTy = dyn_cast<PointerType>(CE->getOperand(0)->getType()))
+ if(PTy->getElementType() == CI->getType()) {
+ LoadInst *LINew = new LoadInst(CE->getOperand(0), "", LI);
+ LINew->dump();
+ LI->dump();
+ CI->dump();
+ CE->dump();
+ CI->replaceAllUsesWith(LINew);
+ }
+ }
+ }
+ }
+ }
+
+
+ }
+ }
+ }
+ } while(changed);
+ return (numErased > 0);
+}
+
+// Pass ID variable
+char SimplifyLoad::ID = 0;
+
+// Register the pass
+static RegisterPass<SimplifyLoad>
+X("simplify-load", "Simplify load insts");
More information about the llvm-commits
mailing list