[llvm-commits] [llvm] r118080 - in /llvm/trunk: include/llvm/MC/MCAssembler.h lib/MC/MCAssembler.cpp
Rafael Espindola
rafael.espindola at gmail.com
Tue Nov 2 14:38:23 PDT 2010
Author: rafael
Date: Tue Nov 2 16:38:23 2010
New Revision: 118080
URL: http://llvm.org/viewvc/llvm-project?rev=118080&view=rev
Log:
Do relaxations with FT_Org fragments. Fixes the FIXME:
// FIXME: We should compute this sooner, we don't want to recurse here, and
// we would like to be more functional.
In MCAssembler::ComputeFragmentSize.
Modified:
llvm/trunk/include/llvm/MC/MCAssembler.h
llvm/trunk/lib/MC/MCAssembler.cpp
Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=118080&r1=118079&r2=118080&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Tue Nov 2 16:38:23 2010
@@ -319,10 +319,13 @@
/// Value - Value to use for filling bytes.
int8_t Value;
+ /// Size - The current estimate of the size.
+ unsigned Size;
+
public:
MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0)
: MCFragment(FT_Org, SD),
- Offset(&_Offset), Value(_Value) {}
+ Offset(&_Offset), Value(_Value), Size(0) {}
/// @name Accessors
/// @{
@@ -331,6 +334,9 @@
uint8_t getValue() const { return Value; }
+ unsigned getSize() const { return Size; }
+
+ void setSize(unsigned Size_) { Size = Size_; }
/// @}
static bool classof(const MCFragment *F) {
@@ -715,6 +721,9 @@
bool RelaxInstruction(const MCObjectWriter &Writer, MCAsmLayout &Layout,
MCInstFragment &IF);
+ bool RelaxOrg(const MCObjectWriter &Writer, MCAsmLayout &Layout,
+ MCOrgFragment &OF);
+
bool RelaxLEB(const MCObjectWriter &Writer, MCAsmLayout &Layout,
MCLEBFragment &IF);
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=118080&r1=118079&r2=118080&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Tue Nov 2 16:38:23 2010
@@ -337,23 +337,8 @@
return Size;
}
- case MCFragment::FT_Org: {
- const MCOrgFragment &OF = cast<MCOrgFragment>(F);
-
- // FIXME: We should compute this sooner, we don't want to recurse here, and
- // we would like to be more functional.
- int64_t TargetLocation;
- if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, &Layout))
- report_fatal_error("expected assembly-time absolute expression");
-
- // FIXME: We need a way to communicate this error.
- int64_t Offset = TargetLocation - FragmentOffset;
- if (Offset < 0 || Offset >= 0x40000000)
- report_fatal_error("invalid .org offset '" + Twine(TargetLocation) +
- "' (at offset '" + Twine(FragmentOffset) + "')");
-
- return Offset;
- }
+ case MCFragment::FT_Org:
+ return cast<MCOrgFragment>(F).getSize();
case MCFragment::FT_Dwarf: {
const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F);
@@ -841,6 +826,25 @@
return true;
}
+bool MCAssembler::RelaxOrg(const MCObjectWriter &Writer,
+ MCAsmLayout &Layout,
+ MCOrgFragment &OF) {
+ int64_t TargetLocation;
+ if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, &Layout))
+ report_fatal_error("expected assembly-time absolute expression");
+
+ // FIXME: We need a way to communicate this error.
+ uint64_t FragmentOffset = Layout.getFragmentOffset(&OF);
+ int64_t Offset = TargetLocation - FragmentOffset;
+ if (Offset < 0 || Offset >= 0x40000000)
+ report_fatal_error("invalid .org offset '" + Twine(TargetLocation) +
+ "' (at offset '" + Twine(FragmentOffset) + "')");
+
+ unsigned OldSize = OF.getSize();
+ OF.setSize(Offset);
+ return OldSize != OF.getSize();
+}
+
bool MCAssembler::RelaxLEB(const MCObjectWriter &Writer,
MCAsmLayout &Layout,
MCLEBFragment &LF) {
@@ -857,7 +861,6 @@
return OldSize != LF.getSize();
}
-
bool MCAssembler::LayoutOnce(const MCObjectWriter &Writer,
MCAsmLayout &Layout) {
++stats::RelaxationSteps;
@@ -880,6 +883,9 @@
WasRelaxed |= RelaxInstruction(Writer, Layout,
*cast<MCInstFragment>(it2));
break;
+ case MCFragment::FT_Org:
+ WasRelaxed |= RelaxOrg(Writer, Layout, *cast<MCOrgFragment>(it2));
+ break;
case MCFragment::FT_LEB:
WasRelaxed |= RelaxLEB(Writer, Layout, *cast<MCLEBFragment>(it2));
break;
More information about the llvm-commits
mailing list