comparison gen/abi.cpp @ 1571:8d086d552909

IntegerType is now contextifed. Requires llvm >= 78969. resistor says this will be the last context API change :)
author Benjamin Kramer <benny.kra@gmail.com>
date Fri, 14 Aug 2009 00:39:18 +0200
parents d6e8d5db259f
children
comparison
equal deleted inserted replaced
1570:ab03cfb3a212 1571:8d086d552909
54 LLValue* get(Type*, DValue* dv) 54 LLValue* get(Type*, DValue* dv)
55 { 55 {
56 LLValue* in = dv->getRVal(); 56 LLValue* in = dv->getRVal();
57 57
58 // extract real part 58 // extract real part
59 LLValue* rpart = gIR->ir->CreateTrunc(in, LLType::Int32Ty); 59 LLValue* rpart = gIR->ir->CreateTrunc(in, LLType::getInt32Ty(gIR->context()));
60 rpart = gIR->ir->CreateBitCast(rpart, LLType::FloatTy, ".re"); 60 rpart = gIR->ir->CreateBitCast(rpart, LLType::getFloatTy(gIR->context()), ".re");
61 61
62 // extract imag part 62 // extract imag part
63 LLValue* ipart = gIR->ir->CreateLShr(in, LLConstantInt::get(LLType::Int64Ty, 32, false)); 63 LLValue* ipart = gIR->ir->CreateLShr(in, LLConstantInt::get(LLType::getInt64Ty(gIR->context()), 32, false));
64 ipart = gIR->ir->CreateTrunc(ipart, LLType::Int32Ty); 64 ipart = gIR->ir->CreateTrunc(ipart, LLType::getInt32Ty(gIR->context()));
65 ipart = gIR->ir->CreateBitCast(ipart, LLType::FloatTy, ".im"); 65 ipart = gIR->ir->CreateBitCast(ipart, LLType::getFloatTy(gIR->context()), ".im");
66 66
67 // return {float,float} aggr pair with same bits 67 // return {float,float} aggr pair with same bits
68 return DtoAggrPair(rpart, ipart, ".final_cfloat"); 68 return DtoAggrPair(rpart, ipart, ".final_cfloat");
69 } 69 }
70 70
74 LLValue* v = dv->getRVal(); 74 LLValue* v = dv->getRVal();
75 75
76 // extract real 76 // extract real
77 LLValue* r = gIR->ir->CreateExtractValue(v, 0); 77 LLValue* r = gIR->ir->CreateExtractValue(v, 0);
78 // cast to i32 78 // cast to i32
79 r = gIR->ir->CreateBitCast(r, LLType::Int32Ty); 79 r = gIR->ir->CreateBitCast(r, LLType::getInt32Ty(gIR->context()));
80 // zext to i64 80 // zext to i64
81 r = gIR->ir->CreateZExt(r, LLType::Int64Ty); 81 r = gIR->ir->CreateZExt(r, LLType::getInt64Ty(gIR->context()));
82 82
83 // extract imag 83 // extract imag
84 LLValue* i = gIR->ir->CreateExtractValue(v, 1); 84 LLValue* i = gIR->ir->CreateExtractValue(v, 1);
85 // cast to i32 85 // cast to i32
86 i = gIR->ir->CreateBitCast(i, LLType::Int32Ty); 86 i = gIR->ir->CreateBitCast(i, LLType::getInt32Ty(gIR->context()));
87 // zext to i64 87 // zext to i64
88 i = gIR->ir->CreateZExt(i, LLType::Int64Ty); 88 i = gIR->ir->CreateZExt(i, LLType::getInt64Ty(gIR->context()));
89 // shift up 89 // shift up
90 i = gIR->ir->CreateShl(i, LLConstantInt::get(LLType::Int64Ty, 32, false)); 90 i = gIR->ir->CreateShl(i, LLConstantInt::get(LLType::getInt64Ty(gIR->context()), 32, false));
91 91
92 // combine and return 92 // combine and return
93 return v = gIR->ir->CreateOr(r, i); 93 return v = gIR->ir->CreateOr(r, i);
94 } 94 }
95 95
96 // {float,float} -> i64 96 // {float,float} -> i64
97 const LLType* type(Type*, const LLType* t) 97 const LLType* type(Type*, const LLType* t)
98 { 98 {
99 return LLType::Int64Ty; 99 return LLType::getInt64Ty(gIR->context());
100 } 100 }
101 }; 101 };
102 102
103 ////////////////////////////////////////////////////////////////////////////// 103 //////////////////////////////////////////////////////////////////////////////
104 104
129 LLValue* put(Type* dty, DValue* dv) 129 LLValue* put(Type* dty, DValue* dv)
130 { 130 {
131 Logger::println("rewriting struct -> int"); 131 Logger::println("rewriting struct -> int");
132 assert(dv->isLVal()); 132 assert(dv->isLVal());
133 LLValue* mem = dv->getLVal(); 133 LLValue* mem = dv->getLVal();
134 const LLType* t = LLIntegerType::get(dty->size()*8); 134 const LLType* t = LLIntegerType::get(gIR->context(), dty->size()*8);
135 return DtoLoad(DtoBitCast(mem, getPtrToType(t))); 135 return DtoLoad(DtoBitCast(mem, getPtrToType(t)));
136 } 136 }
137 const LLType* type(Type* t, const LLType*) 137 const LLType* type(Type* t, const LLType*)
138 { 138 {
139 size_t sz = t->size()*8; 139 size_t sz = t->size()*8;
140 return LLIntegerType::get(sz); 140 return LLIntegerType::get(gIR->context(), sz);
141 } 141 }
142 }; 142 };
143 143
144 ////////////////////////////////////////////////////////////////////////////// 144 //////////////////////////////////////////////////////////////////////////////
145 145
256 256
257 // cfloat -> i64 257 // cfloat -> i64
258 if (tf->next->toBasetype() == Type::tcomplex32) 258 if (tf->next->toBasetype() == Type::tcomplex32)
259 { 259 {
260 fty.ret->rewrite = &cfloatToInt; 260 fty.ret->rewrite = &cfloatToInt;
261 fty.ret->ltype = LLType::Int64Ty; 261 fty.ret->ltype = LLType::getInt64Ty(gIR->context());
262 } 262 }
263 263
264 // IMPLICIT PARAMETERS 264 // IMPLICIT PARAMETERS
265 265
266 // EXPLICIT PARAMETERS 266 // EXPLICIT PARAMETERS