Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ec207a

Browse files
committed
don't bump allocate the omnisimplex
1 parent 7f773e5 commit 8ec207a

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

include/LoopBlock.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,11 +1034,10 @@ class LinearProgramLoopBlock {
10341034
/// w: bounding offsets, independent of symbolic variables
10351035
/// u: bounding offsets, dependent on symbolic variables
10361036
auto instantiateOmniSimplex(const Graph &g, size_t d, bool satisfyDeps)
1037-
-> Optional<Simplex *> {
1038-
auto omniSimplex =
1039-
Simplex::create(allocator, numConstraints + numSlack,
1040-
numBounding + numActiveEdges + numPhiCoefs +
1041-
numOmegaCoefs + numSlack + numLambda);
1037+
-> std::unique_ptr<Simplex> {
1038+
auto omniSimplex = Simplex::create(
1039+
numConstraints + numSlack, numBounding + numActiveEdges + numPhiCoefs +
1040+
numOmegaCoefs + numSlack + numLambda);
10421041
auto C{omniSimplex->getConstraints()};
10431042
C << 0;
10441043
// layout of omniSimplex:
@@ -1160,8 +1159,8 @@ class LinearProgramLoopBlock {
11601159
}
11611160
invariant(size_t(l), size_t(1 + numLambda));
11621161
invariant(size_t(c), size_t(numConstraints));
1163-
addIndependentSolutionConstraints(omniSimplex, g, d);
1164-
return omniSimplex->initiateFeasible() ? nullptr : (Simplex *)omniSimplex;
1162+
addIndependentSolutionConstraints(omniSimplex.get(), g, d);
1163+
return omniSimplex;
11651164
}
11661165
static void updateConstraints(MutPtrMatrix<int64_t> C,
11671166
const ScheduledNode &node,
@@ -1188,9 +1187,8 @@ class LinearProgramLoopBlock {
11881187
setSchedulesIndependent(g, depth);
11891188
return checkEmptySatEdges(g, depth);
11901189
}
1191-
auto p = allocator.scope();
11921190
auto omniSimplex = instantiateOmniSimplex(g, depth, satisfyDeps);
1193-
if (!omniSimplex) return std::nullopt;
1191+
if (omniSimplex->initiateFeasible()) return std::nullopt;
11941192
auto sol = omniSimplex->rLexMinStop(numLambda + numSlack);
11951193
assert(sol.size() ==
11961194
numBounding + numActiveEdges + numPhiCoefs + numOmegaCoefs);
@@ -1574,7 +1572,7 @@ class LinearProgramLoopBlock {
15741572
std::swap(g.nodeIds, nodeIds);
15751573
g.activeEdges = activeEdges; // undo such that g.getEdges(d) is correct
15761574
for (auto &&e : g.getEdges(d)) e.popSatLevel();
1577-
g.activeEdges = oldEdges; // restore backup
1575+
g.activeEdges = oldEdges; // restore backup
15781576
auto *oldNodeIter = oldSchedules.begin();
15791577
for (auto &&n : g) n.getSchedule() = *(oldNodeIter++);
15801578
std::swap(carriedDeps, oldCarriedDeps);

include/Math/Simplex.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <llvm/ADT/ArrayRef.h>
1717
#include <llvm/ADT/SmallVector.h>
1818
#include <llvm/Support/raw_ostream.h>
19+
#include <new>
1920
#include <tuple>
2021

2122
// #define VERBOSESIMPLEX
@@ -880,6 +881,32 @@ class Simplex {
880881
return mem;
881882
}
882883

884+
static auto operator new(size_t count, unsigned conCap, unsigned varCap)
885+
-> void * {
886+
size_t memNeeded = tableauOffset(conCap, varCap) +
887+
sizeof(value_type) * reservedTableau(conCap, varCap);
888+
// void *p = ::operator new(count + memNeeded);
889+
return ::operator new(count + memNeeded,
890+
std::align_val_t(alignof(Simplex)));
891+
}
892+
static void operator delete(void *ptr, size_t) {
893+
::operator delete(ptr, std::align_val_t(alignof(Simplex)));
894+
}
895+
896+
static auto create(unsigned numCon, unsigned numVar)
897+
-> std::unique_ptr<Simplex> {
898+
return create(numCon, numVar, numCon, numVar + numCon);
899+
}
900+
static auto create(unsigned numCon, unsigned numVar, unsigned conCap,
901+
unsigned varCap) -> std::unique_ptr<Simplex> {
902+
auto *ret = new (conCap, varCap) Simplex;
903+
ret->numConstraints = numCon;
904+
ret->numVars = numVar;
905+
ret->constraintCapacity = conCap;
906+
ret->varCapacity = varCap;
907+
return std::unique_ptr<Simplex>(ret);
908+
}
909+
883910
static constexpr auto
884911
create(BumpAlloc<> &alloc, unsigned numCon,
885912
unsigned numVar, // NOLINT(bugprone-easily-swappable-parameters)

0 commit comments

Comments
 (0)