llvm.org GIT mirror llvm / 57ec696
Revert r240762 "[X86] Cleanup X86WindowsTargetObjectFile::getSectionForConstant" It seems to have caused PR23966: "UNREACHABLE executed at ..\lib\Target\X86\X86TargetObjectFile.cpp:148" git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240793 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 5 years ago
1 changed file(s) with 37 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
130130 return HexString;
131131 }
132132
133
133134 static std::string scalarConstantToHexString(const Constant *C) {
134135 Type *Ty = C->getType();
136 APInt AI;
135137 if (isa(C)) {
136 return APIntToHexString(APInt::getNullValue(Ty->getPrimitiveSizeInBits()));
137 } else if (const auto *CFP = dyn_cast(C)) {
138 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
139 } else if (const auto *CI = dyn_cast(C)) {
140 return APIntToHexString(CI->getValue());
141 } else if (const auto *VTy = dyn_cast(Ty)) {
142 std::string HexString;
143 for (int I = VTy->getNumElements() - 1, E = -1; I != E; --I)
144 HexString += scalarConstantToHexString(C->getAggregateElement(I));
145 return HexString;
138 AI = APInt(Ty->getPrimitiveSizeInBits(), /*val=*/0);
139 } else if (Ty->isFloatTy() || Ty->isDoubleTy()) {
140 const auto *CFP = cast(C);
141 AI = CFP->getValueAPF().bitcastToAPInt();
142 } else if (Ty->isIntegerTy()) {
143 const auto *CI = cast(C);
144 AI = CI->getValue();
145 } else {
146 llvm_unreachable("unexpected constant pool element type!");
146147 }
147 llvm_unreachable("unexpected constant pool element type!");
148 return APIntToHexString(AI);
148149 }
149150
150151 MCSection *
151152 X86WindowsTargetObjectFile::getSectionForConstant(SectionKind Kind,
152153 const Constant *C) const {
153 if (Kind.isMergeableConst() && C) {
154 const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
155 COFF::IMAGE_SCN_MEM_READ |
156 COFF::IMAGE_SCN_LNK_COMDAT;
157 std::string COMDATSymName;
158 if (Kind.isMergeableConst4() || Kind.isMergeableConst8())
159 COMDATSymName = "__real@" + scalarConstantToHexString(C);
160 else if (Kind.isMergeableConst16())
161 COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
162
163 if (!COMDATSymName.empty())
164 return getContext().getCOFFSection(".rdata", Characteristics, Kind,
165 COMDATSymName,
166 COFF::IMAGE_COMDAT_SELECT_ANY);
154 if (Kind.isReadOnly()) {
155 if (C) {
156 Type *Ty = C->getType();
157 SmallString<32> COMDATSymName;
158 if (Ty->isFloatTy() || Ty->isDoubleTy()) {
159 COMDATSymName = "__real@";
160 COMDATSymName += scalarConstantToHexString(C);
161 } else if (const auto *VTy = dyn_cast(Ty)) {
162 uint64_t NumBits = VTy->getBitWidth();
163 if (NumBits == 128 || NumBits == 256) {
164 COMDATSymName = NumBits == 128 ? "__xmm@" : "__ymm@";
165 for (int I = VTy->getNumElements() - 1, E = -1; I != E; --I)
166 COMDATSymName +=
167 scalarConstantToHexString(C->getAggregateElement(I));
168 }
169 }
170 if (!COMDATSymName.empty()) {
171 unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
172 COFF::IMAGE_SCN_MEM_READ |
173 COFF::IMAGE_SCN_LNK_COMDAT;
174 return getContext().getCOFFSection(".rdata", Characteristics, Kind,
175 COMDATSymName,
176 COFF::IMAGE_COMDAT_SELECT_ANY);
177 }
178 }
167179 }
168180
169181 return TargetLoweringObjectFile::getSectionForConstant(Kind, C);