From a5448544eea6663f8dce30a50343ef5125559794 Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Fri, 13 Feb 2009 15:32:32 +0000 Subject: [PATCH] Fixup spacing a tad. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64454 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBlocks.cpp | 136 +++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 2168351738..9588e4df5e 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -30,15 +30,15 @@ const llvm::Type *CodeGenModule::getBlockDescriptorType() { 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 @@ CodeGenModule::getGenericBlockLiteralType() { 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 @@ CodeGenModule::getGenericBlockLiteralType() { 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(BPT->getPointeeType()); - + llvm::SmallVector 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 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) { 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 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) { 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 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *BE) { 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(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(Expr->getBody())->getRBracLoc()); return Fn; } - - -- 2.40.0