codeGen->setFrameRequired(true);
#endif
- if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT))
+ if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT) && !IsTargetAbi(CORINFO_NATIVEAOT_ABI))
{
- // The JIT doesn't currently support loop alignment for prejitted images.
+ // The JIT doesn't currently support loop alignment for prejitted images outside NativeAOT.
// (The JIT doesn't know the final address of the code, hence
// it can't align code based on unknown addresses.)
// For x64/x86/arm64, align methods that are "optimizations enabled" to 32 byte boundaries if
// they are larger than 16 bytes and contain a loop.
//
- if (emitComp->opts.OptimizationEnabled() && !emitComp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT) &&
+ if (emitComp->opts.OptimizationEnabled() &&
+ (!emitComp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT) || comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI)) &&
(emitTotalHotCodeSize > 16) && emitComp->fgHasLoops)
{
codeAlignment = 32;
#ifdef DEBUG
if ((allocMemFlag & CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN) != 0)
{
- assert(((size_t)codeBlock & 31) == 0);
+ // For prejit, codeBlock will not be necessarily aligned, but it is aligned
+ // in final obj file.
+ assert((((size_t)codeBlock & 31) == 0) || emitComp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT));
}
#if 0
// TODO: we should be able to assert the following, but it appears crossgen2 doesn't respect them,
// For cases where 'align' was placed behind a 'jmp' in an IG that does not
// immediately preced the loop IG, we do not know in advance the offset of
// IG having loop. For such cases, skip the padding calculation validation.
- bool validatePadding = !alignInstr->isPlacedAfterJmp;
+
+ // For prejit, `dst` is not aliged as requested, but the final assembly will have them aligned.
+ // So, just calculate the offset of the current `dst` from the start.
+ size_t offset = emitComp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT) ? emitCurCodeOffs(dst) : (size_t)dst;
+ bool validatePadding = !alignInstr->isPlacedAfterJmp;
#endif
// Candidate for loop alignment
unsigned paddingToAdd = id->idCodeSize();
// Either things are already aligned or align them here.
- assert(!validatePadding || (paddingToAdd == 0) ||
- (((size_t)dst & (emitComp->opts.compJitAlignLoopBoundary - 1)) != 0));
+ assert(!validatePadding || (paddingToAdd == 0) || ((offset & (emitComp->opts.compJitAlignLoopBoundary - 1)) != 0));
// Padding amount should not exceed the alignment boundary
assert(0 <= paddingToAdd && paddingToAdd < emitComp->opts.compJitAlignLoopBoundary);
if (validatePadding)
{
unsigned paddingNeeded =
- emitCalculatePaddingForLoopAlignment(((instrDescAlign*)id)->idaIG->igNext, (size_t)dst, true);
+ emitCalculatePaddingForLoopAlignment(((instrDescAlign*)id)->idaIG->igNext, offset, true);
// For non-adaptive, padding size is spread in multiple instructions, so don't bother checking
if (emitComp->opts.compJitAlignLoopAdaptive)