From acb8b516ee9662f3ab78f1401ccb563d54aecc43 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 6 Dec 2019 01:08:40 -0800 Subject: [PATCH] LLVM::AddressOfOp: properly take into account the address space The AddressOf operation in the LLVM dialect return a pointer to a global variable. The latter may be in a non-default address space as indicated by the "addr_space" attribute. Check that the address space of the pointer returned by AddressOfOp matches that of the referenced GlobalOp. Update the AddressOfOp builder to respect this constraint. PiperOrigin-RevId: 284138860 Change-Id: I2ada419c22b4ba7ac0788cefff199123e4634344 --- third_party/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 5 +++-- third_party/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/third_party/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/third_party/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 573542ba838..66d9ba3f750 100644 --- a/third_party/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/third_party/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -509,8 +509,9 @@ def LLVM_AddressOfOp OpBuilder<"Builder *builder, OperationState &result, GlobalOp global, " "ArrayRef attrs = {}", [{ - build(builder, result, global.getType().getPointerTo(), global.sym_name(), - attrs);}]> + build(builder, result, + global.getType().getPointerTo(global.addr_space().getZExtValue()), + global.sym_name(), attrs);}]> ]; let extraClassDeclaration = [{ diff --git a/third_party/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/third_party/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index 00911012c1d..fb4555674eb 100644 --- a/third_party/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/third_party/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -825,7 +825,8 @@ static LogicalResult verify(AddressOfOp op) { return op.emitOpError( "must reference a global defined by 'llvm.mlir.global'"); - if (global.getType().getPointerTo() != op.getResult()->getType()) + if (global.getType().getPointerTo(global.addr_space().getZExtValue()) != + op.getResult()->getType()) return op.emitOpError( "the type must be a pointer to the type of the referred global");