File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -2057,6 +2057,21 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
2057
2057
// / overhead or too rigid restriction.
2058
2058
virtual unsigned getMemOperandAACheckLimit () const { return 16 ; }
2059
2059
2060
+ // / Return the maximum number of memory operands to check instruction for
2061
+ // / memory-related properties.
2062
+ // /
2063
+ // / After MIR transformations like tail merging etc. memory operands are
2064
+ // / united for the merged result instructions. Compiler might ends up with
2065
+ // / thousands of memory operands for each instruction for tricky CFGs like
2066
+ // / for switch construction.
2067
+ // /
2068
+ // / Even linear algorithms on instructions with thousands of memory operands
2069
+ // / leads to significant compilation slowdown.
2070
+ // /
2071
+ // / Heuristic is designed to limit checks count for algorithms where
2072
+ // / conservative answer like "I don't know" is possible.
2073
+ virtual unsigned getMemOperandLinearCheckLimit () const { return 16 ; }
2074
+
2060
2075
// / Return an array that contains the ids of the target indices (used for the
2061
2076
// / TargetIndex machine operand) and their names.
2062
2077
// /
Original file line number Diff line number Diff line change @@ -1581,6 +1581,12 @@ bool MachineInstr::hasOrderedMemoryRef() const {
1581
1581
if (memoperands_empty ())
1582
1582
return true ;
1583
1583
1584
+ // Conservatively skip analysis if there are too many memory operands. Keep
1585
+ // compilation time reasonable.
1586
+ const TargetInstrInfo *TII = getMF ()->getSubtarget ().getInstrInfo ();
1587
+ if (getNumMemOperands () > TII->getMemOperandLinearCheckLimit ())
1588
+ return true ;
1589
+
1584
1590
// Check if any of our memory operands are ordered.
1585
1591
return llvm::any_of (memoperands (), [](const MachineMemOperand *MMO) {
1586
1592
return !MMO->isUnordered ();
@@ -1600,7 +1606,15 @@ bool MachineInstr::isDereferenceableInvariantLoad() const {
1600
1606
if (memoperands_empty ())
1601
1607
return false ;
1602
1608
1603
- const MachineFrameInfo &MFI = getParent ()->getParent ()->getFrameInfo ();
1609
+ const MachineFunction &MF = *getMF ();
1610
+
1611
+ // Conservatively skip analysis if there are too many memory operands. Keep
1612
+ // compilation time reasonable.
1613
+ const TargetInstrInfo *TII = MF.getSubtarget ().getInstrInfo ();
1614
+ if (getNumMemOperands () > TII->getMemOperandLinearCheckLimit ())
1615
+ return false ;
1616
+
1617
+ const MachineFrameInfo &MFI = MF.getFrameInfo ();
1604
1618
1605
1619
for (MachineMemOperand *MMO : memoperands ()) {
1606
1620
if (!MMO->isUnordered ())
You can’t perform that action at this time.
0 commit comments