Index: lib/MC/MCAssembler.cpp |
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp |
index b6c3bb20b56eda68153a3c4416628d859c676575..31754b45208a6728fcfca23512884f3534023d4e 100644 |
--- a/lib/MC/MCAssembler.cpp |
+++ b/lib/MC/MCAssembler.cpp |
@@ -493,50 +493,22 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, |
llvm_unreachable("invalid fragment kind"); |
} |
-void MCAsmLayout::LayoutFragment(MCFragment *F) { |
- MCFragment *Prev = F->getPrevNode(); |
- |
- // We should never try to recompute something which is up-to-date. |
- assert(!isFragmentUpToDate(F) && "Attempt to recompute up-to-date fragment!"); |
- // We should never try to compute the fragment layout if it's predecessor |
- // isn't up-to-date. |
- assert((!Prev || isFragmentUpToDate(Prev)) && |
- "Attempt to compute fragment before it's predecessor!"); |
- |
- ++stats::FragmentLayouts; |
- |
- // Compute fragment offset and size. |
- uint64_t Offset = 0; |
- if (Prev) |
- Offset += Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev); |
- // @LOCALMOD-BEGIN |
- F->BundlePadding = getAssembler().ComputeBundlePadding(*this, F, Offset); |
- Offset += F->BundlePadding; |
- // @LOCALMOD-END |
- F->Offset = Offset; |
- LastValidFragment[F->getParent()] = F; |
-} |
- |
// @LOCALMOD-BEGIN |
+namespace { |
// Returns number of bytes of padding needed to align to bundle start. |
-static uint64_t AddressToBundlePadding(uint64_t Address, uint64_t BundleMask) { |
+uint64_t AddressToBundlePadding(uint64_t Address, uint64_t BundleMask) { |
eliben
2012/12/05 00:01:34
Why was static removed?
sehr
2012/12/05 00:11:05
Added back, per the coding conventions.
|
return (~Address + 1) & BundleMask; |
} |
-uint64_t MCAssembler::getBundleSize() const { |
- return getBackend().getBundleSize(); |
-} |
- |
-uint64_t MCAssembler::getBundleMask() const { |
- uint64_t BundleSize = getBundleSize(); |
- uint64_t BundleMask = BundleSize - 1; |
- assert(BundleSize != 0); |
- assert((BundleSize & BundleMask) == 0 && |
+uint64_t ComputeNaClAlignMask(uint64_t NaClAlignSize) { |
eliben
2012/12/05 00:01:34
static?
eliben
2012/12/05 00:01:34
why the change s/bundle/nacl/ here? Would we not w
sehr
2012/12/05 00:11:05
Done.
sehr
2012/12/05 00:11:05
Reverted, per your suggestion.
|
+ uint64_t NaClAlignMask = NaClAlignSize - 1; |
+ assert(NaClAlignSize != 0); |
+ assert((NaClAlignSize & NaClAlignMask) == 0 && |
"Bundle size must be a power of 2!"); |
- return BundleMask; |
+ return NaClAlignMask; |
} |
-static unsigned ComputeGroupSize(MCFragment *F) { |
+unsigned ComputeGroupSize(MCFragment *F) { |
if (!F->isBundleGroupStart()) { |
return 0; |
} |
@@ -570,14 +542,15 @@ static unsigned ComputeGroupSize(MCFragment *F) { |
return GroupSize; |
} |
-uint8_t MCAssembler::ComputeBundlePadding(const MCAsmLayout &Layout, |
- MCFragment *F, |
- uint64_t FragmentOffset) const { |
+uint8_t ComputeBundlePadding(const MCAssembler &Asm, |
+ const MCAsmLayout &Layout, |
+ MCFragment *F, |
+ uint64_t FragmentOffset) { |
if (!F->getParent()->isBundlingEnabled()) |
return 0; |
- uint64_t BundleSize = getBundleSize(); |
- uint64_t BundleMask = getBundleMask(); |
+ uint64_t BundleSize = Asm.getBackend().getBundleSize(); |
+ uint64_t BundleMask = ComputeNaClAlignMask(BundleSize); |
unsigned GroupSize = ComputeGroupSize(F); |
if (GroupSize > BundleSize) { |
@@ -603,20 +576,15 @@ uint8_t MCAssembler::ComputeBundlePadding(const MCAsmLayout &Layout, |
} |
return Padding; |
} |
-// @LOCALMOD-END |
- |
- |
- |
-// @LOCALMOD-BEGIN |
// Write out BundlePadding bytes in NOPs, being careful not to cross a bundle |
// boundary. |
-static void WriteBundlePadding(const MCAssembler &Asm, |
- const MCAsmLayout &Layout, |
- uint64_t Offset, uint64_t TotalPadding, |
- MCObjectWriter *OW) { |
- uint64_t BundleSize = Asm.getBundleSize(); |
- uint64_t BundleMask = Asm.getBundleMask(); |
+void WriteBundlePadding(const MCAssembler &Asm, |
+ const MCAsmLayout &Layout, |
+ uint64_t Offset, uint64_t TotalPadding, |
+ MCObjectWriter *OW) { |
+ uint64_t BundleSize = Asm.getBackend().getBundleSize(); |
+ uint64_t BundleMask = ComputeNaClAlignMask(BundleSize); |
uint64_t PaddingLeft = TotalPadding; |
uint64_t StartPos = Offset; |
@@ -634,8 +602,35 @@ static void WriteBundlePadding(const MCAssembler &Asm, |
FirstWrite = false; |
} |
} |
+ |
+} // namespace |
// @LOCALMOD-END |
+void MCAsmLayout::LayoutFragment(MCFragment *F) { |
+ MCFragment *Prev = F->getPrevNode(); |
+ |
+ // We should never try to recompute something which is up-to-date. |
+ assert(!isFragmentUpToDate(F) && "Attempt to recompute up-to-date fragment!"); |
+ // We should never try to compute the fragment layout if it's predecessor |
+ // isn't up-to-date. |
+ assert((!Prev || isFragmentUpToDate(Prev)) && |
+ "Attempt to compute fragment before it's predecessor!"); |
+ |
+ ++stats::FragmentLayouts; |
+ |
+ // Compute fragment offset and size. |
+ uint64_t Offset = 0; |
+ if (Prev) |
+ Offset += Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev); |
+ // @LOCALMOD-BEGIN |
+ F->BundlePadding = ComputeBundlePadding(getAssembler(), *this, F, Offset); |
+ Offset += F->BundlePadding; |
+ // @LOCALMOD-END |
+ F->Offset = Offset; |
+ LastValidFragment[F->getParent()] = F; |
+} |
+ |
+ |
/// WriteFragmentData - Write the \p F data to the output file. |
static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout, |
const MCFragment &F) { |
@@ -677,7 +672,7 @@ static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout, |
// If we are aligning with nops, ask that target to emit the right data. |
if (AF.hasEmitNops()) { |
// @LOCALMOD-BEGIN |
- if (Asm.getBundleSize()) { |
+ if (Asm.getBackend().getBundleSize()) { |
WriteBundlePadding(Asm, Layout, |
Layout.getFragmentOffset(&F), |
FragmentSize, |