Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ZOL to aie2p #311

Open
wants to merge 9 commits into
base: aie-public
Choose a base branch
from
Open

Add ZOL to aie2p #311

wants to merge 9 commits into from

Conversation

martien-de-jong
Copy link
Collaborator

@martien-de-jong martien-de-jong commented Jan 24, 2025

Leveraged the great similarity between aie2 and aie2p. All of ZOL can now be defined by a dozen of opcodes, registers and other numbers

// LoopStart carries an immediate operand that is dedicated to the tripcount
// update of the pipeliner. We translate to ADD_NC, which has a similar
// operand.
BuildMI(*MBB, Start, Start->getDebugLoc(), TII->get(AIE2::ADD_NC), AIE2::LC)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not generic, but we only need the right numbers. They are now supplied by one single getZOLSupport() call.

LLVMContext &C = L->getHeader()->getContext();
HWLoopInfo.CountType = Type::getInt32Ty(C);
HWLoopInfo.LoopDecrement = ConstantInt::get(HWLoopInfo.CountType, 1);
// We always allow nested hardware loops, but only the innermost loop
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah right. Note how we only allow single block loops above. Details.

@@ -221,35 +245,31 @@ struct AIEBaseInstrInfo : public TargetInstrInfo {
// Opcodes related to hardware loop handling
virtual bool isHardwareLoopDec(unsigned Opcode) const { return false; }
virtual bool isHardwareLoopJNZ(unsigned Opcode) const { return false; }
virtual bool isHardwareLoopStart(unsigned Opcode) const { return false; }
virtual bool isHardwareLoopEnd(unsigned Opcode) const { return false; }
virtual bool isHardwareLoopStart(unsigned Opcode) const;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This completely stands on the base class now. I hope no need to override this in the future ;-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The base class will work if there's a fixed set of opcodes that is used in all occurrences. I expect this to remain true.

HWLoopInfo.CounterInReg = true;
}
return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line.

// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// (c) Copyright 2023-2025 Advanced Micro Devices, Inc. or its affiliates
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be only 2025?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This file was copied, then modified.

//
//===----------------------------------------------------------------------===//

#include "AIE2PTargetTransformInfo.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future (really not now): refactor this to a common class.

extern cl::opt<unsigned> MaxUnrollCost;
extern cl::opt<unsigned> PreferSwpOverUnroll;

void AIE2PTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really needed by this PR, but a nice-to-have change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it for free, and it made getting an end-to-end postpiperliner test working a lot eaesier.

@andcarminati
Copy link
Collaborator

General comment: looks good, just some outdated dates.

Result.LoopEndOpcode = AIE2::PseudoLoopEnd;
Result.SetLoopCountOpcode = AIE2::ADD_NC;
Result.SetAddressOpcode = AIE2::MOVXM_lng_cg;
Result.LoopSetupDistance = 7;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would be nice if you could comment on this number.

@@ -329,6 +329,14 @@ bool AIEBaseInstrInfo::isCallBundle(MachineBasicBlock::iterator MII) const {
return IsReturnAddr;
}

bool AIEBaseInstrInfo::isZOLTripCountDef(const MachineInstr &MI,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: May be you dont need this to be virtual function anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Murphy law, in the formulation "Constants aren't, variables won't": if I leave it I will never need it; if I remove it, I will need it next week.

bool AIEBaseInstrInfo::isZeroOverheadLoopSetupInstr(
const MachineInstr &MI) const {
auto ZOLSupport = getZOLSupport();
if (!ZOLSupport) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant we just assert like in getLoopSetupDistance

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. We are a simple predicate that returns whether this is a ZOLsetup instruction. If we haven't got ZOLSupport, it isn't one. No reason to abort.

%12:_(s32) = nsw G_ADD %4, %11
G_STORE %12(s32), %0(p0) :: (store (s32))
%14:_(s32) = nuw nsw G_ADD %5, %13
%15:_(s1) = G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.loop.decrement), %13(s32)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this entire loop to test this? can we simply use %15:_(s1) = G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.loop.decrement), %13(s32)

llvm/lib/Target/AIE/aie2p/AIE2PInstructionSelector.cpp Outdated Show resolved Hide resolved
llvm/lib/Target/AIE/aie2p/AIE2PInstructionSelector.cpp Outdated Show resolved Hide resolved
llvm/test/CodeGen/AIE/aie2p/zol/legalize.mir Outdated Show resolved Hide resolved
llvm/test/CodeGen/AIE/aie2p/zol/legalize.mir Outdated Show resolved Hide resolved
Copy link
Collaborator

@andcarminati andcarminati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. All relevant refactorings were included and all comments addressed.

@niwinanto
Copy link
Collaborator

@martien-de-jong I can see many ZOL tests for aie2 llvm/test/CodeGen/AIE/aie2/hardware-loops/, do we plan to run those tests for aie2p as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants