Skip to content

Commit fe34b8c

Browse files
committed
Activate packing constraints when the definer operation is implemented by a 'pack instruction' rather than when the operand is assigned to a particular register classs
1 parent 87695f5 commit fe34b8c

18 files changed

Lines changed: 80 additions & 82 deletions

doc/constraints.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
\begin{equation}\textstyle\label{eq:packing}
164164
\begin{aligned}
165165
\connectedOperand{p} \land
166-
\temporaryRegister{\operandTemporary{p}} &\in \atoms{\packRegisterClass{p}{q}}
166+
&\operationInstruction{\operandOperation{\definer{\operandTemporary{p}}}} \in \packInstructions{p}{q}
167167
\implies\\
168168
&\temporaryRegister{\operandTemporary{q}} =
169169
\temporaryRegister{\operandTemporary{p}} +

doc/manual.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ \subsection{Register allocation}
642642
given relative distance}
643643
\alignmentEquation
644644
\constraintComment{packing}{\emph{bound} operands are packed together
645-
with \emph{free} operands assigned to pack register classes}
645+
with \emph{free} operands if the definer operation is implemented by a pack instruction}
646646
\packingEquation
647647
648648

doc/program-parameters.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@
7979

8080
\tableSpace
8181

82-
\parameter{\packRegisterClass{p}{q}}{pack register class of packed operands $p$ and $q$}
83-
\json{pclass}{[13, 24, 13]}
82+
\parameter{\packInstructions{p}{q}}{pack instructions of packed operands $p$ and $q$}
83+
\json{pinstrs}{[[10, 17], [11, 15], [5]]}
8484
\jsonComment{Note: this parameter is encoded with the same structure
8585
as \code{packed}: each packed operand pair and its corresponding
86-
pack register class are found in the same positions of their
86+
pack instructions are found in the same positions of their
8787
respective JSON arrays (example: \code{packed[1]~=~[34, 35]},
88-
\code{pclass[1]~=~24}.)}
88+
\code{pinstrs[1]~=~[11, 15]}.)}
8989

9090
\tableSpace
9191

doc/unison.sty

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
\newcommand{\operationBlockSymbol}{\operator{block}}
111111
\newcommand{\usersSymbol}{\operator{users}}
112112
\newcommand{\registerClassSymbol}{\operator{class}}
113-
\newcommand{\packRegisterClassSymbol}{\operator{pclass}}
113+
\newcommand{\packInstructionsSymbol}{\operator{pinstrs}}
114114
\newcommand{\registerSpaceSymbol}{\operator{space}}
115115
\newcommand{\oldRegisterSpaceSymbol}{\operator{space}}
116116
\newcommand{\sourceSymbol}{\operator{src}}
@@ -183,7 +183,7 @@
183183
\newcommand{\operationBlock}[1]{\operationBlockSymbol(#1)}
184184
\newcommand{\users}[1]{\usersSymbol(#1)}
185185
\newcommand{\registerClass}[3]{\registerClassSymbol(#1, #2, #3)}
186-
\newcommand{\packRegisterClass}[2]{\packRegisterClassSymbol(#1, #2)}
186+
\newcommand{\packInstructions}[2]{\packInstructionsSymbol(#1, #2)}
187187
\newcommand{\registerSpace}[1]{\registerSpaceSymbol(#1)}
188188
\newcommand{\oldRegisterSpace}[3]{\oldRegisterSpaceSymbol(#1, #2, #3)}
189189
\newcommand{\source}[1]{\sourceSymbol(#1)}

src/solvers/gecode/models/model.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -592,25 +592,6 @@ interchangeable_atoms(bool global, block b) const {
592592
class_atoms.insert(set<register_atom>(input->calleesaved.begin(),
593593
input->calleesaved.end()));
594594

595-
// add individual atoms in pack register classes
596-
set<pair<register_class, int> > rcws;
597-
for (block b : B) {
598-
for (unsigned int pi = 0; pi < input->bpacked[b].size(); pi++) {
599-
operand p = input->bpacked[b][pi][0];
600-
register_class rc = input->bpclass[b][pi];
601-
rcws.insert(make_pair(rc, input->operand_width[p]));
602-
}
603-
}
604-
for (pair<register_class, int> rcw : rcws) {
605-
for (register_atom ra : input->atoms[rcw.first]) {
606-
set<register_atom> rc_atoms;
607-
for (int w = 0; w < rcw.second; w++) {
608-
rc_atoms.insert(ra + w);
609-
}
610-
class_atoms.insert(rc_atoms);
611-
}
612-
}
613-
614595
set<register_atom> finite;
615596
for (auto ra : interchangeable) finite.insert(ra.first);
616597

@@ -1032,32 +1013,47 @@ void Model::post_alignment_constraints(block b) {
10321013

10331014
void Model::post_packing_constraints(block b) {
10341015

1035-
// Bound operands are packed together with free operands assigned to
1036-
// pack register classes:
1016+
// Bound operands are packed together with free operands if the definer
1017+
// operation is implemented by a pack instruction:
10371018

10381019
for (unsigned int pi = 0; pi < input->bpacked[b].size(); pi++) {
10391020
operand p = input->bpacked[b][pi][0], q = input->bpacked[b][pi][1];
1040-
register_class rc = input->bpclass[b][pi];
10411021
int w = input->operand_width[p];
1022+
vector<instruction> pis = input->bpinstrs[b][pi];
1023+
1024+
// instruction that defines the temporary connected to p
1025+
IntVar di(*this, 0, input->I.size() - 1);
1026+
IntVarArgs is;
1027+
for (temporary t : input->temps[p]) {
1028+
if (t == NULL_TEMPORARY) {
1029+
is << var(NULL_INSTRUCTION);
1030+
} else {
1031+
operation d = input->def_opr[t];
1032+
IntVar instr(*this, 0, input->I.size() - 1);
1033+
element(*this, IntArgs(input->instructions[d]), i(d), instr);
1034+
is << instr;
1035+
}
1036+
}
1037+
element(*this, is, y(p), di);
1038+
BoolVar pack_definer(*this, 0, 1);
1039+
IntArgs pack_is(pis);
1040+
dom(*this, di, IntSet(pack_is), pack_definer, ipl);
10421041

10431042
BoolVarArgs cases;
10441043
IntVarArgs ryps;
1045-
BoolVar ryp_in_rc(*this, 0, 1);
1046-
IntArgs rc_atoms(input->atoms[rc]);
1047-
dom(*this, ry(p), IntSet(rc_atoms), ryp_in_rc, ipl);
10481044

10491045
// first case: bound operand packed in high component
1050-
cases << var(x(p) && ryp_in_rc && ((ry(p) % (w*2)) == 0));
1046+
cases << var(x(p) && pack_definer && ((ry(p) % (w*2)) == 0));
10511047
ryps << var(ry(p) + w);
10521048

10531049
// second case: bound operand packed in low component
1054-
cases << var(x(p) && ryp_in_rc && ((ry(p) % (w*2)) != 0));
1050+
cases << var(x(p) && pack_definer && ((ry(p) % (w*2)) != 0));
10551051
ryps << var(ry(p) - w);
10561052

10571053
// third case: bound operand not packed
10581054
BoolVarArgs conds;
10591055
conds << x(p);
1060-
conds << ryp_in_rc;
1056+
conds << pack_definer;
10611057
cases << var(sum(conds) < 2);
10621058
IntVar any(*this, Gecode::Int::Limits::min, Gecode::Int::Limits::max);
10631059
ryps << any;

src/solvers/gecode/models/parameters.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Parameters::Parameters(JSONVALUE root) :
5454
aligned (get_2d_vector<int>(getRoot(root, "aligned"))),
5555
adist (get_vector<int>(getRoot(root, "adist"))),
5656
packed (get_2d_vector<int>(getRoot(root, "packed"))),
57-
pclass (get_vector<int>(getRoot(root, "pclass"))),
57+
pinstrs (get_2d_vector<int>(getRoot(root, "pinstrs"))),
5858
minlive (get_vector<int>(getRoot(root, "minlive"))),
5959
dep (get_3d_vector<int>(getRoot(root, "dep"))),
6060
activators (get_2d_vector<int>(getRoot(root, "activators"))),
@@ -162,7 +162,7 @@ void Parameters::compute_derived() {
162162
baligned.clear();
163163
badist.clear();
164164
bpacked.clear();
165-
bpclass.clear();
165+
bpinstrs.clear();
166166
copyreltop.clear();
167167
def_opr.clear();
168168
copies.clear();
@@ -337,14 +337,14 @@ void Parameters::compute_derived() {
337337
badist[b].push_back(adist[a]);
338338
}
339339

340-
vector<register_class> emptypclasses;
340+
vector<vector<instruction> > emptypinstrs;
341341
init_vector(bpacked, B.size(), empty);
342-
init_vector(bpclass, B.size(), emptypclasses);
342+
init_vector(bpinstrs, B.size(), emptypinstrs);
343343
for (unsigned int p = 0; p < packed.size(); p++) {
344344
vector<operand> pa = packed[p];
345345
block b = pb[pa[0]];
346346
bpacked[b].push_back(pa);
347-
bpclass[b].push_back(pclass[p]);
347+
bpinstrs[b].push_back(pinstrs[p]);
348348
}
349349

350350
init_vector(copyreltop, P.size(), -1);

src/solvers/gecode/models/parameters.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class Parameters {
117117
// packed operand pairs
118118
vector<vector<operand> > packed;
119119

120-
// register class of each packed operand pair
121-
vector<register_class> pclass;
120+
// pack instructions of each packed operand pair
121+
vector<vector<instruction> > pinstrs;
122122

123123
// minimum live range duration of each temporary
124124
vector<int> minlive;
@@ -404,8 +404,8 @@ class Parameters {
404404
// packed operand pairs in each block
405405
vector<vector<vector<operand> > > bpacked;
406406

407-
// register class of each packed operand pair in each block
408-
vector<vector<register_class> > bpclass;
407+
// pack instructions of each packed operand pair in each block
408+
vector<vector<vector<instruction> > > bpinstrs;
409409

410410
// top representative operand of each copy-related class
411411
vector<operand> copyreltop;

src/solvers/gecode/presolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ string produce_json(Parameters &input)
9494
<< emit_json_line("aligned", input.aligned)
9595
<< emit_json_line("adist", input.adist)
9696
<< emit_json_line("packed", input.packed)
97-
<< emit_json_line("pclass", input.pclass)
97+
<< emit_json_line("pinstrs", input.pinstrs)
9898
<< emit_json_line("minlive", input.minlive)
9999
<< emit_json_line("dep", input.dep)
100100
<< emit_json_line("activators", input.activators)

src/unison/src/MachineIR/Base.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ data MachineOperand r =
270270
MachineCFIIndex {
271271
mcfiIndex :: Integer
272272
} |
273-
-- | Register class (does not correspond to any LLVM operand)
274-
MachineRegClass {
275-
mrcName :: String
273+
-- | Instruction list (does not correspond to any LLVM operand)
274+
MachineInstructions {
275+
mriList :: [String]
276276
} |
277277
-- | Memory partition (does not correspond to any LLVM operand, we represent
278278
-- it in LLVM with a metadata operand)

src/unison/src/MachineIR/Constructors.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module MachineIR.Constructors
5757
mkMachineRegMask,
5858
mkMachineConstantPoolIndex,
5959
mkMachineCFIIndex,
60-
mkMachineRegClass,
60+
mkMachineInstructions,
6161
mkMachineMemPartition,
6262
mkMachineProperty,
6363
mkMachineNullReg,
@@ -121,7 +121,7 @@ mkMachineJumpTableIndex = MachineJumpTableIndex
121121
mkMachineRegMask = MachineRegMask
122122
mkMachineConstantPoolIndex = MachineConstantPoolIndex
123123
mkMachineCFIIndex = MachineCFIIndex
124-
mkMachineRegClass = MachineRegClass
124+
mkMachineInstructions = MachineInstructions
125125
mkMachineMemPartition = MachineMemPartition
126126
mkMachineProperty = MachineProperty
127127
mkMachineNullReg = MachineNullReg

0 commit comments

Comments
 (0)