Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 64cd232

Browse files
committed
Remove a rather egregious use of getFunctionInfo.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127324 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1f6f961 commit 64cd232

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

Diff for: lib/CodeGen/CGBlocks.cpp

+9-22
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace CodeGen;
2727

2828
CGBlockInfo::CGBlockInfo(const BlockExpr *blockExpr, const char *N)
2929
: Name(N), CXXThisIndex(0), CanBeGlobal(false), NeedsCopyDispose(false),
30-
HasCXXObject(false), StructureType(0), Block(blockExpr) {
30+
HasCXXObject(false), UsesStret(false), StructureType(0), Block(blockExpr) {
3131

3232
// Skip asm prefix, if any.
3333
if (Name && Name[0] == '\01')
@@ -104,23 +104,6 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM,
104104
return llvm::ConstantExpr::getBitCast(global, CGM.getBlockDescriptorType());
105105
}
106106

107-
static BlockFlags computeBlockFlag(CodeGenModule &CGM,
108-
const BlockExpr *BE,
109-
BlockFlags flags) {
110-
const FunctionType *ftype = BE->getFunctionType();
111-
112-
// This is a bit overboard.
113-
CallArgList args;
114-
const CGFunctionInfo &fnInfo =
115-
CGM.getTypes().getFunctionInfo(ftype->getResultType(), args,
116-
ftype->getExtInfo());
117-
118-
if (CGM.ReturnTypeUsesSRet(fnInfo))
119-
flags |= BLOCK_USE_STRET;
120-
121-
return flags;
122-
}
123-
124107
/*
125108
Purely notional variadic template describing the layout of a block.
126109
@@ -536,7 +519,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) {
536519
BlockFlags flags = BLOCK_HAS_SIGNATURE;
537520
if (blockInfo.NeedsCopyDispose) flags |= BLOCK_HAS_COPY_DISPOSE;
538521
if (blockInfo.HasCXXObject) flags |= BLOCK_HAS_CXX_OBJ;
539-
flags = computeBlockFlag(CGM, blockInfo.getBlockExpr(), flags);
522+
if (blockInfo.UsesStret) flags |= BLOCK_USE_STRET;
540523

541524
// Initialize the block literal.
542525
Builder.CreateStore(isa, Builder.CreateStructGEP(blockAddr, 0, "block.isa"));
@@ -747,7 +730,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E,
747730
// Load the function.
748731
llvm::Value *Func = Builder.CreateLoad(FuncPtr, "tmp");
749732

750-
const FunctionType *FuncTy = FnType->getAs<FunctionType>();
733+
const FunctionType *FuncTy = FnType->castAs<FunctionType>();
751734
QualType ResultType = FuncTy->getResultType();
752735

753736
const CGFunctionInfo &FnInfo =
@@ -836,8 +819,9 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,
836819
fields[0] = CGM.getNSConcreteGlobalBlock();
837820

838821
// __flags
839-
BlockFlags flags = computeBlockFlag(CGM, blockInfo.getBlockExpr(),
840-
BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE);
822+
BlockFlags flags = BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE;
823+
if (blockInfo.UsesStret) flags |= BLOCK_USE_STRET;
824+
841825
fields[1] = llvm::ConstantInt::get(CGM.IntTy, flags.getBitMask());
842826

843827
// Reserved
@@ -915,6 +899,9 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
915899
const CGFunctionInfo &fnInfo =
916900
CGM.getTypes().getFunctionInfo(fnType->getResultType(), args,
917901
fnType->getExtInfo());
902+
if (CGM.ReturnTypeUsesSRet(fnInfo))
903+
blockInfo.UsesStret = true;
904+
918905
const llvm::FunctionType *fnLLVMType =
919906
CGM.getTypes().GetFunctionType(fnInfo, fnType->isVariadic());
920907

Diff for: lib/CodeGen/CGBlocks.h

+4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ class CGBlockInfo {
173173
/// need to be run even in GC mode.
174174
bool HasCXXObject : 1;
175175

176+
/// UsesStret : True if the block uses an stret return. Mutable
177+
/// because it gets set later in the block-creation process.
178+
mutable bool UsesStret : 1;
179+
176180
const llvm::StructType *StructureType;
177181
const BlockExpr *Block;
178182
CharUnits BlockSize;

0 commit comments

Comments
 (0)