Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,28 @@ def NVVM_GriddepcontrolLaunchDependentsOp
}];
}

//===----------------------------------------------------------------------===//
// NVVM Mapa Op
//===----------------------------------------------------------------------===//

def NVVM_MapaOp: NVVM_Op<"mapa",
[TypesMatchWith<"`res` and `a` should have the same type",
"a", "res", "$_self">]> {
let results = (outs AnyTypeOf<[LLVM_PointerGeneric, LLVM_PointerShared]>:$res);
let arguments = (ins AnyTypeOf<[LLVM_PointerGeneric, LLVM_PointerShared]>:$a, I32:$b);

string llvmBuilder = [{
int addrSpace = llvm::cast<LLVMPointerType>(op.getA().getType()).getAddressSpace();

bool isSharedMemory = addrSpace == NVVM::NVVMMemorySpace::kSharedMemorySpace;

auto intId = isSharedMemory? llvm::Intrinsic::nvvm_mapa_shared_cluster : llvm::Intrinsic::nvvm_mapa;
$res = createIntrinsicCall(builder, intId, {$a, $b});
}];

let assemblyFormat = "$a`,` $b attr-dict `:` type($a) `->` type($res)";
}

def NVVM_Exit : NVVM_Op<"exit"> {
let summary = "Exit Op";
let description = [{
Expand Down
8 changes: 8 additions & 0 deletions mlir/test/Dialect/LLVMIR/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,14 @@ func.func @cp_async(%arg0: !llvm.ptr<3>, %arg1: !llvm.ptr<1>) {

// -----

func.func @mapa(%a: !llvm.ptr, %b : i32) {
// expected-error @below {{`res` and `a` should have the same type}}
%0 = nvvm.mapa %a, %b: !llvm.ptr -> !llvm.ptr<3>
return
}

// -----

func.func @gep_struct_variable(%arg0: !llvm.ptr, %arg1: i32, %arg2: i32) {
// expected-error @below {{op expected index 1 indexing a struct to be constant}}
llvm.getelementptr %arg0[%arg1, %arg1] : (!llvm.ptr, i32, i32) -> !llvm.ptr, !llvm.struct<(i32)>
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/Dialect/LLVMIR/nvvm.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,15 @@ func.func @griddepcontrol_launch_dependents()
return
}

// CHECK-LABEL: @mapa
func.func @mapa(%a: !llvm.ptr, %a_shared: !llvm.ptr<3>, %b : i32) {
// CHECK: nvvm.mapa %{{.*}}
%0 = nvvm.mapa %a, %b: !llvm.ptr -> !llvm.ptr
// CHECK: nvvm.mapa %{{.*}}
%1 = nvvm.mapa %a_shared, %b: !llvm.ptr<3> -> !llvm.ptr<3>
return
}

// -----

// Just check these don't emit errors.
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/Target/LLVMIR/nvvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,13 @@ llvm.func @nvvm_griddepcontrol_launch_dependents() {
nvvm.griddepcontrol.launch.dependents
llvm.return
}

// -----
// CHECK-LABEL: @nvvm_mapa
llvm.func @nvvm_mapa(%a: !llvm.ptr, %a_shared: !llvm.ptr<3>, %b : i32) {
// CHECK-LLVM: call ptr @llvm.nvvm.mapa(ptr %{{.*}}, i32 %{{.*}})
%0 = nvvm.mapa %a, %b: !llvm.ptr -> !llvm.ptr
// CHECK-LLVM: call ptr addrspace(3) @llvm.nvvm.mapa.shared.cluster(ptr addrspace(3) %{{.*}}, i32 %{{.*}})
%1 = nvvm.mapa %a_shared, %b: !llvm.ptr<3> -> !llvm.ptr<3>
llvm.return
}