-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Put large common blocks into .lbss for the medium and large code models #161483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ class ELFAsmParser : public MCAsmParserExtension { | |
&ELFAsmParser::parseDirectiveSymbolAttribute>(".hidden"); | ||
addDirectiveHandler<&ELFAsmParser::parseDirectiveSubsection>(".subsection"); | ||
addDirectiveHandler<&ELFAsmParser::parseDirectiveCGProfile>(".cg_profile"); | ||
addDirectiveHandler<&ELFAsmParser::parseDirectiveLargecomm>(".largecomm"); | ||
} | ||
|
||
// FIXME: Part of this logic is duplicated in the MCELFStreamer. What is | ||
|
@@ -126,6 +127,7 @@ class ELFAsmParser : public MCAsmParserExtension { | |
bool parseDirectiveSymbolAttribute(StringRef, SMLoc); | ||
bool parseDirectiveSubsection(StringRef, SMLoc); | ||
bool parseDirectiveCGProfile(StringRef, SMLoc); | ||
bool parseDirectiveLargecomm(StringRef, SMLoc); | ||
|
||
private: | ||
bool parseSectionName(StringRef &SectionName); | ||
|
@@ -886,6 +888,54 @@ bool ELFAsmParser::parseDirectiveCGProfile(StringRef S, SMLoc Loc) { | |
return MCAsmParserExtension::parseDirectiveCGProfile(S, Loc); | ||
} | ||
|
||
bool ELFAsmParser::parseDirectiveLargecomm(StringRef s, SMLoc Loc) { | ||
|
||
if (getParser().checkForValidSection()) | ||
return true; | ||
|
||
MCSymbol *Sym; | ||
if (getParser().parseSymbol(Sym)) | ||
return TokError("expected identifier in directive"); | ||
|
||
if (getLexer().isNot(AsmToken::Comma)) | ||
return TokError("expected a comma"); | ||
Lex(); | ||
|
||
int64_t Size; | ||
SMLoc SizeLoc = getLexer().getLoc(); | ||
if (getParser().parseAbsoluteExpression(Size)) | ||
return true; | ||
|
||
int64_t Pow2Alignment = 0; | ||
SMLoc Pow2AlignmentLoc; | ||
if (getLexer().is(AsmToken::Comma)) { | ||
Lex(); | ||
Pow2AlignmentLoc = getLexer().getLoc(); | ||
if (getParser().parseAbsoluteExpression(Pow2Alignment)) | ||
return true; | ||
|
||
// If this target takes alignments in bytes (not log) validate and convert. | ||
if (getLexer().getMAI().getCOMMDirectiveAlignmentIsInBytes()) { | ||
if (!isPowerOf2_64(Pow2Alignment)) | ||
return Error(Pow2AlignmentLoc, "alignment must be a power of 2"); | ||
Pow2Alignment = Log2_64(Pow2Alignment); | ||
} | ||
} | ||
|
||
if (parseEOL()) | ||
return true; | ||
|
||
if (Size < 0) | ||
return Error(SizeLoc, "size must be non-negative"); | ||
|
||
Sym->redefineIfPossible(); | ||
if (!Sym->isUndefined()) | ||
return Error(Loc, "invalid symbol redefinition"); | ||
|
||
getStreamer().emitLargeCommonSymbol(Sym, Size, Align(1ULL << Pow2Alignment)); | ||
|
||
return false; | ||
} | ||
|
||
namespace llvm { | ||
|
||
MCAsmParserExtension *createELFAsmParser() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
; RUN: llc -filetype=asm -code-model=medium %s --large-data-threshold=65636 -o - | FileCheck %s --check-prefix=CHECKASM-MEDIUM | ||
; RUN: llc -filetype=asm -code-model=large %s -o - | FileCheck %s --check-prefix=CHECKASM-LARGE | ||
; RUN: llc -filetype=asm -code-model=medium %s --large-data-threshold=65636 -o - | llvm-mc -filetype=obj - | llvm-readelf -s - | FileCheck %s --check-prefix=CHECKOBJ-MEDIUM | ||
; RUN: llc -filetype=asm -code-model=large %s -o - | llvm-mc -filetype=obj - | llvm-readelf -s - | FileCheck %s --check-prefix=CHECKOBJ-LARGE | ||
|
||
; CHECKASM-MEDIUM: .section .lbss,"awl",@nobits | ||
; CHECKASM-MEDIUM-NEXT: .type __BLNK__,@object # @__BLNK__ | ||
; CHECKASM-MEDIUM-NEXT: .largecomm __BLNK__,48394093832,8 | ||
; CHECKASM-MEDIUM-NEXT: .type ccc_,@object # @ccc_ | ||
; CHECKASM-MEDIUM-NEXT: .comm ccc_,8,8 | ||
|
||
; CHECKASM-LARGE: .section .lbss,"awl",@nobits | ||
; CHECKASM-LARGE-NEXT: .type __BLNK__,@object # @__BLNK__ | ||
; CHECKASM-LARGE-NEXT: .largecomm __BLNK__,48394093832,8 | ||
; CHECKASM-LARGE-NEXT: .type ccc_,@object # @ccc_ | ||
; CHECKASM-LARGE-NEXT: .largecomm ccc_,8,8 | ||
|
||
; CHECKOBJ-MEDIUM: 8 OBJECT GLOBAL DEFAULT COM ccc_ | ||
; CHECKOBJ-MEDIUM: 48394093832 OBJECT GLOBAL DEFAULT LARGE_COMMON __BLNK | ||
|
||
; CHECKOBJ-LARGE: 8 OBJECT GLOBAL DEFAULT LARGE_COMMON ccc_ | ||
; CHECKOBJ-LARGE: 48394093832 OBJECT GLOBAL DEFAULT LARGE_COMMON __BLNK__ | ||
|
||
source_filename = "FIRModule" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
@__BLNK__ = common global [48394093832 x i8] zeroinitializer, align 8 | ||
@ccc_ = common global [8 x i8] zeroinitializer, align 8 | ||
@_QFECn1 = internal constant i32 77777 | ||
@_QFECn2 = internal constant i32 77777 | ||
|
||
define void @_QQmain() #0 { | ||
store double 1.000000e+00, ptr @ccc_, align 8 | ||
store double 2.000000e+00, ptr getelementptr inbounds nuw (i8, ptr @__BLNK__, i64 61600176), align 8 | ||
ret void | ||
} | ||
|
||
declare void @_FortranAProgramStart(i32, ptr, ptr, ptr) #1 | ||
|
||
declare void @_FortranAProgramEndStatement() #1 | ||
|
||
define i32 @main(i32 %0, ptr %1, ptr %2) #0 { | ||
call void @_FortranAProgramStart(i32 %0, ptr %1, ptr %2, ptr null) | ||
call void @_QQmain() | ||
call void @_FortranAProgramEndStatement() | ||
ret i32 0 | ||
} | ||
|
||
attributes #0 = { "frame-pointer"="all" "target-cpu"="x86-64" } | ||
attributes #1 = { "frame-pointer"="all" } | ||
|
||
!llvm.ident = !{!0} | ||
!llvm.module.flags = !{!1, !2, !3} | ||
|
||
!0 = !{!"flang version 22.0.0 (https://github.com/llvm/llvm-project.git e1afe25356b8d2ee14f5f88bdb6c2a1526ed14ef)"} | ||
!1 = !{i32 2, !"Debug Info Version", i32 3} | ||
!2 = !{i32 8, !"PIC Level", i32 2} | ||
!3 = !{i32 7, !"PIE Level", i32 2} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1052,6 +1052,8 @@ ELFDumper<ELFT>::getSymbolSectionIndex(const Elf_Sym &Symbol, unsigned SymIndex, | |
return CreateErr("SHN_ABS"); | ||
if (Ndx == ELF::SHN_COMMON) | ||
return CreateErr("SHN_COMMON"); | ||
if (Ndx == ELF::SHN_AMD64_LCOMMON) | ||
return CreateErr("SHN_AMD64_LCOMMON"); | ||
return CreateErr("SHN_LORESERVE", Ndx - SHN_LORESERVE); | ||
} | ||
|
||
|
@@ -4308,6 +4310,9 @@ std::string GNUELFDumper<ELFT>::getSymbolSectionNdx( | |
default: | ||
// Find if: | ||
// Processor specific | ||
if (this->Obj.getHeader().e_machine == EM_X86_64 && | ||
|
||
SectionIndex == ELF::SHN_AMD64_LCOMMON) | ||
return "LARGE_COMMON"; | ||
if (SectionIndex >= ELF::SHN_LOPROC && SectionIndex <= ELF::SHN_HIPROC) | ||
return std::string("PRC[0x") + | ||
to_string(format_hex_no_prefix(SectionIndex, 4)) + "]"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LargeCommonSec