[X86] Merge X86MCInstLowering's maxLongNopLength into emitNop and remove check for FeatureNOPL.

The switch in emitNop uses 64-bit registers for nops exceeding
2 bytes. This isn't valid outside 64-bit mode. We could fix this
easily enough, but there are no users that ask for more than 2
bytes outside 64-bit mode.

Inlining the method to make the coupling between the two methods
more explicit.
This commit is contained in:
Craig Topper 2020-07-25 22:05:46 -07:00
parent 14c59b4577
commit 1a1448e656
1 changed files with 16 additions and 18 deletions

View File

@ -1079,29 +1079,27 @@ void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,
}
}
/// Return the longest nop which can be efficiently decoded for the given
/// target cpu. 15-bytes is the longest single NOP instruction, but some
/// platforms can't decode the longest forms efficiently.
static unsigned maxLongNopLength(const X86Subtarget *Subtarget) {
if (Subtarget->getFeatureBits()[X86::FeatureFast7ByteNOP])
return 7;
if (Subtarget->getFeatureBits()[X86::FeatureFast15ByteNOP])
return 15;
if (Subtarget->getFeatureBits()[X86::FeatureFast11ByteNOP])
return 11;
if (Subtarget->getFeatureBits()[X86::FeatureNOPL] || Subtarget->is64Bit())
return 10;
if (Subtarget->is32Bit())
return 2;
return 1;
}
/// Emit the largest nop instruction smaller than or equal to \p NumBytes
/// bytes. Return the size of nop emitted.
static unsigned emitNop(MCStreamer &OS, unsigned NumBytes,
const X86Subtarget *Subtarget) {
unsigned MaxNopLength = 1;
if (Subtarget->is64Bit()) {
// FIXME: We can use NOOPL on 32-bit targets with FeatureNOPL, but the
// IndexReg/BaseReg below need to be updated.
if (Subtarget->hasFeature(X86::FeatureFast7ByteNOP))
MaxNopLength = 7;
else if (Subtarget->hasFeature(X86::FeatureFast15ByteNOP))
MaxNopLength = 15;
else if (Subtarget->hasFeature(X86::FeatureFast11ByteNOP))
MaxNopLength = 11;
else
MaxNopLength = 10;
} if (Subtarget->is32Bit())
MaxNopLength = 2;
// Cap a single nop emission at the profitable value for the target
NumBytes = std::min(NumBytes, maxLongNopLength(Subtarget));
NumBytes = std::min(NumBytes, MaxNopLength);
unsigned NopSize;
unsigned Opc, BaseReg, ScaleVal, IndexReg, Displacement, SegmentReg;