Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,8 @@ bool RISCVAsmParser::parseDirectiveOption() {

getTargetStreamer().emitDirectiveOptionRVC();
setFeatureBits(RISCV::FeatureStdExtC, "c");
clearFeatureBits(RISCV::FeatureDisableAsmCompression,
"disable-asm-compression");
return false;
}

Expand All @@ -3074,6 +3076,28 @@ bool RISCVAsmParser::parseDirectiveOption() {
getTargetStreamer().emitDirectiveOptionNoRVC();
clearFeatureBits(RISCV::FeatureStdExtC, "c");
clearFeatureBits(RISCV::FeatureStdExtZca, "zca");
setFeatureBits(RISCV::FeatureDisableAsmCompression,
"disable-asm-compression");
return false;
}

if (Option == "autocompress") {
if (Parser.parseEOL())
return true;

getTargetStreamer().emitDirectiveOptionAutoCompress();
clearFeatureBits(RISCV::FeatureDisableAsmCompression,
"disable-asm-compression");
return false;
}

if (Option == "noautocompress") {
if (Parser.parseEOL())
return true;

getTargetStreamer().emitDirectiveOptionNoAutoCompress();
setFeatureBits(RISCV::FeatureDisableAsmCompression,
"disable-asm-compression");
return false;
}

Expand Down Expand Up @@ -3326,7 +3350,9 @@ bool RISCVAsmParser::parseDirectiveVariantCC() {

void RISCVAsmParser::emitToStreamer(MCStreamer &S, const MCInst &Inst) {
MCInst CInst;
bool Res = RISCVRVC::compress(CInst, Inst, getSTI());
bool Res = false;
if (!getSTI().hasFeature(RISCV::FeatureDisableAsmCompression))
Res = RISCVRVC::compress(CInst, Inst, getSTI());
if (Res)
++RISCVNumInstrsCompressed;
S.emitInstruction((Res ? CInst : Inst), getSTI());
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void RISCVTargetELFStreamer::emitDirectiveOptionPIC() {}
void RISCVTargetELFStreamer::emitDirectiveOptionNoPIC() {}
void RISCVTargetELFStreamer::emitDirectiveOptionRVC() {}
void RISCVTargetELFStreamer::emitDirectiveOptionNoRVC() {}
void RISCVTargetELFStreamer::emitDirectiveOptionAutoCompress() {}
void RISCVTargetELFStreamer::emitDirectiveOptionNoAutoCompress() {}
void RISCVTargetELFStreamer::emitDirectiveOptionRelax() {}
void RISCVTargetELFStreamer::emitDirectiveOptionNoRelax() {}

Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class RISCVTargetELFStreamer : public RISCVTargetStreamer {
void emitDirectiveOptionNoPIC() override;
void emitDirectiveOptionRVC() override;
void emitDirectiveOptionNoRVC() override;
void emitDirectiveOptionAutoCompress() override;
void emitDirectiveOptionNoAutoCompress() override;
void emitDirectiveOptionRelax() override;
void emitDirectiveOptionNoRelax() override;
void emitDirectiveVariantCC(MCSymbol &Symbol) override;
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void RISCVTargetStreamer::emitDirectiveOptionPIC() {}
void RISCVTargetStreamer::emitDirectiveOptionNoPIC() {}
void RISCVTargetStreamer::emitDirectiveOptionRVC() {}
void RISCVTargetStreamer::emitDirectiveOptionNoRVC() {}
void RISCVTargetStreamer::emitDirectiveOptionAutoCompress() {}
void RISCVTargetStreamer::emitDirectiveOptionNoAutoCompress() {}
void RISCVTargetStreamer::emitDirectiveOptionRelax() {}
void RISCVTargetStreamer::emitDirectiveOptionNoRelax() {}
void RISCVTargetStreamer::emitDirectiveOptionArch(
Expand Down Expand Up @@ -122,6 +124,14 @@ void RISCVTargetAsmStreamer::emitDirectiveOptionNoRVC() {
OS << "\t.option\tnorvc\n";
}

void RISCVTargetAsmStreamer::emitDirectiveOptionAutoCompress() {
OS << "\t.option\tautocompress\n";
}

void RISCVTargetAsmStreamer::emitDirectiveOptionNoAutoCompress() {
OS << "\t.option\tnoautocompress\n";
}

void RISCVTargetAsmStreamer::emitDirectiveOptionRelax() {
OS << "\t.option\trelax\n";
}
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class RISCVTargetStreamer : public MCTargetStreamer {
virtual void emitDirectiveOptionNoPIC();
virtual void emitDirectiveOptionRVC();
virtual void emitDirectiveOptionNoRVC();
virtual void emitDirectiveOptionAutoCompress();
virtual void emitDirectiveOptionNoAutoCompress();
virtual void emitDirectiveOptionRelax();
virtual void emitDirectiveOptionNoRelax();
virtual void emitDirectiveOptionArch(ArrayRef<RISCVOptionArchArg> Args);
Expand Down Expand Up @@ -84,6 +86,8 @@ class RISCVTargetAsmStreamer : public RISCVTargetStreamer {
void emitDirectiveOptionNoPIC() override;
void emitDirectiveOptionRVC() override;
void emitDirectiveOptionNoRVC() override;
void emitDirectiveOptionAutoCompress() override;
void emitDirectiveOptionNoAutoCompress() override;
void emitDirectiveOptionRelax() override;
void emitDirectiveOptionNoRelax() override;
void emitDirectiveOptionArch(ArrayRef<RISCVOptionArchArg> Args) override;
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ void RISCVAsmPrinter::LowerSTATEPOINT(MCStreamer &OutStreamer, StackMaps &SM,
bool RISCVAsmPrinter::EmitToStreamer(MCStreamer &S, const MCInst &Inst,
const MCSubtargetInfo &SubtargetInfo) {
MCInst CInst;
bool Res = RISCVRVC::compress(CInst, Inst, SubtargetInfo);
bool Res = false;
if (!SubtargetInfo.hasFeature(RISCV::FeatureDisableAsmCompression))
Res = RISCVRVC::compress(CInst, Inst, SubtargetInfo);
if (Res)
++RISCVNumInstrsCompressed;
S.emitInstruction(Res ? CInst : Inst, SubtargetInfo);
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/RISCV/RISCVFeatures.td
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,10 @@ def FeatureRelax
: SubtargetFeature<"relax", "EnableLinkerRelax", "true",
"Enable Linker relaxation.">;

def FeatureDisableAsmCompression
: SubtargetFeature<"disable-asm-compression", "EnableAsmCompression", "false",
"Disable Automatic Assembly Compression.">;

foreach i = {1-31} in
def FeatureReserveX#i :
SubtargetFeature<"reserve-x"#i, "UserReservedRegister[RISCV::X"#i#"]",
Expand Down
70 changes: 70 additions & 0 deletions llvm/test/MC/RISCV/option-autocompress.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# RUN: llvm-mc -triple riscv32 -show-encoding -mattr=+c < %s \
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-ALIAS %s
# RUN: llvm-mc -triple riscv32 -show-encoding -mattr=+c \
# RUN: -M no-aliases < %s | FileCheck -check-prefixes=CHECK,CHECK-INST %s
# RUN: llvm-mc -triple riscv32 -filetype=obj -mattr=+c < %s \
# RUN: | llvm-objdump --triple=riscv32 --mattr=+c --no-print-imm-hex -d - \
# RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-ALIAS %s
# RUN: llvm-mc -triple riscv32 -filetype=obj -mattr=+c < %s \
# RUN: | llvm-objdump --triple=riscv32 --mattr=+c --no-print-imm-hex -d -M no-aliases - \
# RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-INST %s

# RUN: llvm-mc -triple riscv64 -show-encoding -mattr=+c < %s \
# RUN: | FileCheck -check-prefixes=CHECK-ALIAS %s
# RUN: llvm-mc -triple riscv64 -show-encoding -mattr=+c \
# RUN: -M no-aliases < %s | FileCheck -check-prefixes=CHECK-INST %s
# RUN: llvm-mc -triple riscv64 -filetype=obj -mattr=+c < %s \
# RUN: | llvm-objdump --triple=riscv64 --mattr=+c --no-print-imm-hex -d - \
# RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-ALIAS %s
# RUN: llvm-mc -triple riscv64 -filetype=obj -mattr=+c < %s \
# RUN: | llvm-objdump --triple=riscv64 --mattr=+c --no-print-imm-hex -d -M no-aliases - \
# RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-INST %s


# `.option (no)autocompress` enables and disables instruction compression in the
# assembler, without changing the current architecture.
#
# The default is as if `.option autocompress` has been specified, that is, the
# assembler compresses by default.

# CHECK-BYTES: 4108
# CHECK-INST: c.lw a0, 0(a0)
# CHECK-ALIAS: lw a0, 0(a0)
# CHECK: # encoding: [0x08,0x41]
lw a0, 0(a0)

# CHECK-BYTES: 4108
# CHECK-INST: c.lw a0, 0(a0)
# CHECK-ALIAS: lw a0, 0(a0)
# CHECK: # encoding: [0x08,0x41]
c.lw a0, 0(a0)

# CHECK: .option noautocompress
.option noautocompress

# CHECK-BYTES: 00052503
# CHECK-INST: lw a0, 0(a0)
# CHECK-ALIAS: lw a0, 0(a0)
# CHECK: # encoding: [0x03,0x25,0x05,0x00]
lw a0, 0(a0)

# CHECK-BYTES: 4108
# CHECK-INST: c.lw a0, 0(a0)
# CHECK-ALIAS: lw a0, 0(a0)
# CHECK: # encoding: [0x08,0x41]
c.lw a0, 0(a0)

# CHECK: .option autocompress
.option autocompress

# CHECK-BYTES: 4108
# CHECK-INST: c.lw a0, 0(a0)
# CHECK-ALIAS: lw a0, 0(a0)
# CHECK: # encoding: [0x08,0x41]
lw a0, 0(a0)

# CHECK-BYTES: 4108
# CHECK-INST: c.lw a0, 0(a0)
# CHECK-ALIAS: lw a0, 0(a0)
# CHECK: # encoding: [0x08,0x41]
c.lw a0, 0(a0)
Loading