[llvm-commits] [llvm] r122138 - in /llvm/trunk: include/llvm/MC/MCExpr.h lib/MC/MCExpr.cpp lib/MC/MCObjectStreamer.cpp
Rafael Espindola
rafael.espindola at gmail.com
Fri Dec 17 19:57:21 PST 2010
Author: rafael
Date: Fri Dec 17 21:57:21 2010
New Revision: 122138
URL: http://llvm.org/viewvc/llvm-project?rev=122138&view=rev
Log:
Revert 122011, 122012, 122013, 122023 adding back an important optimization.
I added a note, but suggestions on how to add a test are really welcome.
Modified:
llvm/trunk/include/llvm/MC/MCExpr.h
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/lib/MC/MCObjectStreamer.cpp
Modified: llvm/trunk/include/llvm/MC/MCExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCExpr.h?rev=122138&r1=122137&r2=122138&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCExpr.h (original)
+++ llvm/trunk/include/llvm/MC/MCExpr.h Fri Dec 17 21:57:21 2010
@@ -44,12 +44,14 @@
MCExpr(const MCExpr&); // DO NOT IMPLEMENT
void operator=(const MCExpr&); // DO NOT IMPLEMENT
- bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout,
+ bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
+ const MCAsmLayout *Layout,
const SectionAddrMap *Addrs) const;
protected:
explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
- bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
+ bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
+ const MCAsmLayout *Layout,
const SectionAddrMap *Addrs,
bool InSet) const;
public:
@@ -76,16 +78,11 @@
/// values. If not given, then only non-symbolic expressions will be
/// evaluated.
/// @result - True on success.
- bool EvaluateAsAbsolute(int64_t &Res) const {
- return EvaluateAsAbsolute(Res, 0, 0);
- }
- bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const{
- return EvaluateAsAbsolute(Res, &Layout, 0);
- }
+ bool EvaluateAsAbsolute(int64_t &Res) const;
+ bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
+ bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout,
- const SectionAddrMap &Addrs) const {
- return EvaluateAsAbsolute(Res, &Layout, &Addrs);
- }
+ const SectionAddrMap &Addrs) const;
/// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
/// value, i.e. an expression of the fixed form (a - b + constant).
@@ -93,10 +90,7 @@
/// @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 = 0) const {
- return EvaluateAsRelocatableImpl(Res, Layout, 0, false);
- }
+ bool EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout = 0) const;
/// @}
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=122138&r1=122137&r2=122138&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Fri Dec 17 21:57:21 2010
@@ -237,7 +237,27 @@
/* *** */
-bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout,
+bool MCExpr::EvaluateAsAbsolute(int64_t &Res) const {
+ return EvaluateAsAbsolute(Res, 0, 0, 0);
+}
+
+bool MCExpr::EvaluateAsAbsolute(int64_t &Res,
+ const MCAsmLayout &Layout) const {
+ return EvaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, 0);
+}
+
+bool MCExpr::EvaluateAsAbsolute(int64_t &Res,
+ const MCAsmLayout &Layout,
+ const SectionAddrMap &Addrs) const {
+ return EvaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs);
+}
+
+bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
+ return EvaluateAsAbsolute(Res, &Asm, 0, 0);
+}
+
+bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
+ const MCAsmLayout *Layout,
const SectionAddrMap *Addrs) const {
MCValue Value;
@@ -247,8 +267,7 @@
return true;
}
- // FIXME: This use of Addrs is wrong, right?
- if (!EvaluateAsRelocatableImpl(Value, Layout, Addrs, /*InSet=*/Addrs) ||
+ if (!EvaluateAsRelocatableImpl(Value, Asm, Layout, Addrs, Addrs) ||
!Value.isAbsolute()) {
// EvaluateAsAbsolute is defined to return the "current value" of
// the expression if we are given a Layout object, even in cases
@@ -304,7 +323,13 @@
///
/// \returns True on success, false if the result is not representable in an
/// MCValue.
-static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout,
+
+/// NOTE: It is really important to have both the Asm and Layout arguments.
+/// They might look redundant, but this function can be used before layout
+/// is done (see the object streamer for example) and having the Asm argument
+/// lets us avoid relocations.
+static bool EvaluateSymbolicAdd(const MCAssembler *Asm,
+ const MCAsmLayout *Layout,
const SectionAddrMap *Addrs,
bool InSet,
const MCValue &LHS,const MCSymbolRefExpr *RHS_A,
@@ -353,14 +378,17 @@
// Absolutize symbol differences between defined symbols when we have a
// layout object and the target requests it.
- if (Layout && A && B) {
- const MCAssembler &Asm = Layout->getAssembler();
+
+ assert((!Layout || Asm) &&
+ "Must have an assembler object if layout is given!");
+
+ if (Asm && A && B) {
const MCSymbol &SA = A->getSymbol();
const MCSymbol &SB = B->getSymbol();
- const MCObjectFormat &F = Asm.getBackend().getObjectFormat();
+ const MCObjectFormat &F = Asm->getBackend().getObjectFormat();
if (SA.isDefined() && SB.isDefined() && F.isAbsolute(InSet, SA, SB)) {
- MCSymbolData &AD = Asm.getSymbolData(A->getSymbol());
- MCSymbolData &BD = Asm.getSymbolData(B->getSymbol());
+ MCSymbolData &AD = Asm->getSymbolData(A->getSymbol());
+ MCSymbolData &BD = Asm->getSymbolData(B->getSymbol());
if (AD.getFragment() == BD.getFragment()) {
Res = MCValue::get(+ AD.getOffset()
@@ -391,7 +419,17 @@
return true;
}
+bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
+ const MCAsmLayout *Layout) const {
+ if (Layout)
+ return EvaluateAsRelocatableImpl(Res, &Layout->getAssembler(), Layout,
+ 0, false);
+ else
+ return EvaluateAsRelocatableImpl(Res, 0, 0, 0, false);
+}
+
bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
+ const MCAssembler *Asm,
const MCAsmLayout *Layout,
const SectionAddrMap *Addrs,
bool InSet) const {
@@ -411,8 +449,10 @@
// Evaluate recursively if this is a variable.
if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None) {
- bool Ret = Sym.getVariableValue()->EvaluateAsRelocatableImpl(Res, Layout,
- Addrs, true);
+ bool Ret = Sym.getVariableValue()->EvaluateAsRelocatableImpl(Res, Asm,
+ Layout,
+ Addrs,
+ true);
// If we failed to simplify this to a constant, let the target
// handle it.
if (Ret && !Res.getSymA() && !Res.getSymB())
@@ -427,7 +467,7 @@
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
MCValue Value;
- if (!AUE->getSubExpr()->EvaluateAsRelocatableImpl(Value, Layout,
+ if (!AUE->getSubExpr()->EvaluateAsRelocatableImpl(Value, Asm, Layout,
Addrs, InSet))
return false;
@@ -461,9 +501,9 @@
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
MCValue LHSValue, RHSValue;
- if (!ABE->getLHS()->EvaluateAsRelocatableImpl(LHSValue, Layout,
+ if (!ABE->getLHS()->EvaluateAsRelocatableImpl(LHSValue, Asm, Layout,
Addrs, InSet) ||
- !ABE->getRHS()->EvaluateAsRelocatableImpl(RHSValue, Layout,
+ !ABE->getRHS()->EvaluateAsRelocatableImpl(RHSValue, Asm, Layout,
Addrs, InSet))
return false;
@@ -475,13 +515,13 @@
return false;
case MCBinaryExpr::Sub:
// Negate RHS and add.
- return EvaluateSymbolicAdd(Layout, Addrs, InSet, LHSValue,
+ return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
RHSValue.getSymB(), RHSValue.getSymA(),
-RHSValue.getConstant(),
Res);
case MCBinaryExpr::Add:
- return EvaluateSymbolicAdd(Layout, Addrs, InSet, LHSValue,
+ return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
RHSValue.getSymA(), RHSValue.getSymB(),
RHSValue.getConstant(),
Res);
Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=122138&r1=122137&r2=122138&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Fri Dec 17 21:57:21 2010
@@ -85,7 +85,7 @@
// Avoid fixups when possible.
int64_t AbsValue;
- if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
+ if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue, getAssembler())) {
EmitIntValue(AbsValue, Size, AddrSpace);
return;
}
@@ -116,7 +116,7 @@
void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value,
unsigned AddrSpace) {
int64_t IntValue;
- if (Value->EvaluateAsAbsolute(IntValue)) {
+ if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) {
EmitULEB128IntValue(IntValue, AddrSpace);
return;
}
@@ -126,7 +126,7 @@
void MCObjectStreamer::EmitSLEB128Value(const MCExpr *Value,
unsigned AddrSpace) {
int64_t IntValue;
- if (Value->EvaluateAsAbsolute(IntValue)) {
+ if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) {
EmitSLEB128IntValue(IntValue, AddrSpace);
return;
}
@@ -206,7 +206,7 @@
MCBinaryExpr::Create(MCBinaryExpr::Sub, LabelRef, LastLabelRef,
getContext());
int64_t Res;
- if (AddrDelta->EvaluateAsAbsolute(Res)) {
+ if (AddrDelta->EvaluateAsAbsolute(Res, getAssembler())) {
MCDwarfLineAddr::Emit(this, LineDelta, Res);
return;
}
More information about the llvm-commits
mailing list