Skip to content

Commit 63be84f

Browse files
committed
Merge branch 'master' into release-0.16.0
2 parents 1362534 + 97819eb commit 63be84f

File tree

15 files changed

+250
-256
lines changed

15 files changed

+250
-256
lines changed

gen/abi-aarch64.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,13 @@ struct AArch64TargetABI : TargetABI
110110
}
111111

112112
void vaCopy(LLValue* pDest, LLValue* src) {
113-
// Analog to va_start, we need to allocate a __va_list struct on the stack first
114-
// and set the passed 'dest' char* pointer to its address.
115-
LLValue* valistmem = DtoRawAlloca(getValistType(), 0, "__va_list_mem");
116-
DtoStore(DtoBitCast(valistmem, getVoidPtrType()), pDest);
117-
118-
// Now bitcopy the source struct over the destination struct.
119-
src = DtoBitCast(src, valistmem->getType());
120-
DtoStore(DtoLoad(src), valistmem); // *(__va_list*)dest = *(__va_list*)src
113+
// Analog to va_start, we need to allocate a new __va_list struct on the stack,
114+
// fill it with a bitcopy of the source struct...
115+
src = DtoLoad(DtoBitCast(src, getValistType()->getPointerTo())); // *(__va_list*)src
116+
LLValue* valistmem = DtoAllocaDump(src, 0, "__va_list_mem");
117+
// ... and finally set the passed 'dest' char* pointer to the new struct's address.
118+
DtoStore(DtoBitCast(valistmem, getVoidPtrType()),
119+
DtoBitCast(pDest, getPtrToType(getVoidPtrType())));
121120
}
122121

123122
LLValue* prepareVaArg(LLValue* pAp)

gen/abi-generic.h

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,23 @@ struct LLTypeMemoryLayout
8282
/// Removes padding fields for (non-union-containing!) structs
8383
struct RemoveStructPadding : ABIRewrite {
8484
/// get a rewritten value back to its original form
85-
LLValue* get(Type* dty, DValue* v) {
85+
LLValue* get(Type* dty, LLValue* v) {
8686
LLValue* lval = DtoAlloca(dty, ".rewritetmp");
8787
getL(dty, v, lval);
8888
return lval;
8989
}
9090

9191
/// get a rewritten value back to its original form and store result in provided lvalue
92-
/// this one is optional and defaults to calling the one above
93-
void getL(Type* dty, DValue* v, LLValue* lval) {
92+
void getL(Type* dty, LLValue* v, LLValue* lval) {
9493
// Make sure the padding is zero, so struct comparisons work.
9594
// TODO: Only do this if there's padding, and/or only initialize padding.
9695
DtoMemSetZero(lval, DtoConstSize_t(getTypePaddedSize(DtoType(dty))));
97-
DtoPaddedStruct(dty->toBasetype(), v->getRVal(), lval);
96+
DtoPaddedStruct(dty->toBasetype(), v, lval);
9897
}
9998

10099
/// put out rewritten value
101-
LLValue* put(Type* dty, DValue* v) {
102-
return DtoUnpaddedStruct(dty->toBasetype(), v->getRVal());
100+
LLValue* put(DValue* v) {
101+
return DtoUnpaddedStruct(v->getType()->toBasetype(), v->getRVal());
103102
}
104103

105104
/// return the transformed type for this rewrite
@@ -154,26 +153,22 @@ struct IntegerRewrite : ABIRewrite
154153
return LLTypeMemoryLayout::typesAreEquivalent(llType, integerType);
155154
}
156155

157-
LLValue* get(Type* dty, DValue* dv)
156+
LLValue* get(Type* dty, LLValue* v)
158157
{
159-
LLValue* integer = dv->getRVal();
160-
LLValue* integerDump = storeToMemory(integer, 0, ".IntegerRewrite_dump");
161-
158+
LLValue* integerDump = DtoAllocaDump(v, dty, ".IntegerRewrite_dump");
162159
LLType* type = DtoType(dty);
163160
return loadFromMemory(integerDump, type, ".IntegerRewrite_getResult");
164161
}
165162

166-
void getL(Type* dty, DValue* dv, LLValue* lval)
163+
void getL(Type* dty, LLValue* v, LLValue* lval)
167164
{
168-
LLValue* integer = dv->getRVal();
169-
storeToMemory(integer, lval);
165+
storeToMemory(v, lval);
170166
}
171167

172-
LLValue* put(Type* dty, DValue* dv)
168+
LLValue* put(DValue* dv)
173169
{
174-
assert(dty == dv->getType());
175170
LLValue* address = getAddressOf(dv);
176-
LLType* integerType = getIntegerType(dty->size());
171+
LLType* integerType = getIntegerType(dv->getType()->size());
177172
return loadFromMemory(address, integerType, ".IntegerRewrite_putResult");
178173
}
179174

@@ -205,21 +200,19 @@ struct ExplicitByvalRewrite : ABIRewrite
205200
ExplicitByvalRewrite(size_t alignment = 16) : alignment(alignment)
206201
{ }
207202

208-
LLValue* get(Type* dty, DValue* v)
203+
LLValue* get(Type* dty, LLValue* v)
209204
{
210-
LLValue* pointer = v->getRVal();
211-
return DtoLoad(pointer, ".ExplicitByvalRewrite_getResult");
205+
return DtoLoad(v, ".ExplicitByvalRewrite_getResult");
212206
}
213207

214-
void getL(Type* dty, DValue* v, LLValue* lval)
208+
void getL(Type* dty, LLValue* v, LLValue* lval)
215209
{
216-
LLValue* pointer = v->getRVal();
217-
DtoAggrCopy(lval, pointer);
210+
DtoAggrCopy(lval, v);
218211
}
219212

220-
LLValue* put(Type* dty, DValue* v)
213+
LLValue* put(DValue* v)
221214
{
222-
if (DtoIsPassedByRef(dty))
215+
if (DtoIsPassedByRef(v->getType()))
223216
{
224217
LLValue* originalPointer = v->getRVal();
225218
LLType* type = originalPointer->getType()->getPointerElementType();
@@ -228,9 +221,7 @@ struct ExplicitByvalRewrite : ABIRewrite
228221
return copyForCallee;
229222
}
230223

231-
LLValue* originalValue = v->getRVal();
232-
LLValue* copyForCallee = storeToMemory(originalValue, alignment, ".ExplicitByvalRewrite_putResult");
233-
return copyForCallee;
224+
return DtoAllocaDump(v->getRVal(), alignment, ".ExplicitByvalRewrite_putResult");
234225
}
235226

236227
LLType* type(Type* dty, LLType* t)

gen/abi-x86-64.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,21 @@ namespace {
160160
* memory so that it's then readable as the other type (i.e., bit-casting).
161161
*/
162162
struct X86_64_C_struct_rewrite : ABIRewrite {
163-
LLValue* get(Type* dty, DValue* v)
163+
LLValue* get(Type* dty, LLValue* v)
164164
{
165-
LLValue* address = storeToMemory(v->getRVal(), 0, ".X86_64_C_struct_rewrite_dump");
165+
LLValue* address = DtoAllocaDump(v, dty, ".X86_64_C_struct_rewrite_dump");
166166
LLType* type = DtoType(dty);
167167
return loadFromMemory(address, type, ".X86_64_C_struct_rewrite_getResult");
168168
}
169169

170-
void getL(Type* dty, DValue* v, LLValue* lval) {
171-
storeToMemory(v->getRVal(), lval);
170+
void getL(Type* dty, LLValue* v, LLValue* lval) {
171+
storeToMemory(v, lval);
172172
}
173173

174-
LLValue* put(Type* dty, DValue* v) {
175-
assert(dty == v->getType());
174+
LLValue* put(DValue* v) {
176175
LLValue* address = getAddressOf(v);
177176

178-
LLType* abiTy = getAbiType(dty);
177+
LLType* abiTy = getAbiType(v->getType());
179178
assert(abiTy && "Why are we rewriting a non-rewritten type?");
180179

181180
return loadFromMemory(address, abiTy, ".X86_64_C_struct_rewrite_putResult");
@@ -195,18 +194,15 @@ struct X86_64_C_struct_rewrite : ABIRewrite {
195194
* the ByVal LLVM attribute.
196195
*/
197196
struct ImplicitByvalRewrite : ABIRewrite {
198-
LLValue* get(Type* dty, DValue* v) {
199-
LLValue* pointer = v->getRVal();
200-
return DtoLoad(pointer, ".ImplicitByvalRewrite_getResult");
197+
LLValue* get(Type* dty, LLValue* v) {
198+
return DtoLoad(v, ".ImplicitByvalRewrite_getResult");
201199
}
202200

203-
void getL(Type* dty, DValue* v, LLValue* lval) {
204-
LLValue* pointer = v->getRVal();
205-
DtoAggrCopy(lval, pointer);
201+
void getL(Type* dty, LLValue* v, LLValue* lval) {
202+
DtoAggrCopy(lval, v);
206203
}
207204

208-
LLValue* put(Type* dty, DValue* v) {
209-
assert(dty == v->getType());
205+
LLValue* put(DValue* v) {
210206
return getAddressOf(v);
211207
}
212208

@@ -388,15 +384,13 @@ LLValue* X86_64TargetABI::prepareVaStart(LLValue* pAp) {
388384
}
389385

390386
void X86_64TargetABI::vaCopy(LLValue* pDest, LLValue* src) {
391-
// Analog to va_start, we need to allocate a __va_list struct on the stack first
392-
// and set the passed 'dest' char* pointer to its address.
393-
LLValue* valistmem = DtoRawAlloca(getValistType(), 0, "__va_list_mem");
387+
// Analog to va_start, we need to allocate a new __va_list struct on the stack,
388+
// fill it with a bitcopy of the source struct...
389+
src = DtoLoad(DtoBitCast(src, getValistType()->getPointerTo())); // *(__va_list*)src
390+
LLValue* valistmem = DtoAllocaDump(src, 0, "__va_list_mem");
391+
// ... and finally set the passed 'dest' char* pointer to the new struct's address.
394392
DtoStore(DtoBitCast(valistmem, getVoidPtrType()),
395393
DtoBitCast(pDest, getPtrToType(getVoidPtrType())));
396-
397-
// Now bitcopy the source struct over the destination struct.
398-
src = DtoBitCast(src, valistmem->getType());
399-
DtoStore(DtoLoad(src), valistmem); // *(__va_list*)dest = *(__va_list*)src
400394
}
401395

402396
LLValue* X86_64TargetABI::prepareVaArg(LLValue* pAp)

gen/abi.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
//////////////////////////////////////////////////////////////////////////////
3030

31-
void ABIRewrite::getL(Type* dty, DValue* v, LLValue* lval)
31+
void ABIRewrite::getL(Type* dty, LLValue* v, LLValue* lval)
3232
{
3333
LLValue* rval = get(dty, v);
3434
assert(rval->getType() == lval->getType()->getContainedType(0));
@@ -49,29 +49,22 @@ LLValue* ABIRewrite::getAddressOf(DValue* v)
4949
if (v->isLVal())
5050
return v->getLVal();
5151

52-
return storeToMemory(v->getRVal(), 0, ".getAddressOf_dump");
53-
}
54-
55-
LLValue* ABIRewrite::storeToMemory(LLValue* rval, size_t alignment, const char* name)
56-
{
57-
LLValue* address = DtoRawAlloca(rval->getType(), alignment, name);
58-
DtoStore(rval, address);
59-
return address;
52+
return DtoAllocaDump(v, ".getAddressOf_dump");
6053
}
6154

6255
void ABIRewrite::storeToMemory(LLValue* rval, LLValue* address)
6356
{
6457
LLType* pointerType = address->getType();
6558
assert(pointerType->isPointerTy());
66-
LLType* pointerElementType = pointerType->getPointerElementType();
59+
LLType* pointeeType = pointerType->getPointerElementType();
6760

6861
LLType* rvalType = rval->getType();
69-
if (rvalType != pointerElementType)
62+
if (rvalType != pointeeType)
7063
{
71-
if (getTypeStoreSize(rvalType) > getTypeAllocSize(pointerElementType))
64+
if (getTypeStoreSize(rvalType) > getTypeAllocSize(pointeeType))
7265
{
7366
// not enough allocated memory
74-
LLValue* paddedDump = storeToMemory(rval, 0, ".storeToMemory_paddedDump");
67+
LLValue* paddedDump = DtoAllocaDump(rval, 0, ".storeToMemory_paddedDump");
7568
DtoAggrCopy(address, paddedDump);
7669
return;
7770
}
@@ -86,16 +79,16 @@ LLValue* ABIRewrite::loadFromMemory(LLValue* address, LLType* asType, const char
8679
{
8780
LLType* pointerType = address->getType();
8881
assert(pointerType->isPointerTy());
89-
LLType* pointerElementType = pointerType->getPointerElementType();
82+
LLType* pointeeType = pointerType->getPointerElementType();
9083

91-
if (asType == pointerElementType)
84+
if (asType == pointeeType)
9285
return DtoLoad(address, name);
9386

94-
if (getTypeStoreSize(asType) > getTypeAllocSize(pointerElementType))
87+
if (getTypeStoreSize(asType) > getTypeAllocSize(pointeeType))
9588
{
9689
// not enough allocated memory
9790
LLValue* paddedDump = DtoRawAlloca(asType, 0, ".loadFromMemory_paddedDump");
98-
DtoMemCpy(paddedDump, address, DtoConstSize_t(getTypeAllocSize(pointerElementType)));
91+
DtoMemCpy(paddedDump, address, DtoConstSize_t(getTypeAllocSize(pointeeType)));
9992
return DtoLoad(paddedDump, name);
10093
}
10194

gen/abi.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ struct ABIRewrite
4444
virtual ~ABIRewrite() {}
4545

4646
/// get a rewritten value back to its original form
47-
virtual llvm::Value* get(Type* dty, DValue* v) = 0;
47+
virtual llvm::Value* get(Type* dty, llvm::Value* v) = 0;
4848

4949
/// get a rewritten value back to its original form and store result in provided lvalue
5050
/// this one is optional and defaults to calling the one above
51-
virtual void getL(Type* dty, DValue* v, llvm::Value* lval);
51+
virtual void getL(Type* dty, llvm::Value* v, llvm::Value* lval);
5252

5353
/// put out rewritten value
54-
virtual llvm::Value* put(Type* dty, DValue* v) = 0;
54+
virtual llvm::Value* put(DValue* v) = 0;
5555

5656
/// should return the transformed type for this rewrite
5757
virtual llvm::Type* type(Type* dty, llvm::Type* t) = 0;
@@ -62,10 +62,6 @@ struct ABIRewrite
6262
// Returns the address of a D value, storing it to memory first if need be.
6363
static llvm::Value* getAddressOf(DValue* v);
6464

65-
// Stores a LL value to memory and returns its address.
66-
static llvm::Value* storeToMemory(llvm::Value* rval, size_t alignment = 0,
67-
const char* name = ".store_result");
68-
6965
// Stores a LL value to a specified memory address. The element type of the provided
7066
// pointer doesn't need to match the value type (=> suited for bit-casting).
7167
static void storeToMemory(llvm::Value* rval, llvm::Value* address);

gen/arrays.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ static void DtoArrayInit(Loc& loc, LLValue* ptr, LLValue* length, DValue* dvalue
150150
gIR->topfunc());
151151

152152
// initialize iterator
153-
LLValue *itr = DtoAlloca(Type::tsize_t, "arrayinit.itr");
154-
DtoStore(DtoConstSize_t(0), itr);
153+
LLValue *itr = DtoAllocaDump(DtoConstSize_t(0), 0, "arrayinit.itr");
155154

156155
// move into the for condition block, ie. start the loop
157156
assert(!gIR->scopereturned());

gen/asmstmt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState* p)
512512

513513
// location of the special value determining the goto label
514514
// will be set if post-asm dispatcher block is needed
515-
llvm::AllocaInst* jump_target = 0;
515+
LLValue* jump_target = 0;
516516

517517
{
518518
FuncDeclaration* fd = gIR->func()->decl;
@@ -577,8 +577,7 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState* p)
577577
outSetterStmt->code += asmGotoEndLabel.str()+":\n";
578578

579579
// create storage for and initialize the temporary
580-
jump_target = DtoAlloca(Type::tint32, "__llvm_jump_target");
581-
gIR->ir->CreateStore(DtoConstUint(0), jump_target);
580+
jump_target = DtoAllocaDump(DtoConstUint(0), 0, "__llvm_jump_target");
582581
// setup variable for output from asm
583582
outSetterStmt->out_c = "=*m,";
584583
outSetterStmt->out.push_back(jump_target);

gen/functions.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
819819
LLValue* thismem = thisvar;
820820
if (!irFty.arg_this->byref)
821821
{
822-
thismem = DtoRawAlloca(thisvar->getType(), 0, "this"); // FIXME: align?
823-
DtoStore(thisvar, thismem);
822+
thismem = DtoAllocaDump(thisvar, 0, "this");
824823
irFunc->thisArg = thismem;
825824
}
826825

@@ -832,12 +831,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
832831

833832
// give the 'nestArg' storage
834833
if (irFty.arg_nest)
835-
{
836-
LLValue *nestArg = irFunc->nestArg;
837-
LLValue *val = DtoRawAlloca(nestArg->getType(), 0, "nestedFrame");
838-
DtoStore(nestArg, val);
839-
irFunc->nestArg = val;
840-
}
834+
irFunc->nestArg = DtoAllocaDump(irFunc->nestArg, 0, "nestedFrame");
841835

842836
// give arguments storage and debug info
843837
if (fd->parameters)
@@ -873,8 +867,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
873867
LLValue* mem = DtoAlloca(irparam->arg->type, vd->ident->toChars());
874868

875869
// let the abi transform the argument back first
876-
DImValue arg_dval(vd->type, irparam->value);
877-
irFty.getParam(vd->type, llArgIdx, &arg_dval, mem);
870+
irFty.getParam(vd->type, llArgIdx, irparam->value, mem);
878871

879872
// set the arg var value to the alloca
880873
irparam->value = mem;
@@ -912,10 +905,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
912905
llvm::CallInst::Create(GET_INTRINSIC_DECL(vastart), vaStartArg, "", gIR->scopebb());
913906

914907
// copy _arguments to a memory location
915-
LLType* argumentsType = irFunc->_arguments->getType();
916-
LLValue* argumentsmem = DtoRawAlloca(argumentsType, 0, "_arguments_mem");
917-
new llvm::StoreInst(irFunc->_arguments, argumentsmem, gIR->scopebb());
918-
irFunc->_arguments = argumentsmem;
908+
irFunc->_arguments = DtoAllocaDump(irFunc->_arguments, 0, "_arguments_mem");
919909
}
920910

921911
// output function body

0 commit comments

Comments
 (0)