[llvm] r240793 - Revert r240762 "[X86] Cleanup X86WindowsTargetObjectFile::getSectionForConstant"
Hans Wennborg
hans at hanshq.net
Fri Jun 26 09:48:03 PDT 2015
Author: hans
Date: Fri Jun 26 11:48:02 2015
New Revision: 240793
URL: http://llvm.org/viewvc/llvm-project?rev=240793&view=rev
Log:
Revert r240762 "[X86] Cleanup X86WindowsTargetObjectFile::getSectionForConstant"
It seems to have caused PR23966: "UNREACHABLE executed at ..\lib\Target\X86\X86TargetObjectFile.cpp:148"
Modified:
llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp
Modified: llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp?rev=240793&r1=240792&r2=240793&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp Fri Jun 26 11:48:02 2015
@@ -131,40 +131,52 @@ static std::string APIntToHexString(cons
return HexString;
}
+
static std::string scalarConstantToHexString(const Constant *C) {
Type *Ty = C->getType();
+ APInt AI;
if (isa<UndefValue>(C)) {
- return APIntToHexString(APInt::getNullValue(Ty->getPrimitiveSizeInBits()));
- } else if (const auto *CFP = dyn_cast<ConstantFP>(C)) {
- return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
- } else if (const auto *CI = dyn_cast<ConstantInt>(C)) {
- return APIntToHexString(CI->getValue());
- } else if (const auto *VTy = dyn_cast<VectorType>(Ty)) {
- std::string HexString;
- for (int I = VTy->getNumElements() - 1, E = -1; I != E; --I)
- HexString += scalarConstantToHexString(C->getAggregateElement(I));
- return HexString;
+ AI = APInt(Ty->getPrimitiveSizeInBits(), /*val=*/0);
+ } else if (Ty->isFloatTy() || Ty->isDoubleTy()) {
+ const auto *CFP = cast<ConstantFP>(C);
+ AI = CFP->getValueAPF().bitcastToAPInt();
+ } else if (Ty->isIntegerTy()) {
+ const auto *CI = cast<ConstantInt>(C);
+ AI = CI->getValue();
+ } else {
+ llvm_unreachable("unexpected constant pool element type!");
}
- llvm_unreachable("unexpected constant pool element type!");
+ return APIntToHexString(AI);
}
MCSection *
X86WindowsTargetObjectFile::getSectionForConstant(SectionKind Kind,
const Constant *C) const {
- if (Kind.isMergeableConst() && C) {
- const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- COFF::IMAGE_SCN_MEM_READ |
- COFF::IMAGE_SCN_LNK_COMDAT;
- std::string COMDATSymName;
- if (Kind.isMergeableConst4() || Kind.isMergeableConst8())
- COMDATSymName = "__real@" + scalarConstantToHexString(C);
- else if (Kind.isMergeableConst16())
- COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
-
- if (!COMDATSymName.empty())
- return getContext().getCOFFSection(".rdata", Characteristics, Kind,
- COMDATSymName,
- COFF::IMAGE_COMDAT_SELECT_ANY);
+ if (Kind.isReadOnly()) {
+ if (C) {
+ Type *Ty = C->getType();
+ SmallString<32> COMDATSymName;
+ if (Ty->isFloatTy() || Ty->isDoubleTy()) {
+ COMDATSymName = "__real@";
+ COMDATSymName += scalarConstantToHexString(C);
+ } else if (const auto *VTy = dyn_cast<VectorType>(Ty)) {
+ uint64_t NumBits = VTy->getBitWidth();
+ if (NumBits == 128 || NumBits == 256) {
+ COMDATSymName = NumBits == 128 ? "__xmm@" : "__ymm@";
+ for (int I = VTy->getNumElements() - 1, E = -1; I != E; --I)
+ COMDATSymName +=
+ scalarConstantToHexString(C->getAggregateElement(I));
+ }
+ }
+ if (!COMDATSymName.empty()) {
+ unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ |
+ COFF::IMAGE_SCN_LNK_COMDAT;
+ return getContext().getCOFFSection(".rdata", Characteristics, Kind,
+ COMDATSymName,
+ COFF::IMAGE_COMDAT_SELECT_ANY);
+ }
+ }
}
return TargetLoweringObjectFile::getSectionForConstant(Kind, C);
More information about the llvm-commits
mailing list