13 #include "llvm/IR/BasicBlock.h"
14 #include "llvm/IR/Constants.h"
15 #include "llvm/IR/InstrTypes.h"
16 #include "llvm/IR/Instructions.h"
17 #include "llvm/IR/Metadata.h"
18 using namespace clang::CodeGen;
30 auto TempNode = MDNode::getTemporary(Ctx, None);
31 Args.push_back(TempNode.get());
35 Metadata *Vals[] = {MDString::get(Ctx,
"llvm.loop.vectorize.width"),
36 ConstantAsMetadata::get(ConstantInt::get(
38 Args.push_back(MDNode::get(Ctx, Vals));
43 Metadata *Vals[] = {MDString::get(Ctx,
"llvm.loop.interleave.count"),
44 ConstantAsMetadata::get(ConstantInt::get(
46 Args.push_back(MDNode::get(Ctx, Vals));
52 MDString::get(Ctx,
"llvm.loop.vectorize.enable"),
53 ConstantAsMetadata::get(ConstantInt::get(
56 Args.push_back(MDNode::get(Ctx, Vals));
60 MDNode *LoopID = MDNode::get(Ctx, Args);
61 LoopID->replaceOperandWith(0, LoopID);
66 : IsParallel(IsParallel), VectorizerEnable(
LoopAttributes::VecUnspecified),
67 VectorizerWidth(0), VectorizerUnroll(0) {}
77 : LoopID(nullptr), Header(Header), Attrs(Attrs) {
83 for (
const auto *
Attr : Attrs) {
84 const LoopHintAttr *LH = dyn_cast<LoopHintAttr>(
Attr);
90 LoopHintAttr::OptionType Option = LH->getOption();
91 LoopHintAttr::LoopHintState
State = LH->getState();
93 case LoopHintAttr::Vectorize:
94 case LoopHintAttr::Interleave:
95 if (State == LoopHintAttr::AssumeSafety) {
100 case LoopHintAttr::VectorizeWidth:
101 case LoopHintAttr::InterleaveCount:
102 case LoopHintAttr::Unroll:
103 case LoopHintAttr::UnrollCount:
109 Active.push_back(
LoopInfo(Header, StagedAttrs));
115 assert(!Active.empty() &&
"No active loops to pop");
127 if (TerminatorInst *TI = dyn_cast<TerminatorInst>(I)) {
128 for (
unsigned i = 0, ie = TI->getNumSuccessors(); i < ie; ++i)
129 if (TI->getSuccessor(i) == L.
getHeader()) {
130 TI->setMetadata(
"llvm.loop", L.
getLoopID());
137 I->setMetadata(
"llvm.mem.parallel_loop_access", L.
getLoopID());
Attributes that may be specified on loops.
Information used when generating a structured loop.
LoopAttributes(bool IsParallel=false)
llvm::BasicBlock * getHeader() const
Get the header block of this loop.
void pop()
End the current loop.
unsigned VectorizerUnroll
llvm.loop.interleave.count
LVEnableState VectorizerEnable
llvm.loop.vectorize.enable
llvm::MDNode * getLoopID() const
Get the loop id metadata for this loop.
bool IsParallel
Generate llvm.loop.parallel metadata for loads and stores.
void setParallel(bool Enable=true)
Set the next pushed loop as parallel.
static MDNode * createMetadata(LLVMContext &Ctx, const LoopAttributes &Attrs)
unsigned VectorizerWidth
llvm.loop.vectorize.width
LoopInfo(llvm::BasicBlock *Header, const LoopAttributes &Attrs)
Construct a new LoopInfo for the loop with entry Header.
void InsertHelper(llvm::Instruction *I) const
Function called by the CodeGenFunction when an instruction is created.
const LoopAttributes & getAttributes() const
Get the set of attributes active for this loop.
void push(llvm::BasicBlock *Header, llvm::ArrayRef< const Attr * > Attrs=llvm::None)
Begin a new structured loop. The set of staged attributes will be applied to the loop and then cleare...
Attr - This represents one attribute.