[llvm] r203677 - Try harder to evaluate expressions when printing assembly.
Rafael Espindola
rafael.espindola at gmail.com
Wed Mar 12 09:55:59 PDT 2014
Author: rafael
Date: Wed Mar 12 11:55:59 2014
New Revision: 203677
URL: http://llvm.org/viewvc/llvm-project?rev=203677&view=rev
Log:
Try harder to evaluate expressions when printing assembly.
When printing assembly we don't have a Layout object, but we can still
try to fold some constants.
Testcase by Ulrich Weigand.
Modified:
llvm/trunk/include/llvm/MC/MCExpr.h
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp
llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
llvm/trunk/test/MC/PowerPC/ppc64-fixups.s
Modified: llvm/trunk/include/llvm/MC/MCExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCExpr.h?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCExpr.h (original)
+++ llvm/trunk/include/llvm/MC/MCExpr.h Wed Mar 12 11:55:59 2014
@@ -91,7 +91,7 @@ public:
/// @param Res - The relocatable value, if evaluation succeeds.
/// @param Layout - The assembler layout object to use for evaluating values.
/// @result - True on success.
- bool EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout &Layout) const;
+ bool EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout) const;
/// FindAssociatedSection - Find the "associated section" for this expression,
/// which is currently defined as the absolute section for constants, or
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Wed Mar 12 11:55:59 2014
@@ -122,7 +122,7 @@ uint64_t MCAsmLayout::getSymbolOffset(co
// If this is a variable, then recursively evaluate now.
if (S.isVariable()) {
MCValue Target;
- if (!S.getVariableValue()->EvaluateAsRelocatable(Target, *this))
+ if (!S.getVariableValue()->EvaluateAsRelocatable(Target, this))
report_fatal_error("unable to evaluate offset for variable '" +
S.getName() + "'");
@@ -357,7 +357,7 @@ bool MCAssembler::evaluateFixup(const MC
MCValue &Target, uint64_t &Value) const {
++stats::evaluateFixup;
- if (!Fixup.getValue()->EvaluateAsRelocatable(Target, Layout))
+ if (!Fixup.getValue()->EvaluateAsRelocatable(Target, &Layout))
getContext().FatalError(Fixup.getLoc(), "expected relocatable expression");
bool IsPCRel = Backend.getFixupKindInfo(
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Wed Mar 12 11:55:59 2014
@@ -607,9 +607,9 @@ static bool EvaluateSymbolicAdd(const MC
}
bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
- const MCAsmLayout &Layout) const {
- return EvaluateAsRelocatableImpl(Res, &Layout.getAssembler(), &Layout,
- 0, false);
+ const MCAsmLayout *Layout) const {
+ MCAssembler *Assembler = Layout ? &Layout->getAssembler() : 0;
+ return EvaluateAsRelocatableImpl(Res, Assembler, Layout, 0, false);
}
bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Wed Mar 12 11:55:59 2014
@@ -82,7 +82,7 @@ uint64_t MachObjectWriter::getSymbolAddr
MCValue Target;
- if (!S.getVariableValue()->EvaluateAsRelocatable(Target, Layout))
+ if (!S.getVariableValue()->EvaluateAsRelocatable(Target, &Layout))
report_fatal_error("unable to evaluate offset for variable '" +
S.getName() + "'");
@@ -631,7 +631,7 @@ void MachObjectWriter::markAbsoluteVaria
// and neither symbol is external, mark the variable as absolute.
const MCExpr *Expr = SD.getSymbol().getVariableValue();
MCValue Value;
- if (Expr->EvaluateAsRelocatable(Value, Layout)) {
+ if (Expr->EvaluateAsRelocatable(Value, &Layout)) {
if (Value.getSymA() && Value.getSymB())
const_cast<MCSymbol*>(&SD.getSymbol())->setAbsolute();
}
Modified: llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp Wed Mar 12 11:55:59 2014
@@ -79,7 +79,7 @@ void AArch64MCExpr::PrintImpl(raw_ostrea
bool
AArch64MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const {
- return getSubExpr()->EvaluateAsRelocatable(Res, *Layout);
+ return getSubExpr()->EvaluateAsRelocatable(Res, Layout);
}
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp Wed Mar 12 11:55:59 2014
@@ -36,9 +36,7 @@ void MipsMCExpr::PrintImpl(raw_ostream &
bool
MipsMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const {
- if (!Layout)
- return false;
- return getSubExpr()->EvaluateAsRelocatable(Res, *Layout);
+ return getSubExpr()->EvaluateAsRelocatable(Res, Layout);
}
// FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
Modified: llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp Wed Mar 12 11:55:59 2014
@@ -54,7 +54,7 @@ PPCMCExpr::EvaluateAsRelocatableImpl(MCV
const MCAsmLayout *Layout) const {
MCValue Value;
- if (!Layout || !getSubExpr()->EvaluateAsRelocatable(Value, *Layout))
+ if (!getSubExpr()->EvaluateAsRelocatable(Value, Layout))
return false;
if (Value.isAbsolute()) {
@@ -86,6 +86,9 @@ PPCMCExpr::EvaluateAsRelocatableImpl(MCV
}
Res = MCValue::get(Result);
} else {
+ if (!Layout)
+ return false;
+
MCContext &Context = Layout->getAssembler().getContext();
const MCSymbolRefExpr *Sym = Value.getSymA();
MCSymbolRefExpr::VariantKind Modifier = Sym->getKind();
Modified: llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp Wed Mar 12 11:55:59 2014
@@ -160,9 +160,7 @@ Sparc::Fixups SparcMCExpr::getFixupKind(
bool
SparcMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const {
- if (!Layout)
- return false;
- return getSubExpr()->EvaluateAsRelocatable(Res, *Layout);
+ return getSubExpr()->EvaluateAsRelocatable(Res, Layout);
}
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
Modified: llvm/trunk/test/MC/PowerPC/ppc64-fixups.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/PowerPC/ppc64-fixups.s?rev=203677&r1=203676&r2=203677&view=diff
==============================================================================
--- llvm/trunk/test/MC/PowerPC/ppc64-fixups.s (original)
+++ llvm/trunk/test/MC/PowerPC/ppc64-fixups.s Wed Mar 12 11:55:59 2014
@@ -423,6 +423,14 @@ base:
# CHECK-REL: 0x{{[0-9A-F]*[048C]}} R_PPC64_TLS target 0x0
add 3, 4, target at tls
+# Verify that fixups on constants are resolved at assemble time
+
+# CHECK: ori 1, 2, 65535 # encoding: [0x60,0x41,0xff,0xff]
+ ori 1, 2, 131071 at l
+# CHECK: ori 1, 2, 1 # encoding: [0x60,0x41,0x00,0x01]
+ ori 1, 2, 131071 at h
+# CHECK: ori 1, 2, 2 # encoding: [0x60,0x41,0x00,0x02]
+ ori 1, 2, 131071 at ha
# Data relocs
# llvm-mc does not show any "encoding" string for data, so we just check the relocs
@@ -442,7 +450,3 @@ base:
# CHECK-REL: 0x{{[0-9A-F]*[08]}} R_PPC64_DTPREL64 target 0x0
.quad target at dtprel
-# Constant fixup
- ori 1, 2, 131071 at l
-# CHECK: ori 1, 2, 131071 at l # encoding: [0x60,0x41,A,A]
-# CHECK-NEXT: # fixup A - offset: 2, value: 131071 at l, kind: fixup_ppc_half16
More information about the llvm-commits
mailing list