[llvm] r282897 - [Coroutines] Part 15a: Lower coro.subfn.addr in CoroCleanup
Gor Nishanov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 30 11:41:36 PDT 2016
Author: gornishanov
Date: Fri Sep 30 13:41:35 2016
New Revision: 282897
URL: http://llvm.org/viewvc/llvm-project?rev=282897&view=rev
Log:
[Coroutines] Part 15a: Lower coro.subfn.addr in CoroCleanup
Summary: Not all coro.subfn.addr intrinsics can be eliminated in CoroElide through devirtualization. Those that remain need to be lowered in CoroCleanup.
Reviewers: majnemer
Subscribers: llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D24412
Added:
llvm/trunk/test/Transforms/Coroutines/coro-cleanup.ll
Modified:
llvm/trunk/lib/Transforms/Coroutines/CoroCleanup.cpp
llvm/trunk/lib/Transforms/Coroutines/Coroutines.cpp
Modified: llvm/trunk/lib/Transforms/Coroutines/CoroCleanup.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Coroutines/CoroCleanup.cpp?rev=282897&r1=282896&r2=282897&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Coroutines/CoroCleanup.cpp (original)
+++ llvm/trunk/lib/Transforms/Coroutines/CoroCleanup.cpp Fri Sep 30 13:41:35 2016
@@ -10,6 +10,7 @@
//===----------------------------------------------------------------------===//
#include "CoroInternal.h"
+#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Pass.h"
@@ -22,7 +23,8 @@ using namespace llvm;
namespace {
// Created on demand if CoroCleanup pass has work to do.
struct Lowerer : coro::LowererBase {
- Lowerer(Module &M) : LowererBase(M) {}
+ IRBuilder<> Builder;
+ Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
bool lowerRemainingCoroIntrinsics(Function &F);
};
}
@@ -36,6 +38,23 @@ static void simplifyCFG(Function &F) {
FPM.doFinalization();
}
+static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
+ Builder.SetInsertPoint(SubFn);
+ Value *FrameRaw = SubFn->getFrame();
+ int Index = SubFn->getIndex();
+
+ auto *FrameTy = StructType::get(
+ SubFn->getContext(), {Builder.getInt8PtrTy(), Builder.getInt8PtrTy()});
+ PointerType *FramePtrTy = FrameTy->getPointerTo();
+
+ Builder.SetInsertPoint(SubFn);
+ auto *FramePtr = Builder.CreateBitCast(FrameRaw, FramePtrTy);
+ auto *Gep = Builder.CreateConstInBoundsGEP2_32(FrameTy, FramePtr, 0, Index);
+ auto *Load = Builder.CreateLoad(Gep);
+
+ SubFn->replaceAllUsesWith(Load);
+}
+
bool Lowerer::lowerRemainingCoroIntrinsics(Function &F) {
bool Changed = false;
@@ -57,6 +76,9 @@ bool Lowerer::lowerRemainingCoroIntrinsi
case Intrinsic::coro_id:
II->replaceAllUsesWith(ConstantTokenNone::get(Context));
break;
+ case Intrinsic::coro_subfn_addr:
+ lowerSubFn(Builder, cast<CoroSubFnInst>(II));
+ break;
}
II->eraseFromParent();
Changed = true;
@@ -87,7 +109,8 @@ struct CoroCleanup : FunctionPass {
// in the module.
bool doInitialization(Module &M) override {
if (coro::declaresIntrinsics(M, {"llvm.coro.alloc", "llvm.coro.begin",
- "llvm.coro.free", "llvm.coro.id"}))
+ "llvm.coro.subfn.addr", "llvm.coro.free",
+ "llvm.coro.id"}))
L = llvm::make_unique<Lowerer>(M);
return false;
}
Modified: llvm/trunk/lib/Transforms/Coroutines/Coroutines.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Coroutines/Coroutines.cpp?rev=282897&r1=282896&r2=282897&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Coroutines/Coroutines.cpp (original)
+++ llvm/trunk/lib/Transforms/Coroutines/Coroutines.cpp Fri Sep 30 13:41:35 2016
@@ -107,7 +107,7 @@ static bool isCoroutineIntrinsicName(Str
"llvm.coro.done", "llvm.coro.end", "llvm.coro.frame",
"llvm.coro.free", "llvm.coro.id", "llvm.coro.param",
"llvm.coro.promise", "llvm.coro.resume", "llvm.coro.save",
- "llvm.coro.size", "llvm.coro.suspend",
+ "llvm.coro.size", "llvm.coro.subfn.addr", "llvm.coro.suspend",
};
return Intrinsic::lookupLLVMIntrinsicByName(CoroIntrinsics, Name) != -1;
}
Added: llvm/trunk/test/Transforms/Coroutines/coro-cleanup.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Coroutines/coro-cleanup.ll?rev=282897&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Coroutines/coro-cleanup.ll (added)
+++ llvm/trunk/test/Transforms/Coroutines/coro-cleanup.ll Fri Sep 30 13:41:35 2016
@@ -0,0 +1,18 @@
+; Make sure that all library helper coro intrinsics are lowered.
+; RUN: opt < %s -O0 -enable-coroutines -S | FileCheck %s
+
+; CHECK-LABEL: @uses_library_support_coro_intrinsics(
+; CHECK-NOT: @llvm.coro
+; CHECK: ret void
+define void @uses_library_support_coro_intrinsics(i8* %hdl) {
+entry:
+ call void @llvm.coro.resume(i8* %hdl)
+ call void @llvm.coro.destroy(i8* %hdl)
+ call i1 @llvm.coro.done(i8* %hdl)
+ ret void
+}
+
+declare void @llvm.coro.resume(i8*)
+declare void @llvm.coro.destroy(i8*)
+declare i1 @llvm.coro.done(i8*)
+
More information about the llvm-commits
mailing list