Allow targets to specify a minimum supported NOP size when performing NOP padding...
authorOwen Anderson <resistor@mac.com>
Wed, 29 Aug 2012 22:18:56 +0000 (22:18 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 29 Aug 2012 22:18:56 +0000 (22:18 +0000)
we will enlarge the padding to make it work.

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

include/llvm/MC/MCAsmBackend.h
lib/MC/MCAssembler.cpp

index 43aceba3e14526c2de41fd01be2f5808e4888ecd..1c450909b1afbdf444467da306ec7132cba70604 100644 (file)
@@ -133,6 +133,13 @@ public:
 
   /// @}
 
+  /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
+  /// target. The assembler will use this to emit excess padding in situations
+  /// where the padding required for simple alignment would be less than the
+  /// minimum nop size.
+  ///
+  virtual unsigned getMinimumNopSize() const { return 1; }
+
   /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
   /// output. If the target cannot generate such a sequence, it should return an
   /// error.
index 05519b56ffecbf2dbc03263cfceeefd933dbf0f2..c872bd62c9abe9e7d8e75ee9a78a1b35f2d96366 100644 (file)
@@ -325,6 +325,12 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
     const MCAlignFragment &AF = cast<MCAlignFragment>(F);
     unsigned Offset = Layout.getFragmentOffset(&AF);
     unsigned Size = OffsetToAlignment(Offset, AF.getAlignment());
+    // If we are padding with nops, force the padding to be larger than the
+    // minimum nop size.
+    if (Size > 0 && AF.hasEmitNops()) {
+      while (Size % getBackend().getMinimumNopSize())
+        Size += AF.getAlignment();
+    }
     if (Size > AF.getMaxBytesToEmit())
       return 0;
     return Size;