[llvm] 77e71c5 - [AIX] Don't use a zero fill with a second parameter
David Tenty via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 3 12:16:13 PST 2020
Author: David Tenty
Date: 2020-02-03T15:16:08-05:00
New Revision: 77e71c521726a7d3fce3d6dddbba9887d1a225c7
URL: https://github.com/llvm/llvm-project/commit/77e71c521726a7d3fce3d6dddbba9887d1a225c7
DIFF: https://github.com/llvm/llvm-project/commit/77e71c521726a7d3fce3d6dddbba9887d1a225c7.diff
LOG: [AIX] Don't use a zero fill with a second parameter
Summary:
The AIX assembler .space directive can't take a second non-zero argument to fill
with. But LLVM emitFill currently assumes it can. We add a flag to the AsmInfo
to check if non-zero fill is supported, and if we can't zerofill non-zero values
we just splat the .byte directives.
Reviewers: stevewan, sfertile, DiggerLin, jasonliu, Xiangling_L
Reviewed By: jasonliu
Subscribers: Xiangling_L, wuzish, nemanjai, hiraditya, kbarton, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73554
Added:
llvm/test/CodeGen/PowerPC/aix-nonzero-zerofill.ll
Modified:
llvm/include/llvm/MC/MCAsmInfo.h
llvm/lib/MC/MCAsmStreamer.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 5a6dff64caef..4ed1170f97ab 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -171,12 +171,17 @@ class MCAsmInfo {
//===--- Data Emission Directives -------------------------------------===//
- /// This should be set to the directive used to get some number of zero bytes
- /// emitted to the current section. Common cases are "\t.zero\t" and
- /// "\t.space\t". If this is set to null, the Data*bitsDirective's will be
- /// used to emit zero bytes. Defaults to "\t.zero\t"
+ /// This should be set to the directive used to get some number of zero (and
+ /// non-zero if supported by the directive) bytes emitted to the current
+ /// section. Common cases are "\t.zero\t" and "\t.space\t". Defaults to
+ /// "\t.zero\t"
const char *ZeroDirective;
+ /// This should be set to true if the zero directive supports a value to emit
+ /// other than zero. If this is set to false, the Data*bitsDirective's will be
+ /// used to emit these bytes. Defaults to true.
+ bool ZeroDirectiveSupportsNonZeroValue = true;
+
/// This directive allows emission of an ascii string with the standard C
/// escape characters embedded into it. If a target doesn't support this, it
/// can be set to null. Defaults to "\t.ascii\t"
@@ -543,6 +548,9 @@ class MCAsmInfo {
}
const char *getZeroDirective() const { return ZeroDirective; }
+ bool doesZeroDirectiveSupportNonZeroValue() const {
+ return ZeroDirectiveSupportsNonZeroValue;
+ }
const char *getAsciiDirective() const { return AsciiDirective; }
const char *getAscizDirective() const { return AscizDirective; }
bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 5d369503995b..0921cb8fe16a 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -1098,16 +1098,27 @@ void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
void MCAsmStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
SMLoc Loc) {
int64_t IntNumBytes;
- if (NumBytes.evaluateAsAbsolute(IntNumBytes) && IntNumBytes == 0)
+ const bool IsAbsolute = NumBytes.evaluateAsAbsolute(IntNumBytes);
+ if (IsAbsolute && IntNumBytes == 0)
return;
if (const char *ZeroDirective = MAI->getZeroDirective()) {
- // FIXME: Emit location directives
- OS << ZeroDirective;
- NumBytes.print(OS, MAI);
- if (FillValue != 0)
- OS << ',' << (int)FillValue;
- EmitEOL();
+ if (MAI->doesZeroDirectiveSupportNonZeroValue() || FillValue == 0) {
+ // FIXME: Emit location directives
+ OS << ZeroDirective;
+ NumBytes.print(OS, MAI);
+ if (FillValue != 0)
+ OS << ',' << (int)FillValue;
+ EmitEOL();
+ } else {
+ if (!IsAbsolute)
+ report_fatal_error(
+ "Cannot emit non-absolute expression lengths of fill.");
+ for (int i = 0; i < IntNumBytes; ++i) {
+ OS << MAI->getData8bitsDirective() << (int)FillValue;
+ EmitEOL();
+ }
+ }
return;
}
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
index dc2c216a3efd..8c7b8a81889e 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
@@ -60,5 +60,6 @@ PPCXCOFFMCAsmInfo::PPCXCOFFMCAsmInfo(bool Is64Bit, const Triple &T) {
assert(!IsLittleEndian && "Little-endian XCOFF not supported.");
CodePointerSize = CalleeSaveStackSlotSize = Is64Bit ? 8 : 4;
ZeroDirective = "\t.space\t";
+ ZeroDirectiveSupportsNonZeroValue = false;
SymbolsHaveSMC = true;
}
diff --git a/llvm/test/CodeGen/PowerPC/aix-nonzero-zerofill.ll b/llvm/test/CodeGen/PowerPC/aix-nonzero-zerofill.ll
new file mode 100644
index 000000000000..0c974773f022
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-nonzero-zerofill.ll
@@ -0,0 +1,10 @@
+; RUN: llc -verify-machineinstrs -O0 -mcpu=pwr4 -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -O0 -mcpu=pwr4 -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s
+
+ at a = constant [4 x i8] c"\02\02\02\02", align 1
+
+; CHECK-NOT: .space 4,2
+; CHECK: .byte 2
+; CHECK-NEXT: .byte 2
+; CHECK-NEXT: .byte 2
+; CHECK-NEXT: .byte 2
More information about the llvm-commits
mailing list