aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-02-14 22:16:35 +0000
committerMike Stump <mrs@apple.com>2009-02-14 22:16:35 +0000
commit67a6448a8d52ae46d1cba4e474f9f6b3968d2ff9 (patch)
tree14a831dcb5e300c620837596f17990fcd40ac9a0
parent3ab75bde6d8d2798a1f400b9335d359e25fb1765 (diff)
Generate the helper function for blocks. Now basic codegen is
starting to work for blocks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64570 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGBlocks.cpp18
-rw-r--r--lib/CodeGen/CGExprConstant.cpp5
-rw-r--r--lib/CodeGen/CGExprScalar.cpp2
-rw-r--r--lib/CodeGen/CodeGenFunction.h13
-rw-r--r--lib/CodeGen/CodeGenModule.h2
5 files changed, 25 insertions, 15 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index cb9de169d7..ecc9406b2f 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -107,7 +107,7 @@ llvm::Constant *CodeGenModule::getNSConcreteStackBlock() {
return NSConcreteStackBlock;
}
-llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp() {
+llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
// FIXME: Push up
bool BlockHasCopyDispose = false;
bool insideFunction = false;
@@ -147,8 +147,12 @@ llvm::Constant *CodeGenFunction::BuildBlockLiteralTmp() {
Elts.push_back(C);
// __FuncPtr
- // FIXME: Build this up.
- Elts.push_back(C);
+ std::string Name;
+ if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurFuncDecl))
+ Name = ND->getNameAsString();
+ BlockInfo Info(0, Name);
+ llvm::Function *Fn = CodeGenFunction(*this).GenerateBlockFunction(BE, Info);
+ Elts.push_back(Fn);
// __descriptor
Elts.push_back(BuildDescriptorBlockDecl());
@@ -287,7 +291,8 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) {
Func, Args);
}
-llvm::Constant *CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE) {
+llvm::Constant *
+CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE, std::string n) {
// Generate the block descriptor.
const llvm::Type *UnsignedLongTy = Types.ConvertType(Context.UnsignedLongTy);
const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(
@@ -316,7 +321,7 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE) {
// Generate the constants for the block literal.
llvm::Constant *LiteralFields[5];
- CodeGenFunction::BlockInfo Info(0, "global");
+ CodeGenFunction::BlockInfo Info(0, n);
llvm::Function *Fn = CodeGenFunction(*this).GenerateBlockFunction(BE, Info);
// isa
@@ -371,8 +376,7 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(const BlockExpr *Expr,
const CGFunctionInfo &FI =
CGM.getTypes().getFunctionInfo(FTy->getResultType(), Args);
- std::string Name = std::string("__block_function_") + Info.NameSuffix;
-
+ std::string Name = std::string("__") + Info.Name + "_block_invoke_";
CodeGenTypes &Types = CGM.getTypes();
const llvm::FunctionType *LTy = Types.GetFunctionType(FI, FTy->isVariadic());
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index bfb523bb32..aa5d37dd1f 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -372,7 +372,10 @@ public:
}
llvm::Constant *VisitBlockExpr(const BlockExpr *E) {
- return CGM.GetAddrOfGlobalBlock(E);
+ const char *Name = "";
+ if (const NamedDecl *ND = dyn_cast<NamedDecl>(CGF->CurFuncDecl))
+ Name = ND->getNameAsString().c_str();
+ return CGM.GetAddrOfGlobalBlock(E, Name);
}
// Utility methods
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 164d57eb71..f5a1cf0525 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -1369,7 +1369,7 @@ Value *ScalarExprEmitter::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) {
Value *ScalarExprEmitter::VisitBlockExpr(const BlockExpr *BE) {
- llvm::Constant *C = CGF.BuildBlockLiteralTmp();
+ llvm::Constant *C = CGF.BuildBlockLiteralTmp(BE);
const llvm::PointerType *PtrToInt8Ty
= llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index ff505856f5..038db1b305 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -88,7 +88,7 @@ public:
const llvm::Type *LLVMIntTy;
uint32_t LLVMPointerWidth;
- llvm::Constant *BuildBlockLiteralTmp();
+ llvm::Constant *BuildBlockLiteralTmp(const BlockExpr *);
llvm::Constant *BuildDescriptorBlockDecl();
public:
@@ -250,13 +250,16 @@ public:
void GenerateObjCSetter(ObjCImplementationDecl *IMP,
const ObjCPropertyImplDecl *PID);
+ /// BlockInfo - Information to generate a block literal.
struct BlockInfo {
+ /// BlockLiteralTy - The type of the block literal.
const llvm::Type *BlockLiteralTy;
-
- const char *NameSuffix;
- BlockInfo(const llvm::Type *blt, const char *ns)
- : BlockLiteralTy(blt), NameSuffix(ns) {}
+ /// Name - the name of the function this block was created for, if any
+ std::string Name;
+
+ BlockInfo(const llvm::Type *blt, std::string n)
+ : BlockLiteralTy(blt), Name(n) {}
};
llvm::Function *GenerateBlockFunction(const BlockExpr *Expr,
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index 4c2aeb75ac..e5c412a75c 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -219,7 +219,7 @@ public:
llvm::Constant *GetAddrOfConstantCString(const std::string &str,
const char *GlobalName=0);
- llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE);
+ llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, std::string);
/// getBuiltinLibFunction - Given a builtin id for a function like
/// "__builtin_fabsf", return a Function* for "fabsf".