diff options
author | Michael Kruse <llvm@meinersbur.de> | 2018-12-20 21:24:54 +0000 |
---|---|---|
committer | Michael Kruse <llvm@meinersbur.de> | 2018-12-20 21:24:54 +0000 |
commit | 0535137e4ad5fc76b19ec6118724f66023f565f7 (patch) | |
tree | 450b4a084973a76d4b7237bc355664aa19dd9255 /clang/lib/CodeGen | |
parent | a6b9c68a85df16560c4a20a918321d0a847971cd (diff) | |
download | bcm5719-llvm-0535137e4ad5fc76b19ec6118724f66023f565f7.tar.gz bcm5719-llvm-0535137e4ad5fc76b19ec6118724f66023f565f7.zip |
[CodeGen] Generate llvm.loop.parallel_accesses instead of llvm.mem.parallel_loop_access metadata.
Instead of generating llvm.mem.parallel_loop_access metadata, generate
llvm.access.group on instructions and llvm.loop.parallel_accesses on
loops. There is one access group per generated loop.
This is clang part of D52116/r349725.
Differential Revision: https://reviews.llvm.org/D52117
llvm-svn: 349823
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGLoopInfo.cpp | 40 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGLoopInfo.h | 5 |
2 files changed, 29 insertions, 16 deletions
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp index 169ae4fcde1..6cbf801ae61 100644 --- a/clang/lib/CodeGen/CGLoopInfo.cpp +++ b/clang/lib/CodeGen/CGLoopInfo.cpp @@ -21,7 +21,7 @@ using namespace llvm; static MDNode *createMetadata(LLVMContext &Ctx, const LoopAttributes &Attrs, const llvm::DebugLoc &StartLoc, - const llvm::DebugLoc &EndLoc) { + const llvm::DebugLoc &EndLoc, MDNode *&AccGroup) { if (!Attrs.IsParallel && Attrs.VectorizeWidth == 0 && Attrs.InterleaveCount == 0 && Attrs.UnrollCount == 0 && @@ -122,6 +122,12 @@ static MDNode *createMetadata(LLVMContext &Ctx, const LoopAttributes &Attrs, Args.push_back(MDNode::get(Ctx, Vals)); } + if (Attrs.IsParallel) { + AccGroup = MDNode::getDistinct(Ctx, {}); + Args.push_back(MDNode::get( + Ctx, {MDString::get(Ctx, "llvm.loop.parallel_accesses"), AccGroup})); + } + // Set the first operand to itself. MDNode *LoopID = MDNode::get(Ctx, Args); LoopID->replaceOperandWith(0, LoopID); @@ -150,7 +156,8 @@ void LoopAttributes::clear() { LoopInfo::LoopInfo(BasicBlock *Header, const LoopAttributes &Attrs, const llvm::DebugLoc &StartLoc, const llvm::DebugLoc &EndLoc) : LoopID(nullptr), Header(Header), Attrs(Attrs) { - LoopID = createMetadata(Header->getContext(), Attrs, StartLoc, EndLoc); + LoopID = + createMetadata(Header->getContext(), Attrs, StartLoc, EndLoc, AccGroup); } void LoopInfoStack::push(BasicBlock *Header, const llvm::DebugLoc &StartLoc, @@ -328,6 +335,21 @@ void LoopInfoStack::pop() { } void LoopInfoStack::InsertHelper(Instruction *I) const { + if (I->mayReadOrWriteMemory()) { + SmallVector<Metadata *, 4> AccessGroups; + for (const LoopInfo &AL : Active) { + // Here we assume that every loop that has an access group is parallel. + if (MDNode *Group = AL.getAccessGroup()) + AccessGroups.push_back(Group); + } + MDNode *UnionMD = nullptr; + if (AccessGroups.size() == 1) + UnionMD = cast<MDNode>(AccessGroups[0]); + else if (AccessGroups.size() >= 2) + UnionMD = MDNode::get(I->getContext(), AccessGroups); + I->setMetadata("llvm.access.group", UnionMD); + } + if (!hasInfo()) return; @@ -343,18 +365,4 @@ void LoopInfoStack::InsertHelper(Instruction *I) const { } return; } - - if (I->mayReadOrWriteMemory()) { - SmallVector<Metadata *, 2> ParallelLoopIDs; - for (const LoopInfo &AL : Active) - if (AL.getAttributes().IsParallel) - ParallelLoopIDs.push_back(AL.getLoopID()); - - MDNode *ParallelMD = nullptr; - if (ParallelLoopIDs.size() == 1) - ParallelMD = cast<MDNode>(ParallelLoopIDs[0]); - else if (ParallelLoopIDs.size() >= 2) - ParallelMD = MDNode::get(I->getContext(), ParallelLoopIDs); - I->setMetadata("llvm.mem.parallel_loop_access", ParallelMD); - } } diff --git a/clang/lib/CodeGen/CGLoopInfo.h b/clang/lib/CodeGen/CGLoopInfo.h index 466fdc9fedd..201cbb7894b 100644 --- a/clang/lib/CodeGen/CGLoopInfo.h +++ b/clang/lib/CodeGen/CGLoopInfo.h @@ -84,6 +84,9 @@ public: /// Get the set of attributes active for this loop. const LoopAttributes &getAttributes() const { return Attrs; } + /// Return this loop's access group or nullptr if it does not have one. + llvm::MDNode *getAccessGroup() const { return AccGroup; } + private: /// Loop ID metadata. llvm::MDNode *LoopID; @@ -91,6 +94,8 @@ private: llvm::BasicBlock *Header; /// The attributes for this loop. LoopAttributes Attrs; + /// The access group for memory accesses parallel to this loop. + llvm::MDNode *AccGroup = nullptr; }; /// A stack of loop information corresponding to loop nesting levels. |