|
@@ -61,21 +61,30 @@ llvm::Value *CodeGenFunction::EmitCastToVoidPtr(llvm::Value *value) {
|
|
|
|
|
|
/// CreateTempAlloca - This creates a alloca and inserts it into the entry
|
|
/// CreateTempAlloca - This creates a alloca and inserts it into the entry
|
|
/// block.
|
|
/// block.
|
|
|
|
+Address CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type *Ty,
|
|
|
|
+ CharUnits Align,
|
|
|
|
+ const Twine &Name,
|
|
|
|
+ llvm::Value *ArraySize) {
|
|
|
|
+ auto Alloca = CreateTempAlloca(Ty, Name, ArraySize);
|
|
|
|
+ Alloca->setAlignment(Align.getQuantity());
|
|
|
|
+ return Address(Alloca, Align);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// CreateTempAlloca - This creates a alloca and inserts it into the entry
|
|
|
|
+/// block. The alloca is casted to default address space if necessary.
|
|
Address CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
|
|
Address CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
|
|
const Twine &Name,
|
|
const Twine &Name,
|
|
llvm::Value *ArraySize,
|
|
llvm::Value *ArraySize,
|
|
- Address *AllocaAddr,
|
|
|
|
- bool CastToDefaultAddrSpace) {
|
|
|
|
- auto Alloca = CreateTempAlloca(Ty, Name, ArraySize);
|
|
|
|
- Alloca->setAlignment(Align.getQuantity());
|
|
|
|
|
|
+ Address *AllocaAddr) {
|
|
|
|
+ auto Alloca = CreateTempAllocaWithoutCast(Ty, Align, Name, ArraySize);
|
|
if (AllocaAddr)
|
|
if (AllocaAddr)
|
|
- *AllocaAddr = Address(Alloca, Align);
|
|
|
|
- llvm::Value *V = Alloca;
|
|
|
|
|
|
+ *AllocaAddr = Alloca;
|
|
|
|
+ llvm::Value *V = Alloca.getPointer();
|
|
// Alloca always returns a pointer in alloca address space, which may
|
|
// Alloca always returns a pointer in alloca address space, which may
|
|
// be different from the type defined by the language. For example,
|
|
// be different from the type defined by the language. For example,
|
|
// in C++ the auto variables are in the default address space. Therefore
|
|
// in C++ the auto variables are in the default address space. Therefore
|
|
// cast alloca to the default address space when necessary.
|
|
// cast alloca to the default address space when necessary.
|
|
- if (CastToDefaultAddrSpace && getASTAllocaAddressSpace() != LangAS::Default) {
|
|
|
|
|
|
+ if (getASTAllocaAddressSpace() != LangAS::Default) {
|
|
auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);
|
|
auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);
|
|
llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
|
|
llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
|
|
// When ArraySize is nullptr, alloca is inserted at AllocaInsertPt,
|
|
// When ArraySize is nullptr, alloca is inserted at AllocaInsertPt,
|
|
@@ -128,19 +137,26 @@ Address CodeGenFunction::CreateIRTemp(QualType Ty, const Twine &Name) {
|
|
}
|
|
}
|
|
|
|
|
|
Address CodeGenFunction::CreateMemTemp(QualType Ty, const Twine &Name,
|
|
Address CodeGenFunction::CreateMemTemp(QualType Ty, const Twine &Name,
|
|
- Address *Alloca,
|
|
|
|
- bool CastToDefaultAddrSpace) {
|
|
|
|
|
|
+ Address *Alloca) {
|
|
// FIXME: Should we prefer the preferred type alignment here?
|
|
// FIXME: Should we prefer the preferred type alignment here?
|
|
- return CreateMemTemp(Ty, getContext().getTypeAlignInChars(Ty), Name, Alloca,
|
|
|
|
- CastToDefaultAddrSpace);
|
|
|
|
|
|
+ return CreateMemTemp(Ty, getContext().getTypeAlignInChars(Ty), Name, Alloca);
|
|
}
|
|
}
|
|
|
|
|
|
Address CodeGenFunction::CreateMemTemp(QualType Ty, CharUnits Align,
|
|
Address CodeGenFunction::CreateMemTemp(QualType Ty, CharUnits Align,
|
|
- const Twine &Name, Address *Alloca,
|
|
|
|
- bool CastToDefaultAddrSpace) {
|
|
|
|
|
|
+ const Twine &Name, Address *Alloca) {
|
|
return CreateTempAlloca(ConvertTypeForMem(Ty), Align, Name,
|
|
return CreateTempAlloca(ConvertTypeForMem(Ty), Align, Name,
|
|
- /*ArraySize=*/nullptr, Alloca,
|
|
|
|
- CastToDefaultAddrSpace);
|
|
|
|
|
|
+ /*ArraySize=*/nullptr, Alloca);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Address CodeGenFunction::CreateMemTempWithoutCast(QualType Ty, CharUnits Align,
|
|
|
|
+ const Twine &Name) {
|
|
|
|
+ return CreateTempAllocaWithoutCast(ConvertTypeForMem(Ty), Align, Name);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Address CodeGenFunction::CreateMemTempWithoutCast(QualType Ty,
|
|
|
|
+ const Twine &Name) {
|
|
|
|
+ return CreateMemTempWithoutCast(Ty, getContext().getTypeAlignInChars(Ty),
|
|
|
|
+ Name);
|
|
}
|
|
}
|
|
|
|
|
|
/// EvaluateExprAsBool - Perform the usual unary conversions on the specified
|
|
/// EvaluateExprAsBool - Perform the usual unary conversions on the specified
|