21
21
#include " llvm/ADT/DepthFirstIterator.h"
22
22
#include " llvm/ADT/SmallPtrSet.h"
23
23
#include " llvm/ADT/Statistic.h"
24
+ #include " llvm/Analysis/OptimizationRemarkEmitter.h"
24
25
#include " llvm/CodeGen/MachineBranchProbabilityInfo.h"
25
26
#include " llvm/CodeGen/MachineDominators.h"
26
27
#include " llvm/CodeGen/MachineFunction.h"
27
28
#include " llvm/CodeGen/MachineFunctionPass.h"
28
29
#include " llvm/CodeGen/MachineInstrBuilder.h"
29
30
#include " llvm/CodeGen/MachineLoopInfo.h"
31
+ #include " llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
30
32
#include " llvm/CodeGen/MachineRegisterInfo.h"
31
33
#include " llvm/CodeGen/MachineTraceMetrics.h"
32
34
#include " llvm/CodeGen/Passes.h"
@@ -129,6 +131,7 @@ class SSACCmpConv {
129
131
const TargetRegisterInfo *TRI;
130
132
MachineRegisterInfo *MRI;
131
133
const MachineBranchProbabilityInfo *MBPI;
134
+ MachineOptimizationRemarkEmitter *ORE;
132
135
133
136
public:
134
137
// / The first block containing a conditional branch, dominating everything
@@ -177,9 +180,11 @@ class SSACCmpConv {
177
180
public:
178
181
// / runOnMachineFunction - Initialize per-function data structures.
179
182
void runOnMachineFunction (MachineFunction &MF,
180
- const MachineBranchProbabilityInfo *MBPI) {
183
+ const MachineBranchProbabilityInfo *MBPI,
184
+ MachineOptimizationRemarkEmitter *ORE) {
181
185
this ->MF = &MF;
182
186
this ->MBPI = MBPI;
187
+ this ->ORE = ORE;
183
188
TII = MF.getSubtarget ().getInstrInfo ();
184
189
TRI = MF.getSubtarget ().getRegisterInfo ();
185
190
MRI = &MF.getRegInfo ();
@@ -663,11 +668,17 @@ void SSACCmpConv::convert(SmallVectorImpl<MachineBasicBlock *> &RemovedBlocks) {
663
668
unsigned NumDefs = CmpMI->getDesc ().getNumDefs ();
664
669
MachineOperand Op0 = CmpMI->getOperand (NumDefs);
665
670
MachineOperand Op1 = CmpMI->getOperand (NumDefs + 1 );
666
- BuildMI (*Head, CmpMI, CmpMI->getDebugLoc (), MCID)
671
+ DebugLoc DL = CmpMI->getDebugLoc ();
672
+ BuildMI (*Head, CmpMI, DL, MCID)
667
673
.add (Op0)
668
674
.add (Op1)
669
675
.addImm (X86::getCondFlagsFromCondCode (CmpBBTailCC))
670
676
.addImm (HeadCmpBBCC);
677
+ ORE->emit ([&]() {
678
+ MachineOptimizationRemark R (DEBUG_TYPE, " ConvertedCMP" , DL, CmpBB);
679
+ R << " convert CMP into conditional CMP" ;
680
+ return R;
681
+ });
671
682
CmpMI->eraseFromParent ();
672
683
Head->updateTerminator (CmpBB->getNextNode ());
673
684
@@ -691,6 +702,7 @@ class X86ConditionalCompares : public MachineFunctionPass {
691
702
MachineDominatorTree *DomTree = nullptr ;
692
703
MachineLoopInfo *Loops = nullptr ;
693
704
MachineTraceMetrics *Traces = nullptr ;
705
+ MachineOptimizationRemarkEmitter *ORE = nullptr ;
694
706
SSACCmpConv CmpConv;
695
707
696
708
public:
@@ -802,9 +814,10 @@ bool X86ConditionalCompares::runOnMachineFunction(MachineFunction &MF) {
802
814
Loops = getAnalysisIfAvailable<MachineLoopInfo>();
803
815
MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
804
816
Traces = &getAnalysis<MachineTraceMetrics>();
817
+ ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE ();
805
818
806
819
bool Changed = false ;
807
- CmpConv.runOnMachineFunction (MF, MBPI);
820
+ CmpConv.runOnMachineFunction (MF, MBPI, ORE );
808
821
809
822
// Visit blocks in dominator tree pre-order. The pre-order enables multiple
810
823
// cmp-conversions from the same head block.
@@ -815,5 +828,16 @@ bool X86ConditionalCompares::runOnMachineFunction(MachineFunction &MF) {
815
828
if (tryConvert (I->getBlock ()))
816
829
Changed = true ;
817
830
831
+ if (NumConverted) {
832
+ ORE->emit ([&]() {
833
+ MachineOptimizationRemarkAnalysis R (DEBUG_TYPE, " NumOfCCMP" ,
834
+ MF.getFunction ().getSubprogram (),
835
+ &MF.front ());
836
+ R << " generate " << ore::NV (" NumConverted" , NumConverted)
837
+ << " CCMP in function to eliminate JCC" ;
838
+ return R;
839
+ });
840
+ }
841
+
818
842
return Changed;
819
843
}
0 commit comments