[Openmp-commits] [lldb] [clang] [llvm] [libcxx] [clang-tools-extra] [mlir] [openmp] [SEH] Fix register liveness verification for EHa (PR #76933)

via Openmp-commits openmp-commits at lists.llvm.org
Fri Jan 5 01:06:09 PST 2024


================
@@ -3347,10 +3348,37 @@ void MachineVerifier::verifyLiveRangeSegment(const LiveRange &LR,
     OwnerLI.computeSubRangeUndefs(Undefs, LaneMask, *MRI, *Indexes);
   }
 
+  bool IsEHa = MF->getMMI().getModule()->getModuleFlag("eh-asynch");
   while (true) {
     assert(LiveInts->isLiveInToMBB(LR, &*MFI));
-    // We don't know how to track physregs into a landing pad.
-    if (!Reg.isVirtual() && MFI->isEHPad()) {
+    auto IsSEHHandler = [](const MachineBasicBlock &Handler) -> bool {
+      if (!Handler.isMachineBlockAddressTaken())
+        return false;
+
+      for (const User *U : Handler.getBasicBlock()->users()) {
+        if (!isa<InvokeInst>(U))
+          continue;
+        const Function *Fn = cast<CallBase>(U)->getCalledFunction();
+        if (!Fn || !Fn->isIntrinsic())
+          continue;
+
+        switch (Fn->getIntrinsicID()) {
+        default:
+          continue;
+        case Intrinsic::seh_scope_begin:
+        case Intrinsic::seh_scope_end:
+        case Intrinsic::seh_try_begin:
+        case Intrinsic::seh_try_end:
+          return true;
+        }
+      }
+      return false;
+    };
+
+    // TODO: we don't know how to track physregs into a landing pad. For async
+    // EH, the virtual reg lives before scope begin, but we don't know seh scope
----------------
HaohaiWen wrote:

seh_scope_begin/seh_scope_end is lowered to fall through jmp which can be eliminated.
e.g.
```
BB0:
  instA
  jmp BB1:
BB1:
  invoke llvm.seh.scope.begin to BB2
BB2:
  instB
```

Those BB0, BB1, BB2 can be optimized to
```
MBB0:
   EH_LABEL
   instA
   EH_LABEL
   EH_LABEL
   instB
   EH_LABEL
```

We don't know which MBB the BB2 is mapped to. We also don't know which EH_LABEL the llvm.seh.scope.begin was located.


https://github.com/llvm/llvm-project/pull/76933


More information about the Openmp-commits mailing list