llvm.org GIT mirror llvm / 2540c74
[NFC] Convert OptimizationRemarkEmitter old emit() calls to new closure parameterized emit() calls Summary: This is not functional change to adopt new emit() API added in r313691. Reviewed By: anemet Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38285 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315476 91177308-0d34-0410-b5e6-96231b3b80d8 Vivek Pandya 3 years ago
23 changed file(s) with 534 addition(s) and 374 deletion(s). Raw diff Collapse all Expand all
163163 .getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
164164 }
165165
166 /// \brief Take a lambda that returns a remark which will be emitted. Second
167 /// argument is only used to restrict this to functions.
168 template
169 void emit(T RemarkBuilder, decltype(RemarkBuilder()) * = nullptr) {
170 // Avoid building the remark unless we know there are at least *some*
171 // remarks enabled. We can't currently check whether remarks are requested
172 // for the calling pass since that requires actually building the remark.
173
174 if (MF.getFunction()->getContext().getDiagnosticsOutputFile() ||
175 MF.getFunction()->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled()) {
176 auto R = RemarkBuilder();
177 emit(R);
178 }
179 }
180
166181 private:
167182 MachineFunction &MF;
168183
14391439 if (IsRecursiveCall || ExposesReturnsTwice || HasDynamicAlloca ||
14401440 HasIndirectBr || HasFrameEscape) {
14411441 if (ORE)
1442 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline",
1443 CandidateCS.getInstruction())
1444 << NV("Callee", &F)
1445 << " has uninlinable pattern and cost is not fully computed");
1442 ORE->emit([&]() {
1443 return OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline",
1444 CandidateCS.getInstruction())
1445 << NV("Callee", &F)
1446 << " has uninlinable pattern and cost is not fully computed";
1447 });
14461448 return false;
14471449 }
14481450
14521454 if (IsCallerRecursive &&
14531455 AllocatedSize > InlineConstants::TotalAllocaSizeRecursiveCaller) {
14541456 if (ORE)
1455 ORE->emit(
1456 OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline",
1457 CandidateCS.getInstruction())
1458 << NV("Callee", &F)
1459 << " is recursive and allocates too much stack space. Cost is "
1460 "not fully computed");
1457 ORE->emit([&]() {
1458 return OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline",
1459 CandidateCS.getInstruction())
1460 << NV("Callee", &F)
1461 << " is recursive and allocates too much stack space. Cost is "
1462 "not fully computed";
1463 });
14611464 return false;
14621465 }
14631466
776776 if (Known.Zero.intersects(Known.One)) {
777777 Known.resetAll();
778778
779 if (Q.ORE) {
780 auto *CxtI = const_cast(Q.CxtI);
781 OptimizationRemarkAnalysis ORA("value-tracking", "BadAssumption", CxtI);
782 Q.ORE->emit(ORA << "Detected conflicting code assumptions. Program may "
783 "have undefined behavior, or compiler may have "
784 "internal error.");
785 }
779 if (Q.ORE)
780 Q.ORE->emit([&]() {
781 auto *CxtI = const_cast(Q.CxtI);
782 return OptimizationRemarkAnalysis("value-tracking", "BadAssumption",
783 CxtI)
784 << "Detected conflicting code assumptions. Program may "
785 "have undefined behavior, or compiler may have "
786 "internal error.";
787 });
786788 }
787789 }
788790
938938 // Emit a remark explaining why we didn't outline this candidate.
939939 std::pair C =
940940 RepeatedSequenceLocs[0];
941 MachineOptimizationRemarkEmitter MORE(*(C.first->getMF()), nullptr);
942 MachineOptimizationRemarkMissed R(DEBUG_TYPE, "NotOutliningCheaper",
943 C.first->getDebugLoc(),
944 C.first->getParent());
945 R << "Did not outline " << NV("Length", StringLen) << " instructions"
946 << " from " << NV("NumOccurrences", RepeatedSequenceLocs.size())
947 << " locations."
948 << " Instructions from outlining all occurrences ("
949 << NV("OutliningCost", OF.getOutliningCost()) << ")"
950 << " >= Unoutlined instruction count ("
951 << NV("NotOutliningCost", StringLen * OF.OccurrenceCount) << ")"
952 << " (Also found at: ";
953
954 // Tell the user the other places the candidate was found.
955 for (unsigned i = 1, e = RepeatedSequenceLocs.size(); i < e; i++) {
956 R << NV((Twine("OtherStartLoc") + Twine(i)).str(),
957 RepeatedSequenceLocs[i].first->getDebugLoc());
958 if (i != e - 1)
959 R << ", ";
960 }
961
962 R << ")";
963 MORE.emit(R);
941 MachineOptimizationRemarkEmitter MORE(
942 *(C.first->getParent()->getParent()), nullptr);
943 MORE.emit([&]() {
944 MachineOptimizationRemarkMissed R(DEBUG_TYPE, "NotOutliningCheaper",
945 C.first->getDebugLoc(),
946 C.first->getParent());
947 R << "Did not outline " << NV("Length", StringLen) << " instructions"
948 << " from " << NV("NumOccurrences", RepeatedSequenceLocs.size())
949 << " locations."
950 << " Instructions from outlining all occurrences ("
951 << NV("OutliningCost", OF.getOutliningCost()) << ")"
952 << " >= Unoutlined instruction count ("
953 << NV("NotOutliningCost", StringLen * OF.OccurrenceCount) << ")"
954 << " (Also found at: ";
955
956 // Tell the user the other places the candidate was found.
957 for (unsigned i = 1, e = RepeatedSequenceLocs.size(); i < e; i++) {
958 R << NV((Twine("OtherStartLoc") + Twine(i)).str(),
959 RepeatedSequenceLocs[i].first->getDebugLoc());
960 if (i != e - 1)
961 R << ", ";
962 }
963
964 R << ")";
965 return R;
966 });
964967
965968 // Move to the next candidate.
966969 continue;
959959 MFI.setStackSize(StackSize);
960960 NumBytesStackSpace += StackSize;
961961
962 MachineOptimizationRemarkAnalysis R(
963 DEBUG_TYPE, "StackSize", Fn.getFunction()->getSubprogram(), &Fn.front());
964 R << ore::NV("NumStackBytes", StackSize)
965 << " stack bytes in function";
966 ORE->emit(R);
962 ORE->emit([&]() {
963 return MachineOptimizationRemarkAnalysis(DEBUG_TYPE, "StackSize",
964 Fn.getFunction()->getSubprogram(),
965 &Fn.front())
966 << ore::NV("NumStackBytes", StackSize) << " stack bytes in function";
967 });
967968 }
968969
969970 /// insertPrologEpilogCode - Scan the function for modified callee saved
27162716 if (Reloads || FoldedReloads || Spills || FoldedSpills) {
27172717 using namespace ore;
27182718
2719 MachineOptimizationRemarkMissed R(DEBUG_TYPE, "LoopSpillReload",
2720 L->getStartLoc(), L->getHeader());
2721 if (Spills)
2722 R << NV("NumSpills", Spills) << " spills ";
2723 if (FoldedSpills)
2724 R << NV("NumFoldedSpills", FoldedSpills) << " folded spills ";
2725 if (Reloads)
2726 R << NV("NumReloads", Reloads) << " reloads ";
2727 if (FoldedReloads)
2728 R << NV("NumFoldedReloads", FoldedReloads) << " folded reloads ";
2729 ORE->emit(R << "generated in loop");
2719 ORE->emit([&]() {
2720 MachineOptimizationRemarkMissed R(DEBUG_TYPE, "LoopSpillReload",
2721 L->getStartLoc(), L->getHeader());
2722 if (Spills)
2723 R << NV("NumSpills", Spills) << " spills ";
2724 if (FoldedSpills)
2725 R << NV("NumFoldedSpills", FoldedSpills) << " folded spills ";
2726 if (Reloads)
2727 R << NV("NumReloads", Reloads) << " reloads ";
2728 if (FoldedReloads)
2729 R << NV("NumFoldedReloads", FoldedReloads) << " folded reloads ";
2730 R << "generated in loop";
2731 return R;
2732 });
27302733 }
27312734 }
27322735
246246 OptimizationRemarkEmitter ORE(F);
247247
248248 if (F->hasFnAttribute(Attribute::StackProtectReq)) {
249 ORE.emit(OptimizationRemark(DEBUG_TYPE, "StackProtectorRequested", F)
249 ORE.emit([&]() {
250 return OptimizationRemark(DEBUG_TYPE, "StackProtectorRequested", F)
250251 << "Stack protection applied to function "
251252 << ore::NV("Function", F)
252 << " due to a function attribute or command-line switch");
253 << " due to a function attribute or command-line switch";
254 });
253255 NeedsProtector = true;
254256 Strong = true; // Use the same heuristic as strong to determine SSPLayout
255257 } else if (F->hasFnAttribute(Attribute::StackProtectStrong))
263265 for (const Instruction &I : BB) {
264266 if (const AllocaInst *AI = dyn_cast(&I)) {
265267 if (AI->isArrayAllocation()) {
266 OptimizationRemark Remark(DEBUG_TYPE, "StackProtectorAllocaOrArray",
267 &I);
268 Remark
269 << "Stack protection applied to function "
270 << ore::NV("Function", F)
271 << " due to a call to alloca or use of a variable length array";
268 auto RemarkBuilder = [&]() {
269 return OptimizationRemark(DEBUG_TYPE, "StackProtectorAllocaOrArray",
270 &I)
271 << "Stack protection applied to function "
272 << ore::NV("Function", F)
273 << " due to a call to alloca or use of a variable length "
274 "array";
275 };
272276 if (const auto *CI = dyn_cast(AI->getArraySize())) {
273277 if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) {
274278 // A call to alloca with size >= SSPBufferSize requires
275279 // stack protectors.
276280 Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
277 ORE.emit(Remark);
281 ORE.emit(RemarkBuilder);
278282 NeedsProtector = true;
279283 } else if (Strong) {
280284 // Require protectors for all alloca calls in strong mode.
281285 Layout.insert(std::make_pair(AI, SSPLK_SmallArray));
282 ORE.emit(Remark);
286 ORE.emit(RemarkBuilder);
283287 NeedsProtector = true;
284288 }
285289 } else {
286290 // A call to alloca with a variable size requires protectors.
287291 Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
288 ORE.emit(Remark);
292 ORE.emit(RemarkBuilder);
289293 NeedsProtector = true;
290294 }
291295 continue;
295299 if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) {
296300 Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
297301 : SSPLK_SmallArray));
298 ORE.emit(OptimizationRemark(DEBUG_TYPE, "StackProtectorBuffer", &I)
302 ORE.emit([&]() {
303 return OptimizationRemark(DEBUG_TYPE, "StackProtectorBuffer", &I)
299304 << "Stack protection applied to function "
300305 << ore::NV("Function", F)
301306 << " due to a stack allocated buffer or struct containing a "
302 "buffer");
307 "buffer";
308 });
303309 NeedsProtector = true;
304310 continue;
305311 }
307313 if (Strong && HasAddressTaken(AI)) {
308314 ++NumAddrTaken;
309315 Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
310 ORE.emit(
311 OptimizationRemark(DEBUG_TYPE, "StackProtectorAddressTaken", &I)
312 << "Stack protection applied to function "
313 << ore::NV("Function", F)
314 << " due to the address of a local variable being taken");
316 ORE.emit([&]() {
317 return OptimizationRemark(DEBUG_TYPE, "StackProtectorAddressTaken",
318 &I)
319 << "Stack protection applied to function "
320 << ore::NV("Function", F)
321 << " due to the address of a local variable being taken";
322 });
315323 NeedsProtector = true;
316324 }
317325 }
383383 DEBUG(dbgs() << " NOT Inlining: " << *CS.getInstruction()
384384 << " Cost = " << IC.getCost()
385385 << ", outer Cost = " << TotalSecondaryCost << '\n');
386 ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "IncreaseCostInOtherContexts",
386 ORE.emit([&]() {
387 return OptimizationRemarkMissed(DEBUG_TYPE, "IncreaseCostInOtherContexts",
387388 Call)
388389 << "Not inlining. Cost of inlining " << NV("Callee", Callee)
389390 << " increases the cost of inlining " << NV("Caller", Caller)
390 << " in other contexts");
391 << " in other contexts";
392 });
391393
392394 // IC does not bool() to false, so get an InlineCost that will.
393395 // This will not be inspected to make an error message.
475477 if (Function *Callee = CS.getCalledFunction())
476478 if (Callee->isDeclaration()) {
477479 using namespace ore;
478 ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "NoDefinition", &I)
480 ORE.emit([&]() {
481 return OptimizationRemarkMissed(DEBUG_TYPE, "NoDefinition", &I)
479482 << NV("Callee", Callee) << " will not be inlined into "
480483 << NV("Caller", CS.getCaller())
481484 << " because its definition is unavailable"
482 << setIsVerbose());
485 << setIsVerbose();
486 });
483487 continue;
484488 }
485489
571575 if (!InlineCallIfPossible(CS, InlineInfo, InlinedArrayAllocas,
572576 InlineHistoryID, InsertLifetime, AARGetter,
573577 ImportedFunctionsStats)) {
574 ORE.emit(
575 OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
576 << NV("Callee", Callee) << " will not be inlined into "
577 << NV("Caller", Caller));
578 ORE.emit([&]() {
579 return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc,
580 Block)
581 << NV("Callee", Callee) << " will not be inlined into "
582 << NV("Caller", Caller);
583 });
578584 continue;
579585 }
580586 ++NumInlined;
581587
582 if (OIC->isAlways())
583 ORE.emit(OptimizationRemark(DEBUG_TYPE, "AlwaysInline", DLoc, Block)
584 << NV("Callee", Callee) << " inlined into "
585 << NV("Caller", Caller) << " with cost=always");
586 else
587 ORE.emit([&]() {
588 return OptimizationRemark(DEBUG_TYPE, "Inlined", DLoc, Block)
589 << NV("Callee", Callee) << " inlined into "
590 << NV("Caller", Caller)
591 << " with cost=" << NV("Cost", OIC->getCost())
592 << " (threshold=" << NV("Threshold", OIC->getThreshold())
593 << ")";
594 });
588 ORE.emit([&]() {
589 bool AlwaysInline = OIC->isAlways();
590 StringRef RemarkName = AlwaysInline ? "AlwaysInline" : "Inlined";
591 OptimizationRemark R(DEBUG_TYPE, RemarkName, DLoc, Block);
592 R << NV("Callee", Callee) << " inlined into ";
593 R << NV("Caller", Caller);
594 if (AlwaysInline)
595 R << " with cost=always";
596 else {
597 R << " with cost=" << NV("Cost", OIC->getCost());
598 R << " (threshold=" << NV("Threshold", OIC->getThreshold());
599 R << ")";
600 }
601 return R;
602 });
595603
596604 // If inlining this function gave us any new call sites, throw them
597605 // onto our worklist to process. They are useful inline candidates.
914922
915923 using namespace ore;
916924 if (!InlineFunction(CS, IFI)) {
917 ORE.emit(
918 OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
919 << NV("Callee", &Callee) << " will not be inlined into "
920 << NV("Caller", &F));
925 ORE.emit([&]() {
926 return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
927 << NV("Callee", &Callee) << " will not be inlined into "
928 << NV("Caller", &F);
929 });
921930 continue;
922931 }
923932 DidInline = true;
924933 InlinedCallees.insert(&Callee);
925934
926 if (OIC->isAlways())
927 ORE.emit(OptimizationRemark(DEBUG_TYPE, "AlwaysInline", DLoc, Block)
928 << NV("Callee", &Callee) << " inlined into "
929 << NV("Caller", &F) << " with cost=always");
930 else
931 ORE.emit(
932 OptimizationRemark(DEBUG_TYPE, "Inlined", DLoc, Block)
933 << NV("Callee", &Callee) << " inlined into " << NV("Caller", &F)
934 << " with cost=" << NV("Cost", OIC->getCost())
935 << " (threshold=" << NV("Threshold", OIC->getThreshold()) << ")");
935 ORE.emit([&]() {
936 bool AlwaysInline = OIC->isAlways();
937 StringRef RemarkName = AlwaysInline ? "AlwaysInline" : "Inlined";
938 OptimizationRemark R(DEBUG_TYPE, RemarkName, DLoc, Block);
939 R << NV("Callee", &Callee) << " inlined into ";
940 R << NV("Caller", &F);
941 if (AlwaysInline)
942 R << " with cost=always";
943 else {
944 R << " with cost=" << NV("Cost", OIC->getCost());
945 R << " (threshold=" << NV("Threshold", OIC->getThreshold());
946 R << ")";
947 }
948 return R;
949 });
936950
937951 // Add any new callsites to defined functions to the worklist.
938952 if (!IFI.InlinedCallSites.empty()) {
498498 *GetAssumptionCache, GetBFI, PSI, &ORE);
499499
500500 if (IC.isAlways()) {
501 ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AlwaysInline", Call)
501 ORE.emit([&]() {
502 return OptimizationRemarkAnalysis(DEBUG_TYPE, "AlwaysInline", Call)
502503 << NV("Callee", Cloner.OrigFunc)
503 << " should always be fully inlined, not partially");
504 << " should always be fully inlined, not partially";
505 });
504506 return false;
505507 }
506508
507509 if (IC.isNever()) {
508 ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline", Call)
510 ORE.emit([&]() {
511 return OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline", Call)
509512 << NV("Callee", Cloner.OrigFunc) << " not partially inlined into "
510513 << NV("Caller", Caller)
511 << " because it should never be inlined (cost=never)");
514 << " because it should never be inlined (cost=never)";
515 });
512516 return false;
513517 }
514518
515519 if (!IC) {
516 ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "TooCostly", Call)
520 ORE.emit([&]() {
521 return OptimizationRemarkAnalysis(DEBUG_TYPE, "TooCostly", Call)
517522 << NV("Callee", Cloner.OrigFunc) << " not partially inlined into "
518523 << NV("Caller", Caller) << " because too costly to inline (cost="
519524 << NV("Cost", IC.getCost()) << ", threshold="
520 << NV("Threshold", IC.getCostDelta() + IC.getCost()) << ")");
525 << NV("Threshold", IC.getCostDelta() + IC.getCost()) << ")";
526 });
521527 return false;
522528 }
523529 const DataLayout &DL = Caller->getParent()->getDataLayout();
528534
529535 // Weighted saving is smaller than weighted cost, return false
530536 if (NormWeightedSavings < WeightedOutliningRcost) {
531 ORE.emit(
532 OptimizationRemarkAnalysis(DEBUG_TYPE, "OutliningCallcostTooHigh", Call)
533 << NV("Callee", Cloner.OrigFunc) << " not partially inlined into "
534 << NV("Caller", Caller) << " runtime overhead (overhead="
535 << NV("Overhead", (unsigned)WeightedOutliningRcost.getFrequency())
536 << ", savings="
537 << NV("Savings", (unsigned)NormWeightedSavings.getFrequency()) << ")"
538 << " of making the outlined call is too high");
537 ORE.emit([&]() {
538 return OptimizationRemarkAnalysis(DEBUG_TYPE, "OutliningCallcostTooHigh",
539 Call)
540 << NV("Callee", Cloner.OrigFunc) << " not partially inlined into "
541 << NV("Caller", Caller) << " runtime overhead (overhead="
542 << NV("Overhead", (unsigned)WeightedOutliningRcost.getFrequency())
543 << ", savings="
544 << NV("Savings", (unsigned)NormWeightedSavings.getFrequency())
545 << ")"
546 << " of making the outlined call is too high";
547 });
539548
540549 return false;
541550 }
542551
543 ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "CanBePartiallyInlined", Call)
552 ORE.emit([&]() {
553 return OptimizationRemarkAnalysis(DEBUG_TYPE, "CanBePartiallyInlined", Call)
544554 << NV("Callee", Cloner.OrigFunc) << " can be partially inlined into "
545555 << NV("Caller", Caller) << " with cost=" << NV("Cost", IC.getCost())
546556 << " (threshold="
547 << NV("Threshold", IC.getCostDelta() + IC.getCost()) << ")");
557 << NV("Threshold", IC.getCostDelta() + IC.getCost()) << ")";
558 });
548559 return true;
549560 }
550561
882893 DebugLoc DLoc;
883894 BasicBlock *Block;
884895 std::tie(DLoc, Block) = getOneDebugLoc(Cloner.ClonedFunc);
885 ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "OutlineRegionTooSmall",
896 ORE.emit([&]() {
897 return OptimizationRemarkAnalysis(DEBUG_TYPE, "OutlineRegionTooSmall",
886898 DLoc, Block)
887899 << ore::NV("Function", Cloner.OrigFunc)
888900 << " not partially inlined into callers (Original Size = "
889901 << ore::NV("OutlinedRegionOriginalSize", Cloner.OutlinedRegionCost)
890902 << ", Size of call sequence to outlined function = "
891 << ore::NV("NewSize", SizeCost) << ")");
903 << ore::NV("NewSize", SizeCost) << ")";
904 });
892905 return false;
893906 }
894907
917930 if (!shouldPartialInline(CS, Cloner, WeightedRcost, ORE))
918931 continue;
919932
920 ORE.emit(
921 OptimizationRemark(DEBUG_TYPE, "PartiallyInlined", CS.getInstruction())
922 << ore::NV("Callee", Cloner.OrigFunc) << " partially inlined into "
923 << ore::NV("Caller", CS.getCaller()));
933 ORE.emit([&]() {
934 return OptimizationRemark(DEBUG_TYPE, "PartiallyInlined",
935 CS.getInstruction())
936 << ore::NV("Callee", Cloner.OrigFunc) << " partially inlined into "
937 << ore::NV("Caller", CS.getCaller());
938 });
924939
925940 InlineFunctionInfo IFI(nullptr, GetAssumptionCache, PSI);
926941 InlineFunction(CS, IFI);
527527 bool FirstMark =
528528 CoverageTracker.markSamplesUsed(FS, LineOffset, Discriminator, R.get());
529529 if (FirstMark) {
530 if (Discriminator)
531 ORE->emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AppliedSamples", &Inst)
532 << "Applied " << ore::NV("NumSamples", *R)
533 << " samples from profile (offset: "
534 << ore::NV("LineOffset", LineOffset) << "."
535 << ore::NV("Discriminator", Discriminator) << ")");
536 else
537 ORE->emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AppliedSamples", &Inst)
538 << "Applied " << ore::NV("NumSamples", *R)
539 << " samples from profile (offset: "
540 << ore::NV("LineOffset", LineOffset) << ")");
530 ORE->emit([&]() {
531 OptimizationRemarkAnalysis Remark(DEBUG_TYPE, "AppliedSamples", &Inst);
532 Remark << "Applied " << ore::NV("NumSamples", *R);
533 Remark << " samples from profile (offset: ";
534 Remark << ore::NV("LineOffset", LineOffset);
535 if (Discriminator) {
536 Remark << ".";
537 Remark << ore::NV("Discriminator", Discriminator);
538 }
539 Remark << ")";
540 return Remark;
541 });
541542 }
542543 DEBUG(dbgs() << " " << DLoc.getLine() << "."
543544 << DIL->getBaseDiscriminator() << ":" << Inst
13231324 DEBUG(dbgs() << "SUCCESS. Found non-zero weights.\n");
13241325 TI->setMetadata(llvm::LLVMContext::MD_prof,
13251326 MDB.createBranchWeights(Weights));
1326 ORE->emit(OptimizationRemark(DEBUG_TYPE, "PopularDest", MaxDestInst)
1327 << "most popular destination for conditional branches at "
1328 << ore::NV("CondBranchesLoc", BranchLoc));
1327 ORE->emit([&]() {
1328 return OptimizationRemark(DEBUG_TYPE, "PopularDest", MaxDestInst)
1329 << "most popular destination for conditional branches at "
1330 << ore::NV("CondBranchesLoc", BranchLoc);
1331 });
13291332 } else {
13301333 DEBUG(dbgs() << "SKIPPED. All branch weights are zero.\n");
13311334 }
276276
277277 if (ICPInvokeOnly && dyn_cast(Inst)) {
278278 DEBUG(dbgs() << " Not promote: User options.\n");
279 ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "UserOptions", Inst)
280 << " Not promote: User options");
279 ORE.emit([&]() {
280 return OptimizationRemarkMissed(DEBUG_TYPE, "UserOptions", Inst)
281 << " Not promote: User options";
282 });
281283 break;
282284 }
283285 if (ICPCallOnly && dyn_cast(Inst)) {
284286 DEBUG(dbgs() << " Not promote: User option.\n");
285 ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "UserOptions", Inst)
286 << " Not promote: User options");
287 ORE.emit([&]() {
288 return OptimizationRemarkMissed(DEBUG_TYPE, "UserOptions", Inst)
289 << " Not promote: User options";
290 });
287291 break;
288292 }
289293 if (ICPCutOff != 0 && NumOfPGOICallPromotion >= ICPCutOff) {
290294 DEBUG(dbgs() << " Not promote: Cutoff reached.\n");
291 ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "CutOffReached", Inst)
292 << " Not promote: Cutoff reached");
295 ORE.emit([&]() {
296 return OptimizationRemarkMissed(DEBUG_TYPE, "CutOffReached", Inst)
297 << " Not promote: Cutoff reached";
298 });
293299 break;
294300 }
295301
296302 Function *TargetFunction = Symtab->getFunction(Target);
297303 if (TargetFunction == nullptr) {
298304 DEBUG(dbgs() << " Not promote: Cannot find the target\n");
299 ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "UnableToFindTarget", Inst)
300 << "Cannot promote indirect call: target not found");
305 ORE.emit([&]() {
306 return OptimizationRemarkMissed(DEBUG_TYPE, "UnableToFindTarget", Inst)
307 << "Cannot promote indirect call: target not found";
308 });
301309 break;
302310 }
303311
304312 const char *Reason = nullptr;
305313 if (!isLegalToPromote(Inst, TargetFunction, &Reason)) {
306314 using namespace ore;
307 ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "UnableToPromote", Inst)
315 ORE.emit([&]() {
316 return OptimizationRemarkMissed(DEBUG_TYPE, "UnableToPromote", Inst)
308317 << "Cannot promote indirect call to "
309318 << NV("TargetFunction", TargetFunction) << " with count of "
310 << NV("Count", Count) << ": " << Reason);
319 << NV("Count", Count) << ": " << Reason;
320 });
311321 break;
312322 }
313323
603613
604614 using namespace ore;
605615 if (ORE)
606 ORE->emit(OptimizationRemark(DEBUG_TYPE, "Promoted", Inst)
607 << "Promote indirect call to " << NV("DirectCallee", DirectCallee)
608 << " with count " << NV("Count", Count) << " out of "
609 << NV("TotalCount", TotalCount));
616 ORE->emit([&]() {
617 return OptimizationRemark(DEBUG_TYPE, "Promoted", Inst)
618 << "Promote indirect call to " << NV("DirectCallee", DirectCallee)
619 << " with count " << NV("Count", Count) << " out of "
620 << NV("TotalCount", TotalCount);
621 });
610622 return NewInst;
611623 }
612624
15091509 OS.flush();
15101510 Function *F = TI->getParent()->getParent();
15111511 OptimizationRemarkEmitter ORE(F);
1512 ORE.emit(OptimizationRemark(DEBUG_TYPE, "pgo-instrumentation", TI)
1513 << BrCondStr << " is true with probability : " << BranchProbStr);
1512 ORE.emit([&]() {
1513 return OptimizationRemark(DEBUG_TYPE, "pgo-instrumentation", TI)
1514 << BrCondStr << " is true with probability : " << BranchProbStr;
1515 });
15141516 }
15151517 }
15161518
381381 DEBUG(dbgs() << *DefaultBB << "\n");
382382 DEBUG(dbgs() << *MergeBB << "\n");
383383
384 {
384 ORE.emit([&]() {
385385 using namespace ore;
386 ORE.emit(OptimizationRemark(DEBUG_TYPE, "memopt-opt", MI)
386 return OptimizationRemark(DEBUG_TYPE, "memopt-opt", MI)
387387 << "optimized " << NV("Intrinsic", StringRef(getMIName(MI)))
388388 << " with count " << NV("Count", SumForOpt) << " out of "
389389 << NV("Total", TotalCount) << " for " << NV("Versions", Version)
390 << " versions");
391 }
390 << " versions";
391 });
392392
393393 return true;
394394 }
12751275 if (V->getType()->isPtrOrPtrVectorTy())
12761276 MD->invalidateCachedPointerInfo(V);
12771277 markInstructionForDeletion(LI);
1278 ORE->emit(OptimizationRemark(DEBUG_TYPE, "LoadPRE", LI)
1279 << "load eliminated by PRE");
1278 ORE->emit([&]() {
1279 return OptimizationRemark(DEBUG_TYPE, "LoadPRE", LI)
1280 << "load eliminated by PRE";
1281 });
12801282 ++NumPRELoad;
12811283 return true;
12821284 }
12851287 OptimizationRemarkEmitter *ORE) {
12861288 using namespace ore;
12871289
1288 ORE->emit(OptimizationRemark(DEBUG_TYPE, "LoadElim", LI)
1289 << "load of type " << NV("Type", LI->getType()) << " eliminated"
1290 << setExtraArgs() << " in favor of "
1291 << NV("InfavorOfValue", AvailableValue));
1290 ORE->emit([&]() {
1291 return OptimizationRemark(DEBUG_TYPE, "LoadElim", LI)
1292 << "load of type " << NV("Type", LI->getType()) << " eliminated"
1293 << setExtraArgs() << " in favor of "
1294 << NV("InfavorOfValue", AvailableValue);
1295 });
12921296 }
12931297
12941298 /// Attempt to eliminate a load whose dependencies are
611611 // Check loop-invariant address because this may also be a sinkable load
612612 // whose address is not necessarily loop-invariant.
613613 if (ORE && Invalidated && CurLoop->isLoopInvariant(LI->getPointerOperand()))
614 ORE->emit(OptimizationRemarkMissed(
615 DEBUG_TYPE, "LoadWithLoopInvariantAddressInvalidated", LI)
616 << "failed to move load with loop-invariant address "
617 "because the loop may invalidate its value");
614 ORE->emit([&]() {
615 return OptimizationRemarkMissed(
616 DEBUG_TYPE, "LoadWithLoopInvariantAddressInvalidated", LI)
617 << "failed to move load with loop-invariant address "
618 "because the loop may invalidate its value";
619 });
618620
619621 return !Invalidated;
620622 } else if (CallInst *CI = dyn_cast(&I)) {
813815 const LoopSafetyInfo *SafetyInfo,
814816 OptimizationRemarkEmitter *ORE) {
815817 DEBUG(dbgs() << "LICM sinking instruction: " << I << "\n");
816 ORE->emit(OptimizationRemark(DEBUG_TYPE, "InstSunk", &I)
817 << "sinking " << ore::NV("Inst", &I));
818 ORE->emit([&]() {
819 return OptimizationRemark(DEBUG_TYPE, "InstSunk", &I)
820 << "sinking " << ore::NV("Inst", &I);
821 });
818822 bool Changed = false;
819823 if (isa(I))
820824 ++NumMovedLoads;
886890 auto *Preheader = CurLoop->getLoopPreheader();
887891 DEBUG(dbgs() << "LICM hoisting to " << Preheader->getName() << ": " << I
888892 << "\n");
889 ORE->emit(OptimizationRemark(DEBUG_TYPE, "Hoisted", &I)
890 << "hoisting " << ore::NV("Inst", &I));
893 ORE->emit([&]() {
894 return OptimizationRemark(DEBUG_TYPE, "Hoisted", &I) << "hoisting "
895 << ore::NV("Inst", &I);
896 });
891897
892898 // Metadata can be dependent on conditions we are hoisting above.
893899 // Conservatively strip all metadata on the instruction unless we were
937943 if (!GuaranteedToExecute) {
938944 auto *LI = dyn_cast(&Inst);
939945 if (LI && CurLoop->isLoopInvariant(LI->getPointerOperand()))
940 ORE->emit(OptimizationRemarkMissed(
941 DEBUG_TYPE, "LoadWithLoopInvariantAddressCondExecuted", LI)
942 << "failed to hoist load with loop-invariant address "
943 "because load is conditionally executed");
946 ORE->emit([&]() {
947 return OptimizationRemarkMissed(
948 DEBUG_TYPE, "LoadWithLoopInvariantAddressCondExecuted", LI)
949 << "failed to hoist load with loop-invariant address "
950 "because load is conditionally executed";
951 });
944952 }
945953
946954 return GuaranteedToExecute;
12561264 // Otherwise, this is safe to promote, lets do it!
12571265 DEBUG(dbgs() << "LICM: Promoting value stored to in loop: " << *SomePtr
12581266 << '\n');
1259 ORE->emit(
1260 OptimizationRemark(DEBUG_TYPE, "PromoteLoopAccessesToScalar", LoopUses[0])
1261 << "Moving accesses to memory location out of the loop");
1267 ORE->emit([&]() {
1268 return OptimizationRemark(DEBUG_TYPE, "PromoteLoopAccessesToScalar",
1269 LoopUses[0])
1270 << "Moving accesses to memory location out of the loop";
1271 });
12621272 ++NumPromoted;
12631273
12641274 // Grab a debug location for the inserted loads/stores; given that the
326326 ++NumPrefetches;
327327 DEBUG(dbgs() << " Access: " << *PtrValue << ", SCEV: " << *LSCEV
328328 << "\n");
329 ORE->emit(OptimizationRemark(DEBUG_TYPE, "Prefetched", MemI)
330 << "prefetched memory access");
329 ORE->emit([&]() {
330 return OptimizationRemark(DEBUG_TYPE, "Prefetched", MemI)
331 << "prefetched memory access";
332 });
331333
332334 MadeChange = true;
333335 }
754754
755755 ++NumLoopsDistributed;
756756 // Report the success.
757 ORE->emit(OptimizationRemark(LDIST_NAME, "Distribute", L->getStartLoc(),
758 L->getHeader())
759 << "distributed loop");
757 ORE->emit([&]() {
758 return OptimizationRemark(LDIST_NAME, "Distribute", L->getStartLoc(),
759 L->getHeader())
760 << "distributed loop";
761 });
760762 return true;
761763 }
762764
768770 DEBUG(dbgs() << "Skipping; " << Message << "\n");
769771
770772 // With Rpass-missed report that distribution failed.
771 ORE->emit(
772 OptimizationRemarkMissed(LDIST_NAME, "NotDistributed", L->getStartLoc(),
773 L->getHeader())
774 << "loop not distributed: use -Rpass-analysis=loop-distribute for more "
775 "info");
773 ORE->emit([&]() {
774 return OptimizationRemarkMissed(LDIST_NAME, "NotDistributed",
775 L->getStartLoc(), L->getHeader())
776 << "loop not distributed: use -Rpass-analysis=loop-distribute for "
777 "more "
778 "info";
779 });
776780
777781 // With Rpass-analysis report why. This is on by default if distribution
778782 // was requested explicitly.
595595 return false;
596596 }
597597
598 ORE->emit(OptimizationRemark(DEBUG_TYPE, "Interchanged",
599 InnerLoop->getStartLoc(),
600 InnerLoop->getHeader())
601 << "Loop interchanged with enclosing loop.");
598 ORE->emit([&]() {
599 return OptimizationRemark(DEBUG_TYPE, "Interchanged",
600 InnerLoop->getStartLoc(),
601 InnerLoop->getHeader())
602 << "Loop interchanged with enclosing loop.";
603 });
602604
603605 LoopInterchangeTransform LIT(OuterLoop, InnerLoop, SE, LI, DT,
604606 LoopNestExit, LIL.hasInnerLoopReduction());
771773 if (!findInductionAndReductions(InnerLoop, Inductions, Reductions)) {
772774 DEBUG(dbgs() << "Only inner loops with induction or reduction PHI nodes "
773775 << "are supported currently.\n");
774 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
775 "UnsupportedPHIInner",
776 InnerLoop->getStartLoc(),
777 InnerLoop->getHeader())
778 << "Only inner loops with induction or reduction PHI nodes can be"
779 " interchange currently.");
776 ORE->emit([&]() {
777 return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedPHIInner",
778 InnerLoop->getStartLoc(),
779 InnerLoop->getHeader())
780 << "Only inner loops with induction or reduction PHI nodes can be"
781 " interchange currently.";
782 });
780783 return true;
781784 }
782785
784787 if (Inductions.size() != 1) {
785788 DEBUG(dbgs() << "We currently only support loops with 1 induction variable."
786789 << "Failed to interchange due to current limitation\n");
787 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
788 "MultiInductionInner",
789 InnerLoop->getStartLoc(),
790 InnerLoop->getHeader())
791 << "Only inner loops with 1 induction variable can be "
792 "interchanged currently.");
790 ORE->emit([&]() {
791 return OptimizationRemarkMissed(DEBUG_TYPE, "MultiInductionInner",
792 InnerLoop->getStartLoc(),
793 InnerLoop->getHeader())
794 << "Only inner loops with 1 induction variable can be "
795 "interchanged currently.";
796 });
793797 return true;
794798 }
795799 if (Reductions.size() > 0)
800804 if (!findInductionAndReductions(OuterLoop, Inductions, Reductions)) {
801805 DEBUG(dbgs() << "Only outer loops with induction or reduction PHI nodes "
802806 << "are supported currently.\n");
803 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
804 "UnsupportedPHIOuter",
805 OuterLoop->getStartLoc(),
806 OuterLoop->getHeader())
807 << "Only outer loops with induction or reduction PHI nodes can be"
808 " interchanged currently.");
807 ORE->emit([&]() {
808 return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedPHIOuter",
809 OuterLoop->getStartLoc(),
810 OuterLoop->getHeader())
811 << "Only outer loops with induction or reduction PHI nodes can be"
812 " interchanged currently.";
813 });
809814 return true;
810815 }
811816
814819 if (!Reductions.empty()) {
815820 DEBUG(dbgs() << "Outer loops with reductions are not supported "
816821 << "currently.\n");
817 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
818 "ReductionsOuter",
819 OuterLoop->getStartLoc(),
820 OuterLoop->getHeader())
821 << "Outer loops with reductions cannot be interchangeed "
822 "currently.");
822 ORE->emit([&]() {
823 return OptimizationRemarkMissed(DEBUG_TYPE, "ReductionsOuter",
824 OuterLoop->getStartLoc(),
825 OuterLoop->getHeader())
826 << "Outer loops with reductions cannot be interchangeed "
827 "currently.";
828 });
823829 return true;
824830 }
825831 // TODO: Currently we handle only loops with 1 induction variable.
826832 if (Inductions.size() != 1) {
827833 DEBUG(dbgs() << "Loops with more than 1 induction variables are not "
828834 << "supported currently.\n");
829 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
830 "MultiIndutionOuter",
831 OuterLoop->getStartLoc(),
832 OuterLoop->getHeader())
833 << "Only outer loops with 1 induction variable can be "
834 "interchanged currently.");
835 ORE->emit([&]() {
836 return OptimizationRemarkMissed(DEBUG_TYPE, "MultiIndutionOuter",
837 OuterLoop->getStartLoc(),
838 OuterLoop->getHeader())
839 << "Only outer loops with 1 induction variable can be "
840 "interchanged currently.";
841 });
835842 return true;
836843 }
837844
838845 // TODO: Triangular loops are not handled for now.
839846 if (!isLoopStructureUnderstood(InnerInductionVar)) {
840847 DEBUG(dbgs() << "Loop structure not understood by pass\n");
841 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
842 "UnsupportedStructureInner",
843 InnerLoop->getStartLoc(),
844 InnerLoop->getHeader())
845 << "Inner loop structure not understood currently.");
848 ORE->emit([&]() {
849 return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedStructureInner",
850 InnerLoop->getStartLoc(),
851 InnerLoop->getHeader())
852 << "Inner loop structure not understood currently.";
853 });
846854 return true;
847855 }
848856
851859 getLoopLatchExitBlock(OuterLoopLatch, OuterLoopHeader);
852860 if (!LoopExitBlock || !containsSafePHI(LoopExitBlock, true)) {
853861 DEBUG(dbgs() << "Can only handle LCSSA PHIs in outer loops currently.\n");
854 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
855 "NoLCSSAPHIOuter",
856 OuterLoop->getStartLoc(),
857 OuterLoop->getHeader())
858 << "Only outer loops with LCSSA PHIs can be interchange "
859 "currently.");
862 ORE->emit([&]() {
863 return OptimizationRemarkMissed(DEBUG_TYPE, "NoLCSSAPHIOuter",
864 OuterLoop->getStartLoc(),
865 OuterLoop->getHeader())
866 << "Only outer loops with LCSSA PHIs can be interchange "
867 "currently.";
868 });
860869 return true;
861870 }
862871
863872 LoopExitBlock = getLoopLatchExitBlock(InnerLoopLatch, InnerLoopHeader);
864873 if (!LoopExitBlock || !containsSafePHI(LoopExitBlock, false)) {
865874 DEBUG(dbgs() << "Can only handle LCSSA PHIs in inner loops currently.\n");
866 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
867 "NoLCSSAPHIOuterInner",
868 InnerLoop->getStartLoc(),
869 InnerLoop->getHeader())
870 << "Only inner loops with LCSSA PHIs can be interchange "
871 "currently.");
875 ORE->emit([&]() {
876 return OptimizationRemarkMissed(DEBUG_TYPE, "NoLCSSAPHIOuterInner",
877 InnerLoop->getStartLoc(),
878 InnerLoop->getHeader())
879 << "Only inner loops with LCSSA PHIs can be interchange "
880 "currently.";
881 });
872882 return true;
873883 }
874884
893903 if (!InnerIndexVarInc) {
894904 DEBUG(dbgs() << "Did not find an instruction to increment the induction "
895905 << "variable.\n");
896 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
897 "NoIncrementInInner",
898 InnerLoop->getStartLoc(),
899 InnerLoop->getHeader())
900 << "The inner loop does not increment the induction variable.");
906 ORE->emit([&]() {
907 return OptimizationRemarkMissed(DEBUG_TYPE, "NoIncrementInInner",
908 InnerLoop->getStartLoc(),
909 InnerLoop->getHeader())
910 << "The inner loop does not increment the induction variable.";
911 });
901912 return true;
902913 }
903914
916927 if (!I.isIdenticalTo(InnerIndexVarInc)) {
917928 DEBUG(dbgs() << "Found unsupported instructions between induction "
918929 << "variable increment and branch.\n");
919 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
920 "UnsupportedInsBetweenInduction",
921 InnerLoop->getStartLoc(),
922 InnerLoop->getHeader())
923 << "Found unsupported instruction between induction variable "
924 "increment and branch.");
930 ORE->emit([&]() {
931 return OptimizationRemarkMissed(
932 DEBUG_TYPE, "UnsupportedInsBetweenInduction",
933 InnerLoop->getStartLoc(), InnerLoop->getHeader())
934 << "Found unsupported instruction between induction variable "
935 "increment and branch.";
936 });
925937 return true;
926938 }
927939
932944 // current limitation.
933945 if (!FoundInduction) {
934946 DEBUG(dbgs() << "Did not find the induction variable.\n");
935 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
936 "NoIndutionVariable",
937 InnerLoop->getStartLoc(),
938 InnerLoop->getHeader())
939 << "Did not find the induction variable.");
947 ORE->emit([&]() {
948 return OptimizationRemarkMissed(DEBUG_TYPE, "NoIndutionVariable",
949 InnerLoop->getStartLoc(),
950 InnerLoop->getHeader())
951 << "Did not find the induction variable.";
952 });
940953 return true;
941954 }
942955 return false;
950963 DEBUG(dbgs() << "Failed interchange InnerLoopId = " << InnerLoopId
951964 << " and OuterLoopId = " << OuterLoopId
952965 << " due to dependence\n");
953 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
954 "Dependence",
955 InnerLoop->getStartLoc(),
956 InnerLoop->getHeader())
957 << "Cannot interchange loops due to dependences.");
966 ORE->emit([&]() {
967 return OptimizationRemarkMissed(DEBUG_TYPE, "Dependence",
968 InnerLoop->getStartLoc(),
969 InnerLoop->getHeader())
970 << "Cannot interchange loops due to dependences.";
971 });
958972 return false;
959973 }
960974
10021016 // Check if the loops are tightly nested.
10031017 if (!tightlyNested(OuterLoop, InnerLoop)) {
10041018 DEBUG(dbgs() << "Loops not tightly nested\n");
1005 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
1006 "NotTightlyNested",
1007 InnerLoop->getStartLoc(),
1008 InnerLoop->getHeader())
1009 << "Cannot interchange loops because they are not tightly "
1010 "nested.");
1019 ORE->emit([&]() {
1020 return OptimizationRemarkMissed(DEBUG_TYPE, "NotTightlyNested",
1021 InnerLoop->getStartLoc(),
1022 InnerLoop->getHeader())
1023 << "Cannot interchange loops because they are not tightly "
1024 "nested.";
1025 });
10111026 return false;
10121027 }
10131028
11041119 if (isProfitableForVectorization(InnerLoopId, OuterLoopId, DepMatrix))
11051120 return true;
11061121
1107 ORE->emit(OptimizationRemarkMissed(DEBUG_TYPE,
1108 "InterchangeNotProfitable",
1109 InnerLoop->getStartLoc(),
1110 InnerLoop->getHeader())
1111 << "Interchanging loops is too costly (cost="
1112 << ore::NV("Cost", Cost) << ", threshold="
1113 << ore::NV("Threshold", LoopInterchangeCostThreshold) <<
1114 ") and it does not improve parallelism.");
1122 ORE->emit([&]() {
1123 return OptimizationRemarkMissed(DEBUG_TYPE, "InterchangeNotProfitable",
1124 InnerLoop->getStartLoc(),
1125 InnerLoop->getHeader())
1126 << "Interchanging loops is too costly (cost="
1127 << ore::NV("Cost", Cost) << ", threshold="
1128 << ore::NV("Threshold", LoopInterchangeCostThreshold)
1129 << ") and it does not improve parallelism.";
1130 });
11151131 return false;
11161132 }
11171133
841841 }
842842 if (UP.Count < 2) {
843843 if (PragmaEnableUnroll)
844 ORE->emit(
845 OptimizationRemarkMissed(DEBUG_TYPE, "UnrollAsDirectedTooLarge",
846 L->getStartLoc(), L->getHeader())
847 << "Unable to unroll loop as directed by unroll(enable) pragma "
848 "because unrolled size is too large.");
844 ORE->emit([&]() {
845 return OptimizationRemarkMissed(DEBUG_TYPE,
846 "UnrollAsDirectedTooLarge",
847 L->getStartLoc(), L->getHeader())
848 << "Unable to unroll loop as directed by unroll(enable) "
849 "pragma "
850 "because unrolled size is too large.";
851 });
849852 UP.Count = 0;
850853 }
851854 } else {
855858 UP.Count = UP.MaxCount;
856859 if ((PragmaFullUnroll || PragmaEnableUnroll) && TripCount &&
857860 UP.Count != TripCount)
858 ORE->emit(
859 OptimizationRemarkMissed(DEBUG_TYPE, "FullUnrollAsDirectedTooLarge",
860 L->getStartLoc(), L->getHeader())
861 << "Unable to fully unroll loop as directed by unroll pragma because "
862 "unrolled size is too large.");
861 ORE->emit([&]() {
862 return OptimizationRemarkMissed(DEBUG_TYPE,
863 "FullUnrollAsDirectedTooLarge",
864 L->getStartLoc(), L->getHeader())
865 << "Unable to fully unroll loop as directed by unroll pragma "
866 "because "
867 "unrolled size is too large.";
868 });
863869 return ExplicitUnroll;
864870 }
865871 assert(TripCount == 0 &&
866872 "All cases when TripCount is constant should be covered here.");
867873 if (PragmaFullUnroll)
868 ORE->emit(
869 OptimizationRemarkMissed(DEBUG_TYPE,
870 "CantFullUnrollAsDirectedRuntimeTripCount",
871 L->getStartLoc(), L->getHeader())
872 << "Unable to fully unroll loop as directed by unroll(full) pragma "
873 "because loop has a runtime trip count.");
874 ORE->emit([&]() {
875 return OptimizationRemarkMissed(
876 DEBUG_TYPE, "CantFullUnrollAsDirectedRuntimeTripCount",
877 L->getStartLoc(), L->getHeader())
878 << "Unable to fully unroll loop as directed by unroll(full) "
879 "pragma "
880 "because loop has a runtime trip count.";
881 });
874882
875883 // 6th priority is runtime unrolling.
876884 // Don't unroll a runtime trip count loop when it is disabled.
921929 << OrigCount << " to " << UP.Count << ".\n");
922930 using namespace ore;
923931 if (PragmaCount > 0 && !UP.AllowRemainder)
924 ORE->emit(
925 OptimizationRemarkMissed(DEBUG_TYPE,
926 "DifferentUnrollCountFromDirected",
927 L->getStartLoc(), L->getHeader())
928 << "Unable to unroll loop the number of times directed by "
929 "unroll_count pragma because remainder loop is restricted "
930 "(that could architecture specific or because the loop "
931 "contains a convergent instruction) and so must have an unroll "
932 "count that divides the loop trip multiple of "
933 << NV("TripMultiple", TripMultiple) << ". Unrolling instead "
934 << NV("UnrollCount", UP.Count) << " time(s).");
932 ORE->emit([&]() {
933 return OptimizationRemarkMissed(DEBUG_TYPE,
934 "DifferentUnrollCountFromDirected",
935 L->getStartLoc(), L->getHeader())
936 << "Unable to unroll loop the number of times directed by "
937 "unroll_count pragma because remainder loop is restricted "
938 "(that could architecture specific or because the loop "
939 "contains a convergent instruction) and so must have an "
940 "unroll "
941 "count that divides the loop trip multiple of "
942 << NV("TripMultiple", TripMultiple) << ". Unrolling instead "
943 << NV("UnrollCount", UP.Count) << " time(s).";
944 });
935945 }
936946
937947 if (UP.Count > UP.MaxCount)
254254 }
255255 if (SafeToTail) {
256256 using namespace ore;
257 ORE->emit(OptimizationRemark(DEBUG_TYPE, "tailcall-readnone", CI)
258 << "marked as tail call candidate (readnone)");
257 ORE->emit([&]() {
258 return OptimizationRemark(DEBUG_TYPE, "tailcall-readnone", CI)
259 << "marked as tail call candidate (readnone)";
260 });
259261 CI->setTailCall();
260262 Modified = true;
261263 continue;
300302 if (Visited[CI->getParent()] != ESCAPED) {
301303 // If the escape point was part way through the block, calls after the
302304 // escape point wouldn't have been put into DeferredTails.
303 ORE->emit(OptimizationRemark(DEBUG_TYPE, "tailcall", CI)
304 << "marked as tail call candidate");
305 ORE->emit([&]() {
306 return OptimizationRemark(DEBUG_TYPE, "tailcall", CI)
307 << "marked as tail call candidate";
308 });
305309 CI->setTailCall();
306310 Modified = true;
307311 } else {
553557 Function *F = BB->getParent();
554558
555559 using namespace ore;
556 ORE->emit(OptimizationRemark(DEBUG_TYPE, "tailcall-recursion", CI)
557 << "transforming tail recursion into loop");
560 ORE->emit([&]() {
561 return OptimizationRemark(DEBUG_TYPE, "tailcall-recursion", CI)
562 << "transforming tail recursion into loop";
563 });
558564
559565 // OK! We can transform this tail call. If this is the first one found,
560566 // create the new entry block, allowing us to branch back to the old entry.
459459 // Report the unrolling decision.
460460 if (CompletelyUnroll) {
461461 DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName()
462 << " with trip count " << TripCount << "!\n");
463 ORE->emit(OptimizationRemark(DEBUG_TYPE, "FullyUnrolled", L->getStartLoc(),
464 L->getHeader())
465 << "completely unrolled loop with "
466 << NV("UnrollCount", TripCount) << " iterations");
462 << " with trip count " << TripCount << "!\n");
463 ORE->emit([&]() {
464 return OptimizationRemark(DEBUG_TYPE, "FullyUnrolled", L->getStartLoc(),
465 L->getHeader())
466 << "completely unrolled loop with " << NV("UnrollCount", TripCount)
467 << " iterations";
468 });
467469 } else if (PeelCount) {
468470 DEBUG(dbgs() << "PEELING loop %" << Header->getName()
469471 << " with iteration count " << PeelCount << "!\n");
470 ORE->emit(OptimizationRemark(DEBUG_TYPE, "Peeled", L->getStartLoc(),
471 L->getHeader())
472 << " peeled loop by " << NV("PeelCount", PeelCount)
473 << " iterations");
472 ORE->emit([&]() {
473 return OptimizationRemark(DEBUG_TYPE, "Peeled", L->getStartLoc(),
474 L->getHeader())
475 << " peeled loop by " << NV("PeelCount", PeelCount)
476 << " iterations";
477 });
474478 } else {
475479 auto DiagBuilder = [&]() {
476480 OptimizationRemark Diag(DEBUG_TYPE, "PartialUnrolled", L->getStartLoc(),
484484 uint64_t LenTrue = GetStringLength(SI->getTrueValue(), CharSize);
485485 uint64_t LenFalse = GetStringLength(SI->getFalseValue(), CharSize);
486486 if (LenTrue && LenFalse) {
487 ORE.emit(OptimizationRemark("instcombine", "simplify-libcalls", CI)
488 << "folded strlen(select) to select of constants");
487 ORE.emit([&]() {
488 return OptimizationRemark("instcombine", "simplify-libcalls", CI)
489 << "folded strlen(select) to select of constants";
490 });
489491 return B.CreateSelect(SI->getCondition(),
490492 ConstantInt::get(CI->getType(), LenTrue - 1),
491493 ConstantInt::get(CI->getType(), LenFalse - 1));
12471247 /// Dumps all the hint information.
12481248 void emitRemarkWithHints() const {
12491249 using namespace ore;
1250 if (Force.Value == LoopVectorizeHints::FK_Disabled)
1251 ORE.emit(OptimizationRemarkMissed(LV_NAME, "MissedExplicitlyDisabled",
1250 ORE.emit([&]() {
1251 if (Force.Value == LoopVectorizeHints::FK_Disabled)
1252 return OptimizationRemarkMissed(LV_NAME, "MissedExplicitlyDisabled",
12521253 TheLoop->getStartLoc(),
12531254 TheLoop->getHeader())
1254 << "loop not vectorized: vectorization is explicitly disabled");
1255 else {
1256 OptimizationRemarkMissed R(LV_NAME, "MissedDetails",
1257 TheLoop->getStartLoc(), TheLoop->getHeader());
1258 R << "loop not vectorized";
1259 if (Force.Value == LoopVectorizeHints::FK_Enabled) {
1260 R << " (Force=" << NV("Force", true);
1261 if (Width.Value != 0)
1262 R << ", Vector Width=" << NV("VectorWidth", Width.Value);
1263 if (Interleave.Value != 0)
1264 R << ", Interleave Count=" << NV("InterleaveCount", Interleave.Value);
1265 R << ")";
1255 << "loop not vectorized: vectorization is explicitly disabled";
1256 else {
1257 OptimizationRemarkMissed R(LV_NAME, "MissedDetails",
1258 TheLoop->getStartLoc(),
1259 TheLoop->getHeader());
1260 R << "loop not vectorized";
1261 if (Force.Value == LoopVectorizeHints::FK_Enabled) {
1262 R << " (Force=" << NV("Force", true);
1263 if (Width.Value != 0)
1264 R << ", Vector Width=" << NV("VectorWidth", Width.Value);
1265 if (Interleave.Value != 0)
1266 R << ", Interleave Count="
1267 << NV("InterleaveCount", Interleave.Value);
1268 R << ")";
1269 }
1270 return R;
12661271 }
1267 ORE.emit(R);
1268 }
1272 });
12691273 }
12701274
12711275 unsigned getWidth() const { return Width.Value; }
22762280 const char *PassName = Hints.vectorizeAnalysisPassName();
22772281 bool Failed = false;
22782282 if (UnsafeAlgebraInst && !Hints.allowReordering()) {
2279 ORE.emit(
2280 OptimizationRemarkAnalysisFPCommute(PassName, "CantReorderFPOps",
2281 UnsafeAlgebraInst->getDebugLoc(),
2282 UnsafeAlgebraInst->getParent())
2283 << "loop not vectorized: cannot prove it is safe to reorder "
2284 "floating-point operations");
2283 ORE.emit([&]() {
2284 return OptimizationRemarkAnalysisFPCommute(
2285 PassName, "CantReorderFPOps",
2286 UnsafeAlgebraInst->getDebugLoc(),
2287 UnsafeAlgebraInst->getParent())
2288 << "loop not vectorized: cannot prove it is safe to reorder "
2289 "floating-point operations";
2290 });
22852291 Failed = true;
22862292 }
22872293
22922298 NumRuntimePointerChecks > VectorizerParams::RuntimeMemoryCheckThreshold;
22932299 if ((ThresholdReached && !Hints.allowReordering()) ||
22942300 PragmaThresholdReached) {
2295 ORE.emit(OptimizationRemarkAnalysisAliasing(PassName, "CantReorderMemOps",
2301 ORE.emit([&]() {
2302 return OptimizationRemarkAnalysisAliasing(PassName, "CantReorderMemOps",
22962303 L->getStartLoc(),
22972304 L->getHeader())
22982305 << "loop not vectorized: cannot prove it is safe to reorder "
2299 "memory operations");
2306 "memory operations";
2307 });
23002308 DEBUG(dbgs() << "LV: Too many memory checks needed.\n");
23012309 Failed = true;
23022310 }
57415749 InterleaveInfo.setLAI(LAI);
57425750 const OptimizationRemarkAnalysis *LAR = LAI->getReport();
57435751 if (LAR) {
5744 OptimizationRemarkAnalysis VR(Hints->vectorizeAnalysisPassName(),
5745 "loop not vectorized: ", *LAR);
5746 ORE->emit(VR);
5752 ORE->emit([&]() {
5753 return OptimizationRemarkAnalysis(Hints->vectorizeAnalysisPassName(),
5754 "loop not vectorized: ", *LAR);
5755 });
57475756 }
57485757 if (!LAI->canVectorizeMemory())
57495758 return false;
85728581 const char *VAPassName = Hints.vectorizeAnalysisPassName();
85738582 if (!VectorizeLoop && !InterleaveLoop) {
85748583 // Do not vectorize or interleaving the loop.
8575 ORE->emit(OptimizationRemarkMissed(VAPassName, VecDiagMsg.first,
8576 L->getStartLoc(), L->getHeader())
8577 << VecDiagMsg.second);
8578 ORE->emit(OptimizationRemarkMissed(LV_NAME, IntDiagMsg.first,
8579 L->getStartLoc(), L->getHeader())
8580 << IntDiagMsg.second);
8584 ORE->emit([&]() {
8585 return OptimizationRemarkMissed(VAPassName, VecDiagMsg.first,
8586 L->getStartLoc(), L->getHeader())
8587 << VecDiagMsg.second;
8588 });
8589 ORE->emit([&]() {
8590 return OptimizationRemarkMissed(LV_NAME, IntDiagMsg.first,
8591 L->getStartLoc(), L->getHeader())
8592 << IntDiagMsg.second;
8593 });
85818594 return false;
85828595 } else if (!VectorizeLoop && InterleaveLoop) {
85838596 DEBUG(dbgs() << "LV: Interleave Count is " << IC << '\n');
8584 ORE->emit(OptimizationRemarkAnalysis(VAPassName, VecDiagMsg.first,
8585 L->getStartLoc(), L->getHeader())
8586 << VecDiagMsg.second);
8597 ORE->emit([&]() {
8598 return OptimizationRemarkAnalysis(VAPassName, VecDiagMsg.first,
8599 L->getStartLoc(), L->getHeader())
8600 << VecDiagMsg.second;
8601 });
85878602 } else if (VectorizeLoop && !InterleaveLoop) {
85888603 DEBUG(dbgs() << "LV: Found a vectorizable loop (" << VF.Width << ") in "
85898604 << DebugLocStr << '\n');
8590 ORE->emit(OptimizationRemarkAnalysis(LV_NAME, IntDiagMsg.first,
8591 L->getStartLoc(), L->getHeader())
8592 << IntDiagMsg.second);
8605 ORE->emit([&]() {
8606 return OptimizationRemarkAnalysis(LV_NAME, IntDiagMsg.first,
8607 L->getStartLoc(), L->getHeader())
8608 << IntDiagMsg.second;
8609 });
85938610 } else if (VectorizeLoop && InterleaveLoop) {
85948611 DEBUG(dbgs() << "LV: Found a vectorizable loop (" << VF.Width << ") in "
85958612 << DebugLocStr << '\n');
86078624 &CM);
86088625 LVP.executePlan(Unroller, DT);
86098626
8610 ORE->emit(OptimizationRemark(LV_NAME, "Interleaved", L->getStartLoc(),
8611 L->getHeader())
8612 << "interleaved loop (interleaved count: "
8613 << NV("InterleaveCount", IC) << ")");
8627 ORE->emit([&]() {
8628 return OptimizationRemark(LV_NAME, "Interleaved", L->getStartLoc(),
8629 L->getHeader())
8630 << "interleaved loop (interleaved count: "
8631 << NV("InterleaveCount", IC) << ")";
8632 });
86148633 } else {
86158634 // If we decided that it is *legal* to vectorize the loop, then do it.
86168635 InnerLoopVectorizer LB(L, PSE, LI, DT, TLI, TTI, AC, ORE, VF.Width, IC,
86258644 AddRuntimeUnrollDisableMetaData(L);
86268645
86278646 // Report the vectorization decision.
8628 ORE->emit(OptimizationRemark(LV_NAME, "Vectorized", L->getStartLoc(),
8629 L->getHeader())
8630 << "vectorized loop (vectorization width: "
8631 << NV("VectorizationFactor", VF.Width)
8632 << ", interleaved count: " << NV("InterleaveCount", IC) << ")");
8647 ORE->emit([&]() {
8648 return OptimizationRemark(LV_NAME, "Vectorized", L->getStartLoc(),
8649 L->getHeader())
8650 << "vectorized loop (vectorization width: "
8651 << NV("VectorizationFactor", VF.Width)
8652 << ", interleaved count: " << NV("InterleaveCount", IC) << ")";
8653 });
86338654 }
86348655
86358656 // Mark the loop as already vectorized to avoid vectorizing again.