mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
Move code for checking loop metadata into Analysis [nfc]
I need the mustprogress loop metadata in ScalarEvolution and it makes sense to keep all the accessors for quering loop metadate together.
This commit is contained in:
parent
c9694dc562
commit
52d05589ca
@ -1292,6 +1292,27 @@ MDNode *findOptionMDForLoopID(MDNode *LoopID, StringRef Name);
|
||||
/// found, return nullptr.
|
||||
MDNode *findOptionMDForLoop(const Loop *TheLoop, StringRef Name);
|
||||
|
||||
Optional<bool> getOptionalBoolLoopAttribute(const Loop *TheLoop,
|
||||
StringRef Name);
|
||||
|
||||
/// Returns true if Name is applied to TheLoop and enabled.
|
||||
bool getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name);
|
||||
|
||||
/// Find named metadata for a loop with an integer value.
|
||||
llvm::Optional<int>
|
||||
getOptionalIntLoopAttribute(const Loop *TheLoop, StringRef Name);
|
||||
|
||||
/// Find string metadata for loop
|
||||
///
|
||||
/// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
|
||||
/// operand or null otherwise. If the string metadata is not found return
|
||||
/// Optional's not-a-value.
|
||||
Optional<const MDOperand *> findStringMetadataForLoop(const Loop *TheLoop,
|
||||
StringRef Name);
|
||||
|
||||
/// Look for the loop attribute that requires progress within the loop.
|
||||
bool hasMustProgress(const Loop *L);
|
||||
|
||||
/// Return whether an MDNode might represent an access group.
|
||||
///
|
||||
/// Access group metadata nodes have to be distinct and empty. Being
|
||||
|
@ -210,18 +210,6 @@ SmallVector<DomTreeNode *, 16> collectChildrenInLoop(DomTreeNode *N,
|
||||
/// Returns the instructions that use values defined in the loop.
|
||||
SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L);
|
||||
|
||||
/// Find string metadata for loop
|
||||
///
|
||||
/// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
|
||||
/// operand or null otherwise. If the string metadata is not found return
|
||||
/// Optional's not-a-value.
|
||||
Optional<const MDOperand *> findStringMetadataForLoop(const Loop *TheLoop,
|
||||
StringRef Name);
|
||||
|
||||
/// Find named metadata for a loop with an integer value.
|
||||
llvm::Optional<int> getOptionalIntLoopAttribute(const Loop *TheLoop,
|
||||
StringRef Name);
|
||||
|
||||
/// Find a combination of metadata ("llvm.loop.vectorize.width" and
|
||||
/// "llvm.loop.vectorize.scalable.enable") for a loop and use it to construct a
|
||||
/// ElementCount. If the metadata "llvm.loop.vectorize.width" cannot be found
|
||||
@ -264,9 +252,6 @@ bool hasDisableAllTransformsHint(const Loop *L);
|
||||
/// Look for the loop attribute that disables the LICM transformation heuristics.
|
||||
bool hasDisableLICMTransformsHint(const Loop *L);
|
||||
|
||||
/// Look for the loop attribute that requires progress within the loop.
|
||||
bool hasMustProgress(const Loop *L);
|
||||
|
||||
/// The mode sets how eager a transformation should be applied.
|
||||
enum TransformationMode {
|
||||
/// The pass can use heuristics to determine whether a transformation should
|
||||
@ -309,9 +294,6 @@ TransformationMode hasLICMVersioningTransformation(const Loop *L);
|
||||
void addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
|
||||
unsigned V = 0);
|
||||
|
||||
/// Returns true if Name is applied to TheLoop and enabled.
|
||||
bool getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name);
|
||||
|
||||
/// Returns a loop's estimated trip count based on branch weight metadata.
|
||||
/// In addition if \p EstimatedLoopInvocationWeight is not null it is
|
||||
/// initialized with weight of loop's latch leading to the exit.
|
||||
|
@ -1046,6 +1046,68 @@ MDNode *llvm::findOptionMDForLoop(const Loop *TheLoop, StringRef Name) {
|
||||
return findOptionMDForLoopID(TheLoop->getLoopID(), Name);
|
||||
}
|
||||
|
||||
/// Find string metadata for loop
|
||||
///
|
||||
/// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
|
||||
/// operand or null otherwise. If the string metadata is not found return
|
||||
/// Optional's not-a-value.
|
||||
Optional<const MDOperand *> llvm::findStringMetadataForLoop(const Loop *TheLoop,
|
||||
StringRef Name) {
|
||||
MDNode *MD = findOptionMDForLoop(TheLoop, 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<bool> llvm::getOptionalBoolLoopAttribute(const Loop *TheLoop,
|
||||
StringRef Name) {
|
||||
MDNode *MD = findOptionMDForLoop(TheLoop, Name);
|
||||
if (!MD)
|
||||
return None;
|
||||
switch (MD->getNumOperands()) {
|
||||
case 1:
|
||||
// When the value is absent it is interpreted as 'attribute set'.
|
||||
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 llvm::getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name) {
|
||||
return getOptionalBoolLoopAttribute(TheLoop, Name).getValueOr(false);
|
||||
}
|
||||
|
||||
llvm::Optional<int> llvm::getOptionalIntLoopAttribute(const Loop *TheLoop,
|
||||
StringRef Name) {
|
||||
const MDOperand *AttrMD =
|
||||
findStringMetadataForLoop(TheLoop, Name).getValueOr(nullptr);
|
||||
if (!AttrMD)
|
||||
return None;
|
||||
|
||||
ConstantInt *IntMD = mdconst::extract_or_null<ConstantInt>(AttrMD->get());
|
||||
if (!IntMD)
|
||||
return None;
|
||||
|
||||
return IntMD->getSExtValue();
|
||||
}
|
||||
|
||||
static const char *LLVMLoopMustProgress = "llvm.loop.mustprogress";
|
||||
|
||||
bool llvm::hasMustProgress(const Loop *L) {
|
||||
return getBooleanLoopAttribute(L, LLVMLoopMustProgress);
|
||||
}
|
||||
|
||||
bool llvm::isValidAsAccessGroup(MDNode *Node) {
|
||||
return Node->getNumOperands() == 0 && Node->isDistinct();
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ using namespace llvm::PatternMatch;
|
||||
|
||||
static const char *LLVMLoopDisableNonforced = "llvm.loop.disable_nonforced";
|
||||
static const char *LLVMLoopDisableLICM = "llvm.licm.disable";
|
||||
static const char *LLVMLoopMustProgress = "llvm.loop.mustprogress";
|
||||
|
||||
bool llvm::formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI,
|
||||
MemorySSAUpdater *MSSAU,
|
||||
@ -255,48 +254,6 @@ void llvm::addStringMetadataToLoop(Loop *TheLoop, const char *StringMD,
|
||||
TheLoop->setLoopID(NewLoopID);
|
||||
}
|
||||
|
||||
/// Find string metadata for loop
|
||||
///
|
||||
/// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
|
||||
/// operand or null otherwise. If the string metadata is not found return
|
||||
/// Optional's not-a-value.
|
||||
Optional<const MDOperand *> llvm::findStringMetadataForLoop(const Loop *TheLoop,
|
||||
StringRef Name) {
|
||||
MDNode *MD = findOptionMDForLoop(TheLoop, 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");
|
||||
}
|
||||
}
|
||||
|
||||
static Optional<bool> getOptionalBoolLoopAttribute(const Loop *TheLoop,
|
||||
StringRef Name) {
|
||||
MDNode *MD = findOptionMDForLoop(TheLoop, Name);
|
||||
if (!MD)
|
||||
return None;
|
||||
switch (MD->getNumOperands()) {
|
||||
case 1:
|
||||
// When the value is absent it is interpreted as 'attribute set'.
|
||||
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 llvm::getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name) {
|
||||
return getOptionalBoolLoopAttribute(TheLoop, Name).getValueOr(false);
|
||||
}
|
||||
|
||||
Optional<ElementCount>
|
||||
llvm::getOptionalElementCountLoopAttribute(const Loop *TheLoop) {
|
||||
Optional<int> Width =
|
||||
@ -311,20 +268,6 @@ llvm::getOptionalElementCountLoopAttribute(const Loop *TheLoop) {
|
||||
return None;
|
||||
}
|
||||
|
||||
llvm::Optional<int> llvm::getOptionalIntLoopAttribute(const Loop *TheLoop,
|
||||
StringRef Name) {
|
||||
const MDOperand *AttrMD =
|
||||
findStringMetadataForLoop(TheLoop, Name).getValueOr(nullptr);
|
||||
if (!AttrMD)
|
||||
return None;
|
||||
|
||||
ConstantInt *IntMD = mdconst::extract_or_null<ConstantInt>(AttrMD->get());
|
||||
if (!IntMD)
|
||||
return None;
|
||||
|
||||
return IntMD->getSExtValue();
|
||||
}
|
||||
|
||||
Optional<MDNode *> llvm::makeFollowupLoopID(
|
||||
MDNode *OrigLoopID, ArrayRef<StringRef> FollowupOptions,
|
||||
const char *InheritOptionsExceptPrefix, bool AlwaysNew) {
|
||||
@ -414,10 +357,6 @@ bool llvm::hasDisableLICMTransformsHint(const Loop *L) {
|
||||
return getBooleanLoopAttribute(L, LLVMLoopDisableLICM);
|
||||
}
|
||||
|
||||
bool llvm::hasMustProgress(const Loop *L) {
|
||||
return getBooleanLoopAttribute(L, LLVMLoopMustProgress);
|
||||
}
|
||||
|
||||
TransformationMode llvm::hasUnrollTransformation(const Loop *L) {
|
||||
if (getBooleanLoopAttribute(L, "llvm.loop.unroll.disable"))
|
||||
return TM_SuppressedByUser;
|
||||
|
Loading…
Reference in New Issue
Block a user