@@ -81,16 +81,15 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
81
81
if (DiscardResult)
82
82
return this ->discard (SubExpr);
83
83
84
- return dereference (
85
- SubExpr, DerefKind::Read,
86
- [](PrimType) {
87
- // Value loaded - nothing to do here.
88
- return true ;
89
- },
90
- [this , CE](PrimType T) {
91
- // Pointer on stack - dereference it.
92
- return this ->emitLoadPop (T, CE);
93
- });
84
+ if (SubExpr->getType ()->isAnyComplexType ())
85
+ return this ->delegate (SubExpr);
86
+
87
+ if (!this ->visit (SubExpr))
88
+ return false ;
89
+
90
+ if (std::optional<PrimType> SubExprT = classify (SubExpr->getType ()))
91
+ return this ->emitLoadPop (*SubExprT, CE);
92
+ return false ;
94
93
}
95
94
96
95
case CK_UncheckedDerivedToBase:
@@ -2326,134 +2325,6 @@ bool ByteCodeExprGen<Emitter>::visitZeroRecordInitializer(const Record *R,
2326
2325
return true ;
2327
2326
}
2328
2327
2329
- template <class Emitter >
2330
- bool ByteCodeExprGen<Emitter>::dereference(
2331
- const Expr *LV, DerefKind AK, llvm::function_ref<bool (PrimType)> Direct,
2332
- llvm::function_ref<bool (PrimType)> Indirect) {
2333
- if (std::optional<PrimType> T = classify (LV->getType ())) {
2334
- if (!LV->refersToBitField ()) {
2335
- // Only primitive, non bit-field types can be dereferenced directly.
2336
- if (const auto *DE = dyn_cast<DeclRefExpr>(LV)) {
2337
- if (!DE->getDecl ()->getType ()->isReferenceType ()) {
2338
- if (const auto *PD = dyn_cast<ParmVarDecl>(DE->getDecl ()))
2339
- return dereferenceParam (LV, *T, PD, AK, Direct, Indirect);
2340
- if (const auto *VD = dyn_cast<VarDecl>(DE->getDecl ()))
2341
- return dereferenceVar (LV, *T, VD, AK, Direct, Indirect);
2342
- }
2343
- }
2344
- }
2345
-
2346
- if (!visit (LV))
2347
- return false ;
2348
- return Indirect (*T);
2349
- }
2350
-
2351
- if (LV->getType ()->isAnyComplexType ())
2352
- return this ->delegate (LV);
2353
-
2354
- return false ;
2355
- }
2356
-
2357
- template <class Emitter >
2358
- bool ByteCodeExprGen<Emitter>::dereferenceParam(
2359
- const Expr *LV, PrimType T, const ParmVarDecl *PD, DerefKind AK,
2360
- llvm::function_ref<bool (PrimType)> Direct,
2361
- llvm::function_ref<bool (PrimType)> Indirect) {
2362
- if (auto It = this ->Params .find (PD); It != this ->Params .end ()) {
2363
- unsigned Idx = It->second .Offset ;
2364
- switch (AK) {
2365
- case DerefKind::Read:
2366
- return DiscardResult ? true : this ->emitGetParam (T, Idx, LV);
2367
-
2368
- case DerefKind::Write:
2369
- if (!Direct (T))
2370
- return false ;
2371
- if (!this ->emitSetParam (T, Idx, LV))
2372
- return false ;
2373
- return DiscardResult ? true : this ->emitGetPtrParam (Idx, LV);
2374
-
2375
- case DerefKind::ReadWrite:
2376
- if (!this ->emitGetParam (T, Idx, LV))
2377
- return false ;
2378
- if (!Direct (T))
2379
- return false ;
2380
- if (!this ->emitSetParam (T, Idx, LV))
2381
- return false ;
2382
- return DiscardResult ? true : this ->emitGetPtrParam (Idx, LV);
2383
- }
2384
- return true ;
2385
- }
2386
-
2387
- // If the param is a pointer, we can dereference a dummy value.
2388
- if (!DiscardResult && T == PT_Ptr && AK == DerefKind::Read) {
2389
- if (auto Idx = P.getOrCreateDummy (PD))
2390
- return this ->emitGetPtrGlobal (*Idx, PD);
2391
- return false ;
2392
- }
2393
-
2394
- // Value cannot be produced - try to emit pointer and do stuff with it.
2395
- return visit (LV) && Indirect (T);
2396
- }
2397
-
2398
- template <class Emitter >
2399
- bool ByteCodeExprGen<Emitter>::dereferenceVar(
2400
- const Expr *LV, PrimType T, const VarDecl *VD, DerefKind AK,
2401
- llvm::function_ref<bool (PrimType)> Direct,
2402
- llvm::function_ref<bool (PrimType)> Indirect) {
2403
- auto It = Locals.find (VD);
2404
- if (It != Locals.end ()) {
2405
- const auto &L = It->second ;
2406
- switch (AK) {
2407
- case DerefKind::Read:
2408
- if (!this ->emitGetLocal (T, L.Offset , LV))
2409
- return false ;
2410
- return DiscardResult ? this ->emitPop (T, LV) : true ;
2411
-
2412
- case DerefKind::Write:
2413
- if (!Direct (T))
2414
- return false ;
2415
- if (!this ->emitSetLocal (T, L.Offset , LV))
2416
- return false ;
2417
- return DiscardResult ? true : this ->emitGetPtrLocal (L.Offset , LV);
2418
-
2419
- case DerefKind::ReadWrite:
2420
- if (!this ->emitGetLocal (T, L.Offset , LV))
2421
- return false ;
2422
- if (!Direct (T))
2423
- return false ;
2424
- if (!this ->emitSetLocal (T, L.Offset , LV))
2425
- return false ;
2426
- return DiscardResult ? true : this ->emitGetPtrLocal (L.Offset , LV);
2427
- }
2428
- } else if (auto Idx = P.getGlobal (VD)) {
2429
- switch (AK) {
2430
- case DerefKind::Read:
2431
- if (!this ->emitGetGlobal (T, *Idx, LV))
2432
- return false ;
2433
- return DiscardResult ? this ->emitPop (T, LV) : true ;
2434
-
2435
- case DerefKind::Write:
2436
- if (!Direct (T))
2437
- return false ;
2438
- if (!this ->emitSetGlobal (T, *Idx, LV))
2439
- return false ;
2440
- return DiscardResult ? true : this ->emitGetPtrGlobal (*Idx, LV);
2441
-
2442
- case DerefKind::ReadWrite:
2443
- if (!this ->emitGetGlobal (T, *Idx, LV))
2444
- return false ;
2445
- if (!Direct (T))
2446
- return false ;
2447
- if (!this ->emitSetGlobal (T, *Idx, LV))
2448
- return false ;
2449
- return DiscardResult ? true : this ->emitGetPtrGlobal (*Idx, LV);
2450
- }
2451
- }
2452
-
2453
- // Value cannot be produced - try to emit pointer.
2454
- return visit (LV) && Indirect (T);
2455
- }
2456
-
2457
2328
template <class Emitter >
2458
2329
template <typename T>
2459
2330
bool ByteCodeExprGen<Emitter>::emitConst(T Value, PrimType Ty, const Expr *E) {
@@ -3092,15 +2963,9 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
3092
2963
// We should already have a pointer when we get here.
3093
2964
return this ->delegate (SubExpr);
3094
2965
case UO_Deref: // *x
3095
- return dereference (
3096
- SubExpr, DerefKind::Read,
3097
- [](PrimType) {
3098
- llvm_unreachable (" Dereferencing requires a pointer" );
3099
- return false ;
3100
- },
3101
- [this , E](PrimType T) {
3102
- return DiscardResult ? this ->emitPop (T, E) : true ;
3103
- });
2966
+ if (DiscardResult)
2967
+ return this ->discard (SubExpr);
2968
+ return this ->visit (SubExpr);
3104
2969
case UO_Not: // ~x
3105
2970
if (!this ->visit (SubExpr))
3106
2971
return false ;
0 commit comments