Skip to content

Commit

Permalink
[AIE] Factor getLoopID from getMinTripCount
Browse files Browse the repository at this point in the history
  • Loading branch information
Martien de Jong authored and andcarminati committed Aug 21, 2024
1 parent b906925 commit 71484dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 13 additions & 11 deletions llvm/lib/Target/AIE/Utils/AIELoopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@
#define DEBUG_TYPE "aielooputils"

namespace llvm::AIELoopUtils {
const MDNode *getLoopID(const MachineBasicBlock &LoopBlock) {
const BasicBlock *BBLK = LoopBlock.getBasicBlock();
if (!BBLK)
return nullptr;

std::optional<int64_t> getMinTripCount(const MDNode *LoopID) {
const Instruction *TI = BBLK->getTerminator();
if (!TI)
return nullptr;

const MDNode *LoopID = TI->getMetadata(LLVMContext::MD_loop);
return LoopID;
}

std::optional<int64_t> getMinTripCount(const MDNode *LoopID) {
if (LoopID == nullptr)
return std::nullopt;

Expand Down Expand Up @@ -48,16 +59,7 @@ std::optional<int64_t> getMinTripCount(const MDNode *LoopID) {
}

std::optional<int64_t> getMinTripCount(const MachineBasicBlock &LoopBlock) {
const BasicBlock *BBLK = LoopBlock.getBasicBlock();
if (!BBLK)
return std::nullopt;

const Instruction *TI = BBLK->getTerminator();
if (!TI)
return std::nullopt;

const MDNode *LoopID = TI->getMetadata(LLVMContext::MD_loop);
return getMinTripCount(LoopID);
return getMinTripCount(getLoopID(LoopBlock));
}

MachineBasicBlock *
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AIE/Utils/AIELoopUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class MachineBasicBlock;

namespace llvm::AIELoopUtils {

/// Get the LoopID from a single block loop or nullptr
const MDNode *getLoopID(const MachineBasicBlock &LoopBlock);

/// Get the tripcount from the LoopID node
std::optional<int64_t> getMinTripCount(const MDNode *LoopID);

Expand Down

0 comments on commit 71484dd

Please sign in to comment.