Skip to content

Commit 035f811

Browse files
authored
[APFloat] Outline special member functions (#164073)
As discussed in #111544 (comment), large special member functions in APFloat prevent function inlining and cause compile-time regression. This patch moves them into the cpp file. Compile-time improvement (-0.1%): https://llvm-compile-time-tracker.com/compare.php?from=0f68dc6cffd93954188f73bff8aced93aab63687&to=d3105c0860920651a7e939346e67c040776b2278&stat=instructions:u
1 parent 48a0a3b commit 035f811

File tree

2 files changed

+69
-63
lines changed

2 files changed

+69
-63
lines changed

llvm/include/llvm/ADT/APFloat.h

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -967,69 +967,11 @@ class APFloat : public APFloatBase {
967967
llvm_unreachable("Unexpected semantics");
968968
}
969969

970-
~Storage() {
971-
if (usesLayout<IEEEFloat>(*semantics)) {
972-
IEEE.~IEEEFloat();
973-
return;
974-
}
975-
if (usesLayout<DoubleAPFloat>(*semantics)) {
976-
Double.~DoubleAPFloat();
977-
return;
978-
}
979-
llvm_unreachable("Unexpected semantics");
980-
}
981-
982-
Storage(const Storage &RHS) {
983-
if (usesLayout<IEEEFloat>(*RHS.semantics)) {
984-
new (this) IEEEFloat(RHS.IEEE);
985-
return;
986-
}
987-
if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
988-
new (this) DoubleAPFloat(RHS.Double);
989-
return;
990-
}
991-
llvm_unreachable("Unexpected semantics");
992-
}
993-
994-
Storage(Storage &&RHS) {
995-
if (usesLayout<IEEEFloat>(*RHS.semantics)) {
996-
new (this) IEEEFloat(std::move(RHS.IEEE));
997-
return;
998-
}
999-
if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
1000-
new (this) DoubleAPFloat(std::move(RHS.Double));
1001-
return;
1002-
}
1003-
llvm_unreachable("Unexpected semantics");
1004-
}
1005-
1006-
Storage &operator=(const Storage &RHS) {
1007-
if (usesLayout<IEEEFloat>(*semantics) &&
1008-
usesLayout<IEEEFloat>(*RHS.semantics)) {
1009-
IEEE = RHS.IEEE;
1010-
} else if (usesLayout<DoubleAPFloat>(*semantics) &&
1011-
usesLayout<DoubleAPFloat>(*RHS.semantics)) {
1012-
Double = RHS.Double;
1013-
} else if (this != &RHS) {
1014-
this->~Storage();
1015-
new (this) Storage(RHS);
1016-
}
1017-
return *this;
1018-
}
1019-
1020-
Storage &operator=(Storage &&RHS) {
1021-
if (usesLayout<IEEEFloat>(*semantics) &&
1022-
usesLayout<IEEEFloat>(*RHS.semantics)) {
1023-
IEEE = std::move(RHS.IEEE);
1024-
} else if (usesLayout<DoubleAPFloat>(*semantics) &&
1025-
usesLayout<DoubleAPFloat>(*RHS.semantics)) {
1026-
Double = std::move(RHS.Double);
1027-
} else if (this != &RHS) {
1028-
this->~Storage();
1029-
new (this) Storage(std::move(RHS));
1030-
}
1031-
return *this;
1032-
}
970+
LLVM_ABI ~Storage();
971+
LLVM_ABI Storage(const Storage &RHS);
972+
LLVM_ABI Storage(Storage &&RHS);
973+
LLVM_ABI Storage &operator=(const Storage &RHS);
974+
LLVM_ABI Storage &operator=(Storage &&RHS);
1033975
} U;
1034976

1035977
template <typename T> static bool usesLayout(const fltSemantics &Semantics) {

llvm/lib/Support/APFloat.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6165,6 +6165,70 @@ float APFloat::convertToFloat() const {
61656165
return Temp.getIEEE().convertToFloat();
61666166
}
61676167

6168+
APFloat::Storage::~Storage() {
6169+
if (usesLayout<IEEEFloat>(*semantics)) {
6170+
IEEE.~IEEEFloat();
6171+
return;
6172+
}
6173+
if (usesLayout<DoubleAPFloat>(*semantics)) {
6174+
Double.~DoubleAPFloat();
6175+
return;
6176+
}
6177+
llvm_unreachable("Unexpected semantics");
6178+
}
6179+
6180+
APFloat::Storage::Storage(const APFloat::Storage &RHS) {
6181+
if (usesLayout<IEEEFloat>(*RHS.semantics)) {
6182+
new (this) IEEEFloat(RHS.IEEE);
6183+
return;
6184+
}
6185+
if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
6186+
new (this) DoubleAPFloat(RHS.Double);
6187+
return;
6188+
}
6189+
llvm_unreachable("Unexpected semantics");
6190+
}
6191+
6192+
APFloat::Storage::Storage(APFloat::Storage &&RHS) {
6193+
if (usesLayout<IEEEFloat>(*RHS.semantics)) {
6194+
new (this) IEEEFloat(std::move(RHS.IEEE));
6195+
return;
6196+
}
6197+
if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
6198+
new (this) DoubleAPFloat(std::move(RHS.Double));
6199+
return;
6200+
}
6201+
llvm_unreachable("Unexpected semantics");
6202+
}
6203+
6204+
APFloat::Storage &APFloat::Storage::operator=(const APFloat::Storage &RHS) {
6205+
if (usesLayout<IEEEFloat>(*semantics) &&
6206+
usesLayout<IEEEFloat>(*RHS.semantics)) {
6207+
IEEE = RHS.IEEE;
6208+
} else if (usesLayout<DoubleAPFloat>(*semantics) &&
6209+
usesLayout<DoubleAPFloat>(*RHS.semantics)) {
6210+
Double = RHS.Double;
6211+
} else if (this != &RHS) {
6212+
this->~Storage();
6213+
new (this) Storage(RHS);
6214+
}
6215+
return *this;
6216+
}
6217+
6218+
APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&RHS) {
6219+
if (usesLayout<IEEEFloat>(*semantics) &&
6220+
usesLayout<IEEEFloat>(*RHS.semantics)) {
6221+
IEEE = std::move(RHS.IEEE);
6222+
} else if (usesLayout<DoubleAPFloat>(*semantics) &&
6223+
usesLayout<DoubleAPFloat>(*RHS.semantics)) {
6224+
Double = std::move(RHS.Double);
6225+
} else if (this != &RHS) {
6226+
this->~Storage();
6227+
new (this) Storage(std::move(RHS));
6228+
}
6229+
return *this;
6230+
}
6231+
61686232
} // namespace llvm
61696233

61706234
#undef APFLOAT_DISPATCH_ON_SEMANTICS

0 commit comments

Comments
 (0)