Use ValueMap instead of DenseMap.

The ValueMapper used by various cloning utility maps MDNodes also.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106706 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2010-06-24 00:33:28 +00:00
parent 6539dc6e6c
commit e9916a302f
15 changed files with 108 additions and 109 deletions

View File

@ -18,7 +18,7 @@
#ifndef LLVM_TRANSFORMS_UTILS_CLONING_H
#define LLVM_TRANSFORMS_UTILS_CLONING_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/ValueMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ValueHandle.h"
@ -46,7 +46,7 @@ class AllocaInst;
/// CloneModule - Return an exact copy of the specified module
///
Module *CloneModule(const Module *M);
Module *CloneModule(const Module *M, DenseMap<const Value*, Value*> &VMap);
Module *CloneModule(const Module *M, ValueMap<const Value*, Value*> &VMap);
/// ClonedCodeInfo - This struct can be used to capture information about code
/// being cloned, while it is being cloned.
@ -102,7 +102,7 @@ struct ClonedCodeInfo {
/// parameter.
///
BasicBlock *CloneBasicBlock(const BasicBlock *BB,
DenseMap<const Value*, Value*> &VMap,
ValueMap<const Value*, Value*> &VMap,
const Twine &NameSuffix = "", Function *F = 0,
ClonedCodeInfo *CodeInfo = 0);
@ -110,7 +110,7 @@ BasicBlock *CloneBasicBlock(const BasicBlock *BB,
/// CloneLoop - Clone Loop. Clone dominator info for loop insiders. Populate
/// VMap using old blocks to new blocks mapping.
Loop *CloneLoop(Loop *L, LPPassManager *LPM, LoopInfo *LI,
DenseMap<const Value *, Value *> &VMap, Pass *P);
ValueMap<const Value *, Value *> &VMap, Pass *P);
/// CloneFunction - Return a copy of the specified function, but without
/// embedding the function into another module. Also, any references specified
@ -122,13 +122,13 @@ Loop *CloneLoop(Loop *L, LPPassManager *LPM, LoopInfo *LI,
/// information about the cloned code if non-null.
///
Function *CloneFunction(const Function *F,
DenseMap<const Value*, Value*> &VMap,
ValueMap<const Value*, Value*> &VMap,
ClonedCodeInfo *CodeInfo = 0);
/// CloneFunction - Version of the function that doesn't need the VMap.
///
inline Function *CloneFunction(const Function *F, ClonedCodeInfo *CodeInfo = 0){
DenseMap<const Value*, Value*> VMap;
ValueMap<const Value*, Value*> VMap;
return CloneFunction(F, VMap, CodeInfo);
}
@ -139,7 +139,7 @@ inline Function *CloneFunction(const Function *F, ClonedCodeInfo *CodeInfo = 0){
/// specified suffix to all values cloned.
///
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
DenseMap<const Value*, Value*> &VMap,
ValueMap<const Value*, Value*> &VMap,
SmallVectorImpl<ReturnInst*> &Returns,
const char *NameSuffix = "",
ClonedCodeInfo *CodeInfo = 0);
@ -152,7 +152,7 @@ void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
/// dead. Since this doesn't produce an exactly copy of the input, it can't be
/// used for things like CloneFunction or CloneModule.
void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
DenseMap<const Value*, Value*> &VMap,
ValueMap<const Value*, Value*> &VMap,
SmallVectorImpl<ReturnInst*> &Returns,
const char *NameSuffix = "",
ClonedCodeInfo *CodeInfo = 0,

View File

@ -150,8 +150,8 @@ void PIC16Cloner::markCallGraph(CallGraphNode *CGN, string StringMark) {
// For PIC16, automatic variables of a function are emitted as globals.
// Clone the auto variables of a function and put them in ValueMap,
// this ValueMap will be used while
// Clone the auto variables of a function and put them in VMap,
// this VMap will be used while
// Cloning the code of function itself.
//
void PIC16Cloner::CloneAutos(Function *F) {
@ -160,11 +160,11 @@ void PIC16Cloner::CloneAutos(Function *F) {
Module *M = F->getParent();
Module::GlobalListType &Globals = M->getGlobalList();
// Clear the leftovers in ValueMap by any previous cloning.
ValueMap.clear();
// Clear the leftovers in VMap by any previous cloning.
VMap.clear();
// Find the auto globls for this function and clone them, and put them
// in ValueMap.
// in VMap.
std::string FnName = F->getName().str();
std::string VarName, ClonedVarName;
for (Module::global_iterator I = M->global_begin(), E = M->global_end();
@ -182,8 +182,8 @@ void PIC16Cloner::CloneAutos(Function *F) {
// Add these new globals to module's globals list.
Globals.push_back(ClonedGV);
// Update ValueMap.
ValueMap[GV] = ClonedGV;
// Update VMap.
VMap[GV] = ClonedGV;
}
}
}
@ -236,10 +236,10 @@ void PIC16Cloner::cloneSharedFunctions(CallGraphNode *CGN) {
}
// Clone the given function and return it.
// Note: it uses the ValueMap member of the class, which is already populated
// Note: it uses the VMap member of the class, which is already populated
// by cloneAutos by the time we reach here.
// FIXME: Should we just pass ValueMap's ref as a parameter here? rather
// than keeping the ValueMap as a member.
// FIXME: Should we just pass VMap's ref as a parameter here? rather
// than keeping the VMap as a member.
Function *
PIC16Cloner::cloneFunction(Function *OrgF) {
Function *ClonedF;
@ -252,11 +252,11 @@ PIC16Cloner::cloneFunction(Function *OrgF) {
}
// Clone does not exist.
// First clone the autos, and populate ValueMap.
// First clone the autos, and populate VMap.
CloneAutos(OrgF);
// Now create the clone.
ClonedF = CloneFunction(OrgF, ValueMap);
ClonedF = CloneFunction(OrgF, VMap);
// The new function should be for interrupt line. Therefore should have
// the name suffixed with IL and section attribute marked with IL.

View File

@ -15,7 +15,7 @@
#ifndef PIC16CLONER_H
#define PIC16CLONER_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/ValueMap.h"
using namespace llvm;
using std::vector;
@ -72,7 +72,7 @@ namespace llvm {
// the corresponding cloned auto variable of the cloned function.
// This value map is passed during the function cloning so that all the
// uses of auto variables be updated properly.
DenseMap<const Value*, Value*> ValueMap;
ValueMap<const Value*, Value*> VMap;
// Map of a already cloned functions.
map<Function *, Function *> ClonedFunctionMap;

View File

@ -66,13 +66,13 @@ Function* PartialInliner::unswitchFunction(Function* F) {
return 0;
// Clone the function, so that we can hack away on it.
DenseMap<const Value*, Value*> ValueMap;
Function* duplicateFunction = CloneFunction(F, ValueMap);
ValueMap<const Value*, Value*> VMap;
Function* duplicateFunction = CloneFunction(F, VMap);
duplicateFunction->setLinkage(GlobalValue::InternalLinkage);
F->getParent()->getFunctionList().push_back(duplicateFunction);
BasicBlock* newEntryBlock = cast<BasicBlock>(ValueMap[entryBlock]);
BasicBlock* newReturnBlock = cast<BasicBlock>(ValueMap[returnBlock]);
BasicBlock* newNonReturnBlock = cast<BasicBlock>(ValueMap[nonReturnBlock]);
BasicBlock* newEntryBlock = cast<BasicBlock>(VMap[entryBlock]);
BasicBlock* newReturnBlock = cast<BasicBlock>(VMap[returnBlock]);
BasicBlock* newNonReturnBlock = cast<BasicBlock>(VMap[nonReturnBlock]);
// Go ahead and update all uses to the duplicate, so that we can just
// use the inliner functionality when we're done hacking.

View File

@ -64,10 +64,10 @@ X("partialspecialization", "Partial Specialization");
// a call to the specialized function. Returns the specialized function
static Function*
SpecializeFunction(Function* F,
DenseMap<const Value*, Value*>& replacements) {
ValueMap<const Value*, Value*>& replacements) {
// arg numbers of deleted arguments
DenseMap<unsigned, const Argument*> deleted;
for (DenseMap<const Value*, Value*>::iterator
for (ValueMap<const Value*, Value*>::iterator
repb = replacements.begin(), repe = replacements.end();
repb != repe; ++repb) {
Argument const *arg = cast<const Argument>(repb->first);
@ -150,7 +150,7 @@ bool PartSpec::runOnModule(Module &M) {
ee = distribution.end(); ii != ee; ++ii)
if (total > ii->second && ii->first &&
ii->second > total * ConstValPercent) {
DenseMap<const Value*, Value*> m;
ValueMap<const Value*, Value*> m;
Function::arg_iterator arg = F.arg_begin();
for (int y = 0; y < interestingArgs[x]; ++y)
++arg;

View File

@ -1016,13 +1016,13 @@ bool LoopIndexSplit::splitLoop() {
BSV = getMax(BSV, IVStartValue, Sign, PHTerm);
// [*] Clone Loop
DenseMap<const Value *, Value *> ValueMap;
Loop *BLoop = CloneLoop(L, LPM, LI, ValueMap, this);
ValueMap<const Value *, Value *> VMap;
Loop *BLoop = CloneLoop(L, LPM, LI, VMap, this);
Loop *ALoop = L;
// [*] ALoop's exiting edge enters BLoop's header.
// ALoop's original exit block becomes BLoop's exit block.
PHINode *B_IndVar = cast<PHINode>(ValueMap[IndVar]);
PHINode *B_IndVar = cast<PHINode>(VMap[IndVar]);
BasicBlock *A_ExitingBlock = ExitCondition->getParent();
BranchInst *A_ExitInsn =
dyn_cast<BranchInst>(A_ExitingBlock->getTerminator());
@ -1047,7 +1047,7 @@ bool LoopIndexSplit::splitLoop() {
for (BasicBlock::iterator BI = ALoop->getHeader()->begin(),
BE = ALoop->getHeader()->end(); BI != BE; ++BI) {
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
PHINode *PNClone = cast<PHINode>(ValueMap[PN]);
PHINode *PNClone = cast<PHINode>(VMap[PN]);
InverseMap[PNClone] = PN;
} else
break;
@ -1085,11 +1085,11 @@ bool LoopIndexSplit::splitLoop() {
// block. Remove incoming PHINode values from ALoop's exiting block.
// Add new incoming values from BLoop's incoming exiting value.
// Update BLoop exit block's dominator info..
BasicBlock *B_ExitingBlock = cast<BasicBlock>(ValueMap[A_ExitingBlock]);
BasicBlock *B_ExitingBlock = cast<BasicBlock>(VMap[A_ExitingBlock]);
for (BasicBlock::iterator BI = B_ExitBlock->begin(), BE = B_ExitBlock->end();
BI != BE; ++BI) {
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
PN->addIncoming(ValueMap[PN->getIncomingValueForBlock(A_ExitingBlock)],
PN->addIncoming(VMap[PN->getIncomingValueForBlock(A_ExitingBlock)],
B_ExitingBlock);
PN->removeIncomingValue(A_ExitingBlock);
} else
@ -1131,7 +1131,7 @@ bool LoopIndexSplit::splitLoop() {
removeBlocks(A_InactiveBranch, L, A_ActiveBranch);
//[*] Eliminate split condition's inactive branch in from BLoop.
BasicBlock *B_SplitCondBlock = cast<BasicBlock>(ValueMap[A_SplitCondBlock]);
BasicBlock *B_SplitCondBlock = cast<BasicBlock>(VMap[A_SplitCondBlock]);
BranchInst *B_BR = cast<BranchInst>(B_SplitCondBlock->getTerminator());
BasicBlock *B_InactiveBranch = NULL;
BasicBlock *B_ActiveBranch = NULL;
@ -1146,9 +1146,9 @@ bool LoopIndexSplit::splitLoop() {
//[*] Move exit condition into split condition block to avoid
// executing dead loop iteration.
ICmpInst *B_ExitCondition = cast<ICmpInst>(ValueMap[ExitCondition]);
Instruction *B_IndVarIncrement = cast<Instruction>(ValueMap[IVIncrement]);
ICmpInst *B_SplitCondition = cast<ICmpInst>(ValueMap[SplitCondition]);
ICmpInst *B_ExitCondition = cast<ICmpInst>(VMap[ExitCondition]);
Instruction *B_IndVarIncrement = cast<Instruction>(VMap[IVIncrement]);
ICmpInst *B_SplitCondition = cast<ICmpInst>(VMap[SplitCondition]);
moveExitCondition(A_SplitCondBlock, A_ActiveBranch, A_ExitBlock, ExitCondition,
cast<ICmpInst>(SplitCondition), IndVar, IVIncrement,

View File

@ -457,21 +457,21 @@ bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val) {
}
// RemapInstruction - Convert the instruction operands from referencing the
// current values into those specified by ValueMap.
// current values into those specified by VMap.
//
static inline void RemapInstruction(Instruction *I,
DenseMap<const Value *, Value*> &ValueMap) {
ValueMap<const Value *, Value*> &VMap) {
for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
Value *Op = I->getOperand(op);
DenseMap<const Value *, Value*>::iterator It = ValueMap.find(Op);
if (It != ValueMap.end()) Op = It->second;
ValueMap<const Value *, Value*>::iterator It = VMap.find(Op);
if (It != VMap.end()) Op = It->second;
I->setOperand(op, Op);
}
}
/// CloneLoop - Recursively clone the specified loop and all of its children,
/// mapping the blocks with the specified map.
static Loop *CloneLoop(Loop *L, Loop *PL, DenseMap<const Value*, Value*> &VM,
static Loop *CloneLoop(Loop *L, Loop *PL, ValueMap<const Value*, Value*> &VM,
LoopInfo *LI, LPPassManager *LPM) {
Loop *New = new Loop();
LPM->insertLoop(New, PL);
@ -615,11 +615,11 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
// the loop preheader and exit blocks), keeping track of the mapping between
// the instructions and blocks.
NewBlocks.reserve(LoopBlocks.size());
DenseMap<const Value*, Value*> ValueMap;
ValueMap<const Value*, Value*> VMap;
for (unsigned i = 0, e = LoopBlocks.size(); i != e; ++i) {
BasicBlock *NewBB = CloneBasicBlock(LoopBlocks[i], ValueMap, ".us", F);
BasicBlock *NewBB = CloneBasicBlock(LoopBlocks[i], VMap, ".us", F);
NewBlocks.push_back(NewBB);
ValueMap[LoopBlocks[i]] = NewBB; // Keep the BB mapping.
VMap[LoopBlocks[i]] = NewBB; // Keep the BB mapping.
LPM->cloneBasicBlockSimpleAnalysis(LoopBlocks[i], NewBB, L);
}
@ -629,7 +629,7 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
NewBlocks[0], F->end());
// Now we create the new Loop object for the versioned loop.
Loop *NewLoop = CloneLoop(L, L->getParentLoop(), ValueMap, LI, LPM);
Loop *NewLoop = CloneLoop(L, L->getParentLoop(), VMap, LI, LPM);
Loop *ParentLoop = L->getParentLoop();
if (ParentLoop) {
// Make sure to add the cloned preheader and exit blocks to the parent loop
@ -638,7 +638,7 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
}
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
BasicBlock *NewExit = cast<BasicBlock>(ValueMap[ExitBlocks[i]]);
BasicBlock *NewExit = cast<BasicBlock>(VMap[ExitBlocks[i]]);
// The new exit block should be in the same loop as the old one.
if (Loop *ExitBBLoop = LI->getLoopFor(ExitBlocks[i]))
ExitBBLoop->addBasicBlockToLoop(NewExit, LI->getBase());
@ -653,8 +653,8 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
for (BasicBlock::iterator I = ExitSucc->begin(); isa<PHINode>(I); ++I) {
PN = cast<PHINode>(I);
Value *V = PN->getIncomingValueForBlock(ExitBlocks[i]);
DenseMap<const Value *, Value*>::iterator It = ValueMap.find(V);
if (It != ValueMap.end()) V = It->second;
ValueMap<const Value *, Value*>::iterator It = VMap.find(V);
if (It != VMap.end()) V = It->second;
PN->addIncoming(V, NewExit);
}
}
@ -663,7 +663,7 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
for (unsigned i = 0, e = NewBlocks.size(); i != e; ++i)
for (BasicBlock::iterator I = NewBlocks[i]->begin(),
E = NewBlocks[i]->end(); I != E; ++I)
RemapInstruction(I, ValueMap);
RemapInstruction(I, VMap);
// Rewrite the original preheader to select between versions of the loop.
BranchInst *OldBR = cast<BranchInst>(loopPreheader->getTerminator());

View File

@ -15,7 +15,6 @@
#include "llvm/BasicBlock.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/ADT/DenseMap.h"
using namespace llvm;
@ -23,12 +22,12 @@ using namespace llvm;
/// CloneDominatorInfo - Clone basicblock's dominator tree and, if available,
/// dominance info. It is expected that basic block is already cloned.
static void CloneDominatorInfo(BasicBlock *BB,
DenseMap<const Value *, Value *> &VMap,
ValueMap<const Value *, Value *> &VMap,
DominatorTree *DT,
DominanceFrontier *DF) {
assert (DT && "DominatorTree is not available");
DenseMap<const Value *, Value*>::iterator BI = VMap.find(BB);
ValueMap<const Value *, Value*>::iterator BI = VMap.find(BB);
assert (BI != VMap.end() && "BasicBlock clone is missing");
BasicBlock *NewBB = cast<BasicBlock>(BI->second);
@ -43,7 +42,7 @@ static void CloneDominatorInfo(BasicBlock *BB,
// NewBB's dominator is either BB's dominator or BB's dominator's clone.
BasicBlock *NewBBDom = BBDom;
DenseMap<const Value *, Value*>::iterator BBDomI = VMap.find(BBDom);
ValueMap<const Value *, Value*>::iterator BBDomI = VMap.find(BBDom);
if (BBDomI != VMap.end()) {
NewBBDom = cast<BasicBlock>(BBDomI->second);
if (!DT->getNode(NewBBDom))
@ -60,7 +59,7 @@ static void CloneDominatorInfo(BasicBlock *BB,
for (DominanceFrontier::DomSetType::iterator I = S.begin(), E = S.end();
I != E; ++I) {
BasicBlock *DB = *I;
DenseMap<const Value*, Value*>::iterator IDM = VMap.find(DB);
ValueMap<const Value*, Value*>::iterator IDM = VMap.find(DB);
if (IDM != VMap.end())
NewDFSet.insert(cast<BasicBlock>(IDM->second));
else
@ -74,7 +73,7 @@ static void CloneDominatorInfo(BasicBlock *BB,
/// CloneLoop - Clone Loop. Clone dominator info. Populate VMap
/// using old blocks to new blocks mapping.
Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager *LPM, LoopInfo *LI,
DenseMap<const Value *, Value *> &VMap, Pass *P) {
ValueMap<const Value *, Value *> &VMap, Pass *P) {
DominatorTree *DT = NULL;
DominanceFrontier *DF = NULL;
@ -135,7 +134,7 @@ Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager *LPM, LoopInfo *LI,
for (unsigned index = 0, num_ops = Insn->getNumOperands();
index != num_ops; ++index) {
Value *Op = Insn->getOperand(index);
DenseMap<const Value *, Value *>::iterator OpItr = VMap.find(Op);
ValueMap<const Value *, Value *>::iterator OpItr = VMap.find(Op);
if (OpItr != VMap.end())
Insn->setOperand(index, OpItr->second);
}

View File

@ -169,7 +169,7 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
/// some edges of the callgraph may remain.
static void UpdateCallGraphAfterInlining(CallSite CS,
Function::iterator FirstNewBlock,
DenseMap<const Value*, Value*> &VMap,
ValueMap<const Value*, Value*> &VMap,
InlineFunctionInfo &IFI) {
CallGraph &CG = *IFI.CG;
const Function *Caller = CS.getInstruction()->getParent()->getParent();
@ -192,7 +192,7 @@ static void UpdateCallGraphAfterInlining(CallSite CS,
for (; I != E; ++I) {
const Value *OrigCall = I->first;
DenseMap<const Value*, Value*>::iterator VMI = VMap.find(OrigCall);
ValueMap<const Value*, Value*>::iterator VMI = VMap.find(OrigCall);
// Only copy the edge if the call was inlined!
if (VMI == VMap.end() || VMI->second == 0)
continue;
@ -286,7 +286,7 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI) {
Function::iterator FirstNewBlock;
{ // Scope to destroy VMap after cloning.
DenseMap<const Value*, Value*> VMap;
ValueMap<const Value*, Value*> VMap;
assert(CalledFunc->arg_size() == CS.arg_size() &&
"No varargs calls can be inlined!");

View File

@ -39,10 +39,10 @@ STATISTIC(NumUnrolled, "Number of loops unrolled (completely or otherwise)");
/// RemapInstruction - Convert the instruction operands from referencing the
/// current values into those specified by VMap.
static inline void RemapInstruction(Instruction *I,
DenseMap<const Value *, Value*> &VMap) {
ValueMap<const Value *, Value*> &VMap) {
for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
Value *Op = I->getOperand(op);
DenseMap<const Value *, Value*>::iterator It = VMap.find(Op);
ValueMap<const Value *, Value*>::iterator It = VMap.find(Op);
if (It != VMap.end())
I->setOperand(op, It->second);
}
@ -183,7 +183,7 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, LoopInfo* LI, LPPassManager* LPM)
// For the first iteration of the loop, we should use the precloned values for
// PHI nodes. Insert associations now.
typedef DenseMap<const Value*, Value*> ValueToValueMapTy;
typedef ValueMap<const Value*, Value*> ValueToValueMapTy;
ValueToValueMapTy LastValueMap;
std::vector<PHINode*> OrigPHINode;
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {

View File

@ -15,12 +15,12 @@
#ifndef VALUEMAPPER_H
#define VALUEMAPPER_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/ValueMap.h"
namespace llvm {
class Value;
class Instruction;
typedef DenseMap<const Value *, Value *> ValueToValueMapTy;
typedef ValueMap<const Value *, Value *> ValueToValueMapTy;
Value *MapValue(const Value *V, ValueToValueMapTy &VM);
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM);

View File

@ -16,7 +16,7 @@
#ifndef BUGDRIVER_H
#define BUGDRIVER_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/ValueMap.h"
#include <vector>
#include <string>
@ -325,7 +325,7 @@ void DeleteFunctionBody(Function *F);
/// module, split the functions OUT of the specified module, and place them in
/// the new module.
Module *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F,
DenseMap<const Value*, Value*> &ValueMap);
ValueMap<const Value*, Value*> &VMap);
} // End llvm namespace

View File

@ -130,14 +130,14 @@ bool
ReduceCrashingGlobalVariables::TestGlobalVariables(
std::vector<GlobalVariable*> &GVs) {
// Clone the program to try hacking it apart...
DenseMap<const Value*, Value*> ValueMap;
Module *M = CloneModule(BD.getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *M = CloneModule(BD.getProgram(), VMap);
// Convert list to set for fast lookup...
std::set<GlobalVariable*> GVSet;
for (unsigned i = 0, e = GVs.size(); i != e; ++i) {
GlobalVariable* CMGV = cast<GlobalVariable>(ValueMap[GVs[i]]);
GlobalVariable* CMGV = cast<GlobalVariable>(VMap[GVs[i]]);
assert(CMGV && "Global Variable not in module?!");
GVSet.insert(CMGV);
}
@ -204,13 +204,13 @@ bool ReduceCrashingFunctions::TestFuncs(std::vector<Function*> &Funcs) {
return false;
// Clone the program to try hacking it apart...
DenseMap<const Value*, Value*> ValueMap;
Module *M = CloneModule(BD.getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *M = CloneModule(BD.getProgram(), VMap);
// Convert list to set for fast lookup...
std::set<Function*> Functions;
for (unsigned i = 0, e = Funcs.size(); i != e; ++i) {
Function *CMF = cast<Function>(ValueMap[Funcs[i]]);
Function *CMF = cast<Function>(VMap[Funcs[i]]);
assert(CMF && "Function not in module?!");
assert(CMF->getFunctionType() == Funcs[i]->getFunctionType() && "wrong ty");
assert(CMF->getName() == Funcs[i]->getName() && "wrong name");
@ -270,13 +270,13 @@ namespace {
bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
// Clone the program to try hacking it apart...
DenseMap<const Value*, Value*> ValueMap;
Module *M = CloneModule(BD.getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *M = CloneModule(BD.getProgram(), VMap);
// Convert list to set for fast lookup...
SmallPtrSet<BasicBlock*, 8> Blocks;
for (unsigned i = 0, e = BBs.size(); i != e; ++i)
Blocks.insert(cast<BasicBlock>(ValueMap[BBs[i]]));
Blocks.insert(cast<BasicBlock>(VMap[BBs[i]]));
outs() << "Checking for crash with only these blocks:";
unsigned NumPrint = Blocks.size();
@ -371,14 +371,14 @@ namespace {
bool ReduceCrashingInstructions::TestInsts(std::vector<const Instruction*>
&Insts) {
// Clone the program to try hacking it apart...
DenseMap<const Value*, Value*> ValueMap;
Module *M = CloneModule(BD.getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *M = CloneModule(BD.getProgram(), VMap);
// Convert list to set for fast lookup...
SmallPtrSet<Instruction*, 64> Instructions;
for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
assert(!isa<TerminatorInst>(Insts[i]));
Instructions.insert(cast<Instruction>(ValueMap[Insts[i]]));
Instructions.insert(cast<Instruction>(VMap[Insts[i]]));
}
outs() << "Checking for crash with only " << Instructions.size();

View File

@ -201,7 +201,7 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
/// static ctors/dtors, we need to add an llvm.global_[cd]tors global to M2, and
/// prune appropriate entries out of M1s list.
static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
DenseMap<const Value*, Value*> ValueMap) {
ValueMap<const Value*, Value*> VMap) {
GlobalVariable *GV = M1->getNamedGlobal(GlobalName);
if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() ||
!GV->use_empty()) return;
@ -229,7 +229,7 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
M1Tors.push_back(std::make_pair(F, Priority));
else {
// Map to M2's version of the function.
F = cast<Function>(ValueMap[F]);
F = cast<Function>(VMap[F]);
M2Tors.push_back(std::make_pair(F, Priority));
}
}
@ -264,7 +264,7 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
Module *
llvm::SplitFunctionsOutOfModule(Module *M,
const std::vector<Function*> &F,
DenseMap<const Value*, Value*> &ValueMap) {
ValueMap<const Value*, Value*> &VMap) {
// Make sure functions & globals are all external so that linkage
// between the two modules will work.
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
@ -276,8 +276,8 @@ llvm::SplitFunctionsOutOfModule(Module *M,
I->setLinkage(GlobalValue::ExternalLinkage);
}
DenseMap<const Value*, Value*> NewValueMap;
Module *New = CloneModule(M, NewValueMap);
ValueMap<const Value*, Value*> NewVMap;
Module *New = CloneModule(M, NewVMap);
// Make sure global initializers exist only in the safe module (CBE->.so)
for (Module::global_iterator I = New->global_begin(), E = New->global_end();
@ -287,11 +287,11 @@ llvm::SplitFunctionsOutOfModule(Module *M,
// Remove the Test functions from the Safe module
std::set<Function *> TestFunctions;
for (unsigned i = 0, e = F.size(); i != e; ++i) {
Function *TNOF = cast<Function>(ValueMap[F[i]]);
Function *TNOF = cast<Function>(VMap[F[i]]);
DEBUG(errs() << "Removing function ");
DEBUG(WriteAsOperand(errs(), TNOF, false));
DEBUG(errs() << "\n");
TestFunctions.insert(cast<Function>(NewValueMap[TNOF]));
TestFunctions.insert(cast<Function>(NewVMap[TNOF]));
DeleteFunctionBody(TNOF); // Function is now external in this module!
}
@ -304,8 +304,8 @@ llvm::SplitFunctionsOutOfModule(Module *M,
// Make sure that there is a global ctor/dtor array in both halves of the
// module if they both have static ctor/dtor functions.
SplitStaticCtorDtor("llvm.global_ctors", M, New, NewValueMap);
SplitStaticCtorDtor("llvm.global_dtors", M, New, NewValueMap);
SplitStaticCtorDtor("llvm.global_ctors", M, New, NewVMap);
SplitStaticCtorDtor("llvm.global_dtors", M, New, NewVMap);
return New;
}

View File

@ -251,10 +251,10 @@ int ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*> &Funcs,
outs() << '\n';
// Split the module into the two halves of the program we want.
DenseMap<const Value*, Value*> ValueMap;
Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs,
ValueMap);
VMap);
// Run the predicate, note that the predicate will delete both input modules.
return TestFn(BD, ToOptimize, ToNotOptimize, Error);
@ -285,11 +285,11 @@ static bool ExtractLoops(BugDriver &BD,
while (1) {
if (BugpointIsInterrupted) return MadeChange;
DenseMap<const Value*, Value*> ValueMap;
Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
MiscompiledFunctions,
ValueMap);
VMap);
Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize);
if (!ToOptimizeLoopExtracted) {
// If the loop extractor crashed or if there were no extractible loops,
@ -448,11 +448,11 @@ bool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock*> &BBs,
outs() << '\n';
// Split the module into the two halves of the program we want.
DenseMap<const Value*, Value*> ValueMap;
Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
FunctionsBeingTested,
ValueMap);
VMap);
// Try the extraction. If it doesn't work, then the block extractor crashed
// or something, in which case bugpoint can't chase down this possibility.
@ -505,11 +505,11 @@ static bool ExtractBlocks(BugDriver &BD,
return false;
}
DenseMap<const Value*, Value*> ValueMap;
Module *ProgClone = CloneModule(BD.getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *ProgClone = CloneModule(BD.getProgram(), VMap);
Module *ToExtract = SplitFunctionsOutOfModule(ProgClone,
MiscompiledFunctions,
ValueMap);
VMap);
Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract);
if (Extracted == 0) {
// Weird, extraction should have worked.
@ -687,11 +687,11 @@ void BugDriver::debugMiscompilation(std::string *Error) {
// Output a bunch of bitcode files for the user...
outs() << "Outputting reduced bitcode files which expose the problem:\n";
DenseMap<const Value*, Value*> ValueMap;
Module *ToNotOptimize = CloneModule(getProgram(), ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *ToNotOptimize = CloneModule(getProgram(), VMap);
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
MiscompiledFunctions,
ValueMap);
VMap);
outs() << " Non-optimized portion: ";
ToNotOptimize = swapProgramIn(ToNotOptimize);
@ -960,9 +960,9 @@ bool BugDriver::debugCodeGenerator(std::string *Error) {
return true;
// Split the module into the two halves of the program we want.
DenseMap<const Value*, Value*> ValueMap;
Module *ToNotCodeGen = CloneModule(getProgram(), ValueMap);
Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, ValueMap);
ValueMap<const Value*, Value*> VMap;
Module *ToNotCodeGen = CloneModule(getProgram(), VMap);
Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, VMap);
// Condition the modules
CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen);