/// CurrentSection - The current section we are emitting to. This is
/// controlled and used by the SwitchSection method.
std::string CurrentSection;
+
+ /// IsInTextSection - True if the current section we are emitting to is a
+ /// text section.
+ bool IsInTextSection;
protected:
AsmPrinter(std::ostream &o, TargetMachine &TM, const TargetAsmInfo *T);
/// an explicit alignment requested, it will unconditionally override the
/// alignment request. However, if ForcedAlignBits is specified, this value
/// has final say: the ultimate alignment will be the max of ForcedAlignBits
- /// and the alignment computed with NumBits and the global. If UseFillExpr
- /// is true, it also emits an optional second value FillValue which the
- /// assembler uses to fill gaps to match alignment.
+ /// and the alignment computed with NumBits and the global
///
/// The algorithm is:
/// Align = NumBits;
/// Align = std::max(Align, ForcedAlignBits);
///
void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0,
- unsigned ForcedAlignBits = 0, bool UseFillExpr = false,
- unsigned FillValue = 0) const;
+ unsigned ForcedAlignBits = 0) const;
/// printLabel - This method prints a local label used by debug and
/// exception handling tables.
/// printBasicBlockLabel - This method prints the label for the specified
/// MachineBasicBlock
virtual void printBasicBlockLabel(const MachineBasicBlock *MBB,
+ bool printAlign = false,
bool printColon = false,
bool printComment = true) const;
/// LiveIns - Keep track of the physical registers that are livein of
/// the basicblock.
std::vector<unsigned> LiveIns;
+
+ /// Alignment - Alignment of the basic block. Zero if the basic block does
+ /// not need to be aligned.
+ unsigned Alignment;
/// IsLandingPad - Indicate that this basic block is entered via an
/// exception handler.
public:
explicit MachineBasicBlock(const BasicBlock *bb = 0)
- : Prev(0), Next(0), BB(bb), Number(-1), xParent(0), IsLandingPad(false) {
+ : Prev(0), Next(0), BB(bb), Number(-1), xParent(0),
+ Alignment(0), IsLandingPad(false) {
Insts.parent = this;
}
const_livein_iterator livein_end() const { return LiveIns.end(); }
bool livein_empty() const { return LiveIns.empty(); }
+ /// getAlignment - Return alignment of the basic block.
+ ///
+ unsigned getAlignment() const { return Alignment; }
+
+ /// setAlignment - Set alignment of the basic block.
+ ///
+ void setAlignment(unsigned Align) { Alignment = Align; }
+
/// isLandingPad - Returns true if the block is a landing pad. That is
/// this basic block is entered via an exception handler.
bool isLandingPad() const { return IsLandingPad; }
}
/// getObjectAlignment - Return the alignment of the specified stack object...
- int getObjectAlignment(int ObjectIdx) const {
+ unsigned getObjectAlignment(int ObjectIdx) const {
assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
"Invalid Object Idx!");
return Objects[ObjectIdx+NumFixedObjects].Alignment;
/// IfConverter Pass - This pass performs machine code if conversion.
FunctionPass *createIfConverterPass();
+ /// LoopAligner Pass - This pass aligns loop headers to target specific
+ /// alignment boundary.
+ FunctionPass *createLoopAlignerPass();
+
/// DebugLabelFoldingPass - This pass prunes out redundant debug labels. This
/// allows a debug emitter to determine if the range of two labels is empty,
/// by seeing if the labels map to the same reduced label.
/// boundary.
bool AlignmentIsInBytes; // Defaults to true
+ /// TextAlignFillValue - If non-zero, this is used to fill the executable
+ /// space created as the result of a alignment directive.
+ unsigned TextAlignFillValue;
+
//===--- Section Switching Directives ---------------------------------===//
/// SwitchToSectionDirective - This is the directive used when we want to
bool getAlignmentIsInBytes() const {
return AlignmentIsInBytes;
}
+ unsigned getTextAlignFillValue() const {
+ return TextAlignFillValue;
+ }
const char *getSwitchToSectionDirective() const {
return SwitchToSectionDirective;
}
/// getIfCvtBlockLimit - returns the target specific if-conversion block size
/// limit. Any block whose size is greater should not be predicated.
- virtual unsigned getIfCvtBlockSizeLimit() const {
+ unsigned getIfCvtBlockSizeLimit() const {
return IfCvtBlockSizeLimit;
}
/// getIfCvtDupBlockLimit - returns the target specific size limit for a
/// block to be considered for duplication. Any block whose size is greater
/// should not be duplicated to facilitate its predication.
- virtual unsigned getIfCvtDupBlockSizeLimit() const {
+ unsigned getIfCvtDupBlockSizeLimit() const {
return IfCvtDupBlockSizeLimit;
}
+ /// getPrefLoopAlignment - return the preferred loop alignment.
+ ///
+ unsigned getPrefLoopAlignment() const {
+ return PrefLoopAlignment;
+ }
+
/// getPreIndexedAddressParts - returns true by value, base pointer and
/// offset pointer and addressing mode by reference if the node's address
/// can be legally represented as pre-indexed load / store address.
/// jumptable.
virtual SDOperand getPICJumpTableRelocBase(SDOperand Table,
SelectionDAG &DAG) const;
-
+
//===--------------------------------------------------------------------===//
// TargetLowering Optimization Methods
//
void setIfCvtDupBlockSizeLimit(unsigned Limit) {
IfCvtDupBlockSizeLimit = Limit;
}
+
+ /// setPrefLoopAlignment - Set the target's preferred loop alignment. Default
+ /// alignment is zero, it means the target does not care about loop alignment.
+ void setPrefLoopAlignment(unsigned Align) {
+ PrefLoopAlignment = Align;
+ }
public:
/// duplicated during if-conversion.
unsigned IfCvtDupBlockSizeLimit;
+ /// PrefLoopAlignment - The perferred loop alignment.
+ ///
+ unsigned PrefLoopAlignment;
+
/// StackPointerRegisterToSaveRestore - If set to a physical register, this
/// specifies the register that llvm.savestack/llvm.restorestack should save
/// and restore.
char AsmPrinter::ID = 0;
AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
const TargetAsmInfo *T)
- : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T)
+ : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T),
+ IsInTextSection(false)
{}
std::string AsmPrinter::getSectionForFunction(const Function &F) const {
if (!CurrentSection.empty())
O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
+
+ IsInTextSection = true;
}
/// SwitchToDataSection - Switch to the specified data section of the executable
if (!CurrentSection.empty())
O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
+
+ IsInTextSection = false;
}
O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
<< '_' << uid << "_set_" << MBB->getNumber();
} else {
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
// If the arch uses custom Jump Table directives, don't calc relative to
// JT
if (!HadJTEntryDirective)
<< getFunctionNumber() << '_' << uid;
}
} else {
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
}
}
// Align = std::max(Align, ForcedAlignBits);
//
void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
- unsigned ForcedAlignBits, bool UseFillExpr,
- unsigned FillValue) const {
+ unsigned ForcedAlignBits) const {
if (GV && GV->getAlignment())
NumBits = Log2_32(GV->getAlignment());
NumBits = std::max(NumBits, ForcedAlignBits);
if (NumBits == 0) return; // No need to emit alignment.
if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
O << TAI->getAlignDirective() << NumBits;
+
+ unsigned FillValue = TAI->getTextAlignFillValue();
+ bool UseFillExpr = IsInTextSection && FillValue;
if (UseFillExpr) O << ",0x" << std::hex << FillValue << std::dec;
O << "\n";
}
if (Modifier[0]=='l') // labels are target independent
printBasicBlockLabel(MI->getOperand(OpNo).getMBB(),
- false, false);
+ false, false, false);
else {
AsmPrinter *AP = const_cast<AsmPrinter*>(this);
if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
/// printBasicBlockLabel - This method prints the label for the specified
/// MachineBasicBlock
void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
+ bool printAlign,
bool printColon,
bool printComment) const {
+ if (printAlign) {
+ unsigned Align = MBB->getAlignment();
+ if (Align)
+ EmitAlignment(Log2_32(Align));
+ }
+
O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << "_"
<< MBB->getNumber();
if (printColon)
O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << uid << '\n';
}
O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
<< getFunctionNumber() << '_' << uid << '_' << uid2
<< "_set_" << MBB->getNumber() << ',';
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << uid << '_' << uid2 << '\n';
}
cl::desc("Max number of predecessors to consider tail merging"),
cl::init(100), cl::Hidden);
- struct BranchFolder : public MachineFunctionPass {
+ struct VISIBILITY_HIDDEN BranchFolder : public MachineFunctionPass {
static char ID;
explicit BranchFolder(bool defaultEnableTailMerge) :
MachineFunctionPass((intptr_t)&ID) {
STATISTIC(NumDupBBs, "Number of duplicated blocks");
namespace {
- class IfConverter : public MachineFunctionPass {
+ class VISIBILITY_HIDDEN IfConverter : public MachineFunctionPass {
enum IfcvtKind {
ICNotClassfied, // BB data valid, but not classified.
ICSimpleFalse, // Same as ICSimple, but on the false path.
--- /dev/null
+//===-- LoopAligner.cpp - Loop aligner pass. ------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the pass that align loop headers to target specific
+// alignment boundary.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "loopalign"
+#include "llvm/CodeGen/MachineLoopInfo.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/Target/TargetLowering.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Debug.h"
+using namespace llvm;
+
+namespace {
+ class LoopAligner : public MachineFunctionPass {
+ const TargetLowering *TLI;
+
+ public:
+ static char ID;
+ LoopAligner() : MachineFunctionPass((intptr_t)&ID) {}
+
+ virtual bool runOnMachineFunction(MachineFunction &MF);
+ virtual const char *getPassName() const { return "Loop aligner"; }
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.addRequired<MachineLoopInfo>();
+ AU.addPreserved<MachineLoopInfo>();
+ MachineFunctionPass::getAnalysisUsage(AU);
+ }
+ };
+
+ char LoopAligner::ID = 0;
+} // end anonymous namespace
+
+FunctionPass *llvm::createLoopAlignerPass() { return new LoopAligner(); }
+
+bool LoopAligner::runOnMachineFunction(MachineFunction &MF) {
+ const MachineLoopInfo *MLI = &getAnalysis<MachineLoopInfo>();
+
+ if (MLI->begin() == MLI->end())
+ return false; // No loops.
+
+ unsigned Align = MF.getTarget().getTargetLowering()->getPrefLoopAlignment();
+ if (!Align)
+ return false; // Don't care about loop alignment.
+
+ for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
+ MachineBasicBlock *MBB = I;
+ if (MLI->isLoopHeader(MBB))
+ MBB->setAlignment(Align);
+ }
+
+ return true;
+}
if (LBB) OS << LBB->getName() << ": ";
OS << (const void*)this
<< ", LLVM BB @" << (const void*) LBB << ", ID#" << getNumber();
+ if (Alignment) OS << ", Alignment " << Alignment;
if (isLandingPad()) OS << ", EH LANDING PAD";
OS << ":\n";
JumpBufSize = 0;
JumpBufAlignment = 0;
IfCvtBlockSizeLimit = 2;
+ IfCvtDupBlockSizeLimit = 0;
+ PrefLoopAlignment = 0;
InitLibcallNames(LibcallRoutineNames);
InitCmpLibcallCCs(CmpLibcallCCs);
I != E; ++I) {
// Print a label for the basic block.
if (I != MF.begin()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
<< '_' << JTI << '_' << MO2.getImm()
<< "_set_" << MBB->getNumber();
else if (TM.getRelocationModel() == Reloc::PIC_) {
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
// If the arch uses custom Jump Table directives, don't calc relative to JT
if (!TAI->getJumpTableDirective())
O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
<< getFunctionNumber() << '_' << JTI << '_' << MO2.getImm();
} else
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
if (i != e-1)
O << '\n';
}
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
I != E; ++I) {
if (I != MF.begin()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
I != E; ++I) {
// Print a label for the basic block.
if (I != MF.begin()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
I != E; ++I) {
// Print a label for the basic block if there are any predecessors.
if (!I->pred_empty()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
// Print a label for the basic block.
if (I != MF.begin()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
I != E; ++I) {
// Print a label for the basic block.
if (I != MF.begin()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
I != E; ++I) {
// Print a label for the basic block.
if (I != MF.begin()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
I != E; ++I) {
// Print a label for the basic block.
if (I != MF.begin()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::InternalLinkage: // Symbols default to internal.
- if (Subtarget->isTargetDarwin())
- // FIXME: This should be parameterized somewhere.
- EmitAlignment(4, F, 0, true, 0x90);
- else
- EmitAlignment(4, F);
+ EmitAlignment(4, F);
break;
case Function::DLLExportLinkage:
DLLExportedFns.insert(Mang->makeNameProper(F->getName(), ""));
//FALLS THROUGH
case Function::ExternalLinkage:
- if (Subtarget->isTargetDarwin())
- // FIXME: This should be parameterized somewhere.
- EmitAlignment(4, F, 0, true, 0x90);
- else
- EmitAlignment(4, F);
+ EmitAlignment(4, F);
O << "\t.globl\t" << CurrentFnName << "\n";
break;
case Function::LinkOnceLinkage:
case Function::WeakLinkage:
+ EmitAlignment(4, F);
if (Subtarget->isTargetDarwin()) {
- // FIXME: This should be parameterized somewhere.
- EmitAlignment(4, F, 0, true, 0x90);
O << "\t.globl\t" << CurrentFnName << "\n";
O << TAI->getWeakDefDirective() << CurrentFnName << "\n";
} else if (Subtarget->isTargetCygMing()) {
- EmitAlignment(4, F);
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.linkonce discard\n";
} else {
- EmitAlignment(4, F);
O << "\t.weak\t" << CurrentFnName << "\n";
}
break;
I != E; ++I) {
// Print a label for the basic block.
if (!I->pred_empty()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
if (Subtarget->isPICStyleRIPRel())
O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << uid << '\n';
O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
<< '_' << uid << "_set_" << MBB->getNumber();
} else if (Subtarget->isPICStyleGOT()) {
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
O << "@GOTOFF";
} else
assert(0 && "Don't know how to print MBB label for this PIC mode");
} else
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
}
bool X86ATTAsmPrinter::printAsmMRegister(const MachineOperand &MO,
maxStoresPerMemcpy = 16; // For %llvm.memcpy -> sequence of stores
maxStoresPerMemmove = 16; // For %llvm.memmove -> sequence of stores
allowUnalignedMemoryAccesses = true; // x86 supports it!
+ setPrefLoopAlignment(16);
}
/// getMaxByValAlign - Helper for getByValTypeAlignment to determine
I != E; ++I) {
// Print a label for the basic block if there are any predecessors.
if (!I->pred_empty()) {
- printBasicBlockLabel(I, true);
+ printBasicBlockLabel(I, true, true);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
- printBasicBlockLabel(MBB, false, false);
+ printBasicBlockLabel(MBB, false, false, false);
O << '-' << "\"L" << getFunctionNumber() << "$pb\"'\n";
}
switch (Subtarget->TargetType) {
case X86Subtarget::isDarwin:
AlignmentIsInBytes = false;
+ TextAlignFillValue = 0x90;
GlobalPrefix = "_";
if (!Subtarget->is64Bit())
Data64bitsDirective = 0; // we can't emit a 64-bit unit
return true; // -print-machineinstr should print after this.
}
+bool X86TargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
+ if (Fast) return false;
+
+ PM.add(createLoopAlignerPass());
+ return true;
+}
+
bool X86TargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
std::ostream &Out) {
PM.add(createX86CodePrinterPass(Out, *this));
// Set up the pass pipeline.
virtual bool addInstSelector(FunctionPassManager &PM, bool Fast);
virtual bool addPostRegAlloc(FunctionPassManager &PM, bool Fast);
+ virtual bool addPreEmitPass(FunctionPassManager &PM, bool Fast);
virtual bool addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
std::ostream &Out);
virtual bool addCodeEmitter(FunctionPassManager &PM, bool Fast,