Skip to content

Commit a7b4a4b

Browse files
committed
fix GlobalISEL
1 parent 1c601e3 commit a7b4a4b

File tree

10 files changed

+73
-25
lines changed

10 files changed

+73
-25
lines changed

llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/CodeGen/CallingConvLower.h"
2020
#include "llvm/CodeGen/MachineOperand.h"
2121
#include "llvm/CodeGen/TargetCallingConv.h"
22+
#include "llvm/IR/Attributes.h"
2223
#include "llvm/IR/CallingConv.h"
2324
#include "llvm/IR/Type.h"
2425
#include "llvm/IR/Value.h"
@@ -30,7 +31,6 @@
3031

3132
namespace llvm {
3233

33-
class AttributeList;
3434
class CallBase;
3535
class DataLayout;
3636
class Function;

llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ class LegalizationArtifactCombiner {
15401540
SubRegs.reserve(NumSubSrcs);
15411541
for (unsigned Idx = MergeSrcIdx; Idx <= EndMergeSrcIdx; ++Idx)
15421542
SubRegs.push_back(SrcDef->getOperand(Idx + 1).getReg());
1543-
UpdatedDefs.push_back(Builder.buildMerge(DstReg, SubRegs).getReg(0));
1543+
UpdatedDefs.push_back(Builder.buildMergeValues(DstReg, SubRegs).getReg(0));
15441544
markInstAndDefDead(MI, *SrcDef, DeadInsts);
15451545
return true;
15461546
}

llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,82 @@ struct IgnoreMatch {
6969
};
7070

7171
template <typename ConstT>
72-
Optional<ConstT> matchConstant(Register Reg, const MachineRegisterInfo &MRI);
72+
std::optional<ConstT> matchConstant(Register Reg, const MachineRegisterInfo &MRI);
7373

7474
template <>
75-
inline Optional<ValueAndVReg>
76-
matchConstant<ValueAndVReg>(Register Reg, const MachineRegisterInfo &MRI) {
75+
inline std::optional<std::optional<ValueAndVReg>>
76+
matchConstant<std::optional<ValueAndVReg>>(Register Reg,
77+
const MachineRegisterInfo &MRI) {
7778
return getIConstantVRegValWithLookThrough(Reg, MRI);
7879
}
7980

8081
template <>
81-
inline Optional<APInt> matchConstant<APInt>(Register Reg,
82+
inline std::optional<APInt> matchConstant<APInt>(Register Reg,
8283
const MachineRegisterInfo &MRI) {
83-
return matchConstant<ValueAndVReg>(Reg, MRI).map(
84-
[](ValueAndVReg &&ValAndVReg) { return ValAndVReg.Value; });
84+
const auto& Val = matchConstant<std::optional<ValueAndVReg>>(Reg, MRI);
85+
if (Val.has_value())
86+
return { Val.value()->Value };
87+
return { std::nullopt };
8588
}
8689

8790
template <>
88-
inline Optional<const IgnoreMatch>
91+
inline std::optional<const IgnoreMatch>
8992
matchConstant<const IgnoreMatch>(Register Reg, const MachineRegisterInfo &MRI) {
90-
return matchConstant<APInt>(Reg, MRI).map(
91-
[](const APInt &) -> const IgnoreMatch { return {}; });
93+
matchConstant<APInt>(Reg, MRI);
94+
return std::optional<const IgnoreMatch>{ IgnoreMatch{} };
9295
}
9396

94-
template <typename ConstT>
95-
inline std::optional<ConstT> matchConstant(Register Reg,
96-
const MachineRegisterInfo &MRI) {
97+
template <>
98+
inline std::optional<int64_t> matchConstant<int64_t>(Register Reg,
99+
const MachineRegisterInfo &MRI) {
100+
auto Val = matchConstant<APInt>(Reg, MRI);
101+
if (Val && Val->getBitWidth() <= 64)
102+
return Val->getSExtValue();
103+
return std::nullopt;
104+
}
105+
106+
template <>
107+
inline std::optional<uint64_t> matchConstant<uint64_t>(Register Reg,
108+
const MachineRegisterInfo &MRI) {
109+
auto Val = matchConstant<APInt>(Reg, MRI);
110+
if (Val && Val->getBitWidth() <= 64)
111+
return Val->getSExtValue();
112+
return std::nullopt;
113+
}
114+
115+
template <>
116+
inline std::optional<unsigned char> matchConstant<unsigned char>(Register Reg,
117+
const MachineRegisterInfo &MRI) {
97118
auto Val = matchConstant<APInt>(Reg, MRI);
98119
if (Val && Val->getBitWidth() <= 64)
99120
return Val->getSExtValue();
100121
return std::nullopt;
101122
}
102123

124+
template <>
125+
inline std::optional<unsigned int> matchConstant<unsigned int>(Register Reg,
126+
const MachineRegisterInfo &MRI) {
127+
auto Val = matchConstant<APInt>(Reg, MRI);
128+
if (Val && Val->getBitWidth() <= 64)
129+
return Val->getSExtValue();
130+
return std::nullopt;
131+
}
132+
133+
template <>
134+
inline std::optional<bool> matchConstant<bool>(Register Reg,
135+
const MachineRegisterInfo &MRI) {
136+
auto Val = matchConstant<APInt>(Reg, MRI);
137+
if (Val && Val->getBitWidth() <= 64)
138+
return Val->getSExtValue();
139+
return std::nullopt;
140+
}
141+
142+
template <>
143+
inline std::optional<ValueAndVReg> matchConstant<ValueAndVReg>(Register Reg,
144+
const MachineRegisterInfo &MRI) {
145+
return getIConstantVRegValWithLookThrough(Reg, MRI);
146+
}
147+
103148
template <typename ConstT> struct ConstantMatch {
104149
ConstT &CR;
105150
ConstantMatch(ConstT &C) : CR(C) {}
@@ -165,10 +210,12 @@ struct GCstAndRegMatch {
165210
bool match(const MachineRegisterInfo &MRI, Register Reg) {
166211
ValReg = getIConstantVRegValWithLookThrough(Reg, MRI);
167212
return ValReg ? true : false;
168-
}
213+
}
214+
};
169215

170216
template <typename ConstT> inline ConstantMatch<ConstT> m_ICst(ConstT &Cst) {
171217
return {Cst};
218+
}
172219

173220
inline GCstAndRegMatch m_GCst(std::optional<ValueAndVReg> &ValReg) {
174221
return GCstAndRegMatch(ValReg);

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,13 +1167,13 @@ def lower_is_power_of_two : GICombineRule<
11671167
[{ return Helper.matchLowerIsPowerOfTwo(*${mi}); }]),
11681168
(apply [{ Helper.applyLowerIsPowerOfTwo(*${mi}); }])>;
11691169

1170-
def simplify_const_matchdata : GIDefMatchData<"Optional<ValueAndVReg>">;
1170+
def simplify_const_matchdata : GIDefMatchData<"std::optional<ValueAndVReg>">;
11711171
def simplify_const : GICombineRule<
11721172
(defs root:$mi, simplify_const_matchdata:$matchinfo),
11731173
(match (wip_match_opcode G_TRUNC, G_SEXT, G_ZEXT):$mi,
11741174
[{ ${matchinfo} = getIConstantVRegValWithLookThrough(
11751175
${mi}->getOperand(0).getReg(), MRI);
1176-
return ${matchinfo}.hasValue(); }]),
1176+
return ${matchinfo}.has_value(); }]),
11771177
(apply [{ Helper.replaceInstWithConstant(*${mi}, ${matchinfo}->Value); }])>;
11781178

11791179
def simplify_known_const_matchdata : GIDefMatchData<"APInt">;

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ std::optional<DefinitionAndSourceRegister>
473473
llvm::getDefSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI,
474474
bool HasOneNonDBGUse) {
475475
if (HasOneNonDBGUse && !MRI.hasOneNonDBGUse(Reg))
476-
return None;
476+
return std::nullopt;
477477
Register DefSrcReg = Reg;
478478
auto *DefMI = MRI.getVRegDef(Reg);
479479
auto DstTy = MRI.getType(DefMI->getOperand(0).getReg());

llvm/lib/Target/Z80/GISel/Z80InstructionSelector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ bool Z80InstructionSelector::selectLoadStore(MachineInstr &I,
903903
}
904904
bool IsOff = MOs.size() == 2;
905905
if (RMWOps.empty()) {
906-
Optional<APInt> ValConst;
906+
std::optional<APInt> ValConst;
907907
switch (Ty.getSizeInBits()) {
908908
case 8:
909909
if (!IsLoad)
@@ -1526,7 +1526,7 @@ Z80::CondCode Z80InstructionSelector::foldExtendedAddSub(
15261526
Register DstReg = DstMO.getReg();
15271527
Register LHSReg = I.getOperand(2).getReg();
15281528
Register RHSReg = I.getOperand(3).getReg();
1529-
Optional<ValueAndVReg> RHSConst = None;
1529+
std::optional<ValueAndVReg> RHSConst = std::nullopt;
15301530
LLT OpTy = MRI.getType(DstReg);
15311531

15321532
unsigned AddSubOpc;

llvm/lib/Target/Z80/GISel/Z80LegalizerInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ Z80LegalizerInfo::legalizeCompare(LegalizerHelper &Helper,
667667
CallLowering::ArgInfo::NoArgIndex);
668668
CallLowering::ArgInfo Args[2] = {{LHSReg, Ty, 0}, {RHSReg, Ty, 1}};
669669
auto Result = createLibcall(MIRBuilder, Libcall, FlagsArg,
670-
makeArrayRef(Args, 2 - ZeroRHS));
670+
ArrayRef(Args, 2 - ZeroRHS));
671671
if (Result != LegalizerHelper::Legalized)
672672
return Result;
673673
MIRBuilder.buildCopy(Register(Z80::F), FlagsReg);
@@ -1086,7 +1086,7 @@ bool Z80LegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
10861086
CallLowering::CallLoweringInfo Info;
10871087
Info.CallConv = CallingConv::C;
10881088
Info.Callee = MachineOperand::CreateES("abort");
1089-
Info.OrigRet = CallLowering::ArgInfo{None, Type::getVoidTy(Ctx), 0};
1089+
Info.OrigRet = CallLowering::ArgInfo{{}, Type::getVoidTy(Ctx), 0};
10901090
if (!CLI.lowerCall(MIRBuilder, Info))
10911091
return false;
10921092
break;

llvm/lib/Target/Z80/GISel/Z80PostLegalizerCombiner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Z80PostLegalizerCombinerInfo : public CombinerInfo {
5656
bool Z80PostLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
5757
MachineInstr &MI,
5858
MachineIRBuilder &B) const {
59-
CombinerHelper Helper(Observer, B, KB, MDT,
59+
CombinerHelper Helper(Observer, B, false, KB, MDT,
6060
MI.getMF()->getSubtarget().getLegalizerInfo());
6161
Z80GenPostLegalizerCombinerHelper Generated(GeneratedRuleCfg, Helper);
6262
return Generated.tryCombineAll(Observer, MI, B, Helper);

llvm/lib/Target/Z80/GISel/Z80PreLegalizerCombiner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class Z80PreLegalizerCombinerInfo : public CombinerInfo {
6060
bool Z80PreLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
6161
MachineInstr &MI,
6262
MachineIRBuilder &B) const {
63-
CombinerHelper Helper(Observer, B, KB, MDT);
63+
CombinerHelper Helper(Observer, B, true, KB, MDT,
64+
MI.getMF()->getSubtarget().getLegalizerInfo());
6465
Z80GenPreLegalizerCombinerHelper Generated(GeneratedRuleCfg, Helper);
6566
return Generated.tryCombineAll(Observer, MI, B, Helper);
6667
}

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,7 @@ class NoUsePredicateMatcher : public InstructionPredicateMatcher {
22592259
}
22602260

22612261
void emitPredicateOpcodes(MatchTable &Table,
2262-
RuleMatcher &Rule) const override {
2262+
Matcher &Rule) const override {
22632263
Table << MatchTable::Opcode("GIM_CheckHasNoUse")
22642264
<< MatchTable::Comment("MI") << MatchTable::IntValue(InsnVarID)
22652265
<< MatchTable::LineBreak;

0 commit comments

Comments
 (0)