From 4e3ccc0505a59effce209f47a89cd6f5950884b7 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 15 Jul 2014 02:34:12 +0000 Subject: CodeGen: Handle ConstantVector and undef in WinCOFF constant pools The constant pool entry code for WinCOFF assumed that vector constants would be formed using ConstantDataVector, it did not expect to see a ConstantVector. Furthermore, it did not expect undef as one of the elements of the vector. ConstantVectors should be handled like ConstantDataVectors, treat Undef as zero. llvm-svn: 213038 --- llvm/lib/Target/X86/X86TargetObjectFile.cpp | 34 ++++++++++++++++++----------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'llvm/lib/Target/X86/X86TargetObjectFile.cpp') diff --git a/llvm/lib/Target/X86/X86TargetObjectFile.cpp b/llvm/lib/Target/X86/X86TargetObjectFile.cpp index c780232..21ee047 100644 --- a/llvm/lib/Target/X86/X86TargetObjectFile.cpp +++ b/llvm/lib/Target/X86/X86TargetObjectFile.cpp @@ -109,7 +109,8 @@ const MCExpr *X86WindowsTargetObjectFile::getExecutableRelativeSymbol( getContext()); } -static std::string APIntToHexString(const APInt &AI, unsigned Width) { +static std::string APIntToHexString(const APInt &AI) { + unsigned Width = (AI.getBitWidth() / 8) * 2; std::string HexString = utohexstr(AI.getLimitedValue(), /*LowerCase=*/true); unsigned Size = HexString.size(); assert(Width >= Size && "hex string is too large!"); @@ -121,17 +122,19 @@ static std::string APIntToHexString(const APInt &AI, unsigned Width) { static std::string scalarConstantToHexString(const Constant *C) { Type *Ty = C->getType(); - if (Ty->isFloatTy()) { + APInt AI; + if (isa(C)) { + AI = APInt(Ty->getPrimitiveSizeInBits(), /*val=*/0); + } else if (Ty->isFloatTy() || Ty->isDoubleTy()) { const auto *CFP = cast(C); - return APIntToHexString(CFP->getValueAPF().bitcastToAPInt(), /*Width=*/8); - } else if (Ty->isDoubleTy()) { - const auto *CFP = cast(C); - return APIntToHexString(CFP->getValueAPF().bitcastToAPInt(), /*Width=*/16); - } else if (const auto *ITy = dyn_cast(Ty)) { + AI = CFP->getValueAPF().bitcastToAPInt(); + } else if (Ty->isIntegerTy()) { const auto *CI = cast(C); - return APIntToHexString(CI->getValue(), (ITy->getBitWidth() / 8) * 2); + AI = CI->getValue(); + } else { + llvm_unreachable("unexpected constant pool element type!"); } - llvm_unreachable("unexpected constant pool element type!"); + return APIntToHexString(AI); } const MCSection * @@ -147,11 +150,16 @@ X86WindowsTargetObjectFile::getSectionForConstant(SectionKind Kind, } else if (const auto *VTy = dyn_cast(Ty)) { uint64_t NumBits = VTy->getBitWidth(); if (NumBits == 128 || NumBits == 256) { - const auto *CDV = cast(C); COMDATSymName = NumBits == 128 ? "__xmm@" : "__ymm@"; - for (int I = CDV->getNumElements() - 1, E = -1; I != E; --I) - COMDATSymName += - scalarConstantToHexString(CDV->getElementAsConstant(I)); + if (const auto *CDV = dyn_cast(C)) { + for (int I = CDV->getNumElements() - 1, E = -1; I != E; --I) + COMDATSymName += + scalarConstantToHexString(CDV->getElementAsConstant(I)); + } else { + const auto *CV = cast(C); + for (int I = CV->getNumOperands() - 1, E = -1; I != E; --I) + COMDATSymName += scalarConstantToHexString(CV->getOperand(I)); + } } } if (!COMDATSymName.empty()) { -- cgit v1.1