[cfe-commits] r64454 - /cfe/trunk/lib/CodeGen/CGBlocks.cpp
Mike Stump
mrs at apple.com
Fri Feb 13 07:32:32 PST 2009
Author: mrs
Date: Fri Feb 13 09:32:32 2009
New Revision: 64454
URL: http://llvm.org/viewvc/llvm-project?rev=64454&view=rev
Log:
Fixup spacing a tad.
Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=64454&r1=64453&r2=64454&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Feb 13 09:32:32 2009
@@ -30,15 +30,15 @@
if (BlockDescriptorType)
return BlockDescriptorType;
- const llvm::Type *UnsignedLongTy =
+ const llvm::Type *UnsignedLongTy =
getTypes().ConvertType(getContext().UnsignedLongTy);
-
+
// struct __block_descriptor {
// unsigned long reserved;
// unsigned long block_size;
// };
- BlockDescriptorType = llvm::StructType::get(UnsignedLongTy,
- UnsignedLongTy,
+ BlockDescriptorType = llvm::StructType::get(UnsignedLongTy,
+ UnsignedLongTy,
NULL);
getModule().addTypeName("struct.__block_descriptor",
@@ -52,12 +52,12 @@
if (GenericBlockLiteralType)
return GenericBlockLiteralType;
- const llvm::Type *Int8PtrTy =
+ const llvm::Type *Int8PtrTy =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
-
- const llvm::Type *BlockDescPtrTy =
+
+ const llvm::Type *BlockDescPtrTy =
llvm::PointerType::getUnqual(getBlockDescriptorType());
-
+
// struct __block_literal_generic {
// void *isa;
// int flags;
@@ -71,35 +71,35 @@
Int8PtrTy,
BlockDescPtrTy,
NULL);
-
+
getModule().addTypeName("struct.__block_literal_generic",
GenericBlockLiteralType);
-
+
return GenericBlockLiteralType;
}
-/// getBlockFunctionType - Given a BlockPointerType, will return the
+/// getBlockFunctionType - Given a BlockPointerType, will return the
/// function type for the block, including the first block literal argument.
static QualType getBlockFunctionType(ASTContext &Ctx,
const BlockPointerType *BPT) {
const FunctionTypeProto *FTy = cast<FunctionTypeProto>(BPT->getPointeeType());
-
+
llvm::SmallVector<QualType, 8> Types;
Types.push_back(Ctx.getPointerType(Ctx.VoidTy));
-
+
for (FunctionTypeProto::arg_type_iterator i = FTy->arg_type_begin(),
e = FTy->arg_type_end(); i != e; ++i)
Types.push_back(*i);
-
+
return Ctx.getFunctionType(FTy->getResultType(),
- &Types[0], Types.size(),
+ &Types[0], Types.size(),
FTy->isVariadic(), 0);
}
RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) {
- const BlockPointerType *BPT =
+ const BlockPointerType *BPT =
E->getCallee()->getType()->getAsBlockPointerType();
-
+
llvm::Value *Callee = EmitScalarExpr(E->getCallee());
// Get a pointer to the generic block literal.
@@ -107,7 +107,7 @@
llvm::PointerType::getUnqual(CGM.getGenericBlockLiteralType());
// Bitcast the callee to a block literal.
- llvm::Value *BlockLiteral =
+ llvm::Value *BlockLiteral =
Builder.CreateBitCast(Callee, BlockLiteralTy, "block.literal");
// Get the function pointer from the literal.
@@ -115,29 +115,29 @@
llvm::Value *Func = Builder.CreateLoad(FuncPtr, FuncPtr, "tmp");
// Cast the function pointer to the right type.
- const llvm::Type *BlockFTy =
+ const llvm::Type *BlockFTy =
ConvertType(getBlockFunctionType(getContext(), BPT));
const llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy);
Func = Builder.CreateBitCast(Func, BlockFTyPtr);
- BlockLiteral =
- Builder.CreateBitCast(BlockLiteral,
+ BlockLiteral =
+ Builder.CreateBitCast(BlockLiteral,
llvm::PointerType::getUnqual(llvm::Type::Int8Ty),
"tmp");
-
+
// Add the block literal.
QualType VoidPtrTy = getContext().getPointerType(getContext().VoidTy);
CallArgList Args;
Args.push_back(std::make_pair(RValue::get(BlockLiteral), VoidPtrTy));
-
+
// And the rest of the arguments.
- for (CallExpr::const_arg_iterator i = E->arg_begin(), e = E->arg_end();
+ for (CallExpr::const_arg_iterator i = E->arg_begin(), e = E->arg_end();
i != e; ++i)
- Args.push_back(std::make_pair(EmitAnyExprToTemp(*i),
+ Args.push_back(std::make_pair(EmitAnyExprToTemp(*i),
i->getType()));
-
+
// And call the block.
- return EmitCall(CGM.getTypes().getFunctionInfo(E->getType(), Args),
+ return EmitCall(CGM.getTypes().getFunctionInfo(E->getType(), Args),
Func, Args);
}
@@ -145,112 +145,110 @@
if (!NSConcreteGlobalBlock) {
const llvm::Type *Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
- // FIXME: Wee should have a CodeGenModule::AddRuntimeVariable that does the
+ // FIXME: Wee should have a CodeGenModule::AddRuntimeVariable that does the
// same thing as CreateRuntimeFunction if there's already a variable with
// the same name.
- NSConcreteGlobalBlock =
+ NSConcreteGlobalBlock =
new llvm::GlobalVariable(Ty, false,
- llvm::GlobalVariable::ExternalLinkage, 0,
- "_NSConcreteGlobalBlock", &getModule());
+ llvm::GlobalVariable::ExternalLinkage, 0,
+ "_NSConcreteGlobalBlock", &getModule());
}
// Generate the block descriptor.
const llvm::Type *UnsignedLongTy = Types.ConvertType(Context.UnsignedLongTy);
-
+
llvm::Constant *DescriptorFields[2];
-
+
// Reserved
DescriptorFields[0] = llvm::Constant::getNullValue(UnsignedLongTy);
-
+
// Block literal size. For global blocks we just use the size of the generic
// block literal struct.
- uint64_t BlockLiteralSize =
+ uint64_t BlockLiteralSize =
TheTargetData.getTypeStoreSizeInBits(getGenericBlockLiteralType()) / 8;
DescriptorFields[1] = llvm::ConstantInt::get(UnsignedLongTy,BlockLiteralSize);
-
- llvm::Constant *DescriptorStruct =
+
+ llvm::Constant *DescriptorStruct =
llvm::ConstantStruct::get(&DescriptorFields[0], 2);
-
+
llvm::GlobalVariable *Descriptor =
new llvm::GlobalVariable(DescriptorStruct->getType(), true,
- llvm::GlobalVariable::InternalLinkage,
- DescriptorStruct, "__block_descriptor_global",
+ llvm::GlobalVariable::InternalLinkage,
+ DescriptorStruct, "__block_descriptor_global",
&getModule());
-
+
// Generate the constants for the block literal.
llvm::Constant *LiteralFields[5];
-
+
CodeGenFunction::BlockInfo Info(0, "global");
llvm::Function *Fn = CodeGenFunction(*this).GenerateBlockFunction(BE, Info);
-
+
// isa
LiteralFields[0] = NSConcreteGlobalBlock;
-
+
// Flags
LiteralFields[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, IsGlobal);
-
+
// Reserved
LiteralFields[2] = llvm::Constant::getNullValue(llvm::Type::Int32Ty);
-
+
// Function
LiteralFields[3] = Fn;
-
+
// Descriptor
LiteralFields[4] = Descriptor;
-
- llvm::Constant *BlockLiteralStruct =
+
+ llvm::Constant *BlockLiteralStruct =
llvm::ConstantStruct::get(&LiteralFields[0], 5);
-
- llvm::GlobalVariable *BlockLiteral =
+
+ llvm::GlobalVariable *BlockLiteral =
new llvm::GlobalVariable(BlockLiteralStruct->getType(), true,
- llvm::GlobalVariable::InternalLinkage,
- BlockLiteralStruct, "__block_literal_global",
+ llvm::GlobalVariable::InternalLinkage,
+ BlockLiteralStruct, "__block_literal_global",
&getModule());
-
+
return BlockLiteral;
}
llvm::Function *CodeGenFunction::GenerateBlockFunction(const BlockExpr *Expr,
const BlockInfo& Info)
{
- const FunctionTypeProto *FTy =
+ const FunctionTypeProto *FTy =
cast<FunctionTypeProto>(Expr->getFunctionType());
-
+
FunctionArgList Args;
-
+
const BlockDecl *BD = Expr->getBlockDecl();
// FIXME: This leaks
- ImplicitParamDecl *SelfDecl =
+ ImplicitParamDecl *SelfDecl =
ImplicitParamDecl::Create(getContext(), 0,
SourceLocation(), 0,
getContext().getPointerType(getContext().VoidTy));
-
+
Args.push_back(std::make_pair(SelfDecl, SelfDecl->getType()));
-
- for (BlockDecl::param_iterator i = BD->param_begin(),
+
+ for (BlockDecl::param_iterator i = BD->param_begin(),
e = BD->param_end(); i != e; ++i)
Args.push_back(std::make_pair(*e, (*e)->getType()));
-
- const CGFunctionInfo &FI =
+
+ const CGFunctionInfo &FI =
CGM.getTypes().getFunctionInfo(FTy->getResultType(), Args);
std::string Name = std::string("__block_function_") + Info.NameSuffix;
CodeGenTypes &Types = CGM.getTypes();
const llvm::FunctionType *LTy = Types.GetFunctionType(FI, FTy->isVariadic());
-
- llvm::Function *Fn =
+
+ llvm::Function *Fn =
llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
Name,
&CGM.getModule());
-
- StartFunction(BD, FTy->getResultType(), Fn, Args,
+
+ StartFunction(BD, FTy->getResultType(), Fn, Args,
Expr->getBody()->getLocEnd());
EmitStmt(Expr->getBody());
FinishFunction(cast<CompoundStmt>(Expr->getBody())->getRBracLoc());
return Fn;
}
-
-
More information about the cfe-commits
mailing list