1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

Add a helper to MCExpr for when an expression is know to be absolute.

llvm-svn: 215713
This commit is contained in:
Rafael Espindola 2014-08-15 14:20:32 +00:00
parent 80b0c0c71c
commit 272bca16f6
4 changed files with 30 additions and 22 deletions

View File

@ -50,6 +50,11 @@ private:
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const SectionAddrMap *Addrs) const;
bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const SectionAddrMap *Addrs, bool InSet) const;
protected:
explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
@ -89,6 +94,8 @@ public:
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
int64_t evaluateKnownAbsolute(const MCAsmLayout &Layout) const;
/// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
/// value, i.e. an expression of the fixed form (a - b + constant).
///

View File

@ -994,11 +994,8 @@ bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
}
bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
int64_t Value = 0;
uint64_t OldSize = LF.getContents().size();
bool IsAbs = LF.getValue().EvaluateAsAbsolute(Value, Layout);
(void)IsAbs;
assert(IsAbs);
int64_t Value = LF.getValue().evaluateKnownAbsolute(Layout);
SmallString<8> &Data = LF.getContents();
Data.clear();
raw_svector_ostream OSE(Data);
@ -1013,11 +1010,8 @@ bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout,
MCDwarfLineAddrFragment &DF) {
MCContext &Context = Layout.getAssembler().getContext();
int64_t AddrDelta = 0;
uint64_t OldSize = DF.getContents().size();
bool IsAbs = DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout);
(void)IsAbs;
assert(IsAbs);
int64_t AddrDelta = DF.getAddrDelta().evaluateKnownAbsolute(Layout);
int64_t LineDelta;
LineDelta = DF.getLineDelta();
SmallString<8> &Data = DF.getContents();
@ -1031,11 +1025,8 @@ bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout,
bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
MCDwarfCallFrameFragment &DF) {
MCContext &Context = Layout.getAssembler().getContext();
int64_t AddrDelta = 0;
uint64_t OldSize = DF.getContents().size();
bool IsAbs = DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout);
(void)IsAbs;
assert(IsAbs);
int64_t AddrDelta = DF.getAddrDelta().evaluateKnownAbsolute(Layout);
SmallString<8> &Data = DF.getContents();
Data.clear();
raw_svector_ostream OSE(Data);

View File

@ -467,9 +467,27 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
return EvaluateAsAbsolute(Res, &Asm, nullptr, nullptr);
}
int64_t MCExpr::evaluateKnownAbsolute(const MCAsmLayout &Layout) const {
int64_t Res;
bool Abs =
evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, true);
(void)Abs;
assert(Abs && "Not actually absolute");
return Res;
}
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const SectionAddrMap *Addrs) const {
// FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us
// absolutize differences across sections and that is what the MachO writer
// uses Addrs for.
return evaluateAsAbsolute(Res, Asm, Layout, Addrs, Addrs);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const SectionAddrMap *Addrs, bool InSet) const {
MCValue Value;
// Fast path constants.
@ -478,12 +496,8 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
return true;
}
// FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us
// absolutize differences across sections and that is what the MachO writer
// uses Addrs for.
bool IsRelocatable =
EvaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs,
/*InSet*/ Addrs, /*ForceVarExpansion*/ false);
bool IsRelocatable = EvaluateAsRelocatableImpl(
Value, Asm, Layout, nullptr, Addrs, InSet, /*ForceVarExpansion*/ false);
// Record the current value.
Res = Value.getConstant();

View File

@ -144,7 +144,6 @@ void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value) {
EmitULEB128IntValue(IntValue);
return;
}
Value = ForceExpAbs(Value);
insert(new MCLEBFragment(*Value, false));
}
@ -154,7 +153,6 @@ void MCObjectStreamer::EmitSLEB128Value(const MCExpr *Value) {
EmitSLEB128IntValue(IntValue);
return;
}
Value = ForceExpAbs(Value);
insert(new MCLEBFragment(*Value, true));
}
@ -280,7 +278,6 @@ void MCObjectStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
MCDwarfLineAddr::Emit(this, LineDelta, Res);
return;
}
AddrDelta = ForceExpAbs(AddrDelta);
insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
}
@ -292,7 +289,6 @@ void MCObjectStreamer::EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
MCDwarfFrameEmitter::EmitAdvanceLoc(*this, Res);
return;
}
AddrDelta = ForceExpAbs(AddrDelta);
insert(new MCDwarfCallFrameFragment(*AddrDelta));
}