Use twines to simplify calls to report_fatal_error. For code size and readability.

llvm-svn: 100756
This commit is contained in:
Benjamin Kramer 2010-04-08 10:44:28 +00:00
parent 634d9ff7c0
commit a6769269f3
11 changed files with 69 additions and 135 deletions

View File

@ -76,7 +76,7 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, unsigned LocCookie) const {
OwningPtr<TargetAsmParser> TAP(TM.getTarget().createAsmParser(Parser));
if (!TAP)
report_fatal_error("Inline asm not supported by this streamer because"
" we don't have an asm parser for this target\n");
" we don't have an asm parser for this target\n");
Parser.setTargetParser(*TAP.get());
// Don't implicitly switch to the text section before the asm.
@ -178,8 +178,8 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
case '(': // $( -> same as GCC's { character.
++LastEmitted; // Consume '(' character.
if (CurVariant != -1)
report_fatal_error("Nested variants found in inline asm string: '"
+ std::string(AsmStr) + "'");
report_fatal_error("Nested variants found in inline asm string: '" +
Twine(AsmStr) + "'");
CurVariant = 0; // We're in the first variant now.
break;
case '|':
@ -213,8 +213,8 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
const char *StrStart = LastEmitted;
const char *StrEnd = strchr(StrStart, '}');
if (StrEnd == 0)
report_fatal_error(Twine("Unterminated ${:foo} operand in inline asm"
" string: '") + Twine(AsmStr) + "'");
report_fatal_error("Unterminated ${:foo} operand in inline asm"
" string: '" + Twine(AsmStr) + "'");
std::string Val(StrStart, StrEnd);
PrintSpecial(MI, OS, Val.c_str());
@ -228,8 +228,8 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
unsigned Val;
if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
report_fatal_error("Bad $ operand number in inline asm string: '"
+ std::string(AsmStr) + "'");
report_fatal_error("Bad $ operand number in inline asm string: '" +
Twine(AsmStr) + "'");
LastEmitted = IDEnd;
char Modifier[2] = { 0, 0 };
@ -241,21 +241,21 @@ void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
++LastEmitted; // Consume ':' character.
if (*LastEmitted == 0)
report_fatal_error("Bad ${:} expression in inline asm string: '" +
std::string(AsmStr) + "'");
Twine(AsmStr) + "'");
Modifier[0] = *LastEmitted;
++LastEmitted; // Consume modifier character.
}
if (*LastEmitted != '}')
report_fatal_error("Bad ${} expression in inline asm string: '"
+ std::string(AsmStr) + "'");
report_fatal_error("Bad ${} expression in inline asm string: '" +
Twine(AsmStr) + "'");
++LastEmitted; // Consume '}' character.
}
if (Val >= NumOperands-1)
report_fatal_error("Invalid $ operand number in inline asm string: '"
+ std::string(AsmStr) + "'");
report_fatal_error("Invalid $ operand number in inline asm string: '" +
Twine(AsmStr) + "'");
// Okay, we finally have a value number. Ask the target to print this
// operand!

View File

@ -109,13 +109,11 @@ void OcamlGCMetadataPrinter::finishAssembly(AsmPrinter &AP) {
uint64_t FrameSize = FI.getFrameSize();
if (FrameSize >= 1<<16) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Function '" << FI.getFunction().getName()
<< "' is too large for the ocaml GC! "
<< "Frame size " << FrameSize << " >= 65536.\n";
Msg << "(" << uintptr_t(&FI) << ")";
report_fatal_error(Msg.str()); // Very rude!
// Very rude!
report_fatal_error("Function '" + FI.getFunction().getName() +
"' is too large for the ocaml GC! "
"Frame size " + Twine(FrameSize) + ">= 65536.\n"
"(" + Twine(uintptr_t(&FI)) + ")");
}
AP.OutStreamer.AddComment("live roots for " +
@ -125,12 +123,10 @@ void OcamlGCMetadataPrinter::finishAssembly(AsmPrinter &AP) {
for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
size_t LiveCount = FI.live_size(J);
if (LiveCount >= 1<<16) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Function '" << FI.getFunction().getName()
<< "' is too large for the ocaml GC! "
<< "Live root count " << LiveCount << " >= 65536.";
report_fatal_error(Msg.str()); // Very rude!
// Very rude!
report_fatal_error("Function '" + FI.getFunction().getName() +
"' is too large for the ocaml GC! "
"Live root count "+Twine(LiveCount)+" >= 65536.");
}
AP.OutStreamer.EmitSymbolValue(J->Label, IntPtrSize, 0);

View File

@ -572,10 +572,8 @@ CstExprResTy ELFWriter::ResolveConstantExpr(const Constant *CV) {
}
}
std::string msg(CE->getOpcodeName());
raw_string_ostream ErrorMsg(msg);
ErrorMsg << ": Unsupported ConstantExpr type";
report_fatal_error(ErrorMsg.str());
report_fatal_error(CE->getOpcodeName() +
StringRef(": Unsupported ConstantExpr type"));
return std::make_pair(CV, 0); // silence warning
}

View File

@ -5334,8 +5334,8 @@ void SelectionDAGBuilder::visitInlineAsm(CallSite CS) {
(OpInfo.ConstraintVT.getSizeInBits() !=
Input.ConstraintVT.getSizeInBits())) {
report_fatal_error("Unsupported asm: input constraint"
" with a matching output constraint of incompatible"
" type!");
" with a matching output constraint of"
" incompatible type!");
}
Input.ConstraintVT = OpInfo.ConstraintVT;
}
@ -5446,8 +5446,8 @@ void SelectionDAGBuilder::visitInlineAsm(CallSite CS) {
// Copy the output from the appropriate register. Find a register that
// we can use.
if (OpInfo.AssignedRegs.Regs.empty())
report_fatal_error("Couldn't allocate output reg for"
" constraint '" + OpInfo.ConstraintCode + "'!");
report_fatal_error("Couldn't allocate output reg for constraint '" +
Twine(OpInfo.ConstraintCode) + "'!");
// If this is an indirect operand, store through the pointer after the
// asm.
@ -5547,8 +5547,8 @@ void SelectionDAGBuilder::visitInlineAsm(CallSite CS) {
TLI.LowerAsmOperandForConstraint(InOperandVal, OpInfo.ConstraintCode[0],
hasMemory, Ops, DAG);
if (Ops.empty())
report_fatal_error("Invalid operand for inline asm"
" constraint '" + OpInfo.ConstraintCode + "'!");
report_fatal_error("Invalid operand for inline asm constraint '" +
Twine(OpInfo.ConstraintCode) + "'!");
// Add information to the INLINEASM node to know about this input.
unsigned ResOpType =
@ -5581,8 +5581,8 @@ void SelectionDAGBuilder::visitInlineAsm(CallSite CS) {
// Copy the input into the appropriate registers.
if (OpInfo.AssignedRegs.Regs.empty() ||
!OpInfo.AssignedRegs.areValueTypesLegal())
report_fatal_error("Couldn't allocate input reg for"
" constraint '"+ OpInfo.ConstraintCode +"'!");
report_fatal_error("Couldn't allocate input reg for constraint '" +
Twine(OpInfo.ConstraintCode) + "'!");
OpInfo.AssignedRegs.getCopyToRegs(InOperandVal, DAG, getCurDebugLoc(),
Chain, &Flag);

View File

@ -15,6 +15,7 @@
#include "llvm/ExecutionEngine/JITMemoryManager.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.h"
#include "llvm/GlobalValue.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
@ -22,12 +23,9 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Memory.h"
#include <map>
#include <vector>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace llvm;
@ -615,7 +613,7 @@ sys::MemoryBlock DefaultJITMemoryManager::allocateNewSlab(size_t size) {
sys::MemoryBlock B = sys::Memory::AllocateRWX(size, LastSlabPtr, &ErrMsg);
if (B.base() == 0) {
report_fatal_error("Allocation failed when allocating new memory in the"
" JIT\n" + ErrMsg);
" JIT\n" + Twine(ErrMsg));
}
LastSlab = B;
++NumSlabs;

View File

@ -248,10 +248,7 @@ void AlphaRegisterInfo::emitPrologue(MachineFunction &MF) const {
BuildMI(MBB, MBBI, dl, TII.get(Alpha::LDA), Alpha::R30)
.addImm(getLower16(NumBytes)).addReg(Alpha::R30);
} else {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Too big a stack frame at " << NumBytes;
report_fatal_error(Msg.str());
report_fatal_error("Too big a stack frame at " + Twine(NumBytes));
}
//now if we need to, save the old FP and set the new
@ -300,10 +297,7 @@ void AlphaRegisterInfo::emitEpilogue(MachineFunction &MF,
BuildMI(MBB, MBBI, dl, TII.get(Alpha::LDA), Alpha::R30)
.addImm(getLower16(NumBytes)).addReg(Alpha::R30);
} else {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Too big a stack frame at " << NumBytes;
report_fatal_error(Msg.str());
report_fatal_error("Too big a stack frame at " + Twine(NumBytes));
}
}
}

View File

@ -194,11 +194,8 @@ namespace {
#ifndef NDEBUG
if (retval == 0) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "SPUISelDAGToDAG.cpp: getValueTypeMapEntry returns NULL for "
<< VT.getEVTString();
report_fatal_error(Msg.str());
report_fatal_error("SPUISelDAGToDAG.cpp: getValueTypeMapEntry returns"
"NULL for " + Twine(VT.getEVTString()));
}
#endif
@ -915,11 +912,8 @@ SPUDAGToDAGISel::Select(SDNode *N) {
const valtype_map_s *vtm = getValueTypeMapEntry(VT);
if (vtm->ldresult_ins == 0) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "LDRESULT for unsupported type: "
<< VT.getEVTString();
report_fatal_error(Msg.str());
report_fatal_error("LDRESULT for unsupported type: " +
Twine(VT.getEVTString()));
}
Opc = vtm->ldresult_ins;

View File

@ -71,11 +71,8 @@ namespace {
#ifndef NDEBUG
if (retval == 0) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "getValueTypeMapEntry returns NULL for "
<< VT.getEVTString();
report_fatal_error(Msg.str());
report_fatal_error("getValueTypeMapEntry returns NULL for " +
Twine(VT.getEVTString()));
}
#endif
@ -714,12 +711,9 @@ LowerLOAD(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
case ISD::POST_DEC:
case ISD::LAST_INDEXED_MODE:
{
std::string msg;
raw_string_ostream Msg(msg);
Msg << "LowerLOAD: Got a LoadSDNode with an addr mode other than "
"UNINDEXED\n";
Msg << (unsigned) LN->getAddressingMode();
report_fatal_error(Msg.str());
report_fatal_error("LowerLOAD: Got a LoadSDNode with an addr mode other "
"than UNINDEXED\n" +
Twine((unsigned)LN->getAddressingMode()));
/*NOTREACHED*/
}
}
@ -884,12 +878,9 @@ LowerSTORE(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
case ISD::POST_DEC:
case ISD::LAST_INDEXED_MODE:
{
std::string msg;
raw_string_ostream Msg(msg);
Msg << "LowerLOAD: Got a LoadSDNode with an addr mode other than "
"UNINDEXED\n";
Msg << (unsigned) SN->getAddressingMode();
report_fatal_error(Msg.str());
report_fatal_error("LowerLOAD: Got a LoadSDNode with an addr mode other "
"than UNINDEXED\n" +
Twine((unsigned)SN->getAddressingMode()));
/*NOTREACHED*/
}
}
@ -1038,13 +1029,9 @@ SPUTargetLowering::LowerFormalArguments(SDValue Chain,
const TargetRegisterClass *ArgRegClass;
switch (ObjectVT.getSimpleVT().SimpleTy) {
default: {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "LowerFormalArguments Unhandled argument type: "
<< ObjectVT.getEVTString();
report_fatal_error(Msg.str());
}
default:
report_fatal_error("LowerFormalArguments Unhandled argument type: " +
Twine(ObjectVT.getEVTString()));
case MVT::i8:
ArgRegClass = &SPU::R8CRegClass;
break;
@ -1581,14 +1568,10 @@ LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) {
uint64_t SplatBits = APSplatBits.getZExtValue();
switch (VT.getSimpleVT().SimpleTy) {
default: {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "CellSPU: Unhandled VT in LowerBUILD_VECTOR, VT = "
<< VT.getEVTString();
report_fatal_error(Msg.str());
default:
report_fatal_error("CellSPU: Unhandled VT in LowerBUILD_VECTOR, VT = " +
Twine(VT.getEVTString()));
/*NOTREACHED*/
}
case MVT::v4f32: {
uint32_t Value32 = uint32_t(SplatBits);
assert(SplatBitSize == 32

View File

@ -509,10 +509,7 @@ void SPURegisterInfo::emitPrologue(MachineFunction &MF) const
.addReg(SPU::R2)
.addReg(SPU::R1);
} else {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Unhandled frame size: " << FrameSize;
report_fatal_error(Msg.str());
report_fatal_error("Unhandled frame size: " + Twine(FrameSize));
}
if (hasDebugInfo) {
@ -605,10 +602,7 @@ SPURegisterInfo::emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const
.addReg(SPU::R2)
.addReg(SPU::R1);
} else {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Unhandled frame size: " << FrameSize;
report_fatal_error(Msg.str());
report_fatal_error("Unhandled frame size: " + Twine(FrameSize));
}
}
}

View File

@ -225,12 +225,9 @@ XCoreRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
unsigned FramePtr = XCore::R10;
if (!isUs) {
if (!RS) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "eliminateFrameIndex Frame size too big: " << Offset;
report_fatal_error(Msg.str());
}
if (!RS)
report_fatal_error("eliminateFrameIndex Frame size too big: " +
Twine(Offset));
unsigned ScratchReg = RS->scavengeRegister(XCore::GRRegsRegisterClass, II,
SPAdj);
loadConstant(MBB, II, ScratchReg, Offset, dl);
@ -278,12 +275,9 @@ XCoreRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
}
} else {
bool isU6 = isImmU6(Offset);
if (!isU6 && !isImmU16(Offset)) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "eliminateFrameIndex Frame size too big: " << Offset;
report_fatal_error(Msg.str());
}
if (!isU6 && !isImmU16(Offset))
report_fatal_error("eliminateFrameIndex Frame size too big: " +
Twine(Offset));
switch (MI.getOpcode()) {
int NewOpcode;
@ -360,10 +354,7 @@ loadConstant(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
// TODO use mkmsk if possible.
if (!isImmU16(Value)) {
// TODO use constant pool.
std::string msg;
raw_string_ostream Msg(msg);
Msg << "loadConstant value too big " << Value;
report_fatal_error(Msg.str());
report_fatal_error("loadConstant value too big " + Twine(Value));
}
int Opcode = isImmU6(Value) ? XCore::LDC_ru6 : XCore::LDC_lru6;
BuildMI(MBB, I, dl, TII.get(Opcode), DstReg).addImm(Value);
@ -375,12 +366,8 @@ storeToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
assert(Offset%4 == 0 && "Misaligned stack offset");
Offset/=4;
bool isU6 = isImmU6(Offset);
if (!isU6 && !isImmU16(Offset)) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "storeToStack offset too big " << Offset;
report_fatal_error(Msg.str());
}
if (!isU6 && !isImmU16(Offset))
report_fatal_error("storeToStack offset too big " + Twine(Offset));
int Opcode = isU6 ? XCore::STWSP_ru6 : XCore::STWSP_lru6;
BuildMI(MBB, I, dl, TII.get(Opcode))
.addReg(SrcReg)
@ -393,12 +380,8 @@ loadFromStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
assert(Offset%4 == 0 && "Misaligned stack offset");
Offset/=4;
bool isU6 = isImmU6(Offset);
if (!isU6 && !isImmU16(Offset)) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "loadFromStack offset too big " << Offset;
report_fatal_error(Msg.str());
}
if (!isU6 && !isImmU16(Offset))
report_fatal_error("loadFromStack offset too big " + Twine(Offset));
int Opcode = isU6 ? XCore::LDWSP_ru6 : XCore::LDWSP_lru6;
BuildMI(MBB, I, dl, TII.get(Opcode), DstReg)
.addImm(Offset);
@ -425,10 +408,7 @@ void XCoreRegisterInfo::emitPrologue(MachineFunction &MF) const {
if (!isU6 && !isImmU16(FrameSize)) {
// FIXME could emit multiple instructions.
std::string msg;
raw_string_ostream Msg(msg);
Msg << "emitPrologue Frame size too big: " << FrameSize;
report_fatal_error(Msg.str());
report_fatal_error("emitPrologue Frame size too big: " + Twine(FrameSize));
}
bool emitFrameMoves = needsFrameMoves(MF);
@ -549,10 +529,7 @@ void XCoreRegisterInfo::emitEpilogue(MachineFunction &MF,
if (!isU6 && !isImmU16(FrameSize)) {
// FIXME could emit multiple instructions.
std::string msg;
raw_string_ostream Msg(msg);
Msg << "emitEpilogue Frame size too big: " << FrameSize;
report_fatal_error(Msg.str());
report_fatal_error("emitEpilogue Frame size too big: " + Twine(FrameSize));
}
if (FrameSize) {

View File

@ -1294,7 +1294,7 @@ bool FunctionPassManager::run(Function &F) {
if (F.isMaterializable()) {
std::string errstr;
if (F.Materialize(&errstr))
report_fatal_error("Error reading bitcode file: " + errstr);
report_fatal_error("Error reading bitcode file: " + Twine(errstr));
}
return FPM->run(F);
}