llvm.org GIT mirror llvm / fe095f3
Restore minor deletion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70892 91177308-0d34-0410-b5e6-96231b3b80d8 Mike Stump 10 years ago
24 changed file(s) with 374 addition(s) and 228 deletion(s). Raw diff Collapse all Expand all
358358
359359 ifeq ($(ARCH),Alpha)
360360 LD.Flags += -Wl,--no-relax
361 endif
362
363 ifeq ($(OS),MingW)
364 ifeq ($(LLVM_CROSS_COMPILING),1)
365 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
366 ifdef TOOLNAME
367 LD.Flags += -Wl,--allow-multiple-definition
368 endif
369 endif
361370 endif
362371
363372 #--------------------------------------------------------------------
544544 about symbols remaining in the table on destruction.

545545

GCC 4.1.2 20071124 (Red Hat 4.1.2-42): Suffers from the same symptoms

546546 as the previous one. It appears to work with ENABLE_OPTIMIZED=0 (the default).

547

Cygwin GCC 4.3.2 20080827 (beta) 2:

548 Users reported various problems related
549 with link errors when using this GCC version.

547550
548551

GNU ld 2.16.X. Some 2.16.X versions of the ld linker will produce very

549552 long warning messages complaining that some ".gnu.linkonce.t.*" symbol was
7575 return true;
7676 }
7777
78 template
79 void insert(IterT I, IterT E) {
80 for (; I != E; ++I)
81 insert(*I);
82 }
83
7884 bool erase(const T &V) {
7985 if (!isSmall())
8086 return Set.erase(V);
169169 return ID;
170170 }
171171
172 /// RecordSourceLine - Records location information and associates it with a
173 /// label. Returns a unique label ID used to generate a label and
174 /// provide correspondence to the source line list.
175 unsigned RecordSourceLine(unsigned Line, unsigned Column, unsigned Source);
176
177172 /// InvalidateLabel - Inhibit use of the specified label # from
178173 /// MachineModuleInfo, for example because the code was deleted.
179174 void InvalidateLabel(unsigned LabelID) {
8888 BasicBlock::iterator &ScanFrom,
8989 unsigned MaxInstsToScan = 6,
9090 AliasAnalysis *AA = 0);
91
91
92 /// FindFunctionBackedges - Analyze the specified function to find all of the
93 /// loop backedges in the function and return them. This is a relatively cheap
94 /// (compared to computing dominators and loop info) analysis.
95 ///
96 /// The output is added to Result, as pairs of edge info.
97 void FindFunctionBackedges(const Function &F,
98 SmallVectorImpl > &Result);
9299
93100
94101 // RemoveSuccessor - Change the specified terminator instruction such that its
4848 switch (I->getOpcode()) {
4949 case Instruction::Call:
5050 case Instruction::Invoke: {
51 CallSite CS = CallSite::get(I);
52 // Not captured if the callee is readonly and doesn't return a copy
53 // through its return value.
54 if (CS.onlyReadsMemory() && I->getType() == Type::VoidTy)
55 break;
51 CallSite CS(I);
5652
5753 // Not captured if only passed via 'nocapture' arguments. Note that
5854 // calling a function pointer does not in itself cause the pointer to
6157 // that loading a value from a pointer does not cause the pointer to be
6258 // captured, even though the loaded value might be the pointer itself
6359 // (think of self-referential objects).
60 bool MayBeCaptured = false;
6461 CallSite::arg_iterator B = CS.arg_begin(), E = CS.arg_end();
6562 for (CallSite::arg_iterator A = B; A != E; ++A)
66 if (A->get() == V && !CS.paramHasAttr(A - B + 1, Attribute::NoCapture))
67 // The parameter is not marked 'nocapture' - captured.
68 return true;
69 // Only passed via 'nocapture' arguments, or is the called function - not
70 // captured.
63 if (A->get() == V && !CS.paramHasAttr(A-B+1, Attribute::NoCapture)) {
64 // The parameter is not marked 'nocapture' - handled by generic code
65 // below.
66 MayBeCaptured = true;
67 break;
68 }
69 if (!MayBeCaptured)
70 // Only passed via 'nocapture' arguments, or is the called function -
71 // not captured.
72 continue;
73 if (!CS.doesNotThrow())
74 // Even a readonly function can leak bits by throwing an exception or
75 // not depending on the input value.
76 return true;
77 // Fall through to the generic code.
7178 break;
7279 }
7380 case Instruction::Free:
7481 // Freeing a pointer does not cause it to be captured.
75 break;
82 continue;
7683 case Instruction::Load:
7784 // Loading from a pointer does not cause it to be captured.
78 break;
85 continue;
7986 case Instruction::Ret:
8087 if (ReturnCaptures)
8188 return true;
82 break;
89 continue;
8390 case Instruction::Store:
8491 if (V == I->getOperand(0))
8592 // Stored the pointer - it may be captured.
8693 return true;
8794 // Storing to the pointee does not cause the pointer to be captured.
88 break;
89 case Instruction::BitCast:
90 case Instruction::GetElementPtr:
91 case Instruction::PHI:
92 case Instruction::Select:
93 // The original value is not captured via this if the new value isn't.
94 for (Instruction::use_iterator UI = I->use_begin(), UE = I->use_end();
95 UI != UE; ++UI) {
96 Use *U = &UI.getUse();
97 if (Visited.insert(U))
98 Worklist.push_back(U);
99 }
100 break;
101 default:
102 // Something else - be conservative and say it is captured.
95 continue;
96 }
97
98 // If it may write to memory and isn't one of the special cases above,
99 // be conservative and assume the pointer is captured.
100 if (I->mayWriteToMemory())
103101 return true;
102
103 // If the instruction doesn't write memory, it can only capture by
104 // having its own value depend on the input value.
105 const Type* Ty = I->getType();
106 if (Ty == Type::VoidTy)
107 // The value of an instruction can't be a copy if it can't contain any
108 // information.
109 continue;
110 if (!isa(Ty))
111 // At the moment, we don't track non-pointer values, so be conservative
112 // and assume the pointer is captured.
113 // FIXME: Track these too. This would need to be done very carefully as
114 // it is easy to leak bits via control flow if integer values are allowed.
115 return true;
116
117 // The original value is not captured via this if the new value isn't.
118 for (Instruction::use_iterator UI = I->use_begin(), UE = I->use_end();
119 UI != UE; ++UI) {
120 Use *U = &UI.getUse();
121 if (Visited.insert(U))
122 Worklist.push_back(U);
104123 }
105124 }
106125
32613261 // Assumes in correct section after the entry point.
32623262 EmitLabel("func_begin", ++SubprogramCount);
32633263
3264 // Emit label for the implicitly defined dbg.stoppoint at the start of
3265 // the function.
3266 if (!Lines.empty()) {
3267 const SrcLineInfo &LineInfo = Lines[0];
3268 Asm->printLabel(LineInfo.getLabelID());
3264 DebugLoc FDL = MF->getDefaultDebugLoc();
3265 if (!FDL.isUnknown()) {
3266 DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
3267 unsigned LabelID = RecordSourceLine(DLT.Line, DLT.Col,
3268 DICompileUnit(DLT.CompileUnit));
3269 Asm->printLabel(LabelID);
32693270 }
32703271
32713272 if (TimePassesIsEnabled)
332332 unsigned Col = SPI->getColumn();
333333 unsigned Idx = MF.getOrCreateDebugLocID(CU.getGV(), Line, Col);
334334 setCurDebugLoc(DebugLoc::get(Idx));
335 if (DW && DW->ShouldEmitDwarfDebug()) {
336 unsigned ID = DW->RecordSourceLine(Line, Col, CU);
337 const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL);
338 BuildMI(MBB, DL, II).addImm(ID);
339 }
340335 }
341336 return true;
342337 }
401396 CompileUnit.getGV(), Line, 0)));
402397
403398 if (DW && DW->ShouldEmitDwarfDebug()) {
404 unsigned LabelID = DW->RecordSourceLine(Line, 0, CompileUnit);
399 unsigned LabelID = MMI->NextLabelID();
405400 const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL);
406401 BuildMI(MBB, DL, II).addImm(LabelID);
407402 DebugLocTuple PrevLocTpl = MF.getDebugLocTuple(PrevLoc);
413408 } else {
414409 // Record the source line.
415410 unsigned Line = Subprogram.getLineNumber();
416 setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(
411 MF.setDefaultDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(
417412 CompileUnit.getGV(), Line, 0)));
418413 if (DW && DW->ShouldEmitDwarfDebug()) {
419 DW->RecordSourceLine(Line, 0, CompileUnit);
420414 // llvm.dbg.func_start also defines beginning of function scope.
421415 DW->RecordRegionStart(cast(FSI->getSubprogram()));
422416 }
39793979 MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0)));
39803980
39813981 if (DW && DW->ShouldEmitDwarfDebug()) {
3982 unsigned LabelID = DW->RecordSourceLine(Line, 0, CompileUnit);
3982 unsigned LabelID = DAG.getMachineModuleInfo()->NextLabelID();
39833983 DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(),
39843984 getRoot(), LabelID));
39853985 DebugLocTuple PrevLocTpl = MF.getDebugLocTuple(PrevLoc);
39913991 } else {
39923992 // Record the source line.
39933993 unsigned Line = Subprogram.getLineNumber();
3994 setCurDebugLoc(DebugLoc::get(
3994 MF.setDefaultDebugLoc(DebugLoc::get(
39953995 MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0)));
39963996 if (DW && DW->ShouldEmitDwarfDebug()) {
3997 DW->RecordSourceLine(Line, 0, CompileUnit);
39983997 // llvm.dbg.func_start also defines beginning of function scope.
39993998 DW->RecordRegionStart(cast(FSI.getSubprogram()));
40003999 }
231231 int SS = li->getStackSlotIndex();
232232 if (!UsedColors[SS])
233233 continue;
234 // Get the largest common sub- register class of all the stack slots that
235 // are colored to this stack slot.
236 const TargetRegisterClass *RC = 0;
234
235 // These slots allow to share the same registers.
236 bool AllColored = true;
237 SmallVector ColoredRegs;
237238 for (unsigned j = 0, ee = RevMap[SS].size(); j != ee; ++j) {
238239 int RSS = RevMap[SS][j];
239 const TargetRegisterClass *RRC = LS->getIntervalRegClass(RSS);
240 if (!RC)
241 RC = RRC;
242 else
243 RC = getCommonSubClass(RC, RRC);
244 }
245
246 // If it's not colored to another stack slot, try coloring it
247 // to a "free" register.
248 if (!RC)
249 continue;
250 unsigned Reg = VRM->getFirstUnusedRegister(RC);
251 if (!Reg)
252 continue;
253 bool IsSafe = true;
254 for (unsigned j = 0, ee = RevMap[SS].size(); j != ee; ++j) {
255 int RSS = RevMap[SS][j];
240 const TargetRegisterClass *RC = LS->getIntervalRegClass(RSS);
241 // If it's not colored to another stack slot, try coloring it
242 // to a "free" register.
243 if (!RC) {
244 AllColored = false;
245 continue;
246 }
247 unsigned Reg = VRM->getFirstUnusedRegister(RC);
248 if (!Reg) {
249 AllColored = false;
250 continue;
251 }
256252 if (!AllMemRefsCanBeUnfolded(RSS)) {
257 IsSafe = false;
258 break;
253 AllColored = false;
254 continue;
255 } else {
256 DOUT << "Assigning fi#" << RSS << " to " << TRI->getName(Reg) << '\n';
257 ColoredRegs.push_back(Reg);
258 SlotMapping[RSS] = Reg;
259 SlotIsReg.set(RSS);
260 Changed = true;
259261 }
260262 }
261 if (!IsSafe)
262 // Try color the next spill slot.
263 continue;
264
265 DOUT << "Assigning fi#" << SS << " to " << TRI->getName(Reg)
266 << ", which in turn means...\n";
263
267264 // Register and its sub-registers are no longer free.
268 VRM->setRegisterUsed(Reg);
269 // If reg is a callee-saved register, it will have to be spilled in
270 // the prologue.
271 MRI->setPhysRegUsed(Reg);
272 for (const unsigned *AS = TRI->getAliasSet(Reg); *AS; ++AS) {
273 VRM->setRegisterUsed(*AS);
274 MRI->setPhysRegUsed(*AS);
265 while (!ColoredRegs.empty()) {
266 unsigned Reg = ColoredRegs.back();
267 ColoredRegs.pop_back();
268 VRM->setRegisterUsed(Reg);
269 // If reg is a callee-saved register, it will have to be spilled in
270 // the prologue.
271 MRI->setPhysRegUsed(Reg);
272 for (const unsigned *AS = TRI->getAliasSet(Reg); *AS; ++AS) {
273 VRM->setRegisterUsed(*AS);
274 MRI->setPhysRegUsed(*AS);
275 }
275276 }
276277 // This spill slot is dead after the rewrites
277 MFI->RemoveStackObject(SS);
278
279 // Remember all these FI references will have to be unfolded.
280 for (unsigned j = 0, ee = RevMap[SS].size(); j != ee; ++j) {
281 int RSS = RevMap[SS][j];
282 DOUT << " Assigning fi#" << RSS << " to " << TRI->getName(Reg) << '\n';
283 SlotMapping[RSS] = Reg;
284 SlotIsReg.set(RSS);
285 }
286
287 ++NumEliminated;
288 Changed = true;
278 if (AllColored) {
279 MFI->RemoveStackObject(SS);
280 ++NumEliminated;
281 }
289282 }
290283 DOUT << '\n';
291284
2525 #include "llvm/CodeGen/MachineRegisterInfo.h"
2626 #include "llvm/Target/TargetMachine.h"
2727 #include "llvm/Target/TargetInstrInfo.h"
28 #include "llvm/Target/TargetRegisterInfo.h"
2829 #include "llvm/Support/CommandLine.h"
2930 #include "llvm/Support/Compiler.h"
3031 #include "llvm/Support/Debug.h"
5051
5152 bool VirtRegMap::runOnMachineFunction(MachineFunction &mf) {
5253 TII = mf.getTarget().getInstrInfo();
54 TRI = mf.getTarget().getRegisterInfo();
5355 MF = &mf;
5456
5557 ReMatId = MAX_STACK_SLOT+1;
7274 SpillSlotToUsesMap.resize(8);
7375 ImplicitDefed.resize(MF->getRegInfo().getLastVirtReg()+1-
7476 TargetRegisterInfo::FirstVirtualRegister);
77
78 allocatableRCRegs.clear();
79 for (TargetRegisterInfo::regclass_iterator I = TRI->regclass_begin(),
80 E = TRI->regclass_end(); I != E; ++I)
81 allocatableRCRegs.insert(std::make_pair(*I,
82 TRI->getAllocatableSet(mf, *I)));
83
7584 grow();
7685
7786 return false;
3131 class MachineInstr;
3232 class MachineFunction;
3333 class TargetInstrInfo;
34 class TargetRegisterInfo;
3435
3536 class VirtRegMap : public MachineFunctionPass {
3637 public:
4647
4748 private:
4849 const TargetInstrInfo *TII;
49
50 const TargetRegisterInfo *TRI;
5051 MachineFunction *MF;
52
53 DenseMap allocatableRCRegs;
54
5155 /// Virt2PhysMap - This is a virtual to physical register
5256 /// mapping. Each virtual register is required to have an entry in
5357 /// it; even spilled virtual registers (the register mapped to a
465469 unsigned getFirstUnusedRegister(const TargetRegisterClass *RC) {
466470 int Reg = UnusedRegs.find_first();
467471 while (Reg != -1) {
468 if (RC->contains(Reg))
472 if (allocatableRCRegs[RC][Reg])
469473 return (unsigned)Reg;
470474 Reg = UnusedRegs.find_next(Reg);
471475 }
2727 #include "llvm/Target/TargetLowering.h"
2828 #include "llvm/Support/Compiler.h"
2929 #include "llvm/Support/Debug.h"
30 #include
31 #include
3230 using namespace llvm;
3331
3432 /// MSP430DAGToDAGISel - MSP430 specific code to select MSP430 machine
5151
5252 /// BackEdges - Keep a set of all the loop back edges.
5353 ///
54 SmallSetBasicBlock*,BasicBlock*>, 8> BackEdges;
54 SmallSetconst BasicBlock*, const BasicBlock*>, 8> BackEdges;
5555 public:
5656 static char ID; // Pass identification, replacement for typeid
5757 explicit CodeGenPrepare(const TargetLowering *tli = 0)
6868 bool OptimizeInlineAsmInst(Instruction *I, CallSite CS,
6969 DenseMap &SunkAddrs);
7070 bool OptimizeExtUses(Instruction *I);
71 void findLoopBackEdges(Function &F);
71 void findLoopBackEdges(const Function &F);
7272 };
7373 }
7474
8282
8383 /// findLoopBackEdges - Do a DFS walk to find loop back edges.
8484 ///
85 void CodeGenPrepare::findLoopBackEdges(Function &F) {
86 SmallPtrSet Visited;
87 SmallVector, 8> VisitStack;
88 SmallPtrSet InStack;
89
90 BasicBlock *BB = &F.getEntryBlock();
91 if (succ_begin(BB) == succ_end(BB))
92 return;
93 Visited.insert(BB);
94 VisitStack.push_back(std::make_pair(BB, succ_begin(BB)));
95 InStack.insert(BB);
96 do {
97 std::pair &Top = VisitStack.back();
98 BasicBlock *ParentBB = Top.first;
99 succ_iterator &I = Top.second;
100
101 bool FoundNew = false;
102 while (I != succ_end(ParentBB)) {
103 BB = *I++;
104 if (Visited.insert(BB)) {
105 FoundNew = true;
106 break;
107 }
108 // Successor is in VisitStack, it's a back edge.
109 if (InStack.count(BB))
110 BackEdges.insert(std::make_pair(ParentBB, BB));
111 }
112
113 if (FoundNew) {
114 // Go down one level if there is a unvisited successor.
115 InStack.insert(BB);
116 VisitStack.push_back(std::make_pair(BB, succ_begin(BB)));
117 } else {
118 // Go up one level.
119 std::pair &Pop = VisitStack.back();
120 InStack.erase(Pop.first);
121 VisitStack.pop_back();
122 }
123 } while (!VisitStack.empty());
85 void CodeGenPrepare::findLoopBackEdges(const Function &F) {
86 SmallVector, 32> Edges;
87 FindFunctionBackedges(F, Edges);
88
89 BackEdges.insert(Edges.begin(), Edges.end());
12490 }
12591
12692
327293 /// predecessor of the succ that is empty (and thus has no phi nodes), use it
328294 /// instead of introducing a new block.
329295 static void SplitEdgeNicely(TerminatorInst *TI, unsigned SuccNum,
330 SmallSetBasicBlock*,BasicBlock*>, 8> &BackEdges,
296 SmallSetconst BasicBlock*,
297 const BasicBlock*>, 8> &BackEdges,
331298 Pass *P) {
332299 BasicBlock *TIBB = TI->getParent();
333300 BasicBlock *Dest = TI->getSuccessor(SuccNum);
1414 #include "llvm/Transforms/Scalar.h"
1515 #include "llvm/IntrinsicInst.h"
1616 #include "llvm/Pass.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/Statistic.h"
19 #include "llvm/ADT/STLExtras.h"
2017 #include "llvm/Analysis/ConstantFolding.h"
2118 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
2219 #include "llvm/Transforms/Utils/Local.h"
2320 #include "llvm/Target/TargetData.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/Statistic.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/SmallPtrSet.h"
25 #include "llvm/ADT/SmallSet.h"
2426 #include "llvm/Support/CommandLine.h"
2527 #include "llvm/Support/Compiler.h"
2628 #include "llvm/Support/Debug.h"
27 #include "llvm/ADT/SmallPtrSet.h"
29 #include "llvm/Support/ValueHandle.h"
2830 using namespace llvm;
2931
3032 STATISTIC(NumThreads, "Number of jumps threaded");
5456 ///
5557 class VISIBILITY_HIDDEN JumpThreading : public FunctionPass {
5658 TargetData *TD;
59 #ifdef NDEBUG
60 SmallPtrSet LoopHeaders;
61 #else
62 SmallSet, 16> LoopHeaders;
63 #endif
5764 public:
5865 static char ID; // Pass identification
5966 JumpThreading() : FunctionPass(&ID) {}
6370 }
6471
6572 bool runOnFunction(Function &F);
73 void FindLoopHeaders(Function &F);
74
6675 bool ProcessBlock(BasicBlock *BB);
67 void ThreadEdge(BasicBlock *BB, BasicBlock *PredBB, BasicBlock *SuccBB);
76 bool ThreadEdge(BasicBlock *BB, BasicBlock *PredBB, BasicBlock *SuccBB,
77 unsigned JumpThreadCost);
6878 BasicBlock *FactorCommonPHIPreds(PHINode *PN, Constant *CstVal);
6979 bool ProcessBranchOnDuplicateCond(BasicBlock *PredBB, BasicBlock *DestBB);
7080 bool ProcessSwitchOnDuplicateCond(BasicBlock *PredBB, BasicBlock *DestBB);
8999 bool JumpThreading::runOnFunction(Function &F) {
90100 DOUT << "Jump threading on function '" << F.getNameStart() << "'\n";
91101 TD = &getAnalysis();
102
103 FindLoopHeaders(F);
92104
93105 bool AnotherIteration = true, EverChanged = false;
94106 while (AnotherIteration) {
107119 BB != &BB->getParent()->getEntryBlock()) {
108120 DOUT << " JT: Deleting dead block '" << BB->getNameStart()
109121 << "' with terminator: " << *BB->getTerminator();
122 LoopHeaders.erase(BB);
110123 DeleteDeadBlock(BB);
111124 Changed = true;
112125 }
114127 AnotherIteration = Changed;
115128 EverChanged |= Changed;
116129 }
130
131 LoopHeaders.clear();
117132 return EverChanged;
118133 }
134
135 /// FindLoopHeaders - We do not want jump threading to turn proper loop
136 /// structures into irreducible loops. Doing this breaks up the loop nesting
137 /// hierarchy and pessimizes later transformations. To prevent this from
138 /// happening, we first have to find the loop headers. Here we approximate this
139 /// by finding targets of backedges in the CFG.
140 ///
141 /// Note that there definitely are cases when we want to allow threading of
142 /// edges across a loop header. For example, threading a jump from outside the
143 /// loop (the preheader) to an exit block of the loop is definitely profitable.
144 /// It is also almost always profitable to thread backedges from within the loop
145 /// to exit blocks, and is often profitable to thread backedges to other blocks
146 /// within the loop (forming a nested loop). This simple analysis is not rich
147 /// enough to track all of these properties and keep it up-to-date as the CFG
148 /// mutates, so we don't allow any of these transformations.
149 ///
150 void JumpThreading::FindLoopHeaders(Function &F) {
151 SmallVector, 32> Edges;
152 FindFunctionBackedges(F, Edges);
153
154 for (unsigned i = 0, e = Edges.size(); i != e; ++i)
155 LoopHeaders.insert(const_cast(Edges[i].second));
156 }
157
119158
120159 /// FactorCommonPHIPreds - If there are multiple preds with the same incoming
121160 /// value for the PHI, factor them together so we get one block to thread for
190229 if (BasicBlock *SinglePred = BB->getSinglePredecessor())
191230 if (SinglePred->getTerminator()->getNumSuccessors() == 1 &&
192231 SinglePred != BB) {
232 // If SinglePred was a loop header, BB becomes one.
233 if (LoopHeaders.erase(SinglePred))
234 LoopHeaders.insert(BB);
235
193236 // Remember if SinglePred was the entry block of the function. If so, we
194237 // will need to move BB back to the entry position.
195238 bool isEntry = SinglePred == &SinglePred->getParent()->getEntryBlock();
388431 // Next, figure out which successor we are threading to.
389432 BasicBlock *SuccBB = DestBI->getSuccessor(!BranchDir);
390433
391 // If threading to the same block as we come from, we would infinite loop.
392 if (SuccBB == BB) {
393 DOUT << " Not threading BB '" << BB->getNameStart()
394 << "' - would thread to self!\n";
395 return false;
396 }
397
398 // And finally, do it!
399 DOUT << " Threading edge from '" << PredBB->getNameStart() << "' to '"
400 << SuccBB->getNameStart() << "' with cost: " << JumpThreadCost
401 << ", across block:\n "
402 << *BB << "\n";
403
404 ThreadEdge(BB, PredBB, SuccBB);
405 ++NumThreads;
406 return true;
434 // Ok, try to thread it!
435 return ThreadEdge(BB, PredBB, SuccBB, JumpThreadCost);
407436 }
408437
409438 /// ProcessSwitchOnDuplicateCond - We found a block and a predecessor of that
674703 SuccBB = SI->getSuccessor(SI->findCaseValue(PredCst));
675704 }
676705
677 // If threading to the same block as we come from, we would infinite loop.
678 if (SuccBB == BB) {
679 DOUT << " Not threading BB '" << BB->getNameStart()
680 << "' - would thread to self!\n";
681 return false;
682 }
683
684 // And finally, do it!
685 DOUT << " Threading edge from '" << PredBB->getNameStart() << "' to '"
686 << SuccBB->getNameStart() << "' with cost: " << JumpThreadCost
687 << ", across block:\n "
688 << *BB << "\n";
689
690 ThreadEdge(BB, PredBB, SuccBB);
691 ++NumThreads;
692 return true;
706 // Ok, try to thread it!
707 return ThreadEdge(BB, PredBB, SuccBB, JumpThreadCost);
693708 }
694709
695710 /// ProcessJumpOnLogicalPHI - PN's basic block contains a conditional branch
750765 // 'true' block.
751766 BasicBlock *SuccBB = BB->getTerminator()->getSuccessor(isAnd);
752767
753 // If threading to the same block as we come from, we would infinite loop.
754 if (SuccBB == BB) {
755 DOUT << " Not threading BB '" << BB->getNameStart()
756 << "' - would thread to self!\n";
757 return false;
758 }
759
760 // And finally, do it!
761 DOUT << " Threading edge through bool from '" << PredBB->getNameStart()
762 << "' to '" << SuccBB->getNameStart() << "' with cost: "
763 << JumpThreadCost << ", across block:\n "
764 << *BB << "\n";
765
766 ThreadEdge(BB, PredBB, SuccBB);
767 ++NumThreads;
768 return true;
768 // Ok, try to thread it!
769 return ThreadEdge(BB, PredBB, SuccBB, JumpThreadCost);
769770 }
770771
771772 /// ProcessBranchOnCompare - We found a branch on a comparison between a phi
828829 // Next, get our successor.
829830 BasicBlock *SuccBB = BB->getTerminator()->getSuccessor(!TrueDirection);
830831
831 // If threading to the same block as we come from, we would infinite loop.
832 if (SuccBB == BB) {
833 DOUT << " Not threading BB '" << BB->getNameStart()
834 << "' - would thread to self!\n";
835 return false;
836 }
837
838
839 // And finally, do it!
840 DOUT << " Threading edge through bool from '" << PredBB->getNameStart()
841 << "' to '" << SuccBB->getNameStart() << "' with cost: "
842 << JumpThreadCost << ", across block:\n "
843 << *BB << "\n";
844
845 ThreadEdge(BB, PredBB, SuccBB);
846 ++NumThreads;
847 return true;
832 // Ok, try to thread it!
833 return ThreadEdge(BB, PredBB, SuccBB, JumpThreadCost);
848834 }
849835
850836
851837 /// ThreadEdge - We have decided that it is safe and profitable to thread an
852838 /// edge from PredBB to SuccBB across BB. Transform the IR to reflect this
853839 /// change.
854 void JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB,
855 BasicBlock *SuccBB) {
856
840 bool JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB,
841 BasicBlock *SuccBB, unsigned JumpThreadCost) {
842
843 // If threading to the same block as we come from, we would infinite loop.
844 if (SuccBB == BB) {
845 DOUT << " Not threading across BB '" << BB->getNameStart()
846 << "' - would thread to self!\n";
847 return false;
848 }
849
850 // If threading this would thread across a loop header, don't thread the edge.
851 // See the comments above FindLoopHeaders for justifications and caveats.
852 if (LoopHeaders.count(BB)) {
853 DOUT << " Not threading from '" << PredBB->getNameStart()
854 << "' across loop header BB '" << BB->getNameStart()
855 << "' to dest BB '" << SuccBB->getNameStart()
856 << "' - it might create an irreducible loop!\n";
857 return false;
858 }
859
860 // And finally, do it!
861 DOUT << " Threading edge from '" << PredBB->getNameStart() << "' to '"
862 << SuccBB->getNameStart() << "' with cost: " << JumpThreadCost
863 << ", across block:\n "
864 << *BB << "\n";
865
857866 // Jump Threading can not update SSA properties correctly if the values
858867 // defined in the duplicated block are used outside of the block itself. For
859868 // this reason, we spill all values that are used outside of BB to the stack.
937946
938947 RecursivelyDeleteTriviallyDeadInstructions(Inst);
939948 }
940 }
949
950 // Threaded an edge!
951 ++NumThreads;
952 return true;
953 }
440440
441441 return NewBB;
442442 }
443
444 /// FindFunctionBackedges - Analyze the specified function to find all of the
445 /// loop backedges in the function and return them. This is a relatively cheap
446 /// (compared to computing dominators and loop info) analysis.
447 ///
448 /// The output is added to Result, as pairs of edge info.
449 void llvm::FindFunctionBackedges(const Function &F,
450 SmallVectorImpl > &Result) {
451 const BasicBlock *BB = &F.getEntryBlock();
452 if (succ_begin(BB) == succ_end(BB))
453 return;
454
455 SmallPtrSet Visited;
456 SmallVector, 8> VisitStack;
457 SmallPtrSet InStack;
458
459 Visited.insert(BB);
460 VisitStack.push_back(std::make_pair(BB, succ_begin(BB)));
461 InStack.insert(BB);
462 do {
463 std::pair &Top = VisitStack.back();
464 const BasicBlock *ParentBB = Top.first;
465 succ_const_iterator &I = Top.second;
466
467 bool FoundNew = false;
468 while (I != succ_end(ParentBB)) {
469 BB = *I++;
470 if (Visited.insert(BB)) {
471 FoundNew = true;
472 break;
473 }
474 // Successor is in VisitStack, it's a back edge.
475 if (InStack.count(BB))
476 Result.push_back(std::make_pair(ParentBB, BB));
477 }
478
479 if (FoundNew) {
480 // Go down one level if there is a unvisited successor.
481 InStack.insert(BB);
482 VisitStack.push_back(std::make_pair(BB, succ_begin(BB)));
483 } else {
484 // Go up one level.
485 InStack.erase(VisitStack.pop_back_val().first);
486 }
487 } while (!VisitStack.empty());
488
489
490 }
491
492
443493
444494 /// AreEquivalentAddressValues - Test if A and B will obviously have the same
445495 /// value. This includes recognizing that %t0 and %t1 will have the same
405405 typedef DenseMap ValueHandlesTy;
406406 static ManagedStatic ValueHandles;
407407
408 /// AddToUseList - Add this ValueHandle to the use list for VP, where List is
409 /// known to point into the existing use list.
408 /// AddToExistingUseList - Add this ValueHandle to the use list for VP, where
409 /// List is known to point into the existing use list.
410410 void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
411411 assert(List && "Handle list is null?");
412412
442442 ValueHandleBase *&Entry = Handles[VP];
443443 assert(Entry == 0 && "Value really did already have handles?");
444444 AddToExistingUseList(&Entry);
445 VP->HasValueHandle = 1;
445 VP->HasValueHandle = true;
446446
447447 // If reallocation didn't happen or if this was the first insertion, don't
448448 // walk the table.
None ; RUN: llvm-as < %s | llc | grep "m.h" | count 1
0 ; RUN: llvm-as < %s | llc | grep "\\"m.h\\"" | count 1
11 target triple = "i386-apple-darwin9.6"
22 %llvm.dbg.anchor.type = type { i32, i32 }
33 %llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32 }
0 // RUN: %llvmgcc -S -m32 -mregparm=3 %s -emit-llvm -o - | grep {inreg %action}
1 // XTARGET: x86
2 // PR3967
3
4 enum kobject_action {
5 KOBJ_ADD,
6 KOBJ_REMOVE,
7 KOBJ_CHANGE,
8 KOBJ_MOVE,
9 KOBJ_ONLINE,
10 KOBJ_OFFLINE,
11 KOBJ_MAX
12 };
13
14 struct kobject;
15
16 int kobject_uevent(struct kobject *kobj, enum kobject_action action) {}
0 // RUN: %llvmgxx -S -emit-llvm %s -o - | grep nounwind | count 4
1 int c(void) __attribute__((const));
2 int p(void) __attribute__((pure));
3 int t(void);
4
5 int f(void) {
6 return c() + p() + t();
7 }
3838 ret i1 %val
3939 }
4040
41 declare void @throw_if_bit_set(i8*, i8) readonly
42 define i1 @c6(i8* %q, i8 %bit) {
43 invoke void @throw_if_bit_set(i8* %q, i8 %bit)
44 to label %ret0 unwind label %ret1
45 ret0:
46 ret i1 0
47 ret1:
48 ret i1 1
49 }
50
4151 define i32 @nc1(i32* %q, i32* %p, i1 %b) {
4252 e:
4353 br label %l
6272 ret void
6373 }
6474
65 declare void @external(i8*) readonly
75 declare void @external(i8*) readonly nounwind
6676 define void @nc4(i8* %p) {
6777 call void @external(i8* %p)
6878 ret void
6979 }
7080
71 define void @nc5(void (i8*)* %f, i8* %p) {
72 call void %f(i8* %p) readonly
73 call void %f(i8* nocapture %p)
81 define void @nc5(void (i8*)* %p, i8* %r) {
82 call void %p(i8* %r)
83 call void %p(i8* nocapture %r)
7484 ret void
7585 }
86
87 declare i8* @external_identity(i8*) readonly nounwind
88 define void @nc6(i8* %p) {
89 call i8* @external_identity(i8* %p)
90 ret void
91 }
0 ; RUN: llvm-as < %s | opt -jump-threading -loop-rotate -instcombine -indvars -loop-unroll -simplifycfg | llvm-dis > %t
1 ; RUN: grep {volatile store} %t | count 3
2 ; RUN: not grep {br label} %t
3
4 ; Jump threading should not prevent this loop from being unrolled.
5
6 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
7 target triple = "i386-apple-darwin9.6"
8 @v1 = external global i32 ; [#uses=2]
9
10 define i32 @unroll() nounwind {
11 entry:
12 br label %bb4
13
14 bb: ; preds = %bb4
15 %0 = icmp eq i32 %i.0, 0 ; [#uses=1]
16 br i1 %0, label %bb1, label %bb2
17
18 bb1: ; preds = %bb
19 volatile store i32 1000, i32* @v1, align 4
20 br label %bb3
21
22 bb2: ; preds = %bb
23 volatile store i32 1001, i32* @v1, align 4
24 br label %bb3
25
26 bb3: ; preds = %bb2, %bb1
27 %1 = add i32 %i.0, 1 ; [#uses=1]
28 br label %bb4
29
30 bb4: ; preds = %bb3, %entry
31 %i.0 = phi i32 [ 0, %entry ], [ %1, %bb3 ] ; [#uses=3]
32 %2 = icmp sgt i32 %i.0, 2 ; [#uses=1]
33 br i1 %2, label %bb5, label %bb
34
35 bb5: ; preds = %bb4
36 ret i32 0
37 }
649649 O << "\";\n\n";
650650
651651 O << " if (TAI->doesSupportDebugInformation() &&\n"
652 << " DW->ShouldEmitDwarfDebug() && OptLevel != CodeGenOpt::None) {\n"
652 << " DW->ShouldEmitDwarfDebug()) {\n"
653653 << " DebugLoc CurDL = MI->getDebugLoc();\n\n"
654654 << " if (!CurDL.isUnknown()) {\n"
655655 << " static DebugLocTuple PrevDLT(0, ~0U, ~0U);\n"
656656 << " DebugLocTuple CurDLT = MF->getDebugLocTuple(CurDL);\n\n"
657 << " if (PrevDLT.CompileUnit != 0 && PrevDLT != CurDLT)\n"
657 << " if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT)\n"
658658 << " printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,\n"
659659 << " DICompileUnit(CurDLT.CompileUnit)));\n\n"
660660 << " PrevDLT = CurDLT;\n"
21012101
21022102 OS << "// Include standard, target-independent definitions and methods used\n"
21032103 << "// by the instruction selector.\n";
2104 OS << "#include \n\n";
2104 OS << "#include \"llvm/CodeGen/DAGISelHeader.h\"\n\n";
21052105
21062106 EmitNodeTransforms(OS);
21072107 EmitPredicateFunctions(OS);