diff gen/aa.cpp @ 1418:f5f8c21ce6ef

Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls these were using were different, but with equivalent definitions. With `ldc -O3`, the following functions now all compile to the exact same code: {{{ int[int] y; void foo(int x) { if (x in y) { auto z = x in y; sink(*z); } } void bar(int x) { if (x in y) { sink(y[x]); } } void baz(int x) { if (auto p = x in y) { sink(*p); } } }}}
author Frits van Bommel <fvbommel wxs.nl>
date Mon, 25 May 2009 12:50:40 +0200
parents 15e9762bb620
children 09734fb929c0
line wrap: on
line diff
--- a/gen/aa.cpp	Sat May 23 23:18:47 2009 +0200
+++ b/gen/aa.cpp	Mon May 25 12:50:40 2009 +0200
@@ -64,10 +64,10 @@
     // call:
     // extern(C) void* _aaGet(AA* aa, TypeInfo keyti, size_t valuesize, void* pkey)
     // or
-    // extern(C) void* _aaGetRvalue(AA aa, TypeInfo keyti, size_t valuesize, void* pkey)
+    // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey)
 
     // first get the runtime function
-    llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, lvalue?"_aaGet":"_aaGetRvalue");
+    llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, lvalue?"_aaGet":"_aaIn");
     const llvm::FunctionType* funcTy = func->getFunctionType();
 
     // aa param
@@ -78,15 +78,20 @@
     LLValue* keyti = to_keyti(key);
     keyti = DtoBitCast(keyti, funcTy->getParamType(1));
 
-    // valuesize param
-    LLValue* valsize = DtoConstSize_t(getTypePaddedSize(DtoType(type)));
-
     // pkey param
     LLValue* pkey = to_pkey(loc, key);
-    pkey = DtoBitCast(pkey, funcTy->getParamType(3));
+    pkey = DtoBitCast(pkey, funcTy->getParamType(lvalue ? 3 : 2));
 
     // call runtime
-    LLValue* ret = gIR->CreateCallOrInvoke4(func, aaval, keyti, valsize, pkey, "aa.index").getInstruction();
+    LLValue* ret;
+    if (lvalue) {
+        // valuesize param
+        LLValue* valsize = DtoConstSize_t(getTypePaddedSize(DtoType(type)));
+        
+        ret = gIR->CreateCallOrInvoke4(func, aaval, keyti, valsize, pkey, "aa.index").getInstruction();
+    } else {
+        ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.index").getInstruction();
+    }
 
     // cast return value
     const LLType* targettype = getPtrToType(DtoType(type));