[PATCH] D63854: NFC: Convert large lambda into method
This revision was automatically updated to reflect the committed changes. Closed by commit rL365708: NFC: Convert large lambda into method (authored by vitalybuka, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D63854?vs=206771=209085#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63854/new/ https://reviews.llvm.org/D63854 Files: cfe/trunk/lib/CodeGen/CGDecl.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h Index: cfe/trunk/lib/CodeGen/CGDecl.cpp === --- cfe/trunk/lib/CodeGen/CGDecl.cpp +++ cfe/trunk/lib/CodeGen/CGDecl.cpp @@ -1663,6 +1663,87 @@ return false; } +void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type, + const VarDecl , + Address Loc) { + auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit(); + CharUnits Size = getContext().getTypeSizeInChars(type); + bool isVolatile = type.isVolatileQualified(); + if (!Size.isZero()) { +switch (trivialAutoVarInit) { +case LangOptions::TrivialAutoVarInitKind::Uninitialized: + llvm_unreachable("Uninitialized handled by caller"); +case LangOptions::TrivialAutoVarInitKind::Zero: + emitStoresForZeroInit(CGM, D, Loc, isVolatile, Builder); + break; +case LangOptions::TrivialAutoVarInitKind::Pattern: + emitStoresForPatternInit(CGM, D, Loc, isVolatile, Builder); + break; +} +return; + } + + // VLAs look zero-sized to getTypeInfo. We can't emit constant stores to + // them, so emit a memcpy with the VLA size to initialize each element. + // Technically zero-sized or negative-sized VLAs are undefined, and UBSan + // will catch that code, but there exists code which generates zero-sized + // VLAs. Be nice and initialize whatever they requested. + const auto *VlaType = getContext().getAsVariableArrayType(type); + if (!VlaType) +return; + auto VlaSize = getVLASize(VlaType); + auto SizeVal = VlaSize.NumElts; + CharUnits EltSize = getContext().getTypeSizeInChars(VlaSize.Type); + switch (trivialAutoVarInit) { + case LangOptions::TrivialAutoVarInitKind::Uninitialized: +llvm_unreachable("Uninitialized handled by caller"); + + case LangOptions::TrivialAutoVarInitKind::Zero: +if (!EltSize.isOne()) + SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize)); +Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, 0), SizeVal, + isVolatile); +break; + + case LangOptions::TrivialAutoVarInitKind::Pattern: { +llvm::Type *ElTy = Loc.getElementType(); +llvm::Constant *Constant = constWithPadding( +CGM, IsPattern::Yes, initializationPatternFor(CGM, ElTy)); +CharUnits ConstantAlign = getContext().getTypeAlignInChars(VlaSize.Type); +llvm::BasicBlock *SetupBB = createBasicBlock("vla-setup.loop"); +llvm::BasicBlock *LoopBB = createBasicBlock("vla-init.loop"); +llvm::BasicBlock *ContBB = createBasicBlock("vla-init.cont"); +llvm::Value *IsZeroSizedVLA = Builder.CreateICmpEQ( +SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0), +"vla.iszerosized"); +Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB); +EmitBlock(SetupBB); +if (!EltSize.isOne()) + SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize)); +llvm::Value *BaseSizeInChars = +llvm::ConstantInt::get(IntPtrTy, EltSize.getQuantity()); +Address Begin = Builder.CreateElementBitCast(Loc, Int8Ty, "vla.begin"); +llvm::Value *End = +Builder.CreateInBoundsGEP(Begin.getPointer(), SizeVal, "vla.end"); +llvm::BasicBlock *OriginBB = Builder.GetInsertBlock(); +EmitBlock(LoopBB); +llvm::PHINode *Cur = Builder.CreatePHI(Begin.getType(), 2, "vla.cur"); +Cur->addIncoming(Begin.getPointer(), OriginBB); +CharUnits CurAlign = Loc.getAlignment().alignmentOfArrayElement(EltSize); +Builder.CreateMemCpy(Address(Cur, CurAlign), + createUnnamedGlobalForMemcpyFrom( + CGM, D, Builder, Constant, ConstantAlign), + BaseSizeInChars, isVolatile); +llvm::Value *Next = +Builder.CreateInBoundsGEP(Int8Ty, Cur, BaseSizeInChars, "vla.next"); +llvm::Value *Done = Builder.CreateICmpEQ(Next, End, "vla-init.isdone"); +Builder.CreateCondBr(Done, ContBB, LoopBB); +Cur->addIncoming(Next, LoopBB); +EmitBlock(ContBB); + } break; + } +} + void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission ) { assert(emission.Variable && "emission was not valid!"); @@ -1727,87 +1808,11 @@ if (emission.IsEscapingByRef && !locIsByrefHeader) Loc = emitBlockByrefAddress(Loc, , /*follow=*/false); -bool isVolatile = type.isVolatileQualified(); -CharUnits Size =
[PATCH] D63854: [NFC] Convert large lambda into method
eugenis accepted this revision. eugenis added a comment. This revision is now accepted and ready to land. LGTM if it's really NFC Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63854/new/ https://reviews.llvm.org/D63854 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D63854: [NFC] Convert large lambda into method
vitalybuka updated this revision to Diff 206771. vitalybuka added a comment. remove unrelated file Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63854/new/ https://reviews.llvm.org/D63854 Files: clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CodeGenFunction.h Index: clang/lib/CodeGen/CodeGenFunction.h === --- clang/lib/CodeGen/CodeGenFunction.h +++ clang/lib/CodeGen/CodeGenFunction.h @@ -4195,6 +4195,9 @@ llvm::Value *EmittedE, bool IsDynamic); + void emitZeroOrPatternForAutoVarInit(QualType type, const VarDecl , + Address Loc); + public: #ifndef NDEBUG // Determine whether the given argument is an Objective-C method Index: clang/lib/CodeGen/CGDecl.cpp === --- clang/lib/CodeGen/CGDecl.cpp +++ clang/lib/CodeGen/CGDecl.cpp @@ -1662,6 +1662,87 @@ return false; } +void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type, + const VarDecl , + Address Loc) { + auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit(); + CharUnits Size = getContext().getTypeSizeInChars(type); + bool isVolatile = type.isVolatileQualified(); + if (!Size.isZero()) { +switch (trivialAutoVarInit) { +case LangOptions::TrivialAutoVarInitKind::Uninitialized: + llvm_unreachable("Uninitialized handled by caller"); +case LangOptions::TrivialAutoVarInitKind::Zero: + emitStoresForZeroInit(CGM, D, Loc, isVolatile, Builder); + break; +case LangOptions::TrivialAutoVarInitKind::Pattern: + emitStoresForPatternInit(CGM, D, Loc, isVolatile, Builder); + break; +} +return; + } + + // VLAs look zero-sized to getTypeInfo. We can't emit constant stores to + // them, so emit a memcpy with the VLA size to initialize each element. + // Technically zero-sized or negative-sized VLAs are undefined, and UBSan + // will catch that code, but there exists code which generates zero-sized + // VLAs. Be nice and initialize whatever they requested. + const auto *VlaType = getContext().getAsVariableArrayType(type); + if (!VlaType) +return; + auto VlaSize = getVLASize(VlaType); + auto SizeVal = VlaSize.NumElts; + CharUnits EltSize = getContext().getTypeSizeInChars(VlaSize.Type); + switch (trivialAutoVarInit) { + case LangOptions::TrivialAutoVarInitKind::Uninitialized: +llvm_unreachable("Uninitialized handled by caller"); + + case LangOptions::TrivialAutoVarInitKind::Zero: +if (!EltSize.isOne()) + SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize)); +Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, 0), SizeVal, + isVolatile); +break; + + case LangOptions::TrivialAutoVarInitKind::Pattern: { +llvm::Type *ElTy = Loc.getElementType(); +llvm::Constant *Constant = constWithPadding( +CGM, IsPattern::Yes, initializationPatternFor(CGM, ElTy)); +CharUnits ConstantAlign = getContext().getTypeAlignInChars(VlaSize.Type); +llvm::BasicBlock *SetupBB = createBasicBlock("vla-setup.loop"); +llvm::BasicBlock *LoopBB = createBasicBlock("vla-init.loop"); +llvm::BasicBlock *ContBB = createBasicBlock("vla-init.cont"); +llvm::Value *IsZeroSizedVLA = Builder.CreateICmpEQ( +SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0), +"vla.iszerosized"); +Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB); +EmitBlock(SetupBB); +if (!EltSize.isOne()) + SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize)); +llvm::Value *BaseSizeInChars = +llvm::ConstantInt::get(IntPtrTy, EltSize.getQuantity()); +Address Begin = Builder.CreateElementBitCast(Loc, Int8Ty, "vla.begin"); +llvm::Value *End = +Builder.CreateInBoundsGEP(Begin.getPointer(), SizeVal, "vla.end"); +llvm::BasicBlock *OriginBB = Builder.GetInsertBlock(); +EmitBlock(LoopBB); +llvm::PHINode *Cur = Builder.CreatePHI(Begin.getType(), 2, "vla.cur"); +Cur->addIncoming(Begin.getPointer(), OriginBB); +CharUnits CurAlign = Loc.getAlignment().alignmentOfArrayElement(EltSize); +Builder.CreateMemCpy(Address(Cur, CurAlign), + createUnnamedGlobalForMemcpyFrom( + CGM, D, Builder, Constant, ConstantAlign), + BaseSizeInChars, isVolatile); +llvm::Value *Next = +Builder.CreateInBoundsGEP(Int8Ty, Cur, BaseSizeInChars, "vla.next"); +llvm::Value *Done = Builder.CreateICmpEQ(Next, End, "vla-init.isdone"); +Builder.CreateCondBr(Done, ContBB, LoopBB); +Cur->addIncoming(Next, LoopBB); +EmitBlock(ContBB); + } break; + } +}; + void CodeGenFunction::EmitAutoVarInit(const
[PATCH] D63854: [NFC] Convert large lambda into method
vitalybuka created this revision. vitalybuka added a reviewer: pcc. Herald added projects: clang, LLDB. Herald added subscribers: lldb-commits, cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D63854 Files: clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CodeGenFunction.h lldb/source/Symbol/LocateSymbolFileMacOSX.cpp Index: lldb/source/Symbol/LocateSymbolFileMacOSX.cpp === --- lldb/source/Symbol/LocateSymbolFileMacOSX.cpp +++ lldb/source/Symbol/LocateSymbolFileMacOSX.cpp @@ -9,7 +9,6 @@ #include "lldb/Symbol/LocateSymbolFile.h" #include -#include #include #include @@ -38,8 +37,14 @@ using namespace lldb; using namespace lldb_private; -static CFURLRef (*g_dlsym_DBGCopyFullDSYMURLForUUID)(CFUUIDRef uuid, CFURLRef exec_url) = nullptr; -static CFDictionaryRef (*g_dlsym_DBGCopyDSYMPropertyLists)(CFURLRef dsym_url) = nullptr; +#if !defined(__arm__) && !defined(__arm64__) &&\ +!defined(__aarch64__) // No DebugSymbols on the iOS devices +extern "C" { + +CFURLRef DBGCopyFullDSYMURLForUUID(CFUUIDRef uuid, CFURLRef exec_url); +CFDictionaryRef DBGCopyDSYMPropertyLists(CFURLRef dsym_url); +} +#endif int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec _spec, ModuleSpec _module_spec) { @@ -56,19 +61,8 @@ int items_found = 0; - if (g_dlsym_DBGCopyFullDSYMURLForUUID == nullptr || - g_dlsym_DBGCopyDSYMPropertyLists == nullptr) { -void *handle = dlopen ("/System/Library/PrivateFrameworks/DebugSymbols.framework/DebugSymbols", RTLD_LAZY | RTLD_LOCAL); -if (handle) { - g_dlsym_DBGCopyFullDSYMURLForUUID = (CFURLRef (*)(CFUUIDRef, CFURLRef)) dlsym (handle, "DBGCopyFullDSYMURLForUUID"); - g_dlsym_DBGCopyDSYMPropertyLists = (CFDictionaryRef (*)(CFURLRef)) dlsym (handle, "DBGCopyDSYMPropertyLists"); -} - } - - if (g_dlsym_DBGCopyFullDSYMURLForUUID == nullptr || - g_dlsym_DBGCopyDSYMPropertyLists == nullptr) { -return items_found; - } +#if !defined(__arm__) && !defined(__arm64__) &&\ +!defined(__aarch64__) // No DebugSymbols on the iOS devices const UUID *uuid = module_spec.GetUUIDPtr(); const ArchSpec *arch = module_spec.GetArchitecturePtr(); @@ -95,7 +89,7 @@ } CFCReleaser dsym_url( -g_dlsym_DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get())); +::DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get())); char path[PATH_MAX]; if (dsym_url.get()) { @@ -131,7 +125,7 @@ } CFCReleaser dict( - g_dlsym_DBGCopyDSYMPropertyLists(dsym_url.get())); + ::DBGCopyDSYMPropertyLists(dsym_url.get())); CFDictionaryRef uuid_dict = NULL; if (dict.get()) { CFCString uuid_cfstr(uuid->GetAsString().c_str()); @@ -242,6 +236,8 @@ } } } +#endif // #if !defined (__arm__) && !defined (__arm64__) && !defined + // (__aarch64__) return items_found; } Index: clang/lib/CodeGen/CodeGenFunction.h === --- clang/lib/CodeGen/CodeGenFunction.h +++ clang/lib/CodeGen/CodeGenFunction.h @@ -4195,6 +4195,9 @@ llvm::Value *EmittedE, bool IsDynamic); + void emitZeroOrPatternForAutoVarInit(QualType type, const VarDecl , + Address Loc); + public: #ifndef NDEBUG // Determine whether the given argument is an Objective-C method Index: clang/lib/CodeGen/CGDecl.cpp === --- clang/lib/CodeGen/CGDecl.cpp +++ clang/lib/CodeGen/CGDecl.cpp @@ -1662,6 +1662,87 @@ return false; } +void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type, + const VarDecl , + Address Loc) { + auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit(); + CharUnits Size = getContext().getTypeSizeInChars(type); + bool isVolatile = type.isVolatileQualified(); + if (!Size.isZero()) { +switch (trivialAutoVarInit) { +case LangOptions::TrivialAutoVarInitKind::Uninitialized: + llvm_unreachable("Uninitialized handled by caller"); +case LangOptions::TrivialAutoVarInitKind::Zero: + emitStoresForZeroInit(CGM, D, Loc, isVolatile, Builder); + break; +case LangOptions::TrivialAutoVarInitKind::Pattern: + emitStoresForPatternInit(CGM, D, Loc, isVolatile, Builder); + break; +} +return; + } + + // VLAs look zero-sized to getTypeInfo. We can't emit constant stores to + // them, so emit a memcpy with the VLA size to initialize each element. + // Technically zero-sized or negative-sized VLAs are undefined, and