#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Debug.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetAsmBackend.h"
namespace {
namespace stats {
-STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
-STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
STATISTIC(EmittedFragments, "Number of emitted assembler fragments");
STATISTIC(EvaluateFixup, "Number of evaluated fixups");
+STATISTIC(FragmentLayouts, "Number of fragment layouts");
STATISTIC(ObjectBytes, "Number of emitted object file bytes");
+STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
+STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
+STATISTIC(SectionLayouts, "Number of section layouts");
}
}
MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
MCCodeEmitter &_Emitter, raw_ostream &_OS)
: Context(_Context), Backend(_Backend), Emitter(_Emitter),
- OS(_OS), SubsectionsViaSymbols(false)
+ OS(_OS), RelaxAll(false), SubsectionsViaSymbols(false)
{
}
uint64_t StartAddress) {
bool IsVirtual = getBackend().isVirtualSection(SD.getSection());
+ ++stats::SectionLayouts;
+
// Align this section if necessary by adding padding bytes to the previous
// section. It is safe to adjust this out-of-band, because no symbol or
// fragment is allowed to point past the end of the section at any time.
for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it) {
MCFragment &F = *it;
+ ++stats::FragmentLayouts;
+
uint64_t FragmentOffset = Address - StartAddress;
Layout.setFragmentOffset(&F, FragmentOffset);
bool MCAssembler::FixupNeedsRelaxation(const MCAsmFixup &Fixup,
const MCFragment *DF,
const MCAsmLayout &Layout) const {
+ if (getRelaxAll())
+ return true;
+
// If we cannot resolve the fixup value, it requires relaxation.
MCValue Target;
uint64_t Value;
F.getKind()));
}
- // Update the layout, and remember that we relaxed.
- Layout.UpdateForSlide(IF, SlideAmount);
+ // Update the layout, and remember that we relaxed. If we are relaxing
+ // everything, we can skip this step since nothing will depend on updating
+ // the values.
+ if (!getRelaxAll())
+ Layout.UpdateForSlide(IF, SlideAmount);
WasRelaxed = true;
}
}
CurSectionData(0) {}
~MCMachOStreamer() {}
+ MCAssembler &getAssembler() { return Assembler; }
+
const MCExpr *AddValueSymbols(const MCExpr *Value) {
switch (Value->getKind()) {
case MCExpr::Target: assert(0 && "Can't handle target exprs yet!");
}
MCStreamer *llvm::createMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
- raw_ostream &OS, MCCodeEmitter *CE) {
- return new MCMachOStreamer(Context, TAB, OS, CE);
+ raw_ostream &OS, MCCodeEmitter *CE,
+ bool RelaxAll) {
+ MCMachOStreamer *S = new MCMachOStreamer(Context, TAB, OS, CE);
+ if (RelaxAll)
+ S->getAssembler().setRelaxAll(true);
+ return S;
}
OutputAsmVariant("output-asm-variant",
cl::desc("Syntax variant to use for output printing"));
+static cl::opt<bool>
+RelaxAll("mc-relax-all", cl::desc("Relax all fixups"));
+
enum OutputFileType {
OFT_Null,
OFT_AssemblyFile,
assert(FileType == OFT_ObjectFile && "Invalid file type!");
CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
TAB.reset(TheTarget->createAsmBackend(TripleName));
- Str.reset(createMachOStreamer(Ctx, *TAB, *Out, CE.get()));
+ Str.reset(createMachOStreamer(Ctx, *TAB, *Out, CE.get(), RelaxAll));
}
AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI);