[PATCH] D86071: [MLIR][OpenMP] Add omp.do operation

Kiran Chandramohan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 11:13:39 PDT 2020


kiranchandramohan added a comment.

OK. I had almost typed in discourse. I primarily wanted to ask the following question before posing a general question in llvm-dev about the dialect or the OpenMP IRBuilder.

Consider that we want to parallelize an SCF loop with OpenMP. We can add the omp.do operation around the loop. This would look like.

  func @some_op_inside_loop(%arg0: index, %arg1: index, %arg2: index) {
  omp.do {
    scf.for %i = %arg0 to %arg1 step %arg2 {
      "some.op"(%i) : (index) -> ()
    }
  }
    return
  }

One way to pass this to the OpenMP IR Builder would be as follows. The loop exists as control flow. (Question: Can we have index, start, end and step variables here as operands or attributes?)

    llvm.func @some_op_inside_loop(%arg0: !llvm.i64, %arg1: !llvm.i64, %arg2: !llvm.i64) {
  omp.do {
      llvm.br ^bb1(%arg0 : !llvm.i64)
    ^bb1(%0: !llvm.i64):  // 2 preds: ^bb0, ^bb2
      %1 = llvm.icmp "slt" %0, %arg1 : !llvm.i64
      llvm.cond_br %1, ^bb2, ^bb3
    ^bb2:  // pred: ^bb1
      "some.op"(%0) : (!llvm.i64) -> ()
      %2 = llvm.add %0, %arg2 : !llvm.i64
      llvm.br ^bb1(%2 : !llvm.i64)
    ^bb3:  // pred: ^bb1
  }
      llvm.return
    }

Another way would be as follows where the loop exists without the control flow of the loop.

  llvm.func @some_op_inside_loop(%arg0: !llvm.i64, %arg1: !llvm.i64, %arg2: !llvm.i64) {
  omp.do index(%i: !llvm.i64) start(%arg0: !llvm.i64) stop(%arg1: !llvm.i64) step(%arg2: !llvm.i64) {
      "some.op"(%i) : (!llvm.i64) -> ()
  }
    return
  }

The question I have for @jdoerfert is which one of these will be preferable for the OpenMP IRBuilder? And the question I have for @ftynse is what is the issue that is there in these schemes?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86071/new/

https://reviews.llvm.org/D86071



More information about the llvm-commits mailing list