[llvm] 00bfef2 - [NVPTXAsmPrinter] Extract common error handling code
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 1 04:16:30 PDT 2023
Author: Nikita Popov
Date: 2023-11-01T12:16:17+01:00
New Revision: 00bfef272a36f0a73ba73892e668349f259a7efd
URL: https://github.com/llvm/llvm-project/commit/00bfef272a36f0a73ba73892e668349f259a7efd
DIFF: https://github.com/llvm/llvm-project/commit/00bfef272a36f0a73ba73892e668349f259a7efd.diff
LOG: [NVPTXAsmPrinter] Extract common error handling code
Make the code structure more similar to how the original code
in AsmPrinter looks nowadays: On error, break from the switch
and fall through to general error handling code, which will try
to ConstantFold and otherwise report an error. Ensures we always
go through the constant folding path and avoids duplicating the
error printing.
Added:
Modified:
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index c1df063d80f5ffb..aa4d5fb7298ef49 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -1980,35 +1980,16 @@ NVPTXAsmPrinter::lowerConstantForGV(const Constant *CV, bool ProcessingGeneric)
}
switch (CE->getOpcode()) {
- default: {
- // If the code isn't optimized, there may be outstanding folding
- // opportunities. Attempt to fold the expression using DataLayout as a
- // last resort before giving up.
- Constant *C = ConstantFoldConstant(CE, getDataLayout());
- if (C != CE)
- return lowerConstantForGV(C, ProcessingGeneric);
-
- // Otherwise report the problem to the user.
- std::string S;
- raw_string_ostream OS(S);
- OS << "Unsupported expression in static initializer: ";
- CE->printAsOperand(OS, /*PrintType=*/false,
- !MF ? nullptr : MF->getFunction().getParent());
- report_fatal_error(Twine(OS.str()));
- }
+ default:
+ break; // Error
case Instruction::AddrSpaceCast: {
// Strip the addrspacecast and pass along the operand
PointerType *DstTy = cast<PointerType>(CE->getType());
- if (DstTy->getAddressSpace() == 0) {
+ if (DstTy->getAddressSpace() == 0)
return lowerConstantForGV(cast<const Constant>(CE->getOperand(0)), true);
- }
- std::string S;
- raw_string_ostream OS(S);
- OS << "Unsupported expression in static initializer: ";
- CE->printAsOperand(OS, /*PrintType=*/ false,
- !MF ? nullptr : MF->getFunction().getParent());
- report_fatal_error(Twine(OS.str()));
+
+ break; // Error
}
case Instruction::GetElementPtr: {
@@ -2082,6 +2063,21 @@ NVPTXAsmPrinter::lowerConstantForGV(const Constant *CV, bool ProcessingGeneric)
}
}
}
+
+ // If the code isn't optimized, there may be outstanding folding
+ // opportunities. Attempt to fold the expression using DataLayout as a
+ // last resort before giving up.
+ Constant *C = ConstantFoldConstant(CE, getDataLayout());
+ if (C != CE)
+ return lowerConstantForGV(C, ProcessingGeneric);
+
+ // Otherwise report the problem to the user.
+ std::string S;
+ raw_string_ostream OS(S);
+ OS << "Unsupported expression in static initializer: ";
+ CE->printAsOperand(OS, /*PrintType=*/false,
+ !MF ? nullptr : MF->getFunction().getParent());
+ report_fatal_error(Twine(OS.str()));
}
// Copy of MCExpr::print customized for NVPTX
More information about the llvm-commits
mailing list