[llvm] r269179 - [mips][ias] Fix N32 and N64 .cprestore directive when inside .set noat region.
Daniel Sanders via llvm-commits
llvm-commits at lists.llvm.org
Wed May 11 05:48:19 PDT 2016
Author: dsanders
Date: Wed May 11 07:48:19 2016
New Revision: 269179
URL: http://llvm.org/viewvc/llvm-project?rev=269179&view=rev
Log:
[mips][ias] Fix N32 and N64 .cprestore directive when inside .set noat region.
Summary:
r268058 unintentionally made the retrieval of the current assembler temporary
unconditional. This was fine for the existing tests but it broke the cases
where the assembler temporary is not needed (N32/N64 or not PIC) and is
unavailable due to a '.set noat' directive.
This fixes FreeBSD's libc.
Reviewers: emaste, sdardis, seanbruno
Subscribers: dsanders, emaste, sdardis, llvm-commits
Differential Revision: http://reviews.llvm.org/D20093
Added:
llvm/trunk/test/MC/Mips/cprestore-noreorder-noat.s
Modified:
llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
llvm/trunk/lib/Target/Mips/MipsTargetStreamer.h
Modified: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp?rev=269179&r1=269178&r2=269179&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp Wed May 11 07:48:19 2016
@@ -5448,11 +5448,9 @@ bool MipsAsmParser::parseDirectiveCpRest
return false;
}
- unsigned ATReg = getATReg(Loc);
- if (!ATReg)
+ if (!getTargetStreamer().emitDirectiveCpRestore(
+ CpRestoreOffset, [&]() { return getATReg(Loc); }, Loc, STI))
return true;
-
- getTargetStreamer().emitDirectiveCpRestore(CpRestoreOffset, ATReg, Loc, STI);
Parser.Lex(); // Consume the EndOfStatement.
return false;
}
Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp?rev=269179&r1=269178&r2=269179&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp Wed May 11 07:48:19 2016
@@ -96,10 +96,11 @@ void MipsTargetStreamer::emitDirectiveSe
void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
-void MipsTargetStreamer::emitDirectiveCpRestore(int Offset, unsigned ATReg,
- SMLoc IDLoc,
- const MCSubtargetInfo *STI) {
+bool MipsTargetStreamer::emitDirectiveCpRestore(
+ int Offset, std::function<unsigned()> GetATReg, SMLoc IDLoc,
+ const MCSubtargetInfo *STI) {
forbidModuleDirective();
+ return true;
}
void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
const MCSymbol &Sym, bool IsReg) {
@@ -578,11 +579,12 @@ void MipsTargetAsmStreamer::emitDirectiv
forbidModuleDirective();
}
-void MipsTargetAsmStreamer::emitDirectiveCpRestore(int Offset, unsigned ATReg,
- SMLoc IDLoc,
- const MCSubtargetInfo *STI) {
- MipsTargetStreamer::emitDirectiveCpRestore(Offset, ATReg, IDLoc, STI);
+bool MipsTargetAsmStreamer::emitDirectiveCpRestore(
+ int Offset, std::function<unsigned()> GetATReg, SMLoc IDLoc,
+ const MCSubtargetInfo *STI) {
+ MipsTargetStreamer::emitDirectiveCpRestore(Offset, GetATReg, IDLoc, STI);
OS << "\t.cprestore\t" << Offset << "\n";
+ return true;
}
void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
@@ -1034,10 +1036,10 @@ void MipsTargetELFStreamer::emitDirectiv
forbidModuleDirective();
}
-void MipsTargetELFStreamer::emitDirectiveCpRestore(int Offset, unsigned ATReg,
- SMLoc IDLoc,
- const MCSubtargetInfo *STI) {
- MipsTargetStreamer::emitDirectiveCpRestore(Offset, ATReg, IDLoc, STI);
+bool MipsTargetELFStreamer::emitDirectiveCpRestore(
+ int Offset, std::function<unsigned()> GetATReg, SMLoc IDLoc,
+ const MCSubtargetInfo *STI) {
+ MipsTargetStreamer::emitDirectiveCpRestore(Offset, GetATReg, IDLoc, STI);
// .cprestore offset
// When PIC mode is enabled and the O32 ABI is used, this directive expands
// to:
@@ -1047,11 +1049,16 @@ void MipsTargetELFStreamer::emitDirectiv
// Note that .cprestore is ignored if used with the N32 and N64 ABIs or if it
// is used in non-PIC mode.
if (!Pic || (getABI().IsN32() || getABI().IsN64()))
- return;
+ return true;
+
+ unsigned ATReg = GetATReg();
+ if (!ATReg)
+ return false;
// Store the $gp on the stack.
emitStoreWithImmOffset(Mips::SW, Mips::GP, Mips::SP, Offset, ATReg, IDLoc,
STI);
+ return true;
}
void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
Modified: llvm/trunk/lib/Target/Mips/MipsTargetStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetStreamer.h?rev=269179&r1=269178&r2=269179&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetStreamer.h (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetStreamer.h Wed May 11 07:48:19 2016
@@ -81,8 +81,9 @@ public:
// PIC support
virtual void emitDirectiveCpLoad(unsigned RegNo);
- virtual void emitDirectiveCpRestore(int Offset, unsigned ATReg, SMLoc IDLoc,
- const MCSubtargetInfo *STI);
+ virtual bool emitDirectiveCpRestore(int Offset,
+ std::function<unsigned()> GetATReg,
+ SMLoc IDLoc, const MCSubtargetInfo *STI);
virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
const MCSymbol &Sym, bool IsReg);
virtual void emitDirectiveCpreturn(unsigned SaveLocation,
@@ -235,8 +236,8 @@ public:
// PIC support
void emitDirectiveCpLoad(unsigned RegNo) override;
- void emitDirectiveCpRestore(int Offset, unsigned ATReg, SMLoc IDLoc,
- const MCSubtargetInfo *STI) override;
+ bool emitDirectiveCpRestore(int Offset, std::function<unsigned()> GetATReg,
+ SMLoc IDLoc, const MCSubtargetInfo *STI) override;
void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
const MCSymbol &Sym, bool IsReg) override;
void emitDirectiveCpreturn(unsigned SaveLocation,
@@ -290,8 +291,8 @@ public:
// PIC support
void emitDirectiveCpLoad(unsigned RegNo) override;
- void emitDirectiveCpRestore(int Offset, unsigned ATReg, SMLoc IDLoc,
- const MCSubtargetInfo *STI) override;
+ bool emitDirectiveCpRestore(int Offset, std::function<unsigned()> GetATReg,
+ SMLoc IDLoc, const MCSubtargetInfo *STI) override;
void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
const MCSymbol &Sym, bool IsReg) override;
void emitDirectiveCpreturn(unsigned SaveLocation,
Added: llvm/trunk/test/MC/Mips/cprestore-noreorder-noat.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/cprestore-noreorder-noat.s?rev=269179&view=auto
==============================================================================
--- llvm/trunk/test/MC/Mips/cprestore-noreorder-noat.s (added)
+++ llvm/trunk/test/MC/Mips/cprestore-noreorder-noat.s Wed May 11 07:48:19 2016
@@ -0,0 +1,36 @@
+# RUN: not llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=pic -filetype=obj \
+# RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=O32
+
+# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -relocation-model=pic \
+# RUN: -filetype=obj -o /dev/null 2>&1 | FileCheck %s -allow-empty -check-prefix=N32
+
+# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -relocation-model=pic -target-abi=n32 \
+# RUN: -filetype=obj -o /dev/null 2>&1 | FileCheck %s -allow-empty -check-prefix=N64
+
+# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -relocation-model=pic -target-abi=n32 \
+# RUN: -filetype=obj -o - | llvm-objdump -d -r - | \
+# RUN: FileCheck %s -check-prefix=NO-STORE
+
+# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -relocation-model=pic -filetype=obj -o - | \
+# RUN: llvm-objdump -d -r - | \
+# RUN: FileCheck %s -check-prefix=NO-STORE
+
+ .text
+ .ent foo
+foo:
+ .frame $sp, 0, $ra
+ .set noreorder
+ .set noat
+
+ .cpload $25
+ .cprestore 8
+# O32: :[[@LINE-1]]:3: error: pseudo-instruction requires $at, which is not available
+# N32-NOT: error: pseudo-instruction requires $at, which is not available
+# N64-NOT: error: pseudo-instruction requires $at, which is not available
+# NO-STORE-NOT: sw $gp, 8($sp)
+
+ jal $25
+ jal $4, $25
+ jal foo
+
+ .end foo
More information about the llvm-commits
mailing list