summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/CGLoopInfo.h
diff options
context:
space:
mode:
authorTyler Nowicki <tyler.nowicki@gmail.com>2015-07-27 20:10:20 +0000
committerTyler Nowicki <tyler.nowicki@gmail.com>2015-07-27 20:10:20 +0000
commit33ecde5538b976253e5adf45442e7f0b4a3d21bf (patch)
tree79818a98e9acdf45cbe8f35c4041b7942301a340 /lib/CodeGen/CGLoopInfo.h
parent1dcf333250f807ff367394b8a0e88a32981c6fff (diff)
Use CGLoopInfo to emit metadata for loop hint pragmas.
When ‘#pragma clang loop vectorize(assume_safety)’ was specified on a loop other loop hints were lost. The problem is that CGLoopInfo attaches metadata differently than EmitCondBrHints in CGStmt. For do-loops CGLoopInfo attaches metadata to the br in the body block and for while and for loops, the inc block. EmitCondBrHints on the other hand always attaches data to the br in the cond block. When specifying assume_safety CGLoopInfo emits an empty llvm.loop metadata shadowing the metadata in the cond block. Loop transformations like rotate and unswitch would then eliminate the cond block and its non-empty metadata. This patch unifies both approaches for adding metadata and modifies the existing safety tests to include non-assume_safety loop hints. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243315 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGLoopInfo.h')
-rw-r--r--lib/CodeGen/CGLoopInfo.h24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/CodeGen/CGLoopInfo.h b/lib/CodeGen/CGLoopInfo.h
index 8822c22c91..686a218c76 100644
--- a/lib/CodeGen/CGLoopInfo.h
+++ b/lib/CodeGen/CGLoopInfo.h
@@ -29,6 +29,7 @@ class MDNode;
namespace clang {
class Attr;
+class ASTContext;
namespace CodeGen {
/// \brief Attributes that may be specified on loops.
@@ -45,11 +46,17 @@ struct LoopAttributes {
/// \brief Value for llvm.loop.vectorize.enable metadata.
LVEnableState VectorizeEnable;
+ /// \brief Selects no metadata, llvm.unroll.full, or llvm.unroll.disable.
+ LVEnableState UnrollEnable;
+
/// \brief Value for llvm.loop.vectorize.width metadata.
unsigned VectorizeWidth;
/// \brief Value for llvm.loop.interleave.count metadata.
unsigned InterleaveCount;
+
+ /// \brief llvm.unroll.
+ unsigned UnrollCount;
};
/// \brief Information used when generating a structured loop.
@@ -88,8 +95,12 @@ public:
/// \brief Begin a new structured loop. The set of staged attributes will be
/// applied to the loop and then cleared.
- void push(llvm::BasicBlock *Header,
- llvm::ArrayRef<const Attr *> Attrs = llvm::None);
+ void push(llvm::BasicBlock *Header);
+
+ /// \brief Begin a new structured loop. Stage attributes from the Attrs list.
+ /// The staged attributes are applied to the loop and then cleared.
+ void push(llvm::BasicBlock *Header, clang::ASTContext &Ctx,
+ llvm::ArrayRef<const Attr *> Attrs);
/// \brief End the current loop.
void pop();
@@ -115,12 +126,21 @@ public:
Enable ? LoopAttributes::Enable : LoopAttributes::Disable;
}
+ /// \brief Set the next pushed loop unroll state.
+ void setUnrollEnable(bool Enable = true) {
+ StagedAttrs.UnrollEnable =
+ Enable ? LoopAttributes::Enable : LoopAttributes::Disable;
+ }
+
/// \brief Set the vectorize width for the next loop pushed.
void setVectorizeWidth(unsigned W) { StagedAttrs.VectorizeWidth = W; }
/// \brief Set the interleave count for the next loop pushed.
void setInterleaveCount(unsigned C) { StagedAttrs.InterleaveCount = C; }
+ /// \brief Set the unroll count for the next loop pushed.
+ void setUnrollCount(unsigned C) { StagedAttrs.UnrollCount = C; }
+
private:
/// \brief Returns true if there is LoopInfo on the stack.
bool hasInfo() const { return !Active.empty(); }