Deleted Added
sdiff udiff text old ( 218893 ) new ( 221345 )
full compact
1//===- SSAUpdater.cpp - Unstructured SSA Update Tool ----------------------===//
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//===----------------------------------------------------------------------===//
9//
10// This file implements the SSAUpdater class.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "ssaupdater"
15#include "llvm/Instructions.h"
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/Analysis/InstructionSimplify.h"
18#include "llvm/Support/AlignOf.h"
19#include "llvm/Support/Allocator.h"
20#include "llvm/Support/CFG.h"
21#include "llvm/Support/Debug.h"
22#include "llvm/Support/raw_ostream.h"
23#include "llvm/Transforms/Utils/SSAUpdater.h"
24#include "llvm/Transforms/Utils/SSAUpdaterImpl.h"
25using namespace llvm;
26
27typedef DenseMap<BasicBlock*, Value*> AvailableValsTy;
28static AvailableValsTy &getAvailableVals(void *AV) {
29 return *static_cast<AvailableValsTy*>(AV);
30}
31
32SSAUpdater::SSAUpdater(SmallVectorImpl<PHINode*> *NewPHI)

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

165 for (BasicBlock::iterator It = BB->begin();
166 (SomePHI = dyn_cast<PHINode>(It)); ++It) {
167 if (IsEquivalentPHI(SomePHI, ValueMapping))
168 return SomePHI;
169 }
170 }
171
172 // Ok, we have no way out, insert a new one now.
173 PHINode *InsertedPHI = PHINode::Create(ProtoType, ProtoName, &BB->front());
174 InsertedPHI->reserveOperandSpace(PredValues.size());
175
176 // Fill in all the predecessors of the PHI.
177 for (unsigned i = 0, e = PredValues.size(); i != e; ++i)
178 InsertedPHI->addIncoming(PredValues[i].second, PredValues[i].first);
179
180 // See if the PHI node can be merged to a single value. This can happen in
181 // loop cases when we get a PHI of itself and one other value.
182 if (Value *V = SimplifyInstruction(InsertedPHI)) {
183 InsertedPHI->eraseFromParent();
184 return V;
185 }
186
187 // If the client wants to know about all new instructions, tell it.
188 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
189
190 DEBUG(dbgs() << " Inserted PHI: " << *InsertedPHI << "\n");
191 return InsertedPHI;
192}
193
194/// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,

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

284 static Value *GetUndefVal(BasicBlock *BB, SSAUpdater *Updater) {
285 return UndefValue::get(Updater->ProtoType);
286 }
287
288 /// CreateEmptyPHI - Create a new PHI instruction in the specified block.
289 /// Reserve space for the operands but do not fill them in yet.
290 static Value *CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds,
291 SSAUpdater *Updater) {
292 PHINode *PHI = PHINode::Create(Updater->ProtoType, Updater->ProtoName,
293 &BB->front());
294 PHI->reserveOperandSpace(NumPreds);
295 return PHI;
296 }
297
298 /// AddPHIOperand - Add the specified value as an operand of the PHI for
299 /// the specified predecessor block.
300 static void AddPHIOperand(PHINode *PHI, Value *Val, BasicBlock *Pred) {
301 PHI->addIncoming(Val, Pred);
302 }

--- 209 unchanged lines hidden ---