@@ -437,27 +437,26 @@ class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
437
437
// / Infer a CodeGenRegisterClass for the type of \p SuperRegNode. The returned
438
438
// / CodeGenRegisterClass will support the CodeGenRegisterClass of
439
439
// / \p SubRegNode, and the subregister index defined by \p SubRegIdxNode.
440
- // / If no register class is found, return std::nullopt .
441
- std::optional< const CodeGenRegisterClass *>
440
+ // / If no register class is found, return nullptr .
441
+ const CodeGenRegisterClass *
442
442
inferSuperRegisterClassForNode (const TypeSetByHwMode &Ty,
443
443
const TreePatternNode &SuperRegNode,
444
444
const TreePatternNode &SubRegIdxNode);
445
- std::optional< CodeGenSubRegIndex *>
445
+ const CodeGenSubRegIndex *
446
446
inferSubRegIndexForNode (const TreePatternNode &SubRegIdxNode);
447
447
448
448
// / Infer a CodeGenRegisterClass which suppoorts \p Ty and \p SubRegIdxNode.
449
- // / Return std::nullopt if no such class exists.
450
- std::optional< const CodeGenRegisterClass *>
449
+ // / Return nullptr if no such class exists.
450
+ const CodeGenRegisterClass *
451
451
inferSuperRegisterClass (const TypeSetByHwMode &Ty,
452
452
const TreePatternNode &SubRegIdxNode);
453
453
454
454
// / Return the CodeGenRegisterClass associated with \p Leaf if it has one.
455
- std::optional<const CodeGenRegisterClass *>
456
- getRegClassFromLeaf (const TreePatternNode &Leaf);
455
+ const CodeGenRegisterClass *getRegClassFromLeaf (const TreePatternNode &Leaf);
457
456
458
457
// / Return a CodeGenRegisterClass for \p N if one can be found. Return
459
- // / std::nullopt otherwise.
460
- std::optional< const CodeGenRegisterClass *>
458
+ // / nullptr otherwise.
459
+ const CodeGenRegisterClass *
461
460
inferRegClassFromPattern (const TreePatternNode &N);
462
461
463
462
Error constrainOperands (action_iterator InsertPt, RuleMatcher &M,
@@ -1733,12 +1732,13 @@ Error GlobalISelEmitter::constrainOperands(action_iterator InsertPt,
1733
1732
M.insertAction <ConstrainOperandToRegClassAction>(
1734
1733
InsertPt, InsnID, 0 , Target.getRegisterClass (DstIOpRec));
1735
1734
} else if (DstIName == " EXTRACT_SUBREG" ) {
1736
- auto SuperClass = inferRegClassFromPattern (Dst.getChild (0 ));
1735
+ const CodeGenRegisterClass *SuperClass =
1736
+ inferRegClassFromPattern (Dst.getChild (0 ));
1737
1737
if (!SuperClass)
1738
1738
return failedImport (
1739
1739
" Cannot infer register class from EXTRACT_SUBREG operand #0" );
1740
1740
1741
- auto SubIdx = inferSubRegIndexForNode (Dst.getChild (1 ));
1741
+ const CodeGenSubRegIndex * SubIdx = inferSubRegIndexForNode (Dst.getChild (1 ));
1742
1742
if (!SubIdx)
1743
1743
return failedImport (" EXTRACT_SUBREG child #1 is not a subreg index" );
1744
1744
@@ -1749,7 +1749,7 @@ Error GlobalISelEmitter::constrainOperands(action_iterator InsertPt,
1749
1749
// FIXME: This may introduce an extra copy if the chosen class doesn't
1750
1750
// actually contain the subregisters.
1751
1751
const auto SrcRCDstRCPair =
1752
- (* SuperClass) ->getMatchingSubClassWithSubRegs (CGRegs, * SubIdx);
1752
+ SuperClass->getMatchingSubClassWithSubRegs (CGRegs, SubIdx);
1753
1753
if (!SrcRCDstRCPair) {
1754
1754
return failedImport (" subreg index is incompatible "
1755
1755
" with inferred reg class" );
@@ -1763,56 +1763,59 @@ Error GlobalISelEmitter::constrainOperands(action_iterator InsertPt,
1763
1763
} else if (DstIName == " INSERT_SUBREG" ) {
1764
1764
// We need to constrain the destination, a super regsister source, and a
1765
1765
// subregister source.
1766
- auto SubClass = inferRegClassFromPattern (Dst.getChild (1 ));
1766
+ const CodeGenRegisterClass *SubClass =
1767
+ inferRegClassFromPattern (Dst.getChild (1 ));
1767
1768
if (!SubClass)
1768
1769
return failedImport (
1769
1770
" Cannot infer register class from INSERT_SUBREG operand #1" );
1770
- auto SuperClass = inferSuperRegisterClassForNode (
1771
+ const CodeGenRegisterClass * SuperClass = inferSuperRegisterClassForNode (
1771
1772
Dst.getExtType (0 ), Dst.getChild (0 ), Dst.getChild (2 ));
1772
1773
if (!SuperClass)
1773
1774
return failedImport (
1774
1775
" Cannot infer register class for INSERT_SUBREG operand #0" );
1775
1776
M.insertAction <ConstrainOperandToRegClassAction>(InsertPt, InsnID, 0 ,
1776
- ** SuperClass);
1777
+ *SuperClass);
1777
1778
M.insertAction <ConstrainOperandToRegClassAction>(InsertPt, InsnID, 1 ,
1778
- ** SuperClass);
1779
+ *SuperClass);
1779
1780
M.insertAction <ConstrainOperandToRegClassAction>(InsertPt, InsnID, 2 ,
1780
- ** SubClass);
1781
+ *SubClass);
1781
1782
} else if (DstIName == " SUBREG_TO_REG" ) {
1782
1783
// We need to constrain the destination and subregister source.
1783
1784
// Attempt to infer the subregister source from the first child. If it has
1784
1785
// an explicitly given register class, we'll use that. Otherwise, we will
1785
1786
// fail.
1786
- auto SubClass = inferRegClassFromPattern (Dst.getChild (1 ));
1787
+ const CodeGenRegisterClass *SubClass =
1788
+ inferRegClassFromPattern (Dst.getChild (1 ));
1787
1789
if (!SubClass)
1788
1790
return failedImport (
1789
1791
" Cannot infer register class from SUBREG_TO_REG child #1" );
1790
1792
// We don't have a child to look at that might have a super register node.
1791
- auto SuperClass =
1793
+ const CodeGenRegisterClass * SuperClass =
1792
1794
inferSuperRegisterClass (Dst.getExtType (0 ), Dst.getChild (2 ));
1793
1795
if (!SuperClass)
1794
1796
return failedImport (
1795
1797
" Cannot infer register class for SUBREG_TO_REG operand #0" );
1796
1798
M.insertAction <ConstrainOperandToRegClassAction>(InsertPt, InsnID, 0 ,
1797
- ** SuperClass);
1799
+ *SuperClass);
1798
1800
M.insertAction <ConstrainOperandToRegClassAction>(InsertPt, InsnID, 2 ,
1799
- ** SubClass);
1801
+ *SubClass);
1800
1802
} else if (DstIName == " REG_SEQUENCE" ) {
1801
- auto SuperClass = inferRegClassFromPattern (Dst.getChild (0 ));
1803
+ const CodeGenRegisterClass *SuperClass =
1804
+ inferRegClassFromPattern (Dst.getChild (0 ));
1802
1805
1803
1806
M.insertAction <ConstrainOperandToRegClassAction>(InsertPt, InsnID, 0 ,
1804
- ** SuperClass);
1807
+ *SuperClass);
1805
1808
1806
1809
unsigned Num = Dst.getNumChildren ();
1807
1810
for (unsigned I = 1 ; I != Num; I += 2 ) {
1808
1811
const TreePatternNode &SubRegChild = Dst.getChild (I + 1 );
1809
1812
1810
- auto SubIdx = inferSubRegIndexForNode (SubRegChild);
1813
+ const CodeGenSubRegIndex * SubIdx = inferSubRegIndexForNode (SubRegChild);
1811
1814
if (!SubIdx)
1812
1815
return failedImport (" REG_SEQUENCE child is not a subreg index" );
1813
1816
1814
1817
const auto SrcRCDstRCPair =
1815
- (* SuperClass) ->getMatchingSubClassWithSubRegs (CGRegs, * SubIdx);
1818
+ SuperClass->getMatchingSubClassWithSubRegs (CGRegs, SubIdx);
1816
1819
1817
1820
M.insertAction <ConstrainOperandToRegClassAction>(InsertPt, InsnID, I,
1818
1821
*SrcRCDstRCPair->second );
@@ -1824,19 +1827,16 @@ Error GlobalISelEmitter::constrainOperands(action_iterator InsertPt,
1824
1827
return Error::success ();
1825
1828
}
1826
1829
1827
- std::optional< const CodeGenRegisterClass *>
1830
+ const CodeGenRegisterClass *
1828
1831
GlobalISelEmitter::getRegClassFromLeaf (const TreePatternNode &Leaf) {
1829
1832
assert (Leaf.isLeaf () && " Expected leaf?" );
1830
1833
const Record *RCRec = getInitValueAsRegClass (Leaf.getLeafValue ());
1831
1834
if (!RCRec)
1832
- return std::nullopt;
1833
- const CodeGenRegisterClass *RC = CGRegs.getRegClass (RCRec);
1834
- if (!RC)
1835
- return std::nullopt;
1836
- return RC;
1835
+ return nullptr ;
1836
+ return CGRegs.getRegClass (RCRec);
1837
1837
}
1838
1838
1839
- std::optional< const CodeGenRegisterClass *>
1839
+ const CodeGenRegisterClass *
1840
1840
GlobalISelEmitter::inferRegClassFromPattern (const TreePatternNode &N) {
1841
1841
if (N.isLeaf ())
1842
1842
return getRegClassFromLeaf (N);
@@ -1847,12 +1847,12 @@ GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode &N) {
1847
1847
// Only handle things that produce at least one value (if multiple values,
1848
1848
// just take the first one).
1849
1849
if (N.getNumTypes () < 1 )
1850
- return std::nullopt ;
1850
+ return nullptr ;
1851
1851
const Record *OpRec = N.getOperator ();
1852
1852
1853
1853
// We only want instructions.
1854
1854
if (!OpRec->isSubClassOf (" Instruction" ))
1855
- return std::nullopt ;
1855
+ return nullptr ;
1856
1856
1857
1857
// Don't want to try and infer things when there could potentially be more
1858
1858
// than one candidate register class.
@@ -1867,7 +1867,7 @@ GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode &N) {
1867
1867
// has the desired register class as the first child.
1868
1868
const TreePatternNode &RCChild = N.getChild (IsRegSequence ? 0 : 1 );
1869
1869
if (!RCChild.isLeaf ())
1870
- return std::nullopt ;
1870
+ return nullptr ;
1871
1871
return getRegClassFromLeaf (RCChild);
1872
1872
}
1873
1873
if (InstName == " INSERT_SUBREG" ) {
@@ -1897,55 +1897,49 @@ GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode &N) {
1897
1897
return &RC;
1898
1898
}
1899
1899
1900
- return std::nullopt ;
1900
+ return nullptr ;
1901
1901
}
1902
1902
1903
- std::optional<const CodeGenRegisterClass *>
1904
- GlobalISelEmitter::inferSuperRegisterClass (
1903
+ const CodeGenRegisterClass *GlobalISelEmitter::inferSuperRegisterClass (
1905
1904
const TypeSetByHwMode &Ty, const TreePatternNode &SubRegIdxNode) {
1906
1905
// We need a ValueTypeByHwMode for getSuperRegForSubReg.
1907
1906
if (!Ty.isValueTypeByHwMode (false ))
1908
- return std::nullopt ;
1907
+ return nullptr ;
1909
1908
if (!SubRegIdxNode.isLeaf ())
1910
- return std::nullopt ;
1909
+ return nullptr ;
1911
1910
const DefInit *SubRegInit = dyn_cast<DefInit>(SubRegIdxNode.getLeafValue ());
1912
1911
if (!SubRegInit)
1913
- return std::nullopt ;
1912
+ return nullptr ;
1914
1913
const CodeGenSubRegIndex *SubIdx = CGRegs.getSubRegIdx (SubRegInit->getDef ());
1915
1914
1916
1915
// Use the information we found above to find a minimal register class which
1917
1916
// supports the subregister and type we want.
1918
- auto RC =
1919
- Target.getSuperRegForSubReg (Ty.getValueTypeByHwMode (), CGRegs, SubIdx,
1920
- /* MustBeAllocatable */ true );
1921
- if (!RC)
1922
- return std::nullopt;
1923
- return *RC;
1917
+ return Target.getSuperRegForSubReg (Ty.getValueTypeByHwMode (), CGRegs, SubIdx,
1918
+ /* MustBeAllocatable=*/ true );
1924
1919
}
1925
1920
1926
- std::optional<const CodeGenRegisterClass *>
1927
- GlobalISelEmitter::inferSuperRegisterClassForNode (
1921
+ const CodeGenRegisterClass *GlobalISelEmitter::inferSuperRegisterClassForNode (
1928
1922
const TypeSetByHwMode &Ty, const TreePatternNode &SuperRegNode,
1929
1923
const TreePatternNode &SubRegIdxNode) {
1930
1924
// Check if we already have a defined register class for the super register
1931
1925
// node. If we do, then we should preserve that rather than inferring anything
1932
1926
// from the subregister index node. We can assume that whoever wrote the
1933
1927
// pattern in the first place made sure that the super register and
1934
1928
// subregister are compatible.
1935
- if (std::optional< const CodeGenRegisterClass *> SuperRegisterClass =
1929
+ if (const CodeGenRegisterClass *SuperRegisterClass =
1936
1930
inferRegClassFromPattern (SuperRegNode))
1937
- return * SuperRegisterClass;
1931
+ return SuperRegisterClass;
1938
1932
return inferSuperRegisterClass (Ty, SubRegIdxNode);
1939
1933
}
1940
1934
1941
- std::optional< CodeGenSubRegIndex *> GlobalISelEmitter::inferSubRegIndexForNode (
1935
+ const CodeGenSubRegIndex *GlobalISelEmitter::inferSubRegIndexForNode (
1942
1936
const TreePatternNode &SubRegIdxNode) {
1943
1937
if (!SubRegIdxNode.isLeaf ())
1944
- return std::nullopt ;
1938
+ return nullptr ;
1945
1939
1946
1940
const DefInit *SubRegInit = dyn_cast<DefInit>(SubRegIdxNode.getLeafValue ());
1947
1941
if (!SubRegInit)
1948
- return std::nullopt ;
1942
+ return nullptr ;
1949
1943
return CGRegs.getSubRegIdx (SubRegInit->getDef ());
1950
1944
}
1951
1945
@@ -2095,30 +2089,32 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
2095
2089
if (MatchedRC.isNull ())
2096
2090
return failedImport (" REG_SEQUENCE operand #0 isn't a register class" );
2097
2091
} else if (DstIName == " EXTRACT_SUBREG" ) {
2098
- auto InferredClass = inferRegClassFromPattern (Dst.getChild (0 ));
2092
+ const CodeGenRegisterClass *InferredClass =
2093
+ inferRegClassFromPattern (Dst.getChild (0 ));
2099
2094
if (!InferredClass)
2100
2095
return failedImport (
2101
2096
" Could not infer class for EXTRACT_SUBREG operand #0" );
2102
2097
2103
2098
// We can assume that a subregister is in the same bank as it's super
2104
2099
// register.
2105
- MatchedRC = (* InferredClass) ->getDef ();
2100
+ MatchedRC = InferredClass->getDef ();
2106
2101
} else if (DstIName == " INSERT_SUBREG" ) {
2107
- auto MaybeSuperClass =
2102
+ const CodeGenRegisterClass * MaybeSuperClass =
2108
2103
inferSuperRegisterClassForNode (VTy, Dst.getChild (0 ), Dst.getChild (2 ));
2109
2104
if (!MaybeSuperClass)
2110
2105
return failedImport (
2111
2106
" Cannot infer register class for INSERT_SUBREG operand #0" );
2112
2107
// Move to the next pattern here, because the register class we found
2113
2108
// doesn't necessarily have a record associated with it. So, we can't
2114
2109
// set DstIOpRec using this.
2115
- MatchedRC = * MaybeSuperClass;
2110
+ MatchedRC = MaybeSuperClass;
2116
2111
} else if (DstIName == " SUBREG_TO_REG" ) {
2117
- auto MaybeRegClass = inferSuperRegisterClass (VTy, Dst.getChild (2 ));
2112
+ const CodeGenRegisterClass *MaybeRegClass =
2113
+ inferSuperRegisterClass (VTy, Dst.getChild (2 ));
2118
2114
if (!MaybeRegClass)
2119
2115
return failedImport (
2120
2116
" Cannot infer register class for SUBREG_TO_REG operand #0" );
2121
- MatchedRC = * MaybeRegClass;
2117
+ MatchedRC = MaybeRegClass;
2122
2118
} else if (cast<const Record *>(MatchedRC)->isSubClassOf (" RegisterOperand" ))
2123
2119
MatchedRC = cast<const Record *>(MatchedRC)->getValueAsDef (" RegClass" );
2124
2120
else if (!cast<const Record *>(MatchedRC)->isSubClassOf (" RegisterClass" ))
0 commit comments