[llvm] r333972 - [ShrinkWrap] Add optimization remarks to the shrink-wrapping pass
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 4 17:27:24 PDT 2018
Author: thegameg
Date: Mon Jun 4 17:27:24 2018
New Revision: 333972
URL: http://llvm.org/viewvc/llvm-project?rev=333972&view=rev
Log:
[ShrinkWrap] Add optimization remarks to the shrink-wrapping pass
Start by emitting remarks for very basic unsupported cases such as
irreducible CFGs and EHFunclets. The end goal is to be able to cover all
the cases where we give up with an explanation.
Modified:
llvm/trunk/lib/CodeGen/ShrinkWrap.cpp
llvm/trunk/test/CodeGen/AArch64/O3-pipeline.ll
llvm/trunk/test/CodeGen/X86/O3-pipeline.ll
llvm/trunk/test/CodeGen/X86/late-address-taken.ll
llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll
Modified: llvm/trunk/lib/CodeGen/ShrinkWrap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ShrinkWrap.cpp?rev=333972&r1=333971&r2=333972&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ShrinkWrap.cpp (original)
+++ llvm/trunk/lib/CodeGen/ShrinkWrap.cpp Mon Jun 4 17:27:24 2018
@@ -63,6 +63,7 @@
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
+#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
#include "llvm/CodeGen/MachinePostDominators.h"
#include "llvm/CodeGen/RegisterClassInfo.h"
#include "llvm/CodeGen/RegisterScavenging.h"
@@ -130,6 +131,9 @@ class ShrinkWrap : public MachineFunctio
/// are in the same loop.
MachineLoopInfo *MLI;
+ // Emit remarks.
+ MachineOptimizationRemarkEmitter *ORE = nullptr;
+
/// Frequency of the Entry block.
uint64_t EntryFreq;
@@ -189,6 +193,7 @@ class ShrinkWrap : public MachineFunctio
Restore = nullptr;
MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
MLI = &getAnalysis<MachineLoopInfo>();
+ ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
EntryFreq = MBFI->getEntryFreq();
const TargetSubtargetInfo &Subtarget = MF.getSubtarget();
const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
@@ -222,6 +227,7 @@ public:
AU.addRequired<MachineDominatorTree>();
AU.addRequired<MachinePostDominatorTree>();
AU.addRequired<MachineLoopInfo>();
+ AU.addRequired<MachineOptimizationRemarkEmitterPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}
@@ -248,6 +254,7 @@ INITIALIZE_PASS_DEPENDENCY(MachineBlockF
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree)
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
+INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
INITIALIZE_PASS_END(ShrinkWrap, DEBUG_TYPE, "Shrink Wrap Pass", false, false)
bool ShrinkWrap::useOrDefCSROrFI(const MachineInstr &MI,
@@ -432,6 +439,19 @@ void ShrinkWrap::updateSaveRestorePoints
}
}
+static bool giveUpWithRemarks(MachineOptimizationRemarkEmitter *ORE,
+ StringRef RemarkName, StringRef RemarkMessage,
+ const DiagnosticLocation &Loc,
+ const MachineBasicBlock *MBB) {
+ ORE->emit([&]() {
+ return MachineOptimizationRemarkMissed(DEBUG_TYPE, RemarkName, Loc, MBB)
+ << RemarkMessage;
+ });
+
+ LLVM_DEBUG(dbgs() << RemarkMessage << '\n');
+ return false;
+}
+
bool ShrinkWrap::runOnMachineFunction(MachineFunction &MF) {
if (skipFunction(MF.getFunction()) || MF.empty() || !isShrinkWrapEnabled(MF))
return false;
@@ -448,8 +468,9 @@ bool ShrinkWrap::runOnMachineFunction(Ma
// results. Moreover, we may miss that the prologue and
// epilogue are not in the same loop, leading to unbalanced
// construction/deconstruction of the stack frame.
- LLVM_DEBUG(dbgs() << "Irreducible CFGs are not supported yet\n");
- return false;
+ return giveUpWithRemarks(ORE, "UnsupportedIrreducibleCFG",
+ "Irreducible CFGs are not supported yet.",
+ MF.getFunction().getSubprogram(), &MF.front());
}
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
@@ -460,10 +481,10 @@ bool ShrinkWrap::runOnMachineFunction(Ma
LLVM_DEBUG(dbgs() << "Look into: " << MBB.getNumber() << ' '
<< MBB.getName() << '\n');
- if (MBB.isEHFuncletEntry()) {
- LLVM_DEBUG(dbgs() << "EH Funclets are not supported yet.\n");
- return false;
- }
+ if (MBB.isEHFuncletEntry())
+ return giveUpWithRemarks(ORE, "UnsupportedEHFunclets",
+ "EH Funclets are not supported yet.",
+ MBB.front().getDebugLoc(), &MBB);
if (MBB.isEHPad()) {
// Push the prologue and epilogue outside of
Modified: llvm/trunk/test/CodeGen/AArch64/O3-pipeline.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/O3-pipeline.ll?rev=333972&r1=333971&r2=333972&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/O3-pipeline.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/O3-pipeline.ll Mon Jun 4 17:27:24 2018
@@ -129,9 +129,9 @@
; CHECK-NEXT: Machine Natural Loop Construction
; CHECK-NEXT: Machine Block Frequency Analysis
; CHECK-NEXT: MachinePostDominator Tree Construction
-; CHECK-NEXT: Shrink Wrapping analysis
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Shrink Wrapping analysis
; CHECK-NEXT: Prologue/Epilogue Insertion & Frame Finalization
; CHECK-NEXT: Control Flow Optimizer
; CHECK-NEXT: Tail Duplication
Modified: llvm/trunk/test/CodeGen/X86/O3-pipeline.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/O3-pipeline.ll?rev=333972&r1=333971&r2=333972&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/O3-pipeline.ll (original)
+++ llvm/trunk/test/CodeGen/X86/O3-pipeline.ll Mon Jun 4 17:27:24 2018
@@ -125,9 +125,9 @@
; CHECK-NEXT: PostRA Machine Sink
; CHECK-NEXT: Machine Block Frequency Analysis
; CHECK-NEXT: MachinePostDominator Tree Construction
-; CHECK-NEXT: Shrink Wrapping analysis
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Shrink Wrapping analysis
; CHECK-NEXT: Prologue/Epilogue Insertion & Frame Finalization
; CHECK-NEXT: Control Flow Optimizer
; CHECK-NEXT: Tail Duplication
Modified: llvm/trunk/test/CodeGen/X86/late-address-taken.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/late-address-taken.ll?rev=333972&r1=333971&r2=333972&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/late-address-taken.ll (original)
+++ llvm/trunk/test/CodeGen/X86/late-address-taken.ll Mon Jun 4 17:27:24 2018
@@ -1,6 +1,7 @@
; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s -enable-shrink-wrap=false | FileCheck %s
; Make sure shrink-wrapping does not break the lowering of exception handling.
-; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s -enable-shrink-wrap=true | FileCheck %s
+; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s -enable-shrink-wrap=true -pass-remarks-output=%t | FileCheck %s
+; RUN: cat %t | FileCheck %s --check-prefix=REMARKS
; Repro cases from PR25168
@@ -37,6 +38,11 @@ exit:
; CHECK: leaq [[Exit]](%rip), %rax
; CHECK: retq # CATCHRET
+; REMARKS: Pass: shrink-wrap
+; REMARKS-NEXT: Name: UnsupportedEHFunclets
+; REMARKS-NEXT: Function: catchret
+; REMARKS-NEXT: Args:
+; REMARKS-NEXT: - String: EH Funclets are not supported yet.
; test @setjmp - similar to @catchret, but the MBB in question
; is the one generated when the setjmp's block is split
Modified: llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll?rev=333972&r1=333971&r2=333972&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll (original)
+++ llvm/trunk/test/CodeGen/X86/x86-shrink-wrapping.ll Mon Jun 4 17:27:24 2018
@@ -1,4 +1,5 @@
-; RUN: llc %s -o - -enable-shrink-wrap=true | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
+; RUN: llc %s -o - -enable-shrink-wrap=true -pass-remarks-output=%t | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
+; RUN: cat %t | FileCheck %s --check-prefix=REMARKS
; RUN: llc %s -o - -enable-shrink-wrap=false | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
;
; Note: Lots of tests use inline asm instead of regular calls.
@@ -940,6 +941,13 @@ attributes #3 = { nounwind }
; CHECK: popq
; CHECK-NEXT: popq
; CHECK-NEXT: retq
+; Make sure we emit missed optimization remarks for this.
+; REMARKS: Pass: shrink-wrap
+; REMARKS-NEXT: Name: UnsupportedIrreducibleCFG
+; REMARKS-NEXT: Function: irreducibleCFG
+; REMARKS-NEXT: Args:
+; REMARKS-NEXT: - String: Irreducible CFGs are not supported yet
+
define i32 @irreducibleCFG() #4 {
entry:
%i0 = load i32, i32* @irreducibleCFGa, align 4
More information about the llvm-commits
mailing list