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"
@@ -1503,6 +1505,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
15031505 out.add (pointerSrc);
15041506 return ;
15051507 }
1508+
15061509 if (Builtin.ID == BuiltinValueKind::AllocVector) {
15071510 (void )args.claimAll ();
15081511 IGF.emitTrap (" escaped vector allocation" , /* EmitUnreachable=*/ true );
@@ -1511,5 +1514,47 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
15111514 IGF.Builder .emitBlock (contBB);
15121515 return ;
15131516 }
1517+
1518+ if (Builtin.ID == BuiltinValueKind::GetEnumTag) {
1519+ auto arg = args.claimNext ();
1520+ auto ty = argTypes[0 ];
1521+ auto &ti = IGF.getTypeInfo (ty);
1522+
1523+ // If the type is just an archetype, then we know nothing about the enum
1524+ // strategy for it. Just call the vwt function. Otherwise, we know that this
1525+ // is at least an enum and can optimize away some of the cost of getEnumTag.
1526+ if (!ty.is <ArchetypeType>()) {
1527+ assert (ty.getEnumOrBoundGenericEnum () && " expected enum type in "
1528+ " getEnumTag builtin!" );
1529+
1530+ auto &strategy = getEnumImplStrategy (IGF.IGM , ty);
1531+
1532+ out.add (strategy.emitGetEnumTag (IGF, ty, ti.getAddressForPointer (arg)));
1533+ return ;
1534+ }
1535+
1536+ out.add (emitGetEnumTagCall (IGF, ty, ti.getAddressForPointer (arg)));
1537+ return ;
1538+ }
1539+
1540+ if (Builtin.ID == BuiltinValueKind::InjectEnumTag) {
1541+ auto input = args.claimNext ();
1542+ auto tag = args.claimNext ();
1543+ auto inputTy = argTypes[0 ];
1544+ auto &inputTi = IGF.getTypeInfo (inputTy);
1545+
1546+ // In order for us to call 'storeTag' on an enum strategy (when type is not
1547+ // an archetype), we'd need to be able to map the tag back into an
1548+ // EnumElementDecl which might be fragile. We don't really care about being
1549+ // able to optimize this vwt function call anyway because we expect most
1550+ // use cases to be the truly dynamic case where the compiler has no static
1551+ // information about the type to be able to optimize it away. Just call the
1552+ // vwt function.
1553+
1554+ emitDestructiveInjectEnumTagCall (IGF, inputTy, tag,
1555+ inputTi.getAddressForPointer (input));
1556+ return ;
1557+ }
1558+
15141559 llvm_unreachable (" IRGen unimplemented for this builtin!" );
15151560}
0 commit comments