1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

reduce indentation and use early exits in AsmPrinter::EmitConstantValueOnly

llvm-svn: 93290
This commit is contained in:
Chris Lattner 2010-01-13 04:29:19 +00:00
parent 6de2f65f80
commit 452f5ad8f2

View File

@ -807,18 +807,36 @@ void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
// Print out the specified constant, without a storage class. Only the
// constants valid in constant expressions can occur here.
void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
if (CV->isNullValue() || isa<UndefValue>(CV))
if (CV->isNullValue() || isa<UndefValue>(CV)) {
O << '0';
else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
return;
}
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
O << CI->getZExtValue();
} else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
return;
}
if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
// This is a constant address for a global variable or function. Use the
// name of the variable or function as the address value.
O << Mang->getMangledName(GV);
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
const TargetData *TD = TM.getTargetData();
unsigned Opcode = CE->getOpcode();
switch (Opcode) {
return;
}
if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
GetBlockAddressSymbol(BA)->print(O, MAI);
return;
}
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV);
if (CE == 0) {
llvm_unreachable("Unknown constant value!");
O << '0';
return;
}
switch (CE->getOpcode()) {
case Instruction::ZExt:
case Instruction::SExt:
case Instruction::FPTrunc:
@ -827,13 +845,18 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
case Instruction::SIToFP:
case Instruction::FPToUI:
case Instruction::FPToSI:
default:
llvm_unreachable("FIXME: Don't support this constant cast expr");
case Instruction::GetElementPtr: {
// generate a symbolic expression for the byte address
const TargetData *TD = TM.getTargetData();
const Constant *ptrVal = CE->getOperand(0);
SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
idxVec.size())) {
int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
idxVec.size());
if (Offset == 0)
return EmitConstantValueOnly(ptrVal);
// Truncate/sext the offset to the pointer size.
if (TD->getPointerSizeInBits() != 64) {
int SExtAmount = 64-TD->getPointerSizeInBits();
@ -845,12 +868,9 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
EmitConstantValueOnly(ptrVal);
if (Offset > 0)
O << ") + " << Offset;
else if (Offset < 0)
else
O << ") - " << -Offset;
} else {
EmitConstantValueOnly(ptrVal);
}
break;
return;
}
case Instruction::BitCast:
return EmitConstantValueOnly(CE->getOperand(0));
@ -858,6 +878,7 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
case Instruction::IntToPtr: {
// Handle casts to pointers by changing them into casts to the appropriate
// integer type. This promotes constant folding and simplifies this code.
const TargetData *TD = TM.getTargetData();
Constant *Op = CE->getOperand(0);
Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()),
false/*ZExt*/);
@ -869,6 +890,7 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
// changing the pointer to the appropriately sized integer type.
Constant *Op = CE->getOperand(0);
const Type *Ty = CE->getType();
const TargetData *TD = TM.getTargetData();
// We can emit the pointer value into this slot if the slot is an
// integer slot greater or equal to the size of the pointer.
@ -883,7 +905,7 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
SmallString<40> S;
ptrMask.toStringUnsigned(S);
O << ") & " << S.str() << ')';
break;
return;
}
case Instruction::Trunc:
@ -901,7 +923,7 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
O << '(';
EmitConstantValueOnly(CE->getOperand(0));
O << ')';
switch (Opcode) {
switch (CE->getOpcode()) {
case Instruction::Add:
O << " + ";
break;
@ -924,13 +946,6 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
EmitConstantValueOnly(CE->getOperand(1));
O << ')';
break;
default:
llvm_unreachable("Unsupported operator!");
}
} else if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
GetBlockAddressSymbol(BA)->print(O, MAI);
} else {
llvm_unreachable("Unknown constant value!");
}
}