Commit ac8e22d9 authored by Diego Caballero's avatar Diego Caballero Committed by Scott Cyphers

[MLIR] Add llvm.noalias attribute to nGraph func args (#3232)

Aliasing prevents vectorization and other optimizations in LLVM (dot2d,
for example). I found that LLVM dialect contemplates the possibility of
previous dialects adding llvm.noalias attribute to function arguments so
that the NoAlias attribute is generated in LLVM-IR. This should be good for
now although we should discuss how to model this in Standard dialect and co.
parent 0973ed90
...@@ -125,6 +125,7 @@ namespace ...@@ -125,6 +125,7 @@ namespace
void findOutputValues(); void findOutputValues();
void processFakeInstrs(); void processFakeInstrs();
void insertNoAliasArgAttrs();
Value* insertMemMgrDef(PatternRewriter* rewriter = nullptr); Value* insertMemMgrDef(PatternRewriter* rewriter = nullptr);
private: private:
...@@ -163,6 +164,8 @@ namespace ...@@ -163,6 +164,8 @@ namespace
} }
processFakeInstrs(); processFakeInstrs();
insertNoAliasArgAttrs();
} }
void DialectLoweringPass::populateNGraphToAffineConversionPatterns( void DialectLoweringPass::populateNGraphToAffineConversionPatterns(
...@@ -314,6 +317,23 @@ namespace ...@@ -314,6 +317,23 @@ namespace
} }
} }
/// Add llvm.noalias attribute to all the memref function arguments. We know that this is safe
/// by nGraph op semantics.
void DialectLoweringPass::insertNoAliasArgAttrs()
{
auto func = getModule().getNamedFunction("main");
unsigned int argIdx = 0;
for (auto* arg : func->getArguments())
{
if (arg->getType().isa<MemRefType>())
{
func->setArgAttr(argIdx, "llvm.noalias", BoolAttr::get(true, &getContext()));
}
++argIdx;
}
}
mlir::Function* DialectLoweringPass::getCallDecl(StringRef name, mlir::Function* DialectLoweringPass::getCallDecl(StringRef name,
ArrayRef<Type> args, ArrayRef<Type> args,
ArrayRef<Type> output, ArrayRef<Type> output,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment