@@ -2023,11 +2023,14 @@ class CodeGenFunction : public CodeGenTypeCache {
2023
2023
// / various ways, this function will perform the cast by default. The cast
2024
2024
// / may be avoided by passing false as \p CastToDefaultAddrSpace; this is
2025
2025
// / more efficient if the caller knows that the address will not be exposed.
2026
+ // / The original alloca instruction is returned through \p Alloca if it is
2027
+ // / not nullptr.
2026
2028
llvm::AllocaInst *CreateTempAlloca (llvm::Type *Ty, const Twine &Name = " tmp" ,
2027
2029
llvm::Value *ArraySize = nullptr );
2028
2030
Address CreateTempAlloca (llvm::Type *Ty, CharUnits align,
2029
2031
const Twine &Name = " tmp" ,
2030
2032
llvm::Value *ArraySize = nullptr ,
2033
+ Address *Alloca = nullptr ,
2031
2034
bool CastToDefaultAddrSpace = true );
2032
2035
2033
2036
// / CreateDefaultAlignedTempAlloca - This creates an alloca with the
@@ -2064,10 +2067,13 @@ class CodeGenFunction : public CodeGenTypeCache {
2064
2067
2065
2068
// / CreateMemTemp - Create a temporary memory object of the given type, with
2066
2069
// / appropriate alignment. Cast it to the default address space if
2067
- // / \p CastToDefaultAddrSpace is true.
2070
+ // / \p CastToDefaultAddrSpace is true. Returns the original alloca
2071
+ // / instruction by \p Alloca if it is not nullptr.
2068
2072
Address CreateMemTemp (QualType T, const Twine &Name = " tmp" ,
2073
+ Address *Alloca = nullptr ,
2069
2074
bool CastToDefaultAddrSpace = true );
2070
2075
Address CreateMemTemp (QualType T, CharUnits Align, const Twine &Name = " tmp" ,
2076
+ Address *Alloca = nullptr ,
2071
2077
bool CastToDefaultAddrSpace = true );
2072
2078
2073
2079
// / CreateAggTemp - Create a temporary memory object for the given
@@ -2515,7 +2521,9 @@ class CodeGenFunction : public CodeGenTypeCache {
2515
2521
2516
2522
const VarDecl *Variable;
2517
2523
2518
- // / The address of the alloca. Invalid if the variable was emitted
2524
+ // / The address of the alloca for languages with explicit address space
2525
+ // / (e.g. OpenCL) or alloca casted to generic pointer for address space
2526
+ // / agnostic languages (e.g. C++). Invalid if the variable was emitted
2519
2527
// / as a global constant.
2520
2528
Address Addr;
2521
2529
@@ -2531,13 +2539,19 @@ class CodeGenFunction : public CodeGenTypeCache {
2531
2539
// / Non-null if we should use lifetime annotations.
2532
2540
llvm::Value *SizeForLifetimeMarkers;
2533
2541
2542
+ // / Address with original alloca instruction. Invalid if the variable was
2543
+ // / emitted as a global constant.
2544
+ Address AllocaAddr;
2545
+
2534
2546
struct Invalid {};
2535
- AutoVarEmission (Invalid) : Variable(nullptr ), Addr(Address::invalid()) {}
2547
+ AutoVarEmission (Invalid)
2548
+ : Variable(nullptr ), Addr(Address::invalid()),
2549
+ AllocaAddr (Address::invalid()) {}
2536
2550
2537
2551
AutoVarEmission (const VarDecl &variable)
2538
- : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr ),
2539
- IsByRef (false ), IsConstantAggregate(false ),
2540
- SizeForLifetimeMarkers(nullptr ) {}
2552
+ : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr ),
2553
+ IsByRef(false ), IsConstantAggregate(false ),
2554
+ SizeForLifetimeMarkers(nullptr ), AllocaAddr(Address::invalid() ) {}
2541
2555
2542
2556
bool wasEmittedAsGlobal () const { return !Addr.isValid (); }
2543
2557
@@ -2553,11 +2567,15 @@ class CodeGenFunction : public CodeGenTypeCache {
2553
2567
}
2554
2568
2555
2569
// / Returns the raw, allocated address, which is not necessarily
2556
- // / the address of the object itself.
2570
+ // / the address of the object itself. It is casted to default
2571
+ // / address space for address space agnostic languages.
2557
2572
Address getAllocatedAddress () const {
2558
2573
return Addr;
2559
2574
}
2560
2575
2576
+ // / Returns the address for the original alloca instruction.
2577
+ Address getOriginalAllocatedAddress () const { return AllocaAddr; }
2578
+
2561
2579
// / Returns the address of the object within this declaration.
2562
2580
// / Note that this does not chase the forwarding pointer for
2563
2581
// / __block decls.
0 commit comments