Add a quick and dirty "loop aligner pass". x86 uses it to align its loops to 16-byte...
authorEvan Cheng <evan.cheng@apple.com>
Thu, 28 Feb 2008 00:43:03 +0000 (00:43 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 28 Feb 2008 00:43:03 +0000 (00:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47703 91177308-0d34-0410-b5e6-96231b3b80d8

25 files changed:
include/llvm/CodeGen/AsmPrinter.h
include/llvm/CodeGen/MachineBasicBlock.h
include/llvm/CodeGen/MachineFrameInfo.h
include/llvm/CodeGen/Passes.h
include/llvm/Target/TargetAsmInfo.h
include/llvm/Target/TargetLowering.h
lib/CodeGen/AsmPrinter.cpp
lib/CodeGen/BranchFolding.cpp
lib/CodeGen/IfConversion.cpp
lib/CodeGen/LoopAligner.cpp [new file with mode: 0644]
lib/CodeGen/MachineBasicBlock.cpp
lib/CodeGen/SelectionDAG/TargetLowering.cpp
lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/Alpha/AlphaAsmPrinter.cpp
lib/Target/CellSPU/SPUAsmPrinter.cpp
lib/Target/IA64/IA64AsmPrinter.cpp
lib/Target/Mips/MipsAsmPrinter.cpp
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/Sparc/SparcAsmPrinter.cpp
lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86IntelAsmPrinter.cpp
lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/X86/X86TargetMachine.cpp
lib/Target/X86/X86TargetMachine.h

index 6607afe823abb47ae39d1043a6ab754ad0632b8f..462c401ae0aa87725dca9d0089f3d6fd22194a4e 100644 (file)
@@ -78,6 +78,10 @@ namespace llvm {
     /// 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);
@@ -269,9 +273,7 @@ namespace llvm {
     /// 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;
@@ -279,8 +281,7 @@ namespace llvm {
     ///     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.
@@ -317,6 +318,7 @@ namespace llvm {
     /// 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;
                                       
index d2b1d5fc2d9bd73f52a976c7c0c1e427370f4116..66de06dcafde7aa5a505e72bb99496b449c33dc2 100644 (file)
@@ -75,6 +75,10 @@ class MachineBasicBlock {
   /// 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.
@@ -82,7 +86,8 @@ class MachineBasicBlock {
 
 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;
   }
 
@@ -181,6 +186,14 @@ public:
   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; }
index 3a0432510c86d851c2a01b1ff54f6820a02b9221..4cc9073435649016f464ca7fbab1752474416add 100644 (file)
@@ -204,7 +204,7 @@ public:
   }
 
   /// 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;
index be7857c657c2993ab913a82794fa73e781ffb09c..5218f7ac26e2bcb20648a78a86be84eb40857634 100644 (file)
@@ -129,6 +129,10 @@ namespace llvm {
   /// 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.
index 8597e40eaf789fe764ff35eefa98eff7a8f6f620..f1d29ac2edea3a153a6f44ed54420878fdcfd341 100644 (file)
@@ -164,6 +164,10 @@ namespace llvm {
     /// 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
@@ -503,6 +507,9 @@ namespace llvm {
     bool getAlignmentIsInBytes() const {
       return AlignmentIsInBytes;
     }
+    unsigned getTextAlignFillValue() const {
+      return TextAlignFillValue;
+    }
     const char *getSwitchToSectionDirective() const {
       return SwitchToSectionDirective;
     }
index b010a69ef7217f0d2b303946b0124930639d5f2d..4f04ce34fc6da02e1aa8c79288350439d6c6054a 100644 (file)
@@ -548,17 +548,23 @@ public:
 
   /// 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.
@@ -583,7 +589,7 @@ public:
   /// jumptable.
   virtual SDOperand getPICJumpTableRelocBase(SDOperand Table,
                                              SelectionDAG &DAG) const;
-  
+
   //===--------------------------------------------------------------------===//
   // TargetLowering Optimization Methods
   //
@@ -890,6 +896,12 @@ protected:
   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:
 
@@ -1276,6 +1288,10 @@ private:
   /// 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.
index 7a01a87872bf5e1e0502acc6ad16c4870eebbc50..9cdae3483382c3400e3eccda0dde588fcf08ee30 100644 (file)
@@ -39,7 +39,8 @@ AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
 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 {
@@ -69,6 +70,8 @@ void AsmPrinter::SwitchToTextSection(const char *NewSection,
 
   if (!CurrentSection.empty())
     O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
+
+  IsInTextSection = true;
 }
 
 /// SwitchToDataSection - Switch to the specified data section of the executable
@@ -93,6 +96,8 @@ void AsmPrinter::SwitchToDataSection(const char *NewSection,
   
   if (!CurrentSection.empty())
     O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
+
+  IsInTextSection = false;
 }
 
 
@@ -344,7 +349,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
       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) 
@@ -352,7 +357,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
           << getFunctionNumber() << '_' << uid;
     }
   } else {
-    printBasicBlockLabel(MBB, false, false);
+    printBasicBlockLabel(MBB, false, false, false);
   }
 }
 
@@ -679,8 +684,7 @@ void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
 //     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);
@@ -688,6 +692,9 @@ void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
   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";
 }
@@ -1252,7 +1259,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
 
           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*/) {
@@ -1318,8 +1325,15 @@ bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
 /// 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)
@@ -1338,7 +1352,7 @@ void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
   
   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';
 }
@@ -1351,7 +1365,7 @@ void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
   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';
 }
index 2d7836f4f3bb8736e759d7de9efaeb7cae4a2c68..d9874b53b614806bae5d4d037c288f41c47fe82d 100644 (file)
@@ -44,7 +44,7 @@ namespace {
             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) {
index 7d7f33e53532340617e969f1a4992ffc7813ab73..a77ccb766ff60737b03d03706d8ce50cebfddd0b 100644 (file)
@@ -56,7 +56,7 @@ STATISTIC(NumIfConvBBs,    "Number of if-converted blocks");
 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.
diff --git a/lib/CodeGen/LoopAligner.cpp b/lib/CodeGen/LoopAligner.cpp
new file mode 100644 (file)
index 0000000..a40bb50
--- /dev/null
@@ -0,0 +1,65 @@
+//===-- 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;
+}
index dc6a618d34c782fffa5e7d1781a908ab7e60ea5d..af91a2fb15c471b499892c3970543f17c82785ff 100644 (file)
@@ -166,6 +166,7 @@ void MachineBasicBlock::print(std::ostream &OS) const {
   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";
 
index ba5a34b7b44ad9ba9364087c66ed0c4a99a4d643..ff5289e088291ca21fb6a3d8d4473174d2d92929 100644 (file)
@@ -206,6 +206,8 @@ TargetLowering::TargetLowering(TargetMachine &tm)
   JumpBufSize = 0;
   JumpBufAlignment = 0;
   IfCvtBlockSizeLimit = 2;
+  IfCvtDupBlockSizeLimit = 0;
+  PrefLoopAlignment = 0;
 
   InitLibcallNames(LibcallRoutineNames);
   InitCmpLibcallCCs(CmpLibcallCCs);
index 31055b2a116f8ed84769a6f4ab6cf76924390aca..ed7077129c7d59add2b58dab06e9e82ea6eb5cf3 100644 (file)
@@ -248,7 +248,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        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();
@@ -710,13 +710,13 @@ void ARMAsmPrinter::printJTBlockOperand(const MachineInstr *MI, int OpNo) {
         << '_' << 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';
   }
index a46a64cebd9490e3991072a988c1f011a94cd9e5..42e4b7843cf29c7b7473d40314d3680276fa6ad2 100644 (file)
@@ -171,7 +171,7 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   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();
index d96ec9dac1a05e1ed6b7bdbcc6c31b63fdb6b40c..f627896f6b8999b615c77aafe47b9f38ccfe9c19 100644 (file)
@@ -460,7 +460,7 @@ LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF)
        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();
index 264329d620fb35d8b8a919c282fa71f85504407c..829730da2410f7f24fe568ab03cd41754b92ffff 100644 (file)
@@ -149,7 +149,7 @@ bool IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        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();
index dc3242c0f1c4d3f65e1623b0efbc9725b19ccda9..6c0c908ae7b06f0bdaaed06f014e2064c72262c0 100644 (file)
@@ -297,7 +297,7 @@ runOnMachineFunction(MachineFunction &MF)
 
     // Print a label for the basic block.
     if (I != MF.begin()) {
-      printBasicBlockLabel(I, true);
+      printBasicBlockLabel(I, true, true);
       O << '\n';
     }
 
index 115e490e9e346924a12836b5f54c3571b2b6cd5a..20b0d2adf4fd67e0249a33bb6bdde1b723d27680 100644 (file)
@@ -604,7 +604,7 @@ bool LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        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();
@@ -838,7 +838,7 @@ bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        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();
index d5b20200e4c1e07df3b3992358e6352d6d3c7ddd..01bd0929bdf9eb58c8c0d217d942a7a981d0df93 100644 (file)
@@ -116,7 +116,7 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        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();
index 304e0f7c3463aa9b2912d590f3fc56c5cf20b0b8..b9770fef1826938d8c40dd9c347cd238895037dd 100644 (file)
@@ -101,36 +101,25 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   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;
@@ -180,7 +169,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        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();
@@ -515,7 +504,7 @@ void X86ATTAsmPrinter::printPICJumpTableSetLabel(unsigned uid,
     
   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';
@@ -543,12 +532,12 @@ void X86ATTAsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
       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,
index 50014b31824a1a4c4b9e5c28bbc769d4e6fdea3b..8acf779676edd02a495c83cffa59317cbe781f77 100644 (file)
@@ -714,6 +714,7 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM)
   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
index b753297a940413bb43a56600ff52931c4f7695a1..6c46b45456294219725a51ae2f33e4cc717caa6e 100644 (file)
@@ -78,7 +78,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        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();
@@ -242,7 +242,7 @@ void X86IntelAsmPrinter::printPICJumpTableSetLabel(unsigned uid,
   
   O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
     << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
-  printBasicBlockLabel(MBB, false, false);
+  printBasicBlockLabel(MBB, false, false, false);
   O << '-' << "\"L" << getFunctionNumber() << "$pb\"'\n";
 }
 
index 42e63ecba3495c7cd75e0da3d2620adc61d129df..acc13ba1070091ee26cbe0eba4648bed85c70f92 100644 (file)
@@ -47,6 +47,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
   switch (Subtarget->TargetType) {
   case X86Subtarget::isDarwin:
     AlignmentIsInBytes = false;
+    TextAlignFillValue = 0x90;
     GlobalPrefix = "_";
     if (!Subtarget->is64Bit())
       Data64bitsDirective = 0;       // we can't emit a 64-bit unit
index 850eb386fb5b81805c9368e1fb7aed629d822c41..ad2775a64844e5bdef37e100c33e713aacc40fb0 100644 (file)
@@ -164,6 +164,13 @@ bool X86TargetMachine::addPostRegAlloc(FunctionPassManager &PM, bool Fast) {
   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));
index e9148b5a52edb55879a6f44d0e854e62af9f6aba..61e4451d7ab237374b645f7f3fd728b58b3512f5 100644 (file)
@@ -63,6 +63,7 @@ public:
   // 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,