Skip to content

Commit 98be759

Browse files
tbaederrsvkeerthy
authored andcommitted
[clang][bytecode] Make some builtins no-ops (#141952)
For some builtins, we dont' need to do anything, but due to the cleanup code being the same for all builtins, we still had to duplicate the value on the stack. Remove that and get rid of all the unnecessary pressure on the InterpStack.
1 parent 4fac256 commit 98be759

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@
2323
namespace clang {
2424
namespace interp {
2525

26+
static bool isNoopBuiltin(unsigned ID) {
27+
switch (ID) {
28+
case Builtin::BIas_const:
29+
case Builtin::BIforward:
30+
case Builtin::BIforward_like:
31+
case Builtin::BImove:
32+
case Builtin::BImove_if_noexcept:
33+
case Builtin::BIaddressof:
34+
case Builtin::BI__addressof:
35+
case Builtin::BI__builtin_addressof:
36+
case Builtin::BI__builtin_launder:
37+
return true;
38+
default:
39+
return false;
40+
}
41+
return false;
42+
}
43+
2644
static unsigned callArgSize(const InterpState &S, const CallExpr *C) {
2745
unsigned O = 0;
2846

@@ -100,6 +118,8 @@ static bool retBI(InterpState &S, const CallExpr *Call, unsigned BuiltinID) {
100118
static bool retPrimValue(InterpState &S, CodePtr OpPC,
101119
std::optional<PrimType> &T, const CallExpr *Call,
102120
unsigned BuiltinID) {
121+
if (isNoopBuiltin(BuiltinID))
122+
return true;
103123

104124
if (!T) {
105125
if (!Context::isUnevaluatedBuiltin(BuiltinID)) {
@@ -745,24 +765,14 @@ static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC,
745765
const CallExpr *Call) {
746766
assert(Call->getArg(0)->isLValue());
747767
PrimType PtrT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
748-
749-
if (PtrT == PT_Ptr) {
750-
const Pointer &Arg = S.Stk.peek<Pointer>();
751-
S.Stk.push<Pointer>(Arg);
752-
} else {
753-
assert(false && "Unsupported pointer type passed to __builtin_addressof()");
754-
}
768+
assert(PtrT == PT_Ptr &&
769+
"Unsupported pointer type passed to __builtin_addressof()");
755770
return true;
756771
}
757772

758773
static bool interp__builtin_move(InterpState &S, CodePtr OpPC,
759774
const InterpFrame *Frame,
760775
const CallExpr *Call) {
761-
762-
PrimType ArgT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
763-
764-
TYPE_SWITCH(ArgT, const T &Arg = S.Stk.peek<T>(); S.Stk.push<T>(Arg););
765-
766776
return Call->getDirectCallee()->isConstexpr();
767777
}
768778

@@ -778,13 +788,6 @@ static bool interp__builtin_eh_return_data_regno(InterpState &S, CodePtr OpPC,
778788
return true;
779789
}
780790

781-
/// Just takes the first Argument to the call and puts it on the stack.
782-
static bool noopPointer(InterpState &S) {
783-
const Pointer &Arg = S.Stk.peek<Pointer>();
784-
S.Stk.push<Pointer>(Arg);
785-
return true;
786-
}
787-
788791
// Two integral values followed by a pointer (lhs, rhs, resultOut)
789792
static bool interp__builtin_overflowop(InterpState &S, CodePtr OpPC,
790793
const CallExpr *Call,
@@ -2507,6 +2510,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
25072510
case Builtin::BIaddressof:
25082511
case Builtin::BI__addressof:
25092512
case Builtin::BI__builtin_addressof:
2513+
assert(isNoopBuiltin(BuiltinID));
25102514
if (!interp__builtin_addressof(S, OpPC, Frame, Call))
25112515
return false;
25122516
break;
@@ -2516,6 +2520,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
25162520
case Builtin::BIforward_like:
25172521
case Builtin::BImove:
25182522
case Builtin::BImove_if_noexcept:
2523+
assert(isNoopBuiltin(BuiltinID));
25192524
if (!interp__builtin_move(S, OpPC, Frame, Call))
25202525
return false;
25212526
break;
@@ -2526,8 +2531,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
25262531
break;
25272532

25282533
case Builtin::BI__builtin_launder:
2529-
if (!noopPointer(S))
2530-
return false;
2534+
assert(isNoopBuiltin(BuiltinID));
25312535
break;
25322536

25332537
case Builtin::BI__builtin_add_overflow:

0 commit comments

Comments
 (0)