Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 5 additions & 63 deletions llvm/include/llvm/ADT/APFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,69 +967,11 @@ class APFloat : public APFloatBase {
llvm_unreachable("Unexpected semantics");
}

~Storage() {
if (usesLayout<IEEEFloat>(*semantics)) {
IEEE.~IEEEFloat();
return;
}
if (usesLayout<DoubleAPFloat>(*semantics)) {
Double.~DoubleAPFloat();
return;
}
llvm_unreachable("Unexpected semantics");
}

Storage(const Storage &RHS) {
if (usesLayout<IEEEFloat>(*RHS.semantics)) {
new (this) IEEEFloat(RHS.IEEE);
return;
}
if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
new (this) DoubleAPFloat(RHS.Double);
return;
}
llvm_unreachable("Unexpected semantics");
}

Storage(Storage &&RHS) {
if (usesLayout<IEEEFloat>(*RHS.semantics)) {
new (this) IEEEFloat(std::move(RHS.IEEE));
return;
}
if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
new (this) DoubleAPFloat(std::move(RHS.Double));
return;
}
llvm_unreachable("Unexpected semantics");
}

Storage &operator=(const Storage &RHS) {
if (usesLayout<IEEEFloat>(*semantics) &&
usesLayout<IEEEFloat>(*RHS.semantics)) {
IEEE = RHS.IEEE;
} else if (usesLayout<DoubleAPFloat>(*semantics) &&
usesLayout<DoubleAPFloat>(*RHS.semantics)) {
Double = RHS.Double;
} else if (this != &RHS) {
this->~Storage();
new (this) Storage(RHS);
}
return *this;
}

Storage &operator=(Storage &&RHS) {
if (usesLayout<IEEEFloat>(*semantics) &&
usesLayout<IEEEFloat>(*RHS.semantics)) {
IEEE = std::move(RHS.IEEE);
} else if (usesLayout<DoubleAPFloat>(*semantics) &&
usesLayout<DoubleAPFloat>(*RHS.semantics)) {
Double = std::move(RHS.Double);
} else if (this != &RHS) {
this->~Storage();
new (this) Storage(std::move(RHS));
}
return *this;
}
LLVM_ABI ~Storage();
LLVM_ABI Storage(const Storage &RHS);
LLVM_ABI Storage(Storage &&RHS);
LLVM_ABI Storage &operator=(const Storage &RHS);
LLVM_ABI Storage &operator=(Storage &&RHS);
} U;

template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
Expand Down
64 changes: 64 additions & 0 deletions llvm/lib/Support/APFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6165,6 +6165,70 @@ float APFloat::convertToFloat() const {
return Temp.getIEEE().convertToFloat();
}

APFloat::Storage::~Storage() {
if (usesLayout<IEEEFloat>(*semantics)) {
IEEE.~IEEEFloat();
return;
}
if (usesLayout<DoubleAPFloat>(*semantics)) {
Double.~DoubleAPFloat();
return;
}
llvm_unreachable("Unexpected semantics");
}

APFloat::Storage::Storage(const APFloat::Storage &RHS) {
if (usesLayout<IEEEFloat>(*RHS.semantics)) {
new (this) IEEEFloat(RHS.IEEE);
return;
}
if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
new (this) DoubleAPFloat(RHS.Double);
return;
}
llvm_unreachable("Unexpected semantics");
}

APFloat::Storage::Storage(APFloat::Storage &&RHS) {
if (usesLayout<IEEEFloat>(*RHS.semantics)) {
new (this) IEEEFloat(std::move(RHS.IEEE));
return;
}
if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
new (this) DoubleAPFloat(std::move(RHS.Double));
return;
}
llvm_unreachable("Unexpected semantics");
}

APFloat::Storage &APFloat::Storage::operator=(const APFloat::Storage &RHS) {
if (usesLayout<IEEEFloat>(*semantics) &&
usesLayout<IEEEFloat>(*RHS.semantics)) {
IEEE = RHS.IEEE;
} else if (usesLayout<DoubleAPFloat>(*semantics) &&
usesLayout<DoubleAPFloat>(*RHS.semantics)) {
Double = RHS.Double;
} else if (this != &RHS) {
this->~Storage();
new (this) Storage(RHS);
}
return *this;
}

APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&RHS) {
if (usesLayout<IEEEFloat>(*semantics) &&
usesLayout<IEEEFloat>(*RHS.semantics)) {
IEEE = std::move(RHS.IEEE);
} else if (usesLayout<DoubleAPFloat>(*semantics) &&
usesLayout<DoubleAPFloat>(*RHS.semantics)) {
Double = std::move(RHS.Double);
} else if (this != &RHS) {
this->~Storage();
new (this) Storage(std::move(RHS));
}
return *this;
}

} // namespace llvm

#undef APFLOAT_DISPATCH_ON_SEMANTICS