Skip to content

Commit d1f9277

Browse files
committed
Move getInitValueAsRegClass into CodeGenTarget
1 parent 61146eb commit d1f9277

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

llvm/utils/TableGen/Common/CodeGenTarget.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,29 @@ void CodeGenTarget::ReadLegalValueTypes() const {
197197
LegalValueTypes.erase(llvm::unique(LegalValueTypes), LegalValueTypes.end());
198198
}
199199

200+
const Record *CodeGenTarget::getInitValueAsRegClass(const Init *V) const {
201+
if (const DefInit *VDefInit = dyn_cast<DefInit>(V)) {
202+
const Record *RegClass = VDefInit->getDef();
203+
if (RegClass->isSubClassOf("RegisterOperand"))
204+
RegClass = RegClass->getValueAsDef("RegClass");
205+
206+
if (RegClass->isSubClassOf("RegisterClass"))
207+
return RegClass;
208+
209+
// FIXME: We should figure out the hwmode and dispatch. But this interface
210+
// is broken, we should be returning a register class. The expected uses
211+
// will use the same RegBanks in all modes.
212+
if (RegClass->isSubClassOf("RegClassByHwMode")) {
213+
const HwModeSelect &ModeSelect = getHwModes().getHwModeSelect(RegClass);
214+
if (ModeSelect.Items.empty())
215+
return nullptr;
216+
return ModeSelect.Items.front().second;
217+
}
218+
}
219+
220+
return nullptr;
221+
}
222+
200223
CodeGenSchedModels &CodeGenTarget::getSchedModels() const {
201224
if (!SchedModels)
202225
SchedModels = std::make_unique<CodeGenSchedModels>(Records, *this);

llvm/utils/TableGen/Common/CodeGenTarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class CodeGenTarget {
152152
return LegalValueTypes;
153153
}
154154

155+
const Record *getInitValueAsRegClass(const Init *V) const;
156+
155157
CodeGenSchedModels &getSchedModels() const;
156158

157159
const CodeGenHwModes &getHwModes() const { return CGH; }

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -267,31 +267,6 @@ static Error isTrivialOperatorNode(const TreePatternNode &N) {
267267
return failedImport(Explanation);
268268
}
269269

270-
static const Record *getInitValueAsRegClass(const CodeGenTarget &Target,
271-
const Init *V) {
272-
if (const DefInit *VDefInit = dyn_cast<DefInit>(V)) {
273-
const Record *RegClass = VDefInit->getDef();
274-
if (RegClass->isSubClassOf("RegisterOperand"))
275-
RegClass = RegClass->getValueAsDef("RegClass");
276-
277-
if (RegClass->isSubClassOf("RegisterClass"))
278-
return RegClass;
279-
280-
// FIXME: We should figure out the hwmode and dispatch. But this interface
281-
// is broken, we should be returning a register class. The expected uses
282-
// will use the same RegBanks in all modes.
283-
if (RegClass->isSubClassOf("RegClassByHwMode")) {
284-
const HwModeSelect &ModeSelect =
285-
Target.getHwModes().getHwModeSelect(RegClass);
286-
if (ModeSelect.Items.empty())
287-
return nullptr;
288-
return ModeSelect.Items.front().second;
289-
}
290-
}
291-
292-
return nullptr;
293-
}
294-
295270
static std::string getScopedName(unsigned Scope, const std::string &Name) {
296271
return ("pred:" + Twine(Scope) + ":" + Name).str();
297272
}
@@ -1161,8 +1136,8 @@ Error GlobalISelEmitter::importChildMatcher(
11611136
if (ChildRec->isSubClassOf("RegisterClass") ||
11621137
ChildRec->isSubClassOf("RegisterOperand") ||
11631138
ChildRec->isSubClassOf("RegClassByHwMode")) {
1164-
OM.addPredicate<RegisterBankOperandMatcher>(Target.getRegisterClass(
1165-
getInitValueAsRegClass(Target, ChildDefInit)));
1139+
OM.addPredicate<RegisterBankOperandMatcher>(
1140+
Target.getRegisterClass(Target.getInitValueAsRegClass(ChildDefInit)));
11661141
return Error::success();
11671142
}
11681143

@@ -1660,7 +1635,7 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
16601635

16611636
// If this is a source operand, this is just a subregister copy.
16621637
const Record *RCDef =
1663-
getInitValueAsRegClass(Target, ValChild.getLeafValue());
1638+
Target.getInitValueAsRegClass(ValChild.getLeafValue());
16641639
if (!RCDef)
16651640
return failedImport("EXTRACT_SUBREG child #0 could not "
16661641
"be coerced to a register class");
@@ -1692,7 +1667,7 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
16921667
return failedImport("REG_SEQUENCE child #0 is not a leaf");
16931668

16941669
const Record *RCDef =
1695-
getInitValueAsRegClass(Target, Dst.getChild(0).getLeafValue());
1670+
Target.getInitValueAsRegClass(Dst.getChild(0).getLeafValue());
16961671
if (!RCDef)
16971672
return failedImport("REG_SEQUENCE child #0 could not "
16981673
"be coerced to a register class");
@@ -1811,7 +1786,7 @@ Error GlobalISelEmitter::constrainOperands(action_iterator InsertPt,
18111786
// COPY_TO_REGCLASS does not provide operand constraints itself but the
18121787
// result is constrained to the class given by the second child.
18131788
const Record *DstIOpRec =
1814-
getInitValueAsRegClass(Target, Dst.getChild(1).getLeafValue());
1789+
Target.getInitValueAsRegClass(Dst.getChild(1).getLeafValue());
18151790

18161791
if (DstIOpRec == nullptr)
18171792
return failedImport("COPY_TO_REGCLASS operand #1 isn't a register class");
@@ -1917,7 +1892,7 @@ Error GlobalISelEmitter::constrainOperands(action_iterator InsertPt,
19171892
const CodeGenRegisterClass *
19181893
GlobalISelEmitter::getRegClassFromLeaf(const TreePatternNode &Leaf) const {
19191894
assert(Leaf.isLeaf() && "Expected leaf?");
1920-
const Record *RCRec = getInitValueAsRegClass(Target, Leaf.getLeafValue());
1895+
const Record *RCRec = Target.getInitValueAsRegClass(Leaf.getLeafValue());
19211896
if (!RCRec)
19221897
return nullptr;
19231898
return CGRegs.getRegClass(RCRec);
@@ -2158,7 +2133,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
21582133

21592134
if (Dst.isLeaf()) {
21602135
if (const Record *RCDef =
2161-
getInitValueAsRegClass(Target, Dst.getLeafValue())) {
2136+
Target.getInitValueAsRegClass(Dst.getLeafValue())) {
21622137
const CodeGenRegisterClass &RC = Target.getRegisterClass(RCDef);
21632138

21642139
// We need to replace the def and all its uses with the specified

0 commit comments

Comments
 (0)