3131#include " GenCast.h"
3232#include " GenConcurrency.h"
3333#include " GenDistributed.h"
34+ #include " GenEnum.h"
3435#include " GenPointerAuth.h"
3536#include " GenIntegerLiteral.h"
37+ #include " GenOpaque.h"
3638#include " IRGenFunction.h"
3739#include " IRGenModule.h"
3840#include " LoadableTypeInfo.h"
@@ -1490,6 +1492,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
14901492 out.add (pointerSrc);
14911493 return ;
14921494 }
1495+
14931496 if (Builtin.ID == BuiltinValueKind::AllocVector) {
14941497 (void )args.claimAll ();
14951498 IGF.emitTrap (" escaped vector allocation" , /* EmitUnreachable=*/ true );
@@ -1498,5 +1501,47 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
14981501 IGF.Builder .emitBlock (contBB);
14991502 return ;
15001503 }
1504+
1505+ if (Builtin.ID == BuiltinValueKind::GetEnumTag) {
1506+ auto arg = args.claimNext ();
1507+ auto ty = argTypes[0 ];
1508+ auto &ti = IGF.getTypeInfo (ty);
1509+
1510+ // If the type is just an archetype, then we know nothing about the enum
1511+ // strategy for it. Just call the vwt function. Otherwise, we know that this
1512+ // is at least an enum and can optimize away some of the cost of getEnumTag.
1513+ if (!ty.is <ArchetypeType>()) {
1514+ assert (ty.getEnumOrBoundGenericEnum () && " expected enum type in "
1515+ " getEnumTag builtin!" );
1516+
1517+ auto &strategy = getEnumImplStrategy (IGF.IGM , ty);
1518+
1519+ out.add (strategy.emitGetEnumTag (IGF, ty, ti.getAddressForPointer (arg)));
1520+ return ;
1521+ }
1522+
1523+ out.add (emitGetEnumTagCall (IGF, ty, ti.getAddressForPointer (arg)));
1524+ return ;
1525+ }
1526+
1527+ if (Builtin.ID == BuiltinValueKind::InjectEnumTag) {
1528+ auto input = args.claimNext ();
1529+ auto tag = args.claimNext ();
1530+ auto inputTy = argTypes[0 ];
1531+ auto &inputTi = IGF.getTypeInfo (inputTy);
1532+
1533+ // In order for us to call 'storeTag' on an enum strategy (when type is not
1534+ // an archetype), we'd need to be able to map the tag back into an
1535+ // EnumElementDecl which might be fragile. We don't really care about being
1536+ // able to optimize this vwt function call anyway because we expect most
1537+ // use cases to be the truly dynamic case where the compiler has no static
1538+ // information about the type to be able to optimize it away. Just call the
1539+ // vwt function.
1540+
1541+ emitDestructiveInjectEnumTagCall (IGF, inputTy, tag,
1542+ inputTi.getAddressForPointer (input));
1543+ return ;
1544+ }
1545+
15011546 llvm_unreachable (" IRGen unimplemented for this builtin!" );
15021547}
0 commit comments