diff options
| author | Gor Nishanov <GorNishanov@gmail.com> | 2016-10-27 16:28:31 +0000 |
|---|---|---|
| committer | Gor Nishanov <GorNishanov@gmail.com> | 2016-10-27 16:28:31 +0000 |
| commit | 8df64e940da39899c78493b9b2e330bba5ab48ee (patch) | |
| tree | c1611e0dd4b0304433554fe325c9e1a4895c97c2 /clang/lib/CodeGen | |
| parent | cfb005a0ee6ca75c79805324d377b32d1325774a (diff) | |
| download | bcm5719-llvm-8df64e940da39899c78493b9b2e330bba5ab48ee.tar.gz bcm5719-llvm-8df64e940da39899c78493b9b2e330bba5ab48ee.zip | |
[coroutines] Add allocation and deallocation substatements.
Summary:
SemaCoroutine: Add allocation / deallocation substatements.
CGCoroutine/Test: Emit allocation and deallocation + test.
Reviewers: rsmith
Subscribers: ABataev, EricWF, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D25879
llvm-svn: 285306
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGCoroutine.cpp | 24 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGStmt.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 1 |
3 files changed, 23 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp b/clang/lib/CodeGen/CGCoroutine.cpp index 2f5e8ab2f0f..2fdb1279ece 100644 --- a/clang/lib/CodeGen/CGCoroutine.cpp +++ b/clang/lib/CodeGen/CGCoroutine.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "CodeGenFunction.h" +#include "clang/AST/StmtCXX.h" using namespace clang; using namespace CodeGen; @@ -36,9 +37,10 @@ struct CGCoroData { clang::CodeGen::CodeGenFunction::CGCoroInfo::CGCoroInfo() {} CodeGenFunction::CGCoroInfo::~CGCoroInfo() {} -static bool createCoroData(CodeGenFunction &CGF, +static void createCoroData(CodeGenFunction &CGF, CodeGenFunction::CGCoroInfo &CurCoro, - llvm::CallInst *CoroId, CallExpr const *CoroIdExpr) { + llvm::CallInst *CoroId, + CallExpr const *CoroIdExpr = nullptr) { if (CurCoro.Data) { if (CurCoro.Data->CoroIdExpr) CGF.CGM.Error(CoroIdExpr->getLocStart(), @@ -49,13 +51,27 @@ static bool createCoroData(CodeGenFunction &CGF, else llvm_unreachable("EmitCoroutineBodyStatement called twice?"); - return false; + return; } CurCoro.Data = std::unique_ptr<CGCoroData>(new CGCoroData); CurCoro.Data->CoroId = CoroId; CurCoro.Data->CoroIdExpr = CoroIdExpr; - return true; +} + +void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) { + auto *NullPtr = llvm::ConstantPointerNull::get(Builder.getInt8PtrTy()); + auto &TI = CGM.getContext().getTargetInfo(); + unsigned NewAlign = TI.getNewAlign() / TI.getCharWidth(); + + auto *CoroId = Builder.CreateCall( + CGM.getIntrinsic(llvm::Intrinsic::coro_id), + {Builder.getInt32(NewAlign), NullPtr, NullPtr, NullPtr}); + createCoroData(*this, CurCoro, CoroId); + + EmitScalarExpr(S.getAllocate()); + // FIXME: Emit the rest of the coroutine. + EmitStmt(S.getDeallocate()); } // Emit coroutine intrinsic and patch up arguments of the token type. diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index b4f309353fb..770fc969c09 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -142,6 +142,8 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::GCCAsmStmtClass: // Intentional fall-through. case Stmt::MSAsmStmtClass: EmitAsmStmt(cast<AsmStmt>(*S)); break; case Stmt::CoroutineBodyStmtClass: + EmitCoroutineBody(cast<CoroutineBodyStmt>(*S)); + break; case Stmt::CoreturnStmtClass: CGM.ErrorUnsupported(S, "coroutine"); break; diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 9e9b5c721cd..dade4612ce7 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2311,6 +2311,7 @@ public: void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S); + void EmitCoroutineBody(const CoroutineBodyStmt &S); RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID); void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |

