Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Show First 20 Lines • Show All 2,846 Lines • ▼ Show 20 Lines | void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV, | ||||
} else | } else | ||||
OutStreamer->emitValueToAlignment(Alignment, 0, 1, MaxBytesToEmit); | OutStreamer->emitValueToAlignment(Alignment, 0, 1, MaxBytesToEmit); | ||||
} | } | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// Constant emission. | // Constant emission. | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
Constant *AsmPrinter::constantFoldForPrint(const Constant *CV) { | |||||
return ConstantFoldConstant(CV, getDataLayout()); | |||||
} | |||||
const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) { | const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) { | ||||
MCContext &Ctx = OutContext; | MCContext &Ctx = OutContext; | ||||
if (CV->isNullValue() || isa<UndefValue>(CV)) | if (CV->isNullValue() || isa<UndefValue>(CV)) | ||||
return MCConstantExpr::create(0, Ctx); | return MCConstantExpr::create(0, Ctx); | ||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) | if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) | ||||
return MCConstantExpr::create(CI->getZExtValue(), Ctx); | return MCConstantExpr::create(CI->getZExtValue(), Ctx); | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | case Instruction::Add: { | ||||
const MCExpr *RHS = lowerConstant(CE->getOperand(1)); | const MCExpr *RHS = lowerConstant(CE->getOperand(1)); | ||||
return MCBinaryExpr::createAdd(LHS, RHS, Ctx); | return MCBinaryExpr::createAdd(LHS, RHS, Ctx); | ||||
} | } | ||||
} | } | ||||
// If the code isn't optimized, there may be outstanding folding | // If the code isn't optimized, there may be outstanding folding | ||||
// opportunities. Attempt to fold the expression using DataLayout as a | // opportunities. Attempt to fold the expression using DataLayout as a | ||||
// last resort before giving up. | // last resort before giving up. | ||||
Constant *C = ConstantFoldConstant(CE, getDataLayout()); | Constant *C = constantFoldForPrint(CE); | ||||
if (C != CE) | if (C != CE) | ||||
return lowerConstant(C); | return lowerConstant(C); | ||||
// Otherwise report the problem to the user. | // Otherwise report the problem to the user. | ||||
std::string S; | std::string S; | ||||
raw_string_ostream OS(S); | raw_string_ostream OS(S); | ||||
OS << "Unsupported expression in static initializer: "; | OS << "Unsupported expression in static initializer: "; | ||||
CE->printAsOperand(OS, /*PrintType=*/false, | CE->printAsOperand(OS, /*PrintType=*/false, | ||||
▲ Show 20 Lines • Show All 435 Lines • ▼ Show 20 Lines | if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { | ||||
return; | return; | ||||
} | } | ||||
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) | ||||
return emitGlobalConstantFP(CFP, AP); | return emitGlobalConstantFP(CFP, AP); | ||||
if (isa<ConstantPointerNull>(CV)) { | if (isa<ConstantPointerNull>(CV)) { | ||||
if (Size > 8) { | |||||
// Not always used in order to preserve backwards compatibility while | |||||
// allowing for large pointers. | |||||
AP.OutStreamer->emitZeros(Size); | |||||
return; | |||||
} | |||||
AP.OutStreamer->emitIntValue(0, Size); | AP.OutStreamer->emitIntValue(0, Size); | ||||
arsenm: Don't understand why you can't unconditionally call emitZeros. Compatibility is not a concern… | |||||
return; | return; | ||||
} | } | ||||
if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(CV)) | if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(CV)) | ||||
return emitGlobalConstantDataSequential(DL, CDS, AP, AliasList); | return emitGlobalConstantDataSequential(DL, CDS, AP, AliasList); | ||||
if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) | if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) | ||||
return emitGlobalConstantArray(DL, CVA, AP, BaseCV, Offset, AliasList); | return emitGlobalConstantArray(DL, CVA, AP, BaseCV, Offset, AliasList); | ||||
if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) | if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) | ||||
return emitGlobalConstantStruct(DL, CVS, AP, BaseCV, Offset, AliasList); | return emitGlobalConstantStruct(DL, CVS, AP, BaseCV, Offset, AliasList); | ||||
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { | if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { | ||||
// Look through bitcasts, which might not be able to be MCExpr'ized (e.g. of | // Look through bitcasts, which might not be able to be MCExpr'ized (e.g. of | ||||
// vectors). | // vectors). | ||||
if (CE->getOpcode() == Instruction::BitCast) | if (CE->getOpcode() == Instruction::BitCast) | ||||
return emitGlobalConstantImpl(DL, CE->getOperand(0), AP); | return emitGlobalConstantImpl(DL, CE->getOperand(0), AP); | ||||
if (Size > 8) { | if (Size > 8) { | ||||
// If the constant expression's size is greater than 64-bits, then we have | // If the constant expression's size is greater than 64-bits, then we have | ||||
// to emit the value in chunks. Try to constant fold the value and emit it | // to emit the value in chunks. Try to constant fold the value and emit it | ||||
// that way. | // that way. | ||||
Constant *New = ConstantFoldConstant(CE, DL); | Constant *New = AP.constantFoldForPrint(CE); | ||||
if (New != CE) | if (New != CE) | ||||
return emitGlobalConstantImpl(DL, New, AP); | return emitGlobalConstantImpl(DL, New, AP); | ||||
} | } | ||||
} | } | ||||
if (const ConstantVector *V = dyn_cast<ConstantVector>(CV)) | if (const ConstantVector *V = dyn_cast<ConstantVector>(CV)) | ||||
return emitGlobalConstantVector(DL, V, AP, AliasList); | return emitGlobalConstantVector(DL, V, AP, AliasList); | ||||
▲ Show 20 Lines • Show All 573 Lines • Show Last 20 Lines |
Don't understand why you can't unconditionally call emitZeros. Compatibility is not a concern with the codegen APIs