[PATCH] Resurrect the assertion removed by r227717
Jingyue Wu
jingyue at google.com
Sun Feb 1 20:23:55 PST 2015
Hi mkuper,
MSVC can compile "LoopID->getOperand(0) == LoopID" when LoopID is MDNode*.
http://reviews.llvm.org/D7327
Files:
include/llvm/Transforms/Utils/UnrollLoop.h
lib/Target/NVPTX/NVPTXAsmPrinter.cpp
lib/Transforms/Scalar/LoopUnrollPass.cpp
lib/Transforms/Utils/LoopUnroll.cpp
Index: include/llvm/Transforms/Utils/UnrollLoop.h
===================================================================
--- include/llvm/Transforms/Utils/UnrollLoop.h
+++ include/llvm/Transforms/Utils/UnrollLoop.h
@@ -34,7 +34,7 @@
bool UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
LPPassManager* LPM);
-const MDNode *GetUnrollMetadata(const MDNode *LoopID, StringRef Name);
+MDNode *GetUnrollMetadata(MDNode *LoopID, StringRef Name);
}
#endif
Index: lib/Target/NVPTX/NVPTXAsmPrinter.cpp
===================================================================
--- lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -442,8 +442,7 @@
continue;
}
if (const BasicBlock *PBB = PMBB->getBasicBlock()) {
- if (const MDNode *LoopID =
- PBB->getTerminator()->getMetadata("llvm.loop")) {
+ if (MDNode *LoopID = PBB->getTerminator()->getMetadata("llvm.loop")) {
if (GetUnrollMetadata(LoopID, "llvm.loop.unroll.disable"))
return true;
}
Index: lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -231,11 +231,10 @@
// Returns the loop hint metadata node with the given name (for example,
// "llvm.loop.unroll.count"). If no such metadata node exists, then nullptr is
// returned.
-static const MDNode *GetUnrollMetadataForLoop(const Loop *L, StringRef Name) {
- MDNode *LoopID = L->getLoopID();
- if (!LoopID)
- return nullptr;
- return GetUnrollMetadata(LoopID, Name);
+static MDNode *GetUnrollMetadataForLoop(const Loop *L, StringRef Name) {
+ if (MDNode *LoopID = L->getLoopID())
+ return GetUnrollMetadata(LoopID, Name);
+ return nullptr;
}
// Returns true if the loop has an unroll(full) pragma.
@@ -251,7 +250,7 @@
// If loop has an unroll_count pragma return the (necessarily
// positive) value from the pragma. Otherwise return 0.
static unsigned UnrollCountPragmaValue(const Loop *L) {
- const MDNode *MD = GetUnrollMetadataForLoop(L, "llvm.loop.unroll.count");
+ MDNode *MD = GetUnrollMetadataForLoop(L, "llvm.loop.unroll.count");
if (MD) {
assert(MD->getNumOperands() == 2 &&
"Unroll count hint metadata should have two operands.");
Index: lib/Transforms/Utils/LoopUnroll.cpp
===================================================================
--- lib/Transforms/Utils/LoopUnroll.cpp
+++ lib/Transforms/Utils/LoopUnroll.cpp
@@ -553,16 +553,17 @@
/// Given an llvm.loop loop id metadata node, returns the loop hint metadata
/// node with the given name (for example, "llvm.loop.unroll.count"). If no
/// such metadata node exists, then nullptr is returned.
-const MDNode *llvm::GetUnrollMetadata(const MDNode *LoopID, StringRef Name) {
+MDNode *llvm::GetUnrollMetadata(MDNode *LoopID, StringRef Name) {
// First operand should refer to the loop id itself.
assert(LoopID->getNumOperands() > 0 && "requires at least one operand");
+ assert(LoopID->getOperand(0) == LoopID && "invalid loop id");
for (unsigned i = 1, e = LoopID->getNumOperands(); i < e; ++i) {
- const MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
+ MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
if (!MD)
continue;
- const MDString *S = dyn_cast<MDString>(MD->getOperand(0));
+ MDString *S = dyn_cast<MDString>(MD->getOperand(0));
if (!S)
continue;
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7327.19126.patch
Type: text/x-patch
Size: 3523 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150202/5676f397/attachment.bin>
More information about the llvm-commits
mailing list