LLVM dialect: prefix auxiliary operations with "mlir."

Some of the operations in the LLVM dialect are required to model the LLVM IR in
MLIR, for example "constant" operations are needed to declare a constant value
since MLIR, unlike LLVM, does not support immediate values as operands.  To
avoid confusion with actual LLVM operations, we prefix such axuiliary
operations with "mlir.".

PiperOrigin-RevId: 266942838
This commit is contained in:
A. Unique TensorFlower 2019-09-03 09:10:24 -07:00 committed by TensorFlower Gardener
parent 3904672376
commit c2dbce7f9e
4 changed files with 17 additions and 14 deletions

View File

@ -442,10 +442,10 @@ def LLVM_UnreachableOp : LLVM_TerminatorOp<"unreachable", []> {
let printer = [{ *p << getOperationName(); }];
}
// Pseudo-operations (do not appear in LLVM IR but necessary for the dialect to
// work correctly).
// Auxiliary operations (do not appear in LLVM IR but necessary for the dialect
// to work correctly).
def LLVM_AddressOfOp
: LLVM_OneResultOp<"addressof">,
: LLVM_OneResultOp<"mlir.addressof">,
Arguments<(ins SymbolRefAttr:$global_name)> {
let builders = [
OpBuilder<"Builder *builder, OperationState *result, LLVMType resType, "
@ -461,7 +461,8 @@ def LLVM_AddressOfOp
];
let extraClassDeclaration = [{
/// Return the llvm.global operation that defined the value referenced here.
/// Return the llvm.mlir.global operation that defined the value referenced
/// here.
GlobalOp getGlobal();
}];
@ -471,7 +472,7 @@ def LLVM_AddressOfOp
}
def LLVM_GlobalOp
: LLVM_ZeroResultOp<"global">,
: LLVM_ZeroResultOp<"mlir.global">,
Arguments<(ins TypeAttr:$type, UnitAttr:$constant, StrAttr:$sym_name,
AnyAttr:$value)> {
@ -534,13 +535,13 @@ def LLVM_LLVMFuncOp : LLVM_ZeroResultOp<"func",
}];
}
def LLVM_UndefOp : LLVM_OneResultOp<"undef", [NoSideEffect]>,
def LLVM_UndefOp : LLVM_OneResultOp<"mlir.undef", [NoSideEffect]>,
LLVM_Builder<"$res = llvm::UndefValue::get($_resultType);"> {
let parser = [{ return parseUndefOp(parser, result); }];
let printer = [{ printUndefOp(p, *this); }];
}
def LLVM_ConstantOp
: LLVM_OneResultOp<"constant", [NoSideEffect]>,
: LLVM_OneResultOp<"mlir.constant", [NoSideEffect]>,
Arguments<(ins AnyAttr:$value)>,
LLVM_Builder<"$res = getLLVMConstant($_resultType, $value, $_location);">
{

View File

@ -89,7 +89,7 @@ private:
ModuleOp mlirModule;
std::unique_ptr<llvm::Module> llvmModule;
// Mappings between llvm.global definitions and corresponding globals.
// Mappings between llvm.mlir.global definitions and corresponding globals.
llvm::DenseMap<Operation *, llvm::GlobalValue *> globalsMapping;
protected:

View File

@ -779,7 +779,7 @@ static void printUndefOp(OpAsmPrinter *p, UndefOp &op) {
*p << " : " << op.res()->getType();
}
// <operation> ::= `llvm.undef` attribute-dict? : type
// <operation> ::= `llvm.mlir.undef` attribute-dict? : type
static ParseResult parseUndefOp(OpAsmParser *parser, OperationState *result) {
Type type;
@ -825,7 +825,8 @@ static ParseResult parseAddressOfOp(OpAsmParser *parser,
static LogicalResult verify(AddressOfOp op) {
auto global = op.getGlobal();
if (!global)
return op.emitOpError("must reference a global defined by 'llvm.global'");
return op.emitOpError(
"must reference a global defined by 'llvm.mlir.global'");
if (global.getType().getPointerTo() != op.getResult()->getType())
return op.emitOpError(
@ -844,7 +845,7 @@ static void printConstantOp(OpAsmPrinter *p, ConstantOp &op) {
*p << " : " << op.res()->getType();
}
// <operation> ::= `llvm.constant` `(` attribute `)` attribute-list? : type
// <operation> ::= `llvm.mlir.constant` `(` attribute `)` attribute-list? : type
static ParseResult parseConstantOp(OpAsmParser *parser,
OperationState *result) {
Attribute valueAttr;
@ -894,8 +895,8 @@ static void printGlobalOp(OpAsmPrinter *p, GlobalOp op) {
p->printType(op.type());
}
// <operation> ::= `llvm.global` `constant`? `@` identifier `(` attribute `)`
// attribute-list? (`:` type)?
// <operation> ::= `llvm.mlir.global` `constant`? `@` identifier
// `(` attribute `)` attribute-list? (`:` type)?
//
// The type can be omitted for string attributes, in which case it will be
// inferred from the value of the string as [strlen(value) x i8].

View File

@ -297,7 +297,8 @@ LogicalResult ModuleTranslation::convertBlock(Block &bb, bool ignoreArguments) {
return success();
}
// Create named global variables that correspond to llvm.global definitions.
// Create named global variables that correspond to llvm.mlir.global
// definitions.
void ModuleTranslation::convertGlobals() {
for (auto op : mlirModule.getOps<LLVM::GlobalOp>()) {
llvm::Constant *cst;