Summary:
Adds support for generating the .data section in assembly files for global variables with a non-zero initialization. The support for writing the .data section in XCOFF object files will be added in a follow-on patch. Any relocations are not included in this patch.
Reviewers: hubert.reinterpretcast, sfertile, jasonliu, daltenty, Xiangling_L
Reviewed by: hubert.reinterpretcast
Subscribers: nemanjai, hiraditya, kbarton, MaskRay, jsji, wuzish, shchenz, DiggerLin, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66154
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369869
91177308-0d34-0410-b5e6-
96231b3b80d8
/// supported by the target.
void EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const;
+ /// Return the alignment in log2 form for the specified \p GV.
+ static unsigned getGVAlignmentLog2(const GlobalValue *GV,
+ const DataLayout &DL,
+ unsigned InBits = 0);
+
private:
/// Private state for PrintSpecial()
// Assign a unique ID to this machine instruction.
/// instead.
bool UseDataRegionDirectives = false;
+ /// True if .align is to be used for alignment. Only power-of-two
+ /// alignment is supported.
+ bool UseDotAlignForAlignment = false;
+
//===--- Data Emission Directives -------------------------------------===//
/// This should be set to the directive used to get some number of zero bytes
return UseDataRegionDirectives;
}
+ bool useDotAlignForAlignment() const {
+ return UseDotAlignForAlignment;
+ }
+
const char *getZeroDirective() const { return ZeroDirective; }
const char *getAsciiDirective() const { return AsciiDirective; }
const char *getAscizDirective() const { return AscizDirective; }
/// getGVAlignmentLog2 - Return the alignment to use for the specified global
/// value in log2 form. This rounds up to the preferred alignment if possible
/// and legal.
-static unsigned getGVAlignmentLog2(const GlobalValue *GV, const DataLayout &DL,
- unsigned InBits = 0) {
+unsigned AsmPrinter::getGVAlignmentLog2(const GlobalValue *GV,
+ const DataLayout &DL,
+ unsigned InBits) {
unsigned NumBits = 0;
if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
NumBits = DL.getPreferredAlignmentLog(GVar);
if (Kind.isText())
return TextSection;
+ if (Kind.isData())
+ return DataSection;
+
report_fatal_error("XCOFF other section types not yet implemented.");
}
HasDotTypeDotSizeDirective = false;
COMMDirectiveAlignmentIsInBytes = false;
LCOMMDirectiveAlignmentType = LCOMM::Log2Alignment;
+ UseDotAlignForAlignment = true;
+ AsciiDirective = nullptr; // not supported
+ AscizDirective = nullptr; // not supported
+ Data64bitsDirective = "\t.llong\t";
}
void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) {
+ if (MAI->useDotAlignForAlignment()) {
+ if (!isPowerOf2_32(ByteAlignment))
+ report_fatal_error("Only power-of-two alignments are supported "
+ "with .align.");
+ OS << "\t.align\t";
+ OS << Log2_32(ByteAlignment);
+ EmitEOL();
+ return;
+ }
+
// Some assemblers don't support non-power of two alignments, so we always
// emit alignments as a power of two if possible.
if (isPowerOf2_32(ByteAlignment)) {
TextSection = Ctx->getXCOFFSection(
".text", XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD,
XCOFF::C_HIDEXT, SectionKind::getText());
+
+ DataSection = Ctx->getXCOFFSection(
+ ".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD,
+ XCOFF::C_HIDEXT, SectionKind::getData());
}
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
return;
}
+ if (getKind().isData()) {
+ assert(getMappingClass() == XCOFF::XMC_RW &&
+ "Unhandled storage-mapping class for data section.");
+
+ OS << "\t.csect " << getSectionName() << "["
+ << "RW"
+ << "]" << '\n';
+ return;
+ }
+
if (getKind().isBSSLocal() || getKind().isCommon()) {
assert((getMappingClass() == XCOFF::XMC_RW ||
getMappingClass() == XCOFF::XMC_BS) &&
report_fatal_error("COMDAT not yet supported by AIX.");
SectionKind GVKind = getObjFileLowering().getKindForGlobal(GV, TM);
- if (!GVKind.isCommon() && !GVKind.isBSSLocal())
- report_fatal_error("Only common variables are supported on AIX for now.");
+ if (!GVKind.isCommon() && !GVKind.isBSSLocal() && !GVKind.isData())
+ report_fatal_error("Encountered a global variable kind that is "
+ "not supported yet.");
// Create the containing csect and switch to it.
MCSectionXCOFF *CSect = cast<MCSectionXCOFF>(
OutStreamer->SwitchSection(CSect);
// Create the symbol, set its storage class, and emit it.
- MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(getSymbol(GV));
- XSym->setStorageClass(
+ MCSymbolXCOFF *GVSym = cast<MCSymbolXCOFF>(getSymbol(GV));
+ GVSym->setStorageClass(
TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(GV));
- XSym->setContainingCsect(CSect);
+ GVSym->setContainingCsect(CSect);
const DataLayout &DL = GV->getParent()->getDataLayout();
- unsigned Align =
+
+ // Handle common symbols.
+ if (GVKind.isCommon() || GVKind.isBSSLocal()) {
+ unsigned Align =
GV->getAlignment() ? GV->getAlignment() : DL.getPreferredAlignment(GV);
- uint64_t Size = DL.getTypeAllocSize(GV->getType()->getElementType());
+ uint64_t Size = DL.getTypeAllocSize(GV->getType()->getElementType());
+
+ if (GVKind.isBSSLocal())
+ OutStreamer->EmitXCOFFLocalCommonSymbol(GVSym, Size, Align);
+ else
+ OutStreamer->EmitCommonSymbol(GVSym, Size, Align);
+ return;
+ }
+
+ // Get the alignment in the log2 form.
+ const unsigned AlignLog = getGVAlignmentLog2(GV, DL);
- if (GVKind.isBSSLocal())
- OutStreamer->EmitXCOFFLocalCommonSymbol(XSym, Size, Align);
- else
- OutStreamer->EmitCommonSymbol(XSym, Size, Align);
+ MCSymbol *EmittedInitSym = GVSym;
+ EmitLinkage(GV, EmittedInitSym);
+ EmitAlignment(AlignLog, GV);
+ OutStreamer->EmitLabel(EmittedInitSym);
+ EmitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer());
}
/// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code
--- /dev/null
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s
+
+@ivar = local_unnamed_addr global i32 35, align 4
+@llvar = local_unnamed_addr global i64 36, align 8
+@svar = local_unnamed_addr global i16 37, align 2
+@fvar = local_unnamed_addr global float 8.000000e+02, align 4
+@dvar = local_unnamed_addr global double 9.000000e+02, align 8
+@over_aligned = local_unnamed_addr global double 9.000000e+02, align 32
+@charr = local_unnamed_addr global [4 x i8] c"abcd", align 1
+@dblarr = local_unnamed_addr global [4 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00], align 8
+
+; CHECK: .csect .data[RW]
+; CHECK-NEXT: .globl ivar
+; CHECK-NEXT: .align 2
+; CHECK-NEXT: ivar:
+; CHECK-NEXT: .long 35
+
+; CHECK: .globl llvar
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: llvar:
+; CHECK-NEXT: .llong 36
+
+; CHECK: .globl svar
+; CHECK-NEXT: .align 1
+; CHECK-NEXT: svar:
+; CHECK-NEXT: .short 37
+
+; CHECK: .globl fvar
+; CHECK-NEXT: .align 2
+; CHECK-NEXT: fvar:
+; CHECK-NEXT: .long 1145569280
+
+; CHECK: .globl dvar
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: dvar:
+; CHECK-NEXT: .llong 4651127699538968576
+
+; CHECK: .globl over_aligned
+; CHECK-NEXT: .align 5
+; CHECK-NEXT: over_aligned:
+; CHECK-NEXT: .llong 4651127699538968576
+
+; CHECK: .globl charr
+; CHECK-NEXT: charr:
+; CHECK-NEXT: .byte 97
+; CHECK-NEXT: .byte 98
+; CHECK-NEXT: .byte 99
+; CHECK-NEXT: .byte 100
+
+; CHECK: .globl dblarr
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: dblarr:
+; CHECK-NEXT: .llong 4607182418800017408
+; CHECK-NEXT: .llong 4611686018427387904
+; CHECK-NEXT: .llong 4613937818241073152
+; CHECK-NEXT: .llong 4616189618054758400