diff options
author | Michael Kruse <llvm-project@meinersbur.de> | 2021-04-24 12:10:55 +0300 |
---|---|---|
committer | Michael Kruse <llvm-project@meinersbur.de> | 2021-04-24 12:30:19 +0300 |
commit | 286677870b306582321dcddb1531d8860bc446db (patch) | |
tree | 32fb321be8ec0e539fc822efc31cbdd2183c8e4e /polly/lib/Support | |
parent | fd0af0cf08284de79fe1a5bcfdc2dad83794dcfe (diff) |
[Polly][ManualOpt] Match interpretation of unroll metadata to LoopUnrolls's.
We previously had a different interpretation of unroll transformation
attributes than how LoopUnroll interpreted it. In particular,
llvm.loop.unroll.enable was needed explicitly to enable it and disabling
metadata was ignored.
Additionally, it required that either full unrolling or an unroll factor
to be specified or fail otherwise. An unroll factor is still required,
but the transformation is ignored with the hope that LoopUnroll is going
to apply the unrolling, since Polly currently does not implement an
heuristic.
Fixes llvm.org/PR50109
Diffstat (limited to 'polly/lib/Support')
-rw-r--r-- | polly/lib/Support/ScopHelper.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp index d4a2bfc8d1aa..efb3b9afa698 100644 --- a/polly/lib/Support/ScopHelper.cpp +++ b/polly/lib/Support/ScopHelper.cpp @@ -746,6 +746,21 @@ static MDNode *findNamedMetadataNode(MDNode *LoopMD, StringRef Name) { return nullptr; } +static Optional<const MDOperand *> findNamedMetadataArg(MDNode *LoopID, + StringRef Name) { + MDNode *MD = findNamedMetadataNode(LoopID, Name); + if (!MD) + return None; + switch (MD->getNumOperands()) { + case 1: + return nullptr; + case 2: + return &MD->getOperand(1); + default: + llvm_unreachable("loop metadata has 0 or 1 operand"); + } +} + Optional<Metadata *> polly::findMetadataOperand(MDNode *LoopMD, StringRef Name) { MDNode *MD = findNamedMetadataNode(LoopMD, Name); @@ -761,10 +776,49 @@ Optional<Metadata *> polly::findMetadataOperand(MDNode *LoopMD, } } +static Optional<bool> getOptionalBoolLoopAttribute(MDNode *LoopID, + StringRef Name) { + MDNode *MD = findNamedMetadataNode(LoopID, Name); + if (!MD) + return None; + switch (MD->getNumOperands()) { + case 1: + return true; + case 2: + if (ConstantInt *IntMD = + mdconst::extract_or_null<ConstantInt>(MD->getOperand(1).get())) + return IntMD->getZExtValue(); + return true; + } + llvm_unreachable("unexpected number of options"); +} + +bool polly::getBooleanLoopAttribute(MDNode *LoopID, StringRef Name) { + return getOptionalBoolLoopAttribute(LoopID, Name).getValueOr(false); +} + +llvm::Optional<int> polly::getOptionalIntLoopAttribute(MDNode *LoopID, + StringRef Name) { + const MDOperand *AttrMD = + findNamedMetadataArg(LoopID, Name).getValueOr(nullptr); + if (!AttrMD) + return None; + + ConstantInt *IntMD = mdconst::extract_or_null<ConstantInt>(AttrMD->get()); + if (!IntMD) + return None; + + return IntMD->getSExtValue(); +} + bool polly::hasDisableAllTransformsHint(Loop *L) { return llvm::hasDisableAllTransformsHint(L); } +bool polly::hasDisableAllTransformsHint(llvm::MDNode *LoopID) { + return getBooleanLoopAttribute(LoopID, "llvm.loop.disable_nonforced"); +} + isl::id polly::getIslLoopAttr(isl::ctx Ctx, BandAttr *Attr) { assert(Attr && "Must be a valid BandAttr"); |