let cppNamespace = "::mlir::LLVM";
}
-def LLVM_AddressOfOp : LLVM_Op<"mlir.addressof", [NoSideEffect]> {
+def LLVM_AddressOfOp : LLVM_Op<"mlir.addressof",
+ [NoSideEffect, DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
let arguments = (ins FlatSymbolRefAttr:$global_name);
let results = (outs LLVM_AnyPointer:$res);
}];
let assemblyFormat = "$global_name attr-dict `:` type($res)";
- let hasVerifier = 1;
}
def LLVM_MetadataOp : LLVM_Op<"metadata", [
// Verifier for LLVM::AddressOfOp.
//===----------------------------------------------------------------------===//
-static Operation *lookupSymbolInModule(Operation *parent, StringRef name) {
- Operation *module = parent;
+static Operation *parentLLVMModule(Operation *op) {
+ Operation *module = op->getParentOp();
while (module && !satisfiesLLVMModule(module))
module = module->getParentOp();
assert(module && "unexpected operation outside of a module");
- return mlir::SymbolTable::lookupSymbolIn(module, name);
+ return module;
}
GlobalOp AddressOfOp::getGlobal() {
return dyn_cast_or_null<GlobalOp>(
- lookupSymbolInModule((*this)->getParentOp(), getGlobalName()));
+ SymbolTable::lookupSymbolIn(parentLLVMModule(*this), getGlobalName()));
}
LLVMFuncOp AddressOfOp::getFunction() {
return dyn_cast_or_null<LLVMFuncOp>(
- lookupSymbolInModule((*this)->getParentOp(), getGlobalName()));
+ SymbolTable::lookupSymbolIn(parentLLVMModule(*this), getGlobalName()));
}
-LogicalResult AddressOfOp::verify() {
+LogicalResult
+AddressOfOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
Operation *symbol =
- lookupSymbolInModule((*this)->getParentOp(), getGlobalName());
+ symbolTable.lookupSymbolIn(parentLLVMModule(*this), getGlobalNameAttr());
auto global = dyn_cast_or_null<GlobalOp>(symbol);
auto function = dyn_cast_or_null<LLVMFuncOp>(symbol);
// them to trigger the attribute type mismatch error.
// expected-error @+1 {{invalid kind of attribute specified}}
llvm.mlir.addressof "foo" : i64 : !llvm.ptr<func<void ()>>
+ llvm.return
}
// -----
func.func @foo() {
// expected-error @+1 {{must reference a global defined by 'llvm.mlir.global'}}
llvm.mlir.addressof @foo : !llvm.ptr<func<void ()>>
+ llvm.return
}
// -----
func.func @bar() {
// expected-error @+1 {{the type must be a pointer to the type of the referenced global}}
llvm.mlir.addressof @foo : !llvm.ptr<i64>
+ llvm.return
}
// -----
llvm.func @bar() {
// expected-error @+1 {{the type must be a pointer to the type of the referenced function}}
llvm.mlir.addressof @foo : !llvm.ptr<i8>
+ llvm.return
}
// -----
func.func @mismatch_addr_space_implicit_global() {
// expected-error @+1 {{pointer address space must match address space of the referenced global}}
llvm.mlir.addressof @g : !llvm.ptr<i64>
+ llvm.return
}
// -----
func.func @mismatch_addr_space() {
// expected-error @+1 {{pointer address space must match address space of the referenced global}}
llvm.mlir.addressof @g : !llvm.ptr<i64, 4>
+ llvm.return
}
// -----
func.func @mismatch_addr_space_opaque() {
// expected-error @+1 {{pointer address space must match address space of the referenced global}}
llvm.mlir.addressof @g : !llvm.ptr<4>
+ llvm.return
}
// -----