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

View File

@ -89,7 +89,7 @@ private:
ModuleOp mlirModule; ModuleOp mlirModule;
std::unique_ptr<llvm::Module> llvmModule; 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; llvm::DenseMap<Operation *, llvm::GlobalValue *> globalsMapping;
protected: protected:

View File

@ -779,7 +779,7 @@ static void printUndefOp(OpAsmPrinter *p, UndefOp &op) {
*p << " : " << op.res()->getType(); *p << " : " << op.res()->getType();
} }
// <operation> ::= `llvm.undef` attribute-dict? : type // <operation> ::= `llvm.mlir.undef` attribute-dict? : type
static ParseResult parseUndefOp(OpAsmParser *parser, OperationState *result) { static ParseResult parseUndefOp(OpAsmParser *parser, OperationState *result) {
Type type; Type type;
@ -825,7 +825,8 @@ static ParseResult parseAddressOfOp(OpAsmParser *parser,
static LogicalResult verify(AddressOfOp op) { static LogicalResult verify(AddressOfOp op) {
auto global = op.getGlobal(); auto global = op.getGlobal();
if (!global) 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()) if (global.getType().getPointerTo() != op.getResult()->getType())
return op.emitOpError( return op.emitOpError(
@ -844,7 +845,7 @@ static void printConstantOp(OpAsmPrinter *p, ConstantOp &op) {
*p << " : " << op.res()->getType(); *p << " : " << op.res()->getType();
} }
// <operation> ::= `llvm.constant` `(` attribute `)` attribute-list? : type // <operation> ::= `llvm.mlir.constant` `(` attribute `)` attribute-list? : type
static ParseResult parseConstantOp(OpAsmParser *parser, static ParseResult parseConstantOp(OpAsmParser *parser,
OperationState *result) { OperationState *result) {
Attribute valueAttr; Attribute valueAttr;
@ -894,8 +895,8 @@ static void printGlobalOp(OpAsmPrinter *p, GlobalOp op) {
p->printType(op.type()); p->printType(op.type());
} }
// <operation> ::= `llvm.global` `constant`? `@` identifier `(` attribute `)` // <operation> ::= `llvm.mlir.global` `constant`? `@` identifier
// attribute-list? (`:` type)? // `(` attribute `)` attribute-list? (`:` type)?
// //
// The type can be omitted for string attributes, in which case it will be // 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]. // 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(); 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() { void ModuleTranslation::convertGlobals() {
for (auto op : mlirModule.getOps<LLVM::GlobalOp>()) { for (auto op : mlirModule.getOps<LLVM::GlobalOp>()) {
llvm::Constant *cst; llvm::Constant *cst;