IPConstantPropagation.cpp (193630) | IPConstantPropagation.cpp (198090) |
---|---|
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" | 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/LLVMContext.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? | 23#include "llvm/Module.h" 24#include "llvm/Pass.h" 25#include "llvm/Analysis/ValueTracking.h" 26#include "llvm/Support/CallSite.h" 27#include "llvm/Support/Compiler.h" 28#include "llvm/ADT/Statistic.h" 29#include "llvm/ADT/SmallVector.h" 30using namespace llvm; --- 94 unchanged lines hidden (view full) --- 125 } 126 127 // If we got to this point, there is a constant argument! 128 assert(NumNonconstant != ArgumentConstants.size()); 129 bool MadeChange = false; 130 Function::arg_iterator AI = F.arg_begin(); 131 for (unsigned i = 0, e = ArgumentConstants.size(); i != e; ++i, ++AI) { 132 // Do we have a constant argument? |
132 if (ArgumentConstants[i].second || AI->use_empty()) | 133 if (ArgumentConstants[i].second || AI->use_empty() || 134 (AI->hasByValAttr() && !F.onlyReadsMemory())) |
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) { | 135 continue; 136 137 Value *V = ArgumentConstants[i].first; 138 if (V == 0) V = UndefValue::get(AI->getType()); 139 AI->replaceAllUsesWith(V); 140 ++NumArgumentsProped; 141 MadeChange = true; 142 } --- 5 unchanged lines hidden (view full) --- 148// all callers that use those return values with the constant value. This will 149// leave in the actual return values and instructions, but deadargelim will 150// clean that up. 151// 152// Additionally if a function always returns one of its arguments directly, 153// callers will be updated to use the value they pass in directly instead of 154// using the return value. 155bool IPCP::PropagateConstantReturn(Function &F) { |
154 if (F.getReturnType() == Type::VoidTy) | 156 if (F.getReturnType() == Type::getVoidTy(F.getContext())) |
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; | 157 return false; // No return value. 158 159 // If this function could be overridden later in the link stage, we can't 160 // propagate information about its results into callers. 161 if (F.mayBeOverridden()) 162 return false; |
163 164 LLVMContext &Context = F.getContext(); |
|
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 | 165 166 // Check to see if this function returns a constant. 167 SmallVector<Value *,4> RetVals; 168 const StructType *STy = dyn_cast<StructType>(F.getReturnType()); 169 if (STy) 170 for (unsigned i = 0, e = STy->getNumElements(); i < e; ++i) 171 RetVals.push_back(UndefValue::get(STy->getElementType(i))); 172 else --- 8 unchanged lines hidden (view full) --- 181 if (!RV) 182 continue; 183 184 // Find the returned value 185 Value *V; 186 if (!STy) 187 V = RI->getOperand(i); 188 else |
185 V = FindInsertedValue(RI->getOperand(0), i); | 189 V = FindInsertedValue(RI->getOperand(0), i, Context); |
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 --- | 190 191 if (V) { 192 // Ignore undefs, we can change them into anything 193 if (isa<UndefValue>(V)) 194 continue; 195 196 // Try to see if all the rets return the same constant or argument. 197 if (isa<Constant>(V) || isa<Argument>(V)) { --- 80 unchanged lines hidden --- |