Skip to content

Commit

Permalink
[CodeGen] Add standard print/debug utilities to MVT
Browse files Browse the repository at this point in the history
Doing so makes it easier to do printf style debugging in idiomatic manner. I followed the code structure of Value with only the definition of dump being #ifdef out in non-debug builds. Not sure if this is the "right" option; we don't seem to have any single consistent scheme on how dump is handled.

Note: This is a follow up to D143454 which did the same for EVT.

Differential Revision: https://reviews.llvm.org/D143511
  • Loading branch information
preames committed Feb 7, 2023
1 parent 07c7784 commit 3be1ae2
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 17 deletions.
11 changes: 11 additions & 0 deletions llvm/include/llvm/Support/MachineValueType.h
Expand Up @@ -350,6 +350,12 @@ namespace llvm {
bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }

/// Support for debugging, callable in GDB: VT.dump()
void dump() const;

/// Implement operator<<.
void print(raw_ostream &OS) const;

/// Return true if this is a valid simple valuetype.
bool isValid() const {
return (SimpleTy >= MVT::FIRST_VALUETYPE &&
Expand Down Expand Up @@ -1571,6 +1577,11 @@ namespace llvm {
/// @}
};

inline raw_ostream &operator<<(raw_ostream &OS, const MVT &VT) {
VT.print(OS);
return OS;
}

} // end namespace llvm

#endif // LLVM_SUPPORT_MACHINEVALUETYPE_H
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/CallingConvLower.cpp
Expand Up @@ -129,7 +129,7 @@ void CCState::AnalyzeCallOperands(const SmallVectorImpl<ISD::OutputArg> &Outs,
if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
#ifndef NDEBUG
dbgs() << "Call operand #" << i << " has unhandled type "
<< EVT(ArgVT).getEVTString() << '\n';
<< ArgVT << '\n';
#endif
llvm_unreachable(nullptr);
}
Expand All @@ -147,7 +147,7 @@ void CCState::AnalyzeCallOperands(SmallVectorImpl<MVT> &ArgVTs,
if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
#ifndef NDEBUG
dbgs() << "Call operand #" << i << " has unhandled type "
<< EVT(ArgVT).getEVTString() << '\n';
<< ArgVT << '\n';
#endif
llvm_unreachable(nullptr);
}
Expand All @@ -164,7 +164,7 @@ void CCState::AnalyzeCallResult(const SmallVectorImpl<ISD::InputArg> &Ins,
if (Fn(i, VT, VT, CCValAssign::Full, Flags, *this)) {
#ifndef NDEBUG
dbgs() << "Call result #" << i << " has unhandled type "
<< EVT(VT).getEVTString() << '\n';
<< VT << '\n';
#endif
llvm_unreachable(nullptr);
}
Expand All @@ -176,7 +176,7 @@ void CCState::AnalyzeCallResult(MVT VT, CCAssignFn Fn) {
if (Fn(0, VT, VT, CCValAssign::Full, ISD::ArgFlagsTy(), *this)) {
#ifndef NDEBUG
dbgs() << "Call result has unhandled type "
<< EVT(VT).getEVTString() << '\n';
<< VT << '\n';
#endif
llvm_unreachable(nullptr);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ void CCState::getRemainingRegParmsForType(SmallVectorImpl<MCPhysReg> &Regs,
do {
if (Fn(0, VT, VT, CCValAssign::Full, Flags, *this)) {
#ifndef NDEBUG
dbgs() << "Call has unhandled type " << EVT(VT).getEVTString()
dbgs() << "Call has unhandled type " << VT
<< " while computing remaining regparms\n";
#endif
llvm_unreachable(nullptr);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Expand Up @@ -3240,7 +3240,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
if (CaseSize == 0) break;

// Otherwise, execute the case we found.
LLVM_DEBUG(dbgs() << " TypeSwitch[" << EVT(CurNodeVT).getEVTString()
LLVM_DEBUG(dbgs() << " TypeSwitch[" << CurNodeVT
<< "] from " << SwitchStart << " to " << MatcherIndex
<< '\n');
continue;
Expand Down
12 changes: 12 additions & 0 deletions llvm/lib/CodeGen/ValueTypes.cpp
Expand Up @@ -615,3 +615,15 @@ EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
}
}
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void MVT::dump() const {
print(dbgs());
dbgs() << "\n";
}
#endif

void MVT::print(raw_ostream &OS) const {
OS << EVT(*this).getEVTString();
}

2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
Expand Up @@ -2573,7 +2573,7 @@ HexagonTargetLowering::buildVector32(ArrayRef<SDValue> Elem, const SDLoc &dl,
}

#ifndef NDEBUG
dbgs() << "VecTy: " << EVT(VecTy).getEVTString() << '\n';
dbgs() << "VecTy: " << VecTy << '\n';
#endif
llvm_unreachable("Unexpected vector element type");
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Lanai/LanaiISelLowering.cpp
Expand Up @@ -489,7 +489,7 @@ SDValue LanaiTargetLowering::LowerCCCArguments(
// Check that the argument fits in stack slot
if (ObjSize > 4) {
errs() << "LowerFormalArguments Unhandled argument type: "
<< EVT(VA.getLocVT()).getEVTString() << "\n";
<< VA.getLocVT() << "\n";
}
// Create the frame index object for this incoming parameter...
int FI = MFI.CreateFixedObject(ObjSize, VA.getLocMemOffset(), true);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
Expand Up @@ -2048,7 +2048,7 @@ void LoongArchTargetLowering::analyzeInputArgs(
if (Fn(MF.getDataLayout(), ABI, i, ArgVT, CCValAssign::Full, Ins[i].Flags,
CCInfo, /*IsFixed=*/true, IsRet, ArgTy)) {
LLVM_DEBUG(dbgs() << "InputArg #" << i << " has unhandled type "
<< EVT(ArgVT).getEVTString() << '\n');
<< ArgVT << '\n');
llvm_unreachable("");
}
}
Expand All @@ -2066,7 +2066,7 @@ void LoongArchTargetLowering::analyzeOutputArgs(
if (Fn(MF.getDataLayout(), ABI, i, ArgVT, CCValAssign::Full, Outs[i].Flags,
CCInfo, Outs[i].IsFixed, IsRet, OrigTy)) {
LLVM_DEBUG(dbgs() << "OutputArg #" << i << " has unhandled type "
<< EVT(ArgVT).getEVTString() << "\n");
<< ArgVT << "\n");
llvm_unreachable("");
}
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/MSP430/MSP430ISelLowering.cpp
Expand Up @@ -686,8 +686,7 @@ SDValue MSP430TargetLowering::LowerCCCArguments(
unsigned ObjSize = VA.getLocVT().getSizeInBits()/8;
if (ObjSize > 2) {
errs() << "LowerFormalArguments Unhandled argument type: "
<< EVT(VA.getLocVT()).getEVTString()
<< "\n";
<< VA.getLocVT() << "\n";
}
// Create the frame index object for this incoming parameter...
int FI = MFI.CreateFixedObject(ObjSize, VA.getLocMemOffset(), true);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Expand Up @@ -5784,7 +5784,7 @@ SDValue PPCTargetLowering::LowerCall_32SVR4(
if (Result) {
#ifndef NDEBUG
errs() << "Call operand #" << i << " has unhandled type "
<< EVT(ArgVT).getEVTString() << "\n";
<< ArgVT << "\n";
#endif
llvm_unreachable(nullptr);
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Expand Up @@ -12253,7 +12253,7 @@ void RISCVTargetLowering::analyzeInputArgs(
ArgFlags, CCInfo, /*IsFixed=*/true, IsRet, ArgTy, *this,
FirstMaskArgument)) {
LLVM_DEBUG(dbgs() << "InputArg #" << i << " has unhandled type "
<< EVT(ArgVT).getEVTString() << '\n');
<< ArgVT << '\n');
llvm_unreachable(nullptr);
}
}
Expand All @@ -12279,7 +12279,7 @@ void RISCVTargetLowering::analyzeOutputArgs(
ArgFlags, CCInfo, Outs[i].IsFixed, IsRet, OrigTy, *this,
FirstMaskArgument)) {
LLVM_DEBUG(dbgs() << "OutputArg #" << i << " has unhandled type "
<< EVT(ArgVT).getEVTString() << "\n");
<< ArgVT << "\n");
llvm_unreachable(nullptr);
}
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/XCore/XCoreISelLowering.cpp
Expand Up @@ -1316,8 +1316,7 @@ SDValue XCoreTargetLowering::LowerCCCArguments(
unsigned ObjSize = VA.getLocVT().getSizeInBits()/8;
if (ObjSize > StackSlotSize) {
errs() << "LowerFormalArguments Unhandled argument type: "
<< EVT(VA.getLocVT()).getEVTString()
<< "\n";
<< VA.getLocVT() << "\n";
}
// Create the frame index object for this incoming parameter...
int FI = MFI.CreateFixedObject(ObjSize,
Expand Down

0 comments on commit 3be1ae2

Please sign in to comment.