Deleted Added
sdiff udiff text old ( 193630 ) new ( 198090 )
full compact
1//===-- IPConstantPropagation.cpp - Propagate constants through calls -----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 5 unchanged lines hidden (view full) ---

14// to clean up the mess.
15//
16//===----------------------------------------------------------------------===//
17
18#define DEBUG_TYPE "ipconstprop"
19#include "llvm/Transforms/IPO.h"
20#include "llvm/Constants.h"
21#include "llvm/Instructions.h"
22#include "llvm/Module.h"
23#include "llvm/Pass.h"
24#include "llvm/Analysis/ValueTracking.h"
25#include "llvm/Support/CallSite.h"
26#include "llvm/Support/Compiler.h"
27#include "llvm/ADT/Statistic.h"
28#include "llvm/ADT/SmallVector.h"
29using namespace llvm;

--- 94 unchanged lines hidden (view full) ---

124 }
125
126 // If we got to this point, there is a constant argument!
127 assert(NumNonconstant != ArgumentConstants.size());
128 bool MadeChange = false;
129 Function::arg_iterator AI = F.arg_begin();
130 for (unsigned i = 0, e = ArgumentConstants.size(); i != e; ++i, ++AI) {
131 // Do we have a constant argument?
132 if (ArgumentConstants[i].second || AI->use_empty())
133 continue;
134
135 Value *V = ArgumentConstants[i].first;
136 if (V == 0) V = UndefValue::get(AI->getType());
137 AI->replaceAllUsesWith(V);
138 ++NumArgumentsProped;
139 MadeChange = true;
140 }

--- 5 unchanged lines hidden (view full) ---

146// all callers that use those return values with the constant value. This will
147// leave in the actual return values and instructions, but deadargelim will
148// clean that up.
149//
150// Additionally if a function always returns one of its arguments directly,
151// callers will be updated to use the value they pass in directly instead of
152// using the return value.
153bool IPCP::PropagateConstantReturn(Function &F) {
154 if (F.getReturnType() == Type::VoidTy)
155 return false; // No return value.
156
157 // If this function could be overridden later in the link stage, we can't
158 // propagate information about its results into callers.
159 if (F.mayBeOverridden())
160 return false;
161
162 // Check to see if this function returns a constant.
163 SmallVector<Value *,4> RetVals;
164 const StructType *STy = dyn_cast<StructType>(F.getReturnType());
165 if (STy)
166 for (unsigned i = 0, e = STy->getNumElements(); i < e; ++i)
167 RetVals.push_back(UndefValue::get(STy->getElementType(i)));
168 else

--- 8 unchanged lines hidden (view full) ---

177 if (!RV)
178 continue;
179
180 // Find the returned value
181 Value *V;
182 if (!STy)
183 V = RI->getOperand(i);
184 else
185 V = FindInsertedValue(RI->getOperand(0), i);
186
187 if (V) {
188 // Ignore undefs, we can change them into anything
189 if (isa<UndefValue>(V))
190 continue;
191
192 // Try to see if all the rets return the same constant or argument.
193 if (isa<Constant>(V) || isa<Argument>(V)) {

--- 80 unchanged lines hidden ---