1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[CodeGen] Hoist common AsmPrinter code out of X86, ARM, and AArch64

Every known PE COFF target emits /EXPORT: linker flags into a .drective
section. The AsmPrinter should handle this.

While we're at it, use global_values() and emit each export flag with
its own .ascii directive. This should make the .s file output more
readable.

llvm-svn: 322788
This commit is contained in:
Reid Kleckner 2018-01-17 23:55:23 +00:00
parent f590fad377
commit 8873e1db2a
8 changed files with 138 additions and 191 deletions

View File

@ -1430,6 +1430,22 @@ bool AsmPrinter::doFinalization(Module &M) {
if (MCSection *S = MAI->getNonexecutableStackSection(OutContext))
OutStreamer->SwitchSection(S);
if (TM.getTargetTriple().isOSBinFormatCOFF()) {
// Emit /EXPORT: flags for each exported global as necessary.
const auto &TLOF = getObjFileLowering();
std::string Flags;
for (const GlobalValue &GV : M.global_values()) {
raw_string_ostream OS(Flags);
TLOF.emitLinkerFlagsForGlobal(OS, &GV);
OS.flush();
if (!Flags.empty()) {
OutStreamer->SwitchSection(TLOF.getDrectveSection());
OutStreamer->EmitBytes(Flags);
}
Flags.clear();
}
}
// Allow the target to emit any magic that it wants at the end of the file,
// after everything else has gone out.
EmitEndOfAsmFile(M);

View File

@ -210,29 +210,6 @@ void AArch64AsmPrinter::EmitEndOfAsmFile(Module &M) {
OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
SM.serializeToStackMapSection();
}
if (TT.isOSBinFormatCOFF()) {
const auto &TLOF =
static_cast<const TargetLoweringObjectFileCOFF &>(getObjFileLowering());
std::string Flags;
raw_string_ostream OS(Flags);
for (const auto &Function : M)
TLOF.emitLinkerFlagsForGlobal(OS, &Function);
for (const auto &Global : M.globals())
TLOF.emitLinkerFlagsForGlobal(OS, &Global);
for (const auto &Alias : M.aliases())
TLOF.emitLinkerFlagsForGlobal(OS, &Alias);
OS.flush();
// Output collected flags
if (!Flags.empty()) {
OutStreamer->SwitchSection(TLOF.getDrectveSection());
OutStreamer->EmitBytes(Flags);
}
}
}
void AArch64AsmPrinter::EmitLOHs() {

View File

@ -545,29 +545,6 @@ void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
}
if (TT.isOSBinFormatCOFF()) {
const auto &TLOF =
static_cast<const TargetLoweringObjectFileCOFF &>(getObjFileLowering());
std::string Flags;
raw_string_ostream OS(Flags);
for (const auto &Function : M)
TLOF.emitLinkerFlagsForGlobal(OS, &Function);
for (const auto &Global : M.globals())
TLOF.emitLinkerFlagsForGlobal(OS, &Global);
for (const auto &Alias : M.aliases())
TLOF.emitLinkerFlagsForGlobal(OS, &Alias);
OS.flush();
// Output collected flags
if (!Flags.empty()) {
OutStreamer->SwitchSection(TLOF.getDrectveSection());
OutStreamer->EmitBytes(Flags);
}
}
// The last attribute to be emitted is ABI_optimization_goals
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);

View File

@ -646,27 +646,6 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
}
if (TT.isOSBinFormatCOFF()) {
const TargetLoweringObjectFileCOFF &TLOFCOFF =
static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering());
std::string Flags;
raw_string_ostream FlagsOS(Flags);
for (const auto &Function : M)
TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Function);
for (const auto &Global : M.globals())
TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Global);
for (const auto &Alias : M.aliases())
TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Alias);
FlagsOS.flush();
// Output collected flags.
if (!Flags.empty()) {
OutStreamer->SwitchSection(TLOFCOFF.getDrectveSection());
OutStreamer->EmitBytes(Flags);
}
SM.serializeToStackMapSection();
}

View File

@ -40,35 +40,34 @@ define weak_odr dllexport void @l() {
; CHECK: .section .drectve
; CHECK-GNU-NOT: -export:f
; CHECK-GNU: -export:g
; CHECK-GNU-SAME: -export:h
; CHECK-GNU: .ascii " -export:g"
; CHECK-GNU: .ascii " -export:h"
; CHECK-GNU-NOT: -export:i
; CHECK-GNU-SAME: -export:j
; CHECK-GNU-SAME: -export:k
; CHECK-GNU-SAME: -export:l
; CHECK-GNU-SAME: -export:m,data
; CHECK-GNU-SAME: -export:n,data
; CHECK-GNU-SAME: -export:o,data
; CHECK-GNU-SAME: -export:p,data
; CHECK-GNU-SAME: -export:q,data
; CHECK-GNU-SAME: -export:r
; CHECK-GNU-SAME: -export:s
; CHECK-GNU-SAME: -export:t
; CHECK-GNU-SAME: -export:u
; CHECK-GNU: .ascii " -export:j"
; CHECK-GNU: .ascii " -export:k"
; CHECK-GNU: .ascii " -export:l"
; CHECK-GNU: .ascii " -export:m,data"
; CHECK-GNU: .ascii " -export:n,data"
; CHECK-GNU: .ascii " -export:o,data"
; CHECK-GNU: .ascii " -export:p,data"
; CHECK-GNU: .ascii " -export:q,data"
; CHECK-GNU: .ascii " -export:r"
; CHECK-GNU: .ascii " -export:s"
; CHECK-GNU: .ascii " -export:t"
; CHECK-GNU: .ascii " -export:u"
; CHECK-MSVC-NOT: /EXPORT:f
; CHECK-MSVC: /EXPORT:g
; CHECK-MSVC-SAME: /EXPORT:h
; CHECK-MSVC: .ascii " /EXPORT:g"
; CHECK-MSVC: .ascii " /EXPORT:h"
; CHECK-MSVC-NOT: /EXPORT:i
; CHECK-MSVC-SAME: /EXPORT:j
; CHECK-MSVC-SAME: /EXPORT:k
; CHECK-MSVC-SAME: /EXPORT:l
; CHECK-MSVC-SAME: /EXPORT:m,DATA
; CHECK-MSVC-SAME: /EXPORT:n,DATA
; CHECK-MSVC-SAME: /EXPORT:o,DATA
; CHECK-MSVC-SAME: /EXPORT:p,DATA
; CHECK-MSVC-SAME: /EXPORT:q,DATA
; CHECK-MSVC-SAME: /EXPORT:r
; CHECK-MSVC-SAME: /EXPORT:s
; CHECK-MSVC-SAME: /EXPORT:t
; CHECK-MSVC-SAME: /EXPORT:u
; CHECK-MSVC: .ascii " /EXPORT:j"
; CHECK-MSVC: .ascii " /EXPORT:k"
; CHECK-MSVC: .ascii " /EXPORT:l"
; CHECK-MSVC: .ascii " /EXPORT:m,DATA"
; CHECK-MSVC: .ascii " /EXPORT:n,DATA"
; CHECK-MSVC: .ascii " /EXPORT:o,DATA"
; CHECK-MSVC: .ascii " /EXPORT:p,DATA"
; CHECK-MSVC: .ascii " /EXPORT:q,DATA"
; CHECK-MSVC: .ascii " /EXPORT:r"
; CHECK-MSVC: .ascii " /EXPORT:s"
; CHECK-MSVC: .ascii " /EXPORT:t"
; CHECK-MSVC: .ascii " /EXPORT:u"

View File

@ -41,35 +41,34 @@ define weak_odr dllexport void @l() {
; CHECK: .section .drectve
; CHECK-GNU-NOT: -export:f
; CHECK-GNU: -export:g
; CHECK-GNU-SAME: -export:h
; CHECK-GNU: .ascii " -export:g"
; CHECK-GNU: .ascii " -export:h"
; CHECK-GNU-NOT: -export:i
; CHECK-GNU-SAME: -export:j
; CHECK-GNU-SAME: -export:k
; CHECK-GNU-SAME: -export:l
; CHECK-GNU-SAME: -export:m,data
; CHECK-GNU-SAME: -export:n,data
; CHECK-GNU-SAME: -export:o,data
; CHECK-GNU-SAME: -export:p,data
; CHECK-GNU-SAME: -export:q,data
; CHECK-GNU-SAME: -export:r
; CHECK-GNU-SAME: -export:s
; CHECK-GNU-SAME: -export:t
; CHECK-GNU-SAME: -export:u
; CHECK-GNU: .ascii " -export:j"
; CHECK-GNU: .ascii " -export:k"
; CHECK-GNU: .ascii " -export:l"
; CHECK-GNU: .ascii " -export:m,data"
; CHECK-GNU: .ascii " -export:n,data"
; CHECK-GNU: .ascii " -export:o,data"
; CHECK-GNU: .ascii " -export:p,data"
; CHECK-GNU: .ascii " -export:q,data"
; CHECK-GNU: .ascii " -export:r"
; CHECK-GNU: .ascii " -export:s"
; CHECK-GNU: .ascii " -export:t"
; CHECK-GNU: .ascii " -export:u"
; CHECK-MSVC-NOT: /EXPORT:f
; CHECK-MSVC: /EXPORT:g
; CHECK-MSVC-SAME: /EXPORT:h
; CHECK-MSVC: .ascii " /EXPORT:g"
; CHECK-MSVC: .ascii " /EXPORT:h"
; CHECK-MSVC-NOT: /EXPORT:i
; CHECK-MSVC-SAME: /EXPORT:j
; CHECK-MSVC-SAME: /EXPORT:k
; CHECK-MSVC-SAME: /EXPORT:l
; CHECK-MSVC-SAME: /EXPORT:m,DATA
; CHECK-MSVC-SAME: /EXPORT:n,DATA
; CHECK-MSVC-SAME: /EXPORT:o,DATA
; CHECK-MSVC-SAME: /EXPORT:p,DATA
; CHECK-MSVC-SAME: /EXPORT:q,DATA
; CHECK-MSVC-SAME: /EXPORT:r
; CHECK-MSVC-SAME: /EXPORT:s
; CHECK-MSVC-SAME: /EXPORT:t
; CHECK-MSVC-SAME: /EXPORT:u
; CHECK-MSVC: .ascii " /EXPORT:j"
; CHECK-MSVC: .ascii " /EXPORT:k"
; CHECK-MSVC: .ascii " /EXPORT:l"
; CHECK-MSVC: .ascii " /EXPORT:m,DATA"
; CHECK-MSVC: .ascii " /EXPORT:n,DATA"
; CHECK-MSVC: .ascii " /EXPORT:o,DATA"
; CHECK-MSVC: .ascii " /EXPORT:p,DATA"
; CHECK-MSVC: .ascii " /EXPORT:q,DATA"
; CHECK-MSVC: .ascii " /EXPORT:r"
; CHECK-MSVC: .ascii " /EXPORT:s"
; CHECK-MSVC: .ascii " /EXPORT:t"
; CHECK-MSVC: .ascii " /EXPORT:u"

View File

@ -98,35 +98,35 @@ entry:
; NOTEXPORTED-NOT: exportedButNotDefinedFunction
; CHECK: .section .drectve
; WIN32: /EXPORT:f1
; WIN32-SAME: /EXPORT:f2
; WIN32-SAME: /EXPORT:lnk1
; WIN32-SAME: /EXPORT:lnk2
; WIN32-SAME: /EXPORT:weak1
; WIN32-SAME: /EXPORT:Var1,DATA
; WIN32-SAME: /EXPORT:Var2,DATA
; WIN32-SAME: /EXPORT:Var3,DATA
; WIN32-SAME: /EXPORT:WeakVar1,DATA
; WIN32-SAME: /EXPORT:WeakVar2,DATA
; WIN32-SAME: /EXPORT:WeakVar3,DATA
; WIN32-SAME: /EXPORT:alias
; WIN32-SAME: /EXPORT:alias2
; WIN32-SAME: /EXPORT:alias3
; WIN32-SAME: /EXPORT:weak_alias
; WIN32-SAME: /EXPORT:blob_alias
; MINGW: -export:f1
; MINGW-SAME: -export:f2
; MINGW-SAME: -export:lnk1
; MINGW-SAME: -export:lnk2
; MINGW-SAME: -export:weak1
; MINGW-SAME: -export:Var1,data
; MINGW-SAME: -export:Var2,data
; MINGW-SAME: -export:Var3,data
; MINGW-SAME: -export:WeakVar1,data
; MINGW-SAME: -export:WeakVar2,data
; MINGW-SAME: -export:WeakVar3,data
; MINGW-SAME: -export:alias
; MINGW-SAME: -export:alias2
; MINGW-SAME: -export:alias3
; MINGW-SAME: -export:weak_alias
; MINGW-SAME: -export:blob_alias"
; WIN32: .ascii " /EXPORT:f1"
; WIN32: .ascii " /EXPORT:f2"
; WIN32: .ascii " /EXPORT:lnk1"
; WIN32: .ascii " /EXPORT:lnk2"
; WIN32: .ascii " /EXPORT:weak1"
; WIN32: .ascii " /EXPORT:Var1,DATA"
; WIN32: .ascii " /EXPORT:Var2,DATA"
; WIN32: .ascii " /EXPORT:Var3,DATA"
; WIN32: .ascii " /EXPORT:WeakVar1,DATA"
; WIN32: .ascii " /EXPORT:WeakVar2,DATA"
; WIN32: .ascii " /EXPORT:WeakVar3,DATA"
; WIN32: .ascii " /EXPORT:alias"
; WIN32: .ascii " /EXPORT:alias2"
; WIN32: .ascii " /EXPORT:alias3"
; WIN32: .ascii " /EXPORT:weak_alias"
; WIN32: .ascii " /EXPORT:blob_alias"
; MINGW: .ascii " -export:f1"
; MINGW: .ascii " -export:f2"
; MINGW: .ascii " -export:lnk1"
; MINGW: .ascii " -export:lnk2"
; MINGW: .ascii " -export:weak1"
; MINGW: .ascii " -export:Var1,data"
; MINGW: .ascii " -export:Var2,data"
; MINGW: .ascii " -export:Var3,data"
; MINGW: .ascii " -export:WeakVar1,data"
; MINGW: .ascii " -export:WeakVar2,data"
; MINGW: .ascii " -export:WeakVar3,data"
; MINGW: .ascii " -export:alias"
; MINGW: .ascii " -export:alias2"
; MINGW: .ascii " -export:alias3"
; MINGW: .ascii " -export:weak_alias"
; MINGW: .ascii " -export:blob_alias"

View File

@ -101,37 +101,37 @@ define weak_odr dllexport void @weak1() {
; NOTEXPORTED-NOT: notDefined
; CHECK: .section .drectve
; CHECK-CL: /EXPORT:_f1
; CHECK-CL-SAME: /EXPORT:_f2
; CHECK-CL-SAME: /EXPORT:_stdfun@0
; CHECK-CL-SAME: /EXPORT:@fastfun@0
; CHECK-CL-SAME: /EXPORT:_thisfun
; CHECK-CL-SAME: /EXPORT:_lnk1
; CHECK-CL-SAME: /EXPORT:_lnk2
; CHECK-CL-SAME: /EXPORT:_weak1
; CHECK-CL-SAME: /EXPORT:_Var1,DATA
; CHECK-CL-SAME: /EXPORT:_Var2,DATA
; CHECK-CL-SAME: /EXPORT:_Var3,DATA
; CHECK-CL-SAME: /EXPORT:_WeakVar1,DATA
; CHECK-CL-SAME: /EXPORT:_WeakVar2,DATA
; CHECK-CL-SAME: /EXPORT:_alias
; CHECK-CL-SAME: /EXPORT:_alias2
; CHECK-CL-SAME: /EXPORT:_alias3
; CHECK-CL-SAME: /EXPORT:_weak_alias"
; CHECK-GCC: -export:f1
; CHECK-GCC-SAME: -export:f2
; CHECK-GCC-SAME: -export:stdfun@0
; CHECK-GCC-SAME: -export:@fastfun@0
; CHECK-GCC-SAME: -export:thisfun
; CHECK-GCC-SAME: -export:lnk1
; CHECK-GCC-SAME: -export:lnk2
; CHECK-GCC-SAME: -export:weak1
; CHECK-GCC-SAME: -export:Var1,data
; CHECK-GCC-SAME: -export:Var2,data
; CHECK-GCC-SAME: -export:Var3,data
; CHECK-GCC-SAME: -export:WeakVar1,data
; CHECK-GCC-SAME: -export:WeakVar2,data
; CHECK-GCC-SAME: -export:alias
; CHECK-GCC-SAME: -export:alias2
; CHECK-GCC-SAME: -export:alias3
; CHECK-GCC-SAME: -export:weak_alias"
; CHECK-CL: .ascii " /EXPORT:_f1"
; CHECK-CL: .ascii " /EXPORT:_f2"
; CHECK-CL: .ascii " /EXPORT:_stdfun@0"
; CHECK-CL: .ascii " /EXPORT:@fastfun@0"
; CHECK-CL: .ascii " /EXPORT:_thisfun"
; CHECK-CL: .ascii " /EXPORT:_lnk1"
; CHECK-CL: .ascii " /EXPORT:_lnk2"
; CHECK-CL: .ascii " /EXPORT:_weak1"
; CHECK-CL: .ascii " /EXPORT:_Var1,DATA"
; CHECK-CL: .ascii " /EXPORT:_Var2,DATA"
; CHECK-CL: .ascii " /EXPORT:_Var3,DATA"
; CHECK-CL: .ascii " /EXPORT:_WeakVar1,DATA"
; CHECK-CL: .ascii " /EXPORT:_WeakVar2,DATA"
; CHECK-CL: .ascii " /EXPORT:_alias"
; CHECK-CL: .ascii " /EXPORT:_alias2"
; CHECK-CL: .ascii " /EXPORT:_alias3"
; CHECK-CL: .ascii " /EXPORT:_weak_alias"
; CHECK-GCC: .ascii " -export:f1"
; CHECK-GCC: .ascii " -export:f2"
; CHECK-GCC: .ascii " -export:stdfun@0"
; CHECK-GCC: .ascii " -export:@fastfun@0"
; CHECK-GCC: .ascii " -export:thisfun"
; CHECK-GCC: .ascii " -export:lnk1"
; CHECK-GCC: .ascii " -export:lnk2"
; CHECK-GCC: .ascii " -export:weak1"
; CHECK-GCC: .ascii " -export:Var1,data"
; CHECK-GCC: .ascii " -export:Var2,data"
; CHECK-GCC: .ascii " -export:Var3,data"
; CHECK-GCC: .ascii " -export:WeakVar1,data"
; CHECK-GCC: .ascii " -export:WeakVar2,data"
; CHECK-GCC: .ascii " -export:alias"
; CHECK-GCC: .ascii " -export:alias2"
; CHECK-GCC: .ascii " -export:alias3"
; CHECK-GCC: .ascii " -export:weak_alias"