Skip to content

Commit

Permalink
[CSI] Fix splitting of predecessors of detach-continutaion blocks to …
Browse files Browse the repository at this point in the history
…maintain Tapir-CFG structure.
  • Loading branch information
neboat committed Feb 26, 2021
1 parent 999bd50 commit 4ea2836
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Instrumentation/CilkSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ static void setupBlock(BasicBlock *BB, DominatorTree *DT, LoopInfo *LI,
// Partition the predecessors of the landing pad.
for (BasicBlock *Pred : predecessors(BB)) {
if (isa<DetachInst>(Pred->getTerminator()) ||
isa<ReattachInst>(Pred->getTerminator()) ||
isDetachedRethrow(Pred->getTerminator()))
DetachPreds.push_back(Pred);
else if (isTaskFrameResume(Pred->getTerminator()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ static void setupBlock(BasicBlock *BB, const TargetLibraryInfo *TLI,
// Partition the predecessors of the landing pad.
for (BasicBlock *Pred : predecessors(BB)) {
if (isa<DetachInst>(Pred->getTerminator()) ||
isa<ReattachInst>(Pred->getTerminator()) ||
isDetachedRethrow(Pred->getTerminator()))
DetachPreds.push_back(Pred);
else if (isTaskFrameResume(Pred->getTerminator()))
Expand Down
67 changes: 67 additions & 0 deletions llvm/test/Transforms/Tapir/csi-detach-continue-split.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
; Check that the CSI pass properly splits the predecessors of a detach-continuation block.
;
; RUN: opt < %s -csi -S -o - | FileCheck %s
; RUN: opt < %s -passes='csi' -S -o - | FileCheck %s

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: argmemonly nounwind willreturn
declare token @llvm.syncregion.start() #0

define dso_local void @QuadNode_addIntersections() local_unnamed_addr #1 {
entry:
%syncreg.i28 = tail call token @llvm.syncregion.start()
br i1 undef, label %if.then.tf, label %if.else

if.then.tf: ; preds = %entry
detach within %syncreg.i28, label %det.achd, label %det.cont.tf

det.achd: ; preds = %if.then.tf
unreachable

det.cont.tf: ; preds = %if.then.tf
detach within %syncreg.i28, label %det.achd1.tf.tf.tf, label %if.end

; CHECK: det.cont.tf:
; CHECK: detach within %syncreg.i28, label %[[DETACHED:.+]], label %[[CONTINUE:.+]]

; CHECK: [[CONTINUE]]:
; CHECK-NEXT: call void @__csi_detach_continue(
; CHECK-NEXT: br label %if.end

det.achd1.tf.tf.tf: ; preds = %det.cont.tf
br label %det.achd1.tf.tf.tf.tf

det.achd1.tf.tf.tf.tf: ; preds = %det.achd1.tf.tf.tf
%tf.i = tail call token @llvm.taskframe.create()
%syncreg.i = tail call token @llvm.syncregion.start() #2
reattach within %syncreg.i28, label %if.end

; CHECK: [[DETACHED]]:
; CHECK: reattach within %syncreg.i28, label %[[CONTINUE]]

if.else: ; preds = %entry
sync within %syncreg.i28, label %if.end

; CHECK: if.else:
; CHECK: sync within %syncreg.i28, label %[[SYNC_SPLIT:.+]]

; CHECK: [[SYNC_SPLIT]]:
; CHECK: call void @__csi_after_sync(
; CHECK: br label %if.end

if.end: ; preds = %if.else, %det.achd1.tf.tf.tf.tf, %det.cont.tf
unreachable
}

; Function Attrs: argmemonly nounwind willreturn
declare token @llvm.taskframe.create() #0

attributes #0 = { argmemonly nounwind willreturn }
attributes #1 = { "use-soft-float"="false" }
attributes #2 = { nounwind }

!llvm.ident = !{!0}

!0 = !{!"clang version 10.0.1 ([email protected]:OpenCilk/opencilk-project.git 94a2a3eb6c9f8dd53def6e21c5ab8ff45acb586f)"}

0 comments on commit 4ea2836

Please sign in to comment.