[llvm-commits] [poolalloc] r129280 - in /poolalloc/trunk: lib/AssistDS/CMakeLists.txt lib/AssistDS/SimplifyExtractValue.cpp lib/AssistDS/SimplifyInsertValue.cpp lib/AssistDS/SimplifyMRV.cpp test/TEST.types.Makefile test/TEST.types.report
Arushi Aggarwal
aggarwa4 at illinois.edu
Mon Apr 11 09:20:58 PDT 2011
Author: aggarwa4
Date: Mon Apr 11 11:20:58 2011
New Revision: 129280
URL: http://llvm.org/viewvc/llvm-project?rev=129280&view=rev
Log:
Merge all the extract value simplifications, into a
single file.
Removed:
poolalloc/trunk/lib/AssistDS/SimplifyMRV.cpp
Modified:
poolalloc/trunk/lib/AssistDS/CMakeLists.txt
poolalloc/trunk/lib/AssistDS/SimplifyExtractValue.cpp
poolalloc/trunk/lib/AssistDS/SimplifyInsertValue.cpp
poolalloc/trunk/test/TEST.types.Makefile
poolalloc/trunk/test/TEST.types.report
Modified: poolalloc/trunk/lib/AssistDS/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/CMakeLists.txt?rev=129280&r1=129279&r2=129280&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/CMakeLists.txt (original)
+++ poolalloc/trunk/lib/AssistDS/CMakeLists.txt Mon Apr 11 11:20:58 2011
@@ -8,7 +8,8 @@
MergeArrayIndexGEP.cpp
SVADevirt.cpp
SimplifyGEP.cpp
- SimplifyMRV.cpp
+ SimplifyEV.cpp
+ SimplifyIV.cpp
TestGEP.cpp
TypeAnalysis.cpp
VarArgsFunc.cpp
Modified: poolalloc/trunk/lib/AssistDS/SimplifyExtractValue.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/SimplifyExtractValue.cpp?rev=129280&r1=129279&r2=129280&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/SimplifyExtractValue.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/SimplifyExtractValue.cpp Mon Apr 11 11:20:58 2011
@@ -7,10 +7,12 @@
//
//===----------------------------------------------------------------------===//
//
-// Replace extract value by loads where possible
+// Simplify extractvalue
+//
+// Derived from InstCombine
//
//===----------------------------------------------------------------------===//
-#define DEBUG_TYPE "simplify-ev"
+#define DEBUG_TYPE "simplifyev"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
@@ -40,7 +42,7 @@
// Method: runOnModule()
//
// Description:
- // Entry point for this LLVM pass. Search for extractvalue instructions
+ // Entry point for this LLVM pass. Search for insert/extractvalue instructions
// that can be simplified.
//
// Inputs:
@@ -65,27 +67,176 @@
if(!EV)
continue;
Value *Agg = EV->getAggregateOperand();
- LoadInst *LI = dyn_cast<LoadInst>(Agg);
- if(!LI)
+ if (!EV->hasIndices()) {
+ EV->replaceAllUsesWith(Agg);
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ changed = true;
continue;
- // check that it is in same basic block
- SmallVector<Value*, 8> Indices;
- const Type *Int32Ty = Type::getInt32Ty(M.getContext());
- Indices.push_back(Constant::getNullValue(Int32Ty));
- for (ExtractValueInst::idx_iterator I = EV->idx_begin(), E = EV->idx_end();
- I != E; ++I) {
- Indices.push_back(ConstantInt::get(Int32Ty, *I));
}
+ if (Constant *C = dyn_cast<Constant>(Agg)) {
+ if (isa<UndefValue>(C)) {
+ EV->replaceAllUsesWith(UndefValue::get(EV->getType()));
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ changed = true;
+ continue;
+ }
+ if (isa<ConstantAggregateZero>(C)) {
+ EV->replaceAllUsesWith(Constant::getNullValue(EV->getType()));
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ changed = true;
+ continue;
+ }
+ if (isa<ConstantArray>(C) || isa<ConstantStruct>(C)) {
+ // Extract the element indexed by the first index out of the constant
+ Value *V = C->getOperand(*EV->idx_begin());
+ if (EV->getNumIndices() > 1) {
+ // Extract the remaining indices out of the constant indexed by the
+ // first index
+ ExtractValueInst *EV_new = ExtractValueInst::Create(V,
+ EV->idx_begin() + 1,
+ EV->idx_end(), "", EV);
+ EV->replaceAllUsesWith(EV_new);
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ changed = true;
+ continue;
+ } else {
+ EV->replaceAllUsesWith(V);
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ changed = true;
+ continue;
+ }
+ }
+ continue;
+ }
+ if (LoadInst * LI = dyn_cast<LoadInst>(Agg)) {
+ SmallVector<Value*, 8> Indices;
+ const Type *Int32Ty = Type::getInt32Ty(M.getContext());
+ Indices.push_back(Constant::getNullValue(Int32Ty));
+ for (ExtractValueInst::idx_iterator I = EV->idx_begin(), E = EV->idx_end();
+ I != E; ++I) {
+ Indices.push_back(ConstantInt::get(Int32Ty, *I));
+ }
+
+ GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(LI->getOperand(0), Indices.begin(),
+ Indices.end(), LI->getName(), LI) ;
+ LoadInst *LINew = new LoadInst(GEP, "", LI);
+ EV->replaceAllUsesWith(LINew);
+ EV->eraseFromParent();
+ changed = true;
+ numErased++;
+ continue;
- GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(LI->getOperand(0), Indices.begin(),
- Indices.end(), LI->getName(), LI) ;
- LoadInst *LINew = new LoadInst(GEP, "", LI);
- EV->replaceAllUsesWith(LINew);
- EV->eraseFromParent();
- changed = true;
- numErased++;
-
-
+ }
+ if (InsertValueInst *IV = dyn_cast<InsertValueInst>(Agg)) {
+ bool done = false;
+ // We're extracting from an insertvalue instruction, compare the indices
+ const unsigned *exti, *exte, *insi, *inse;
+ for (exti = EV->idx_begin(), insi = IV->idx_begin(),
+ exte = EV->idx_end(), inse = IV->idx_end();
+ exti != exte && insi != inse;
+ ++exti, ++insi) {
+ if (*insi != *exti) {
+ // The insert and extract both reference distinctly different elements.
+ // This means the extract is not influenced by the insert, and we can
+ // replace the aggregate operand of the extract with the aggregate
+ // operand of the insert. i.e., replace
+ // %I = insertvalue { i32, { i32 } } %A, { i32 } { i32 42 }, 1
+ // %E = extractvalue { i32, { i32 } } %I, 0
+ // with
+ // %E = extractvalue { i32, { i32 } } %A, 0
+ ExtractValueInst *EV_new = ExtractValueInst::Create(IV->getAggregateOperand(),
+ EV->idx_begin(), EV->idx_end(),"", EV);
+ EV->replaceAllUsesWith(EV_new);
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ done = true;
+ changed = true;
+ break;
+ }
+ }
+ if(done)
+ continue;
+ if (exti == exte && insi == inse) {
+ // Both iterators are at the end: Index lists are identical. Replace
+ // %B = insertvalue { i32, { i32 } } %A, i32 42, 1, 0
+ // %C = extractvalue { i32, { i32 } } %B, 1, 0
+ // with "i32 42"
+ EV->replaceAllUsesWith(IV->getInsertedValueOperand());
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ changed = true;
+ continue;
+
+ }
+ if (exti == exte) {
+ // The extract list is a prefix of the insert list. i.e. replace
+ // %I = insertvalue { i32, { i32 } } %A, i32 42, 1, 0
+ // %E = extractvalue { i32, { i32 } } %I, 1
+ // with
+ // %X = extractvalue { i32, { i32 } } %A, 1
+ // %E = insertvalue { i32 } %X, i32 42, 0
+ // by switching the order of the insert and extract (though the
+ // insertvalue should be left in, since it may have other uses).
+ Value *NewEV = ExtractValueInst::Create(IV->getAggregateOperand(),
+ EV->idx_begin(), EV->idx_end(), "", EV);
+ Value *NewIV = InsertValueInst::Create(NewEV, IV->getInsertedValueOperand(),
+ insi, inse, "", EV);
+ EV->replaceAllUsesWith(NewIV);
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ changed = true;
+ continue;
+ }
+ if (insi == inse) {
+ // The insert list is a prefix of the extract list
+ // We can simply remove the common indices from the extract and make it
+ // operate on the inserted value instead of the insertvalue result.
+ // i.e., replace
+ // %I = insertvalue { i32, { i32 } } %A, { i32 } { i32 42 }, 1
+ // %E = extractvalue { i32, { i32 } } %I, 1, 0
+ // with
+ // %E extractvalue { i32 } { i32 42 }, 0
+ ExtractValueInst *EV_new = ExtractValueInst::Create(IV->getInsertedValueOperand(),
+ exti, exte,"", EV);
+ EV->replaceAllUsesWith(EV_new);
+ DEBUG(errs() << "EV:");
+ DEBUG(errs() << "ERASE:");
+ DEBUG(EV->dump());
+ EV->eraseFromParent();
+ numErased++;
+ changed = true;
+ continue;
+ }
+ }
}
}
}
@@ -100,4 +251,4 @@
// Register the pass
static RegisterPass<SimplifyEV>
-X("simplify-ev", "Simplify extract value");
+X("simplify-ev", "Simplify extract/insert value insts");
Modified: poolalloc/trunk/lib/AssistDS/SimplifyInsertValue.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/SimplifyInsertValue.cpp?rev=129280&r1=129279&r2=129280&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/SimplifyInsertValue.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/SimplifyInsertValue.cpp Mon Apr 11 11:20:58 2011
@@ -7,7 +7,8 @@
//
//===----------------------------------------------------------------------===//
//
-// Replace insert value by storess where possible
+// Simplify insertvalue
+// Replace insertvalue by storess where possible
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "simplify-iv"
Removed: poolalloc/trunk/lib/AssistDS/SimplifyMRV.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/SimplifyMRV.cpp?rev=129279&view=auto
==============================================================================
--- poolalloc/trunk/lib/AssistDS/SimplifyMRV.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/SimplifyMRV.cpp (removed)
@@ -1,237 +0,0 @@
-//===-- SimplifyMRV.cpp - Remove extraneous insert/extractvalue insts------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Remove unnecessary insertvalue/extractvalue pairs
-// The name of the pass indicates that such pairs are mostly seen when
-// mrv(s) occur.
-//
-// Derived from InstCombine
-//
-//===----------------------------------------------------------------------===//
-#define DEBUG_TYPE "simplifymrv"
-
-#include "llvm/Instructions.h"
-#include "llvm/Module.h"
-#include "llvm/Pass.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");
-
-namespace {
- class SimplifyMRV : public ModulePass {
- public:
- static char ID;
- SimplifyMRV() : ModulePass(&ID) {}
- //
- // 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 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;) {
- ExtractValueInst *EV = dyn_cast<ExtractValueInst>(I++);
- if(!EV)
- continue;
- Value *Agg = EV->getAggregateOperand();
- if (!EV->hasIndices()) {
- EV->replaceAllUsesWith(Agg);
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- changed = true;
- continue;
- }
- if (Constant *C = dyn_cast<Constant>(Agg)) {
- if (isa<UndefValue>(C)) {
- EV->replaceAllUsesWith(UndefValue::get(EV->getType()));
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- changed = true;
- continue;
- }
- if (isa<ConstantAggregateZero>(C)) {
- EV->replaceAllUsesWith(Constant::getNullValue(EV->getType()));
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- changed = true;
- continue;
- }
- if (isa<ConstantArray>(C) || isa<ConstantStruct>(C)) {
- // Extract the element indexed by the first index out of the constant
- Value *V = C->getOperand(*EV->idx_begin());
- if (EV->getNumIndices() > 1) {
- // Extract the remaining indices out of the constant indexed by the
- // first index
- ExtractValueInst *EV_new = ExtractValueInst::Create(V,
- EV->idx_begin() + 1,
- EV->idx_end(), "", EV);
- EV->replaceAllUsesWith(EV_new);
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- changed = true;
- continue;
- } else {
- EV->replaceAllUsesWith(V);
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- changed = true;
- continue;
- }
- }
- continue;
- }
- if (InsertValueInst *IV = dyn_cast<InsertValueInst>(Agg)) {
- bool done = false;
- // We're extracting from an insertvalue instruction, compare the indices
- const unsigned *exti, *exte, *insi, *inse;
- for (exti = EV->idx_begin(), insi = IV->idx_begin(),
- exte = EV->idx_end(), inse = IV->idx_end();
- exti != exte && insi != inse;
- ++exti, ++insi) {
- if (*insi != *exti) {
- // The insert and extract both reference distinctly different elements.
- // This means the extract is not influenced by the insert, and we can
- // replace the aggregate operand of the extract with the aggregate
- // operand of the insert. i.e., replace
- // %I = insertvalue { i32, { i32 } } %A, { i32 } { i32 42 }, 1
- // %E = extractvalue { i32, { i32 } } %I, 0
- // with
- // %E = extractvalue { i32, { i32 } } %A, 0
- ExtractValueInst *EV_new = ExtractValueInst::Create(IV->getAggregateOperand(),
- EV->idx_begin(), EV->idx_end(),"", EV);
- EV->replaceAllUsesWith(EV_new);
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- done = true;
- changed = true;
- break;
- }
- }
- if(done)
- continue;
- if (exti == exte && insi == inse) {
- // Both iterators are at the end: Index lists are identical. Replace
- // %B = insertvalue { i32, { i32 } } %A, i32 42, 1, 0
- // %C = extractvalue { i32, { i32 } } %B, 1, 0
- // with "i32 42"
- EV->replaceAllUsesWith(IV->getInsertedValueOperand());
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- changed = true;
- continue;
-
- }
- if (exti == exte) {
- // The extract list is a prefix of the insert list. i.e. replace
- // %I = insertvalue { i32, { i32 } } %A, i32 42, 1, 0
- // %E = extractvalue { i32, { i32 } } %I, 1
- // with
- // %X = extractvalue { i32, { i32 } } %A, 1
- // %E = insertvalue { i32 } %X, i32 42, 0
- // by switching the order of the insert and extract (though the
- // insertvalue should be left in, since it may have other uses).
- Value *NewEV = ExtractValueInst::Create(IV->getAggregateOperand(),
- EV->idx_begin(), EV->idx_end(), "", EV);
- Value *NewIV = InsertValueInst::Create(NewEV, IV->getInsertedValueOperand(),
- insi, inse, "", EV);
- EV->replaceAllUsesWith(NewIV);
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- changed = true;
- continue;
- }
- if (insi == inse) {
- // The insert list is a prefix of the extract list
- // We can simply remove the common indices from the extract and make it
- // operate on the inserted value instead of the insertvalue result.
- // i.e., replace
- // %I = insertvalue { i32, { i32 } } %A, { i32 } { i32 42 }, 1
- // %E = extractvalue { i32, { i32 } } %I, 1, 0
- // with
- // %E extractvalue { i32 } { i32 42 }, 0
- ExtractValueInst *EV_new = ExtractValueInst::Create(IV->getInsertedValueOperand(),
- exti, exte,"", EV);
- EV->replaceAllUsesWith(EV_new);
- DEBUG(errs() << "MRV:");
- DEBUG(errs() << "ERASE:");
- DEBUG(EV->dump());
- EV->eraseFromParent();
- numErased++;
- changed = true;
- continue;
- }
- }
- }
- }
- }
- } while(changed);
- return (numErased > 0);
- }
- };
-}
-
-// Pass ID variable
-char SimplifyMRV::ID = 0;
-
-// Register the pass
-static RegisterPass<SimplifyMRV>
-X("simplify-mrv", "Simplify extract/insert value insts");
Modified: poolalloc/trunk/test/TEST.types.Makefile
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/test/TEST.types.Makefile?rev=129280&r1=129279&r2=129280&view=diff
==============================================================================
--- poolalloc/trunk/test/TEST.types.Makefile (original)
+++ poolalloc/trunk/test/TEST.types.Makefile Mon Apr 11 11:20:58 2011
@@ -49,7 +49,7 @@
$(PROGRAMS_TO_TEST:%=Output/%.opt.bc): \
Output/%.opt.bc: Output/%.llvm1.bc $(LOPT) $(ASSIST_SO)
- -$(RUNOPT) -load $(ASSIST_SO) -disable-opt -info-output-file=$(CURDIR)/$@.info -instnamer -internalize -mem2reg -dce -simplify-mrv -basiccg -inline -dce -simplify-mrv -dce -varargsfunc -indclone -funcspec -ipsccp -deadargelim -simplify-gep -die -die -mergearrgep -die -globaldce -simplifycfg -deadargelim -arg-simplify -die -varargsfunc -die -simplifycfg -globaldce -indclone -funcspec -deadargelim -globaldce -die -simplifycfg -gep-args -deadargelim -die -mergefunc -die -die -mergearrgep -die -globaldce -int2ptrcmp -die -dce -simplify-mrv -dce -inline -mem2reg -dce -arg-cast -dce -type-analysis -stats -time-passes $< -f -o $@
+ -$(RUNOPT) -load $(ASSIST_SO) -disable-opt -info-output-file=$(CURDIR)/$@.info -instnamer -internalize -mem2reg -dce -basiccg -inline -dce -dce -varargsfunc -indclone -funcspec -ipsccp -deadargelim -simplify-gep -die -die -mergearrgep -die -globaldce -simplifycfg -deadargelim -arg-simplify -die -varargsfunc -die -simplifycfg -globaldce -indclone -funcspec -deadargelim -globaldce -die -simplifycfg -gep-args -deadargelim -die -mergefunc -die -die -mergearrgep -die -globaldce -int2ptrcmp -die -dce -dce -inline -mem2reg -dce -arg-cast -dce -stats -time-passes -struct-arg -simplify-ev -simplify-iv -dce $< -f -o $@
$(PROGRAMS_TO_TEST:%=Output/%.temp2.bc): \
Output/%.temp2.bc: Output/%.temp1.bc $(LOPT) $(ASSIST_SO)
@@ -214,7 +214,7 @@
@/bin/echo -n "ARG_SMPL: " >> $@
- at grep 'Number of Args changeable' $<.info >> $@
@echo >> $@
- @/bin/echo -n "MRV: " >> $@
+ @/bin/echo -n "EV: " >> $@
- at grep 'Number of Instructions Deleted' $<.info >> $@
@echo >> $@
@/bin/echo -n "ALLOC: " >> $@
Modified: poolalloc/trunk/test/TEST.types.report
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/test/TEST.types.report?rev=129280&r1=129279&r2=129280&view=diff
==============================================================================
--- poolalloc/trunk/test/TEST.types.report (original)
+++ poolalloc/trunk/test/TEST.types.report Mon Apr 11 11:20:58 2011
@@ -169,7 +169,7 @@
["StdLibFold", "STD_LIB_FOLD: *([0-9]+)"],
["I2PB", "I2PB: *([0-9]+)"],
["I2PS", "I2PS: *([0-9]+)"],
- ["MRV", "MRV: *([0-9]+)"],
+ ["EV", "EV: *([0-9]+)"],
["AL", "ALLOC: *([0-9]+)"],
["DE", "DEALLOC: *([0-9]+)"],
["CAST", "CAST: *([0-9]+)"],
More information about the llvm-commits
mailing list