llvm.org GIT mirror llvm / 0818e78
Rename DEBUG macro to LLVM_DEBUG. The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM - Manual change to APInt - Manually chage DOCS as regex doesn't match it. In the transition period the DEBUG() macro is still present and aliased to the LLVM_DEBUG() one. Differential Revision: https://reviews.llvm.org/D43624 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332240 91177308-0d34-0410-b5e6-96231b3b80d8 Nicola Zaghen 1 year, 5 months ago
502 changed file(s) with 9426 addition(s) and 8913 deletion(s). Raw diff Collapse all Expand all
197197
198198 static int calledCount = 0;
199199 calledCount++;
200 DEBUG(if (calledCount < 212) return false);
201 DEBUG(if (calledCount > 217) return false);
202 DEBUG(if (calledCount == 213) return false);
203 DEBUG(if (calledCount == 214) return false);
204 DEBUG(if (calledCount == 215) return false);
205 DEBUG(if (calledCount == 216) return false);
206 DEBUG(dbgs() << "visitXOR calledCount: " << calledCount << "\n");
207 DEBUG(dbgs() << "I: "; I->dump());
200 LLVM_DEBUG(if (calledCount < 212) return false);
201 LLVM_DEBUG(if (calledCount > 217) return false);
202 LLVM_DEBUG(if (calledCount == 213) return false);
203 LLVM_DEBUG(if (calledCount == 214) return false);
204 LLVM_DEBUG(if (calledCount == 215) return false);
205 LLVM_DEBUG(if (calledCount == 216) return false);
206 LLVM_DEBUG(dbgs() << "visitXOR calledCount: " << calledCount << "\n");
207 LLVM_DEBUG(dbgs() << "I: "; I->dump());
208208
209209 could be added to ``visitXOR`` to limit ``visitXor`` to being applied only to
210210 calls 212 and 217. This is from an actual test case and raises an important
9595 .. option:: -debug
9696
9797 If this is a debug build, this option will enable debug printouts from passes
98 which use the ``DEBUG()`` macro. See the `LLVM Programmer's Manual
98 which use the ``LLVM_DEBUG()`` macro. See the `LLVM Programmer's Manual
9999 <../ProgrammersManual.html>`_, section ``#DEBUG`` for more information.
100100
101101 .. option:: -load=
885885 // debug build, then the code specified as the option to the macro will be
886886 // executed. Otherwise it will not be.
887887 #ifdef NDEBUG
888 #define DEBUG(X)
888 #define LLVM_DEBUG(X)
889889 #else
890 #define DEBUG(X) do { if (DebugFlag) { X; } } while (0)
890 #define LLVM_DEBUG(X) do { if (DebugFlag) { X; } } while (0)
891891 #endif
892892
893 This allows clients to blissfully use the ``DEBUG()`` macro, or the
893 This allows clients to blissfully use the ``LLVM_DEBUG()`` macro, or the
894894 ``DebugFlag`` explicitly if they want to. Now we just need to be able to set
895895 the ``DebugFlag`` boolean when the option is set. To do this, we pass an
896896 additional argument to our command line argument processor, and we specify where
10191019
10201020 .. _DEBUG:
10211021
1022 The ``DEBUG()`` macro and ``-debug`` option
1022 The ``LLVM_DEBUG()`` macro and ``-debug`` option
10231023 -------------------------------------------
10241024
10251025 Often when working on your pass you will put a bunch of debugging printouts and
10321032
10331033 The ``llvm/Support/Debug.h`` (`doxygen
10341034 `__) file provides a macro named
1035 ``DEBUG()`` that is a much nicer solution to this problem. Basically, you can
1036 put arbitrary code into the argument of the ``DEBUG`` macro, and it is only
1035 ``LLVM_DEBUG()`` that is a much nicer solution to this problem. Basically, you can
1036 put arbitrary code into the argument of the ``LLVM_DEBUG`` macro, and it is only
10371037 executed if '``opt``' (or any other tool) is run with the '``-debug``' command
10381038 line argument:
10391039
10401040 .. code-block:: c++
10411041
1042 DEBUG(dbgs() << "I am here!\n");
1042 LLVM_DEBUG(dbgs() << "I am here!\n");
10431043
10441044 Then you can run your pass like this:
10451045
10501050 $ opt < a.bc > /dev/null -mypass -debug
10511051 I am here!
10521052
1053 Using the ``DEBUG()`` macro instead of a home-brewed solution allows you to not
1053 Using the ``LLVM_DEBUG()`` macro instead of a home-brewed solution allows you to not
10541054 have to create "yet another" command line option for the debug output for your
1055 pass. Note that ``DEBUG()`` macros are disabled for non-asserts builds, so they
1055 pass. Note that ``LLVM_DEBUG()`` macros are disabled for non-asserts builds, so they
10561056 do not cause a performance impact at all (for the same reason, they should also
10571057 not contain side-effects!).
10581058
1059 One additional nice thing about the ``DEBUG()`` macro is that you can enable or
1059 One additional nice thing about the ``LLVM_DEBUG()`` macro is that you can enable or
10601060 disable it directly in gdb. Just use "``set DebugFlag=0``" or "``set
10611061 DebugFlag=1``" from the gdb if the program is running. If the program hasn't
10621062 been started yet, you can always just run it with ``-debug``.
10751075 .. code-block:: c++
10761076
10771077 #define DEBUG_TYPE "foo"
1078 DEBUG(dbgs() << "'foo' debug type\n");
1078 LLVM_DEBUG(dbgs() << "'foo' debug type\n");
10791079 #undef DEBUG_TYPE
10801080 #define DEBUG_TYPE "bar"
1081 DEBUG(dbgs() << "'bar' debug type\n");
1081 LLVM_DEBUG(dbgs() << "'bar' debug type\n");
10821082 #undef DEBUG_TYPE
10831083
10841084 Then you can run your pass like this:
10291029 Nodes.clear();
10301030
10311031 // Initialize.
1032 DEBUG(dbgs() << "\nblock-frequency: " << F.getName() << "\n================="
1033 << std::string(F.getName().size(), '=') << "\n");
1032 LLVM_DEBUG(dbgs() << "\nblock-frequency: " << F.getName()
1033 << "\n================="
1034 << std::string(F.getName().size(), '=') << "\n");
10341035 initializeRPOT();
10351036 initializeLoops();
10361037
10661067 assert(RPOT.size() - 1 <= BlockNode::getMaxIndex() &&
10671068 "More nodes in function than Block Frequency Info supports");
10681069
1069 DEBUG(dbgs() << "reverse-post-order-traversal\n");
1070 LLVM_DEBUG(dbgs() << "reverse-post-order-traversal\n");
10701071 for (rpot_iterator I = rpot_begin(), E = rpot_end(); I != E; ++I) {
10711072 BlockNode Node = getNode(I);
1072 DEBUG(dbgs() << " - " << getIndex(I) << ": " << getBlockName(Node) << "\n");
1073 LLVM_DEBUG(dbgs() << " - " << getIndex(I) << ": " << getBlockName(Node)
1074 << "\n");
10731075 Nodes[*I] = Node;
10741076 }
10751077
10801082 }
10811083
10821084 template void BlockFrequencyInfoImpl::initializeLoops() {
1083 DEBUG(dbgs() << "loop-detection\n");
1085 LLVM_DEBUG(dbgs() << "loop-detection\n");
10841086 if (LI->empty())
10851087 return;
10861088
10981100
10991101 Loops.emplace_back(Parent, Header);
11001102 Working[Header.Index].Loop = &Loops.back();
1101 DEBUG(dbgs() << " - loop = " << getBlockName(Header) << "\n");
1103 LLVM_DEBUG(dbgs() << " - loop = " << getBlockName(Header) << "\n");
11021104
11031105 for (const LoopT *L : *Loop)
11041106 Q.emplace_back(L, &Loops.back());
11271129
11281130 Working[Index].Loop = HeaderData.Loop;
11291131 HeaderData.Loop->Nodes.push_back(Index);
1130 DEBUG(dbgs() << " - loop = " << getBlockName(Header)
1131 << ": member = " << getBlockName(Index) << "\n");
1132 LLVM_DEBUG(dbgs() << " - loop = " << getBlockName(Header)
1133 << ": member = " << getBlockName(Index) << "\n");
11321134 }
11331135 }
11341136
11491151 template
11501152 bool BlockFrequencyInfoImpl::computeMassInLoop(LoopData &Loop) {
11511153 // Compute mass in loop.
1152 DEBUG(dbgs() << "compute-mass-in-loop: " << getLoopName(Loop) << "\n");
1154 LLVM_DEBUG(dbgs() << "compute-mass-in-loop: " << getLoopName(Loop) << "\n");
11531155
11541156 if (Loop.isIrreducible()) {
1155 DEBUG(dbgs() << "isIrreducible = true\n");
1157 LLVM_DEBUG(dbgs() << "isIrreducible = true\n");
11561158 Distribution Dist;
11571159 unsigned NumHeadersWithWeight = 0;
11581160 Optional MinHeaderWeight;
11641166 IsIrrLoopHeader.set(Loop.Nodes[H].Index);
11651167 Optional HeaderWeight = Block->getIrrLoopHeaderWeight();
11661168 if (!HeaderWeight) {
1167 DEBUG(dbgs() << "Missing irr loop header metadata on "
1168 << getBlockName(HeaderNode) << "\n");
1169 LLVM_DEBUG(dbgs() << "Missing irr loop header metadata on "
1170 << getBlockName(HeaderNode) << "\n");
11691171 HeadersWithoutWeight.insert(H);
11701172 continue;
11711173 }
1172 DEBUG(dbgs() << getBlockName(HeaderNode)
1173 << " has irr loop header weight " << HeaderWeight.getValue()
1174 << "\n");
1174 LLVM_DEBUG(dbgs() << getBlockName(HeaderNode)
1175 << " has irr loop header weight "
1176 << HeaderWeight.getValue() << "\n");
11751177 NumHeadersWithWeight++;
11761178 uint64_t HeaderWeightValue = HeaderWeight.getValue();
11771179 if (!MinHeaderWeight || HeaderWeightValue < MinHeaderWeight)
11931195 assert(!getBlock(HeaderNode)->getIrrLoopHeaderWeight() &&
11941196 "Shouldn't have a weight metadata");
11951197 uint64_t MinWeight = MinHeaderWeight.getValue();
1196 DEBUG(dbgs() << "Giving weight " << MinWeight
1197 << " to " << getBlockName(HeaderNode) << "\n");
1198 LLVM_DEBUG(dbgs() << "Giving weight " << MinWeight << " to "
1199 << getBlockName(HeaderNode) << "\n");
11981200 if (MinWeight)
11991201 Dist.addLocal(HeaderNode, MinWeight);
12001202 }
12231225 template
12241226 bool BlockFrequencyInfoImpl::tryToComputeMassInFunction() {
12251227 // Compute mass in function.
1226 DEBUG(dbgs() << "compute-mass-in-function\n");
1228 LLVM_DEBUG(dbgs() << "compute-mass-in-function\n");
12271229 assert(!Working.empty() && "no blocks in function");
12281230 assert(!Working[0].isLoopHeader() && "entry block is a loop header");
12291231
12751277 template
12761278 void BlockFrequencyInfoImpl::computeIrreducibleMass(
12771279 LoopData *OuterLoop, std::list::iterator Insert) {
1278 DEBUG(dbgs() << "analyze-irreducible-in-";
1279 if (OuterLoop) dbgs() << "loop: " << getLoopName(*OuterLoop) << "\n";
1280 else dbgs() << "function\n");
1280 LLVM_DEBUG(dbgs() << "analyze-irreducible-in-";
1281 if (OuterLoop) dbgs()
1282 << "loop: " << getLoopName(*OuterLoop) << "\n";
1283 else dbgs() << "function\n");
12811284
12821285 using namespace bfi_detail;
12831286
13031306 bool
13041307 BlockFrequencyInfoImpl::propagateMassToSuccessors(LoopData *OuterLoop,
13051308 const BlockNode &Node) {
1306 DEBUG(dbgs() << " - node: " << getBlockName(Node) << "\n");
1309 LLVM_DEBUG(dbgs() << " - node: " << getBlockName(Node) << "\n");
13071310 // Calculate probability for successors.
13081311 Distribution Dist;
13091312 if (auto *Loop = Working[Node.Index].getPackagedLoop()) {
386386 do {
387387 LazyCallGraph::RefSCC *RC = RCWorklist.pop_back_val();
388388 if (InvalidRefSCCSet.count(RC)) {
389 DEBUG(dbgs() << "Skipping an invalid RefSCC...\n");
389 LLVM_DEBUG(dbgs() << "Skipping an invalid RefSCC...\n");
390390 continue;
391391 }
392392
393393 assert(CWorklist.empty() &&
394394 "Should always start with an empty SCC worklist");
395395
396 DEBUG(dbgs() << "Running an SCC pass across the RefSCC: " << *RC
397 << "\n");
396 LLVM_DEBUG(dbgs() << "Running an SCC pass across the RefSCC: " << *RC
397 << "\n");
398398
399399 // Push the initial SCCs in reverse post-order as we'll pop off the
400400 // back and so see this in post-order.
408408 // other RefSCCs should be queued above, so we just need to skip both
409409 // scenarios here.
410410 if (InvalidSCCSet.count(C)) {
411 DEBUG(dbgs() << "Skipping an invalid SCC...\n");
411 LLVM_DEBUG(dbgs() << "Skipping an invalid SCC...\n");
412412 continue;
413413 }
414414 if (&C->getOuterRefSCC() != RC) {
415 DEBUG(dbgs() << "Skipping an SCC that is now part of some other "
416 "RefSCC...\n");
415 LLVM_DEBUG(dbgs()
416 << "Skipping an SCC that is now part of some other "
417 "RefSCC...\n");
417418 continue;
418419 }
419420
435436 // If the CGSCC pass wasn't able to provide a valid updated SCC,
436437 // the current SCC may simply need to be skipped if invalid.
437438 if (UR.InvalidatedSCCs.count(C)) {
438 DEBUG(dbgs() << "Skipping invalidated root or island SCC!\n");
439 LLVM_DEBUG(dbgs()
440 << "Skipping invalidated root or island SCC!\n");
439441 break;
440442 }
441443 // Check that we didn't miss any update scenario.
463465 // FIXME: If we ever start having RefSCC passes, we'll want to
464466 // iterate there too.
465467 if (UR.UpdatedC)
466 DEBUG(dbgs() << "Re-running SCC passes after a refinement of the "
467 "current SCC: "
468 << *UR.UpdatedC << "\n");
468 LLVM_DEBUG(dbgs()
469 << "Re-running SCC passes after a refinement of the "
470 "current SCC: "
471 << *UR.UpdatedC << "\n");
469472
470473 // Note that both `C` and `RC` may at this point refer to deleted,
471474 // invalid SCC and RefSCCs respectively. But we will short circuit
600603 // a pointer we can overwrite.
601604 LazyCallGraph::SCC *CurrentC = &C;
602605
603 DEBUG(dbgs() << "Running function passes across an SCC: " << C << "\n");
606 LLVM_DEBUG(dbgs() << "Running function passes across an SCC: " << C
607 << "\n");
604608
605609 PreservedAnalyses PA = PreservedAnalyses::all();
606610 for (LazyCallGraph::Node *N : Nodes) {
756760 if (!F)
757761 return false;
758762
759 DEBUG(dbgs() << "Found devirutalized call from "
760 << CS.getParent()->getParent()->getName() << " to "
761 << F->getName() << "\n");
763 LLVM_DEBUG(dbgs() << "Found devirutalized call from "
764 << CS.getParent()->getParent()->getName() << " to "
765 << F->getName() << "\n");
762766
763767 // We now have a direct call where previously we had an indirect call,
764768 // so iterate to process this devirtualization site.
792796
793797 // Otherwise, if we've already hit our max, we're done.
794798 if (Iteration >= MaxIterations) {
795 DEBUG(dbgs() << "Found another devirtualization after hitting the max "
796 "number of repetitions ("
797 << MaxIterations << ") on SCC: " << *C << "\n");
799 LLVM_DEBUG(
800 dbgs() << "Found another devirtualization after hitting the max "
801 "number of repetitions ("
802 << MaxIterations << ") on SCC: " << *C << "\n");
798803 PA.intersect(std::move(PassPA));
799804 break;
800805 }
801806
802 DEBUG(dbgs()
803 << "Repeating an SCC pass after finding a devirtualization in: "
804 << *C << "\n");
807 LLVM_DEBUG(
808 dbgs()
809 << "Repeating an SCC pass after finding a devirtualization in: " << *C
810 << "\n");
805811
806812 // Move over the new call counts in preparation for iterating.
807813 CallCounts = std::move(NewCallCounts);
674674 #ifdef EXPENSIVE_CHECKS
675675 region->verifyRegion();
676676 #else
677 DEBUG(region->verifyRegion());
677 LLVM_DEBUG(region->verifyRegion());
678678 #endif
679679
680680 updateStatistics(region);
259259 BasicBlock *BB) {
260260 if (!BBExecutable.insert(BB).second)
261261 return;
262 DEBUG(dbgs() << "Marking Block Executable: " << BB->getName() << "\n");
262 LLVM_DEBUG(dbgs() << "Marking Block Executable: " << BB->getName() << "\n");
263263 BBWorkList.push_back(BB); // Add the block to the work list!
264264 }
265265
269269 if (!KnownFeasibleEdges.insert(Edge(Source, Dest)).second)
270270 return; // This edge is already known to be executable!
271271
272 DEBUG(dbgs() << "Marking Edge Executable: " << Source->getName() << " -> "
273 << Dest->getName() << "\n");
272 LLVM_DEBUG(dbgs() << "Marking Edge Executable: " << Source->getName()
273 << " -> " << Dest->getName() << "\n");
274274
275275 if (BBExecutable.count(Dest)) {
276276 // The destination is already executable, but we just made an edge
476476 Value *V = ValueWorkList.back();
477477 ValueWorkList.pop_back();
478478
479 DEBUG(dbgs() << "\nPopped off V-WL: " << *V << "\n");
479 LLVM_DEBUG(dbgs() << "\nPopped off V-WL: " << *V << "\n");
480480
481481 // "V" got into the work list because it made a transition. See if any
482482 // users are both live and in need of updating.
491491 BasicBlock *BB = BBWorkList.back();
492492 BBWorkList.pop_back();
493493
494 DEBUG(dbgs() << "\nPopped off BBWL: " << *BB);
494 LLVM_DEBUG(dbgs() << "\nPopped off BBWL: " << *BB);
495495
496496 // Notify all instructions in this basic block that they are newly
497497 // executable.
3737 return false;
3838 if (MachineInstr *DefMI = getOpcodeDef(TargetOpcode::G_TRUNC,
3939 MI.getOperand(1).getReg(), MRI)) {
40 DEBUG(dbgs() << ".. Combine MI: " << MI;);
40 LLVM_DEBUG(dbgs() << ".. Combine MI: " << MI;);
4141 unsigned DstReg = MI.getOperand(0).getReg();
4242 unsigned SrcReg = DefMI->getOperand(1).getReg();
4343 Builder.setInstr(MI);
6161 if (isInstUnsupported({TargetOpcode::G_AND, {DstTy}}) ||
6262 isInstUnsupported({TargetOpcode::G_CONSTANT, {DstTy}}))
6363 return false;
64 DEBUG(dbgs() << ".. Combine MI: " << MI;);
64 LLVM_DEBUG(dbgs() << ".. Combine MI: " << MI;);
6565 Builder.setInstr(MI);
6666 unsigned ZExtSrc = MI.getOperand(1).getReg();
6767 LLT ZExtSrcTy = MRI.getType(ZExtSrc);
9090 isInstUnsupported({TargetOpcode::G_ASHR, {DstTy}}) ||
9191 isInstUnsupported({TargetOpcode::G_CONSTANT, {DstTy}}))
9292 return false;
93 DEBUG(dbgs() << ".. Combine MI: " << MI;);
93 LLVM_DEBUG(dbgs() << ".. Combine MI: " << MI;);
9494 Builder.setInstr(MI);
9595 unsigned SExtSrc = MI.getOperand(1).getReg();
9696 LLT SExtSrcTy = MRI.getType(SExtSrc);
122122 LLT DstTy = MRI.getType(DstReg);
123123 if (isInstUnsupported({TargetOpcode::G_IMPLICIT_DEF, {DstTy}}))
124124 return false;
125 DEBUG(dbgs() << ".. Combine EXT(IMPLICIT_DEF) " << MI;);
125 LLVM_DEBUG(dbgs() << ".. Combine EXT(IMPLICIT_DEF) " << MI;);
126126 Builder.setInstr(MI);
127127 Builder.buildInstr(TargetOpcode::G_IMPLICIT_DEF, DstReg);
128128 markInstAndDefDead(MI, *DefMI, DeadInsts);
6262 public:
6363 ~RemoteRTDyldMemoryManager() {
6464 Client.destroyRemoteAllocator(Id);
65 DEBUG(dbgs() << "Destroyed remote allocator " << Id << "\n");
65 LLVM_DEBUG(dbgs() << "Destroyed remote allocator " << Id << "\n");
6666 }
6767
6868 RemoteRTDyldMemoryManager(const RemoteRTDyldMemoryManager &) = delete;
7878 Unmapped.back().CodeAllocs.emplace_back(Size, Alignment);
7979 uint8_t *Alloc = reinterpret_cast(
8080 Unmapped.back().CodeAllocs.back().getLocalAddress());
81 DEBUG(dbgs() << "Allocator " << Id << " allocated code for "
82 << SectionName << ": " << Alloc << " (" << Size
83 << " bytes, alignment " << Alignment << ")\n");
81 LLVM_DEBUG(dbgs() << "Allocator " << Id << " allocated code for "
82 << SectionName << ": " << Alloc << " (" << Size
83 << " bytes, alignment " << Alignment << ")\n");
8484 return Alloc;
8585 }
8686
9191 Unmapped.back().RODataAllocs.emplace_back(Size, Alignment);
9292 uint8_t *Alloc = reinterpret_cast(
9393 Unmapped.back().RODataAllocs.back().getLocalAddress());
94 DEBUG(dbgs() << "Allocator " << Id << " allocated ro-data for "
95 << SectionName << ": " << Alloc << " (" << Size
96 << " bytes, alignment " << Alignment << ")\n");
94 LLVM_DEBUG(dbgs() << "Allocator " << Id << " allocated ro-data for "
95 << SectionName << ": " << Alloc << " (" << Size
96 << " bytes, alignment " << Alignment << ")\n");
9797 return Alloc;
9898 } // else...
9999
100100 Unmapped.back().RWDataAllocs.emplace_back(Size, Alignment);
101101 uint8_t *Alloc = reinterpret_cast(
102102 Unmapped.back().RWDataAllocs.back().getLocalAddress());
103 DEBUG(dbgs() << "Allocator " << Id << " allocated rw-data for "
104 << SectionName << ": " << Alloc << " (" << Size
105 << " bytes, alignment " << Alignment << ")\n");
103 LLVM_DEBUG(dbgs() << "Allocator " << Id << " allocated rw-data for "
104 << SectionName << ": " << Alloc << " (" << Size
105 << " bytes, alignment " << Alignment << ")\n");
106106 return Alloc;
107107 }
108108
112112 uint32_t RWDataAlign) override {
113113 Unmapped.push_back(ObjectAllocs());
114114
115 DEBUG(dbgs() << "Allocator " << Id << " reserved:\n");
115 LLVM_DEBUG(dbgs() << "Allocator " << Id << " reserved:\n");
116116
117117 if (CodeSize != 0) {
118118 Unmapped.back().RemoteCodeAddr =
119119 Client.reserveMem(Id, CodeSize, CodeAlign);
120120
121 DEBUG(dbgs() << " code: "
122 << format("0x%016x", Unmapped.back().RemoteCodeAddr)
123 << " (" << CodeSize << " bytes, alignment " << CodeAlign
124 << ")\n");
121 LLVM_DEBUG(dbgs() << " code: "
122 << format("0x%016x", Unmapped.back().RemoteCodeAddr)
123 << " (" << CodeSize << " bytes, alignment "
124 << CodeAlign << ")\n");
125125 }
126126
127127 if (RODataSize != 0) {
128128 Unmapped.back().RemoteRODataAddr =
129129 Client.reserveMem(Id, RODataSize, RODataAlign);
130130
131 DEBUG(dbgs() << " ro-data: "
132 << format("0x%016x", Unmapped.back().RemoteRODataAddr)
133 << " (" << RODataSize << " bytes, alignment "
134 << RODataAlign << ")\n");
131 LLVM_DEBUG(dbgs() << " ro-data: "
132 << format("0x%016x", Unmapped.back().RemoteRODataAddr)
133 << " (" << RODataSize << " bytes, alignment "
134 << RODataAlign << ")\n");
135135 }
136136
137137 if (RWDataSize != 0) {
138138 Unmapped.back().RemoteRWDataAddr =
139139 Client.reserveMem(Id, RWDataSize, RWDataAlign);
140140
141 DEBUG(dbgs() << " rw-data: "
142 << format("0x%016x", Unmapped.back().RemoteRWDataAddr)
143 << " (" << RWDataSize << " bytes, alignment "
144 << RWDataAlign << ")\n");
141 LLVM_DEBUG(dbgs() << " rw-data: "
142 << format("0x%016x", Unmapped.back().RemoteRWDataAddr)
143 << " (" << RWDataSize << " bytes, alignment "
144 << RWDataAlign << ")\n");
145145 }
146146 }
147147
161161
162162 void notifyObjectLoaded(RuntimeDyld &Dyld,
163163 const object::ObjectFile &Obj) override {
164 DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n");
164 LLVM_DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n");
165165 for (auto &ObjAllocs : Unmapped) {
166166 mapAllocsToRemoteAddrs(Dyld, ObjAllocs.CodeAllocs,
167167 ObjAllocs.RemoteCodeAddr);
175175 }
176176
177177 bool finalizeMemory(std::string *ErrMsg = nullptr) override {
178 DEBUG(dbgs() << "Allocator " << Id << " finalizing:\n");
178 LLVM_DEBUG(dbgs() << "Allocator " << Id << " finalizing:\n");
179179
180180 for (auto &ObjAllocs : Unfinalized) {
181181 if (copyAndProtect(ObjAllocs.CodeAllocs, ObjAllocs.RemoteCodeAddr,
260260 RemoteRTDyldMemoryManager(OrcRemoteTargetClient &Client,
261261 ResourceIdMgr::ResourceId Id)
262262 : Client(Client), Id(Id) {
263 DEBUG(dbgs() << "Created remote allocator " << Id << "\n");
263 LLVM_DEBUG(dbgs() << "Created remote allocator " << Id << "\n");
264264 }
265265
266266 // Maps all allocations in Allocs to aligned blocks
269269 for (auto &Alloc : Allocs) {
270270 NextAddr = alignTo(NextAddr, Alloc.getAlign());
271271 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextAddr);
272 DEBUG(dbgs() << " " << static_cast(Alloc.getLocalAddress())
273 << " -> " << format("0x%016x", NextAddr) << "\n");
272 LLVM_DEBUG(dbgs() << " "
273 << static_cast(Alloc.getLocalAddress())
274 << " -> " << format("0x%016x", NextAddr) << "\n");
274275 Alloc.setRemoteAddress(NextAddr);
275276
276277 // Only advance NextAddr if it was non-null to begin with,
289290 assert(!Allocs.empty() && "No sections in allocated segment");
290291
291292 for (auto &Alloc : Allocs) {
292 DEBUG(dbgs() << " copying section: "
293 << static_cast(Alloc.getLocalAddress()) << " -> "
294 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
295 << Alloc.getSize() << " bytes)\n";);
293 LLVM_DEBUG(dbgs() << " copying section: "
294 << static_cast(Alloc.getLocalAddress())
295 << " -> "
296 << format("0x%016x", Alloc.getRemoteAddress())
297 << " (" << Alloc.getSize() << " bytes)\n";);
296298
297299 if (Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
298300 Alloc.getSize()))
299301 return true;
300302 }
301303
302 DEBUG(dbgs() << " setting "
303 << (Permissions & sys::Memory::MF_READ ? 'R' : '-')
304 << (Permissions & sys::Memory::MF_WRITE ? 'W' : '-')
305 << (Permissions & sys::Memory::MF_EXEC ? 'X' : '-')
306 << " permissions on block: "
307 << format("0x%016x", RemoteSegmentAddr) << "\n");
304 LLVM_DEBUG(dbgs() << " setting "
305 << (Permissions & sys::Memory::MF_READ ? 'R' : '-')
306 << (Permissions & sys::Memory::MF_WRITE ? 'W' : '-')
307 << (Permissions & sys::Memory::MF_EXEC ? 'X' : '-')
308 << " permissions on block: "
309 << format("0x%016x", RemoteSegmentAddr) << "\n");
308310 if (Client.setProtections(Id, RemoteSegmentAddr, Permissions))
309311 return true;
310312 }
486488 /// Call the int(void) function at the given address in the target and return
487489 /// its result.
488490 Expected callIntVoid(JITTargetAddress Addr) {
489 DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n");
491 LLVM_DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr)
492 << "\n");
490493 return callB(Addr);
491494 }
492495
494497 /// return its result.
495498 Expected callMain(JITTargetAddress Addr,
496499 const std::vector &Args) {
497 DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr)
498 << "\n");
500 LLVM_DEBUG(dbgs() << "Calling int(*)(int, char*[]) "
501 << format("0x%016x", Addr) << "\n");
499502 return callB(Addr, Args);
500503 }
501504
502505 /// Call the void() function at the given address in the target and wait for
503506 /// it to finish.
504507 Error callVoidVoid(JITTargetAddress Addr) {
505 DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
506 << "\n");
508 LLVM_DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
509 << "\n");
507510 return callB(Addr);
508511 }
509512
160160 IntVoidFnTy Fn =
161161 reinterpret_cast(static_cast(Addr));
162162
163 DEBUG(dbgs() << " Calling " << format("0x%016x", Addr) << "\n");
163 LLVM_DEBUG(dbgs() << " Calling " << format("0x%016x", Addr) << "\n");
164164 int Result = Fn();
165 DEBUG(dbgs() << " Result = " << Result << "\n");
165 LLVM_DEBUG(dbgs() << " Result = " << Result << "\n");
166166
167167 return Result;
168168 }
179179 for (auto &Arg : Args)
180180 ArgV[Idx++] = Arg.c_str();
181181 ArgV[ArgC] = 0;
182 DEBUG(
183 for (int Idx = 0; Idx < ArgC; ++Idx) {
184 llvm::dbgs() << "Arg " << Idx << ": " << ArgV[Idx] << "\n";
185 }
186 );
187
188 DEBUG(dbgs() << " Calling " << format("0x%016x", Addr) << "\n");
182 LLVM_DEBUG(for (int Idx = 0; Idx < ArgC; ++Idx) {
183 llvm::dbgs() << "Arg " << Idx << ": " << ArgV[Idx] << "\n";
184 });
185
186 LLVM_DEBUG(dbgs() << " Calling " << format("0x%016x", Addr) << "\n");
189187 int Result = Fn(ArgC, ArgV.get());
190 DEBUG(dbgs() << " Result = " << Result << "\n");
188 LLVM_DEBUG(dbgs() << " Result = " << Result << "\n");
191189
192190 return Result;
193191 }
198196 VoidVoidFnTy Fn =
199197 reinterpret_cast(static_cast(Addr));
200198
201 DEBUG(dbgs() << " Calling " << format("0x%016x", Addr) << "\n");
199 LLVM_DEBUG(dbgs() << " Calling " << format("0x%016x", Addr) << "\n");
202200 Fn();
203 DEBUG(dbgs() << " Complete.\n");
201 LLVM_DEBUG(dbgs() << " Complete.\n");
204202
205203 return Error::success();
206204 }
210208 if (I != Allocators.end())
211209 return errorCodeToError(
212210 orcError(OrcErrorCode::RemoteAllocatorIdAlreadyInUse));
213 DEBUG(dbgs() << " Created allocator " << Id << "\n");
211 LLVM_DEBUG(dbgs() << " Created allocator " << Id << "\n");
214212 Allocators[Id] = Allocator();
215213 return Error::success();
216214 }
220218 if (I != IndirectStubsOwners.end())
221219 return errorCodeToError(
222220 orcError(OrcErrorCode::RemoteIndirectStubsOwnerIdAlreadyInUse));
223 DEBUG(dbgs() << " Create indirect stubs owner " << Id << "\n");
221 LLVM_DEBUG(dbgs() << " Create indirect stubs owner " << Id << "\n");
224222 IndirectStubsOwners[Id] = ISBlockOwnerList();
225223 return Error::success();
226224 }
227225
228226 Error handleDeregisterEHFrames(JITTargetAddress TAddr, uint32_t Size) {
229227 uint8_t *Addr = reinterpret_cast(static_cast(TAddr));
230 DEBUG(dbgs() << " Registering EH frames at " << format("0x%016x", TAddr)
231 << ", Size = " << Size << " bytes\n");
228 LLVM_DEBUG(dbgs() << " Registering EH frames at "
229 << format("0x%016x", TAddr) << ", Size = " << Size
230 << " bytes\n");
232231 EHFramesDeregister(Addr, Size);
233232 return Error::success();
234233 }
239238 return errorCodeToError(
240239 orcError(OrcErrorCode::RemoteAllocatorDoesNotExist));
241240 Allocators.erase(I);
242 DEBUG(dbgs() << " Destroyed allocator " << Id << "\n");
241 LLVM_DEBUG(dbgs() << " Destroyed allocator " << Id << "\n");
243242 return Error::success();
244243 }
245244
255254 Expected>
256255 handleEmitIndirectStubs(ResourceIdMgr::ResourceId Id,
257256 uint32_t NumStubsRequired) {
258 DEBUG(dbgs() << " ISMgr " << Id << " request " << NumStubsRequired
259 << " stubs.\n");
257 LLVM_DEBUG(dbgs() << " ISMgr " << Id << " request " << NumStubsRequired
258 << " stubs.\n");
260259
261260 auto StubOwnerItr = IndirectStubsOwners.find(Id);
262261 if (StubOwnerItr == IndirectStubsOwners.end())
327326
328327 Expected handleGetSymbolAddress(const std::string &Name) {
329328 JITTargetAddress Addr = SymbolLookup(Name);
330 DEBUG(dbgs() << " Symbol '" << Name << "' = " << format("0x%016x", Addr)
331 << "\n");
329 LLVM_DEBUG(dbgs() << " Symbol '" << Name
330 << "' = " << format("0x%016x", Addr) << "\n");
332331 return Addr;
333332 }
334333
339338 uint32_t PageSize = sys::Process::getPageSize();
340339 uint32_t TrampolineSize = TargetT::TrampolineSize;
341340 uint32_t IndirectStubSize = TargetT::IndirectStubsInfo::StubSize;
342 DEBUG(dbgs() << " Remote info:\n"
343 << " triple = '" << ProcessTriple << "'\n"
344 << " pointer size = " << PointerSize << "\n"
345 << " page size = " << PageSize << "\n"
346 << " trampoline size = " << TrampolineSize << "\n"
347 << " indirect stub size = " << IndirectStubSize << "\n");
341 LLVM_DEBUG(dbgs() << " Remote info:\n"
342 << " triple = '" << ProcessTriple << "'\n"
343 << " pointer size = " << PointerSize << "\n"
344 << " page size = " << PageSize << "\n"
345 << " trampoline size = " << TrampolineSize << "\n"
346 << " indirect stub size = " << IndirectStubSize
347 << "\n");
348348 return std::make_tuple(ProcessTriple, PointerSize, PageSize, TrampolineSize,
349349 IndirectStubSize);
350350 }
353353 uint64_t Size) {
354354 uint8_t *Src = reinterpret_cast(static_cast(RSrc));
355355
356 DEBUG(dbgs() << " Reading " << Size << " bytes from "
357 << format("0x%016x", RSrc) << "\n");
356 LLVM_DEBUG(dbgs() << " Reading " << Size << " bytes from "
357 << format("0x%016x", RSrc) << "\n");
358358
359359 std::vector Buffer;
360360 Buffer.resize(Size);
366366
367367 Error handleRegisterEHFrames(JITTargetAddress TAddr, uint32_t Size) {
368368 uint8_t *Addr = reinterpret_cast(static_cast(TAddr));
369 DEBUG(dbgs() << " Registering EH frames at " << format("0x%016x", TAddr)
370 << ", Size = " << Size << " bytes\n");
369 LLVM_DEBUG(dbgs() << " Registering EH frames at "
370 << format("0x%016x", TAddr) << ", Size = " << Size
371 << " bytes\n");
371372 EHFramesRegister(Addr, Size);
372373 return Error::success();
373374 }
383384 if (auto Err = Allocator.allocate(LocalAllocAddr, Size, Align))
384385 return std::move(Err);
385386
386 DEBUG(dbgs() << " Allocator " << Id << " reserved " << LocalAllocAddr
387 << " (" << Size << " bytes, alignment " << Align << ")\n");
387 LLVM_DEBUG(dbgs() << " Allocator " << Id << " reserved " << LocalAllocAddr
388 << " (" << Size << " bytes, alignment " << Align
389 << ")\n");
388390
389391 JITTargetAddress AllocAddr = static_cast(
390392 reinterpret_cast(LocalAllocAddr));
400402 orcError(OrcErrorCode::RemoteAllocatorDoesNotExist));
401403 auto &Allocator = I->second;
402404 void *LocalAddr = reinterpret_cast(static_cast(Addr));
403 DEBUG(dbgs() << " Allocator " << Id << " set permissions on " << LocalAddr
404 << " to " << (Flags & sys::Memory::MF_READ ? 'R' : '-')
405 << (Flags & sys::Memory::MF_WRITE ? 'W' : '-')
406 << (Flags & sys::Memory::MF_EXEC ? 'X' : '-') << "\n");
405 LLVM_DEBUG(dbgs() << " Allocator " << Id << " set permissions on "
406 << LocalAddr << " to "
407 << (Flags & sys::Memory::MF_READ ? 'R' : '-')
408 << (Flags & sys::Memory::MF_WRITE ? 'W' : '-')
409 << (Flags & sys::Memory::MF_EXEC ? 'X' : '-') << "\n");
407410 return Allocator.setProtections(LocalAddr, Flags);
408411 }
409412
413416 }
414417
415418 Error handleWriteMem(DirectBufferWriter DBW) {
416 DEBUG(dbgs() << " Writing " << DBW.getSize() << " bytes to "
417 << format("0x%016x", DBW.getDst()) << "\n");
419 LLVM_DEBUG(dbgs() << " Writing " << DBW.getSize() << " bytes to "
420 << format("0x%016x", DBW.getDst()) << "\n");
418421 return Error::success();
419422 }
420423
421424 Error handleWritePtr(JITTargetAddress Addr, JITTargetAddress PtrVal) {
422 DEBUG(dbgs() << " Writing pointer *" << format("0x%016x", Addr) << " = "
423 << format("0x%016x", PtrVal) << "\n");
425 LLVM_DEBUG(dbgs() << " Writing pointer *" << format("0x%016x", Addr)
426 << " = " << format("0x%016x", PtrVal) << "\n");
424427 uintptr_t *Ptr =
425428 reinterpret_cast(static_cast(Addr));
426429 *Ptr = static_cast(PtrVal);
1010 // code, without it being enabled all of the time, and without having to add
1111 // command line options to enable it.
1212 //
13 // In particular, just wrap your code with the DEBUG() macro, and it will be
14 // enabled automatically if you specify '-debug' on the command-line.
15 // DEBUG() requires the DEBUG_TYPE macro to be defined. Set it to "foo" specify
16 // that your debug code belongs to class "foo". Be careful that you only do
17 // this after including Debug.h and not around any #include of headers. Headers
18 // should define and undef the macro acround the code that needs to use the
19 // DEBUG() macro. Then, on the command line, you can specify '-debug-only=foo'
20 // to enable JUST the debug information for the foo class.
13 // In particular, just wrap your code with the LLVM_DEBUG() macro, and it will
14 // be enabled automatically if you specify '-debug' on the command-line.
15 // LLVM_DEBUG() requires the DEBUG_TYPE macro to be defined. Set it to "foo"
16 // specify that your debug code belongs to class "foo". Be careful that you only
17 // do this after including Debug.h and not around any #include of headers.
18 // Headers should define and undef the macro acround the code that needs to use
19 // the LLVM_DEBUG() macro. Then, on the command line, you can specify
20 // '-debug-only=foo' to enable JUST the debug information for the foo class.
2121 //
2222 // When compiling without assertions, the -debug-* options and all code in
23 // DEBUG() statements disappears, so it does not affect the runtime of the code.
23 // LLVM_DEBUG() statements disappears, so it does not affect the runtime of the
24 // code.
2425 //
2526 //===----------------------------------------------------------------------===//
2627
112113 // debug build, then the code specified as the option to the macro will be
113114 // executed. Otherwise it will not be. Example:
114115 //
115 // DEBUG(dbgs() << "Bitset contains: " << Bitset << "\n");
116 // LLVM_DEBUG(dbgs() << "Bitset contains: " << Bitset << "\n");
116117 //
117 #define DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)
118 #define LLVM_DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)
119
120 #define DEBUG(X) LLVM_DEBUG(X)
118121
119122 } // end namespace llvm
120123
145145 assert(llvm::find(Res, Child) != Res.end()
146146 && "Expected child not found in the CFG");
147147 Res.erase(std::remove(Res.begin(), Res.end(), Child), Res.end());
148 DEBUG(dbgs() << "\tHiding edge " << BlockNamePrinter(N) << " -> "
149 << BlockNamePrinter(Child) << "\n");
148 LLVM_DEBUG(dbgs() << "\tHiding edge " << BlockNamePrinter(N) << " -> "
149 << BlockNamePrinter(Child) << "\n");
150150 } else {
151151 // If there's an deletion in the future, it means that the edge cannot
152152 // exist in the current CFG, but existed in it before.
153153 assert(llvm::find(Res, Child) == Res.end() &&
154154 "Unexpected child found in the CFG");
155 DEBUG(dbgs() << "\tShowing virtual edge " << BlockNamePrinter(N)
156 << " -> " << BlockNamePrinter(Child) << "\n");
155 LLVM_DEBUG(dbgs() << "\tShowing virtual edge " << BlockNamePrinter(N)
156 << " -> " << BlockNamePrinter(Child) << "\n");
157157 Res.push_back(Child);
158158 }
159159 }
386386 SNCA.addVirtualRoot();
387387 unsigned Num = 1;
388388
389 DEBUG(dbgs() << "\t\tLooking for trivial roots\n");
389 LLVM_DEBUG(dbgs() << "\t\tLooking for trivial roots\n");
390390
391391 // Step #1: Find all the trivial roots that are going to will definitely
392392 // remain tree roots.
403403 Roots.push_back(N);
404404 // Run DFS not to walk this part of CFG later.
405405 Num = SNCA.runDFS(N, Num, AlwaysDescend, 1);
406 DEBUG(dbgs() << "Found a new trivial root: " << BlockNamePrinter(N)
407 << "\n");
408 DEBUG(dbgs() << "Last visited node: "
409 << BlockNamePrinter(SNCA.NumToNode[Num]) << "\n");
410 }
411 }
412
413 DEBUG(dbgs() << "\t\tLooking for non-trivial roots\n");
406 LLVM_DEBUG(dbgs() << "Found a new trivial root: " << BlockNamePrinter(N)
407 << "\n");
408 LLVM_DEBUG(dbgs() << "Last visited node: "
409 << BlockNamePrinter(SNCA.NumToNode[Num]) << "\n");
410 }
411 }
412
413 LLVM_DEBUG(dbgs() << "\t\tLooking for non-trivial roots\n");
414414
415415 // Step #2: Find all non-trivial root candidates. Those are CFG nodes that
416416 // are reverse-unreachable were not visited by previous DFS walks (i.e. CFG
430430 SmallPtrSet ConnectToExitBlock;
431431 for (const NodePtr I : nodes(DT.Parent)) {
432432 if (SNCA.NodeToInfo.count(I) == 0) {
433 DEBUG(dbgs() << "\t\t\tVisiting node " << BlockNamePrinter(I)
434 << "\n");
433 LLVM_DEBUG(dbgs()
434 << "\t\t\tVisiting node " << BlockNamePrinter(I) << "\n");
435435 // Find the furthest away we can get by following successors, then
436436 // follow them in reverse. This gives us some reasonable answer about
437437 // the post-dom tree inside any infinite loop. In particular, it
442442 // the lowest and highest points in the infinite loop. In theory, it
443443 // would be nice to give the canonical backedge for the loop, but it's
444444 // expensive and does not always lead to a minimal set of roots.
445 DEBUG(dbgs() << "\t\t\tRunning forward DFS\n");
445 LLVM_DEBUG(dbgs() << "\t\t\tRunning forward DFS\n");
446446
447447 const unsigned NewNum = SNCA.runDFS(I, Num, AlwaysDescend, Num);
448448 const NodePtr FurthestAway = SNCA.NumToNode[NewNum];
449 DEBUG(dbgs() << "\t\t\tFound a new furthest away node "
450 << "(non-trivial root): "
451 << BlockNamePrinter(FurthestAway) << "\n");
449 LLVM_DEBUG(dbgs() << "\t\t\tFound a new furthest away node "
450 << "(non-trivial root): "
451 << BlockNamePrinter(FurthestAway) << "\n");
452452 ConnectToExitBlock.insert(FurthestAway);
453453 Roots.push_back(FurthestAway);
454 DEBUG(dbgs() << "\t\t\tPrev DFSNum: " << Num << ", new DFSNum: "
455 << NewNum << "\n\t\t\tRemoving DFS info\n");
454 LLVM_DEBUG(dbgs() << "\t\t\tPrev DFSNum: " << Num << ", new DFSNum: "
455 << NewNum << "\n\t\t\tRemoving DFS info\n");
456456 for (unsigned i = NewNum; i > Num; --i) {
457457 const NodePtr N = SNCA.NumToNode[i];
458 DEBUG(dbgs() << "\t\t\t\tRemoving DFS info for "
459 << BlockNamePrinter(N) << "\n");
458 LLVM_DEBUG(dbgs() << "\t\t\t\tRemoving DFS info for "
459 << BlockNamePrinter(N) << "\n");
460460 SNCA.NodeToInfo.erase(N);
461461 SNCA.NumToNode.pop_back();
462462 }
463463 const unsigned PrevNum = Num;
464 DEBUG(dbgs() << "\t\t\tRunning reverse DFS\n");
464 LLVM_DEBUG(dbgs() << "\t\t\tRunning reverse DFS\n");
465465 Num = SNCA.runDFS(FurthestAway, Num, AlwaysDescend, 1);
466466 for (unsigned i = PrevNum + 1; i <= Num; ++i)
467 DEBUG(dbgs() << "\t\t\t\tfound node "
468 << BlockNamePrinter(SNCA.NumToNode[i]) << "\n");
467 LLVM_DEBUG(dbgs() << "\t\t\t\tfound node "
468 << BlockNamePrinter(SNCA.NumToNode[i]) << "\n");
469469 }
470470 }
471471 }
472472
473 DEBUG(dbgs() << "Total: " << Total << ", Num: " << Num << "\n");
474 DEBUG(dbgs() << "Discovered CFG nodes:\n");
475 DEBUG(for (size_t i = 0; i <= Num; ++i) dbgs()
476 << i << ": " << BlockNamePrinter(SNCA.NumToNode[i]) << "\n");
473 LLVM_DEBUG(dbgs() << "Total: " << Total << ", Num: " << Num << "\n");
474 LLVM_DEBUG(dbgs() << "Discovered CFG nodes:\n");
475 LLVM_DEBUG(for (size_t i = 0; i <= Num; ++i) dbgs()
476 << i << ": " << BlockNamePrinter(SNCA.NumToNode[i]) << "\n");
477477
478478 assert((Total + 1 == Num) && "Everything should have been visited");
479479
480480 // Step #3: If we found some non-trivial roots, make them non-redundant.
481481 if (HasNonTrivialRoots) RemoveRedundantRoots(DT, BUI, Roots);
482482
483 DEBUG(dbgs() << "Found roots: ");
484 DEBUG(for (auto *Root : Roots) dbgs() << BlockNamePrinter(Root) << " ");
485 DEBUG(dbgs() << "\n");
483 LLVM_DEBUG(dbgs() << "Found roots: ");
484 LLVM_DEBUG(for (auto *Root
485 : Roots) dbgs()
486 << BlockNamePrinter(Root) << " ");
487 LLVM_DEBUG(dbgs() << "\n");
486488
487489 return Roots;
488490 }
498500 static void RemoveRedundantRoots(const DomTreeT &DT, BatchUpdatePtr BUI,
499501 RootsT &Roots) {
500502 assert(IsPostDom && "This function is for postdominators only");
501 DEBUG(dbgs() << "Removing redundant roots\n");
503 LLVM_DEBUG(dbgs() << "Removing redundant roots\n");
502504
503505 SemiNCAInfo SNCA(BUI);
504506
506508 auto &Root = Roots[i];
507509 // Trivial roots are always non-redundant.
508510 if (!HasForwardSuccessors(Root, BUI)) continue;
509 DEBUG(dbgs() << "\tChecking if " << BlockNamePrinter(Root)
510 << " remains a root\n");
511 LLVM_DEBUG(dbgs() << "\tChecking if " << BlockNamePrinter(Root)
512 << " remains a root\n");
511513 SNCA.clear();
512514 // Do a forward walk looking for the other roots.
513515 const unsigned Num = SNCA.runDFS(Root, 0, AlwaysDescend, 0);
519521 // root from the set of roots, as it is reverse-reachable from the other
520522 // one.
521523 if (llvm::find(Roots, N) != Roots.end()) {
522 DEBUG(dbgs() << "\tForward DFS walk found another root "
523 << BlockNamePrinter(N) << "\n\tRemoving root "
524 << BlockNamePrinter(Root) << "\n");
524 LLVM_DEBUG(dbgs() << "\tForward DFS walk found another root "
525 << BlockNamePrinter(N) << "\n\tRemoving root "
526 << BlockNamePrinter(Root) << "\n");
525527 std::swap(Root, Roots.back());
526528 Roots.pop_back();
527529
562564 SNCA.runSemiNCA(DT);
563565 if (BUI) {
564566 BUI->IsRecalculated = true;
565 DEBUG(dbgs() << "DomTree recalculated, skipping future batch updates\n");
567 LLVM_DEBUG(
568 dbgs() << "DomTree recalculated, skipping future batch updates\n");
566569 }
567570
568571 if (DT.Roots.empty()) return;
584587 // Loop over all of the discovered blocks in the function...
585588 for (size_t i = 1, e = NumToNode.size(); i != e; ++i) {
586589 NodePtr W = NumToNode[i];
587 DEBUG(dbgs() << "\tdiscovered a new reachable node "
588 << BlockNamePrinter(W) << "\n");
590 LLVM_DEBUG(dbgs() << "\tdiscovered a new reachable node "
591 << BlockNamePrinter(W) << "\n");
589592
590593 // Don't replace this with 'count', the insertion side effect is important
591594 if (DT.DomTreeNodes[W]) continue; // Haven't calculated this node yet?
637640 assert((From || IsPostDom) &&
638641 "From has to be a valid CFG node or a virtual root");
639642 assert(To && "Cannot be a nullptr");
640 DEBUG(dbgs() << "Inserting edge " << BlockNamePrinter(From) << " -> "
641 << BlockNamePrinter(To) << "\n");
643 LLVM_DEBUG(dbgs() << "Inserting edge " << BlockNamePrinter(From) << " -> "
644 << BlockNamePrinter(To) << "\n");
642645 TreeNodePtr FromTN = DT.getNode(From);
643646
644647 if (!FromTN) {
677680 if (RIt == DT.Roots.end())
678681 return false; // To is not a root, nothing to update.
679682
680 DEBUG(dbgs() << "\t\tAfter the insertion, " << BlockNamePrinter(To)
681 << " is no longer a root\n\t\tRebuilding the tree!!!\n");
683 LLVM_DEBUG(dbgs() << "\t\tAfter the insertion, " << BlockNamePrinter(To)
684 << " is no longer a root\n\t\tRebuilding the tree!!!\n");
682685
683686 CalculateFromScratch(DT, BUI);
684687 return true;
705708 // can make a different (implicit) decision about which node within an
706709 // infinite loop becomes a root.
707710
708 DEBUG(dbgs() << "Roots are different in updated trees\n"
709 << "The entire tree needs to be rebuilt\n");
711 LLVM_DEBUG(dbgs() << "Roots are different in updated trees\n"
712 << "The entire tree needs to be rebuilt\n");
710713 // It may be possible to update the tree without recalculating it, but
711714 // we do not know yet how to do it, and it happens rarely in practise.
712715 CalculateFromScratch(DT, BUI);
717720 // Handles insertion to a node already in the dominator tree.
718721 static void InsertReachable(DomTreeT &DT, const BatchUpdatePtr BUI,
719722 const TreeNodePtr From, const TreeNodePtr To) {
720 DEBUG(dbgs() << "\tReachable " << BlockNamePrinter(From->getBlock())
721 << " -> " << BlockNamePrinter(To->getBlock()) << "\n");
723 LLVM_DEBUG(dbgs() << "\tReachable " << BlockNamePrinter(From->getBlock())
724 << " -> " << BlockNamePrinter(To->getBlock()) << "\n");
722725 if (IsPostDom && UpdateRootsBeforeInsertion(DT, BUI, From, To)) return;
723726 // DT.findNCD expects both pointers to be valid. When From is a virtual
724727 // root, then its CFG block pointer is a nullptr, so we have to 'compute'
731734 const TreeNodePtr NCD = DT.getNode(NCDBlock);
732735 assert(NCD);
733736
734 DEBUG(dbgs() << "\t\tNCA == " << BlockNamePrinter(NCD) << "\n");
737 LLVM_DEBUG(dbgs() << "\t\tNCA == " << BlockNamePrinter(NCD) << "\n");
735738 const TreeNodePtr ToIDom = To->getIDom();
736739
737740 // Nothing affected -- NCA property holds.
740743
741744 // Identify and collect affected nodes.
742745 InsertionInfo II;
743 DEBUG(dbgs() << "Marking " << BlockNamePrinter(To) << " as affected\n");
746 LLVM_DEBUG(dbgs() << "Marking " << BlockNamePrinter(To)
747 << " as affected\n");
744748 II.Affected.insert(To);
745749 const unsigned ToLevel = To->getLevel();
746 DEBUG(dbgs() << "Putting " << BlockNamePrinter(To) << " into a Bucket\n");
750 LLVM_DEBUG(dbgs() << "Putting " << BlockNamePrinter(To)
751 << " into a Bucket\n");
747752 II.Bucket.push({ToLevel, To});
748753
749754 while (!II.Bucket.empty()) {
750755 const TreeNodePtr CurrentNode = II.Bucket.top().second;
751756 const unsigned CurrentLevel = CurrentNode->getLevel();
752757 II.Bucket.pop();
753 DEBUG(dbgs() << "\tAdding to Visited and AffectedQueue: "
754 << BlockNamePrinter(CurrentNode) << "\n");
758 LLVM_DEBUG(dbgs() << "\tAdding to Visited and AffectedQueue: "
759 << BlockNamePrinter(CurrentNode) << "\n");
755760
756761 II.Visited.insert({CurrentNode, CurrentLevel});
757762 II.AffectedQueue.push_back(CurrentNode);
769774 const TreeNodePtr TN, const unsigned RootLevel,
770775 const TreeNodePtr NCD, InsertionInfo &II) {
771776 const unsigned NCDLevel = NCD->getLevel();
772 DEBUG(dbgs() << "Visiting " << BlockNamePrinter(TN) << ", RootLevel "
773 << RootLevel << "\n");
777 LLVM_DEBUG(dbgs() << "Visiting " << BlockNamePrinter(TN) << ", RootLevel "
778 << RootLevel << "\n");
774779
775780 SmallVector Stack = {TN};
776781 assert(TN->getBlock() && II.Visited.count(TN) && "Preconditions!");
779784
780785 do {
781786 TreeNodePtr Next = Stack.pop_back_val();
782 DEBUG(dbgs() << " Next: " << BlockNamePrinter(Next) << "\n");
787 LLVM_DEBUG(dbgs() << " Next: " << BlockNamePrinter(Next) << "\n");
783788
784789 for (const NodePtr Succ :
785790 ChildrenGetter::Get(Next->getBlock(), BUI)) {
787792 assert(SuccTN && "Unreachable successor found at reachable insertion");
788793 const unsigned SuccLevel = SuccTN->getLevel();
789794
790 DEBUG(dbgs() << "\tSuccessor " << BlockNamePrinter(Succ) << ", level = "
791 << SuccLevel << "\n");
795 LLVM_DEBUG(dbgs() << "\tSuccessor " << BlockNamePrinter(Succ)
796 << ", level = " << SuccLevel << "\n");
792797
793798 // Do not process the same node multiple times.
794799 if (Processed.count(Next) > 0)
797802 // Succ dominated by subtree From -- not affected.
798803 // (Based on the lemma 2.5 from the second paper.)
799804 if (SuccLevel > RootLevel) {
800 DEBUG(dbgs() << "\t\tDominated by subtree From\n");
805 LLVM_DEBUG(dbgs() << "\t\tDominated by subtree From\n");
801806 if (II.Visited.count(SuccTN) != 0) {
802 DEBUG(dbgs() << "\t\t\talready visited at level "
803 << II.Visited[SuccTN] << "\n\t\t\tcurrent level "
804 << RootLevel << ")\n");
807 LLVM_DEBUG(dbgs() << "\t\t\talready visited at level "
808 << II.Visited[SuccTN] << "\n\t\t\tcurrent level "
809 << RootLevel << ")\n");
805810
806811 // A node can be necessary to visit again if we see it again at
807812 // a lower level than before.
809814 continue;
810815 }
811816
812 DEBUG(dbgs() << "\t\tMarking visited not affected "
813 << BlockNamePrinter(Succ) << "\n");
817 LLVM_DEBUG(dbgs() << "\t\tMarking visited not affected "
818 << BlockNamePrinter(Succ) << "\n");
814819 II.Visited.insert({SuccTN, RootLevel});
815820 II.VisitedNotAffectedQueue.push_back(SuccTN);
816821 Stack.push_back(SuccTN);
817822 } else if ((SuccLevel > NCDLevel + 1) &&
818823 II.Affected.count(SuccTN) == 0) {
819 DEBUG(dbgs() << "\t\tMarking affected and adding "
820 << BlockNamePrinter(Succ) << " to a Bucket\n");
824 LLVM_DEBUG(dbgs() << "\t\tMarking affected and adding "
825 << BlockNamePrinter(Succ) << " to a Bucket\n");
821826 II.Affected.insert(SuccTN);
822827 II.Bucket.push({SuccLevel, SuccTN});
823828 }
830835 // Updates immediate dominators and levels after insertion.
831836 static void UpdateInsertion(DomTreeT &DT, const BatchUpdatePtr BUI,
832837 const TreeNodePtr NCD, InsertionInfo &II) {
833 DEBUG(dbgs() << "Updating NCD = " << BlockNamePrinter(NCD) << "\n");
838 LLVM_DEBUG(dbgs() << "Updating NCD = " << BlockNamePrinter(NCD) << "\n");
834839
835840 for (const TreeNodePtr TN : II.AffectedQueue) {
836 DEBUG(dbgs() << "\tIDom(" << BlockNamePrinter(TN)
837 << ") = " << BlockNamePrinter(NCD) << "\n");
841 LLVM_DEBUG(dbgs() << "\tIDom(" << BlockNamePrinter(TN)
842 << ") = " << BlockNamePrinter(NCD) << "\n");
838843 TN->setIDom(NCD);
839844 }
840845
843848 }
844849
845850 static void UpdateLevelsAfterInsertion(InsertionInfo &II) {
846 DEBUG(dbgs() << "Updating levels for visited but not affected nodes\n");
851 LLVM_DEBUG(
852 dbgs() << "Updating levels for visited but not affected nodes\n");
847853
848854 for (const TreeNodePtr TN : II.VisitedNotAffectedQueue) {
849 DEBUG(dbgs() << "\tlevel(" << BlockNamePrinter(TN) << ") = ("
850 << BlockNamePrinter(TN->getIDom()) << ") "
851 << TN->getIDom()->getLevel() << " + 1\n");
855 LLVM_DEBUG(dbgs() << "\tlevel(" << BlockNamePrinter(TN) << ") = ("
856 << BlockNamePrinter(TN->getIDom()) << ") "
857 << TN->getIDom()->getLevel() << " + 1\n");
852858 TN->UpdateLevel();
853859 }
854860 }
856862 // Handles insertion to previously unreachable nodes.
857863 static void InsertUnreachable(DomTreeT &DT, const BatchUpdatePtr BUI,
858864 const TreeNodePtr From, const NodePtr To) {
859 DEBUG(dbgs() << "Inserting " << BlockNamePrinter(From)
860 << " -> (unreachable) " << BlockNamePrinter(To) << "\n");
865 LLVM_DEBUG(dbgs() << "Inserting " << BlockNamePrinter(From)
866 << " -> (unreachable) " << BlockNamePrinter(To) << "\n");
861867
862868 // Collect discovered edges to already reachable nodes.
863869 SmallVector, 8> DiscoveredEdgesToReachable;
864870 // Discover and connect nodes that became reachable with the insertion.
865871 ComputeUnreachableDominators(DT, BUI, To, From, DiscoveredEdgesToReachable);
866872
867 DEBUG(dbgs() << "Inserted " << BlockNamePrinter(From)
868 << " -> (prev unreachable) " << BlockNamePrinter(To) << "\n");
873 LLVM_DEBUG(dbgs() << "Inserted " << BlockNamePrinter(From)
874 << " -> (prev unreachable) " << BlockNamePrinter(To)
875 << "\n");
869876
870877 // Used the discovered edges and inset discovered connecting (incoming)
871878 // edges.
872879 for (const auto &Edge : DiscoveredEdgesToReachable) {
873 DEBUG(dbgs() << "\tInserting discovered connecting edge "
874 << BlockNamePrinter(Edge.first) << " -> "
875 << BlockNamePrinter(Edge.second) << "\n");
880 LLVM_DEBUG(dbgs() << "\tInserting discovered connecting edge "
881 << BlockNamePrinter(Edge.first) << " -> "
882 << BlockNamePrinter(Edge.second) << "\n");
876883 InsertReachable(DT, BUI, DT.getNode(Edge.first), Edge.second);
877884 }
878885 }
900907 SNCA.runSemiNCA(DT);
901908 SNCA.attachNewSubtree(DT, Incoming);
902909
903 DEBUG(dbgs() << "After adding unreachable nodes\n");
910 LLVM_DEBUG(dbgs() << "After adding unreachable nodes\n");
904911 }
905912
906913 static void DeleteEdge(DomTreeT &DT, const BatchUpdatePtr BUI,
907914 const NodePtr From, const NodePtr To) {
908915 assert(From && To && "Cannot disconnect nullptrs");
909 DEBUG(dbgs() << "Deleting edge " << BlockNamePrinter(From) << " -> "
910 << BlockNamePrinter(To) << "\n");
916 LLVM_DEBUG(dbgs() << "Deleting edge " << BlockNamePrinter(From) << " -> "
917 << BlockNamePrinter(To) << "\n");
911918
912919 #ifndef NDEBUG
913920 // Ensure that the edge was in fact deleted from the CFG before informing
927934
928935 const TreeNodePtr ToTN = DT.getNode(To);
929936 if (!ToTN) {
930 DEBUG(dbgs() << "\tTo (" << BlockNamePrinter(To)
931 << ") already unreachable -- there is no edge to delete\n");
937 LLVM_DEBUG(
938 dbgs() << "\tTo (" << BlockNamePrinter(To)
939 << ") already unreachable -- there is no edge to delete\n");
932940 return;
933941 }
934942
940948 DT.DFSInfoValid = false;
941949
942950 const TreeNodePtr ToIDom = ToTN->getIDom();
943 DEBUG(dbgs() << "\tNCD " << BlockNamePrinter(NCD) << ", ToIDom "
944 << BlockNamePrinter(ToIDom) << "\n");
951 LLVM_DEBUG(dbgs() << "\tNCD " << BlockNamePrinter(NCD) << ", ToIDom "
952 << BlockNamePrinter(ToIDom) << "\n");
945953
946954 // To remains reachable after deletion.
947955 // (Based on the caption under Figure 4. from the second paper.)
958966 static void DeleteReachable(DomTreeT &DT, const BatchUpdatePtr BUI,
959967 const TreeNodePtr FromTN,
960968 const TreeNodePtr ToTN) {
961 DEBUG(dbgs() << "Deleting reachable " << BlockNamePrinter(FromTN) << " -> "
962 << BlockNamePrinter(ToTN) << "\n");
963 DEBUG(dbgs() << "\tRebuilding subtree\n");
969 LLVM_DEBUG(dbgs() << "Deleting reachable " << BlockNamePrinter(FromTN)
970 << " -> " << BlockNamePrinter(ToTN) << "\n");
971 LLVM_DEBUG(dbgs() << "\tRebuilding subtree\n");
964972
965973 // Find the top of the subtree that needs to be rebuilt.
966974 // (Based on the lemma 2.6 from the second paper.)
973981 // Top of the subtree to rebuild is the root node. Rebuild the tree from
974982 // scratch.
975983 if (!PrevIDomSubTree) {
976 DEBUG(dbgs() << "The entire tree needs to be rebuilt\n");
984 LLVM_DEBUG(dbgs() << "The entire tree needs to be rebuilt\n");
977985 CalculateFromScratch(DT, BUI);
978986 return;
979987 }
984992 return DT.getNode(To)->getLevel() > Level;
985993 };
986994
987 DEBUG(dbgs() << "\tTop of subtree: " << BlockNamePrinter(ToIDomTN) << "\n");
995 LLVM_DEBUG(dbgs() << "\tTop of subtree: " << BlockNamePrinter(ToIDomTN)
996 << "\n");
988997
989998 SemiNCAInfo SNCA(BUI);
990999 SNCA.runDFS(ToIDom, 0, DescendBelow, 0);
991 DEBUG(dbgs() << "\tRunning Semi-NCA\n");
1000 LLVM_DEBUG(dbgs() << "\tRunning Semi-NCA\n");
9921001 SNCA.runSemiNCA(DT, Level);
9931002 SNCA.reattachExistingSubtree(DT, PrevIDomSubTree);
9941003 }
9971006 // explained on the page 7 of the second paper.
9981007 static bool HasProperSupport(DomTreeT &DT, const BatchUpdatePtr BUI,
9991008 const TreeNodePtr TN) {
1000 DEBUG(dbgs() << "IsReachableFromIDom " << BlockNamePrinter(TN) << "\n");
1009 LLVM_DEBUG(dbgs() << "IsReachableFromIDom " << BlockNamePrinter(TN)
1010 << "\n");
10011011 for (const NodePtr Pred :
10021012 ChildrenGetter::Get(TN->getBlock(), BUI)) {
1003 DEBUG(dbgs() << "\tPred " << BlockNamePrinter(Pred) << "\n");
1013 LLVM_DEBUG(dbgs() << "\tPred " << BlockNamePrinter(Pred) << "\n");
10041014 if (!DT.getNode(Pred)) continue;
10051015
10061016 const NodePtr Support =
10071017 DT.findNearestCommonDominator(TN->getBlock(), Pred);
1008 DEBUG(dbgs() << "\tSupport " << BlockNamePrinter(Support) << "\n");
1018 LLVM_DEBUG(dbgs() << "\tSupport " << BlockNamePrinter(Support) << "\n");
10091019 if (Support != TN->getBlock()) {
1010 DEBUG(dbgs() << "\t" << BlockNamePrinter(TN)
1011 << " is reachable from support "
1012 << BlockNamePrinter(Support) << "\n");
1020 LLVM_DEBUG(dbgs() << "\t" << BlockNamePrinter(TN)
1021 << " is reachable from support "
1022 << BlockNamePrinter(Support) << "\n");
10131023 return true;
10141024 }
10151025 }
10211031 // (Based on the lemma 2.7 from the second paper.)
10221032 static void DeleteUnreachable(DomTreeT &DT, const BatchUpdatePtr BUI,
10231033 const TreeNodePtr ToTN) {
1024 DEBUG(dbgs() << "Deleting unreachable subtree " << BlockNamePrinter(ToTN)
1025 << "\n");
1034 LLVM_DEBUG(dbgs() << "Deleting unreachable subtree "
1035 << BlockNamePrinter(ToTN) << "\n");
10261036 assert(ToTN);
10271037 assert(ToTN->getBlock());
10281038
10301040 // Deletion makes a region reverse-unreachable and creates a new root.
10311041 // Simulate that by inserting an edge from the virtual root to ToTN and
10321042 // adding it as a new root.
1033 DEBUG(dbgs() << "\tDeletion made a region reverse-unreachable\n");
1034 DEBUG(dbgs() << "\tAdding new root " << BlockNamePrinter(ToTN) << "\n");
1043 LLVM_DEBUG(dbgs() << "\tDeletion made a region reverse-unreachable\n");
1044 LLVM_DEBUG(dbgs() << "\tAdding new root " << BlockNamePrinter(ToTN)
1045 << "\n");
10351046 DT.Roots.push_back(ToTN->getBlock());
10361047 InsertReachable(DT, BUI, DT.getNode(nullptr), ToTN);
10371048 return;
10681079 const TreeNodePtr NCD = DT.getNode(NCDBlock);
10691080 assert(NCD);
10701081
1071 DEBUG(dbgs() << "Processing affected node " << BlockNamePrinter(TN)
1072 << " with NCD = " << BlockNamePrinter(NCD)
1073 << ", MinNode =" << BlockNamePrinter(MinNode) << "\n");
1082 LLVM_DEBUG(dbgs() << "Processing affected node " << BlockNamePrinter(TN)
1083 << " with NCD = " << BlockNamePrinter(NCD)
1084 << ", MinNode =" << BlockNamePrinter(MinNode) << "\n");
10741085 if (NCD != TN && NCD->getLevel() < MinNode->getLevel()) MinNode = NCD;
10751086 }
10761087
10771088 // Root reached, rebuild the whole tree from scratch.
10781089 if (!MinNode->getIDom()) {
1079 DEBUG(dbgs() << "The entire tree needs to be rebuilt\n");
1090 LLVM_DEBUG(dbgs() << "The entire tree needs to be rebuilt\n");
10801091 CalculateFromScratch(DT, BUI);
10811092 return;
10821093 }
10861097 for (unsigned i = LastDFSNum; i > 0; --i) {
10871098 const NodePtr N = SNCA.NumToNode[i];
10881099 const TreeNodePtr TN = DT.getNode(N);
1089 DEBUG(dbgs() << "Erasing node " << BlockNamePrinter(TN) << "\n");
1100 LLVM_DEBUG(dbgs() << "Erasing node " << BlockNamePrinter(TN) << "\n");
10901101
10911102 EraseNode(DT, TN);
10921103 }
10941105 // The affected subtree start at the To node -- there's no extra work to do.
10951106 if (MinNode == ToTN) return;
10961107
1097 DEBUG(dbgs() << "DeleteUnreachable: running DFS with MinNode = "
1098 << BlockNamePrinter(MinNode) << "\n");
1108 LLVM_DEBUG(dbgs() << "DeleteUnreachable: running DFS with MinNode = "
1109 << BlockNamePrinter(MinNode) << "\n");
10991110 const unsigned MinLevel = MinNode->getLevel();
11001111 const TreeNodePtr PrevIDom = MinNode->getIDom();
11011112 assert(PrevIDom);
11081119 };
11091120 SNCA.runDFS(MinNode->getBlock(), 0, DescendBelow, 0);
11101121
1111 DEBUG(dbgs() << "Previous IDom(MinNode) = " << BlockNamePrinter(PrevIDom)
1112 << "\nRunning Semi-NCA\n");
1122 LLVM_DEBUG(dbgs() << "Previous IDom(MinNode) = "
1123 << BlockNamePrinter(PrevIDom) << "\nRunning Semi-NCA\n");
11131124
11141125 // Rebuild the remaining part of affected subtree.
11151126 SNCA.runSemiNCA(DT, MinLevel);
11681179 BUI.FuturePredecessors[U.getTo()].insert({U.getFrom(), U.getKind()});
11691180 }
11701181
1171 DEBUG(dbgs() << "About to apply " << NumLegalized << " updates\n");
1172 DEBUG(if (NumLegalized < 32) for (const auto &U
1173 : reverse(BUI.Updates)) dbgs()
1174 << '\t' << U << "\n");
1175 DEBUG(dbgs() << "\n");
1182 LLVM_DEBUG(dbgs() << "About to apply " << NumLegalized << " updates\n");
1183 LLVM_DEBUG(if (NumLegalized < 32) for (const auto &U
1184 : reverse(BUI.Updates)) dbgs()
1185 << '\t' << U << "\n");
1186 LLVM_DEBUG(dbgs() << "\n");
11761187
11771188 // If the DominatorTree was recalculated at some point, stop the batch
11781189 // updates. Full recalculations ignore batch updates and look at the actual
12001211 // minimizes the amount of work needed done during incremental updates.
12011212 static void LegalizeUpdates(ArrayRef AllUpdates,
12021213 SmallVectorImpl &Result) {
1203 DEBUG(dbgs() << "Legalizing " << AllUpdates.size() << " updates\n");
1214 LLVM_DEBUG(dbgs() << "Legalizing " << AllUpdates.size() << " updates\n");
12041215 // Count the total number of inserions of each edge.
12051216 // Each insertion adds 1 and deletion subtracts 1. The end number should be
12061217 // one of {-1 (deletion), 0 (NOP), +1 (insertion)}. Otherwise, the sequence
12501261 static void ApplyNextUpdate(DomTreeT &DT, BatchUpdateInfo &BUI) {
12511262 assert(!BUI.Updates.empty() && "No updates to apply!");
12521263 UpdateT CurrentUpdate = BUI.Updates.pop_back_val();
1253 DEBUG(dbgs() << "Applying update: " << CurrentUpdate << "\n");
1264 LLVM_DEBUG(dbgs() << "Applying update: " << CurrentUpdate << "\n");
12541265
12551266 // Move to the next snapshot of the CFG by removing the reverse-applied
12561267 // current update.
15291540 const NodePtr BB = TN->getBlock();
15301541 if (!BB || TN->getChildren().empty()) continue;
15311542
1532 DEBUG(dbgs() << "Verifying parent property of node "
1533 << BlockNamePrinter(TN) << "\n");
1543 LLVM_DEBUG(dbgs() << "Verifying parent property of node "
1544 << BlockNamePrinter(TN) << "\n");
15341545 clear();
15351546 doFullDFSWalk(DT, [BB](NodePtr From, NodePtr To) {
15361547 return From != BB && To != BB;
7676 for (CharRanges::const_iterator I = Ranges.begin(), E = Ranges.end();
7777 I != E; ++I) {
7878 if (I != Ranges.begin() && Prev >= I->Lower) {
79 DEBUG(dbgs() << "Upper bound 0x");
80 DEBUG(dbgs().write_hex(Prev));
81 DEBUG(dbgs() << " should be less than succeeding lower bound 0x");
82 DEBUG(dbgs().write_hex(I->Lower) << "\n");
79 LLVM_DEBUG(dbgs() << "Upper bound 0x");
80 LLVM_DEBUG(dbgs().write_hex(Prev));
81 LLVM_DEBUG(dbgs() << " should be less than succeeding lower bound 0x");
82 LLVM_DEBUG(dbgs().write_hex(I->Lower) << "\n");
8383 return false;
8484 }
8585 if (I->Upper < I->Lower) {
86 DEBUG(dbgs() << "Upper bound 0x");
87 DEBUG(dbgs().write_hex(I->Lower));
88 DEBUG(dbgs() << " should not be less than lower bound 0x");
89 DEBUG(dbgs().write_hex(I->Upper) << "\n");
86 LLVM_DEBUG(dbgs() << "Upper bound 0x");
87 LLVM_DEBUG(dbgs().write_hex(I->Lower));
88 LLVM_DEBUG(dbgs() << " should not be less than lower bound 0x");
89 LLVM_DEBUG(dbgs().write_hex(I->Upper) << "\n");
9090 return false;
9191 }
9292 Prev = I->Upper;
3939 /// in it.
4040 void Add(Instruction *I) {
4141 if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) {
42 DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
42 LLVM_DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
4343 Worklist.push_back(I);
4444 }
4545 }
5656 assert(Worklist.empty() && "Worklist must be empty to add initial group");
5757 Worklist.reserve(List.size()+16);
5858 WorklistMap.reserve(List.size());
59 DEBUG(dbgs() << "IC: ADDING: " << List.size() << " instrs to worklist\n");
59 LLVM_DEBUG(dbgs() << "IC: ADDING: " << List.size()
60 << " instrs to worklist\n");
6061 unsigned Idx = 0;
6162 for (Instruction *I : reverse(List)) {
6263 WorklistMap.insert(std::make_pair(I, Idx++));
378378 Traits::AddPHIOperand(PHI, PredInfo->AvailableVal, Pred);
379379 }
380380
381 DEBUG(dbgs() << " Inserted PHI: " << *PHI << "\n");
381 LLVM_DEBUG(dbgs() << " Inserted PHI: " << *PHI << "\n");
382382
383383 // If the client wants to know about all new instructions, tell it.
384384 if (InsertedPHIs) InsertedPHIs->push_back(PHI);
315315 #endif
316316
317317 if (isLoopHeader(Resolved)) {
318 DEBUG(debugSuccessor("backedge"));
318 LLVM_DEBUG(debugSuccessor("backedge"));
319319 Dist.addBackedge(Resolved, Weight);
320320 return true;
321321 }
322322
323323 if (Working[Resolved.Index].getContainingLoop() != OuterLoop) {
324 DEBUG(debugSuccessor(" exit "));
324 LLVM_DEBUG(debugSuccessor(" exit "));
325325 Dist.addExit(Resolved, Weight);
326326 return true;
327327 }
333333 "unhandled irreducible control flow");
334334
335335 // Irreducible backedge. Abort.
336 DEBUG(debugSuccessor("abort!!!"));
336 LLVM_DEBUG(debugSuccessor("abort!!!"));
337337 return false;
338338 }
339339
344344 "unhandled irreducible control flow");
345345 }
346346
347 DEBUG(debugSuccessor(" local "));
347 LLVM_DEBUG(debugSuccessor(" local "));
348348 Dist.addLocal(Resolved, Weight);
349349 return true;
350350 }
364364 /// Compute the loop scale for a loop.
365365 void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) {
366366 // Compute loop scale.
367 DEBUG(dbgs() << "compute-loop-scale: " << getLoopName(Loop) << "\n");
367 LLVM_DEBUG(dbgs() << "compute-loop-scale: " << getLoopName(Loop) << "\n");
368368
369369 // Infinite loops need special handling. If we give the back edge an infinite
370370 // mass, they may saturate all the other scales in the function down to 1,
390390 Loop.Scale =
391391 ExitMass.isEmpty() ? InfiniteLoopScale : ExitMass.toScaled().inverse();
392392
393 DEBUG(dbgs() << " - exit-mass = " << ExitMass << " (" << BlockMass::getFull()
394 << " - " << TotalBackedgeMass << ")\n"
395 << " - scale = " << Loop.Scale << "\n");
393 LLVM_DEBUG(dbgs() << " - exit-mass = " << ExitMass << " ("
394 << BlockMass::getFull() << " - " << TotalBackedgeMass
395 << ")\n"
396 << " - scale = " << Loop.Scale << "\n");
396397 }
397398
398399 /// Package up a loop.
399400 void BlockFrequencyInfoImplBase::packageLoop(LoopData &Loop) {
400 DEBUG(dbgs() << "packaging-loop: " << getLoopName(Loop) << "\n");
401 LLVM_DEBUG(dbgs() << "packaging-loop: " << getLoopName(Loop) << "\n");
401402
402403 // Clear the subloop exits to prevent quadratic memory usage.
403404 for (const BlockNode &M : Loop.Nodes) {
404405 if (auto *Loop = Working[M.Index].getPackagedLoop())
405406 Loop->Exits.clear();
406 DEBUG(dbgs() << " - node: " << getBlockName(M.Index) << "\n");
407 LLVM_DEBUG(dbgs() << " - node: " << getBlockName(M.Index) << "\n");
407408 }
408409 Loop.IsPackaged = true;
409410 }
425426 LoopData *OuterLoop,
426427 Distribution &Dist) {
427428 BlockMass Mass = Working[Source.Index].getMass();
428 DEBUG(dbgs() << " => mass: " << Mass << "\n");
429 LLVM_DEBUG(dbgs() << " => mass: " << Mass << "\n");
429430
430431 // Distribute mass to successors as laid out in Dist.
431432 DitheringDistributer D(Dist, Mass);
435436 BlockMass Taken = D.takeMass(W.Amount);
436437 if (W.Type == Weight::Local) {
437438 Working[W.TargetNode.Index].getMass() += Taken;
438 DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr));
439 LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr));
439440 continue;
440441 }
441442
445446 // Check for a backedge.
446447 if (W.Type == Weight::Backedge) {
447448 OuterLoop->BackedgeMass[OuterLoop->getHeaderIndex(W.TargetNode)] += Taken;
448 DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "back"));
449 LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "back"));
449450 continue;
450451 }
451452
452453 // This must be an exit.
453454 assert(W.Type == Weight::Exit);
454455 OuterLoop->Exits.push_back(std::make_pair(W.TargetNode, Taken));
455 DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "exit"));
456 LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "exit"));
456457 }
457458 }
458459
480481 }
481482
482483 // Translate the floats to integers.
483 DEBUG(dbgs() << "float-to-int: min = " << Min << ", max = " << Max
484 << ", factor = " << ScalingFactor << "\n");
484 LLVM_DEBUG(dbgs() << "float-to-int: min = " << Min << ", max = " << Max
485 << ", factor = " << ScalingFactor << "\n");
485486 for (size_t Index = 0; Index < BFI.Freqs.size(); ++Index) {
486487 Scaled64 Scaled = BFI.Freqs[Index].Scaled * ScalingFactor;
487488 BFI.Freqs[Index].Integer = std::max(UINT64_C(1), Scaled.toInt());
488 DEBUG(dbgs() << " - " << BFI.getBlockName(Index) << ": float = "
489 << BFI.Freqs[Index].Scaled << ", scaled = " << Scaled
490 << ", int = " << BFI.Freqs[Index].Integer << "\n");
489 LLVM_DEBUG(dbgs() << " - " << BFI.getBlockName(Index) << ": float = "
490 << BFI.Freqs[Index].Scaled << ", scaled = " << Scaled
491 << ", int = " << BFI.Freqs[Index].Integer << "\n");
491492 }
492493 }
493494
496497 /// Visits all the members of a loop, adjusting their BlockData according to
497498 /// the loop's pseudo-node.
498499 static void unwrapLoop(BlockFrequencyInfoImplBase &BFI, LoopData &Loop) {
499 DEBUG(dbgs() << "unwrap-loop-package: " << BFI.getLoopName(Loop)
500 << ": mass = " << Loop.Mass << ", scale = " << Loop.Scale
501 << "\n");
500 LLVM_DEBUG(dbgs() << "unwrap-loop-package: " << BFI.getLoopName(Loop)
501 << ": mass = " << Loop.Mass << ", scale = " << Loop.Scale
502 << "\n");
502503 Loop.Scale *= Loop.Mass.toScaled();
503504 Loop.IsPackaged = false;
504 DEBUG(dbgs() << " => combined-scale = " << Loop.Scale << "\n");
505 LLVM_DEBUG(dbgs() << " => combined-scale = " << Loop.Scale << "\n");
505506
506507 // Propagate the head scale through the loop. Since members are visited in
507508 // RPO, the head scale will be updated by the loop scale first, and then the
511512 Scaled64 &F = Working.isAPackage() ? Working.getPackagedLoop()->Scale
512513 : BFI.Freqs[N.Index].Scaled;
513514 Scaled64 New = Loop.Scale * F;
514 DEBUG(dbgs() << " - " << BFI.getBlockName(N) << ": " << F << " => " << New
515 << "\n");
515 LLVM_DEBUG(dbgs() << " - " << BFI.getBlockName(N) << ": " << F << " => "
516 << New << "\n");
516517 F = New;
517518 }
518519 }
544545 cleanup(*this);
545546
546547 // Print out the final stats.
547 DEBUG(dump());
548 LLVM_DEBUG(dump());
548549 }
549550
550551 BlockFrequency
694695 // This is an entry block.
695696 I->second = true;
696697 Headers.push_back(Irr.Node);
697 DEBUG(dbgs() << " => entry = " << BFI.getBlockName(Irr.Node) << "\n");
698 LLVM_DEBUG(dbgs() << " => entry = " << BFI.getBlockName(Irr.Node)
699 << "\n");
698700 break;
699701 }
700702 }
725727
726728 // Store the extra header.
727729 Headers.push_back(Irr.Node);
728 DEBUG(dbgs() << " => extra = " << BFI.getBlockName(Irr.Node) << "\n");
730 LLVM_DEBUG(dbgs() << " => extra = " << BFI.getBlockName(Irr.Node)
731 << "\n");
729732 break;
730733 }
731734 if (Headers.back() == Irr.Node)
734737
735738 // This is not a header.
736739 Others.push_back(Irr.Node);
737 DEBUG(dbgs() << " => other = " << BFI.getBlockName(Irr.Node) << "\n");
740 LLVM_DEBUG(dbgs() << " => other = " << BFI.getBlockName(Irr.Node) << "\n");
738741 }
739742 llvm::sort(Headers.begin(), Headers.end());
740743 llvm::sort(Others.begin(), Others.end());
745748 LoopData *OuterLoop, std::list::iterator Insert,
746749 const std::vector &SCC) {
747750 // Translate the SCC into RPO.
748 DEBUG(dbgs() << " - found-scc\n");
751 LLVM_DEBUG(dbgs() << " - found-scc\n");
749752
750753 LoopData::NodeList Headers;
751754 LoopData::NodeList Others;
806809 BlockMass LoopMass = BlockMass::getFull();
807810 Distribution Dist;
808811
809 DEBUG(dbgs() << "adjust-loop-header-mass:\n");
812 LLVM_DEBUG(dbgs() << "adjust-loop-header-mass:\n");
810813 for (uint32_t H = 0; H < Loop.NumHeaders; ++H) {
811814 auto &HeaderNode = Loop.Nodes[H];
812815 auto &BackedgeMass = Loop.BackedgeMass[Loop.getHeaderIndex(HeaderNode)];
813 DEBUG(dbgs() << " - Add back edge mass for node "
814 << getBlockName(HeaderNode) << ": " << BackedgeMass << "\n");
816 LLVM_DEBUG(dbgs() << " - Add back edge mass for node "
817 << getBlockName(HeaderNode) << ": " << BackedgeMass
818 << "\n");
815819 if (BackedgeMass.getMass() > 0)
816820 Dist.addLocal(HeaderNode, BackedgeMass.getMass());
817821 else
818 DEBUG(dbgs() << " Nothing added. Back edge mass is zero\n");
822 LLVM_DEBUG(dbgs() << " Nothing added. Back edge mass is zero\n");
819823 }
820824
821825 DitheringDistributer D(Dist, LoopMass);
822826
823 DEBUG(dbgs() << " Distribute loop mass " << LoopMass
824 << " to headers using above weights\n");
827 LLVM_DEBUG(dbgs() << " Distribute loop mass " << LoopMass
828 << " to headers using above weights\n");
825829 for (const Weight &W : Dist.Weights) {
826830 BlockMass Taken = D.takeMass(W.Amount);
827831 assert(W.Type == Weight::Local && "all weights should be local");
828832 Working[W.TargetNode.Index].getMass() = Taken;
829 DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr));
833 LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr));
830834 }
831835 }
832836
837841 BlockMass Taken = D.takeMass(W.Amount);
838842 assert(W.Type == Weight::Local && "all weights should be local");
839843 Working[W.TargetNode.Index].getMass() = Taken;
840 DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr));
841 }
842 }
844 LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr));
845 }
846 }
907907 BranchProbability Prob) {
908908 Probs[std::make_pair(Src, IndexInSuccessors)] = Prob;
909909 Handles.insert(BasicBlockCallbackVH(Src, this));
910 DEBUG(dbgs() << "set edge " << Src->getName() << " -> " << IndexInSuccessors
911 << " successor probability to " << Prob << "\n");
910 LLVM_DEBUG(dbgs() << "set edge " << Src->getName() << " -> "
911 << IndexInSuccessors << " successor probability to " << Prob
912 << "\n");
912913 }
913914
914915 raw_ostream &
933934
934935 void BranchProbabilityInfo::calculate(const Function &F, const LoopInfo &LI,
935936 const TargetLibraryInfo *TLI) {
936 DEBUG(dbgs() << "---- Branch Probability Info : " << F.getName()
937 << " ----\n\n");
937 LLVM_DEBUG(dbgs() << "---- Branch Probability Info : " << F.getName()
938 << " ----\n\n");
938939 LastF = &F; // Store the last function we ran on for printing.
939940 assert(PostDominatedByUnreachable.empty());
940941 assert(PostDominatedByColdCall.empty());
952953 if (Scc.size() == 1)
953954 continue;
954955
955 DEBUG(dbgs() << "BPI: SCC " << SccNum << ":");
956 LLVM_DEBUG(dbgs() << "BPI: SCC " << SccNum << ":");
956957 for (auto *BB : Scc) {
957 DEBUG(dbgs() << " " << BB->getName());
958 LLVM_DEBUG(dbgs() << " " << BB->getName());
958959 SccI.SccNums[BB] = SccNum;
959960 }
960 DEBUG(dbgs() << "\n");
961 LLVM_DEBUG(dbgs() << "\n");
961962 }
962963
963964 // Walk the basic blocks in post-order so that we can build up state about
964965 // the successors of a block iteratively.
965966 for (auto BB : post_order(&F.getEntryBlock())) {
966 DEBUG(dbgs() << "Computing probabilities for " << BB->getName() << "\n");
967 LLVM_DEBUG(dbgs() << "Computing probabilities for " << BB->getName()
968 << "\n");
967969 updatePostDominatedByUnreachable(BB);
968970 updatePostDominatedByColdCall(BB);
969971 // If there is no at least two successors, no sense to set probability.
854854 if (!Fn) {
855855 // The only times this is known to happen are when globals + InlineAsm are
856856 // involved
857 DEBUG(dbgs()
858 << "CFLAndersAA: could not extract parent function information.\n");
857 LLVM_DEBUG(
858 dbgs()
859 << "CFLAndersAA: could not extract parent function information.\n");
859860 return MayAlias;
860861 }
861862 } else {
275275 if (!MaybeFnA && !MaybeFnB) {
276276 // The only times this is known to happen are when globals + InlineAsm are
277277 // involved
278 DEBUG(dbgs()
279 << "CFLSteensAA: could not extract parent function information.\n");
278 LLVM_DEBUG(
279 dbgs()
280 << "CFLSteensAA: could not extract parent function information.\n");
280281 return MayAlias;
281282 }
282283
7474 // If the CGSCC pass wasn't able to provide a valid updated SCC, the
7575 // current SCC may simply need to be skipped if invalid.
7676 if (UR.InvalidatedSCCs.count(C)) {
77 DEBUG(dbgs() << "Skipping invalidated root or island SCC!\n");
77 LLVM_DEBUG(dbgs() << "Skipping invalidated root or island SCC!\n");
7878 break;
7979 }
8080 // Check that we didn't miss any update scenario.
352352
353353 // Add the current SCC to the worklist as its shape has changed.
354354 UR.CWorklist.insert(C);
355 DEBUG(dbgs() << "Enqueuing the existing SCC in the worklist:" << *C << "\n");
355 LLVM_DEBUG(dbgs() << "Enqueuing the existing SCC in the worklist:" << *C
356 << "\n");
356357
357358 SCC *OldC = C;
358359
388389 assert(C != &NewC && "No need to re-visit the current SCC!");
389390 assert(OldC != &NewC && "Already handled the original SCC!");
390391 UR.CWorklist.insert(&NewC);
391 DEBUG(dbgs() << "Enqueuing a newly formed SCC:" << NewC << "\n");
392 LLVM_DEBUG(dbgs() << "Enqueuing a newly formed SCC:" << NewC << "\n");
392393
393394 // Ensure new SCCs' function analyses are updated.
394395 if (NeedFAMProxy)
513514 return false;
514515
515516 RC->removeOutgoingEdge(N, *TargetN);
516 DEBUG(dbgs() << "Deleting outgoing edge from '" << N
517 << "' to '" << TargetN << "'\n");
517 LLVM_DEBUG(dbgs() << "Deleting outgoing edge from '"
518 << N << "' to '" << TargetN << "'\n");
518519 return true;
519520 }),
520521 DeadTargets.end());
545546 assert(NewRC != RC && "Should not encounter the current RefSCC further "
546547 "in the postorder list of new RefSCCs.");
547548 UR.RCWorklist.insert(NewRC);
548 DEBUG(dbgs() << "Enqueuing a new RefSCC in the update worklist: "
549 << *NewRC << "\n");
549 LLVM_DEBUG(dbgs() << "Enqueuing a new RefSCC in the update worklist: "
550 << *NewRC << "\n");
550551 }
551552 }
552553
563564 assert(RC->isAncestorOf(TargetRC) &&
564565 "Cannot potentially form RefSCC cycles here!");
565566 RC->switchOutgoingEdgeToRef(N, *RefTarget);
566 DEBUG(dbgs() << "Switch outgoing call edge to a ref edge from '" << N
567 << "' to '" << *RefTarget << "'\n");
567 LLVM_DEBUG(dbgs() << "Switch outgoing call edge to a ref edge from '" << N
568 << "' to '" << *RefTarget << "'\n");
568569 continue;
569570 }
570571
592593 assert(RC->isAncestorOf(TargetRC) &&
593594 "Cannot potentially form RefSCC cycles here!");
594595 RC->switchOutgoingEdgeToCall(N, *CallTarget);
595 DEBUG(dbgs() << "Switch outgoing ref edge to a call edge from '" << N
596 << "' to '" << *CallTarget << "'\n");
596 LLVM_DEBUG(dbgs() << "Switch outgoing ref edge to a call edge from '" << N
597 << "' to '" << *CallTarget << "'\n");
597598 continue;
598599 }
599 DEBUG(dbgs() << "Switch an internal ref edge to a call edge from '" << N
600 << "' to '" << *CallTarget << "'\n");
600 LLVM_DEBUG(dbgs() << "Switch an internal ref edge to a call edge from '"
601 << N << "' to '" << *CallTarget << "'\n");
601602
602603 // Otherwise we are switching an internal ref edge to a call edge. This
603604 // may merge away some SCCs, and we add those to the UpdateResult. We also
660661 // post-order sequence, and may end up observing more precise context to
661662 // optimize the current SCC.
662663 UR.CWorklist.insert(C);
663 DEBUG(dbgs() << "Enqueuing the existing SCC in the worklist: " << *C
664 << "\n");
664 LLVM_DEBUG(dbgs() << "Enqueuing the existing SCC in the worklist: " << *C
665 << "\n");
665666 // Enqueue in reverse order as we pop off the back of the worklist.
666667 for (SCC &MovedC : llvm::reverse(make_range(RC->begin() + InitialSCCIndex,
667668 RC->begin() + NewSCCIndex))) {
668669 UR.CWorklist.insert(&MovedC);
669 DEBUG(dbgs() << "Enqueuing a newly earlier in post-order SCC: "
670 << MovedC << "\n");
670 LLVM_DEBUG(dbgs() << "Enqueuing a newly earlier in post-order SCC: "
671 << MovedC << "\n");
671672 }
672673 }
673674 }
161161 // The function pass(es) modified the IR, they may have clobbered the
162162 // callgraph.
163163 if (Changed && CallGraphUpToDate) {
164 DEBUG(dbgs() << "CGSCCPASSMGR: Pass Dirtied SCC: "
165 << P->getPassName() << '\n');
164 LLVM_DEBUG(dbgs() << "CGSCCPASSMGR: Pass Dirtied SCC: " << P->getPassName()
165 << '\n');
166166 CallGraphUpToDate = false;
167167 }
168168 return Changed;
180180 bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,
181181 bool CheckingMode) {
182182 DenseMap CallSites;
183
184 DEBUG(dbgs() << "CGSCCPASSMGR: Refreshing SCC with " << CurSCC.size()
185 << " nodes:\n";
186 for (CallGraphNode *CGN : CurSCC)
187 CGN->dump();
188 );
183
184 LLVM_DEBUG(dbgs() << "CGSCCPASSMGR: Refreshing SCC with " << CurSCC.size()
185 << " nodes:\n";
186 for (CallGraphNode *CGN
187 : CurSCC) CGN->dump(););
189188
190189 bool MadeChange = false;
191190 bool DevirtualizedCall = false;
306305 // one.
307306 if (!ExistingNode->getFunction()) {
308307 DevirtualizedCall = true;
309 DEBUG(dbgs() << " CGSCCPASSMGR: Devirtualized call to '"
310 << Callee->getName() << "'\n");
308 LLVM_DEBUG(dbgs() << " CGSCCPASSMGR: Devirtualized call to '"
309 << Callee->getName() << "'\n");
311310 }
312311 } else {
313312 CalleeNode = CG.getCallsExternalNode();
362361 CallSites.clear();
363362 }
364363
365 DEBUG(if (MadeChange) {
366 dbgs() << "CGSCCPASSMGR: Refreshed SCC is now:\n";
367 for (CallGraphNode *CGN : CurSCC)
368 CGN->dump();
369 if (DevirtualizedCall)
370 dbgs() << "CGSCCPASSMGR: Refresh devirtualized a call!\n";
371
372 } else {
373 dbgs() << "CGSCCPASSMGR: SCC Refresh didn't change call graph.\n";
374 }
375 );
364 LLVM_DEBUG(if (MadeChange) {
365 dbgs() << "CGSCCPASSMGR: Refreshed SCC is now:\n";
366 for (CallGraphNode *CGN : CurSCC)
367 CGN->dump();
368 if (DevirtualizedCall)
369 dbgs() << "CGSCCPASSMGR: Refresh devirtualized a call!\n";
370 } else {
371 dbgs() << "CGSCCPASSMGR: SCC Refresh didn't change call graph.\n";
372 });
376373 (void)MadeChange;
377374
378375 return DevirtualizedCall;
471468 unsigned Iteration = 0;
472469 bool DevirtualizedCall = false;
473470 do {
474 DEBUG(if (Iteration)
475 dbgs() << " SCCPASSMGR: Re-visiting SCC, iteration #"
476 << Iteration << '\n');
471 LLVM_DEBUG(if (Iteration) dbgs()
472 << " SCCPASSMGR: Re-visiting SCC, iteration #" << Iteration
473 << '\n');
477474 DevirtualizedCall = false;
478475 Changed |= RunAllPassesOnSCC(CurSCC, CG, DevirtualizedCall);
479476 } while (Iteration++ < MaxIterations && DevirtualizedCall);
480477
481478 if (DevirtualizedCall)
482 DEBUG(dbgs() << " CGSCCPASSMGR: Stopped iteration after " << Iteration
483 << " times, due to -max-cg-scc-iterations\n");
479 LLVM_DEBUG(dbgs() << " CGSCCPASSMGR: Stopped iteration after "
480 << Iteration
481 << " times, due to -max-cg-scc-iterations\n");
484482
485483 MaxSCCIterations.updateMax(Iteration);
486484 }
6060 continue;
6161
6262 EphValues.insert(V);
63 DEBUG(dbgs() << "Ephemeral Value: " << *V << "\n");
63 LLVM_DEBUG(dbgs() << "Ephemeral Value: " << *V << "\n");
6464
6565 // Append any more operands to consider.
6666 appendSpeculatableOperands(V, Visited, Worklist);
282282 if (!isAlwaysLive(&I))
283283 continue;
284284
285 DEBUG(dbgs() << "DemandedBits: Root: " << I << "\n");
285 LLVM_DEBUG(dbgs() << "DemandedBits: Root: " << I << "\n");
286286 // For integer-valued instructions, set up an initial empty set of alive
287287 // bits and add the instruction to the work list. For other instructions
288288 // add their operands to the work list (for integer values operands, mark
312312 while (!Worklist.empty()) {
313313 Instruction *UserI = Worklist.pop_back_val();
314314
315 DEBUG(dbgs() << "DemandedBits: Visiting: " << *UserI);
315 LLVM_DEBUG(dbgs() << "DemandedBits: Visiting: " << *UserI);
316316 APInt AOut;
317317 if (UserI->getType()->isIntegerTy()) {
318318 AOut = AliveBits[UserI];
319 DEBUG(dbgs() << " Alive Out: " << AOut);
320 }
321 DEBUG(dbgs() << "\n");
319 LLVM_DEBUG(dbgs() << " Alive Out: " << AOut);
320 }
321 LLVM_DEBUG(dbgs() << "\n");
322322
323323 if (!UserI->getType()->isIntegerTy())
324324 Visited.insert(UserI);
414414 // PLDI 1991
415415 bool DependenceInfo::intersectConstraints(Constraint *X, const Constraint *Y) {
416416 ++DeltaApplications;
417 DEBUG(dbgs() << "\tintersect constraints\n");
418 DEBUG(dbgs() << "\t X ="; X->dump(dbgs()));
419 DEBUG(dbgs() << "\t Y ="; Y->dump(dbgs()));
417 LLVM_DEBUG(dbgs() << "\tintersect constraints\n");
418 LLVM_DEBUG(dbgs() << "\t X ="; X->dump(dbgs()));
419 LLVM_DEBUG(dbgs() << "\t Y ="; Y->dump(dbgs()));
420420 assert(!Y->isPoint() && "Y must not be a Point");
421421 if (X->isAny()) {
422422 if (Y->isAny())
432432 }
433433
434434 if (X->isDistance() && Y->isDistance()) {
435 DEBUG(dbgs() << "\t intersect 2 distances\n");
435 LLVM_DEBUG(dbgs() << "\t intersect 2 distances\n");
436436 if (isKnownPredicate(CmpInst::ICMP_EQ, X->getD(), Y->getD()))
437437 return false;
438438 if (isKnownPredicate(CmpInst::ICMP_NE, X->getD(), Y->getD())) {
459459 "We shouldn't ever see X->isPoint() && Y->isPoint()");
460460
461461 if (X->isLine() && Y->isLine()) {
462 DEBUG(dbgs() << "\t intersect 2 lines\n");
462 LLVM_DEBUG(dbgs() << "\t intersect 2 lines\n");
463463 const SCEV *Prod1 = SE->getMulExpr(X->getA(), Y->getB());
464464 const SCEV *Prod2 = SE->getMulExpr(X->getB(), Y->getA());
465465 if (isKnownPredicate(CmpInst::ICMP_EQ, Prod1, Prod2)) {
466466 // slopes are equal, so lines are parallel
467 DEBUG(dbgs() << "\t\tsame slope\n");
467 LLVM_DEBUG(dbgs() << "\t\tsame slope\n");
468468 Prod1 = SE->getMulExpr(X->getC(), Y->getB());
469469 Prod2 = SE->getMulExpr(X->getB(), Y->getC());
470470 if (isKnownPredicate(CmpInst::ICMP_EQ, Prod1, Prod2))
478478 }
479479 if (isKnownPredicate(CmpInst::ICMP_NE, Prod1, Prod2)) {
480480 // slopes differ, so lines intersect
481 DEBUG(dbgs() << "\t\tdifferent slopes\n");
481 LLVM_DEBUG(dbgs() << "\t\tdifferent slopes\n");
482482 const SCEV *C1B2 = SE->getMulExpr(X->getC(), Y->getB());
483483 const SCEV *C1A2 = SE->getMulExpr(X->getC(), Y->getA());
484484 const SCEV *C2B1 = SE->getMulExpr(Y->getC(), X->getB());
500500 APInt Xbot = A1B2_A2B1->getAPInt();
501501 APInt Ytop = C1A2_C2A1->getAPInt();
502502 APInt Ybot = A2B1_A1B2->getAPInt();
503 DEBUG(dbgs() << "\t\tXtop = " << Xtop << "\n");
504 DEBUG(dbgs() << "\t\tXbot = " << Xbot << "\n");
505 DEBUG(dbgs() << "\t\tYtop = " << Ytop << "\n");
506 DEBUG(dbgs() << "\t\tYbot = " << Ybot << "\n");
503 LLVM_DEBUG(dbgs() << "\t\tXtop = " << Xtop << "\n");
504 LLVM_DEBUG(dbgs() << "\t\tXbot = " << Xbot << "\n");
505 LLVM_DEBUG(dbgs() << "\t\tYtop = " << Ytop << "\n");
506 LLVM_DEBUG(dbgs() << "\t\tYbot = " << Ybot << "\n");
507507 APInt Xq = Xtop; // these need to be initialized, even
508508 APInt Xr = Xtop; // though they're just going to be overwritten
509509 APInt::sdivrem(Xtop, Xbot, Xq, Xr);
515515 ++DeltaSuccesses;
516516 return true;
517517 }
518 DEBUG(dbgs() << "\t\tX = " << Xq << ", Y = " << Yq << "\n");
518 LLVM_DEBUG(dbgs() << "\t\tX = " << Xq << ", Y = " << Yq << "\n");
519519 if (Xq.slt(0) || Yq.slt(0)) {
520520 X->setEmpty();
521521 ++DeltaSuccesses;
524524 if (const SCEVConstant *CUB =
525525 collectConstantUpperBound(X->getAssociatedLoop(), Prod1->getType())) {
526526 const APInt &UpperBound = CUB->getAPInt();
527 DEBUG(dbgs() << "\t\tupper bound = " << UpperBound << "\n");
527 LLVM_DEBUG(dbgs() << "\t\tupper bound = " << UpperBound << "\n");
528528 if (Xq.sgt(UpperBound) || Yq.sgt(UpperBound)) {
529529 X->setEmpty();
530530 ++DeltaSuccesses;
544544 assert(!(X->isLine() && Y->isPoint()) && "This case should never occur");
545545
546546 if (X->isPoint() && Y->isLine()) {
547 DEBUG(dbgs() << "\t intersect Point and Line\n");
547 LLVM_DEBUG(dbgs() << "\t intersect Point and Line\n");
548548 const SCEV *A1X1 = SE->getMulExpr(Y->getA(), X->getX());
549549 const SCEV *B1Y1 = SE->getMulExpr(Y->getB(), X->getY());
550550 const SCEV *Sum = SE->getAddExpr(A1X1, B1Y1);
10321032 // Return true if dependence disproved.
10331033 bool DependenceInfo::testZIV(const SCEV *Src, const SCEV *Dst,
10341034 FullDependence &Result) const {
1035 DEBUG(dbgs() << " src = " << *Src << "\n");
1036 DEBUG(dbgs() << " dst = " << *Dst << "\n");
1035 LLVM_DEBUG(dbgs() << " src = " << *Src << "\n");
1036 LLVM_DEBUG(dbgs() << " dst = " << *Dst << "\n");
10371037 ++ZIVapplications;
10381038 if (isKnownPredicate(CmpInst::ICMP_EQ, Src, Dst)) {
1039 DEBUG(dbgs() << " provably dependent\n");
1039 LLVM_DEBUG(dbgs() << " provably dependent\n");
10401040 return false; // provably dependent
10411041 }
10421042 if (isKnownPredicate(CmpInst::ICMP_NE, Src, Dst)) {
1043 DEBUG(dbgs() << " provably independent\n");
1043 LLVM_DEBUG(dbgs() << " provably independent\n");
10441044 ++ZIVindependence;
10451045 return true; // provably independent
10461046 }
1047 DEBUG(dbgs() << " possibly dependent\n");
1047 LLVM_DEBUG(dbgs() << " possibly dependent\n");
10481048 Result.Consistent = false;
10491049 return false; // possibly dependent
10501050 }
10811081 const SCEV *DstConst, const Loop *CurLoop,
10821082 unsigned Level, FullDependence &Result,
10831083 Constraint &NewConstraint) const {
1084 DEBUG(dbgs() << "\tStrong SIV test\n");
1085 DEBUG(dbgs() << "\t Coeff = " << *Coeff);
1086 DEBUG(dbgs() << ", " << *Coeff->getType() << "\n");
1087 DEBUG(dbgs() << "\t SrcConst = " << *SrcConst);
1088 DEBUG(dbgs() << ", " << *SrcConst->getType() << "\n");
1089 DEBUG(dbgs() << "\t DstConst = " << *DstConst);
1090 DEBUG(dbgs() << ", " << *DstConst->getType() << "\n");
1084 LLVM_DEBUG(dbgs() << "\tStrong SIV test\n");
1085 LLVM_DEBUG(dbgs() << "\t Coeff = " << *Coeff);
1086 LLVM_DEBUG(dbgs() << ", " << *Coeff->getType() << "\n");
1087 LLVM_DEBUG(dbgs() << "\t SrcConst = " << *SrcConst);
1088 LLVM_DEBUG(dbgs() << ", " << *SrcConst->getType() << "\n");
1089 LLVM_DEBUG(dbgs() << "\t DstConst = " << *DstConst);
1090 LLVM_DEBUG(dbgs() << ", " << *DstConst->getType() << "\n");
10911091 ++StrongSIVapplications;
10921092 assert(0 < Level && Level <= CommonLevels && "level out of range");
10931093 Level--;
10941094
10951095 const SCEV *Delta = SE->getMinusSCEV(SrcConst, DstConst);
1096 DEBUG(dbgs() << "\t Delta = " << *Delta);
1097 DEBUG(dbgs() << ", " << *Delta->getType() << "\n");
1096 LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta);
1097 LLVM_DEBUG(dbgs() << ", " << *Delta->getType() << "\n");
10981098
10991099 // check that |Delta| < iteration count
11001100 if (const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->getType())) {
1101 DEBUG(dbgs() << "\t UpperBound = " << *UpperBound);
1102 DEBUG(dbgs() << ", " << *UpperBound->getType() << "\n");
1101 LLVM_DEBUG(dbgs() << "\t UpperBound = " << *UpperBound);
1102 LLVM_DEBUG(dbgs() << ", " << *UpperBound->getType() << "\n");
11031103 const SCEV *AbsDelta =
11041104 SE->isKnownNonNegative(Delta) ? Delta : SE->getNegativeSCEV(Delta);
11051105 const SCEV *AbsCoeff =
11201120 APInt Distance = ConstDelta; // these need to be initialized
11211121 APInt Remainder = ConstDelta;
11221122 APInt::sdivrem(ConstDelta, ConstCoeff, Distance, Remainder);
1123 DEBUG(dbgs() << "\t Distance = " << Distance << "\n");
1124 DEBUG(dbgs() << "\t Remainder = " << Remainder << "\n");
1123 LLVM_DEBUG(dbgs() << "\t Distance = " << Distance << "\n");
1124 LLVM_DEBUG(dbgs() << "\t Remainder = " << Remainder << "\n");
11251125 // Make sure Coeff divides Delta exactly
11261126 if (Remainder != 0) {
11271127 // Coeff doesn't divide Distance, no dependence
11481148 }
11491149 else {
11501150 if (Coeff->isOne()) {
1151 DEBUG(dbgs() << "\t Distance = " << *Delta << "\n");
1151 LLVM_DEBUG(dbgs() << "\t Distance = " << *Delta << "\n");
11521152 Result.DV[Level].Distance = Delta; // since X/1 == X
11531153 NewConstraint.setDistance(Delta, CurLoop);
11541154 }
12171217 const SCEV *Coeff, const SCEV *SrcConst, const SCEV *DstConst,
12181218 const Loop *CurLoop, unsigned Level, FullDependence &Result,
12191219 Constraint &NewConstraint, const SCEV *&SplitIter) const {
1220 DEBUG(dbgs() << "\tWeak-Crossing SIV test\n");
1221 DEBUG(dbgs() << "\t Coeff = " << *Coeff << "\n");
1222 DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1223 DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
1220 LLVM_DEBUG(dbgs() << "\tWeak-Crossing SIV test\n");
1221 LLVM_DEBUG(dbgs() << "\t Coeff = " << *Coeff << "\n");
1222 LLVM_DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1223 LLVM_DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
12241224 ++WeakCrossingSIVapplications;
12251225 assert(0 < Level && Level <= CommonLevels && "Level out of range");
12261226 Level--;
12271227 Result.Consistent = false;
12281228 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1229 DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
1229 LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
12301230 NewConstraint.setLine(Coeff, Coeff, Delta, CurLoop);
12311231 if (Delta->isZero()) {
12321232 Result.DV[Level].Direction &= unsigned(~Dependence::DVEntry::LT);
12561256 SplitIter = SE->getUDivExpr(
12571257 SE->getSMaxExpr(SE->getZero(Delta->getType()), Delta),
12581258 SE->getMulExpr(SE->getConstant(Delta->getType(), 2), ConstCoeff));
1259 DEBUG(dbgs() << "\t Split iter = " << *SplitIter << "\n");
1259 LLVM_DEBUG(dbgs() << "\t Split iter = " << *SplitIter << "\n");
12601260
12611261 const SCEVConstant *ConstDelta = dyn_cast(Delta);
12621262 if (!ConstDelta)
12641264
12651265 // We're certain that ConstCoeff > 0; therefore,
12661266 // if Delta < 0, then no dependence.
1267 DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
1268 DEBUG(dbgs() << "\t ConstCoeff = " << *ConstCoeff << "\n");
1267 LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
1268 LLVM_DEBUG(dbgs() << "\t ConstCoeff = " << *ConstCoeff << "\n");
12691269 if (SE->isKnownNegative(Delta)) {
12701270 // No dependence, Delta < 0
12711271 ++WeakCrossingSIVindependence;
12761276 // We're certain that Delta > 0 and ConstCoeff > 0.
12771277 // Check Delta/(2*ConstCoeff) against upper loop bound
12781278 if (const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->getType())) {
1279 DEBUG(dbgs() << "\t UpperBound = " << *UpperBound << "\n");
1279 LLVM_DEBUG(dbgs() << "\t UpperBound = " << *UpperBound << "\n");
12801280 const SCEV *ConstantTwo = SE->getConstant(UpperBound->getType(), 2);
12811281 const SCEV *ML = SE->getMulExpr(SE->getMulExpr(ConstCoeff, UpperBound),
12821282 ConstantTwo);
1283 DEBUG(dbgs() << "\t ML = " << *ML << "\n");
1283 LLVM_DEBUG(dbgs() << "\t ML = " << *ML << "\n");
12841284 if (isKnownPredicate(CmpInst::ICMP_SGT, Delta, ML)) {
12851285 // Delta too big, no dependence
12861286 ++WeakCrossingSIVindependence;
13081308 APInt Distance = APDelta; // these need to be initialzed
13091309 APInt Remainder = APDelta;
13101310 APInt::sdivrem(APDelta, APCoeff, Distance, Remainder);
1311 DEBUG(dbgs() << "\t Remainder = " << Remainder << "\n");
1311 LLVM_DEBUG(dbgs() << "\t Remainder = " << Remainder << "\n");
13121312 if (Remainder != 0) {
13131313 // Coeff doesn't divide Delta, no dependence
13141314 ++WeakCrossingSIVindependence;
13151315 ++WeakCrossingSIVsuccesses;
13161316 return true;
13171317 }
1318 DEBUG(dbgs() << "\t Distance = " << Distance << "\n");
1318 LLVM_DEBUG(dbgs() << "\t Distance = " << Distance << "\n");
13191319
13201320 // if 2*Coeff doesn't divide Delta, then the equal direction isn't possible
13211321 APInt Two = APInt(Distance.getBitWidth(), 2, true);
13221322 Remainder = Distance.srem(Two);
1323 DEBUG(dbgs() << "\t Remainder = " << Remainder << "\n");
1323 LLVM_DEBUG(dbgs() << "\t Remainder = " << Remainder << "\n");
13241324 if (Remainder != 0) {
13251325 // Equal direction isn't possible
13261326 Result.DV[Level].Direction &= unsigned(~Dependence::DVEntry::EQ);
13561356 APInt::sdivrem(G0, G1, Q, R);
13571357 }
13581358 G = G1;
1359 DEBUG(dbgs() << "\t GCD = " << G << "\n");
1359 LLVM_DEBUG(dbgs() << "\t GCD = " << G << "\n");
13601360 X = AM.slt(0) ? -A1 : A1;
13611361 Y = BM.slt(0) ? B1 : -B1;
13621362
14291429 const Loop *CurLoop, unsigned Level,
14301430 FullDependence &Result,
14311431 Constraint &NewConstraint) const {
1432 DEBUG(dbgs() << "\tExact SIV test\n");
1433 DEBUG(dbgs() << "\t SrcCoeff = " << *SrcCoeff << " = AM\n");
1434 DEBUG(dbgs() << "\t DstCoeff = " << *DstCoeff << " = BM\n");
1435 DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1436 DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
1432 LLVM_DEBUG(dbgs() << "\tExact SIV test\n");
1433 LLVM_DEBUG(dbgs() << "\t SrcCoeff = " << *SrcCoeff << " = AM\n");
1434 LLVM_DEBUG(dbgs() << "\t DstCoeff = " << *DstCoeff << " = BM\n");
1435 LLVM_DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1436 LLVM_DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
14371437 ++ExactSIVapplications;
14381438 assert(0 < Level && Level <= CommonLevels && "Level out of range");
14391439 Level--;
14401440 Result.Consistent = false;
14411441 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1442 DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
1442 LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
14431443 NewConstraint.setLine(SrcCoeff, SE->getNegativeSCEV(DstCoeff),
14441444 Delta, CurLoop);
14451445 const SCEVConstant *ConstDelta = dyn_cast(Delta);
14601460 return true;
14611461 }
14621462
1463 DEBUG(dbgs() << "\t X = " << X << ", Y = " << Y << "\n");
1463 LLVM_DEBUG(dbgs() << "\t X = " << X << ", Y = " << Y << "\n");
14641464
14651465 // since SCEV construction normalizes, LM = 0
14661466 APInt UM(Bits, 1, true);
14691469 if (const SCEVConstant *CUB =
14701470 collectConstantUpperBound(CurLoop, Delta->getType())) {
14711471 UM = CUB->getAPInt();
1472 DEBUG(dbgs() << "\t UM = " << UM << "\n");
1472 LLVM_DEBUG(dbgs() << "\t UM = " << UM << "\n");
14731473 UMvalid = true;
14741474 }
14751475
14801480 APInt TMUL = BM.sdiv(G);
14811481 if (TMUL.sgt(0)) {
14821482 TL = maxAPInt(TL, ceilingOfQuotient(-X, TMUL));
1483 DEBUG(dbgs() << "\t TL = " << TL << "\n");
1483 LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
14841484 if (UMvalid) {
14851485 TU = minAPInt(TU, floorOfQuotient(UM - X, TMUL));
1486 DEBUG(dbgs() << "\t TU = " << TU << "\n");
1486 LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
14871487 }
14881488 }
14891489 else {
14901490 TU = minAPInt(TU, floorOfQuotient(-X, TMUL));
1491 DEBUG(dbgs() << "\t TU = " << TU << "\n");
1491 LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
14921492 if (UMvalid) {
14931493 TL = maxAPInt(TL, ceilingOfQuotient(UM - X, TMUL));
1494 DEBUG(dbgs() << "\t TL = " << TL << "\n");
1494 LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
14951495 }
14961496 }
14971497
14991499 TMUL = AM.sdiv(G);
15001500 if (TMUL.sgt(0)) {
15011501 TL = maxAPInt(TL, ceilingOfQuotient(-Y, TMUL));
1502 DEBUG(dbgs() << "\t TL = " << TL << "\n");
1502 LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
15031503 if (UMvalid) {
15041504 TU = minAPInt(TU, floorOfQuotient(UM - Y, TMUL));
1505 DEBUG(dbgs() << "\t TU = " << TU << "\n");
1505 LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
15061506 }
15071507 }
15081508 else {
15091509 TU = minAPInt(TU, floorOfQuotient(-Y, TMUL));
1510 DEBUG(dbgs() << "\t TU = " << TU << "\n");
1510 LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
15111511 if (UMvalid) {
15121512 TL = maxAPInt(TL, ceilingOfQuotient(UM - Y, TMUL));
1513 DEBUG(dbgs() << "\t TL = " << TL << "\n");
1513 LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
15141514 }
15151515 }
15161516 if (TL.sgt(TU)) {
15251525 // less than
15261526 APInt SaveTU(TU); // save these
15271527 APInt SaveTL(TL);
1528 DEBUG(dbgs() << "\t exploring LT direction\n");
1528 LLVM_DEBUG(dbgs() << "\t exploring LT direction\n");
15291529 TMUL = AM - BM;
15301530 if (TMUL.sgt(0)) {
15311531 TL = maxAPInt(TL, ceilingOfQuotient(X - Y + 1, TMUL));
1532 DEBUG(dbgs() << "\t\t TL = " << TL << "\n");
1532 LLVM_DEBUG(dbgs() << "\t\t TL = " << TL << "\n");
15331533 }
15341534 else {
15351535 TU = minAPInt(TU, floorOfQuotient(X - Y + 1, TMUL));
1536 DEBUG(dbgs() << "\t\t TU = " << TU << "\n");
1536 LLVM_DEBUG(dbgs() << "\t\t TU = " << TU << "\n");
15371537 }
15381538 if (TL.sle(TU)) {
15391539 NewDirection |= Dependence::DVEntry::LT;
15431543 // equal
15441544 TU = SaveTU; // restore
15451545 TL = SaveTL;
1546 DEBUG(dbgs() << "\t exploring EQ direction\n");
1546 LLVM_DEBUG(dbgs() << "\t exploring EQ direction\n");
15471547 if (TMUL.sgt(0)) {
15481548 TL = maxAPInt(TL, ceilingOfQuotient(X - Y, TMUL));
1549 DEBUG(dbgs() << "\t\t TL = " << TL << "\n");
1549 LLVM_DEBUG(dbgs() << "\t\t TL = " << TL << "\n");
15501550 }
15511551 else {
15521552 TU = minAPInt(TU, floorOfQuotient(X - Y, TMUL));
1553 DEBUG(dbgs() << "\t\t TU = " << TU << "\n");
1553 LLVM_DEBUG(dbgs() << "\t\t TU = " << TU << "\n");
15541554 }
15551555 TMUL = BM - AM;
15561556 if (TMUL.sgt(0)) {
15571557 TL = maxAPInt(TL, ceilingOfQuotient(Y - X, TMUL));
1558 DEBUG(dbgs() << "\t\t TL = " << TL << "\n");
1558 LLVM_DEBUG(dbgs() << "\t\t TL = " << TL << "\n");
15591559 }
15601560 else {
15611561 TU = minAPInt(TU, floorOfQuotient(Y - X, TMUL));
1562 DEBUG(dbgs() << "\t\t TU = " << TU << "\n");
1562 LLVM_DEBUG(dbgs() << "\t\t TU = " << TU << "\n");
15631563 }
15641564 if (TL.sle(TU)) {
15651565 NewDirection |= Dependence::DVEntry::EQ;
15691569 // greater than
15701570 TU = SaveTU; // restore
15711571 TL = SaveTL;
1572 DEBUG(dbgs() << "\t exploring GT direction\n");
1572 LLVM_DEBUG(dbgs() << "\t exploring GT direction\n");
15731573 if (TMUL.sgt(0)) {
15741574 TL = maxAPInt(TL, ceilingOfQuotient(Y - X + 1, TMUL));
1575 DEBUG(dbgs() << "\t\t TL = " << TL << "\n");
1575 LLVM_DEBUG(dbgs() << "\t\t TL = " << TL << "\n");
15761576 }
15771577 else {
15781578 TU = minAPInt(TU, floorOfQuotient(Y - X + 1, TMUL));
1579 DEBUG(dbgs() << "\t\t TU = " << TU << "\n");
1579 LLVM_DEBUG(dbgs() << "\t\t TU = " << TU << "\n");
15801580 }
15811581 if (TL.sle(TU)) {
15821582 NewDirection |= Dependence::DVEntry::GT;
16421642 // For the WeakSIV test, it's possible the loop isn't common to
16431643 // the Src and Dst loops. If it isn't, then there's no need to
16441644 // record a direction.
1645 DEBUG(dbgs() << "\tWeak-Zero (src) SIV test\n");
1646 DEBUG(dbgs() << "\t DstCoeff = " << *DstCoeff << "\n");
1647 DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1648 DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
1645 LLVM_DEBUG(dbgs() << "\tWeak-Zero (src) SIV test\n");
1646 LLVM_DEBUG(dbgs() << "\t DstCoeff = " << *DstCoeff << "\n");
1647 LLVM_DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1648 LLVM_DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
16491649 ++WeakZeroSIVapplications;
16501650 assert(0 < Level && Level <= MaxLevels && "Level out of range");
16511651 Level--;
16531653 const SCEV *Delta = SE->getMinusSCEV(SrcConst, DstConst);
16541654 NewConstraint.setLine(SE->getZero(Delta->getType()), DstCoeff, Delta,
16551655 CurLoop);
1656 DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
1656 LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
16571657 if (isKnownPredicate(CmpInst::ICMP_EQ, SrcConst, DstConst)) {
16581658 if (Level < CommonLevels) {
16591659 Result.DV[Level].Direction &= Dependence::DVEntry::LE;
16741674 // check that Delta/SrcCoeff < iteration count
16751675 // really check NewDelta < count*AbsCoeff
16761676 if (const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->getType())) {
1677 DEBUG(dbgs() << "\t UpperBound = " << *UpperBound << "\n");
1677 LLVM_DEBUG(dbgs() << "\t UpperBound = " << *UpperBound << "\n");
16781678 const SCEV *Product = SE->getMulExpr(AbsCoeff, UpperBound);
16791679 if (isKnownPredicate(CmpInst::ICMP_SGT, NewDelta, Product)) {
16801680 ++WeakZeroSIVindependence;
17511751 Constraint &NewConstraint) const {
17521752 // For the WeakSIV test, it's possible the loop isn't common to the
17531753 // Src and Dst loops. If it isn't, then there's no need to record a direction.
1754 DEBUG(dbgs() << "\tWeak-Zero (dst) SIV test\n");
1755 DEBUG(dbgs() << "\t SrcCoeff = " << *SrcCoeff << "\n");
1756 DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1757 DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
1754 LLVM_DEBUG(dbgs() << "\tWeak-Zero (dst) SIV test\n");
1755 LLVM_DEBUG(dbgs() << "\t SrcCoeff = " << *SrcCoeff << "\n");
1756 LLVM_DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1757 LLVM_DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
17581758 ++WeakZeroSIVapplications;
17591759 assert(0 < Level && Level <= SrcLevels && "Level out of range");
17601760 Level--;
17621762 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
17631763 NewConstraint.setLine(SrcCoeff, SE->getZero(Delta->getType()), Delta,
17641764 CurLoop);
1765 DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
1765 LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
17661766 if (isKnownPredicate(CmpInst::ICMP_EQ, DstConst, SrcConst)) {
17671767 if (Level < CommonLevels) {
17681768 Result.DV[Level].Direction &= Dependence::DVEntry::LE;
17831783 // check that Delta/SrcCoeff < iteration count
17841784 // really check NewDelta < count*AbsCoeff
17851785 if (const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->getType())) {
1786 DEBUG(dbgs() << "\t UpperBound = " << *UpperBound << "\n");
1786 LLVM_DEBUG(dbgs() << "\t UpperBound = " << *UpperBound << "\n");
17871787 const SCEV *Product = SE->getMulExpr(AbsCoeff, UpperBound);
17881788 if (isKnownPredicate(CmpInst::ICMP_SGT, NewDelta, Product)) {
17891789 ++WeakZeroSIVindependence;
18321832 const SCEV *SrcConst, const SCEV *DstConst,
18331833 const Loop *SrcLoop, const Loop *DstLoop,
18341834 FullDependence &Result) const {
1835 DEBUG(dbgs() << "\tExact RDIV test\n");
1836 DEBUG(dbgs() << "\t SrcCoeff = " << *SrcCoeff << " = AM\n");
1837 DEBUG(dbgs() << "\t DstCoeff = " << *DstCoeff << " = BM\n");
1838 DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1839 DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
1835 LLVM_DEBUG(dbgs() << "\tExact RDIV test\n");
1836 LLVM_DEBUG(dbgs() << "\t SrcCoeff = " << *SrcCoeff << " = AM\n");
1837 LLVM_DEBUG(dbgs() << "\t DstCoeff = " << *DstCoeff << " = BM\n");
1838 LLVM_DEBUG(dbgs() << "\t SrcConst = " << *SrcConst << "\n");
1839 LLVM_DEBUG(dbgs() << "\t DstConst = " << *DstConst << "\n");
18401840 ++ExactRDIVapplications;
18411841 Result.Consistent = false;
18421842 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
1843 DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
1843 LLVM_DEBUG(dbgs() << "\t Delta = " << *Delta << "\n");
18441844 const SCEVConstant *ConstDelta = dyn_cast(Delta);
18451845 const SCEVConstant *ConstSrcCoeff = dyn_cast(SrcCoeff);
18461846 const SCEVConstant *ConstDstCoeff = dyn_cast(DstCoeff);
18581858 return true;
18591859 }
18601860
1861 DEBUG(dbgs() << "\t X = " << X << ", Y = " << Y << "\n");
1861 LLVM_DEBUG(dbgs() << "\t X = " << X << ", Y = " << Y << "\n");
18621862
18631863 // since SCEV construction seems to normalize, LM = 0
18641864 APInt SrcUM(Bits, 1, true);
18671867 if (const SCEVConstant *UpperBound =
18681868 collectConstantUpperBound(SrcLoop, Delta->getType())) {
18691869 SrcUM = UpperBound->getAPInt();
1870 DEBUG(dbgs() << "\t SrcUM = " << SrcUM << "\n");
1870 LLVM_DEBUG(dbgs() << "\t SrcUM = " << SrcUM << "\n");
18711871 SrcUMvalid = true;
18721872 }
18731873
18771877 if (const SCEVConstant *UpperBound =
18781878 collectConstantUpperBound(DstLoop, Delta->getType())) {
18791879 DstUM = UpperBound->getAPInt();
1880 DEBUG(dbgs() << "\t DstUM = " << DstUM << "\n");
1880 LLVM_DEBUG(dbgs() << "\t DstUM = " << DstUM << "\n");
18811881 DstUMvalid = true;
18821882 }
18831883
18881888 APInt TMUL = BM.sdiv(G);
18891889 if (TMUL.sgt(0)) {
18901890 TL = maxAPInt(TL, ceilingOfQuotient(-X, TMUL));
1891 DEBUG(dbgs() << "\t TL = " << TL << "\n");
1891 LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
18921892 if (SrcUMvalid) {
18931893 TU = minAPInt(TU, floorOfQuotient(SrcUM - X, TMUL));
1894 DEBUG(dbgs() << "\t TU = " << TU << "\n");
1894 LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
18951895 }
18961896 }
18971897 else {
18981898 TU = minAPInt(TU, floorOfQuotient(-X, TMUL));
1899 DEBUG(dbgs() << "\t TU = " << TU << "\n");
1899 LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
19001900 if (SrcUMvalid) {
19011901 TL = maxAPInt(TL, ceilingOfQuotient(SrcUM - X, TMUL));
1902 DEBUG(dbgs() << "\t TL = " << TL << "\n");
1902 LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
19031903 }
19041904 }
19051905
19071907 TMUL = AM.sdiv(G);
19081908 if (TMUL.sgt(0)) {
19091909 TL = maxAPInt(TL, ceilingOfQuotient(-Y, TMUL));
1910 DEBUG(dbgs() << "\t TL = " << TL << "\n");
1910 LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
19111911 if (DstUMvalid) {
19121912 TU = minAPInt(TU, floorOfQuotient(DstUM - Y, TMUL));
1913 DEBUG(dbgs() << "\t TU = " << TU << "\n");
1913 LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
19141914 }
19151915 }
19161916 else {
19171917 TU = minAPInt(TU, floorOfQuotient(-Y, TMUL));
1918 DEBUG(dbgs() << "\t TU = " << TU << "\n");
1918 LLVM_DEBUG(dbgs() << "\t TU = " << TU << "\n");
19191919 if (DstUMvalid) {
19201920 TL = maxAPInt(TL, ceilingOfQuotient(DstUM - Y, TMUL));
1921 DEBUG(dbgs() << "\t TL = " << TL << "\n");
1921 LLVM_DEBUG(dbgs() << "\t TL = " << TL << "\n");
19221922 }
19231923 }
19241924 if (TL.sgt(TU))
19741974 const Loop *Loop1,
19751975 const Loop *Loop2) const {
19761976 ++SymbolicRDIVapplications;
1977 DEBUG(dbgs() << "\ttry symbolic RDIV test\n");
1978 DEBUG(dbgs() << "\t A1 = " << *A1);
1979 DEBUG(dbgs() << ", type = " << *A1->getType() << "\n");
1980 DEBUG(dbgs() << "\t A2 = " << *A2 << "\n");
1981 DEBUG(dbgs() << "\t C1 = " << *C1 << "\n");
1982 DEBUG(dbgs() << "\t C2 = " << *C2 << "\n");
1977 LLVM_DEBUG(dbgs() << "\ttry symbolic RDIV test\n");
1978 LLVM_DEBUG(dbgs() << "\t A1 = " << *A1);
1979 LLVM_DEBUG(dbgs() << ", type = " << *A1->getType() << "\n");
1980 LLVM_DEBUG(dbgs() << "\t A2 = " << *A2 << "\n");
1981 LLVM_DEBUG(dbgs() << "\t C1 = " << *C1 << "\n");
1982 LLVM_DEBUG(dbgs() << "\t C2 = " << *C2 << "\n");
19831983 const SCEV *N1 = collectUpperBound(Loop1, A1->getType());
19841984 const SCEV *N2 = collectUpperBound(Loop2, A1->getType());
1985 DEBUG(if (N1) dbgs() << "\t N1 = " << *N1 << "\n");
1986 DEBUG(if (N2) dbgs() << "\t N2 = " << *N2 << "\n");
1985 LLVM_DEBUG(if (N1) dbgs() << "\t N1 = " << *N1 << "\n");
1986 LLVM_DEBUG(if (N2) dbgs() << "\t N2 = " << *N2 << "\n");
19871987 const SCEV *C2_C1 = SE->getMinusSCEV(C2, C1);
19881988 const SCEV *C1_C2 = SE->getMinusSCEV(C1, C2);
1989 DEBUG(dbgs() << "\t C2 - C1 = " << *C2_C1 << "\n");
1990 DEBUG(dbgs() << "\t C1 - C2 = " << *C1_C2 << "\n");
1989 LLVM_DEBUG(dbgs() << "\t C2 - C1 = " << *C2_C1 << "\n");
1990 LLVM_DEBUG(dbgs() << "\t C1 - C2 = " << *C1_C2 << "\n");
19911991 if (SE->isKnownNonNegative(A1)) {
19921992 if (SE->isKnownNonNegative(A2)) {
19931993 // A1 >= 0 && A2 >= 0
19941994 if (N1) {
19951995 // make sure that c2 - c1 <= a1*N1
19961996 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
1997 DEBUG(dbgs() << "\t A1*N1 = " << *A1N1 << "\n");
1997 LLVM_DEBUG(dbgs() << "\t A1*N1 = " << *A1N1 << "\n");
19981998 if (isKnownPredicate(CmpInst::ICMP_SGT, C2_C1, A1N1)) {
19991999 ++SymbolicRDIVindependence;
20002000 return true;
20032003 if (N2) {
20042004 // make sure that -a2*N2 <= c2 - c1, or a2*N2 >= c1 - c2
20052005 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2006 DEBUG(dbgs() << "\t A2*N2 = " << *A2N2 << "\n");
2006 LLVM_DEBUG(dbgs() << "\t A2*N2 = " << *A2N2 << "\n");
20072007 if (isKnownPredicate(CmpInst::ICMP_SLT, A2N2, C1_C2)) {
20082008 ++SymbolicRDIVindependence;
20092009 return true;
20172017 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
20182018 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
20192019 const SCEV *A1N1_A2N2 = SE->getMinusSCEV(A1N1, A2N2);
2020 DEBUG(dbgs() << "\t A1*N1 - A2*N2 = " << *A1N1_A2N2 << "\n");
2020 LLVM_DEBUG(dbgs() << "\t A1*N1 - A2*N2 = " << *A1N1_A2N2 << "\n");
20212021 if (isKnownPredicate(CmpInst::ICMP_SGT, C2_C1, A1N1_A2N2)) {
20222022 ++SymbolicRDIVindependence;
20232023 return true;
20382038 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
20392039 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
20402040 const SCEV *A1N1_A2N2 = SE->getMinusSCEV(A1N1, A2N2);
2041 DEBUG(dbgs() << "\t A1*N1 - A2*N2 = " << *A1N1_A2N2 << "\n");
2041 LLVM_DEBUG(dbgs() << "\t A1*N1 - A2*N2 = " << *A1N1_A2N2 << "\n");
20422042 if (isKnownPredicate(CmpInst::ICMP_SGT, A1N1_A2N2, C2_C1)) {
20432043 ++SymbolicRDIVindependence;
20442044 return true;
20552055 if (N1) {
20562056 // make sure that a1*N1 <= c2 - c1
20572057 const SCEV *A1N1 = SE->getMulExpr(A1, N1);
2058 DEBUG(dbgs() << "\t A1*N1 = " << *A1N1 << "\n");
2058 LLVM_DEBUG(dbgs() << "\t A1*N1 = " << *A1N1 << "\n");
20592059 if (isKnownPredicate(CmpInst::ICMP_SGT, A1N1, C2_C1)) {
20602060 ++SymbolicRDIVindependence;
20612061 return true;
20642064 if (N2) {
20652065 // make sure that c2 - c1 <= -a2*N2, or c1 - c2 >= a2*N2
20662066 const SCEV *A2N2 = SE->getMulExpr(A2, N2);
2067 DEBUG(dbgs() << "\t A2*N2 = " << *A2N2 << "\n");
2067 LLVM_DEBUG(dbgs() << "\t A2*N2 = " << *A2N2 << "\n");
20682068 if (isKnownPredicate(CmpInst::ICMP_SLT, C1_C2, A2N2)) {
20692069 ++SymbolicRDIVindependence;
20702070 return true;
20872087 bool DependenceInfo::testSIV(const SCEV *Src, const SCEV *Dst, unsigned &Level,
20882088 FullDependence &Result, Constraint &NewConstraint,
20892089 const SCEV *&SplitIter) const {
2090 DEBUG(dbgs() << " src = " << *Src << "\n");
2091 DEBUG(dbgs() << " dst = " << *Dst << "\n");
2090 LLVM_DEBUG(dbgs() << " src = " << *Src << "\n");
2091 LLVM_DEBUG(dbgs() << " dst = " << *Dst << "\n");
20922092 const SCEVAddRecExpr *SrcAddRec = dyn_cast(Src);
20932093 const SCEVAddRecExpr *DstAddRec = dyn_cast(Dst);
20942094 if (SrcAddRec && DstAddRec) {
21642164 const SCEV *SrcCoeff, *DstCoeff;
21652165 const Loop *SrcLoop, *DstLoop;
21662166
2167 DEBUG(dbgs() << " src = " << *Src << "\n");
2168 DEBUG(dbgs() << " dst = " << *Dst << "\n");
2167 LLVM_DEBUG(dbgs() << " src = " << *Src << "\n");
2168 LLVM_DEBUG(dbgs() << " dst = " << *Dst << "\n");
21692169 const SCEVAddRecExpr *SrcAddRec = dyn_cast(Src);
21702170 const SCEVAddRecExpr *DstAddRec = dyn_cast(Dst);
21712171 if (SrcAddRec && DstAddRec) {
22212221 bool DependenceInfo::testMIV(const SCEV *Src, const SCEV *Dst,
22222222 const SmallBitVector &Loops,
22232223 FullDependence &Result) const {
2224 DEBUG(dbgs() << " src = " << *Src << "\n");
2225 DEBUG(dbgs() << " dst = " << *Dst << "\n");
2224 LLVM_DEBUG(dbgs() << " src = " << *Src << "\n");
2225 LLVM_DEBUG(dbgs() << " dst = " << *Dst << "\n");
22262226 Result.Consistent = false;
22272227 return gcdMIVtest(Src, Dst, Result) ||
22282228 banerjeeMIVtest(Src, Dst, Loops, Result);
22622262 // to "a common divisor".
22632263 bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
22642264 FullDependence &Result) const {
2265 DEBUG(dbgs() << "starting gcd\n");
2265 LLVM_DEBUG(dbgs() << "starting gcd\n");
22662266 ++GCDapplications;
22672267 unsigned BitWidth = SE->getTypeSizeInBits(Src->getType());
22682268 APInt RunningGCD = APInt::getNullValue(BitWidth);
23072307
23082308 APInt ExtraGCD = APInt::getNullValue(BitWidth);
23092309 const SCEV *Delta = SE->getMinusSCEV(DstConst, SrcConst);
2310 DEBUG(dbgs() << " Delta = " << *Delta << "\n");
2310 LLVM_DEBUG(dbgs() << " Delta = " << *Delta << "\n");
23112311 const SCEVConstant *Constant = dyn_cast(Delta);
23122312 if (const SCEVAddExpr *Sum = dyn_cast(Delta)) {
23132313 // If Delta is a sum of products, we may be able to make further progress.
23342334 if (!Constant)
23352335 return false;
23362336 APInt ConstDelta = cast(Constant)->getAPInt();
2337 DEBUG(dbgs() << " ConstDelta = " << ConstDelta << "\n");
2337 LLVM_DEBUG(dbgs() << " ConstDelta = " << ConstDelta << "\n");
23382338 if (ConstDelta == 0)
23392339 return false;
23402340 RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ExtraGCD);
2341 DEBUG(dbgs() << " RunningGCD = " << RunningGCD << "\n");
2341 LLVM_DEBUG(dbgs() << " RunningGCD = " << RunningGCD << "\n");
23422342 APInt Remainder = ConstDelta.srem(RunningGCD);
23432343 if (Remainder != 0) {
23442344 ++GCDindependence;
23572357 // Given A[5*i + 10*j*M + 9*M*N] and A[15*i + 20*j*M - 21*N*M + 5],
23582358 // we need to remember that the constant part is 5 and the RunningGCD should
23592359 // be initialized to ExtraGCD = 30.
2360 DEBUG(dbgs() << " ExtraGCD = " << ExtraGCD << '\n');
2360 LLVM_DEBUG(dbgs() << " ExtraGCD = " << ExtraGCD << '\n');
23612361
23622362 bool Improved = false;
23632363 Coefficients = Src;
24122412 continue;
24132413 APInt ConstCoeff = Constant->getAPInt();
24142414 RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff.abs());
2415 DEBUG(dbgs() << "\tRunningGCD = " << RunningGCD << "\n");
2415 LLVM_DEBUG(dbgs() << "\tRunningGCD = " << RunningGCD << "\n");
24162416 if (RunningGCD != 0) {
24172417 Remainder = ConstDelta.srem(RunningGCD);
2418 DEBUG(dbgs() << "\tRemainder = " << Remainder << "\n");
2418 LLVM_DEBUG(dbgs() << "\tRemainder = " << Remainder << "\n");
24192419 if (Remainder != 0) {
24202420 unsigned Level = mapSrcLoop(CurLoop);
24212421 Result.DV[Level - 1].Direction &= unsigned(~Dependence::DVEntry::EQ);
24252425 }
24262426 if (Improved)
24272427 ++GCDsuccesses;
2428 DEBUG(dbgs() << "all done\n");
2428 LLVM_DEBUG(dbgs() << "all done\n");
24292429 return false;
24302430 }
24312431
24662466 bool DependenceInfo::banerjeeMIVtest(const SCEV *Src, const SCEV *Dst,
24672467 const SmallBitVector &Loops,
24682468 FullDependence &Result) const {
2469 DEBUG(dbgs() << "starting Banerjee\n");
2469 LLVM_DEBUG(dbgs() << "starting Banerjee\n");
24702470 ++BanerjeeApplications;
2471 DEBUG(dbgs() << " Src = " << *Src << '\n');
2471 LLVM_DEBUG(dbgs() << " Src = " << *Src << '\n');
24722472 const SCEV *A0;
24732473 CoefficientInfo *A = collectCoeffInfo(Src, true, A0);
2474 DEBUG(dbgs() << " Dst = " << *Dst << '\n');
2474 LLVM_DEBUG(dbgs() << " Dst = " << *Dst << '\n');
24752475 const SCEV *B0;
24762476 CoefficientInfo *B = collectCoeffInfo(Dst, false, B0);
24772477 BoundInfo *Bound = new BoundInfo[MaxLevels + 1];
24782478 const SCEV *Delta = SE->getMinusSCEV(B0, A0);
2479 DEBUG(dbgs() << "\tDelta = " << *Delta << '\n');
2479 LLVM_DEBUG(dbgs() << "\tDelta = " << *Delta << '\n');
24802480
24812481 // Compute bounds for all the * directions.
2482 DEBUG(dbgs() << "\tBounds[*]\n");
2482 LLVM_DEBUG(dbgs() << "\tBounds[*]\n");
24832483 for (unsigned K = 1; K <= MaxLevels; ++K) {
24842484 Bound[K].Iterations = A[K].Iterations ? A[K].Iterations : B[K].Iterations;
24852485 Bound[K].Direction = Dependence::DVEntry::ALL;
24862486 Bound[K].DirSet = Dependence::DVEntry::NONE;
24872487 findBoundsALL(A, B, Bound, K);
24882488 #ifndef NDEBUG
2489 DEBUG(dbgs() << "\t " << K << '\t');
2489 LLVM_DEBUG(dbgs() << "\t " << K << '\t');
24902490 if (Bound[K].Lower[Dependence::DVEntry::ALL])
2491 DEBUG(dbgs() << *Bound[K].Lower[Dependence::DVEntry::ALL] << '\t');
2491 LLVM_DEBUG(dbgs() << *Bound[K].Lower[Dependence::DVEntry::ALL] << '\t');
24922492 else
2493 DEBUG(dbgs() << "-inf\t");
2493 LLVM_DEBUG(dbgs() << "-inf\t");
24942494 if (Bound[K].Upper[Dependence::DVEntry::ALL])
2495 DEBUG(dbgs() << *Bound[K].Upper[Dependence::DVEntry::ALL] << '\n');
2495 LLVM_DEBUG(dbgs() << *Bound[K].Upper[Dependence::DVEntry::ALL] << '\n');
24962496 else
2497 DEBUG(dbgs() << "+inf\n");
2497 LLVM_DEBUG(dbgs() << "+inf\n");
24982498 #endif
24992499 }
25002500
25502550 const SCEV *Delta) const {
25512551 if (Level > CommonLevels) {
25522552 // record result
2553 DEBUG(dbgs() << "\t[");
2553 LLVM_DEBUG(dbgs() << "\t[");
25542554 for (unsigned K = 1; K <= CommonLevels; ++K) {
25552555 if (Loops[K]) {
25562556 Bound[K].DirSet |= Bound[K].Direction;
25572557 #ifndef NDEBUG
25582558 switch (Bound[K].Direction) {
25592559 case Dependence::DVEntry::LT:
2560 DEBUG(dbgs() << " <");
2560 LLVM_DEBUG(dbgs() << " <");
25612561 break;
25622562 case Dependence::DVEntry::EQ:
2563 DEBUG(dbgs() << " =");
2563 LLVM_DEBUG(dbgs() << " =");
25642564 break;
25652565 case Dependence::DVEntry::GT:
2566 DEBUG(dbgs() << " >");
2566 LLVM_DEBUG(dbgs() << " >");
25672567 break;
25682568 case Dependence::DVEntry::ALL:
2569 DEBUG(dbgs() << " *");
2569 LLVM_DEBUG(dbgs() << " *");
25702570 break;
25712571 default:
25722572 llvm_unreachable("unexpected Bound[K].Direction");
25742574 #endif
25752575 }
25762576 }
2577 DEBUG(dbgs() << " ]\n");
2577 LLVM_DEBUG(dbgs() << " ]\n");
25782578 return 1;
25792579 }
25802580 if (Loops[Level]) {
25852585 findBoundsGT(A, B, Bound, Level);
25862586 findBoundsEQ(A, B, Bound, Level);
25872587 #ifndef NDEBUG
2588 DEBUG(dbgs() << "\tBound for level = " << Level << '\n');
2589 DEBUG(dbgs() << "\t <\t");
2588 LLVM_DEBUG(dbgs() << "\tBound for level = " << Level << '\n');
2589 LLVM_DEBUG(dbgs() << "\t <\t");
25902590 if (Bound[Level].Lower[Dependence::DVEntry::LT])
2591 DEBUG(dbgs() << *Bound[Level].Lower[Dependence::DVEntry::LT] << '\t');
2591 LLVM_DEBUG(dbgs() << *Bound[Level].Lower[Dependence::DVEntry::LT]
2592 << '\t');
25922593 else
2593 DEBUG(dbgs() << "-inf\t");
2594 LLVM_DEBUG(dbgs() << "-inf\t");
25942595 if (Bound[Level].Upper[Dependence::DVEntry::LT])
2595 DEBUG(dbgs() << *Bound[Level].Upper[Dependence::DVEntry::LT] << '\n');
2596 LLVM_DEBUG(dbgs() << *Bound[Level].Upper[Dependence::DVEntry::LT]
2597 << '\n');
25962598 else
2597 DEBUG(dbgs() << "+inf\n");
2598 DEBUG(dbgs() << "\t =\t");
2599 LLVM_DEBUG(dbgs() << "+inf\n");
2600 LLVM_DEBUG(dbgs() << "\t =\t");
25992601 if (Bound[Level].Lower[Dependence::DVEntry::EQ])
2600 DEBUG(dbgs() << *Bound[Level].Lower[Dependence::DVEntry::EQ] << '\t');
2602 LLVM_DEBUG(dbgs() << *Bound[Level].Lower[Dependence::DVEntry::EQ]
2603 << '\t');
26012604 else
2602 DEBUG(dbgs() << "-inf\t");
2605 LLVM_DEBUG(dbgs() << "-inf\t");
26032606 if (Bound[Level].Upper[Dependence::DVEntry::EQ])
2604 DEBUG(dbgs() << *Bound[Level].Upper[Dependence::DVEntry::EQ] << '\n');
2607 LLVM_DEBUG(dbgs() << *Bound[Level].Upper[Dependence::DVEntry::EQ]
2608 << '\n');
26052609 else
2606 DEBUG(dbgs() << "+inf\n");
2607 DEBUG(dbgs() << "\t >\t");
2610 LLVM_DEBUG(dbgs() << "+inf\n");
2611 LLVM_DEBUG(dbgs() << "\t >\t");
26082612 if (Bound[Level].Lower[Dependence::DVEntry::GT])
2609 DEBUG(dbgs() << *Bound[Level].Lower[Dependence::DVEntry::GT] << '\t');
2613 LLVM_DEBUG(dbgs() << *Bound[Level].Lower[Dependence::DVEntry::GT]
2614 << '\t');
26102615 else
2611 DEBUG(dbgs() << "-inf\t");
2616 LLVM_DEBUG(dbgs() << "-inf\t");
26122617 if (Bound[Level].Upper[Dependence::DVEntry::GT])
2613 DEBUG(dbgs() << *Bound[Level].Upper[Dependence::DVEntry::GT] << '\n');
2618 LLVM_DEBUG(dbgs() << *Bound[Level].Upper[Dependence::DVEntry::GT]
2619 << '\n');
26142620 else
2615 DEBUG(dbgs() << "+inf\n");
2621 LLVM_DEBUG(dbgs() << "+inf\n");
26162622 #endif
26172623 }
26182624
28592865 }
28602866 Constant = Subscript;
28612867 #ifndef NDEBUG
2862 DEBUG(dbgs() << "\tCoefficient Info\n");
2868 LLVM_DEBUG(dbgs() << "\tCoefficient Info\n");
28632869 for (unsigned K = 1; K <= MaxLevels; ++K) {
2864 DEBUG(dbgs() << "\t " << K << "\t" << *CI[K].Coeff);
2865 DEBUG(dbgs() << "\tPos Part = ");
2866 DEBUG(dbgs() << *CI[K].PosPart);
2867 DEBUG(dbgs() << "\tNeg Part = ");
2868 DEBUG(dbgs() << *CI[K].NegPart);
2869 DEBUG(dbgs() << "\tUpper Bound = ");
2870 LLVM_DEBUG(dbgs() << "\t " << K << "\t" << *CI[K].Coeff);
2871 LLVM_DEBUG(dbgs() << "\tPos Part = ");
2872 LLVM_DEBUG(dbgs() << *CI[K].PosPart);
2873 LLVM_DEBUG(dbgs() << "\tNeg Part = ");
2874 LLVM_DEBUG(dbgs() << *CI[K].NegPart);
2875 LLVM_DEBUG(dbgs() << "\tUpper Bound = ");
28702876 if (CI[K].Iterations)
2871 DEBUG(dbgs() << *CI[K].Iterations);
2877 LLVM_DEBUG(dbgs() << *CI[K].Iterations);
28722878 else
2873 DEBUG(dbgs() << "+inf");
2874 DEBUG(dbgs() << '\n');
2875 }
2876 DEBUG(dbgs() << "\t Constant = " << *Subscript << '\n');
2879 LLVM_DEBUG(dbgs() << "+inf");
2880 LLVM_DEBUG(dbgs() << '\n');
2881 }
2882 LLVM_DEBUG(dbgs() << "\t Constant = " << *Subscript << '\n');
28772883 #endif
28782884 return CI;
28792885 }
29983004 bool &Consistent) {
29993005 bool Result = false;
30003006 for (unsigned LI : Loops.set_bits()) {
3001 DEBUG(dbgs() << "\t Constraint[" << LI << "] is");
3002 DEBUG(Constraints[LI].dump(dbgs()));
3007 LLVM_DEBUG(dbgs() << "\t Constraint[" << LI << "] is");
3008 LLVM_DEBUG(Constraints[LI].dump(dbgs()));
30033009 if (Constraints[LI].isDistance())
30043010 Result |= propagateDistance(Src, Dst, Constraints[LI], Consistent);
30053011 else if (Constraints[LI].isLine())
30203026 Constraint &CurConstraint,
30213027 bool &Consistent) {
30223028 const Loop *CurLoop = CurConstraint.getAssociatedLoop();
3023 DEBUG(dbgs() << "\t\tSrc is " << *Src << "\n");
3029 LLVM_DEBUG(dbgs() << "\t\tSrc is " << *Src << "\n");
30243030 const SCEV *A_K = findCoefficient(Src, CurLoop);
30253031 if (A_K->isZero())
30263032 return false;
30273033 const SCEV *DA_K = SE->getMulExpr(A_K, CurConstraint.getD());
30283034 Src = SE->getMinusSCEV(Src, DA_K);
30293035 Src = zeroCoefficient(Src, CurLoop);
3030 DEBUG(dbgs() << "\t\tnew Src is " << *Src << "\n");
3031 DEBUG(dbgs() << "\t\tDst is " << *Dst << "\n");
3036 LLVM_DEBUG(dbgs() << "\t\tnew Src is " << *Src << "\n");
3037 LLVM_DEBUG(dbgs() << "\t\tDst is " << *Dst << "\n");
30323038 Dst = addToCoefficient(Dst, CurLoop, SE->getNegativeSCEV(A_K));
3033 DEBUG(dbgs() << "\t\tnew Dst is " << *Dst << "\n");
3039 LLVM_DEBUG(dbgs() << "\t\tnew Dst is " << *Dst << "\n");
30343040 if (!findCoefficient(Dst, CurLoop)->isZero())
30353041 Consistent = false;
30363042 return true;
30493055 const SCEV *A = CurConstraint.getA();
30503056 const SCEV *B = CurConstraint.getB();
30513057 const SCEV *C = CurConstraint.getC();
3052 DEBUG(dbgs() << "\t\tA = " << *A << ", B = " << *B << ", C = " << *C << "\n");
3053 DEBUG(dbgs() << "\t\tSrc = " << *Src << "\n");
3054 DEBUG(dbgs() << "\t\tDst = " << *Dst << "\n");
3058 LLVM_DEBUG(dbgs() << "\t\tA = " << *A << ", B = " << *B << ", C = " << *C
3059 << "\n");
3060 LLVM_DEBUG(dbgs() << "\t\tSrc = " << *Src << "\n");
3061 LLVM_DEBUG(dbgs() << "\t\tDst = " << *Dst << "\n");
30553062 if (A->isZero()) {
30563063 const SCEVConstant *Bconst = dyn_cast(B);
30573064 const SCEVConstant *Cconst = dyn_cast(C);
31073114 if (!findCoefficient(Dst, CurLoop)->isZero())
31083115 Consistent = false;
31093116 }
3110 DEBUG(dbgs() << "\t\tnew Src = " << *Src << "\n");
3111 DEBUG(dbgs() << "\t\tnew Dst = " << *Dst << "\n");
3117 LLVM_DEBUG(dbgs() << "\t\tnew Src = " << *Src << "\n");
3118 LLVM_DEBUG(dbgs() << "\t\tnew Dst = " << *Dst << "\n");
31123119 return true;
31133120 }
31143121
31233130 const SCEV *AP_K = findCoefficient(Dst, CurLoop);
31243131 const SCEV *XA_K = SE->getMulExpr(A_K, CurConstraint.getX());
31253132 const SCEV *YAP_K = SE->getMulExpr(AP_K, CurConstraint.getY());
3126 DEBUG(dbgs() << "\t\tSrc is " << *Src << "\n");
3133 LLVM_DEBUG(dbgs() << "\t\tSrc is " << *Src << "\n");
31273134 Src = SE->getAddExpr(Src, SE->getMinusSCEV(XA_K, YAP_K));
31283135 Src = zeroCoefficient(Src, CurLoop);
3129 DEBUG(dbgs() << "\t\tnew Src is " << *Src << "\n");
3130 DEBUG(dbgs() << "\t\tDst is " << *Dst << "\n");
3136 LLVM_DEBUG(dbgs() << "\t\tnew Src is " << *Src << "\n");
3137 LLVM_DEBUG(dbgs() << "\t\tDst is " << *Dst << "\n");
31313138 Dst = zeroCoefficient(Dst, CurLoop);
3132 DEBUG(dbgs() << "\t\tnew Dst is " << *Dst << "\n");
3139 LLVM_DEBUG(dbgs() << "\t\tnew Dst is " << *Dst << "\n");
31333140 return true;
31343141 }
31353142
31373144 // Update direction vector entry based on the current constraint.
31383145 void DependenceInfo::updateDirection(Dependence::DVEntry &Level,
31393146 const Constraint &CurConstraint) const {
3140 DEBUG(dbgs() << "\tUpdate direction, constraint =");
3141 DEBUG(CurConstraint.dump(dbgs()));
3147 LLVM_DEBUG(dbgs() << "\tUpdate direction, constraint =");
3148 LLVM_DEBUG(CurConstraint.dump(dbgs()));
31423149 if (CurConstraint.isAny())
31433150 ; // use defaults
31443151 else if (CurConstraint.isDistance()) {
32453252
32463253 int size = SrcSubscripts.size();
32473254
3248 DEBUG({
3249 dbgs() << "\nSrcSubscripts: ";
3255 LLVM_DEBUG({
3256 dbgs() << "\nSrcSubscripts: ";
32503257 for (int i = 0; i < size; i++)
32513258 dbgs() << *SrcSubscripts[i];
32523259 dbgs() << "\nDstSubscripts: ";
32533260 for (int i = 0; i < size; i++)
32543261 dbgs() << *DstSubscripts[i];
3255 });
3262 });
32563263
32573264 // The delinearization transforms a single-subscript MIV dependence test into
32583265 // a multi-subscript SIV dependence test that is easier to compute. So we
33143321
33153322 if (!isLoadOrStore(Src) || !isLoadOrStore(Dst)) {
33163323 // can only analyze simple loads and stores, i.e., no calls, invokes, etc.
3317 DEBUG(dbgs() << "can only handle simple loads and stores\n");
3324 LLVM_DEBUG(dbgs() << "can only handle simple loads and stores\n");
33183325 return make_unique(Src, Dst);
33193326 }
33203327
33293336 case MayAlias:
33303337 case PartialAlias:
33313338 // cannot analyse objects if we don't understand their aliasing.
3332 DEBUG(dbgs() << "can't analyze may or partial alias\n");
3339 LLVM_DEBUG(dbgs() << "can't analyze may or partial alias\n");
33333340 return make_unique(Src, Dst);
33343341 case NoAlias:
33353342 // If the objects noalias, they are distinct, accesses are independent.
3336 DEBUG(dbgs() << "no alias\n");
3343 LLVM_DEBUG(dbgs() << "no alias\n");
33373344 return nullptr;
33383345 case MustAlias:
33393346 break; // The underlying objects alias; test accesses for dependence.
33413348
33423349 // establish loop nesting levels
33433350 establishNestingLevels(Src, Dst);
3344 DEBUG(dbgs() << " common nesting levels = " << CommonLevels << "\n");
3345 DEBUG(dbgs() << " maximum nesting levels = " << MaxLevels << "\n");
3351 LLVM_DEBUG(dbgs() << " common nesting levels = " << CommonLevels << "\n");
3352 LLVM_DEBUG(dbgs() << " maximum nesting levels = " << MaxLevels << "\n");
33463353
33473354 FullDependence Result(Src, Dst, PossiblyLoopIndependent, CommonLevels);
33483355 ++TotalArrayPairs;
33513358 SmallVector Pair(Pairs);
33523359 const SCEV *SrcSCEV = SE->getSCEV(SrcPtr);
33533360 const SCEV *DstSCEV = SE->getSCEV(DstPtr);
3354 DEBUG(dbgs() << " SrcSCEV = " << *SrcSCEV << "\n");
3355 DEBUG(dbgs() << " DstSCEV = " << *DstSCEV << "\n");
3361 LLVM_DEBUG(dbgs() << " SrcSCEV = " << *SrcSCEV << "\n");
3362 LLVM_DEBUG(dbgs() << " DstSCEV = " << *DstSCEV << "\n");
33563363 Pair[0].Src = SrcSCEV;
33573364 Pair[0].Dst = DstSCEV;
33583365
33593366 if (Delinearize) {
33603367 if (tryDelinearize(Src, Dst, Pair)) {
3361 DEBUG(dbgs() << " delinearized\n");
3368 LLVM_DEBUG(dbgs() << " delinearized\n");
33623369 Pairs = Pair.size();
33633370 }
33643371 }
33743381 Pair[P].Loops);
33753382 Pair[P].GroupLoops = Pair[P].Loops;
33763383 Pair[P].Group.set(P);
3377 DEBUG(dbgs() << " subscript " << P << "\n");
3378 DEBUG(dbgs() << "\tsrc = " << *Pair[P].Src << "\n");
3379 DEBUG(dbgs() << "\tdst = " << *Pair[P].Dst << "\n");
3380 DEBUG(dbgs() << "\tclass = " << Pair[P].Classification << "\n");
3381 DEBUG(dbgs() << "\tloops = ");
3382 DEBUG(dumpSmallBitVector(Pair[P].Loops));
3384 LLVM_DEBUG(dbgs() << " subscript " << P << "\n");
3385 LLVM_DEBUG(dbgs() << "\tsrc = " << *Pair[P].Src << "\n");
3386 LLVM_DEBUG(dbgs() << "\tdst = " << *Pair[P].Dst << "\n");
3387 LLVM_DEBUG(dbgs() << "\tclass = " << Pair[P].Classification << "\n");
3388 LLVM_DEBUG(dbgs() << "\tloops = ");
3389 LLVM_DEBUG(dumpSmallBitVector(Pair[P].