[PATCH] D98176: Introduce a generic operator to apply complex operations to BitVector
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 06:13:53 PST 2021
serge-sans-paille updated this revision to Diff 328995.
serge-sans-paille added a comment.
Fix formatting
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98176/new/
https://reviews.llvm.org/D98176
Files:
llvm/include/llvm/ADT/BitVector.h
llvm/lib/CodeGen/CFIInstrInserter.cpp
Index: llvm/lib/CodeGen/CFIInstrInserter.cpp
===================================================================
--- llvm/lib/CodeGen/CFIInstrInserter.cpp
+++ llvm/lib/CodeGen/CFIInstrInserter.cpp
@@ -265,9 +265,9 @@
MBBInfo.OutgoingCFARegister = SetRegister;
// Update outgoing CSR info.
- MBBInfo.OutgoingCSRSaved = MBBInfo.IncomingCSRSaved;
- MBBInfo.OutgoingCSRSaved |= CSRSaved;
- MBBInfo.OutgoingCSRSaved.reset(CSRRestored);
+ BitVector::apply([](auto x, auto y, auto z) { return (x | y) & ~z; },
+ MBBInfo.OutgoingCSRSaved, MBBInfo.IncomingCSRSaved, CSRSaved,
+ CSRRestored);
}
void CFIInstrInserter::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
@@ -295,6 +295,7 @@
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
bool InsertedCFIInstr = false;
+ BitVector SetDifference;
for (MachineBasicBlock &MBB : MF) {
// Skip the first MBB in a function
if (MBB.getNumber() == MF.front().getNumber()) continue;
@@ -346,8 +347,8 @@
continue;
}
- BitVector SetDifference = PrevMBBInfo->OutgoingCSRSaved;
- SetDifference.reset(MBBInfo.IncomingCSRSaved);
+ BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
+ PrevMBBInfo->OutgoingCSRSaved, MBBInfo.IncomingCSRSaved);
for (int Reg : SetDifference.set_bits()) {
unsigned CFIIndex =
MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, Reg));
@@ -356,8 +357,8 @@
InsertedCFIInstr = true;
}
- SetDifference = MBBInfo.IncomingCSRSaved;
- SetDifference.reset(PrevMBBInfo->OutgoingCSRSaved);
+ BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
+ MBBInfo.IncomingCSRSaved, PrevMBBInfo->OutgoingCSRSaved);
for (int Reg : SetDifference.set_bits()) {
auto it = CSRLocMap.find(Reg);
assert(it != CSRLocMap.end() && "Reg should have an entry in CSRLocMap");
Index: llvm/include/llvm/ADT/BitVector.h
===================================================================
--- llvm/include/llvm/ADT/BitVector.h
+++ llvm/include/llvm/ADT/BitVector.h
@@ -568,6 +568,18 @@
return false;
}
+ template <class F, class... ArgTys>
+ static BitVector &apply(F &&f, BitVector &Out, ArgTys const &...Args) {
+ static_assert(sizeof...(ArgTys) > 0, "at least one argument");
+ std::initializer_list<size_t> Sizes = {Args.size()...};
+ size_t CommonSize = *std::min_element(Sizes.begin(), Sizes.end());
+ if (Out.size() < CommonSize)
+ Out.resize(CommonSize);
+ for (size_t i = 0, e = Out.NumBitWords(CommonSize); i != e; ++i)
+ Out.Bits[i] = f(Args.Bits[i]...);
+ return Out;
+ }
+
BitVector &operator|=(const BitVector &RHS) {
if (size() < RHS.size())
resize(RHS.size());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98176.328995.patch
Type: text/x-patch
Size: 2800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210308/05815266/attachment.bin>
More information about the llvm-commits
mailing list