Fix the asmprinter so that a globalvalue can specify an explicit alignment
authorChris Lattner <sabre@nondot.org>
Thu, 31 May 2007 18:57:45 +0000 (18:57 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 31 May 2007 18:57:45 +0000 (18:57 +0000)
smaller than the preferred alignment, but so that the target can actually
specify a minimum alignment if needed.  This fixes some objc protocol
failures Devang tracked down.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37373 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter.cpp
lib/Target/ARM/ARMAsmPrinter.cpp

index 8dd6aecf607131bb76494ae6cf4b3d1176a1b5dd..954b9bcee1f8021625454357614cdda6abed6279 100644 (file)
@@ -248,8 +248,18 @@ namespace llvm {
     /// EmitAlignment - Emit an alignment directive to the specified power of
     /// two boundary.  For example, if you pass in 3 here, you will get an 8
     /// byte alignment.  If a global value is specified, and if that global has
-    /// an explicit alignment requested, it will override the alignment request.
-    void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0) const;
+    /// 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.
+    ///
+    /// The algorithm is:
+    ///     Align = NumBits;
+    ///     if (GV && GV->hasalignment) Align = GV->getalignment();
+    ///     Align = std::max(Align, ForcedAlignBits);
+    ///
+    void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0,
+                       unsigned ForcedAlignBits = 0) const;
 
   protected:
     /// EmitZeros - Emit a block of zeros.
index fd112a3531acaba3136bf8ae70feb6cfc5e70cdc..07319d595a1f2d7280121fb4283515b489d4ff66 100644 (file)
@@ -605,12 +605,25 @@ void AsmPrinter::EmitString(const std::string &String) const {
 
 //===----------------------------------------------------------------------===//
 
-// EmitAlignment - Emit an alignment directive to the specified power of two.
-// Use the maximum of the specified alignment and the alignment from the
-// specified GlobalValue (if any).
-void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
+// EmitAlignment - Emit an alignment directive to the specified power of
+// two boundary.  For example, if you pass in 3 here, you will get an 8
+// byte alignment.  If a global value is specified, and if that global has
+// 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.
+//
+// The algorithm is:
+//     Align = NumBits;
+//     if (GV && GV->hasalignment) Align = GV->getalignment();
+//     Align = std::max(Align, ForcedAlignBits);
+//
+void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
+                               unsigned ForcedAlignBits) const {
   if (GV && GV->getAlignment())
-    NumBits = std::max(NumBits, Log2_32(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 << "\n";
index c57fbbc0194a5e6ee532f94eae6c4f3fea34aa63..f6bf6e0be8a51158bbc67807bc717bb9485577c2 100644 (file)
@@ -218,7 +218,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
     O << VisibilityDirective << CurrentFnName << "\n";
 
   if (AFI->isThumbFunction()) {
-    EmitAlignment(AFI->getAlign(), F);
+    EmitAlignment(1, F, AFI->getAlign());
     O << "\t.code\t16\n";
     O << "\t.thumb_func";
     if (Subtarget->isTargetDarwin())