Skip to content

Commit 2ba3f0a

Browse files
committed
Update patch to use PPCTargetXCOFFStreamer instead.
1 parent bef0def commit 2ba3f0a

File tree

14 files changed

+41
-52
lines changed

14 files changed

+41
-52
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ class MCObjectStreamer : public MCStreamer {
185185
void emitFileDirective(StringRef Filename) override;
186186
void emitFileDirective(StringRef Filename, StringRef CompilerVersion,
187187
StringRef TimeStamp, StringRef Description) override;
188-
void emitMachineDirective(StringRef CPU) override;
189188

190189
void emitAddrsig() override;
191190
void emitAddrsigSym(const MCSymbol *Sym) override;

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,6 @@ class MCStreamer {
871871
virtual void emitFileDirective(StringRef Filename, StringRef CompilerVersion,
872872
StringRef TimeStamp, StringRef Description);
873873

874-
// Emit '.machine "CPU"' assembler directive.
875-
virtual void emitMachineDirective(StringRef CPU);
876-
877874
/// Emit the "identifiers" directive. This implements the
878875
/// '.ident "version foo"' assembler directive.
879876
virtual void emitIdent(StringRef IdentString) {}

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
#include "llvm/Target/TargetLoweringObjectFile.h"
121121
#include "llvm/Target/TargetMachine.h"
122122
#include "llvm/Target/TargetOptions.h"
123-
#include "llvm/TargetParser/PPCTargetParser.h"
124123
#include "llvm/TargetParser/Triple.h"
125124
#include <algorithm>
126125
#include <cassert>
@@ -520,28 +519,9 @@ bool AsmPrinter::doInitialization(Module &M) {
520519
}
521520
}
522521

523-
if (Target.isOSBinFormatXCOFF()) {
524-
// Emit .machine directive on AIX.
525-
XCOFF::CFileCpuId TargetCpuId = XCOFF::TCPU_INVALID;
526-
// Walk through the "target-cpu" attribute of functions and use the newest
527-
// level as the CPU of the module.
528-
for (auto &F : M) {
529-
XCOFF::CFileCpuId FunCpuId =
530-
XCOFF::getCpuID(TM.getSubtargetImpl(F)->getCPU());
531-
if (FunCpuId > TargetCpuId)
532-
TargetCpuId = FunCpuId;
533-
}
534-
// If there is no "target-cpu" attribute in functions, take the "-mcpu"
535-
// value. If both are omitted, use getNormalizedPPCTargetCPU() to determine
536-
// the default CPU.
537-
if (!TargetCpuId)
538-
TargetCpuId = XCOFF::getCpuID(TM.getTargetCPU().empty()
539-
? PPC::getNormalizedPPCTargetCPU(Target)
540-
: TM.getTargetCPU());
541-
OutStreamer->emitMachineDirective(XCOFF::getTCPUString(TargetCpuId));
542-
543-
// On AIX, emit bytes for llvm.commandline metadata after .file so that the
544-
// C_INFO symbol is preserved if any csect is kept by the linker.
522+
// On AIX, emit bytes for llvm.commandline metadata after .file so that the
523+
// C_INFO symbol is preserved if any csect is kept by the linker.
524+
if (TM.getTargetTriple().isOSBinFormatXCOFF()) {
545525
emitModuleCommandLines(M);
546526
// Now we can generate section information.
547527
OutStreamer->initSections(false, *TM.getMCSubtargetInfo());

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,6 @@ class MCAsmStreamer final : public MCStreamer {
288288
void emitFileDirective(StringRef Filename) override;
289289
void emitFileDirective(StringRef Filename, StringRef CompilerVersion,
290290
StringRef TimeStamp, StringRef Description) override;
291-
292-
void emitMachineDirective(StringRef CPU) override;
293-
294291
Expected<unsigned> tryEmitDwarfFileDirective(
295292
unsigned FileNo, StringRef Directory, StringRef Filename,
296293
std::optional<MD5::MD5Result> Checksum = std::nullopt,
@@ -1632,12 +1629,6 @@ void MCAsmStreamer::emitFileDirective(StringRef Filename,
16321629
EmitEOL();
16331630
}
16341631

1635-
void MCAsmStreamer::emitMachineDirective(StringRef CPU) {
1636-
OS << "\t.machine\t";
1637-
PrintQuotedString(CPU, OS);
1638-
EmitEOL();
1639-
}
1640-
16411632
void MCAsmStreamer::printDwarfFileDirective(
16421633
unsigned FileNo, StringRef Directory, StringRef Filename,
16431634
std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,6 @@ void MCObjectStreamer::emitFileDirective(StringRef Filename,
804804
// with the integrated assembler.
805805
}
806806

807-
void MCObjectStreamer::emitMachineDirective(StringRef CPU) {
808-
getAssembler().getWriter().setCPU(CPU);
809-
}
810-
811807
void MCObjectStreamer::emitAddrsig() {
812808
getAssembler().getWriter().emitAddrsigSection();
813809
}

llvm/lib/MC/MCStreamer.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,9 +1184,6 @@ void MCStreamer::emitFileDirective(StringRef Filename,
11841184
StringRef CompilerVersion,
11851185
StringRef TimeStamp, StringRef Description) {
11861186
}
1187-
void MCStreamer::emitMachineDirective(StringRef CPU) {
1188-
llvm_unreachable("this directive only supported on XCOFF targets");
1189-
}
11901187
void MCStreamer::emitCOFFSymbolStorageClass(int StorageClass) {
11911188
llvm_unreachable("this directive only supported on COFF targets");
11921189
}

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
259259
}
260260

261261
void emitMachine(StringRef CPU) override {
262-
OS << "\t.machine " << CPU << '\n';
262+
const Triple &TT = Streamer.getContext().getTargetTriple();
263+
if (TT.isOSBinFormatXCOFF())
264+
OS << "\t.machine\t" << '\"' << CPU << '\"' << '\n';
265+
else
266+
OS << "\t.machine " << CPU << '\n';
263267
}
264268

265269
void emitAbiVersion(int AbiVersion) override {
@@ -423,7 +427,8 @@ class PPCTargetXCOFFStreamer : public PPCTargetStreamer {
423427
}
424428

425429
void emitMachine(StringRef CPU) override {
426-
llvm_unreachable("Machine pseudo-ops are invalid for XCOFF.");
430+
MCXCOFFStreamer &XCOFFStreamer = static_cast<MCXCOFFStreamer &>(Streamer);
431+
XCOFFStreamer.getAssembler().getWriter().setCPU(CPU);
427432
}
428433

429434
void emitAbiVersion(int AbiVersion) override {

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "llvm/Support/raw_ostream.h"
7373
#include "llvm/Target/TargetMachine.h"
7474
#include "llvm/TargetParser/Triple.h"
75+
#include "llvm/TargetParser/PPCTargetParser.h"
7576
#include "llvm/Transforms/Utils/ModuleUtils.h"
7677
#include <algorithm>
7778
#include <cassert>
@@ -3047,6 +3048,28 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
30473048
bool PPCAIXAsmPrinter::doInitialization(Module &M) {
30483049
const bool Result = PPCAsmPrinter::doInitialization(M);
30493050

3051+
// Emit .machine directive on AIX.
3052+
const Triple &Target = TM.getTargetTriple();
3053+
XCOFF::CFileCpuId TargetCpuId = XCOFF::TCPU_INVALID;
3054+
// Walk through the "target-cpu" attribute of functions and use the newest
3055+
// level as the CPU of the module.
3056+
for (auto &F : M) {
3057+
XCOFF::CFileCpuId FunCpuId =
3058+
XCOFF::getCpuID(TM.getSubtargetImpl(F)->getCPU());
3059+
if (FunCpuId > TargetCpuId)
3060+
TargetCpuId = FunCpuId;
3061+
}
3062+
// If there is no "target-cpu" attribute within the functions, take the
3063+
// "-mcpu" value. If both are omitted, use getNormalizedPPCTargetCPU() to
3064+
// determine the default CPU.
3065+
if (!TargetCpuId)
3066+
TargetCpuId = XCOFF::getCpuID(TM.getTargetCPU().empty()
3067+
? PPC::getNormalizedPPCTargetCPU(Target)
3068+
: TM.getTargetCPU());
3069+
PPCTargetStreamer *TS =
3070+
static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
3071+
TS->emitMachine(XCOFF::getTCPUString(TargetCpuId));
3072+
30503073
auto setCsectAlignment = [this](const GlobalObject *GO) {
30513074
// Declarations have 0 alignment which is set by default.
30523075
if (GO->isDeclarationForLinker())

llvm/test/CodeGen/PowerPC/aix-cpu-version.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s
22

33
; CHECK: .file "1.c"
4-
; CHECK-NEXT: .machine "PWR8"
54
; CHECK-NEXT: .csect ..text..[PR],5
65
; CHECK-NEXT: .rename ..text..[PR],""
6+
; CHECK-NEXT: .machine "PWR8"
77

88
source_filename = "1.c"
99

llvm/test/CodeGen/PowerPC/aix-filename-c.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
source_filename = "1.c"
99

1010
; ASM: .file "1.c",,"LLVM{{.*}}"
11-
; ASM-NEXT: .machine "PWR9"
1211
; ASM-NEXT: .csect ..text..[PR],5
1312
; ASM-NEXT: .rename ..text..[PR],""
13+
; ASM-NEXT: .machine "PWR9"
1414

1515
; OBJ32: Symbol {
1616
; OBJ32-NEXT: Index: 0

llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
; CHECK-NOT: .toc
4747

4848
; CHECK: .file
49-
; CHECK-NEXT: .machine "PWR7"
5049
; CHECK-NEXT: .csect ..text..[PR],5
50+
; CHECK-NEXT: .rename ..text..[PR],""
51+
; CHECK-NEXT: .machine "PWR7"
5152

5253
; CHECK: .csect .data[RW],5
5354
; CHECK-NEXT: .globl ivar

llvm/test/DebugInfo/XCOFF/empty.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ entry:
3535
!12 = !DILocation(line: 3, column: 3, scope: !8)
3636

3737
; ASM32: .file "1.c"
38-
; ASM32-NEXT: .machine "PWR7"
3938
; ASM32-NEXT: .csect ..text..[PR],5
4039
; ASM32-NEXT: .rename ..text..[PR],""
40+
; ASM32-NEXT: .machine "COM"
4141
; ASM32-NEXT: .globl main[DS] # -- Begin function main
4242
; ASM32-NEXT: .globl .main
4343
; ASM32-NEXT: .align 2
@@ -238,9 +238,9 @@ entry:
238238
; ASM32-NEXT: L..debug_line_end0:
239239

240240
; ASM64: .file "1.c"
241-
; ASM64-NEXT: .machine "PWR7"
242241
; ASM64-NEXT: .csect ..text..[PR],5
243242
; ASM64-NEXT: .rename ..text..[PR],""
243+
; ASM64-NEXT: .machine "COM"
244244
; ASM64-NEXT: .globl main[DS] # -- Begin function main
245245
; ASM64-NEXT: .globl .main
246246
; ASM64-NEXT: .align 2

llvm/test/DebugInfo/XCOFF/explicit-section.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ entry:
4343
!16 = !DILocation(line: 3, column: 3, scope: !14)
4444

4545
; CHECK: .file "2.c"
46-
; CHECK-NEXT: .machine "PWR7"
4746
; CHECK-NEXT: .csect ..text..[PR],5
4847
; CHECK-NEXT: .rename ..text..[PR],""
48+
; CHECK-NEXT: .machine "COM"
4949
; CHECK-NEXT: .globl bar[DS] # -- Begin function bar
5050
; CHECK-NEXT: .globl .bar
5151
; CHECK-NEXT: .align 2

llvm/test/DebugInfo/XCOFF/function-sections.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ entry:
3838
!14 = !DILocation(line: 8, column: 3, scope: !13)
3939

4040
; CHECK: .file "1.c"
41-
; CHECK-NEXT: .machine "PWR7"
4241
; CHECK-NEXT: .csect ..text..[PR],5
4342
; CHECK-NEXT: .rename ..text..[PR],""
43+
; CHECK-NEXT: .machine "COM"
4444
; CHECK-NEXT: .csect .foo[PR],5
4545
; CHECK-NEXT: .globl foo[DS] # -- Begin function foo
4646
; CHECK-NEXT: .globl .foo[PR]

0 commit comments

Comments
 (0)