Deleted Added
full compact
SSAUpdater.cpp (218893) SSAUpdater.cpp (221345)
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"
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/Constants.h"
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"
16#include "llvm/Instructions.h"
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/Analysis/InstructionSimplify.h"
19#include "llvm/Support/AlignOf.h"
20#include "llvm/Support/Allocator.h"
21#include "llvm/Support/CFG.h"
22#include "llvm/Support/Debug.h"
23#include "llvm/Support/raw_ostream.h"
24#include "llvm/Transforms/Utils/BasicBlockUtils.h"
23#include "llvm/Transforms/Utils/SSAUpdater.h"
24#include "llvm/Transforms/Utils/SSAUpdaterImpl.h"
25#include "llvm/Transforms/Utils/SSAUpdater.h"
26#include "llvm/Transforms/Utils/SSAUpdaterImpl.h"
27
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.
28using namespace llvm;
29
30typedef DenseMap<BasicBlock*, Value*> AvailableValsTy;
31static AvailableValsTy &getAvailableVals(void *AV) {
32 return *static_cast<AvailableValsTy*>(AV);
33}
34
35SSAUpdater::SSAUpdater(SmallVectorImpl<PHINode*> *NewPHI)

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

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

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

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

--- 209 unchanged lines hidden ---