def LLVM_AllocaOp : LLVM_Op<"alloca">, LLVM_MemOpPatterns {
let arguments = (ins AnyInteger:$arraySize,
OptionalAttr<I64Attr>:$alignment,
- OptionalAttr<TypeAttr>:$elem_type);
+ OptionalAttr<TypeAttr>:$elem_type,
+ UnitAttr:$inalloca);
let results = (outs Res<LLVM_AnyPointer, "",
[MemAlloc<AutomaticAllocationScopeResource>]>:$res);
string llvmInstName = "Alloca";
: op.getType().cast<LLVMPointerType>().getElementType());
auto *inst = builder.CreateAlloca(elementType, addrSpace, $arraySize);
}] # setAlignmentCode # [{
+ inst->setUsedWithInAlloca($inalloca);
$res = inst;
}];
- // FIXME: Import attributes.
string mlirBuilder = [{
auto *allocaInst = cast<llvm::AllocaInst>(inst);
Type allocatedType =
moduleImport.convertType(allocaInst->getAllocatedType());
unsigned alignment = allocaInst->getAlign().value();
$res = $_builder.create<LLVM::AllocaOp>(
- $_location, $_resultType, allocatedType, $arraySize, alignment);
+ $_location, $_resultType, $arraySize,
+ alignment == 0 ? IntegerAttr() : $_builder.getI64IntegerAttr(alignment),
+ TypeAttr::get(allocatedType), allocaInst->isUsedWithInAlloca());
}];
let builders = [
OpBuilder<(ins "Type":$resultType, "Value":$arraySize,
"pass the allocated type explicitly if opaque pointers are used");
if (alignment == 0)
return build($_builder, $_state, resultType, arraySize, IntegerAttr(),
- TypeAttr());
+ TypeAttr(), false);
build($_builder, $_state, resultType, arraySize,
- $_builder.getI64IntegerAttr(alignment), TypeAttr());
+ $_builder.getI64IntegerAttr(alignment), TypeAttr(), false);
}]>,
OpBuilder<(ins "Type":$resultType, "Type":$elementType, "Value":$arraySize,
CArg<"unsigned", "0">:$alignment),
build($_builder, $_state, resultType, arraySize,
alignment == 0 ? IntegerAttr()
: $_builder.getI64IntegerAttr(alignment),
- elemTypeAttr);
+ elemTypeAttr, false);
}]>
];
auto funcTy =
FunctionType::get(getContext(), {getArraySize().getType()}, {getType()});
+ if (getInalloca())
+ p << " inalloca";
+
p << ' ' << getArraySize() << " x " << elemTy;
if (getAlignment() && *getAlignment() != 0)
- p.printOptionalAttrDict((*this)->getAttrs(), {kElemTypeAttrName});
- else
p.printOptionalAttrDict((*this)->getAttrs(),
- {"alignment", kElemTypeAttrName});
+ {kElemTypeAttrName, getInallocaAttrName()});
+ else
+ p.printOptionalAttrDict(
+ (*this)->getAttrs(),
+ {getAlignmentAttrName(), kElemTypeAttrName, getInallocaAttrName()});
p << " : " << funcTy;
}
-// <operation> ::= `llvm.alloca` ssa-use `x` type attribute-dict?
-// `:` type `,` type
+// <operation> ::= `llvm.alloca` `inalloca`? ssa-use `x` type
+// attribute-dict? `:` type `,` type
ParseResult AllocaOp::parse(OpAsmParser &parser, OperationState &result) {
OpAsmParser::UnresolvedOperand arraySize;
Type type, elemType;
SMLoc trailingTypeLoc;
+
+ if (succeeded(parser.parseOptionalKeyword("inalloca")))
+ result.addAttribute(getInallocaAttrName(result.name),
+ UnitAttr::get(parser.getContext()));
+
if (parser.parseOperand(arraySize) || parser.parseKeyword("x") ||
parser.parseType(elemType) ||
parser.parseOptionalAttrDict(result.attributes) || parser.parseColon() ||