diff --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h --- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h +++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h @@ -145,7 +145,7 @@ template <> struct ScalarTraits { static void output(const MaybeAlign &Alignment, void *, llvm::raw_ostream &out) { - out << uint64_t(Alignment ? Alignment->value() : 0U); + out << Alignment; } static StringRef input(StringRef Scalar, void *, MaybeAlign &Alignment) { unsigned long long n; diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -25,6 +25,9 @@ namespace llvm { +struct Align; +struct MaybeAlign; + class formatv_object_base; class format_object_base; class FormattedString; @@ -228,6 +231,9 @@ /// Output \p N in hexadecimal, without any prefix or padding. raw_ostream &write_hex(unsigned long long N); + raw_ostream &operator<<(const Align &A); + raw_ostream &operator<<(const MaybeAlign &MA); + // Change the foreground color of text. raw_ostream &operator<<(Colors C); diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -637,7 +637,7 @@ } if (MBB.getAlignment() != Align(1)) { OS << (HasAttributes ? ", " : " ("); - OS << "align " << MBB.getAlignment().value(); + OS << "align " << MBB.getAlignment(); HasAttributes = true; } if (MBB.getSectionType() != MBBS_None) { diff --git a/llvm/lib/CodeGen/MachineFrameInfo.cpp b/llvm/lib/CodeGen/MachineFrameInfo.cpp --- a/llvm/lib/CodeGen/MachineFrameInfo.cpp +++ b/llvm/lib/CodeGen/MachineFrameInfo.cpp @@ -41,8 +41,8 @@ Align StackAlignment) { if (!ShouldClamp || Alignment <= StackAlignment) return Alignment; - LLVM_DEBUG(dbgs() << "Warning: requested alignment " << Alignment.value() - << " exceeds the stack alignment " << StackAlignment.value() + LLVM_DEBUG(dbgs() << "Warning: requested alignment " << Alignment + << " exceeds the stack alignment " << StackAlignment << " when stack realignment is off" << '\n'); return StackAlignment; } @@ -231,7 +231,7 @@ OS << "variable sized"; else OS << "size=" << SO.Size; - OS << ", align=" << SO.Alignment.value(); + OS << ", align=" << SO.Alignment; if (i < NumFixedObjects) OS << ", fixed"; diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp --- a/llvm/lib/CodeGen/MachineOperand.cpp +++ b/llvm/lib/CodeGen/MachineOperand.cpp @@ -1152,7 +1152,7 @@ } MachineOperand::printOperandOffset(OS, getOffset()); if (getBaseAlign() != getSize()) - OS << ", align " << getBaseAlign().value(); + OS << ", align " << getBaseAlign(); auto AAInfo = getAAInfo(); if (AAInfo.TBAA) { OS << ", !tbaa "; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -9497,8 +9497,8 @@ if (MFI.getObjectAlign(FixedIndex) < RequiredAlignment) { LLVM_DEBUG(dbgs() << " argument copy elision failed: alignment of alloca " "greater than stack argument alignment (" - << RequiredAlignment.value() << " vs " - << MFI.getObjectAlign(FixedIndex).value() << ")\n"); + << RequiredAlignment << " vs " + << MFI.getObjectAlign(FixedIndex) << ")\n"); return; } diff --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp --- a/llvm/lib/MC/MCFragment.cpp +++ b/llvm/lib/MC/MCFragment.cpp @@ -426,7 +426,7 @@ case MCFragment::FT_BoundaryAlign: { const auto *BF = cast(this); OS << "\n "; - OS << " BoundarySize:" << BF->getAlignment().value() + OS << " BoundarySize:" << BF->getAlignment() << " LastFragment:" << BF->getLastFragment() << " Size:" << BF->getSize(); break; diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -15,6 +15,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" +#include "llvm/Support/Alignment.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" @@ -144,6 +145,14 @@ return *this; } +raw_ostream &raw_ostream::operator<<(const Align &A) { + return this->operator<<(A.value()); +} + +raw_ostream &raw_ostream::operator<<(const MaybeAlign &MA) { + return this->operator<<(uint64_t(MA ? MA->value() : 0U)); +} + raw_ostream &raw_ostream::operator<<(Colors C) { if (C == Colors::RESET) resetColor(); diff --git a/llvm/lib/Target/Mips/MipsRegisterInfo.cpp b/llvm/lib/Target/Mips/MipsRegisterInfo.cpp --- a/llvm/lib/Target/Mips/MipsRegisterInfo.cpp +++ b/llvm/lib/Target/Mips/MipsRegisterInfo.cpp @@ -266,8 +266,7 @@ << "spOffset : " << spOffset << "\n" << "stackSize : " << stackSize << "\n" << "alignment : " - << MF.getFrameInfo().getObjectAlign(FrameIndex).value() - << "\n"); + << MF.getFrameInfo().getObjectAlign(FrameIndex) << "\n"); eliminateFI(MI, FIOperandNum, FrameIndex, stackSize, spOffset); } diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -1477,7 +1477,7 @@ PAL.getParamAlignment(paramIndex), Ty); unsigned sz = DL.getTypeAllocSize(Ty); - O << "\t.param .align " << align.value() << " .b8 "; + O << "\t.param .align " << align << " .b8 "; printParamName(I, paramIndex, O); O << "[" << sz << "]"; @@ -1574,7 +1574,7 @@ if (!isKernelFunc && align < Align(4)) align = Align(4); unsigned sz = DL.getTypeAllocSize(ETy); - O << "\t.param .align " << align.value() << " .b8 "; + O << "\t.param .align " << align << " .b8 "; printParamName(I, paramIndex, O); O << "[" << sz << "]"; continue; @@ -1634,8 +1634,8 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); int NumBytes = (int) MFI.getStackSize(); if (NumBytes) { - O << "\t.local .align " << MFI.getMaxAlign().value() << " .b8 \t" - << DEPOTNAME << getFunctionNumber() << "[" << NumBytes << "];\n"; + O << "\t.local .align " << MFI.getMaxAlign() << " .b8 \t" << DEPOTNAME + << getFunctionNumber() << "[" << NumBytes << "];\n"; if (static_cast(MF.getTarget()).is64Bit()) { O << "\t.reg .b64 \t%SP;\n"; O << "\t.reg .b64 \t%SPL;\n"; diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -1251,7 +1251,8 @@ if (!isABI) return ""; - std::stringstream O; + std::string Buffer; + raw_string_ostream O(Buffer); O << "prototype_" << uniqueCallSite << " : .callprototype "; if (retTy->getTypeID() == Type::VoidTyID) { @@ -1278,8 +1279,8 @@ O << ".param .b" << PtrVT.getSizeInBits() << " _"; } else if (retTy->isAggregateType() || retTy->isVectorTy() || retTy->isIntegerTy(128)) { - O << ".param .align " << (retAlignment ? retAlignment->value() : 0) - << " .b8 _[" << DL.getTypeAllocSize(retTy) << "]"; + O << ".param .align " << retAlignment << " .b8 _[" + << DL.getTypeAllocSize(retTy) << "]"; } else { llvm_unreachable("Unknown return type"); } @@ -1344,7 +1345,7 @@ Align align = Outs[OIdx].Flags.getNonZeroByValAlign(); unsigned sz = DL.getTypeAllocSize(ETy); - O << ".param .align " << align.value() << " .b8 "; + O << ".param .align " << align << " .b8 "; O << "_"; O << "[" << sz << "]"; }