Skip to content

Commit 0ef522f

Browse files
[TableGen] Use MVT instead of MVT::SimpleValueType. NFC (#169180)
This improves type safety and is less verbose. Use SimpleTy only where an integer is needed like switches or emitting a VBR. --------- Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
1 parent 0619292 commit 0ef522f

18 files changed

+122
-137
lines changed

llvm/utils/TableGen/CallingConvEmitter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ void CallingConvEmitter::emitAction(const Record *Action, indent Indent,
271271
O << Indent << "return false;\n";
272272
} else if (Action->isSubClassOf("CCPromoteToType")) {
273273
const Record *DestTy = Action->getValueAsDef("DestTy");
274-
MVT::SimpleValueType DestVT = getValueType(DestTy);
274+
MVT DestVT = getValueType(DestTy);
275275
O << Indent << "LocVT = " << getEnumName(DestVT) << ";\n";
276-
if (MVT(DestVT).isFloatingPoint()) {
276+
if (DestVT.isFloatingPoint()) {
277277
O << Indent << "LocInfo = CCValAssign::FPExt;\n";
278278
} else {
279279
O << Indent << "if (ArgFlags.isSExt())\n"
@@ -285,9 +285,9 @@ void CallingConvEmitter::emitAction(const Record *Action, indent Indent,
285285
}
286286
} else if (Action->isSubClassOf("CCPromoteToUpperBitsInType")) {
287287
const Record *DestTy = Action->getValueAsDef("DestTy");
288-
MVT::SimpleValueType DestVT = getValueType(DestTy);
288+
MVT DestVT = getValueType(DestTy);
289289
O << Indent << "LocVT = " << getEnumName(DestVT) << ";\n";
290-
if (MVT(DestVT).isFloatingPoint()) {
290+
if (DestVT.isFloatingPoint()) {
291291
PrintFatalError(Action->getLoc(),
292292
"CCPromoteToUpperBitsInType does not handle floating "
293293
"point");

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,8 +1921,8 @@ SDNodeInfo::SDNodeInfo(const Record *R, const CodeGenHwModes &CGH) : Def(R) {
19211921

19221922
/// getKnownType - If the type constraints on this node imply a fixed type
19231923
/// (e.g. all stores return void, etc), then return it as an
1924-
/// MVT::SimpleValueType. Otherwise, return EEVT::Other.
1925-
MVT::SimpleValueType SDNodeInfo::getKnownType(unsigned ResNo) const {
1924+
/// MVT. Otherwise, return EEVT::Other.
1925+
MVT SDNodeInfo::getKnownType(unsigned ResNo) const {
19261926
unsigned NumResults = getNumResults();
19271927
assert(NumResults <= 1 &&
19281928
"We only work with nodes with zero or one result so far!");
@@ -2586,14 +2586,14 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
25862586

25872587
ValueTypeByHwMode VVT = TP.getInfer().getConcrete(Types[0], false);
25882588
for (auto &P : VVT) {
2589-
MVT::SimpleValueType VT = P.second.SimpleTy;
2589+
MVT VT = P.second;
25902590
// Can only check for types of a known size
25912591
if (VT == MVT::iPTR)
25922592
continue;
25932593

25942594
// Check that the value doesn't use more bits than we have. It must
25952595
// either be a sign- or zero-extended equivalent of the original.
2596-
unsigned Width = MVT(VT).getFixedSizeInBits();
2596+
unsigned Width = VT.getFixedSizeInBits();
25972597
int64_t Val = II->getValue();
25982598
if (!isIntN(Width, Val) && !isUIntN(Width, Val)) {
25992599
TP.error("Integer value '" + Twine(Val) +
@@ -2630,8 +2630,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
26302630
for (unsigned i = 0, e = getNumChildren() - 1; i != e; ++i) {
26312631
MadeChange |= getChild(i + 1).ApplyTypeConstraints(TP, NotRegisters);
26322632

2633-
MVT::SimpleValueType OpVT =
2634-
getValueType(Int->IS.ParamTys[i]->getValueAsDef("VT"));
2633+
MVT OpVT = getValueType(Int->IS.ParamTys[i]->getValueAsDef("VT"));
26352634
assert(getChild(i + 1).getNumTypes() == 1 && "Unhandled case");
26362635
MadeChange |= getChild(i + 1).UpdateNodeType(0, OpVT, TP);
26372636
}
@@ -2677,8 +2676,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
26772676

26782677
// FIXME: Generalize to multiple possible types and multiple possible
26792678
// ImplicitDefs.
2680-
MVT::SimpleValueType VT =
2681-
InstInfo.HasOneImplicitDefWithKnownVT(CDP.getTargetInfo());
2679+
MVT VT = InstInfo.HasOneImplicitDefWithKnownVT(CDP.getTargetInfo());
26822680

26832681
if (VT != MVT::Other)
26842682
MadeChange |= UpdateNodeType(ResNo, VT, TP);

llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ struct TypeSetByHwMode : public InfoByHwMode<MachineValueTypeSet> {
191191
TypeSetByHwMode() = default;
192192
TypeSetByHwMode(const TypeSetByHwMode &VTS) = default;
193193
TypeSetByHwMode &operator=(const TypeSetByHwMode &) = default;
194-
TypeSetByHwMode(MVT::SimpleValueType VT)
195-
: TypeSetByHwMode(ValueTypeByHwMode(VT)) {}
194+
TypeSetByHwMode(MVT VT) : TypeSetByHwMode(ValueTypeByHwMode(VT)) {}
196195
TypeSetByHwMode(ArrayRef<ValueTypeByHwMode> VTList);
197196

198197
SetType &getOrCreate(unsigned Mode) { return Map[Mode]; }
@@ -259,7 +258,7 @@ struct TypeInfer {
259258
/// otherwise.
260259

261260
bool MergeInTypeInfo(TypeSetByHwMode &Out, const TypeSetByHwMode &In) const;
262-
bool MergeInTypeInfo(TypeSetByHwMode &Out, MVT::SimpleValueType InVT) const {
261+
bool MergeInTypeInfo(TypeSetByHwMode &Out, MVT InVT) const {
263262
return MergeInTypeInfo(Out, TypeSetByHwMode(InVT));
264263
}
265264
bool MergeInTypeInfo(TypeSetByHwMode &Out,
@@ -451,8 +450,8 @@ class SDNodeInfo {
451450

452451
/// getKnownType - If the type constraints on this node imply a fixed type
453452
/// (e.g. all stores return void, etc), then return it as an
454-
/// MVT::SimpleValueType. Otherwise, return MVT::Other.
455-
MVT::SimpleValueType getKnownType(unsigned ResNo) const;
453+
/// MVT. Otherwise, return MVT::Other.
454+
MVT getKnownType(unsigned ResNo) const;
456455

457456
unsigned getProperties() const { return Properties; }
458457

@@ -698,8 +697,8 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
698697
}
699698
TypeSetByHwMode &getExtType(unsigned ResNo) { return Types[ResNo]; }
700699
void setType(unsigned ResNo, const TypeSetByHwMode &T) { Types[ResNo] = T; }
701-
MVT::SimpleValueType getSimpleType(unsigned ResNo) const {
702-
return Types[ResNo].getMachineValueType().SimpleTy;
700+
MVT getSimpleType(unsigned ResNo) const {
701+
return Types[ResNo].getMachineValueType();
703702
}
704703

705704
bool hasConcreteType(unsigned ResNo) const {
@@ -850,8 +849,7 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
850849
///
851850
bool UpdateNodeType(unsigned ResNo, const TypeSetByHwMode &InTy,
852851
TreePattern &TP);
853-
bool UpdateNodeType(unsigned ResNo, MVT::SimpleValueType InTy,
854-
TreePattern &TP);
852+
bool UpdateNodeType(unsigned ResNo, MVT InTy, TreePattern &TP);
855853
bool UpdateNodeType(unsigned ResNo, const ValueTypeByHwMode &InTy,
856854
TreePattern &TP);
857855

@@ -1001,8 +999,7 @@ inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
1001999
return TP.getInfer().MergeInTypeInfo(Types[ResNo], VTS);
10021000
}
10031001

1004-
inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
1005-
MVT::SimpleValueType InTy,
1002+
inline bool TreePatternNode::UpdateNodeType(unsigned ResNo, MVT InTy,
10061003
TreePattern &TP) {
10071004
TypeSetByHwMode VTS(InTy);
10081005
TP.getInfer().expandOverloads(VTS);

llvm/utils/TableGen/Common/CodeGenInstruction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ CodeGenInstruction::CodeGenInstruction(const Record *R)
499499
/// HasOneImplicitDefWithKnownVT - If the instruction has at least one
500500
/// implicit def and it has a known VT, return the VT, otherwise return
501501
/// MVT::Other.
502-
MVT::SimpleValueType CodeGenInstruction::HasOneImplicitDefWithKnownVT(
502+
MVT CodeGenInstruction::HasOneImplicitDefWithKnownVT(
503503
const CodeGenTarget &TargetInfo) const {
504504
if (ImplicitDefs.empty())
505505
return MVT::Other;
@@ -510,7 +510,7 @@ MVT::SimpleValueType CodeGenInstruction::HasOneImplicitDefWithKnownVT(
510510
const std::vector<ValueTypeByHwMode> &RegVTs =
511511
TargetInfo.getRegisterVTs(FirstImplicitDef);
512512
if (RegVTs.size() == 1 && RegVTs[0].isSimple())
513-
return RegVTs[0].getSimple().SimpleTy;
513+
return RegVTs[0].getSimple();
514514
return MVT::Other;
515515
}
516516

llvm/utils/TableGen/Common/CodeGenInstruction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ class CodeGenInstruction {
289289
/// HasOneImplicitDefWithKnownVT - If the instruction has at least one
290290
/// implicit def and it has a known VT, return the VT, otherwise return
291291
/// MVT::Other.
292-
MVT::SimpleValueType
293-
HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const;
292+
MVT HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const;
294293

295294
/// FlattenAsmStringVariants - Flatten the specified AsmString to only
296295
/// include text from the specified variant, returning the new string.

llvm/utils/TableGen/Common/CodeGenTarget.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ static cl::opt<unsigned>
3939
cl::desc("Make -gen-asm-writer emit assembly writer #N"),
4040
cl::cat(AsmWriterCat));
4141

42-
/// getValueType - Return the MVT::SimpleValueType that the specified TableGen
42+
/// Returns the MVT that the specified TableGen
4343
/// record corresponds to.
44-
MVT::SimpleValueType llvm::getValueType(const Record *Rec) {
44+
MVT llvm::getValueType(const Record *Rec) {
4545
return (MVT::SimpleValueType)Rec->getValueAsInt("Value");
4646
}
4747

48-
StringRef llvm::getEnumName(MVT::SimpleValueType T) {
48+
StringRef llvm::getEnumName(MVT T) {
4949
// clang-format off
50-
switch (T) {
50+
switch (T.SimpleTy) {
5151
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
5252
case MVT::Ty: return "MVT::" # Ty;
5353
#include "llvm/CodeGen/GenVT.inc"

llvm/utils/TableGen/Common/CodeGenTarget.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class CodeGenRegisterClass;
4141
class CodeGenSchedModels;
4242
class CodeGenSubRegIndex;
4343

44-
/// getValueType - Return the MVT::SimpleValueType that the specified TableGen
44+
/// Returns the MVT that the specified TableGen
4545
/// record corresponds to.
46-
MVT::SimpleValueType getValueType(const Record *Rec);
46+
MVT getValueType(const Record *Rec);
4747

48-
StringRef getEnumName(MVT::SimpleValueType T);
48+
StringRef getEnumName(MVT T);
4949

5050
/// getQualifiedName - Return the name of the specified record, with a
5151
/// namespace qualifier if the record contains one.

llvm/utils/TableGen/Common/DAGISelMatcher.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, indent Indent) const {
286286
OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
287287
<< CGI.Namespace << "::" << CGI.getName() << ": <todo flags> ";
288288

289-
for (MVT::SimpleValueType VT : VTs)
289+
for (MVT VT : VTs)
290290
OS << ' ' << getEnumName(VT);
291291
OS << '(';
292292
for (unsigned Operand : Operands)
@@ -321,8 +321,7 @@ void MorphNodeToMatcher::anchor() {}
321321

322322
// isContradictoryImpl Implementations.
323323

324-
static bool TypesAreContradictory(MVT::SimpleValueType T1,
325-
MVT::SimpleValueType T2) {
324+
static bool TypesAreContradictory(MVT T1, MVT T2) {
326325
// If the two types are the same, then they are the same, so they don't
327326
// contradict.
328327
if (T1 == T2)
@@ -339,16 +338,16 @@ static bool TypesAreContradictory(MVT::SimpleValueType T1,
339338
// If either type is about iPtr, then they don't conflict unless the other
340339
// one is not a scalar integer type.
341340
if (T1 == MVT::iPTR)
342-
return !MVT(T2).isInteger() || MVT(T2).isVector();
341+
return !T2.isInteger() || T2.isVector();
343342

344343
if (T2 == MVT::iPTR)
345-
return !MVT(T1).isInteger() || MVT(T1).isVector();
344+
return !T1.isInteger() || T1.isVector();
346345

347346
if (T1 == MVT::cPTR)
348-
return !MVT(T2).isCheriCapability() || MVT(T2).isVector();
347+
return !T2.isCheriCapability() || T2.isVector();
349348

350349
if (T2 == MVT::cPTR)
351-
return !MVT(T1).isCheriCapability() || MVT(T1).isVector();
350+
return !T1.isCheriCapability() || T1.isVector();
352351

353352
// Otherwise, they are two different non-iPTR/cPTR types, they conflict.
354353
return true;
@@ -370,7 +369,7 @@ bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
370369
if (CT->getResNo() >= getOpcode().getNumResults())
371370
return true;
372371

373-
MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
372+
MVT NodeType = getOpcode().getKnownType(CT->getResNo());
374373
if (NodeType != MVT::Other)
375374
return TypesAreContradictory(NodeType, CT->getType());
376375
}

0 commit comments

Comments
 (0)