Skip to content

Commit e06d141

Browse files
committed
[clang][bytecode] Make some builtins no-ops
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 843e362 commit e06d141

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)) {
@@ -742,24 +762,14 @@ static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC,
742762
const CallExpr *Call) {
743763
assert(Call->getArg(0)->isLValue());
744764
PrimType PtrT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
745-
746-
if (PtrT == PT_Ptr) {
747-
const Pointer &Arg = S.Stk.peek<Pointer>();
748-
S.Stk.push<Pointer>(Arg);
749-
} else {
750-
assert(false && "Unsupported pointer type passed to __builtin_addressof()");
751-
}
765+
assert(PtrT == PT_Ptr &&
766+
"Unsupported pointer type passed to __builtin_addressof()");
752767
return true;
753768
}
754769

755770
static bool interp__builtin_move(InterpState &S, CodePtr OpPC,
756771
const InterpFrame *Frame,
757772
const CallExpr *Call) {
758-
759-
PrimType ArgT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
760-
761-
TYPE_SWITCH(ArgT, const T &Arg = S.Stk.peek<T>(); S.Stk.push<T>(Arg););
762-
763773
return Call->getDirectCallee()->isConstexpr();
764774
}
765775

@@ -775,13 +785,6 @@ static bool interp__builtin_eh_return_data_regno(InterpState &S, CodePtr OpPC,
775785
return true;
776786
}
777787

778-
/// Just takes the first Argument to the call and puts it on the stack.
779-
static bool noopPointer(InterpState &S) {
780-
const Pointer &Arg = S.Stk.peek<Pointer>();
781-
S.Stk.push<Pointer>(Arg);
782-
return true;
783-
}
784-
785788
// Two integral values followed by a pointer (lhs, rhs, resultOut)
786789
static bool interp__builtin_overflowop(InterpState &S, CodePtr OpPC,
787790
const CallExpr *Call,
@@ -2504,6 +2507,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
25042507
case Builtin::BIaddressof:
25052508
case Builtin::BI__addressof:
25062509
case Builtin::BI__builtin_addressof:
2510+
assert(isNoopBuiltin(BuiltinID));
25072511
if (!interp__builtin_addressof(S, OpPC, Frame, Call))
25082512
return false;
25092513
break;
@@ -2513,6 +2517,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
25132517
case Builtin::BIforward_like:
25142518
case Builtin::BImove:
25152519
case Builtin::BImove_if_noexcept:
2520+
assert(isNoopBuiltin(BuiltinID));
25162521
if (!interp__builtin_move(S, OpPC, Frame, Call))
25172522
return false;
25182523
break;
@@ -2523,8 +2528,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
25232528
break;
25242529

25252530
case Builtin::BI__builtin_launder:
2526-
if (!noopPointer(S))
2527-
return false;
2531+
assert(isNoopBuiltin(BuiltinID));
25282532
break;
25292533

25302534
case Builtin::BI__builtin_add_overflow:

0 commit comments

Comments
 (0)