Skip to content

Commit 83c7a35

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:c649fd34e928 into amd-gfx:a460bc1de785
Local branch amd-gfx a460bc1 Merged main:056406570915 into amd-gfx:850c4ac2ec17 Remote branch main c649fd3 [MachineSink][AArch64] Sink instruction copies when they can replace copy into hard register or folded into addressing mode
2 parents a460bc1 + c649fd3 commit 83c7a35

File tree

173 files changed

+5134
-1955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+5134
-1955
lines changed

clang/lib/CodeGen/CGAtomic.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ namespace {
8787
llvm::Value *StoragePtr = CGF.Builder.CreateConstGEP1_64(
8888
CGF.Int8Ty, BitFieldPtr, OffsetInChars.getQuantity());
8989
StoragePtr = CGF.Builder.CreateAddrSpaceCast(
90-
StoragePtr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
91-
"atomic_bitfield_base");
90+
StoragePtr, CGF.UnqualPtrTy, "atomic_bitfield_base");
9291
BFI = OrigBFI;
9392
BFI.Offset = Offset;
9493
BFI.StorageSize = AtomicSizeInBits;

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,8 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E,
11891189
}
11901190
} else {
11911191
// Bitcast the block literal to a generic block literal.
1192-
BlockPtr = Builder.CreatePointerCast(
1193-
BlockPtr, llvm::PointerType::get(GenBlockTy, 0), "block.literal");
1192+
BlockPtr =
1193+
Builder.CreatePointerCast(BlockPtr, UnqualPtrTy, "block.literal");
11941194
// Get pointer to the block invoke function
11951195
llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 3);
11961196

@@ -1208,12 +1208,6 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E,
12081208
const CGFunctionInfo &FnInfo =
12091209
CGM.getTypes().arrangeBlockFunctionCall(Args, FuncTy);
12101210

1211-
// Cast the function pointer to the right type.
1212-
llvm::Type *BlockFTy = CGM.getTypes().GetFunctionType(FnInfo);
1213-
1214-
llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy);
1215-
Func = Builder.CreatePointerCast(Func, BlockFTyPtr);
1216-
12171211
// Prepare the callee.
12181212
CGCallee Callee(CGCalleeInfo(), Func);
12191213

@@ -2589,11 +2583,11 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
25892583
SmallVector<llvm::Type *, 8> types;
25902584

25912585
// void *__isa;
2592-
types.push_back(Int8PtrTy);
2586+
types.push_back(VoidPtrTy);
25932587
size += getPointerSize();
25942588

25952589
// void *__forwarding;
2596-
types.push_back(llvm::PointerType::getUnqual(byrefType));
2590+
types.push_back(VoidPtrTy);
25972591
size += getPointerSize();
25982592

25992593
// int32_t __flags;
@@ -2608,11 +2602,11 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
26082602
bool hasCopyAndDispose = getContext().BlockRequiresCopying(Ty, D);
26092603
if (hasCopyAndDispose) {
26102604
/// void *__copy_helper;
2611-
types.push_back(Int8PtrTy);
2605+
types.push_back(VoidPtrTy);
26122606
size += getPointerSize();
26132607

26142608
/// void *__destroy_helper;
2615-
types.push_back(Int8PtrTy);
2609+
types.push_back(VoidPtrTy);
26162610
size += getPointerSize();
26172611
}
26182612

@@ -2621,7 +2615,7 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
26212615
if (getContext().getByrefLifetime(Ty, Lifetime, HasByrefExtendedLayout) &&
26222616
HasByrefExtendedLayout) {
26232617
/// void *__byref_variable_layout;
2624-
types.push_back(Int8PtrTy);
2618+
types.push_back(VoidPtrTy);
26252619
size += CharUnits::fromQuantity(PointerSizeInBytes);
26262620
}
26272621

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 30 additions & 69 deletions
Large diffs are not rendered by default.

clang/lib/CodeGen/CGCUDANV.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,15 @@ CGNVCUDARuntime::CGNVCUDARuntime(CodeGenModule &CGM)
226226
TheModule(CGM.getModule()),
227227
RelocatableDeviceCode(CGM.getLangOpts().GPURelocatableDeviceCode),
228228
DeviceMC(InitDeviceMC(CGM)) {
229-
CodeGen::CodeGenTypes &Types = CGM.getTypes();
230-
ASTContext &Ctx = CGM.getContext();
231-
232229
IntTy = CGM.IntTy;
233230
SizeTy = CGM.SizeTy;
234231
VoidTy = CGM.VoidTy;
235232
Zeros[0] = llvm::ConstantInt::get(SizeTy, 0);
236233
Zeros[1] = Zeros[0];
237234

238-
CharPtrTy = llvm::PointerType::getUnqual(Types.ConvertType(Ctx.CharTy));
239-
VoidPtrTy = cast<llvm::PointerType>(Types.ConvertType(Ctx.VoidPtrTy));
240-
VoidPtrPtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext());
235+
CharPtrTy = CGM.UnqualPtrTy;
236+
VoidPtrTy = CGM.UnqualPtrTy;
237+
VoidPtrPtrTy = CGM.UnqualPtrTy;
241238
}
242239

243240
llvm::FunctionCallee CGNVCUDARuntime::getSetupArgumentFn() const {

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ LValue CodeGenFunction::EmitUnsupportedLValue(const Expr *E,
12121212
const char *Name) {
12131213
ErrorUnsupported(E, Name);
12141214
llvm::Type *ElTy = ConvertType(E->getType());
1215-
llvm::Type *Ty = llvm::PointerType::getUnqual(ElTy);
1215+
llvm::Type *Ty = UnqualPtrTy;
12161216
return MakeAddrLValue(
12171217
Address(llvm::UndefValue::get(Ty), ElTy, CharUnits::One()), E->getType());
12181218
}
@@ -4599,7 +4599,7 @@ std::optional<LValue> HandleConditionalOperatorLValueSimpleCase(
45994599
if (auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Live->IgnoreParens())) {
46004600
CGF.EmitCXXThrowExpr(ThrowExpr);
46014601
llvm::Type *ElemTy = CGF.ConvertType(Dead->getType());
4602-
llvm::Type *Ty = llvm::PointerType::getUnqual(ElemTy);
4602+
llvm::Type *Ty = CGF.UnqualPtrTy;
46034603
return CGF.MakeAddrLValue(
46044604
Address(llvm::UndefValue::get(Ty), ElemTy, CharUnits::One()),
46054605
Dead->getType());

clang/lib/CodeGen/CGObjCRuntime.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
6363
CGF.CGM.getContext().getObjCObjectPointerType(InterfaceTy);
6464
QualType IvarTy =
6565
Ivar->getUsageType(ObjectPtrTy).withCVRQualifiers(CVRQualifiers);
66-
llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy);
67-
llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, CGF.Int8PtrTy);
66+
llvm::Value *V = BaseValue;
6867
V = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, V, Offset, "add.ptr");
6968

7069
if (!Ivar->isBitField()) {
71-
V = CGF.Builder.CreateBitCast(V, llvm::PointerType::getUnqual(LTy));
7270
LValue LV = CGF.MakeNaturalAlignAddrLValue(V, IvarTy);
7371
return LV;
7472
}

clang/lib/CodeGen/CGOpenCLRuntime.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ llvm::PointerType *CGOpenCLRuntime::getPointerType(const Type *T,
7171
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
7272
uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace(
7373
CGM.getContext().getOpenCLTypeAddrSpace(T));
74-
auto *PTy =
75-
llvm::PointerType::get(llvm::StructType::create(Ctx, Name), AddrSpc);
74+
auto *PTy = llvm::PointerType::get(Ctx, AddrSpc);
7675
CachedTys[Name] = PTy;
7776
return PTy;
7877
}
@@ -90,10 +89,9 @@ llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) {
9089
llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T, StringRef Name,
9190
llvm::Type *&PipeTy) {
9291
if (!PipeTy)
93-
PipeTy = llvm::PointerType::get(llvm::StructType::create(
94-
CGM.getLLVMContext(), Name),
95-
CGM.getContext().getTargetAddressSpace(
96-
CGM.getContext().getOpenCLTypeAddrSpace(T)));
92+
PipeTy = llvm::PointerType::get(
93+
CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace(
94+
CGM.getContext().getOpenCLTypeAddrSpace(T)));
9795
return PipeTy;
9896
}
9997

@@ -105,10 +103,10 @@ llvm::Type *CGOpenCLRuntime::getSamplerType(const Type *T) {
105103
CGM, CGM.getContext().OCLSamplerTy.getTypePtr()))
106104
SamplerTy = TransTy;
107105
else
106+
// struct opencl.sampler_t*
108107
SamplerTy = llvm::PointerType::get(
109-
llvm::StructType::create(CGM.getLLVMContext(), "opencl.sampler_t"),
110-
CGM.getContext().getTargetAddressSpace(
111-
CGM.getContext().getOpenCLTypeAddrSpace(T)));
108+
CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace(
109+
CGM.getContext().getOpenCLTypeAddrSpace(T)));
112110
return SamplerTy;
113111
}
114112

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,14 @@ CodeGenModule::CodeGenModule(ASTContext &C,
360360
IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
361361
IntPtrTy = llvm::IntegerType::get(LLVMContext,
362362
C.getTargetInfo().getMaxPointerWidth());
363-
Int8PtrTy = Int8Ty->getPointerTo(0);
364-
Int8PtrPtrTy = Int8PtrTy->getPointerTo(0);
363+
Int8PtrTy = llvm::PointerType::get(LLVMContext, 0);
365364
const llvm::DataLayout &DL = M.getDataLayout();
366-
AllocaInt8PtrTy = Int8Ty->getPointerTo(DL.getAllocaAddrSpace());
367-
GlobalsInt8PtrTy = Int8Ty->getPointerTo(DL.getDefaultGlobalsAddressSpace());
368-
ConstGlobalsPtrTy = Int8Ty->getPointerTo(
369-
C.getTargetAddressSpace(GetGlobalConstantAddressSpace()));
365+
AllocaInt8PtrTy =
366+
llvm::PointerType::get(LLVMContext, DL.getAllocaAddrSpace());
367+
GlobalsInt8PtrTy =
368+
llvm::PointerType::get(LLVMContext, DL.getDefaultGlobalsAddressSpace());
369+
ConstGlobalsPtrTy = llvm::PointerType::get(
370+
LLVMContext, C.getTargetAddressSpace(GetGlobalConstantAddressSpace()));
370371
ASTAllocaAddressSpace = getTargetCodeGenInfo().getASTAllocaAddressSpace();
371372

372373
// Build C++20 Module initializers.

clang/lib/CodeGen/CodeGenTypeCache.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ struct CodeGenTypeCache {
5151
llvm::IntegerType *PtrDiffTy;
5252
};
5353

54-
/// void* in address space 0
54+
/// void*, void** in address space 0
5555
union {
56+
llvm::PointerType *UnqualPtrTy;
5657
llvm::PointerType *VoidPtrTy;
5758
llvm::PointerType *Int8PtrTy;
58-
};
59-
60-
/// void** in address space 0
61-
union {
6259
llvm::PointerType *VoidPtrPtrTy;
6360
llvm::PointerType *Int8PtrPtrTy;
6461
};

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,9 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
750750
} else {
751751
llvm::Value *VFPAddr =
752752
CGF.Builder.CreateGEP(CGF.Int8Ty, VTable, VTableOffset);
753-
VirtualFn = CGF.Builder.CreateAlignedLoad(
754-
llvm::PointerType::getUnqual(CGF.getLLVMContext()), VFPAddr,
755-
CGF.getPointerAlign(), "memptr.virtualfn");
753+
VirtualFn = CGF.Builder.CreateAlignedLoad(CGF.UnqualPtrTy, VFPAddr,
754+
CGF.getPointerAlign(),
755+
"memptr.virtualfn");
756756
}
757757
}
758758
assert(VirtualFn && "Virtual fuction pointer not created!");
@@ -792,9 +792,8 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
792792
// In the non-virtual path, the function pointer is actually a
793793
// function pointer.
794794
CGF.EmitBlock(FnNonVirtual);
795-
llvm::Value *NonVirtualFn = Builder.CreateIntToPtr(
796-
FnAsInt, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
797-
"memptr.nonvirtualfn");
795+
llvm::Value *NonVirtualFn =
796+
Builder.CreateIntToPtr(FnAsInt, CGF.UnqualPtrTy, "memptr.nonvirtualfn");
798797

799798
// Check the function pointer if CFI on member function pointers is enabled.
800799
if (ShouldEmitCFICheck) {
@@ -833,8 +832,7 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
833832

834833
// We're done.
835834
CGF.EmitBlock(FnEnd);
836-
llvm::PHINode *CalleePtr =
837-
Builder.CreatePHI(llvm::PointerType::getUnqual(CGF.getLLVMContext()), 2);
835+
llvm::PHINode *CalleePtr = Builder.CreatePHI(CGF.UnqualPtrTy, 2);
838836
CalleePtr->addIncoming(VirtualFn, FnVirtual);
839837
CalleePtr->addIncoming(NonVirtualFn, FnNonVirtual);
840838

@@ -1238,8 +1236,7 @@ void ItaniumCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
12381236
// Grab the vtable pointer as an intptr_t*.
12391237
auto *ClassDecl =
12401238
cast<CXXRecordDecl>(ElementType->castAs<RecordType>()->getDecl());
1241-
llvm::Value *VTable = CGF.GetVTablePtr(
1242-
Ptr, llvm::PointerType::getUnqual(CGF.getLLVMContext()), ClassDecl);
1239+
llvm::Value *VTable = CGF.GetVTablePtr(Ptr, CGF.UnqualPtrTy, ClassDecl);
12431240

12441241
// Track back to entry -2 and pull out the offset there.
12451242
llvm::Value *OffsetPtr = CGF.Builder.CreateConstInBoundsGEP1_64(
@@ -1591,9 +1588,8 @@ llvm::Value *ItaniumCXXABI::emitDynamicCastToVoid(CodeGenFunction &CGF,
15911588
llvm::Value *OffsetToTop;
15921589
if (CGM.getItaniumVTableContext().isRelativeLayout()) {
15931590
// Get the vtable pointer.
1594-
llvm::Value *VTable = CGF.GetVTablePtr(
1595-
ThisAddr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
1596-
ClassDecl);
1591+
llvm::Value *VTable =
1592+
CGF.GetVTablePtr(ThisAddr, CGF.UnqualPtrTy, ClassDecl);
15971593

15981594
// Get the offset-to-top from the vtable.
15991595
OffsetToTop =
@@ -1605,9 +1601,8 @@ llvm::Value *ItaniumCXXABI::emitDynamicCastToVoid(CodeGenFunction &CGF,
16051601
CGF.ConvertType(CGF.getContext().getPointerDiffType());
16061602

16071603
// Get the vtable pointer.
1608-
llvm::Value *VTable = CGF.GetVTablePtr(
1609-
ThisAddr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
1610-
ClassDecl);
1604+
llvm::Value *VTable =
1605+
CGF.GetVTablePtr(ThisAddr, CGF.UnqualPtrTy, ClassDecl);
16111606

16121607
// Get the offset-to-top from the vtable.
16131608
OffsetToTop =
@@ -2308,8 +2303,8 @@ llvm::Value *ItaniumCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
23082303
// cookie, otherwise return 0 to avoid an infinite loop calling DTORs.
23092304
// We can't simply ignore this load using nosanitize metadata because
23102305
// the metadata may be lost.
2311-
llvm::FunctionType *FTy = llvm::FunctionType::get(
2312-
CGF.SizeTy, llvm::PointerType::getUnqual(CGF.getLLVMContext()), false);
2306+
llvm::FunctionType *FTy =
2307+
llvm::FunctionType::get(CGF.SizeTy, CGF.UnqualPtrTy, false);
23132308
llvm::FunctionCallee F =
23142309
CGM.CreateRuntimeFunction(FTy, "__asan_load_cxx_array_cookie");
23152310
return CGF.Builder.CreateCall(F, numElementsPtr.getPointer());
@@ -2652,7 +2647,7 @@ static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
26522647

26532648
// We're assuming that the destructor function is something we can
26542649
// reasonably call with the default CC.
2655-
llvm::Type *dtorTy = llvm::PointerType::getUnqual(CGF.getLLVMContext());
2650+
llvm::Type *dtorTy = CGF.UnqualPtrTy;
26562651

26572652
// Preserve address space of addr.
26582653
auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
@@ -4654,8 +4649,7 @@ static void InitCatchParam(CodeGenFunction &CGF,
46544649
auto catchRD = CatchType->getAsCXXRecordDecl();
46554650
CharUnits caughtExnAlignment = CGF.CGM.getClassPointerAlignment(catchRD);
46564651

4657-
llvm::Type *PtrTy =
4658-
llvm::PointerType::getUnqual(CGF.getLLVMContext()); // addrspace 0 ok
4652+
llvm::Type *PtrTy = CGF.UnqualPtrTy; // addrspace 0 ok
46594653

46604654
// Check for a copy expression. If we don't have a copy expression,
46614655
// that means a trivial copy is okay.
@@ -4843,8 +4837,7 @@ void XLCXXABI::registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
48434837
llvm::FunctionCallee Dtor,
48444838
llvm::Constant *Addr) {
48454839
if (D.getTLSKind() != VarDecl::TLS_None) {
4846-
llvm::PointerType *PtrTy =
4847-
llvm::PointerType::getUnqual(CGF.getLLVMContext());
4840+
llvm::PointerType *PtrTy = CGF.UnqualPtrTy;
48484841

48494842
// extern "C" int __pt_atexit_np(int flags, int(*)(int,...), ...);
48504843
llvm::FunctionType *AtExitTy =

clang/lib/CodeGen/Targets/PPC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
431431

432432
llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
433433
if (isIndirect)
434-
DirectTy = llvm::PointerType::getUnqual(CGF.getLLVMContext());
434+
DirectTy = CGF.UnqualPtrTy;
435435

436436
// Case 1: consume registers.
437437
Address RegAddr = Address::invalid();

clang/lib/CodeGen/Targets/Sparc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ Address SparcV9ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
286286
CGBuilderTy &Builder = CGF.Builder;
287287
Address Addr = Address(Builder.CreateLoad(VAListAddr, "ap.cur"),
288288
getVAListElementType(CGF), SlotSize);
289-
llvm::Type *ArgPtrTy = llvm::PointerType::getUnqual(ArgTy);
289+
llvm::Type *ArgPtrTy = CGF.UnqualPtrTy;
290290

291291
auto TypeInfo = getContext().getTypeInfoInChars(Ty);
292292

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,9 +2978,7 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction &CGF,
29782978

29792979
// AMD64-ABI 3.5.7p5: Step 8. Fetch type from l->overflow_arg_area.
29802980
llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
2981-
llvm::Value *Res =
2982-
CGF.Builder.CreateBitCast(overflow_arg_area,
2983-
llvm::PointerType::getUnqual(LTy));
2981+
llvm::Value *Res = overflow_arg_area;
29842982

29852983
// AMD64-ABI 3.5.7p5: Step 9. Set l->overflow_arg_area to:
29862984
// l->overflow_arg_area + sizeof(type).
@@ -3083,8 +3081,6 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
30833081
llvm::Type *TyHi = ST->getElementType(1);
30843082
assert((TyLo->isFPOrFPVectorTy() ^ TyHi->isFPOrFPVectorTy()) &&
30853083
"Unexpected ABI info for mixed regs");
3086-
llvm::Type *PTyLo = llvm::PointerType::getUnqual(TyLo);
3087-
llvm::Type *PTyHi = llvm::PointerType::getUnqual(TyHi);
30883084
llvm::Value *GPAddr =
30893085
CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, gp_offset);
30903086
llvm::Value *FPAddr =
@@ -3095,13 +3091,13 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
30953091
// Copy the first element.
30963092
// FIXME: Our choice of alignment here and below is probably pessimistic.
30973093
llvm::Value *V = CGF.Builder.CreateAlignedLoad(
3098-
TyLo, CGF.Builder.CreateBitCast(RegLoAddr, PTyLo),
3094+
TyLo, RegLoAddr,
30993095
CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyLo)));
31003096
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
31013097

31023098
// Copy the second element.
31033099
V = CGF.Builder.CreateAlignedLoad(
3104-
TyHi, CGF.Builder.CreateBitCast(RegHiAddr, PTyHi),
3100+
TyHi, RegHiAddr,
31053101
CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyHi)));
31063102
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
31073103

flang/lib/Lower/ConvertCall.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "flang/Lower/ConvertCall.h"
14+
#include "flang/Lower/Allocatable.h"
1415
#include "flang/Lower/ConvertExprToHLFIR.h"
1516
#include "flang/Lower/ConvertVariable.h"
1617
#include "flang/Lower/CustomIntrinsicCall.h"
@@ -1199,12 +1200,21 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals,
11991200
}
12001201
// Passing a POINTER to a POINTER, or an ALLOCATABLE to an ALLOCATABLE.
12011202
assert(actual.isMutableBox() && "actual must be a mutable box");
1202-
caller.placeInput(arg, actual);
12031203
if (fir::isAllocatableType(argTy) && arg.isIntentOut() &&
12041204
Fortran::semantics::IsBindCProcedure(
12051205
*callContext.procRef.proc().GetSymbol())) {
1206-
TODO(loc, "BIND(C) INTENT(OUT) allocatable deallocation in HLFIR");
1206+
// INTENT(OUT) allocatables are deallocated on the callee side,
1207+
// but BIND(C) procedures may be implemented in C, so deallocation is
1208+
// also done on the caller side (if the procedure is implemented in
1209+
// Fortran, the deallocation attempt in the callee will be a no-op).
1210+
auto [exv, cleanup] =
1211+
hlfir::translateToExtendedValue(loc, builder, actual);
1212+
const auto *mutableBox = exv.getBoxOf<fir::MutableBoxValue>();
1213+
assert(mutableBox && !cleanup && "expect allocatable");
1214+
Fortran::lower::genDeallocateIfAllocated(callContext.converter,
1215+
*mutableBox, loc);
12071216
}
1217+
caller.placeInput(arg, actual);
12081218
} break;
12091219
}
12101220
}

0 commit comments

Comments
 (0)