diff options
author | Chris Lattner <sabre@nondot.org> | 2004-05-23 21:19:55 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-05-23 21:19:55 +0000 |
commit | 057f78ab4e07af936fc4ba13d82d920e02f06ba3 (patch) | |
tree | 796d32ac13d4c68cc44681819be4480069cb0f43 /lib/Transforms/Scalar/GCSE.cpp | |
parent | 08005dfdc967a916375da83515b25dd131750bc6 (diff) |
Add support for replacement of formal arguments with simpler expressions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13689 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/GCSE.cpp')
-rw-r--r-- | lib/Transforms/Scalar/GCSE.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/GCSE.cpp b/lib/Transforms/Scalar/GCSE.cpp index 7db7d4dcde..7d93c50373 100644 --- a/lib/Transforms/Scalar/GCSE.cpp +++ b/lib/Transforms/Scalar/GCSE.cpp @@ -1,4 +1,4 @@ -//===-- GCSE.cpp - SSA based Global Common Subexpr Elimination ------------===// +//===-- GCSE.cpp - SSA-based Global Common Subexpression Elimination ------===// // // The LLVM Compiler Infrastructure // @@ -33,6 +33,8 @@ namespace { Statistic<> NumCallRemoved("gcse", "Number of calls removed"); Statistic<> NumNonInsts ("gcse", "Number of instructions removed due " "to non-instruction values"); + Statistic<> NumArgsRepl ("gcse", "Number of function arguments replaced " + "with constant values"); struct GCSE : public FunctionPass { virtual bool runOnFunction(Function &F); @@ -68,6 +70,25 @@ bool GCSE::runOnFunction(Function &F) { std::vector<Value*> EqualValues; + // Check for value numbers of arguments. If the value numbering + // implementation can prove that an incoming argument is a constant or global + // value address, substitute it, making the argument dead. + for (Function::aiterator AI = F.abegin(), E = F.aend(); AI != E; ++AI) + if (!AI->use_empty()) { + VN.getEqualNumberNodes(AI, EqualValues); + if (!EqualValues.empty()) { + for (unsigned i = 0, e = EqualValues.size(); i != e; ++i) + if (isa<Constant>(EqualValues[i]) || + isa<GlobalValue>(EqualValues[i])) { + AI->replaceAllUsesWith(EqualValues[i]); + ++NumArgsRepl; + Changed = true; + break; + } + EqualValues.clear(); + } + } + // Traverse the CFG of the function in dominator order, so that we see each // instruction after we see its operands. for (df_iterator<DominatorTree::Node*> DI = df_begin(DT.getRootNode()), @@ -161,7 +182,7 @@ void GCSE::ReplaceInstructionWith(Instruction *I, Value *V) { ++NumInstRemoved; // Keep track of number of insts eliminated // Update value numbering - getAnalysis<ValueNumbering>().deleteInstruction(I); + getAnalysis<ValueNumbering>().deleteValue(I); // If we are not replacing the instruction with a constant, we cannot do // anything special. |