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