<div dir="ltr">This doesn't pass 'check' if the default OS is Windows. I have ~12 tests failing. I'll try to take a look at this.<div><br></div><div><div><br></div><div>D:/src/llvm/build_debug/./bin\llc.EXE < D:\src\llvm\test\CodeGen\X86\widen_load-2.ll -o - -mcpu=generic -march=x86-64 -mattr=+sse4.2 | D:/src/llvm/build_debug/./bin\FileCheck.EXE D:\src\llvm\test\CodeGen\X86\widen_load-2.ll</div>
<div>--</div><div>Exit Code: 1</div><div><br></div><div>Command Output (stdout):</div><div>--</div><div>Command 0: "D:/src/llvm/build_debug/./bin\llc.EXE" "-o" "-" "-mcpu=generic" "-march=x86-64" "-mattr=+sse4.2"</div>
<div>Command 0 Result: -2147483645</div><div>Command 0 Output:</div><div><br></div><div><br></div><div>Command 0 Stderr:</div><div>Assertion failed: isa<X>(Val) && "cast<Ty>() argument of incompatible type!", file D:\src\llvm\include\llvm/Support/Casting.h, line 237</div>
<div>Stack dump:</div><div>0. Program arguments: D:/src/llvm/build_debug/./bin\llc.EXE -o - -mcpu=generic -march=x86-64 -mattr=+sse4.2</div><div>1. Running pass 'Function Pass Manager' on module '<stdin>'.</div>
<div>2. Running pass 'X86 Assembly / Object Emitter' on function '@rot'</div><div>0x01592A9A (0x0000000A 0x00000000 0x0290EEB0 0x0157BC2B), _NMSG_WRITE() + 0x8A bytes(s), f:\dd\vctools\crt\crtw32\startup\crt0msg.c, line 226</div>
<div>0x0157DE8C (0x0290EF90 0x0290EFA0 0x00000000 0x00002940), abort() + 0x1C bytes(s), f:\dd\vctools\crt\crtw32\misc\abort.c, line 62 + 0x7 byte(s)</div><div>0x0157BC2B (0x01953358 0x01953300 0x000000ED 0x0290EF90), _wassert() + 0xBEB bytes(s), f:\dd\vctools\crt\crtw32\misc\assert.c, line 380</div>
<div>0x00AA5343 (0x0019F8C8 0x0290F0F8 0xCCCCCCCC 0xCCCCCCCC), llvm::cast<llvm::ConstantDataVector,llvm::Constant const >() + 0x33 bytes(s), d:\src\llvm\include\llvm\support\casting.h, line 237 + 0x30 byte(s)</div><div>
0x00AA4C92 (0xCCCCCC09 0x0019F8C8 0x0290F160 0x0290F100), llvm::X86WindowsTargetObjectFile::getSectionForConstant() + 0x112 bytes(s), d:\src\llvm\lib\target\x86\x86targetobjectfile.cpp, line 150 + 0x9 byte(s)</div><div>0x00B017C0 (0x0290F1FC 0x0290F168 0xCCCCCCCC 0xCCCCCCCC), llvm::AsmPrinter::EmitConstantPool() + 0x150 bytes(s), d:\src\llvm\lib\codegen\asmprinter\asmprinter.cpp, line 1071 + 0x31 byte(s)</div>
<div>0x00B0086B (0x0290F184 0x00000002 0x00CCCCCC 0x001DC220), llvm::AsmPrinter::EmitFunctionHeader() + 0x2B bytes(s), d:\src\llvm\lib\codegen\asmprinter\asmprinter.cpp, line 510 + 0xF byte(s)</div><div>0x00959160 (0x001DD858 0x0290F19C 0x001DD858 0x001DC220), llvm::X86AsmPrinter::runOnMachineFunction() + 0xF0 bytes(s), d:\src\llvm\lib\target\x86\x86asmprinter.cpp, line 66</div>
<div>0x00C44800 (0x001A5628 0x0290F2F4 0x0290F238 0x00000001), llvm::MachineFunctionPass::runOnFunction() + 0x50 bytes(s), d:\src\llvm\lib\codegen\machinefunctionpass.cpp, line 33 + 0x13 byte(s)</div><div>0x00EAC9A5 (0x001A5628 0x00000000 0xCCCCCCCC 0x0019A054), llvm::FPPassManager::runOnFunction() + 0x105 bytes(s), d:\src\llvm\lib\ir\legacypassmanager.cpp, line 1545 + 0x17 byte(s)</div>
<div>0x00EACB35 (0x0019A080 0x0290F76C 0x0290F300 0x00000000), llvm::FPPassManager::runOnModule() + 0x75 bytes(s), d:\src\llvm\lib\ir\legacypassmanager.cpp, line 1565 + 0x15 byte(s)</div><div>0x00EADAA9 (0x0019A080 0x0290F344 0x7EFDE000 0xCCCCCCCC), `anonymous namespace'::MPPassManager::runOnModule() + 0x1C9 bytes(s), d:\src\llvm\lib\ir\legacypassmanager.cpp, line 1623 + 0x17 byte(s)</div>
<div>0x00EAE121 (0x0019A080 0x0290F458 0x0290F76C 0x00933991), llvm::legacy::PassManagerImpl::run() + 0x101 bytes(s), d:\src\llvm\lib\ir\legacypassmanager.cpp, line 1730 + 0x1B byte(s)</div><div>0x00EA8E0D (0x0019A080 0x0290F7BC 0x00000000 0xCCCCCCCC), llvm::legacy::PassManager::run() + 0x1D bytes(s), d:\src\llvm\lib\ir\legacypassmanager.cpp, line 1768</div>
<div>0x00933991 (0x001926B0 0x00192390 0x00000000 0xCCCCCCCC), compileModule() + 0xE21 bytes(s), d:\src\llvm\tools\llc\llc.cpp, line 364</div><div>0x009340F7 (0x00000006 0x001926B0 0x00192750 0xA7BE1148), main() + 0xE7 bytes(s), d:\src\llvm\tools\llc\llc.cpp, line 211 + 0xD byte(s)</div>
<div>0x0157C0CA (0x0290F81C 0x74AD338A 0x7EFDE000 0x0290F85C), __tmainCRTStartup() + 0x11A bytes(s), f:\dd\vctools\crt\crtw32\startup\crt0.c, line 255 + 0x19 byte(s)</div><div>0x0157C21D (0x7EFDE000 0x0290F85C 0x76F69F72 0x7EFDE000), mainCRTStartup() + 0xD bytes(s), f:\dd\vctools\crt\crtw32\startup\crt0.c, line 165</div>
<div>0x74AD338A (0x7EFDE000 0x7559FA74 0x00000000 0x00000000), BaseThreadInitThunk() + 0x12 bytes(s)</div><div>0x76F69F72 (0x0157C210 0x7EFDE000 0x00000000 0x00000000), RtlInitializeExceptionChain() + 0x63 bytes(s)</div><div>
0x76F69F45 (0x0157C210 0x7EFDE000 0x00000000 0x00000000), RtlInitializeExceptionChain() + 0x36 bytes(s)</div></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 14, 2014 at 3:57 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: majnemer<br>
Date: Mon Jul 14 17:57:27 2014<br>
New Revision: 213006<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=213006&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=213006&view=rev</a><br>
Log:<br>
CodeGen: Stick constant pool entries in COMDAT sections for WinCOFF<br>
<br>
COFF lacks a feature that other object file formats support: mergeable<br>
sections.<br>
<br>
To work around this, MSVC sticks constant pool entries in special COMDAT<br>
sections so that each constant is in it's own section. This permits<br>
unused constants to be dropped and it also allows duplicate constants in<br>
different translation units to get merged together.<br>
<br>
This fixes PR20262.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D4482" target="_blank">http://reviews.llvm.org/D4482</a><br>
<br>
Added:<br>
llvm/trunk/test/CodeGen/X86/win_cst_pool.ll<br>
Modified:<br>
llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h<br>
llvm/trunk/include/llvm/MC/MCSectionCOFF.h<br>
llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h<br>
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp<br>
llvm/trunk/lib/MC/MCContext.cpp<br>
llvm/trunk/lib/Target/NVPTX/NVPTXTargetObjectFile.h<br>
llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp<br>
llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp<br>
llvm/trunk/lib/Target/X86/X86AsmPrinter.h<br>
llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp<br>
llvm/trunk/lib/Target/X86/X86TargetObjectFile.h<br>
llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp<br>
llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.h<br>
llvm/trunk/test/CodeGen/X86/constant-pool-sharing.ll<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h Mon Jul 14 17:57:27 2014<br>
@@ -43,7 +43,8 @@ public:<br>
<br>
/// Given a constant with the SectionKind, return a section that it should be<br>
/// placed in.<br>
- const MCSection *getSectionForConstant(SectionKind Kind) const override;<br>
+ const MCSection *getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const override;<br>
<br>
const MCSection *getExplicitSectionGlobal(const GlobalValue *GV,<br>
SectionKind Kind, Mangler &Mang,<br>
@@ -100,7 +101,8 @@ public:<br>
SectionKind Kind, Mangler &Mang,<br>
const TargetMachine &TM) const override;<br>
<br>
- const MCSection *getSectionForConstant(SectionKind Kind) const override;<br>
+ const MCSection *getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const override;<br>
<br>
/// The mach-o version of this method defaults to returning a stub reference.<br>
const MCExpr *<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCSectionCOFF.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionCOFF.h?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionCOFF.h?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCSectionCOFF.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCSectionCOFF.h Mon Jul 14 17:57:27 2014<br>
@@ -36,7 +36,7 @@ class MCSymbol;<br>
/// The COMDAT symbol of this section. Only valid if this is a COMDAT<br>
/// section. Two COMDAT sections are merged if they have the same<br>
/// COMDAT symbol.<br>
- const MCSymbol *COMDATSymbol;<br>
+ MCSymbol *COMDATSymbol;<br>
<br>
/// Selection - This is the Selection field for the section symbol, if<br>
/// it is a COMDAT section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0<br>
@@ -45,7 +45,7 @@ class MCSymbol;<br>
private:<br>
friend class MCContext;<br>
MCSectionCOFF(StringRef Section, unsigned Characteristics,<br>
- const MCSymbol *COMDATSymbol, int Selection, SectionKind K)<br>
+ MCSymbol *COMDATSymbol, int Selection, SectionKind K)<br>
: MCSection(SV_COFF, K), SectionName(Section),<br>
Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),<br>
Selection(Selection) {<br>
@@ -67,7 +67,7 @@ class MCSymbol;<br>
return SectionName.str() + "_end";<br>
}<br>
unsigned getCharacteristics() const { return Characteristics; }<br>
- const MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }<br>
+ MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }<br>
int getSelection() const { return Selection; }<br>
<br>
void setSelection(int Selection) const;<br>
<br>
Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)<br>
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Mon Jul 14 17:57:27 2014<br>
@@ -70,7 +70,8 @@ public:<br>
<br>
/// Given a constant with the SectionKind, return a section that it should be<br>
/// placed in.<br>
- virtual const MCSection *getSectionForConstant(SectionKind Kind) const;<br>
+ virtual const MCSection *getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const;<br>
<br>
/// Classify the specified global variable into a set of target independent<br>
/// categories embodied in SectionKind.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Jul 14 17:57:27 2014<br>
@@ -1064,7 +1064,11 @@ void AsmPrinter::EmitConstantPool() {<br>
<br>
SectionKind Kind = CPE.getSectionKind(TM.getDataLayout());<br>
<br>
- const MCSection *S = getObjFileLowering().getSectionForConstant(Kind);<br>
+ const Constant *C = nullptr;<br>
+ if (!CPE.isMachineConstantPoolEntry())<br>
+ C = CPE.Val.ConstVal;<br>
+<br>
+ const MCSection *S = getObjFileLowering().getSectionForConstant(Kind, C);<br>
<br>
// The number of sections are small, just do a linear search from the<br>
// last section to the first.<br>
@@ -1087,13 +1091,22 @@ void AsmPrinter::EmitConstantPool() {<br>
}<br>
<br>
// Now print stuff into the calculated sections.<br>
+ const MCSection *CurSection = nullptr;<br>
+ unsigned Offset = 0;<br>
for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {<br>
- OutStreamer.SwitchSection(CPSections[i].S);<br>
- EmitAlignment(Log2_32(CPSections[i].Alignment));<br>
-<br>
- unsigned Offset = 0;<br>
for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) {<br>
unsigned CPI = CPSections[i].CPEs[j];<br>
+ MCSymbol *Sym = GetCPISymbol(CPI);<br>
+ if (!Sym->isUndefined())<br>
+ continue;<br>
+<br>
+ if (CurSection != CPSections[i].S) {<br>
+ OutStreamer.SwitchSection(CPSections[i].S);<br>
+ EmitAlignment(Log2_32(CPSections[i].Alignment));<br>
+ CurSection = CPSections[i].S;<br>
+ Offset = 0;<br>
+ }<br>
+<br>
MachineConstantPoolEntry CPE = CP[CPI];<br>
<br>
// Emit inter-object padding for alignment.<br>
@@ -1103,8 +1116,8 @@ void AsmPrinter::EmitConstantPool() {<br>
<br>
Type *Ty = CPE.getType();<br>
Offset = NewOffset + TM.getDataLayout()->getTypeAllocSize(Ty);<br>
- OutStreamer.EmitLabel(GetCPISymbol(CPI));<br>
<br>
+ OutStreamer.EmitLabel(Sym);<br>
if (CPE.isMachineConstantPoolEntry())<br>
EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);<br>
else<br>
@@ -1142,7 +1155,8 @@ void AsmPrinter::EmitJumpTableInfo() {<br>
} else {<br>
// Otherwise, drop it in the readonly section.<br>
const MCSection *ReadOnlySection =<br>
- getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly());<br>
+ getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly(),<br>
+ /*C=*/nullptr);<br>
OutStreamer.SwitchSection(ReadOnlySection);<br>
JTInDiffSection = true;<br>
}<br>
<br>
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Mon Jul 14 17:57:27 2014<br>
@@ -338,8 +338,9 @@ SelectSectionForGlobal(const GlobalValue<br>
/// getSectionForConstant - Given a mergeable constant with the<br>
/// specified size and relocation information, return a section that it<br>
/// should be placed in.<br>
-const MCSection *TargetLoweringObjectFileELF::<br>
-getSectionForConstant(SectionKind Kind) const {<br>
+const MCSection *<br>
+TargetLoweringObjectFileELF::getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const {<br>
if (Kind.isMergeableConst4() && MergeableConst4Section)<br>
return MergeableConst4Section;<br>
if (Kind.isMergeableConst8() && MergeableConst8Section)<br>
@@ -654,7 +655,8 @@ SelectSectionForGlobal(const GlobalValue<br>
}<br>
<br>
const MCSection *<br>
-TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind) const {<br>
+TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const {<br>
// If this constant requires a relocation, we have to put it in the data<br>
// segment, not in the text segment.<br>
if (Kind.isDataRel() || Kind.isReadOnlyWithRel())<br>
<br>
Modified: llvm/trunk/lib/MC/MCContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCContext.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCContext.cpp Mon Jul 14 17:57:27 2014<br>
@@ -291,7 +291,7 @@ const MCSectionCOFF *MCContext::getCOFFS<br>
if (!IterBool.second)<br>
return Iter->second;<br>
<br>
- const MCSymbol *COMDATSymbol = nullptr;<br>
+ MCSymbol *COMDATSymbol = nullptr;<br>
if (!COMDATSymName.empty())<br>
COMDATSymbol = GetOrCreateSymbol(COMDATSymName);<br>
<br>
<br>
Modified: llvm/trunk/lib/Target/NVPTX/NVPTXTargetObjectFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXTargetObjectFile.h?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXTargetObjectFile.h?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/NVPTX/NVPTXTargetObjectFile.h (original)<br>
+++ llvm/trunk/lib/Target/NVPTX/NVPTXTargetObjectFile.h Mon Jul 14 17:57:27 2014<br>
@@ -87,7 +87,8 @@ public:<br>
new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());<br>
}<br>
<br>
- const MCSection *getSectionForConstant(SectionKind Kind) const override {<br>
+ const MCSection *getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const override {<br>
return ReadOnlySection;<br>
}<br>
<br>
<br>
Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Mon Jul 14 17:57:27 2014<br>
@@ -297,7 +297,8 @@ TargetLoweringObjectFile::SelectSectionF<br>
/// specified size and relocation information, return a section that it<br>
/// should be placed in.<br>
const MCSection *<br>
-TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const {<br>
+TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const {<br>
if (Kind.isReadOnly() && ReadOnlySection != nullptr)<br>
return ReadOnlySection;<br>
<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp Mon Jul 14 17:57:27 2014<br>
@@ -18,6 +18,7 @@<br>
#include "X86InstrInfo.h"<br>
#include "X86MachineFunctionInfo.h"<br>
#include "llvm/ADT/SmallString.h"<br>
+#include "llvm/CodeGen/MachineConstantPool.h"<br>
#include "llvm/CodeGen/MachineModuleInfoImpls.h"<br>
#include "llvm/CodeGen/MachineValueType.h"<br>
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"<br>
@@ -29,6 +30,7 @@<br>
#include "llvm/MC/MCAsmInfo.h"<br>
#include "llvm/MC/MCContext.h"<br>
#include "llvm/MC/MCExpr.h"<br>
+#include "llvm/MC/MCSectionCOFF.h"<br>
#include "llvm/MC/MCSectionMachO.h"<br>
#include "llvm/MC/MCStreamer.h"<br>
#include "llvm/MC/MCSymbol.h"<br>
@@ -549,6 +551,26 @@ emitNonLazySymbolPointer(MCStreamer &Out<br>
4 /*size*/);<br>
}<br>
<br>
+MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const {<br>
+ if (Subtarget->isTargetKnownWindowsMSVC()) {<br>
+ const MachineConstantPoolEntry &CPE =<br>
+ MF->getConstantPool()->getConstants()[CPID];<br>
+ if (!CPE.isMachineConstantPoolEntry()) {<br>
+ SectionKind Kind = CPE.getSectionKind(TM.getDataLayout());<br>
+ const Constant *C = CPE.Val.ConstVal;<br>
+ const MCSectionCOFF *S = cast<MCSectionCOFF>(<br>
+ getObjFileLowering().getSectionForConstant(Kind, C));<br>
+ if (MCSymbol *Sym = S->getCOMDATSymbol()) {<br>
+ if (Sym->isUndefined())<br>
+ OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global);<br>
+ return Sym;<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ return AsmPrinter::GetCPISymbol(CPID);<br>
+}<br>
+<br>
void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {<br>
SmallString<128> Directive;<br>
raw_svector_ostream OS(Directive);<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86AsmPrinter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.h?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.h?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86AsmPrinter.h (original)<br>
+++ llvm/trunk/lib/Target/X86/X86AsmPrinter.h Mon Jul 14 17:57:27 2014<br>
@@ -50,6 +50,9 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrin<br>
unsigned AsmVariant, const char *ExtraCode,<br>
raw_ostream &OS) override;<br>
<br>
+ /// \brief Return the symbol for the specified constant pool entry.<br>
+ MCSymbol *GetCPISymbol(unsigned CPID) const override;<br>
+<br>
bool runOnMachineFunction(MachineFunction &F) override;<br>
};<br>
<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp Mon Jul 14 17:57:27 2014<br>
@@ -8,10 +8,12 @@<br>
//===----------------------------------------------------------------------===//<br>
<br>
#include "X86TargetObjectFile.h"<br>
+#include "llvm/ADT/StringExtras.h"<br>
#include "llvm/IR/Mangler.h"<br>
#include "llvm/IR/Operator.h"<br>
#include "llvm/MC/MCContext.h"<br>
#include "llvm/MC/MCExpr.h"<br>
+#include "llvm/MC/MCSectionCOFF.h"<br>
#include "llvm/MC/MCSectionELF.h"<br>
#include "llvm/Support/Dwarf.h"<br>
#include "llvm/Target/TargetLowering.h"<br>
@@ -106,3 +108,62 @@ const MCExpr *X86WindowsTargetObjectFile<br>
MCSymbolRefExpr::VK_COFF_IMGREL32,<br>
getContext());<br>
}<br>
+<br>
+static std::string APIntToHexString(const APInt &AI, unsigned Width) {<br>
+ std::string HexString = utohexstr(AI.getLimitedValue(), /*LowerCase=*/true);<br>
+ unsigned Size = HexString.size();<br>
+ assert(Width >= Size && "hex string is too large!");<br>
+ HexString.insert(HexString.begin(), Width - Size, '0');<br>
+<br>
+ return HexString;<br>
+}<br>
+<br>
+<br>
+static std::string scalarConstantToHexString(const Constant *C) {<br>
+ Type *Ty = C->getType();<br>
+ if (Ty->isFloatTy()) {<br>
+ const auto *CFP = cast<ConstantFP>(C);<br>
+ return APIntToHexString(CFP->getValueAPF().bitcastToAPInt(), /*Width=*/8);<br>
+ } else if (Ty->isDoubleTy()) {<br>
+ const auto *CFP = cast<ConstantFP>(C);<br>
+ return APIntToHexString(CFP->getValueAPF().bitcastToAPInt(), /*Width=*/16);<br>
+ } else if (const auto *ITy = dyn_cast<IntegerType>(Ty)) {<br>
+ const auto *CI = cast<ConstantInt>(C);<br>
+ return APIntToHexString(CI->getValue(), (ITy->getBitWidth() / 8) * 2);<br>
+ }<br>
+ llvm_unreachable("unexpected constant pool element type!");<br>
+}<br>
+<br>
+const MCSection *<br>
+X86WindowsTargetObjectFile::getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const {<br>
+ if (Kind.isReadOnly()) {<br>
+ if (C) {<br>
+ Type *Ty = C->getType();<br>
+ SmallString<32> COMDATSymName;<br>
+ if (Ty->isFloatTy() || Ty->isDoubleTy()) {<br>
+ COMDATSymName = "__real@";<br>
+ COMDATSymName += scalarConstantToHexString(C);<br>
+ } else if (const auto *VTy = dyn_cast<VectorType>(Ty)) {<br>
+ uint64_t NumBits = VTy->getBitWidth();<br>
+ if (NumBits == 128 || NumBits == 256) {<br>
+ const auto *CDV = cast<ConstantDataVector>(C);<br>
+ COMDATSymName = NumBits == 128 ? "__xmm@" : "__ymm@";<br>
+ for (int I = CDV->getNumElements() - 1, E = -1; I != E; --I)<br>
+ COMDATSymName +=<br>
+ scalarConstantToHexString(CDV->getElementAsConstant(I));<br>
+ }<br>
+ }<br>
+ if (!COMDATSymName.empty()) {<br>
+ unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |<br>
+ COFF::IMAGE_SCN_MEM_READ |<br>
+ COFF::IMAGE_SCN_LNK_COMDAT;<br>
+ return getContext().getCOFFSection(".rdata", Characteristics, Kind,<br>
+ COMDATSymName,<br>
+ COFF::IMAGE_COMDAT_SELECT_ANY);<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ return TargetLoweringObjectFile::getSectionForConstant(Kind, C);<br>
+}<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86TargetObjectFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetObjectFile.h?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetObjectFile.h?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86TargetObjectFile.h (original)<br>
+++ llvm/trunk/lib/Target/X86/X86TargetObjectFile.h Mon Jul 14 17:57:27 2014<br>
@@ -46,6 +46,11 @@ namespace llvm {<br>
const MCExpr *<br>
getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,<br>
const TargetMachine &TM) const override;<br>
+<br>
+ /// \brief Given a mergeable constant with the specified size and relocation<br>
+ /// information, return a section that it should be placed in.<br>
+ const MCSection *getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const override;<br>
};<br>
<br>
} // end namespace llvm<br>
<br>
Modified: llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp Mon Jul 14 17:57:27 2014<br>
@@ -165,8 +165,9 @@ SelectSectionForGlobal(const GlobalValue<br>
report_fatal_error("Target does not support TLS or Common sections");<br>
}<br>
<br>
-const MCSection *XCoreTargetObjectFile::<br>
-getSectionForConstant(SectionKind Kind) const {<br>
+const MCSection *<br>
+XCoreTargetObjectFile::getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const {<br>
if (Kind.isMergeableConst4()) return MergeableConst4Section;<br>
if (Kind.isMergeableConst8()) return MergeableConst8Section;<br>
if (Kind.isMergeableConst16()) return MergeableConst16Section;<br>
<br>
Modified: llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.h?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.h?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.h (original)<br>
+++ llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.h Mon Jul 14 17:57:27 2014<br>
@@ -34,7 +34,8 @@ static const unsigned CodeModelLargeSize<br>
Mangler &Mang,<br>
const TargetMachine &TM) const override;<br>
<br>
- const MCSection *getSectionForConstant(SectionKind Kind) const override;<br>
+ const MCSection *getSectionForConstant(SectionKind Kind,<br>
+ const Constant *C) const override;<br>
};<br>
} // end namespace llvm<br>
<br>
<br>
Modified: llvm/trunk/test/CodeGen/X86/constant-pool-sharing.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/constant-pool-sharing.ll?rev=213006&r1=213005&r2=213006&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/constant-pool-sharing.ll?rev=213006&r1=213005&r2=213006&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/constant-pool-sharing.ll (original)<br>
+++ llvm/trunk/test/CodeGen/X86/constant-pool-sharing.ll Mon Jul 14 17:57:27 2014<br>
@@ -1,12 +1,13 @@<br>
-; RUN: llc < %s -mtriple=x86_64-linux -mcpu=corei7 | FileCheck %s<br>
-; RUN: llc < %s -mtriple=x86_64-win32 -mcpu=corei7 | FileCheck %s<br>
+; RUN: llc < %s -mtriple=x86_64-linux -mcpu=corei7 | FileCheck %s --check-prefix=COMMON --check-prefix=LINUX<br>
+; RUN: llc < %s -mtriple=x86_64-win32 -mcpu=corei7 | FileCheck %s --check-prefix=COMMON --check-prefix=MSVC<br>
<br>
; llc should share constant pool entries between this integer vector<br>
; and this floating-point vector since they have the same encoding.<br>
<br>
-; CHECK: LCPI0_0(%rip), %xmm0<br>
-; CHECK: movaps %xmm0, ({{%rdi|%rcx}})<br>
-; CHECK: movaps %xmm0, ({{%rsi|%rdx}})<br>
+; LINUX: LCPI0_0(%rip), %xmm0<br>
+; MSVC: __xmm@40000000400000004000000040000000(%rip), %xmm0<br>
+; COMMON: movaps %xmm0, ({{%rdi|%rcx}})<br>
+; COMMON: movaps %xmm0, ({{%rsi|%rdx}})<br>
<br>
define void @foo(<4 x i32>* %p, <4 x float>* %q, i1 %t) nounwind {<br>
entry:<br>
<br>
Added: llvm/trunk/test/CodeGen/X86/win_cst_pool.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win_cst_pool.ll?rev=213006&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win_cst_pool.ll?rev=213006&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/win_cst_pool.ll (added)<br>
+++ llvm/trunk/test/CodeGen/X86/win_cst_pool.ll Mon Jul 14 17:57:27 2014<br>
@@ -0,0 +1,49 @@<br>
+; RUN: llc < %s -mtriple=x86_64-win32 -mcpu=corei7 | FileCheck %s<br>
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-pc-windows-msvc"<br>
+<br>
+define double @double() {<br>
+ ret double 0x0000000000800000<br>
+}<br>
+; CHECK: .globl __real@0000000000800000<br>
+; CHECK-NEXT: .section .rdata,"rd",discard,__real@0000000000800000<br>
+; CHECK-NEXT: .align 8<br>
+; CHECK-NEXT: __real@0000000000800000:<br>
+; CHECK-NEXT: .quad 8388608<br>
+; CHECK: double:<br>
+; CHECK: movsd __real@0000000000800000(%rip), %xmm0<br>
+; CHECK-NEXT: ret<br>
+<br>
+define <4 x i32> @vec1() {<br>
+ ret <4 x i32> <i32 3, i32 2, i32 1, i32 0><br>
+}<br>
+; CHECK: .globl __xmm@00000000000000010000000200000003<br>
+; CHECK-NEXT: .section .rdata,"rd",discard,__xmm@00000000000000010000000200000003<br>
+; CHECK-NEXT: .align 16<br>
+; CHECK-NEXT: __xmm@00000000000000010000000200000003:<br>
+; CHECK-NEXT: .long 3<br>
+; CHECK-NEXT: .long 2<br>
+; CHECK-NEXT: .long 1<br>
+; CHECK-NEXT: .long 0<br>
+; CHECK: vec1:<br>
+; CHECK: movaps __xmm@00000000000000010000000200000003(%rip), %xmm0<br>
+; CHECK-NEXT: ret<br>
+<br>
+define <8 x i16> @vec2() {<br>
+ ret <8 x i16> <i16 7, i16 6, i16 5, i16 4, i16 3, i16 2, i16 1, i16 0><br>
+}<br>
+; CHECK: .globl __xmm@00000001000200030004000500060007<br>
+; CHECK-NEXT: .section .rdata,"rd",discard,__xmm@00000001000200030004000500060007<br>
+; CHECK-NEXT: .align 16<br>
+; CHECK-NEXT: __xmm@00000001000200030004000500060007:<br>
+; CHECK-NEXT: .short 7<br>
+; CHECK-NEXT: .short 6<br>
+; CHECK-NEXT: .short 5<br>
+; CHECK-NEXT: .short 4<br>
+; CHECK-NEXT: .short 3<br>
+; CHECK-NEXT: .short 2<br>
+; CHECK-NEXT: .short 1<br>
+; CHECK-NEXT: .short 0<br>
+; CHECK: vec2:<br>
+; CHECK: movaps __xmm@00000001000200030004000500060007(%rip), %xmm0<br>
+; CHECK-NEXT: ret<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>