llvm.org GIT mirror llvm / e9916a3
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 Devang Patel 10 years ago
15 changed file(s) with 108 addition(s) and 109 deletion(s). Raw diff Collapse all Expand all
1717 #ifndef LLVM_TRANSFORMS_UTILS_CLONING_H
1818 #define LLVM_TRANSFORMS_UTILS_CLONING_H
1919
20 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/ValueMap.h"
2121 #include "llvm/ADT/SmallVector.h"
2222 #include "llvm/ADT/Twine.h"
2323 #include "llvm/Support/ValueHandle.h"
4545 /// CloneModule - Return an exact copy of the specified module
4646 ///
4747 Module *CloneModule(const Module *M);
48 Module *CloneModule(const Module *M, DenseMap &VMap);
48 Module *CloneModule(const Module *M, ValueMap &VMap);
4949
5050 /// ClonedCodeInfo - This struct can be used to capture information about code
5151 /// being cloned, while it is being cloned.
101101 /// parameter.
102102 ///
103103 BasicBlock *CloneBasicBlock(const BasicBlock *BB,
104 DenseMap &VMap,
104 ValueMap &VMap,
105105 const Twine &NameSuffix = "", Function *F = 0,
106106 ClonedCodeInfo *CodeInfo = 0);
107107
109109 /// CloneLoop - Clone Loop. Clone dominator info for loop insiders. Populate
110110 /// VMap using old blocks to new blocks mapping.
111111 Loop *CloneLoop(Loop *L, LPPassManager *LPM, LoopInfo *LI,
112 DenseMap &VMap, Pass *P);
112 ValueMap &VMap, Pass *P);
113113
114114 /// CloneFunction - Return a copy of the specified function, but without
115115 /// embedding the function into another module. Also, any references specified
121121 /// information about the cloned code if non-null.
122122 ///
123123 Function *CloneFunction(const Function *F,
124 DenseMap &VMap,
124 ValueMap &VMap,
125125 ClonedCodeInfo *CodeInfo = 0);
126126
127127 /// CloneFunction - Version of the function that doesn't need the VMap.
128128 ///
129129 inline Function *CloneFunction(const Function *F, ClonedCodeInfo *CodeInfo = 0){
130 DenseMap VMap;
130 ValueMap VMap;
131131 return CloneFunction(F, VMap, CodeInfo);
132132 }
133133
138138 /// specified suffix to all values cloned.
139139 ///
140140 void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
141 DenseMap &VMap,
141 ValueMap &VMap,
142142 SmallVectorImpl &Returns,
143143 const char *NameSuffix = "",
144144 ClonedCodeInfo *CodeInfo = 0);
151151 /// dead. Since this doesn't produce an exactly copy of the input, it can't be
152152 /// used for things like CloneFunction or CloneModule.
153153 void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
154 DenseMap &VMap,
154 ValueMap &VMap,
155155 SmallVectorImpl &Returns,
156156 const char *NameSuffix = "",
157157 ClonedCodeInfo *CodeInfo = 0,
149149
150150
151151 // For PIC16, automatic variables of a function are emitted as globals.
152 // Clone the auto variables of a function and put them in ValueMap,
153 // this ValueMap will be used while
152 // Clone the auto variables of a function and put them in VMap,
153 // this VMap will be used while
154154 // Cloning the code of function itself.
155155 //
156156 void PIC16Cloner::CloneAutos(Function *F) {
159159 Module *M = F->getParent();
160160 Module::GlobalListType &Globals = M->getGlobalList();
161161
162 // Clear the leftovers in ValueMap by any previous cloning.
163 ValueMap.clear();
162 // Clear the leftovers in VMap by any previous cloning.
163 VMap.clear();
164164
165165 // Find the auto globls for this function and clone them, and put them
166 // in ValueMap.
166 // in VMap.
167167 std::string FnName = F->getName().str();
168168 std::string VarName, ClonedVarName;
169169 for (Module::global_iterator I = M->global_begin(), E = M->global_end();
181181 // Add these new globals to module's globals list.
182182 Globals.push_back(ClonedGV);
183183
184 // Update ValueMap.
185 ValueMap[GV] = ClonedGV;
184 // Update VMap.
185 VMap[GV] = ClonedGV;
186186 }
187187 }
188188 }
235235 }
236236
237237 // Clone the given function and return it.
238 // Note: it uses the ValueMap member of the class, which is already populated
238 // Note: it uses the VMap member of the class, which is already populated
239239 // by cloneAutos by the time we reach here.
240 // FIXME: Should we just pass ValueMap's ref as a parameter here? rather
241 // than keeping the ValueMap as a member.
240 // FIXME: Should we just pass VMap's ref as a parameter here? rather
241 // than keeping the VMap as a member.
242242 Function *
243243 PIC16Cloner::cloneFunction(Function *OrgF) {
244244 Function *ClonedF;
251251 }
252252
253253 // Clone does not exist.
254 // First clone the autos, and populate ValueMap.
254 // First clone the autos, and populate VMap.
255255 CloneAutos(OrgF);
256256
257257 // Now create the clone.
258 ClonedF = CloneFunction(OrgF, ValueMap);
258 ClonedF = CloneFunction(OrgF, VMap);
259259
260260 // The new function should be for interrupt line. Therefore should have
261261 // the name suffixed with IL and section attribute marked with IL.
1414 #ifndef PIC16CLONER_H
1515 #define PIC16CLONER_H
1616
17 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/ValueMap.h"
1818
1919 using namespace llvm;
2020 using std::vector;
7171 // the corresponding cloned auto variable of the cloned function.
7272 // This value map is passed during the function cloning so that all the
7373 // uses of auto variables be updated properly.
74 DenseMap ValueMap;
74 ValueMap VMap;
7575
7676 // Map of a already cloned functions.
7777 map ClonedFunctionMap;
6565 return 0;
6666
6767 // Clone the function, so that we can hack away on it.
68 DenseMap ValueMap;
69 Function* duplicateFunction = CloneFunction(F, ValueMap);
68 ValueMap VMap;
69 Function* duplicateFunction = CloneFunction(F, VMap);
7070 duplicateFunction->setLinkage(GlobalValue::InternalLinkage);
7171 F->getParent()->getFunctionList().push_back(duplicateFunction);
72 BasicBlock* newEntryBlock = cast(ValueMap[entryBlock]);
73 BasicBlock* newReturnBlock = cast(ValueMap[returnBlock]);
74 BasicBlock* newNonReturnBlock = cast(ValueMap[nonReturnBlock]);
72 BasicBlock* newEntryBlock = cast(VMap[entryBlock]);
73 BasicBlock* newReturnBlock = cast(VMap[returnBlock]);
74 BasicBlock* newNonReturnBlock = cast(VMap[nonReturnBlock]);
7575
7676 // Go ahead and update all uses to the duplicate, so that we can just
7777 // use the inliner functionality when we're done hacking.
6363 // a call to the specialized function. Returns the specialized function
6464 static Function*
6565 SpecializeFunction(Function* F,
66 DenseMap& replacements) {
66 ValueMap& replacements) {
6767 // arg numbers of deleted arguments
6868 DenseMap deleted;
69 for (DenseMap::iterator
69 for (ValueMap::iterator
7070 repb = replacements.begin(), repe = replacements.end();
7171 repb != repe; ++repb) {
7272 Argument const *arg = cast(repb->first);
149149 ee = distribution.end(); ii != ee; ++ii)
150150 if (total > ii->second && ii->first &&
151151 ii->second > total * ConstValPercent) {
152 DenseMap m;
152 ValueMap m;
153153 Function::arg_iterator arg = F.arg_begin();
154154 for (int y = 0; y < interestingArgs[x]; ++y)
155155 ++arg;
10151015 BSV = getMax(BSV, IVStartValue, Sign, PHTerm);
10161016
10171017 // [*] Clone Loop
1018 DenseMap ValueMap;
1019 Loop *BLoop = CloneLoop(L, LPM, LI, ValueMap, this);
1018 ValueMap VMap;
1019 Loop *BLoop = CloneLoop(L, LPM, LI, VMap, this);
10201020 Loop *ALoop = L;
10211021
10221022 // [*] ALoop's exiting edge enters BLoop's header.
10231023 // ALoop's original exit block becomes BLoop's exit block.
1024 PHINode *B_IndVar = cast(ValueMap[IndVar]);
1024 PHINode *B_IndVar = cast(VMap[IndVar]);
10251025 BasicBlock *A_ExitingBlock = ExitCondition->getParent();
10261026 BranchInst *A_ExitInsn =
10271027 dyn_cast(A_ExitingBlock->getTerminator());
10461046 for (BasicBlock::iterator BI = ALoop->getHeader()->begin(),
10471047 BE = ALoop->getHeader()->end(); BI != BE; ++BI) {
10481048 if (PHINode *PN = dyn_cast(BI)) {
1049 PHINode *PNClone = cast(ValueMap[PN]);
1049 PHINode *PNClone = cast(VMap[PN]);
10501050 InverseMap[PNClone] = PN;
10511051 } else
10521052 break;
10841084 // block. Remove incoming PHINode values from ALoop's exiting block.
10851085 // Add new incoming values from BLoop's incoming exiting value.
10861086 // Update BLoop exit block's dominator info..
1087 BasicBlock *B_ExitingBlock = cast(ValueMap[A_ExitingBlock]);
1087 BasicBlock *B_ExitingBlock = cast(VMap[A_ExitingBlock]);
10881088 for (BasicBlock::iterator BI = B_ExitBlock->begin(), BE = B_ExitBlock->end();
10891089 BI != BE; ++BI) {
10901090 if (PHINode *PN = dyn_cast(BI)) {
1091 PN->addIncoming(ValueMap[PN->getIncomingValueForBlock(A_ExitingBlock)],
1091 PN->addIncoming(VMap[PN->getIncomingValueForBlock(A_ExitingBlock)],
10921092 B_ExitingBlock);
10931093 PN->removeIncomingValue(A_ExitingBlock);
10941094 } else
11301130 removeBlocks(A_InactiveBranch, L, A_ActiveBranch);
11311131
11321132 //[*] Eliminate split condition's inactive branch in from BLoop.
1133 BasicBlock *B_SplitCondBlock = cast(ValueMap[A_SplitCondBlock]);
1133 BasicBlock *B_SplitCondBlock = cast(VMap[A_SplitCondBlock]);
11341134 BranchInst *B_BR = cast(B_SplitCondBlock->getTerminator());
11351135 BasicBlock *B_InactiveBranch = NULL;
11361136 BasicBlock *B_ActiveBranch = NULL;
11451145
11461146 //[*] Move exit condition into split condition block to avoid
11471147 // executing dead loop iteration.
1148 ICmpInst *B_ExitCondition = cast(ValueMap[ExitCondition]);
1149 Instruction *B_IndVarIncrement = cast(ValueMap[IVIncrement]);
1150 ICmpInst *B_SplitCondition = cast(ValueMap[SplitCondition]);
1148 ICmpInst *B_ExitCondition = cast(VMap[ExitCondition]);
1149 Instruction *B_IndVarIncrement = cast(VMap[IVIncrement]);
1150 ICmpInst *B_SplitCondition = cast(VMap[SplitCondition]);
11511151
11521152 moveExitCondition(A_SplitCondBlock, A_ActiveBranch, A_ExitBlock, ExitCondition,
11531153 cast(SplitCondition), IndVar, IVIncrement,
456456 }
457457
458458 // RemapInstruction - Convert the instruction operands from referencing the
459 // current values into those specified by ValueMap.
459 // current values into those specified by VMap.
460460 //
461461 static inline void RemapInstruction(Instruction *I,
462 DenseMap &ValueMap) {
462 ValueMap &VMap) {
463463 for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
464464 Value *Op = I->getOperand(op);
465 DenseMap::iterator It = ValueMap.find(Op);
466 if (It != ValueMap.end()) Op = It->second;
465 ValueMap::iterator It = VMap.find(Op);
466 if (It != VMap.end()) Op = It->second;
467467 I->setOperand(op, Op);
468468 }
469469 }
470470
471471 /// CloneLoop - Recursively clone the specified loop and all of its children,
472472 /// mapping the blocks with the specified map.
473 static Loop *CloneLoop(Loop *L, Loop *PL, DenseMap &VM,
473 static Loop *CloneLoop(Loop *L, Loop *PL, ValueMap &VM,
474474 LoopInfo *LI, LPPassManager *LPM) {
475475 Loop *New = new Loop();
476476 LPM->insertLoop(New, PL);
614614 // the loop preheader and exit blocks), keeping track of the mapping between
615615 // the instructions and blocks.
616616 NewBlocks.reserve(LoopBlocks.size());
617 DenseMap ValueMap;
617 ValueMap VMap;
618618 for (unsigned i = 0, e = LoopBlocks.size(); i != e; ++i) {
619 BasicBlock *NewBB = CloneBasicBlock(LoopBlocks[i], ValueMap, ".us", F);
619 BasicBlock *NewBB = CloneBasicBlock(LoopBlocks[i], VMap, ".us", F);
620620 NewBlocks.push_back(NewBB);
621 ValueMap[LoopBlocks[i]] = NewBB; // Keep the BB mapping.
621 VMap[LoopBlocks[i]] = NewBB; // Keep the BB mapping.
622622 LPM->cloneBasicBlockSimpleAnalysis(LoopBlocks[i], NewBB, L);
623623 }
624624
628628 NewBlocks[0], F->end());
629629
630630 // Now we create the new Loop object for the versioned loop.
631 Loop *NewLoop = CloneLoop(L, L->getParentLoop(), ValueMap, LI, LPM);
631 Loop *NewLoop = CloneLoop(L, L->getParentLoop(), VMap, LI, LPM);
632632 Loop *ParentLoop = L->getParentLoop();
633633 if (ParentLoop) {
634634 // Make sure to add the cloned preheader and exit blocks to the parent loop
637637 }
638638
639639 for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
640 BasicBlock *NewExit = cast(ValueMap[ExitBlocks[i]]);
640 BasicBlock *NewExit = cast(VMap[ExitBlocks[i]]);
641641 // The new exit block should be in the same loop as the old one.
642642 if (Loop *ExitBBLoop = LI->getLoopFor(ExitBlocks[i]))
643643 ExitBBLoop->addBasicBlockToLoop(NewExit, LI->getBase());
652652 for (BasicBlock::iterator I = ExitSucc->begin(); isa(I); ++I) {
653653 PN = cast(I);
654654 Value *V = PN->getIncomingValueForBlock(ExitBlocks[i]);
655 DenseMap::iterator It = ValueMap.find(V);
656 if (It != ValueMap.end()) V = It->second;
655 ValueMap::iterator It = VMap.find(V);
656 if (It != VMap.end()) V = It->second;
657657 PN->addIncoming(V, NewExit);
658658 }
659659 }
662662 for (unsigned i = 0, e = NewBlocks.size(); i != e; ++i)
663663 for (BasicBlock::iterator I = NewBlocks[i]->begin(),
664664 E = NewBlocks[i]->end(); I != E; ++I)
665 RemapInstruction(I, ValueMap);
665 RemapInstruction(I, VMap);
666666
667667 // Rewrite the original preheader to select between versions of the loop.
668668 BranchInst *OldBR = cast(loopPreheader->getTerminator());
1414 #include "llvm/BasicBlock.h"
1515 #include "llvm/Analysis/LoopPass.h"
1616 #include "llvm/Analysis/Dominators.h"
17 #include "llvm/ADT/DenseMap.h"
1817
1918
2019 using namespace llvm;
2221 /// CloneDominatorInfo - Clone basicblock's dominator tree and, if available,
2322 /// dominance info. It is expected that basic block is already cloned.
2423 static void CloneDominatorInfo(BasicBlock *BB,
25 DenseMap &VMap,
24 ValueMap &VMap,
2625 DominatorTree *DT,
2726 DominanceFrontier *DF) {
2827
2928 assert (DT && "DominatorTree is not available");
30 DenseMap::iterator BI = VMap.find(BB);
29 ValueMap::iterator BI = VMap.find(BB);
3130 assert (BI != VMap.end() && "BasicBlock clone is missing");
3231 BasicBlock *NewBB = cast(BI->second);
3332
4241
4342 // NewBB's dominator is either BB's dominator or BB's dominator's clone.
4443 BasicBlock *NewBBDom = BBDom;
45 DenseMap::iterator BBDomI = VMap.find(BBDom);
44 ValueMap::iterator BBDomI = VMap.find(BBDom);
4645 if (BBDomI != VMap.end()) {
4746 NewBBDom = cast(BBDomI->second);
4847 if (!DT->getNode(NewBBDom))
5958 for (DominanceFrontier::DomSetType::iterator I = S.begin(), E = S.end();
6059 I != E; ++I) {
6160 BasicBlock *DB = *I;
62 DenseMap::iterator IDM = VMap.find(DB);
61 ValueMap::iterator IDM = VMap.find(DB);
6362 if (IDM != VMap.end())
6463 NewDFSet.insert(cast(IDM->second));
6564 else
7372 /// CloneLoop - Clone Loop. Clone dominator info. Populate VMap
7473 /// using old blocks to new blocks mapping.
7574 Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager *LPM, LoopInfo *LI,
76 DenseMap &VMap, Pass *P) {
75 ValueMap &VMap, Pass *P) {
7776
7877 DominatorTree *DT = NULL;
7978 DominanceFrontier *DF = NULL;
134133 for (unsigned index = 0, num_ops = Insn->getNumOperands();
135134 index != num_ops; ++index) {
136135 Value *Op = Insn->getOperand(index);
137 DenseMap::iterator OpItr = VMap.find(Op);
136 ValueMap::iterator OpItr = VMap.find(Op);
138137 if (OpItr != VMap.end())
139138 Insn->setOperand(index, OpItr->second);
140139 }
168168 /// some edges of the callgraph may remain.
169169 static void UpdateCallGraphAfterInlining(CallSite CS,
170170 Function::iterator FirstNewBlock,
171 DenseMap &VMap,
171 ValueMap &VMap,
172172 InlineFunctionInfo &IFI) {
173173 CallGraph &CG = *IFI.CG;
174174 const Function *Caller = CS.getInstruction()->getParent()->getParent();
191191 for (; I != E; ++I) {
192192 const Value *OrigCall = I->first;
193193
194 DenseMap::iterator VMI = VMap.find(OrigCall);
194 ValueMap::iterator VMI = VMap.find(OrigCall);
195195 // Only copy the edge if the call was inlined!
196196 if (VMI == VMap.end() || VMI->second == 0)
197197 continue;
285285 Function::iterator FirstNewBlock;
286286
287287 { // Scope to destroy VMap after cloning.
288 DenseMap VMap;
288 ValueMap VMap;
289289
290290 assert(CalledFunc->arg_size() == CS.arg_size() &&
291291 "No varargs calls can be inlined!");
3838 /// RemapInstruction - Convert the instruction operands from referencing the
3939 /// current values into those specified by VMap.
4040 static inline void RemapInstruction(Instruction *I,
41 DenseMap &VMap) {
41 ValueMap &VMap) {
4242 for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
4343 Value *Op = I->getOperand(op);
44 DenseMap::iterator It = VMap.find(Op);
44 ValueMap::iterator It = VMap.find(Op);
4545 if (It != VMap.end())
4646 I->setOperand(op, It->second);
4747 }
182182
183183 // For the first iteration of the loop, we should use the precloned values for
184184 // PHI nodes. Insert associations now.
185 typedef DenseMap ValueToValueMapTy;
185 typedef ValueMap ValueToValueMapTy;
186186 ValueToValueMapTy LastValueMap;
187187 std::vector OrigPHINode;
188188 for (BasicBlock::iterator I = Header->begin(); isa(I); ++I) {
1414 #ifndef VALUEMAPPER_H
1515 #define VALUEMAPPER_H
1616
17 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/ValueMap.h"
1818
1919 namespace llvm {
2020 class Value;
2121 class Instruction;
22 typedef DenseMap ValueToValueMapTy;
22 typedef ValueMap ValueToValueMapTy;
2323
2424 Value *MapValue(const Value *V, ValueToValueMapTy &VM);
2525 void RemapInstruction(Instruction *I, ValueToValueMapTy &VM);
1515 #ifndef BUGDRIVER_H
1616 #define BUGDRIVER_H
1717
18 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/ValueMap.h"
1919 #include
2020 #include
2121
324324 /// module, split the functions OUT of the specified module, and place them in
325325 /// the new module.
326326 Module *SplitFunctionsOutOfModule(Module *M, const std::vector &F,
327 DenseMap &ValueMap);
327 ValueMap &VMap);
328328
329329 } // End llvm namespace
330330
129129 ReduceCrashingGlobalVariables::TestGlobalVariables(
130130 std::vector &GVs) {
131131 // Clone the program to try hacking it apart...
132 DenseMap ValueMap;
133 Module *M = CloneModule(BD.getProgram(), ValueMap);
132 ValueMap VMap;
133 Module *M = CloneModule(BD.getProgram(), VMap);
134134
135135 // Convert list to set for fast lookup...
136136 std::set GVSet;
137137
138138 for (unsigned i = 0, e = GVs.size(); i != e; ++i) {
139 GlobalVariable* CMGV = cast(ValueMap[GVs[i]]);
139 GlobalVariable* CMGV = cast(VMap[GVs[i]]);
140140 assert(CMGV && "Global Variable not in module?!");
141141 GVSet.insert(CMGV);
142142 }
203203 return false;
204204
205205 // Clone the program to try hacking it apart...
206 DenseMap ValueMap;
207 Module *M = CloneModule(BD.getProgram(), ValueMap);
206 ValueMap VMap;
207 Module *M = CloneModule(BD.getProgram(), VMap);
208208
209209 // Convert list to set for fast lookup...
210210 std::set Functions;
211211 for (unsigned i = 0, e = Funcs.size(); i != e; ++i) {
212 Function *CMF = cast(ValueMap[Funcs[i]]);
212 Function *CMF = cast(VMap[Funcs[i]]);
213213 assert(CMF && "Function not in module?!");
214214 assert(CMF->getFunctionType() == Funcs[i]->getFunctionType() && "wrong ty");
215215 assert(CMF->getName() == Funcs[i]->getName() && "wrong name");
269269
270270 bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) {
271271 // Clone the program to try hacking it apart...
272 DenseMap ValueMap;
273 Module *M = CloneModule(BD.getProgram(), ValueMap);
272 ValueMap VMap;
273 Module *M = CloneModule(BD.getProgram(), VMap);
274274
275275 // Convert list to set for fast lookup...
276276 SmallPtrSet Blocks;
277277 for (unsigned i = 0, e = BBs.size(); i != e; ++i)
278 Blocks.insert(cast(ValueMap[BBs[i]]));
278 Blocks.insert(cast(VMap[BBs[i]]));
279279
280280 outs() << "Checking for crash with only these blocks:";
281281 unsigned NumPrint = Blocks.size();
370370 bool ReduceCrashingInstructions::TestInsts(std::vector
371371 &Insts) {
372372 // Clone the program to try hacking it apart...
373 DenseMap ValueMap;
374 Module *M = CloneModule(BD.getProgram(), ValueMap);
373 ValueMap VMap;
374 Module *M = CloneModule(BD.getProgram(), VMap);
375375
376376 // Convert list to set for fast lookup...
377377 SmallPtrSet Instructions;
378378 for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
379379 assert(!isa(Insts[i]));
380 Instructions.insert(cast(ValueMap[Insts[i]]));
380 Instructions.insert(cast(VMap[Insts[i]]));
381381 }
382382
383383 outs() << "Checking for crash with only " << Instructions.size();
200200 /// static ctors/dtors, we need to add an llvm.global_[cd]tors global to M2, and
201201 /// prune appropriate entries out of M1s list.
202202 static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2,
203 DenseMap ValueMap) {
203 ValueMap VMap) {
204204 GlobalVariable *GV = M1->getNamedGlobal(GlobalName);
205205 if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() ||
206206 !GV->use_empty()) return;
228228 M1Tors.push_back(std::make_pair(F, Priority));
229229 else {
230230 // Map to M2's version of the function.
231 F = cast(ValueMap[F]);
231 F = cast(VMap[F]);
232232 M2Tors.push_back(std::make_pair(F, Priority));
233233 }
234234 }
263263 Module *
264264 llvm::SplitFunctionsOutOfModule(Module *M,
265265 const std::vector &F,
266 DenseMap &ValueMap) {
266 ValueMap &VMap) {
267267 // Make sure functions & globals are all external so that linkage
268268 // between the two modules will work.
269269 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
275275 I->setLinkage(GlobalValue::ExternalLinkage);
276276 }
277277
278 DenseMap NewValueMap;
279 Module *New = CloneModule(M, NewValueMap);
278 ValueMap NewVMap;
279 Module *New = CloneModule(M, NewVMap);
280280
281281 // Make sure global initializers exist only in the safe module (CBE->.so)
282282 for (Module::global_iterator I = New->global_begin(), E = New->global_end();
286286 // Remove the Test functions from the Safe module
287287 std::set TestFunctions;
288288 for (unsigned i = 0, e = F.size(); i != e; ++i) {
289 Function *TNOF = cast(ValueMap[F[i]]);
289 Function *TNOF = cast(VMap[F[i]]);
290290 DEBUG(errs() << "Removing function ");
291291 DEBUG(WriteAsOperand(errs(), TNOF, false));
292292 DEBUG(errs() << "\n");
293 TestFunctions.insert(cast(NewValueMap[TNOF]));
293 TestFunctions.insert(cast(NewVMap[TNOF]));
294294 DeleteFunctionBody(TNOF); // Function is now external in this module!
295295 }
296296
303303
304304 // Make sure that there is a global ctor/dtor array in both halves of the
305305 // module if they both have static ctor/dtor functions.
306 SplitStaticCtorDtor("llvm.global_ctors", M, New, NewValueMap);
307 SplitStaticCtorDtor("llvm.global_dtors", M, New, NewValueMap);
306 SplitStaticCtorDtor("llvm.global_ctors", M, New, NewVMap);
307 SplitStaticCtorDtor("llvm.global_dtors", M, New, NewVMap);
308308
309309 return New;
310310 }
250250 outs() << '\n';
251251
252252 // Split the module into the two halves of the program we want.
253 DenseMap ValueMap;
254 Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
253 ValueMap VMap;
254 Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
255255 Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs,
256 ValueMap);
256 VMap);
257257
258258 // Run the predicate, note that the predicate will delete both input modules.
259259 return TestFn(BD, ToOptimize, ToNotOptimize, Error);
284284 while (1) {
285285 if (BugpointIsInterrupted) return MadeChange;
286286
287 DenseMap ValueMap;
288 Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
287 ValueMap VMap;
288 Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
289289 Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
290290 MiscompiledFunctions,
291 ValueMap);
291 VMap);
292292 Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize);
293293 if (!ToOptimizeLoopExtracted) {
294294 // If the loop extractor crashed or if there were no extractible loops,
447447 outs() << '\n';
448448
449449 // Split the module into the two halves of the program we want.
450 DenseMap ValueMap;
451 Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
450 ValueMap VMap;
451 Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
452452 Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
453453 FunctionsBeingTested,
454 ValueMap);
454 VMap);
455455
456456 // Try the extraction. If it doesn't work, then the block extractor crashed
457457 // or something, in which case bugpoint can't chase down this possibility.
504504 return false;
505505 }
506506
507 DenseMap ValueMap;
508 Module *ProgClone = CloneModule(BD.getProgram(), ValueMap);
507 ValueMap VMap;
508 Module *ProgClone = CloneModule(BD.getProgram(), VMap);
509509 Module *ToExtract = SplitFunctionsOutOfModule(ProgClone,
510510 MiscompiledFunctions,
511 ValueMap);
511 VMap);
512512 Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract);
513513 if (Extracted == 0) {
514514 // Weird, extraction should have worked.
686686
687687 // Output a bunch of bitcode files for the user...
688688 outs() << "Outputting reduced bitcode files which expose the problem:\n";
689 DenseMap ValueMap;
690 Module *ToNotOptimize = CloneModule(getProgram(), ValueMap);
689 ValueMap VMap;
690 Module *ToNotOptimize = CloneModule(getProgram(), VMap);
691691 Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
692692 MiscompiledFunctions,
693 ValueMap);
693 VMap);
694694
695695 outs() << " Non-optimized portion: ";
696696 ToNotOptimize = swapProgramIn(ToNotOptimize);
959959 return true;
960960
961961 // Split the module into the two halves of the program we want.
962 DenseMap ValueMap;
963 Module *ToNotCodeGen = CloneModule(getProgram(), ValueMap);
964 Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, ValueMap);
962 ValueMap VMap;
963 Module *ToNotCodeGen = CloneModule(getProgram(), VMap);
964 Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, VMap);
965965
966966 // Condition the modules
967967 CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen);