diff --git a/.travis.yml b/.travis.yml index 3c9340c5..7d7de162 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ # # Main authors: -# Roberto Castaneda Lozano +# Roberto Castaneda Lozano # # This file is part of Unison, see http://unison-code.github.io # diff --git a/LICENSE.md b/LICENSE.md index eb7be743..2be203d2 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -37,11 +37,11 @@ Unison includes code from the following projects: [MIT](https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE). - Erik Ekstrom's [master's - thesis](https://www.sics.se/%7ercas/teaching/ErikEkstrom_2015.pdf) (in parts + thesis](https://robcasloz.github.io/teaching/ErikEkstrom_2015.pdf) (in parts of the presolver). The code is licensed under BSD3 but the copyright is held by Erik Ekstrom. - Mikael Almgren's [master's - thesis](https://www.sics.se/%7ercas/teaching/MikaelAlmgren_2015.pdf) (in parts - of the presolver). The code is licensed under BSD3 but the copyright is held - by Mikael Almgren. \ No newline at end of file + thesis](https://robcasloz.github.io/teaching/MikaelAlmgren_2015.pdf) + (in parts of the presolver). The code is licensed under BSD3 but the + copyright is held by Mikael Almgren. \ No newline at end of file diff --git a/README.md b/README.md index c1ec59ca..76091f1d 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,20 @@ combinatorial optimization. ## Prerequisites Unison has the following dependencies: -[Haskell platform](http://hackage.haskell.org/platform/), -[Qt](https://www.qt.io/) (version 4.x), -[Graphviz library](http://www.graphviz.org/), and +[Stack](http://www.haskellstack.org/), +[Qt](https://www.qt.io/) (version 5.x, optional see [#33](https://github.com/unison-code/unison/issues/33)), +[Graphviz library](http://www.graphviz.org/) (also optional), and [Gecode](http://www.gecode.org/) (version 6.0.0). To get the first three dependencies in Debian-based distributions, just run: ``` -apt-get install haskell-platform libqt4-dev libgraphviz-dev +apt-get install haskell-stack qtbase5-dev libgraphviz-dev +``` + +Upgrade Slack after installing it: + +``` +stack upgrade ``` The source of Gecode can be fetched with: @@ -66,9 +72,23 @@ of LLVM's `llc` code generator. To try it out, just clone the LLVM fork and follow the instructions in the `README.md` file from any of the branches with a `-unison` suffix. +## Documentation + +Check out Unison's work-in-progress +[manual](https://unison-code.github.io/doc/manual.pdf). The manual's source can +be found in the `doc` directory. + +Source-level documentation is also available for the core Haskell modules of +Unison (`MachineIR.Base`, `Unison.Base`, and `Unison.Target.API`). To generate +this documentation in HTML format and open it with a web browser, just run: + +``` +make doc +``` + ## Contact -[Roberto Castañeda Lozano](https://www.sics.se/~rcas/) [] +[Roberto Castañeda Lozano](https://robcasloz.github.io/) [] ## License @@ -77,4 +97,4 @@ for details. ## Further Reading -Check [the Unison website](https://unison-code.github.io/). \ No newline at end of file +Check [the Unison website](https://unison-code.github.io/). diff --git a/doc/code/minimal.mir b/doc/code/minimal.mir new file mode 100644 index 00000000..ddcb9f48 --- /dev/null +++ b/doc/code/minimal.mir @@ -0,0 +1,32 @@ +--- | + (corresponding IR) +... +--- +name: minimal +body: | + bb.0.begin (freq 1): + liveins: %r0 + + %5 = COPY %r0 + %6 = li 1 + %9 = li 0 + %7 = sgt %5, %9 + bif %7, %bb.2.end + + bb.1.loop (freq 20): + + %0 = PHI %6, %bb.0.begin, %3, %bb.1.loop + %1 = PHI %5, %bb.0.begin, %2, %bb.1.loop + %2 = sub %1, %6 + %3 = mul %1, %0 + %8 = sgt %1, %6 + bif %8, %bb.1.loop + + bb.2.end (freq 1): + liveouts: %r2 + + %4 = PHI %6, %bb.0.begin, %3, %bb.1.loop + %r2 = COPY %4 + br %r7 + +... diff --git a/doc/manual.tex b/doc/manual.tex index 896b02ea..15fef78b 100644 --- a/doc/manual.tex +++ b/doc/manual.tex @@ -183,7 +183,7 @@ \chapter{License, Contact, and Acknowledgments}% Unison is designed, developed, and maintained by \begin{itemize} -\item Roberto Castañeda Lozano (\href{mailto:roberto.castaneda@ri.se}{roberto.castaneda@ri.se}) +\item Roberto Castañeda Lozano (\href{mailto:rcas@acm.org}{rcas@acm.org}) \item Mats Carlsson (\href{mailto:mats.carlsson@ri.se}{mats.carlsson@ri.se}) \item Gabriel Hjort Blindell (\href{mailto:ghb@kth.se}{ghb@kth.se}) \item Christian Schulte (\href{mailto:cschulte@kth.se}{cschulte@kth.se}) @@ -231,8 +231,8 @@ \section{Prerequisites} Unison has the following direct dependencies: % \begin{itemize} -\item \href{http://hackage.haskell.org/platform/}{Haskell platform} -\item \href{https://www.qt.io/}{Qt (version 4.x)} +\item \href{http://www.haskellstack.org/}{Stack} +\item \href{https://www.qt.io/}{Qt (version 5.x)} \item \href{http://www.graphviz.org/}{Graphviz library} \item \href{http://www.gecode.org/}{Gecode (version 6.0.0)} \end{itemize} @@ -240,7 +240,13 @@ \section{Prerequisites} To get the first three dependencies in Debian-based distributions, just run: % \begin{command} -apt-get install haskell-platform libqt4-dev libgraphviz-dev +apt-get install haskell-stack qtbase5-dev libgraphviz-dev +\end{command} +% +Upgrade Slack after installing it: +% +\begin{command} +stack upgrade \end{command} The source of Gecode can be fetched with: @@ -917,12 +923,78 @@ \chapter{Target Description} This chapter explains how target processors are described in Unison. % +Section~\ref{sec:target-structure} describes the structure of the source code +that implements a target processor description. +% Section~\ref{sec:generation} describes how major parts of the Unison description can be generated from a higher-level description. % Section~\ref{sec:importing} explains how the higher-level description itself can be imported from LLVM. +\section{Structure} +\label{sec:target-structure} + +The source code describing a new target is located under the directory +\code{src/Unison/Target} within the base directory of the \code{Unison} Haskell +package (\code{src/unison}). +% +At the highest level, a processor description is a function that returns a +parameterized data structure of type \code{TargetDescription i r rc s}, where +\code{i}, \code{r}, \code{rc}, and \code{s} are the processor's instruction, +register, register class, and resource types. +% +They are typically defined as enumeration types, but can consist of more complex +types if required by the target description. +% +A processor is registered in Unison by simply adding the target description to a +list provided by the function \code{unisonTargets} in the module +\code{Unison.Target}. + +The \code{TargetDescription} data structure consists of a collection of +functions that Unison uses to query about the properties of the processor. +% +Detailed documentation about the processor functions can be obtained by building +the code documentation for the Unison package. +% +To do this, just go to the \code{src} directory and run: +% +\begin{command} +make doc +\end{command} + +The generated HTML documentation can be found under the \code{.stack-work/dist} +directory within the Unison package. +% +The \code{TargetDescription} data type can be found in the module +\code{Unison/Target/API}. + +Unison includes a minimal, compilable target (\code{Minimal}) that can be used +as a template to create new targets, see the module \code{Unison.Target.Minimal} +in the Unison package. +% +A simple MIR version of our running example with Minimal instructions is +included in \code{doc/code/factorial.mir}. +% +% +To execute Unison on this function and obtain the optimal register allocation +and instruction schedule for Minimal, run the following command from the top of +the Git repository: +% +\begin{command} +uni run doc/code/minimal.mir --goal=speed --target=Minimal +\end{command} +% +By default, Minimal is defined as a single-issue processor, but an arbitrary +issue width \code{N} can be specified using the following target option: +% +\begin{command} +uni run doc/code/minimal.mir ... --targetoption=issue-width:N +\end{command} + +The rest of this section explains the key abstractions used in the processor +description and how different parts of it can be generated automatically. + \section{Register Array} \label{sec:register-array} diff --git a/src/.gitignore b/src/.gitignore index d5e45f47..f27034e6 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,5 +1,12 @@ +unison/.stack-work +unison/build +unison-specsgen/.stack-work +unison-specsgen/build +.stack-work *.prof *.obj *.dmp *.hi *.o +*.qmake.stash +*~ \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index bde981c2..2713c9d1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ # # Main authors: -# Roberto Castaneda Lozano +# Roberto Castaneda Lozano # # This file is part of Unison, see http://unison-code.github.io # @@ -30,7 +30,7 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # -CABALBIN := cabal +STACKBIN := stack PREFIX := /usr/local BINDIR := $(PREFIX)/bin @@ -55,24 +55,26 @@ build-solver: $(SOLVERBIN) build-presolver: $(PRESOLVERBIN) -build-unison: prepare-unison - cd $(UNISONDIR); $(CABALBIN) configure --enable-tests; $(CABALBIN) build --ghc-options="$(UNISON_GHC_CONFIG)" +build-unison: + $(STACKBIN) build unison \ + --ghc-options="$(UNISON_GHC_CONFIG)" \ + --copy-bins --local-bin-path $(UNISONDIR)/build -prepare-unison: - cd $(UNISONDIR); $(CABALBIN) install --only-dependencies --enable-tests +doc-unison: + $(STACKBIN) haddock unison + $(STACKBIN) haddock --open unison test: - cd $(UNISONDIR); \ - $(CABALBIN) test --show-details=$(UNISON_SHOW_DETAILS) \ - --test-option=--directory=$(CURDIR)/$(UNISONDIR)/test/fast \ - --test-option=--presolver=$(CURDIR)/$(PRESOLVERBIN) \ - --test-option=--solver=$(CURDIR)/$(SOLVERBIN) \ - --test-option=--showprogress + $(STACKBIN) test unison \ + --test-arguments="--directory=$(CURDIR)/$(UNISONDIR)/test/fast \ + --presolver=$(CURDIR)/$(PRESOLVERBIN) \ + --solver=$(CURDIR)/$(SOLVERBIN) \ + --showprogress" install: install-unison install-solver install-presolver install-unison: - cp $(UNISONDIR)/dist/build/uni/uni $(BINDIR) + cp $(UNISONDIR)/build/uni $(BINDIR) install-solver: cp $(SOLVERBIN) $(BINDIR) @@ -84,13 +86,11 @@ include $(PRESOLVERDIR)/presolver.mk include $(SOLVERDIR)/solver.mk clean: - cd $(UNISONDIR); $(CABALBIN) clean - cd $(UNISONSPECSGENDIR); $(CABALBIN) clean + $(STACKBIN) clean unison + $(STACKBIN) clean unison-specsgen $(MAKE) veryclean-solver veryclean-presolver -doc: - cd $(UNISONDIR); $(CABALBIN) haddock - cd $(UNISONSPECSGENDIR); $(CABALBIN) haddock +doc: doc-unison doc-specsgen haskell-loc: cloc unison/src --exclude-dir=SpecsGen @@ -115,17 +115,23 @@ SGARMINPUTYAML = $(SGARMROOTDIR)/input/arm.yaml SGARMAUXYAML = $(SGARMROOTDIR)/input/arm-manual.yaml SGARMREMATYAML = $(SGARMROOTDIR)/input/arm-remat.yaml +SGMINIMALROOTDIR = $(UNISONDIR)/src/Unison/Target/Minimal/SpecsGen +SGMINIMALINPUTYAML = $(SGMINIMALROOTDIR)/input/minimal.yaml -build-specsgen: prepare-specsgen - cd $(UNISONSPECSGENDIR); $(CABALBIN) configure; $(CABALBIN) build +build-specsgen: + $(STACKBIN) build unison-specsgen \ + --ghc-options="$(UNISON_GHC_CONFIG)" \ + --copy-bins --local-bin-path $(UNISONSPECSGENDIR)/build -prepare-specsgen: - cd $(UNISONSPECSGENDIR); $(CABALBIN) install --only-dependencies +doc-specsgen: + $(STACKBIN) haddock unison-specsgen + $(STACKBIN) haddock --open unison-specsgen install-specsgen: - cp $(UNISONSPECSGENDIR)/dist/build/specsgen/specsgen $(BINDIR) + cp $(UNISONSPECSGENDIR)/build/specsgen $(BINDIR) -run-specsgen: run-specsgen-hexagon run-specsgen-mips run-specsgen-arm +run-specsgen: run-specsgen-hexagon run-specsgen-mips run-specsgen-arm \ + run-specsgen-minimal run-specsgen-hexagon: specsgen --targetname=Hexagon $(SGHEXAGONINPUTYAML) $(SGHEXAGONAUXYAML) \ @@ -147,7 +153,12 @@ run-specsgen-arm: --outputdir=$(SGARMROOTDIR) \ --regclass p2:CCR --infiniteregclass M32 --infiniteregclass M32t \ --infiniteregclass M64 --infiniteregclass M128 \ - --infiniteregclass M512 \ + --infiniteregclass M512 \ --promoteeffect CPSR \ --infiniteregclass RM32 --infiniteregclass RM64 \ --rematfile=$(SGARMREMATYAML) + +run-specsgen-minimal: + specsgen --targetname=Minimal $(SGMINIMALINPUTYAML) $(SGMINIMALAUXYAML) \ + --outputdir=$(SGMINIMALROOTDIR) \ + --infiniteregclass M32 diff --git a/src/presolver-reference/common.pl b/src/presolver-reference/common.pl index a83d4791..b9d0ba06 100644 --- a/src/presolver-reference/common.pl +++ b/src/presolver-reference/common.pl @@ -3,7 +3,7 @@ % Mats Carlsson % % Contributing authors: -% Roberto Castaneda Lozano +% Roberto Castaneda Lozano % % This file is part of Unison, see http://unison-code.github.io % diff --git a/src/presolver-reference/presolver.pl b/src/presolver-reference/presolver.pl index b1987dd8..7a7cbc08 100644 --- a/src/presolver-reference/presolver.pl +++ b/src/presolver-reference/presolver.pl @@ -3,7 +3,7 @@ % Mats Carlsson % % Contributing authors: -% Roberto Castaneda Lozano +% Roberto Castaneda Lozano % Noric Couderc % % This file is part of Unison, see http://unison-code.github.io diff --git a/src/solvers/gecode/.gitignore b/src/solvers/gecode/.gitignore index e6029228..85142f11 100644 --- a/src/solvers/gecode/.gitignore +++ b/src/solvers/gecode/.gitignore @@ -6,3 +6,4 @@ generated-static.mk presolver-generated.mk *.o moc_*.cpp +moc_*.h \ No newline at end of file diff --git a/src/solvers/gecode/branchers/filters.cpp b/src/solvers/gecode/branchers/filters.cpp index 9835c443..2c3bd944 100644 --- a/src/solvers/gecode/branchers/filters.cpp +++ b/src/solvers/gecode/branchers/filters.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/filters.hpp b/src/solvers/gecode/branchers/filters.hpp index e16241f0..84247ca1 100644 --- a/src/solvers/gecode/branchers/filters.hpp +++ b/src/solvers/gecode/branchers/filters.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/merit.cpp b/src/solvers/gecode/branchers/merit.cpp index 0a9def6f..9ef77bd4 100644 --- a/src/solvers/gecode/branchers/merit.cpp +++ b/src/solvers/gecode/branchers/merit.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/merit.hpp b/src/solvers/gecode/branchers/merit.hpp index 7cdef5d0..cdf67cc7 100644 --- a/src/solvers/gecode/branchers/merit.hpp +++ b/src/solvers/gecode/branchers/merit.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/pressureschedulingbrancher.cpp b/src/solvers/gecode/branchers/pressureschedulingbrancher.cpp index 7ac02135..8ba2d9c7 100644 --- a/src/solvers/gecode/branchers/pressureschedulingbrancher.cpp +++ b/src/solvers/gecode/branchers/pressureschedulingbrancher.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/pressureschedulingbrancher.hpp b/src/solvers/gecode/branchers/pressureschedulingbrancher.hpp index 96b09219..0002240a 100644 --- a/src/solvers/gecode/branchers/pressureschedulingbrancher.hpp +++ b/src/solvers/gecode/branchers/pressureschedulingbrancher.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/printers.cpp b/src/solvers/gecode/branchers/printers.cpp index 835ffda9..00f7543a 100644 --- a/src/solvers/gecode/branchers/printers.cpp +++ b/src/solvers/gecode/branchers/printers.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/printers.hpp b/src/solvers/gecode/branchers/printers.hpp index be3f6509..ffa8832e 100644 --- a/src/solvers/gecode/branchers/printers.hpp +++ b/src/solvers/gecode/branchers/printers.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/routingbrancher.cpp b/src/solvers/gecode/branchers/routingbrancher.cpp index 3b14d6e9..476049f9 100644 --- a/src/solvers/gecode/branchers/routingbrancher.cpp +++ b/src/solvers/gecode/branchers/routingbrancher.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/routingbrancher.hpp b/src/solvers/gecode/branchers/routingbrancher.hpp index b5f7ef67..0c798b5f 100644 --- a/src/solvers/gecode/branchers/routingbrancher.hpp +++ b/src/solvers/gecode/branchers/routingbrancher.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/value.cpp b/src/solvers/gecode/branchers/value.cpp index d6acc4fd..be1f441e 100644 --- a/src/solvers/gecode/branchers/value.cpp +++ b/src/solvers/gecode/branchers/value.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/branchers/value.hpp b/src/solvers/gecode/branchers/value.hpp index 0d58d6e9..e7cf8c78 100644 --- a/src/solvers/gecode/branchers/value.hpp +++ b/src/solvers/gecode/branchers/value.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/common/definitions.cpp b/src/solvers/gecode/common/definitions.cpp index 35d8dd64..14214c79 100644 --- a/src/solvers/gecode/common/definitions.cpp +++ b/src/solvers/gecode/common/definitions.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -36,7 +36,6 @@ Temporand::Temporand() {} Temporand::Temporand(int id, TemporandType t) : _id(id), _type(t) {} -Temporand::Temporand(const Temporand& t) : _id(t.id()), _type(t.type()) {} bool Temporand::operator==(const Temporand& t) const { return ((_type == t.type()) && (_id == t.id())); diff --git a/src/solvers/gecode/common/definitions.hpp b/src/solvers/gecode/common/definitions.hpp index c77211f3..86712bfc 100644 --- a/src/solvers/gecode/common/definitions.hpp +++ b/src/solvers/gecode/common/definitions.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * Contributing authors: @@ -264,26 +264,6 @@ class PresolverDominates { } }; -class PresolverPred { -public: - vector p; - operation q; - int d; - bool operator==(const PresolverPred& that) const { - return (p == that.p) && (q == that.q) && (d == that.d); - } -}; - -class PresolverSucc { -public: - operation p; - vector q; - int d; - bool operator==(const PresolverSucc& that) const { - return (p == that.p) && (q == that.q) && (d == that.d); - } -}; - class PresolverInstrCond { public: operation o; @@ -390,18 +370,32 @@ class PresolverAcrossTuple { }; +class PresolverWCET { +public: + operation o; + instruction i; + latency d; + // CONSTRUCTORS + PresolverWCET(): + o(-1), i(-1), d(-1) { } + PresolverWCET(operation o, instruction i, latency d): + o(o), i(i), d(d) { } +}; + + typedef pair InstructionAssignment; #ifdef GRAPHICS -#define JSONVALUE QScriptValue #define GIST_OPTIONS Gist::Options #else -#define JSONVALUE Json::Value #define GIST_OPTIONS GistOptionsStub #endif class GistOptionsStub {}; +enum RegisterAtomClass + {RA_CALLEE_SAVED, RA_CALLER_SAVED, RA_RESERVED}; + enum TemporandType {TEMPORAND_OPERAND, TEMPORAND_TEMPORARY, TEMPORAND_REGISTER, TEMPORAND_NONE}; @@ -412,7 +406,6 @@ class Temporand { public: Temporand(); Temporand(int id, TemporandType t); - Temporand(const Temporand& t); bool operator==(const Temporand& t) const; diff --git a/src/solvers/gecode/common/jsonutil.cpp b/src/solvers/gecode/common/jsonutil.cpp index 4abc10e5..161a764a 100644 --- a/src/solvers/gecode/common/jsonutil.cpp +++ b/src/solvers/gecode/common/jsonutil.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/common/jsonutil.hpp b/src/solvers/gecode/common/jsonutil.hpp index a8fe26cc..5b23fcde 100644 --- a/src/solvers/gecode/common/jsonutil.hpp +++ b/src/solvers/gecode/common/jsonutil.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/common/util.cpp b/src/solvers/gecode/common/util.cpp index 3ce818e4..c0d0ddfe 100644 --- a/src/solvers/gecode/common/util.cpp +++ b/src/solvers/gecode/common/util.cpp @@ -1,7 +1,7 @@ /* * Main authors: * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -60,6 +60,12 @@ string show(const int i) { return s.str(); } +string show(const double d) { + stringstream s; + s << d; + return s.str(); +} + string show(const string s) { return s; } @@ -74,6 +80,10 @@ string show(const UnisonConstraintExpr e) { return show(vector{show((int)e.id), show(e.data), show(e.children)}, ", "); } +string show(const PresolverBefore b) { + return show(vector{show(b.p), show(b.q), show(b.d)}, ", "); +} + string show(const PresolverBeforeJSON b) { return show(vector{show(b.p), show(b.q), show(b.e)}, ", "); } @@ -108,14 +118,6 @@ string show(const PresolverCopyTmpTable t) { return show(vector{show(t.os), show(t.ps), show(t.tuples)}, ", "); } -string show(const PresolverPred p) { - return show(vector{show(p.p), show(p.q), show(p.d)}, ", "); -} - -string show(const PresolverSucc p) { - return show(vector{show(p.p), show(p.q), show(p.d)}, ", "); -} - string show(const PresolverAcrossJSON x) { return show(vector{show(x.o), show(x.ras), show(x.as)}, ", "); } @@ -128,6 +130,10 @@ string show(const PresolverAcrossItemJSON x) { return show(vector{show(x.t), show(x.e)}, ", "); } +string show(const PresolverWCET x) { + return show(vector{show(x.o), show(x.i), show(x.d)}, ", "); +} + string show(const PresolverSetAcross x) { return show(vector{show(x.o), show(x.ras), show(x.tsets)}, ", "); } @@ -198,16 +204,6 @@ string emit_json(const PresolverDominates x) { emit_json(x.ins), emit_json(x.temps)}, ", "); } -string emit_json(const PresolverPred x) { - return show(vector{emit_json(x.p), emit_json(x.q), - emit_json(x.d)}, ", "); -} - -string emit_json(const PresolverSucc x) { - return show(vector{emit_json(x.p), emit_json(x.q), - emit_json(x.d)}, ", "); -} - string emit_json(const PresolverInstrCond x) { return show(vector{emit_json(x.o), emit_json(x.i), emit_json(x.q)}, ", "); @@ -217,6 +213,10 @@ string emit_json(const PresolverValuePrecedeChain pvc) { return show(vector{emit_json(pvc.ts), emit_json(pvc.rss)}, ", "); } +string emit_json(const PresolverWCET wcet) { + return show(vector{emit_json(wcet.o), emit_json(wcet.i), emit_json(wcet.d)}, ", "); +} + string emit_json(const UnisonConstraintExpr e) { vector elements; stringstream ids; diff --git a/src/solvers/gecode/common/util.hpp b/src/solvers/gecode/common/util.hpp index 8593a4a0..03e162ee 100644 --- a/src/solvers/gecode/common/util.hpp +++ b/src/solvers/gecode/common/util.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * This file is part of Unison, see http://unison-code.github.io @@ -189,12 +189,16 @@ string show_range(const T & r) { string show(const int); +string show(const double); + string show(const string); string show(const Temporand); string show(const UnisonConstraintExpr); +string show(const PresolverBefore); + string show(const PresolverBeforeJSON); string show(const PresolverDominates); @@ -211,16 +215,14 @@ string show(const PresolverActiveTable); string show(const PresolverCopyTmpTable); -string show(const PresolverPred); - -string show(const PresolverSucc); - string show(const PresolverAcrossJSON); string show(const PresolverAcrossTuple); string show(const PresolverAcrossItemJSON); +string show(const PresolverWCET); + string show(const PresolverSetAcross); string show(const PresolverPrecedence x); @@ -242,6 +244,13 @@ string show(const C& container, string l = ",", string pre = "", return s.str(); } +template +string show(const pair& container, string limits = "(,)") { + stringstream s; + s << limits[0] << show(container.first) << limits[1] << show(container.second) << limits[2]; + return s.str(); +} + string emit_json(const int i); string emit_json(const bool b); @@ -264,14 +273,12 @@ string emit_json(const PresolverSetAcross at); string emit_json(const PresolverDominates at); -string emit_json(const PresolverPred at); - -string emit_json(const PresolverSucc at); - string emit_json(const PresolverInstrCond at); string emit_json(const PresolverValuePrecedeChain at); +string emit_json(const PresolverWCET wcet); + string emit_json(const UnisonConstraintExpr e); template diff --git a/src/solvers/gecode/inspectors/alignmentinspector.cpp b/src/solvers/gecode/inspectors/alignmentinspector.cpp index 0e450ebd..2288375e 100644 --- a/src/solvers/gecode/inspectors/alignmentinspector.cpp +++ b/src/solvers/gecode/inspectors/alignmentinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/alignmentinspector.hpp b/src/solvers/gecode/inspectors/alignmentinspector.hpp index eed40b00..fb6bd153 100644 --- a/src/solvers/gecode/inspectors/alignmentinspector.hpp +++ b/src/solvers/gecode/inspectors/alignmentinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/alignmentpartitioninspector.cpp b/src/solvers/gecode/inspectors/alignmentpartitioninspector.cpp index 7c6f1294..1ac06bd0 100644 --- a/src/solvers/gecode/inspectors/alignmentpartitioninspector.cpp +++ b/src/solvers/gecode/inspectors/alignmentpartitioninspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/alignmentpartitioninspector.hpp b/src/solvers/gecode/inspectors/alignmentpartitioninspector.hpp index a1803297..1de1a7bb 100644 --- a/src/solvers/gecode/inspectors/alignmentpartitioninspector.hpp +++ b/src/solvers/gecode/inspectors/alignmentpartitioninspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/allocationinspector.cpp b/src/solvers/gecode/inspectors/allocationinspector.cpp index b6a8102c..5ce1b60a 100644 --- a/src/solvers/gecode/inspectors/allocationinspector.cpp +++ b/src/solvers/gecode/inspectors/allocationinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/allocationinspector.hpp b/src/solvers/gecode/inspectors/allocationinspector.hpp index 778e9b91..42fa2bff 100644 --- a/src/solvers/gecode/inspectors/allocationinspector.hpp +++ b/src/solvers/gecode/inspectors/allocationinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/assignmentinspector.cpp b/src/solvers/gecode/inspectors/assignmentinspector.cpp index 3faab46a..aaa50b4f 100644 --- a/src/solvers/gecode/inspectors/assignmentinspector.cpp +++ b/src/solvers/gecode/inspectors/assignmentinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/assignmentinspector.hpp b/src/solvers/gecode/inspectors/assignmentinspector.hpp index 3734caea..b55261fb 100644 --- a/src/solvers/gecode/inspectors/assignmentinspector.hpp +++ b/src/solvers/gecode/inspectors/assignmentinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/congruenceallocationinspector.cpp b/src/solvers/gecode/inspectors/congruenceallocationinspector.cpp index 93263cd1..b089b0f8 100644 --- a/src/solvers/gecode/inspectors/congruenceallocationinspector.cpp +++ b/src/solvers/gecode/inspectors/congruenceallocationinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/congruenceallocationinspector.hpp b/src/solvers/gecode/inspectors/congruenceallocationinspector.hpp index d6cf707a..27bffa92 100644 --- a/src/solvers/gecode/inspectors/congruenceallocationinspector.hpp +++ b/src/solvers/gecode/inspectors/congruenceallocationinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/consoleinspector.cpp b/src/solvers/gecode/inspectors/consoleinspector.cpp index af23f0db..8c202680 100644 --- a/src/solvers/gecode/inspectors/consoleinspector.cpp +++ b/src/solvers/gecode/inspectors/consoleinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/consoleinspector.hpp b/src/solvers/gecode/inspectors/consoleinspector.hpp index 0f26da3b..e25a3c2e 100644 --- a/src/solvers/gecode/inspectors/consoleinspector.hpp +++ b/src/solvers/gecode/inspectors/consoleinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/dataflowinspector.cpp b/src/solvers/gecode/inspectors/dataflowinspector.cpp index 197c4359..5a1c19a6 100644 --- a/src/solvers/gecode/inspectors/dataflowinspector.cpp +++ b/src/solvers/gecode/inspectors/dataflowinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -157,8 +157,8 @@ draw(const Model& m, DataFlowGraph& dfg, const QPointF& topLeft) { QGraphicsPathItem * e = new QGraphicsPathItem(edge.path); QGraphicsPathItem * a = new QGraphicsPathItem(edge.arrow); - e->translate(topLeft.x(), topLeft.y()); - a->translate(topLeft.x(), topLeft.y()); + e->setTransform(QTransform::fromTranslate(topLeft.x(), topLeft.y()), true); + a->setTransform(QTransform::fromTranslate(topLeft.x(), topLeft.y()), true); e->setPen(pen); a->setBrush(brush); diff --git a/src/solvers/gecode/inspectors/dataflowinspector.hpp b/src/solvers/gecode/inspectors/dataflowinspector.hpp index 3c9f613b..23466e26 100644 --- a/src/solvers/gecode/inspectors/dataflowinspector.hpp +++ b/src/solvers/gecode/inspectors/dataflowinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/dot.cpp b/src/solvers/gecode/inspectors/dot.cpp index 6ae6993a..ea41008f 100644 --- a/src/solvers/gecode/inspectors/dot.cpp +++ b/src/solvers/gecode/inspectors/dot.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -57,8 +57,7 @@ Dot::Dot() : setGlobalNodeAttribute("width", "0.2"); setGlobalNodeAttribute("height", "0.2"); setGlobalNodeAttribute("fixedsize", "true"); - QString w("%1"); - w.arg(50/DPI); + QString w = QString("%1").arg(50/DPI); setGlobalNodeAttribute("width", w.replace('.', ",")); setGlobalEdgeAttribute("dir", "forward"); } diff --git a/src/solvers/gecode/inspectors/dot.hpp b/src/solvers/gecode/inspectors/dot.hpp index 99dd784f..844a560c 100644 --- a/src/solvers/gecode/inspectors/dot.hpp +++ b/src/solvers/gecode/inspectors/dot.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/issuecycleinspector.cpp b/src/solvers/gecode/inspectors/issuecycleinspector.cpp index b97bffbf..ca976c99 100644 --- a/src/solvers/gecode/inspectors/issuecycleinspector.cpp +++ b/src/solvers/gecode/inspectors/issuecycleinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/issuecycleinspector.hpp b/src/solvers/gecode/inspectors/issuecycleinspector.hpp index 93a8e0f2..8f76f814 100644 --- a/src/solvers/gecode/inspectors/issuecycleinspector.hpp +++ b/src/solvers/gecode/inspectors/issuecycleinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/livedurationinspector.cpp b/src/solvers/gecode/inspectors/livedurationinspector.cpp index 1402af29..b73ead5f 100644 --- a/src/solvers/gecode/inspectors/livedurationinspector.cpp +++ b/src/solvers/gecode/inspectors/livedurationinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/livedurationinspector.hpp b/src/solvers/gecode/inspectors/livedurationinspector.hpp index 2866164c..0e06845e 100644 --- a/src/solvers/gecode/inspectors/livedurationinspector.hpp +++ b/src/solvers/gecode/inspectors/livedurationinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/liverangeinspector.cpp b/src/solvers/gecode/inspectors/liverangeinspector.cpp index f6b682fb..0b4189cb 100644 --- a/src/solvers/gecode/inspectors/liverangeinspector.cpp +++ b/src/solvers/gecode/inspectors/liverangeinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/liverangeinspector.hpp b/src/solvers/gecode/inspectors/liverangeinspector.hpp index 92ea9f9d..79cbdd68 100644 --- a/src/solvers/gecode/inspectors/liverangeinspector.hpp +++ b/src/solvers/gecode/inspectors/liverangeinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/modelgraphicsview.cpp b/src/solvers/gecode/inspectors/modelgraphicsview.cpp index de9b9958..0d422f81 100644 --- a/src/solvers/gecode/inspectors/modelgraphicsview.cpp +++ b/src/solvers/gecode/inspectors/modelgraphicsview.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/modelgraphicsview.hpp b/src/solvers/gecode/inspectors/modelgraphicsview.hpp index 3e0d8d38..c8c2a2f6 100644 --- a/src/solvers/gecode/inspectors/modelgraphicsview.hpp +++ b/src/solvers/gecode/inspectors/modelgraphicsview.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/modelinspector.cpp b/src/solvers/gecode/inspectors/modelinspector.cpp index 19e7371d..16052d82 100644 --- a/src/solvers/gecode/inspectors/modelinspector.cpp +++ b/src/solvers/gecode/inspectors/modelinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/modelinspector.hpp b/src/solvers/gecode/inspectors/modelinspector.hpp index 41a38511..30de1892 100644 --- a/src/solvers/gecode/inspectors/modelinspector.hpp +++ b/src/solvers/gecode/inspectors/modelinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -38,6 +38,8 @@ #include #include +#include +#include #include #include diff --git a/src/solvers/gecode/inspectors/operandallocationinspector.cpp b/src/solvers/gecode/inspectors/operandallocationinspector.cpp index 12f4f15e..19cfd878 100644 --- a/src/solvers/gecode/inspectors/operandallocationinspector.cpp +++ b/src/solvers/gecode/inspectors/operandallocationinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/operandallocationinspector.hpp b/src/solvers/gecode/inspectors/operandallocationinspector.hpp index 0d3ff06b..26167611 100644 --- a/src/solvers/gecode/inspectors/operandallocationinspector.hpp +++ b/src/solvers/gecode/inspectors/operandallocationinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/operandassignmentinspector.cpp b/src/solvers/gecode/inspectors/operandassignmentinspector.cpp index 5a1a321d..064b0a0e 100644 --- a/src/solvers/gecode/inspectors/operandassignmentinspector.cpp +++ b/src/solvers/gecode/inspectors/operandassignmentinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/operandassignmentinspector.hpp b/src/solvers/gecode/inspectors/operandassignmentinspector.hpp index 0ecf9130..d177d5c9 100644 --- a/src/solvers/gecode/inspectors/operandassignmentinspector.hpp +++ b/src/solvers/gecode/inspectors/operandassignmentinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/operandlatencyinspector.cpp b/src/solvers/gecode/inspectors/operandlatencyinspector.cpp index eb8feb1f..9b0c6711 100644 --- a/src/solvers/gecode/inspectors/operandlatencyinspector.cpp +++ b/src/solvers/gecode/inspectors/operandlatencyinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/operandlatencyinspector.hpp b/src/solvers/gecode/inspectors/operandlatencyinspector.hpp index ad1e457d..0a5c64a7 100644 --- a/src/solvers/gecode/inspectors/operandlatencyinspector.hpp +++ b/src/solvers/gecode/inspectors/operandlatencyinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/precedenceinspector.cpp b/src/solvers/gecode/inspectors/precedenceinspector.cpp index b5d3e40d..307726c9 100644 --- a/src/solvers/gecode/inspectors/precedenceinspector.cpp +++ b/src/solvers/gecode/inspectors/precedenceinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -138,8 +138,8 @@ draw(const LocalModel& m, PrecedenceGraph& pg, const QPointF& topLeft) { QGraphicsPathItem * e = new QGraphicsPathItem(edge.path); QGraphicsPathItem * a = new QGraphicsPathItem(edge.arrow); - e->translate(topLeft.x(), topLeft.y()); - a->translate(topLeft.x(), topLeft.y()); + e->setTransform(QTransform::fromTranslate(topLeft.x(), topLeft.y()), true); + a->setTransform(QTransform::fromTranslate(topLeft.x(), topLeft.y()), true); e->setPen(pen); a->setBrush(brush); diff --git a/src/solvers/gecode/inspectors/precedenceinspector.hpp b/src/solvers/gecode/inspectors/precedenceinspector.hpp index 1ee3ddb5..26fb17d6 100644 --- a/src/solvers/gecode/inspectors/precedenceinspector.hpp +++ b/src/solvers/gecode/inspectors/precedenceinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/precedencematrixinspector.cpp b/src/solvers/gecode/inspectors/precedencematrixinspector.cpp index e95385f1..a071dfef 100644 --- a/src/solvers/gecode/inspectors/precedencematrixinspector.cpp +++ b/src/solvers/gecode/inspectors/precedencematrixinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/precedencematrixinspector.hpp b/src/solvers/gecode/inspectors/precedencematrixinspector.hpp index d4490748..ace3712e 100644 --- a/src/solvers/gecode/inspectors/precedencematrixinspector.hpp +++ b/src/solvers/gecode/inspectors/precedencematrixinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/registerarrayinspector.cpp b/src/solvers/gecode/inspectors/registerarrayinspector.cpp index 45eced7e..5f4f66f3 100644 --- a/src/solvers/gecode/inspectors/registerarrayinspector.cpp +++ b/src/solvers/gecode/inspectors/registerarrayinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/registerarrayinspector.hpp b/src/solvers/gecode/inspectors/registerarrayinspector.hpp index 9d674093..0befc893 100644 --- a/src/solvers/gecode/inspectors/registerarrayinspector.hpp +++ b/src/solvers/gecode/inspectors/registerarrayinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/resourceconsumptioninspector.cpp b/src/solvers/gecode/inspectors/resourceconsumptioninspector.cpp index 46b9bdcc..69f0ca82 100644 --- a/src/solvers/gecode/inspectors/resourceconsumptioninspector.cpp +++ b/src/solvers/gecode/inspectors/resourceconsumptioninspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/resourceconsumptioninspector.hpp b/src/solvers/gecode/inspectors/resourceconsumptioninspector.hpp index 5662790d..c0fc7edb 100644 --- a/src/solvers/gecode/inspectors/resourceconsumptioninspector.hpp +++ b/src/solvers/gecode/inspectors/resourceconsumptioninspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/selectioninspector.cpp b/src/solvers/gecode/inspectors/selectioninspector.cpp index 3bcf68a5..7d1cb1a5 100644 --- a/src/solvers/gecode/inspectors/selectioninspector.cpp +++ b/src/solvers/gecode/inspectors/selectioninspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/selectioninspector.hpp b/src/solvers/gecode/inspectors/selectioninspector.hpp index 581a78a9..01feb53b 100644 --- a/src/solvers/gecode/inspectors/selectioninspector.hpp +++ b/src/solvers/gecode/inspectors/selectioninspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/usersinspector.cpp b/src/solvers/gecode/inspectors/usersinspector.cpp index 167cf969..10506d7a 100644 --- a/src/solvers/gecode/inspectors/usersinspector.cpp +++ b/src/solvers/gecode/inspectors/usersinspector.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/inspectors/usersinspector.hpp b/src/solvers/gecode/inspectors/usersinspector.hpp index 26146b82..af01e80a 100644 --- a/src/solvers/gecode/inspectors/usersinspector.hpp +++ b/src/solvers/gecode/inspectors/usersinspector.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/models/completemodel.cpp b/src/solvers/gecode/models/completemodel.cpp index d3efb2ea..16c1edf9 100644 --- a/src/solvers/gecode/models/completemodel.cpp +++ b/src/solvers/gecode/models/completemodel.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Mats Carlsson @@ -213,15 +213,9 @@ void CompleteModel::post_slack_balancing_constraints(void) { void CompleteModel::post_improved_model_constraints(void) { for (block b : input->B) Model::post_improved_model_constraints(b); -#if MCSLACK post_slack_functional_constraints(); -#else - post_slack_lower_bound_constraints(); -#endif } -#if MCSLACK - void CompleteModel::post_slack_functional_constraints(void) { int maxc = max_of(input->maxc); @@ -266,61 +260,10 @@ void CompleteModel::post_slack_functional_constraints(void) { } -#else - -void CompleteModel::post_slack_lower_bound_constraints(void) { - - // The slack of (in) or (out) congruent operands is larger than the latencies - // of their dependent operands: - - for (global_congruence g : input->G) { - congruence c = input->regular[g]; - vector ins, outs; - for (operand p : input->congr[c]) { - if (input->global_operand[p]) { - if (input->type[input->oper[p]] == IN) { - ins.push_back(p); - } else { // type == OUT - outs.push_back(p); - } - } - } - - if (ins.size() > 0) { - IntVarArgs lats; - for (operand p : ins) { - temporary t = input->single_temp[p]; - for (operand q : input->users[t]) lats << lt(q); - } - for (operand p : ins) { - constraint(s(p) >= - max(lats)); - } - } - - if (outs.size() > 0) { - IntVarArgs lats; - for (operand p : outs) { - for (temporary t : input->real_temps[p]) { - operand q = input->definer[t]; - lats << lt(q); - } - } - for (operand p : outs) { - constraint(s(p) >= - max(lats)); - } - } - - } - -} - -#endif - void CompleteModel::post_presolver_constraints(void) { for (block b : input->B) Model::post_presolver_constraints(b); if (!options->disable_presolver_constraints()) { -#if MCMOD // cross-block synchronisation of spill/unspill ops for (const vector& os : input->calleesaved_spill) { operation spillop = os[0]; @@ -346,7 +289,6 @@ void CompleteModel::post_presolver_constraints(void) { ts.finalize(); extensional(*this, as, ts); } -#endif } } diff --git a/src/solvers/gecode/models/completemodel.hpp b/src/solvers/gecode/models/completemodel.hpp index ab97b2ac..bd0f1dc4 100644 --- a/src/solvers/gecode/models/completemodel.hpp +++ b/src/solvers/gecode/models/completemodel.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -99,11 +99,7 @@ class CompleteModel : public Model { void post_slack_balancing_constraints(void); void post_improved_model_constraints(void); -#if MCSLACK void post_slack_functional_constraints(void); -#else - void post_slack_lower_bound_constraints(void); -#endif void post_presolver_constraints(void); diff --git a/src/solvers/gecode/models/globalmodel.cpp b/src/solvers/gecode/models/globalmodel.cpp index ff6202a5..e719c39f 100644 --- a/src/solvers/gecode/models/globalmodel.cpp +++ b/src/solvers/gecode/models/globalmodel.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Mats Carlsson @@ -233,18 +233,6 @@ GlobalModel::GlobalModel(Parameters * p_input, ModelOptions * p_options, // Cost of each block CompleteModel::post_cost_definition(); -#if !MCMOD - // the fear: is this really compatible with local register symmetry breaking? - // Symmetry breaking (depends on the result of propagating all other - // constraints) - if (!options->disable_improving()) { - Gecode::SpaceStatus ss = status(); - if (ss != SS_FAILED && - !options->disable_register_symmetry_breaking_constraints()) { - post_register_symmetry_breaking_constraints(); - } - } -#endif } GlobalModel::GlobalModel(GlobalModel& cg) : @@ -437,46 +425,6 @@ void GlobalModel::post_global_cost_domain_constraints() { } -#if !MCMOD - -void GlobalModel::post_register_symmetry_breaking_constraints() { - - vector Gs(input->G); - - // Gs is a list of global congruences sorted in {descending order by - // width, ascending order by id}. The latter is important for - // callee-saved congruences. - - sort(Gs.begin(), Gs.end(), - [this] - (const global_congruence g1, - const global_congruence g2) -> bool - { - operand p1 = input->representative[input->regular[g1]], - p2 = input->representative[input->regular[g2]]; - return make_tuple(-input->operand_width[p1], p1) < - make_tuple(-input->operand_width[p2], p2); - }); - - IntVarArgs grys; - for (global_congruence g : Gs) { - operand p = input->representative[input->regular[g]]; - for (int w = 0; w < input->operand_width[p]; w++) { - IntVar rypw(*this, ry(p).min() + w, ry(p).max() + w); - constraint(rypw == ry(p) + w); - assert_bounded(rypw); - grys << rypw; - } - } - - for (set interchangeable : interchangeable_atoms(true, -1)) { - IntArgs ras(interchangeable.begin(), interchangeable.end()); - precede(*this, grys, ras); - } - -} - -#else void GlobalModel::post_register_symmetry_breaking_constraints(void) { vector chains = value_precede_chains(*input, this, true, -1); @@ -492,8 +440,6 @@ void GlobalModel::post_register_symmetry_breaking_constraints(void) { } } -#endif - void GlobalModel::post_active_operation(operation o) { if (o != NULL_OPERATION) constraint(a(o)); diff --git a/src/solvers/gecode/models/globalmodel.hpp b/src/solvers/gecode/models/globalmodel.hpp index 3ce9dea0..77cc57ba 100644 --- a/src/solvers/gecode/models/globalmodel.hpp +++ b/src/solvers/gecode/models/globalmodel.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/models/localmodel.cpp b/src/solvers/gecode/models/localmodel.cpp index ec937ce8..7b8604c0 100644 --- a/src/solvers/gecode/models/localmodel.cpp +++ b/src/solvers/gecode/models/localmodel.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Mats Carlsson @@ -151,8 +151,9 @@ LocalModel::LocalModel(Parameters * p_input, ModelOptions * p_options, post_operand_symmetry_breaking_constraints(b); ss = status(); if (ss == SS_FAILED) return; - if (!options->disable_register_symmetry_breaking_constraints()) - post_register_symmetry_breaking_constraints(b); + // cannot be trusted + // if (!options->disable_register_symmetry_breaking_constraints()) + // post_register_symmetry_breaking_constraints(b); } } @@ -169,6 +170,14 @@ LocalModel* LocalModel::copy(void) { return new LocalModel(*this); } +double LocalModel::action(int i) const { + return c_activity[i]; +} + +double LocalModel::actionmerit(const Space& home, BoolVar, int i) { + return static_cast(home).action(i); +} + void LocalModel::post_decision_variable_domain_definitions(void) { Model::post_decision_variable_domain_definitions(b); } @@ -226,28 +235,6 @@ void LocalModel::post_operand_symmetry_breaking_constraints(block b) { } -#if !MCMOD - -void LocalModel::post_register_symmetry_breaking_constraints(block b) { - - IntVarArgs rys; - for (operand p : input->ope[b]) { - for (int w = 0; w < input->operand_width[p]; w++) { - IntVar rypw(*this, ry(p).min() + w, ry(p).max() + w); - constraint(rypw == ry(p) + w); - assert_bounded(rypw); - rys << rypw; - } - } - - for (set interchangeable : interchangeable_atoms(false, b)) { - IntArgs ras(interchangeable.begin(), interchangeable.end()); - precede(*this, rys, ras); - } - -} - -#else void LocalModel::post_register_symmetry_breaking_constraints(block b) { vector chains = value_precede_chains(*input, this, false, b); @@ -255,6 +242,12 @@ void LocalModel::post_register_symmetry_breaking_constraints(block b) { IntVarArgs rts; for (temporary t : vpc.ts) { rts << r(t); + for (int w = 1; w < input->width[t]; w++) { + IntVar rtw(*this, r(t).min() + w, r(t).max() + w); + constraint(rtw == r(t) + w); + assert_bounded(rtw); + rts << rtw; + } } for (vector rs : vpc.rss) { IntArgs ras(rs.begin(), rs.end()); @@ -264,7 +257,6 @@ void LocalModel::post_register_symmetry_breaking_constraints(block b) { } } -#endif void LocalModel::constrain_cost(IntRelType irt, int cost) { rel(*this, f(b, 0), irt, cost, ipl); @@ -307,7 +299,7 @@ void LocalModel::post_aggressive_branchers(void) { void LocalModel::post_trivial_branchers(void) { - branch(*this, v_a, BOOL_VAR_ACTION_MAX(c_activity), BOOL_VAL_MIN(), + branch(*this, v_a, BOOL_VAR_MERIT_MAX(actionmerit), BOOL_VAL_MIN(), NULL, &print_inactive_decision); branch(*this, v_i, INT_VAR_NONE(), INT_VAL_MIN(), @@ -333,7 +325,7 @@ void LocalModel::post_minimum_cost_branchers(void) { branch(*this, cost(), INT_VAR_NONE(), INT_VAL_MIN(), NULL, &print_cost_decision); - branch(*this, v_a, BOOL_VAR_ACTION_MAX(c_activity), BOOL_VAL_MIN(), + branch(*this, v_a, BOOL_VAR_MERIT_MAX(actionmerit), BOOL_VAL_MIN(), NULL, &print_inactive_decision); branch(*this, v_i, INT_VAR_NONE(), INT_VAL_MIN(), @@ -356,7 +348,7 @@ void LocalModel::post_minimum_cost_branchers(void) { void LocalModel::post_fail_first_branchers(void) { - branch(*this, v_a, BOOL_VAR_ACTION_MAX(c_activity), BOOL_VAL_MIN(), + branch(*this, v_a, BOOL_VAR_MERIT_MAX(actionmerit), BOOL_VAL_MIN(), NULL, &print_inactive_decision); branch(*this, v_i, INT_VAR_NONE(), INT_VAL_MAX(), diff --git a/src/solvers/gecode/models/localmodel.hpp b/src/solvers/gecode/models/localmodel.hpp index c5a6f455..0a15a3f9 100644 --- a/src/solvers/gecode/models/localmodel.hpp +++ b/src/solvers/gecode/models/localmodel.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -101,6 +101,11 @@ class LocalModel : public Model { LocalModel* copy(void); + // Changed to Merit because c_activity is IntAction + double action(int i) const; + + static double actionmerit(const Space& home, BoolVar, int i); + // Constraints void post_decision_variable_domain_definitions(void); diff --git a/src/solvers/gecode/models/model.cpp b/src/solvers/gecode/models/model.cpp index 3a485d61..330d5b4b 100644 --- a/src/solvers/gecode/models/model.cpp +++ b/src/solvers/gecode/models/model.cpp @@ -1,10 +1,11 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * Contributing authors: * Daniel Lundén + * Rodothea Myrsini Tsoupidi * * This file is part of Unison, see http://unison-code.github.io * @@ -413,56 +414,6 @@ double Model::pressure(operand p, register_class rc) const { return (double) input->operand_width[p] / (double) (input->atoms[rc].size()); } -int Model::worst(operation o) const { - - block b = input->oblock[o]; - - vector durs; - - for (unsigned int ii = 0; ii < input->instructions[o].size(); ii++) { - - instruction i = input->instructions[o][ii]; - vector opdurs; - - vector duroff; - for (resource r : input->R) - duroff.push_back(input->dur[i][r] + input->off[i][r]); - int maxdur = max_of(duroff); - opdurs.push_back(maxdur); - - int maxuselat = 0, maxdeflat = 0; - for (unsigned pi = 0; pi < input->operands[o].size(); pi++) { - operand p = input->operands[o][pi]; - if (input->use[p] && input->lat[o][ii][pi] > maxuselat) - maxuselat = input->lat[o][ii][pi]; - if (!input->use[p] && input->lat[o][ii][pi] > maxdeflat) - maxdeflat = input->lat[o][ii][pi]; - } - opdurs.push_back(maxuselat + maxdeflat); - - int maxdist = 0; - for (unsigned int e = 0; e < input->dep[b].size(); e++) { - if ((o == input->dep[b][e][0]) && (input->dist[b][e][ii] > maxdist)) - maxdist = input->dist[b][e][ii]; - if ((o == input->dep[b][e][1]) && (max_of(input->dist[b][e]) > maxdist)) - maxdist = max_of(input->dist[b][e]); - } - opdurs.push_back(maxdist); - - int maxminlive = 0; - for (temporary t : input->tmp[b]) - if (input->def_opr[t] == o && input->minlive[t] > maxminlive) - maxminlive = input->minlive[t]; - opdurs.push_back(maxminlive); - - durs.push_back(max_of(opdurs)); - - } - - return max_of(durs); - -} - bool Model::may_saturate(block b, register_atom fa, register_atom la) const { pair C = make_pair(0, c(input->out[b]).max()); // TODO: there should be a better way @@ -483,124 +434,6 @@ IntArgs Model::consumption_domain(resource r, vector & is) const { return IntArgs::create(maxcon / unit + 1, 0, unit); } -#if !MCMOD -// Classes of interchangeable register atoms -set > Model:: -interchangeable_atoms(bool global, block b) const { - - vector B(global ? input->B : vector({b})); - - // initialize 'interchangeable' with all finite register atoms - vector inf; - for (register_space rs : input->RS) - if (input->infinite[rs]) inf.push_back(rs); - disjointSet interchangeable; - for (register_atom ra : input->RA) { - bool infatom = false; - for (register_space rs : inf) { - if (ra >= input->range[rs][0] && ra <= input->range[rs][1]) { - infatom = true; - break; - } - } - if (!infatom) interchangeable.insert(ra, ra); - } - - set > class_atoms; - - // add finite register class atoms - set visited; - for (block b : B) { - for (operation o : input->ops[b]) { - for (unsigned int ii = 0; ii < input->instructions[o].size(); ii++) { - for (unsigned pi = 0; pi < input->operands[o].size(); pi++) { - operand p = input->operands[o][pi]; - if (input->instructions[o][ii] != NULL_INSTRUCTION) { - register_class rc = input->rclass[o][ii][pi]; - if (!input->infinite[input->space[rc]]) { - if (!visited.count(rc)) { - visited.insert(rc); - set rc_atoms; - for (register_atom ra : input->atoms[rc]) { - for (int w = 0; w < input->operand_width[p]; w++) { - if (interchangeable.count(ra + w)) { - rc_atoms.insert(ra + w); - } - } - } - class_atoms.insert(rc_atoms); - } - } - } - } - } - } - } - - bool has_caller = false, has_callee = false; - - for (block b : B) { - for (operand p : input->ope[b]) { - set domain; - for (IntVarValues ra(ry(p)); ra(); ++ra) - if (interchangeable.count(ra.val())) { - for (int w = 0; w < input->operand_width[p]; w++) { - domain.insert(ra.val() + w); - } - } - if (((input->type[input->oper[p]] == FUN) || - (input->type[input->oper[p]] == KILL)) && - subseteq(domain, input->callersaved)) { - has_caller = true; - continue; - } else if - (global && - ((input->type[input->oper[p]] == IN) || - (input->type[input->oper[p]] == OUT) || - (input->type[input->oper[p]] == COPY)) && - subseteq(domain, input->calleesaved)) { - has_callee = true; - continue; - } - class_atoms.insert(domain); - } - } - - - // add caller and caller saved atoms as their own classes - if (has_caller) - class_atoms.insert(set(input->callersaved.begin(), - input->callersaved.end())); - if (has_callee) - class_atoms.insert(set(input->calleesaved.begin(), - input->calleesaved.end())); - - set finite; - for (auto ra : interchangeable) finite.insert(ra.first); - - // merge register atoms that always appear together in the atom classes - for (register_atom ra1 : finite) { - for (register_atom ra2 : finite) { - if (ra1 != ra2) { - bool diff = false; - for (set atoms : class_atoms) { - if ((atoms.count(ra1) && !atoms.count(ra2)) || - (!atoms.count(ra1) && atoms.count(ra2))) { - diff = true; - break; - } - } - if (diff) continue; - interchangeable.merge(ra1, ra2); - } - } - } - - // return equivalence (interchangeable) classes of register atoms - return interchangeable.classes(); - -} -#endif Model::Model(Parameters * p_input, ModelOptions * p_options, IntPropLevel p_ipl) : input(p_input), @@ -899,11 +732,18 @@ void Model::post_basic_model_constraints(block b) { void Model::post_connected_users_constraints(block b) { - // A temporary is live iff it is connected to a user: + // A temporary is live iff it is connected to a user; + // If it's live, then its register must be among the users' registers, + // otherwise its register must be -1: - for (temporary t : input->tmp[b]) + for (temporary t : input->tmp[b]) { constraint(l(t) == (us(t) > 0)); - + IntVarArgs ruses; + for (operand p : input->users[t]) ruses << ry(p); + operand p = input->definer[t]; + if (!must_connect(p)) ruses << IntVar(*this, -1, -1); + member(*this, ruses, r(t), ipl); + } } void Model::post_active_instructions_constraints(block b) { @@ -1012,7 +852,15 @@ void Model::post_alignment_constraints(block b) { instruction i = input->baligned[b][ai][1], j = input->baligned[b][ai][3]; int adist = input->badist[b][ai]; - constraint((imp(op, i) && imp(oq, j)) >> (ry(p) == (ry(q) + adist))); + if (input->instructions[op].size()==1 && input->instructions[oq].size()==1) { + constraint(ry(p) == ry(q) + adist); + } else { + IntVar ryqa(*this, ry(q).min()+adist, ry(q).max()+adist); + constraint(ryqa == (ry(q) + adist)); + BoolVar r(*this, 0, 1); + rel(*this, ry(p), IRT_EQ, ryqa, r, ipl); + constraint(!imp(op, i) || !imp(oq, j) || r); + } } } @@ -1114,8 +962,13 @@ void Model::post_processor_resources_constraints(block b) { // The capacity of processor resources cannot be exceeded at any issue cycle: + vector essential_r; map > r2tasks; + for (resource r : input->R) + if (!contains(input->subsumed_resources[b], r)) + essential_r.push_back(r); + for (operation o : input->ops[b]) { typedef int instruction_index; @@ -1128,7 +981,7 @@ void Model::post_processor_resources_constraints(block b) { // Complete map with tasks grouped by consumption for (unsigned int ii = 0; ii < input->instructions[o].size(); ii++) { instruction i = input->instructions[o][ii]; - for (resource r : input->R) { + for (resource r : essential_r) { int con = input->con[i][r], dur = input->dur[i][r]; if (con > 0 && dur > 0) @@ -1138,7 +991,7 @@ void Model::post_processor_resources_constraints(block b) { // For each operation, resource and consumption, define a task possibly // related to several instructions - for (resource r : input->R) { + for (resource r : essential_r) { for (auto ctts : rc2tasks[r]) { IntArgs iis; vector durs, offs; @@ -1182,7 +1035,7 @@ void Model::post_processor_resources_constraints(block b) { } } - for (resource r : input->R) { + for (resource r : essential_r) { IntVarArgs rc; // Start time of each task IntVarArgs rdur; // Duration of each task @@ -1198,7 +1051,7 @@ void Model::post_processor_resources_constraints(block b) { ro << task.o; } - cumulative(*this, input->cap[r], rc, rdur, re, rcon, ro); + cumulative(*this, input->cap[r], rc, rdur, re, rcon, ro, IPL_BASIC_ADVANCED); } @@ -1290,47 +1143,21 @@ void Model::post_improved_model_constraints(block b) { if (!options->disable_improving()) { post_null_register_constraints(b); post_effective_copy_constraints(b); -#if !MCMOD // subsumed - post_disjoint_operand_constraints(b); -#endif if (!options->disable_maximum_temporary_usage_constraints()) post_maximum_temporary_usage_constraints(b); -#if !MCMOD // they are all subsumed - if (!options->disable_copy_dominance_constraints()) { - post_copy_symmetry_breaking_constraints(b); - post_copy_dominance_constraints(b); - post_non_decreasing_temporary_usage_constraints(b); - post_first_k_copies_constraints(b); - } -#endif -#if MCSLACK -#else - post_reverse_data_precedence_constraints(b); -#endif post_minimum_temporary_duration_constraints(b); post_define_issue_cycle_constraints(b); post_kill_issue_cycle_constraints(b); -#if !MCMOD // subsumed - if (!options->disable_partially_ordered_live_range_constraints()) { - // This is subsumed by the partially ordered live range constraints - post_disjoint_congruent_operand_constraints(b); - } - post_redefined_operand_constraints(b); -#endif post_disjoint_component_operand_constraints(b); if (!options->disable_space_capacity_constraints()) post_space_capacity_constraints(b); post_branch_issue_cycle_constraints(b); post_active_first_copy_constraints(b); - post_sequential_upper_bound_constraints(b); post_callee_saved_symmetry_breaking_constraints(b); if (!options->disable_precedence_variables()) { post_irreflexive_precedence_constraints(b); post_transitive_precedence_constraints(b); } -#if !MCMOD // subsumed - post_killed_temporary_precedence_constraints(b); -#endif post_cost_domain_constraints(b); post_local_congruence_constraints(b); post_ultimate_source_constraints(b); @@ -1484,39 +1311,6 @@ void Model::post_first_k_copies_constraints(block b) { } -#if MCSLACK -#else -void Model::post_reverse_data_precedence_constraints(block b) { - - // An operation that defines a temporary is issued before its last user: - - for (operation o : input->ops[b]) - for (operand p : input->operands[o]) - if (!input->use[p]) { - temporary t = input->single_temp[p]; - IntVarArgs acs, ics; - for (operand q : input->users[t]) { - operation j = input->oper[q]; - // if there is a global operand p1 defining a temporary that can be - // used by q, subtract the slack of p1: - operand p1 = -1; - for (temporary t1 : input->real_temps[q]) { - operand pd = input->definer[t1]; - if (input->global_operand[pd]) { - p1 = pd; - break; - } - } - IntVar pc = var(c(j) - lat(q, t) - (p1 == -1 ? var(0) : s(p1))); - acs << var(ite(u(q, t), pc, 0)); - ics << pc; - } - constraint(c(o) <= ite(l(t), max(acs), max(ics))); - } - -} -#endif - void Model::post_minimum_temporary_duration_constraints(block b) { // The duration of the live range of a temporary is equal or longer @@ -1676,7 +1470,7 @@ void Model::post_space_capacity_constraints(block b) { use << min(cap, input->width[t]); ot << var(l(t) && (ld(t) > 0) && totally_in_register_space(t, rs)); } - cumulative(*this, cap, st, dur, et, use, ot); + cumulative(*this, cap, st, dur, et, use, ot, IPL_BASIC_ADVANCED); } } @@ -1772,20 +1566,6 @@ void Model::post_active_first_copy_constraints(block b) { } -void Model::post_sequential_upper_bound_constraints(block b) { - - // The makespan cannot be larger than that of a sequential schedule: - - IntArgs durs; - BoolVarArgs as; - for (operation o : input->ops[b]) { - durs << worst(o); - as << a(o); - } - constraint(c(input->out[b]) < sum(durs, as)); - -} - void Model::post_callee_saved_symmetry_breaking_constraints(block b) { // Assuming all callee-saved registers and copies are symmetric, @@ -1794,13 +1574,6 @@ void Model::post_callee_saved_symmetry_breaking_constraints(block b) { // unspill operations must be smallest register last // e.g. "calleesaved_spill": [[3,158,167],[4,159,168],[5,160,169],[6,161,170],[7,162,171],[8,163,172]], -#if !MCMOD - if (b == 0) { - BoolVarArgs as; - for (operation o : input->callee_saved_stores) as << a(o); - rel(*this, as, IRT_GQ); - } -#else if (!input->calleesaved_spill.empty()) { unsigned nrows = input->calleesaved_spill[0].size(); unsigned ncols = input->calleesaved_spill.size(); @@ -1834,7 +1607,6 @@ void Model::post_callee_saved_symmetry_breaking_constraints(block b) { } } } -#endif } void Model::post_irreflexive_precedence_constraints(block b) { @@ -1993,13 +1765,11 @@ void Model::post_presolver_constraints(block b) { post_across_call_disjoint_temporary_set_constraints(b); if (!options->disable_temporary_symmetry_breaking_constraints()) post_temporary_symmetry_breaking_constraints(b); -#if MCMOD post_diffregs_constraints(b); post_difftemps_constraints(b); post_dominates_constraints(b); - post_predecessors_constraints(b); - post_successors_constraints(b); -#endif + if (!options->disable_wcet_constraints()) + post_wcet_constraints(b); // TODO: to be revisited after minlive model improvement // post_killer_operand_constraints(b); post_mandatory_reuse_constraints(b); @@ -2260,22 +2030,10 @@ void Model::post_temporary_symmetry_breaking_constraints(block b) { for (vector > interchangeable : input->bdomops[b]) { vector ps = interchangeable[0]; vector ts = interchangeable[1]; -#if !MCMOD - for (unsigned int pi = 0; pi < (ps.size() - 1); pi++) - for (unsigned int qi = pi + 1; qi < ps.size(); qi++) { - operand p = ps[pi], q = ps[qi]; - for (unsigned int t1i = 0; t1i < (ts.size() - 1); t1i++) - for (unsigned int t2i = t1i + 1; t2i < ts.size(); t2i++) { - temporary t1 = ts[t1i], t2 = ts[t2i]; - constraint(!(u(p, t2) && u(q, t1))); - } - } -#else IntVarArgs ysargs; for (operand p : ps) ysargs << y(p); IntArgs tsargs(ts.begin(), ts.end()); precede(*this, ysargs, tsargs); -#endif } } @@ -2347,28 +2105,40 @@ void Model::post_diffregs_constraints(block b) { disjoint_operand_registers(ps); } -void Model::post_predecessors_constraints(block b) { - - // Operations with multiple predecessors must be distant from the earliest predecessor. - - for(PresolverPred& PPi : input->bpredecessors[b]) { - IntVarArgs pred_cs; - for (operation o : PPi.p) - pred_cs << c(o); - constraint(min(pred_cs) + PPi.d <= c(PPi.q)); - } -} - -void Model::post_successors_constraints(block b) { - - // Operations with multiple successors must be distant to the latest successor. - - for(PresolverSucc& PSi : input->bsuccessors[b]) { - IntVarArgs succ_cs; - for (operation o : PSi.q) - succ_cs << c(o); - constraint(c(PSi.p) + PSi.d <= max(succ_cs)); +void Model::post_wcet_constraints(block b) { + + // Longest tolerable inter-issue distance + + IntVarArgs worst; + map> slacks; + if (input->bwcet[b].empty()) + return; + for(PresolverWCET& wcet : input->bwcet[b]) + slacks[wcet.o].push_back(wcet.d); + for(auto kv : slacks) { + operation o = kv.first; + bool allOne = true; + bool allOneButFirst = true; + bool first = true; + bool mand = input->instructions[o][0] != NULL_INSTRUCTION; + + for(int d : kv.second) { + if (d!=1) allOne = false; + if (!first && d!=1) allOneButFirst = false; + first = false; + } + if(allOne) { + worst << var(1); + } else if(allOneButFirst && !mand) { + IntVar ia(*this, 0, 1); + Gecode::channel(*this, ia, a(o), IPL_DOM); + worst << ia; + } else { + worst << var(element(kv.second, i(o))); + } } + constraint(c(input->out[b]) <= sum(worst)); + } void Model::post_killer_operand_constraints(block b) { diff --git a/src/solvers/gecode/models/model.hpp b/src/solvers/gecode/models/model.hpp index 378d82da..627ff91d 100644 --- a/src/solvers/gecode/models/model.hpp +++ b/src/solvers/gecode/models/model.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Mats Carlsson @@ -331,11 +331,6 @@ class Model : public IntLexMinimizeSpace { // Domain of resource consumption cost variable by the given operations IntArgs consumption_domain(resource r, vector & is) const; -#if !MCMOD - // Classes of interchangeable register atoms - set > interchangeable_atoms(bool global, block b) const; -#endif - // Constructors Model(Parameters * p_input, ModelOptions * p_options, IntPropLevel p_ipl); @@ -399,7 +394,6 @@ class Model : public IntLexMinimizeSpace { void post_branch_issue_cycle_constraints(block b); void post_redefined_operand_constraints(block b); void post_active_first_copy_constraints(block b); - void post_sequential_upper_bound_constraints(block b); void post_callee_saved_symmetry_breaking_constraints(block b); void post_irreflexive_precedence_constraints(block b); void post_transitive_precedence_constraints(block b); @@ -421,6 +415,7 @@ class Model : public IntLexMinimizeSpace { void post_dominates_constraints(block b); void post_difftemps_constraints(block b); void post_diffregs_constraints(block b); + void post_wcet_constraints(block b); void post_predecessors_constraints(block b); void post_successors_constraints(block b); void post_killer_operand_constraints(block b); diff --git a/src/solvers/gecode/models/options.cpp b/src/solvers/gecode/models/options.cpp index 8134f403..fa993177 100644 --- a/src/solvers/gecode/models/options.cpp +++ b/src/solvers/gecode/models/options.cpp @@ -1,9 +1,10 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Gabriel Hjort Blindell + * Rodothea Myrsini Tsoupidi * * This file is part of Unison, see http://unison-code.github.io * @@ -41,9 +42,11 @@ ModelOptions::ModelOptions(void) : InstanceOptions("Unison"), _output_file("o", "output file", ""), + _dzn_file("dzn", "dzn file (ignored)", ""), _verbose("verbose", "verbose mode", true), _emit_improvement("emit-improvement", "emit estimated improvement", false), _lower_bound_file("l", "lower bound file", ""), + _initial_gap_file("g", "initial optimality gap file", ""), #ifdef GRAPHICS _gist_global("gist-global", "run Gist for global problems", false), _gist_block("gist-block", "block on which to run Gist", -1), @@ -112,13 +115,16 @@ ModelOptions::ModelOptions(void) _disable_across_call_disjoint_temporary_constraints("disable-across-call-disjoint-temporary-constraints", "disable across call disjoint temporary constraints", false), _disable_across_call_disjoint_temporary_set_constraints("disable-across-call-disjoint-temporary-set-constraints", "disable across call disjoint temporary set constraints", false), _disable_temporary_symmetry_breaking_constraints("disable-temporary-symmetry-breaking-constraints", "disable temporary symmetry breaking constraints", false), - _disable_infinite_register_dominance_constraints("disable-infinite-register-dominance-constraints", "disable infinite register dominance constraints", false) + _disable_infinite_register_dominance_constraints("disable-infinite-register-dominance-constraints", "disable infinite register dominance constraints", false), + _disable_wcet_constraints("disable-wcet-constraints", "disable wcet constraints", false) { add(_output_file); + add(_dzn_file); add(_verbose); add(_emit_improvement); add(_lower_bound_file); + add(_initial_gap_file); #ifdef GRAPHICS add(_gist_global); add(_gist_block); @@ -188,4 +194,5 @@ ModelOptions::ModelOptions(void) add(_disable_across_call_disjoint_temporary_set_constraints); add(_disable_temporary_symmetry_breaking_constraints); add(_disable_infinite_register_dominance_constraints); + add(_disable_wcet_constraints); } diff --git a/src/solvers/gecode/models/options.hpp b/src/solvers/gecode/models/options.hpp index b0cefd1e..06099d64 100644 --- a/src/solvers/gecode/models/options.hpp +++ b/src/solvers/gecode/models/options.hpp @@ -1,6 +1,9 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano + * + * Contributing authors: + * Rodothea Myrsini Tsoupidi * * This file is part of Unison, see http://unison-code.github.io * @@ -50,9 +53,11 @@ class ModelOptions : public InstanceOptions { // Interface Driver::StringValueOption _output_file; // Output file + Driver::StringValueOption _dzn_file; // Dzn file (ignored) Driver::BoolOption _verbose; // Verbose mode Driver::BoolOption _emit_improvement; // Emit estimated improvement Driver::StringValueOption _lower_bound_file; // Lower bound file + Driver::StringValueOption _initial_gap_file; // Initial optimality gap file #ifdef GRAPHICS Driver::BoolOption _gist_global; // Run Gist for global problems Driver::IntOption _gist_block; // Block on which to run Gist @@ -130,15 +135,18 @@ class ModelOptions : public InstanceOptions { Driver::BoolOption _disable_across_call_disjoint_temporary_set_constraints; // Disable across call disjoint temporary set constraints Driver::BoolOption _disable_temporary_symmetry_breaking_constraints; // Disable temporary symmetry breaking constraints Driver::BoolOption _disable_infinite_register_dominance_constraints; // Disable infinite register dominance constraints + Driver::BoolOption _disable_wcet_constraints; // Disable wcet constraints public: ModelOptions(void); string output_file(void) const {return _output_file.value();} + string dzn_file(void) const {return _dzn_file.value();} bool verbose(void) const {return _verbose.value();} bool emit_improvement(void) const {return _emit_improvement.value();} string lower_bound_file(void) const {return _lower_bound_file.value();} + string initial_gap_file(void) const {return _initial_gap_file.value();} #ifdef GRAPHICS bool gist_global(void) const {return _gist_global.value();} int gist_block(void) const {return _gist_block.value();} @@ -208,6 +216,7 @@ class ModelOptions : public InstanceOptions { bool disable_across_call_disjoint_temporary_set_constraints(void) const {return _disable_across_call_disjoint_temporary_set_constraints.value();} bool disable_temporary_symmetry_breaking_constraints(void) const {return _disable_temporary_symmetry_breaking_constraints.value();} bool disable_infinite_register_dominance_constraints(void) const {return _disable_infinite_register_dominance_constraints.value();} + bool disable_wcet_constraints(void) const {return _disable_wcet_constraints.value();} }; diff --git a/src/solvers/gecode/models/parameters.cpp b/src/solvers/gecode/models/parameters.cpp index a4ddf961..be8c291f 100644 --- a/src/solvers/gecode/models/parameters.cpp +++ b/src/solvers/gecode/models/parameters.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * Contributing authors: @@ -38,7 +38,7 @@ #include "parameters.hpp" -Parameters::Parameters(JSONVALUE root) : +Parameters::Parameters(Json::Value root) : // Program parameters @@ -137,12 +137,13 @@ Parameters::Parameters(JSONVALUE root) : diffregs (get_2d_vector(getRoot(root, "diffregs"))), calleesaved_spill (get_2d_vector(getRoot(root, "calleesaved_spill"))), strictly_congr (get_2d_vector(getRoot(root, "strictly_congr"))), - predecessors (get_vector(getRoot(root, "predecessors"))), - successors (get_vector(getRoot(root, "successors"))), value_precede_chains (get_vector(getRoot(root, "value_precede_chains"))), quasi_adjacent (get_2d_vector(getRoot(root, "quasi_adjacent"))), long_latency_index (get_3d_vector(getRoot(root, "long_latency_index"))), - long_latency_def_use (get_2d_vector(getRoot(root, "long_latency_def_use"))) + long_latency_def_use (get_2d_vector(getRoot(root, "long_latency_def_use"))), + subsumed_resources (get_2d_vector(getRoot(root, "subsumed_resources"))), + temp_domain (get_2d_vector(getRoot(root, "temp_domain"))), + wcet (get_vector(getRoot(root, "wcet"))) { compute_derived(); } @@ -223,7 +224,7 @@ void Parameters::compute_derived() { ultimate_source.clear(); p_preassign.clear(); t_preassign.clear(); - r_calleesaved.clear(); + ra_class.clear(); bactive_tables.clear(); gactive_tables.clear(); btmp_tables.clear(); @@ -242,8 +243,7 @@ void Parameters::compute_derived() { bdominates.clear(); bdifftemps.clear(); bdiffregs.clear(); - bpredecessors.clear(); - bsuccessors.clear(); + bwcet.clear(); N = 0; for (unsigned int rc = 0; rc < space.size(); rc++) RC.push_back(rc); @@ -753,9 +753,11 @@ void Parameters::compute_derived() { } int nregs = atoms[0].size(); // safe over-estimation - init_vector(r_calleesaved, nregs, true); // also the default for regs that are neither: Hexagon 29/30/31 + init_vector(ra_class, nregs, RA_RESERVED); // the default for regs that are neither: Hexagon 29/30/31 + for(int r : calleesaved) + ra_class[r] = RA_CALLEE_SAVED; for(int r : callersaved) - r_calleesaved[r] = false; + ra_class[r] = RA_CALLER_SAVED; unsigned cnt; const Parameters * input = this; @@ -905,16 +907,10 @@ void Parameters::compute_derived() { bprecs[oblock[item[0]]].push_back(item); } - vector empty_predecessors; - init_vector(bpredecessors, B.size(), empty_predecessors); - for (PresolverPred item : predecessors) { - bpredecessors[oblock[item.q]].push_back(item); - } - - vector empty_successors; - init_vector(bsuccessors, B.size(), empty_successors); - for (PresolverSucc item : successors) { - bsuccessors[oblock[item.p]].push_back(item); + vector empty_wcet; + init_vector(bwcet, B.size(), empty_wcet); + for (PresolverWCET item : wcet) { + bwcet[oblock[item.o]].push_back(item); } N = maxf.size(); @@ -1071,222 +1067,6 @@ Parameters Parameters::make_local(block b) { return local; } -#ifdef GRAPHICS - -QScriptValue Parameters::getRoot(QScriptValue root, string p) { - return root.property(p.c_str()); -} - -void Parameters::get_element(QScriptValue root, bool & b) { - assert(root.isBoolean()); - b = root.toBoolean(); -} - -void Parameters::get_element(QScriptValue root, int & i) { - assert(root.isNumber()); - i = root.toInt32(); -} - -void Parameters::get_element(QScriptValue root, double & d) { - assert(root.isNumber()); - d = root.toNumber(); -} - -void Parameters::get_element(QScriptValue root, string & s) { - assert(root.isString()); - s = root.toString().toStdString(); -} - -void Parameters::get_element(QScriptValue root, UnisonConstraintExpr & e) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - e.id = (UnisonConstraintExprId) iti.value().toInt32(); - switch (e.id) { - // unary expressions - case NOT_EXPR: - iti.next(); - { - UnisonConstraintExpr e1; - get_element(iti.value(), e1); - e.children.push_back(e1); - } - break; - // binary expressions - case XOR_EXPR: - case IMPLIES_EXPR: - for (unsigned int i = 0; i < 2; i++) { - iti.next(); - { - UnisonConstraintExpr e2; - get_element(iti.value(), e2); - e.children.push_back(e2); - } - } - break; - // n-ary expressions - case OR_EXPR: - case AND_EXPR: - while (iti.hasNext()) { - iti.next(); - if (iti.name() != "length") { - { - UnisonConstraintExpr e3; - get_element(iti.value(), e3); - e.children.push_back(e3); - } - } - } - break; - // unary literals - case ACTIVE_EXPR: - case CALLER_SAVED_EXPR: - iti.next(); - e.data.push_back(iti.value().toInt32()); - break; - // binary literals - case CONNECTS_EXPR: - case IMPLEMENTS_EXPR: - case SHARE_EXPR: - case OPERAND_OVERLAP_EXPR: - case TEMPORARY_OVERLAP_EXPR: - case ALLOCATED_EXPR: - for (unsigned int i = 0; i < 2; i++) { - iti.next(); - e.data.push_back(iti.value().toInt32()); - } - break; - // ternary literals - case DISTANCE_EXPR: - case ALIGNED_EXPR: - for (unsigned int i = 0; i < 3; i++) { - iti.next(); - e.data.push_back(iti.value().toInt32()); - } - break; - default: GECODE_NEVER; - } -} - -void Parameters::get_element(QScriptValue root, PresolverActiveTable & at) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - at.os = get_vector(iti.value()); - iti.next(); - at.tuples = get_2d_vector(iti.value()); -} - -void Parameters::get_element(QScriptValue root, PresolverCopyTmpTable & ctt) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - ctt.os = get_vector(iti.value()); - iti.next(); - ctt.ps = get_vector(iti.value()); - iti.next(); - ctt.tuples = get_2d_vector(iti.value()); -} - -void Parameters::get_element(QScriptValue root, PresolverBeforeJSON & b) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - b.p = iti.value().toInt32(); - iti.next(); - b.q = iti.value().toInt32(); - iti.next(); - get_element(iti.value(), b.e); -} - -void Parameters::get_element(QScriptValue root, PresolverAcrossItemJSON & ai) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - ai.t = iti.value().toInt32(); - iti.next(); - get_element(iti.value(), ai.e); -} - -void Parameters::get_element(QScriptValue root, PresolverAcrossJSON & a) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - a.o = iti.value().toInt32(); - iti.next(); - a.ras = get_vector(iti.value()); - iti.next(); - a.as = get_vector(iti.value()); -} - -void Parameters::get_element(QScriptValue root, PresolverSetAcross & sa) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - sa.o = iti.value().toInt32(); - iti.next(); - sa.ras = get_vector(iti.value()); - iti.next(); - sa.tsets = get_2d_vector(iti.value()); -} - -void Parameters::get_element(QScriptValue root, PresolverDominates & d) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - d.o1 = iti.value().toInt32(); - iti.next(); - d.o2 = iti.value().toInt32(); - iti.next(); - d.ins = get_vector(iti.value()); - iti.next(); - d.temps = get_vector(iti.value()); -} - -void Parameters::get_element(QScriptValue root, PresolverPred & d) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - d.p = get_vector(iti.value()); - iti.next(); - d.q = iti.value().toInt32(); - iti.next(); - d.d = iti.value().toInt32(); -} - -void Parameters::get_element(QScriptValue root, PresolverSucc & d) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - d.p = iti.value().toInt32(); - iti.next(); - d.q = get_vector(iti.value()); - iti.next(); - d.d = iti.value().toInt32(); -} - -void Parameters::get_element(QScriptValue root, PresolverInstrCond & d) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - d.o = iti.value().toInt32(); - iti.next(); - d.i = iti.value().toInt32(); - iti.next(); - d.q = iti.value().toInt32(); -} - -void Parameters::get_element(QScriptValue root, PresolverValuePrecedeChain & d) { - assert(root.isArray()); - QScriptValueIterator iti(root); - iti.next(); - d.ts = get_vector(iti.value()); - iti.next(); - d.rss = get_2d_vector(iti.value()); -} - -#else - Json::Value Parameters::getRoot(Json::Value root, string p) { return root.get(p, "null"); } @@ -1448,34 +1228,24 @@ void Parameters::get_element(Json::Value root, PresolverDominates & d) { d.temps = get_vector(*iti); } -void Parameters::get_element(Json::Value root, PresolverPred & d) { - assert(root.isArray()); - Json::ValueIterator iti = root.begin(); - d.p = get_vector(*iti); - iti++; - d.q = (*iti).asInt(); - iti++; - d.d = (*iti).asInt(); -} - -void Parameters::get_element(Json::Value root, PresolverSucc & d) { +void Parameters::get_element(Json::Value root, PresolverInstrCond & d) { assert(root.isArray()); Json::ValueIterator iti = root.begin(); - d.p = (*iti).asInt(); + d.o = (*iti).asInt(); iti++; - d.q = get_vector(*iti); + d.i = (*iti).asInt(); iti++; - d.d = (*iti).asInt(); + d.q = (*iti).asInt(); } -void Parameters::get_element(Json::Value root, PresolverInstrCond & d) { +void Parameters::get_element(Json::Value root, PresolverWCET & x) { assert(root.isArray()); Json::ValueIterator iti = root.begin(); - d.o = (*iti).asInt(); + x.o = (*iti).asInt(); iti++; - d.i = (*iti).asInt(); + x.i = (*iti).asInt(); iti++; - d.q = (*iti).asInt(); + x.d = (*iti).asInt(); } void Parameters::get_element(Json::Value root, PresolverValuePrecedeChain & d) { @@ -1485,5 +1255,3 @@ void Parameters::get_element(Json::Value root, PresolverValuePrecedeChain & d) { iti++; d.rss = get_2d_vector(*iti); } - -#endif diff --git a/src/solvers/gecode/models/parameters.hpp b/src/solvers/gecode/models/parameters.hpp index 33749530..e66e93b0 100644 --- a/src/solvers/gecode/models/parameters.hpp +++ b/src/solvers/gecode/models/parameters.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * Contributing authors: @@ -50,23 +50,12 @@ #include -#ifdef GRAPHICS -#include -#include -#include -#include -#else // Then we still need an alternative for parsing JSON #include "third-party/jsoncpp/json/value.h" #include "third-party/jsoncpp/json/reader.h" -#endif #include "common/util.hpp" #include "common/definitions.hpp" -// Mats's code changes -#define MCMOD 1 -#define MCSLACK 1 - using namespace Gecode; using namespace std; @@ -335,12 +324,6 @@ class Parameters { // [MC] strictly congruent operand classes vector > strictly_congr; - // [MC] set of predecessors or successors - vector predecessors; - - // [MC] set of predecessors or successors - vector successors; - // [MC] set of value_precede_chain vector value_precede_chains; @@ -353,7 +336,16 @@ class Parameters { // [MC] long_latency use-def hazards vector > long_latency_def_use; - Parameters(JSONVALUE root); + // [MC] subsumed resources + vector > subsumed_resources; + + // [MC] register atom domain of each temp + vector > temp_domain; + + // [MC] max tolerable latency to the following issue + vector wcet; + + Parameters(Json::Value root); // emit parameters in JSON format string emit_json(); @@ -594,8 +586,8 @@ class Parameters { // for sure preassigned reg of t, or -1 vector t_preassign; - // whether r is callee-saved - vector r_calleesaved; + // what is register atom: RA_CALLEE_SAVED, RA_CALLER_SAVED, or RA_RESERVED + vector ra_class; // allowed combinations of active operations, per block vector> bactive_tables; @@ -651,11 +643,8 @@ class Parameters { // set of diffregs, per block vector > > bdiffregs; - // [MC] set of predecessors or successors, per block - vector> bpredecessors; - - // [MC] set of predecessors or successors, per block - vector> bsuccessors; + // max tolerable latency to the following issue, per block + vector > bwcet; // Number of objectives unsigned int N; @@ -664,68 +653,48 @@ class Parameters { Parameters() {}; - JSONVALUE getRoot(JSONVALUE root, string p); - void get_element(JSONVALUE root, bool & b); - void get_element(JSONVALUE root, double & d); - void get_element(JSONVALUE root, int & i); - void get_element(JSONVALUE root, string & s); - void get_element(JSONVALUE root, UnisonConstraintExpr & e); - void get_element(JSONVALUE root, PresolverActiveTable & at); - void get_element(JSONVALUE root, PresolverCopyTmpTable & ctt); - // void get_element(JSONVALUE root, PresolverPrecedence & p); - void get_element(JSONVALUE root, PresolverBeforeJSON & b); - void get_element(JSONVALUE root, PresolverAcrossJSON & a); - void get_element(JSONVALUE root, PresolverAcrossItemJSON & ai); - void get_element(JSONVALUE root, PresolverSetAcross & sa); - void get_element(JSONVALUE root, PresolverDominates & d); - void get_element(JSONVALUE root, PresolverPred & d); - void get_element(JSONVALUE root, PresolverSucc & d); - void get_element(JSONVALUE root, PresolverInstrCond & d); - void get_element(JSONVALUE root, PresolverValuePrecedeChain & d); + Json::Value getRoot(Json::Value root, string p); + void get_element(Json::Value root, bool & b); + void get_element(Json::Value root, double & d); + void get_element(Json::Value root, int & i); + void get_element(Json::Value root, string & s); + void get_element(Json::Value root, UnisonConstraintExpr & e); + void get_element(Json::Value root, PresolverActiveTable & at); + void get_element(Json::Value root, PresolverCopyTmpTable & ctt); + // void get_element(Json::Value root, PresolverPrecedence & p); + void get_element(Json::Value root, PresolverBeforeJSON & b); + void get_element(Json::Value root, PresolverAcrossJSON & a); + void get_element(Json::Value root, PresolverAcrossItemJSON & ai); + void get_element(Json::Value root, PresolverSetAcross & sa); + void get_element(Json::Value root, PresolverDominates & d); + void get_element(Json::Value root, PresolverInstrCond & d); + void get_element(Json::Value root, PresolverWCET & d); + void get_element(Json::Value root, PresolverValuePrecedeChain & d); template - T get_scalar(JSONVALUE root) { + T get_scalar(Json::Value root) { T i; get_element(root, i); return i; } template - vector get_vector(JSONVALUE root) { + vector get_vector(Json::Value root) { vector vi; get_element(root, vi); return vi; } template - vector > get_2d_vector(JSONVALUE root) { + vector > get_2d_vector(Json::Value root) { return get_vector >(root); } template - vector > > get_3d_vector(JSONVALUE root) { + vector > > get_3d_vector(Json::Value root) { return get_vector > >(root); } - -#ifdef GRAPHICS - - template - void get_element(QScriptValue root, vector & vi) { - assert(root.isArray()); - QScriptValueIterator iti(root); - while (iti.hasNext()) { - iti.next(); - if (iti.name() != "length") { - T e; - get_element(iti.value(), e); - vi.push_back(e); - } - } - } - -#else - template void get_element(Json::Value root, vector & vi) { assert(root.isArray()); @@ -738,8 +707,6 @@ class Parameters { } } -#endif - }; #endif diff --git a/src/solvers/gecode/models/presolver-options.cpp b/src/solvers/gecode/models/presolver-options.cpp index c7fc1948..5e3d98a5 100644 --- a/src/solvers/gecode/models/presolver-options.cpp +++ b/src/solvers/gecode/models/presolver-options.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/models/relaxedmodel.cpp b/src/solvers/gecode/models/relaxedmodel.cpp index 11aa6aa0..32f992fb 100644 --- a/src/solvers/gecode/models/relaxedmodel.cpp +++ b/src/solvers/gecode/models/relaxedmodel.cpp @@ -1,7 +1,7 @@ /* * Main authors: * Mikael Almgren - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * This file is part of Unison, see http://unison-code.github.io @@ -105,12 +105,11 @@ BoolVar RelaxedModel::relaxed_adhoc_constraint_var(UnisonConstraintExpr & e) { return u(e.data[0], e.data[1]); case IMPLEMENTS_EXPR: return imp(e.data[0], e.data[1]); - case DISTANCE_EXPR: - return var(c(e.data[1]) >= (c(e.data[0]) + e.data[2])); case SHARE_EXPR: // This is fine because the temps of one will always be a prefix of the // temps of the other return var(y(e.data[0]) == y(e.data[1])); + case DISTANCE_EXPR: case OPERAND_OVERLAP_EXPR: case TEMPORARY_OVERLAP_EXPR: return BoolVar(*this, 0, 1); @@ -176,6 +175,7 @@ void RelaxedModel::post_relaxed_decision_variable_domain_definitions(void) { void RelaxedModel::post_relaxed_secondary_variable_definitions(void) { for(block b : input->B) { Model::post_operand_register_definition(b); + Model::post_connected_operand_definition(b); Model::post_allocation_definition(b); Model::post_use_temporary_definition(b); Model::post_temporary_uses_definition(b); @@ -258,19 +258,19 @@ void RelaxedModel::post_active_operation_branching(vector O) { BoolVarArgs as; for(operation o : O) as << a(o); - branch(*this, as, BOOL_VAR_NONE(), BOOL_VAL_MIN()); + branch(*this, as, BOOL_VAR_AFC_MAX(), BOOL_VAL_MIN()); } void RelaxedModel::post_operand_temporary_branching(vector P) { IntVarArgs ts; for(operand p : P) ts << y(p); - branch(*this, ts, INT_VAR_DEGREE_MAX(),INT_VAL_MED()); + branch(*this, ts, INT_VAR_AFC_MAX(),INT_VALUES_MIN()); } void RelaxedModel::post_instruction_operation_branching(vector O) { IntVarArgs is; for(operation o : O) is << i(o); - branch(*this, is, INT_VAR_DEGREE_MAX(), INT_VAL_MED()); + branch(*this, is, INT_VAR_AFC_MAX(), INT_VALUES_MIN()); } diff --git a/src/solvers/gecode/models/relaxedmodel.hpp b/src/solvers/gecode/models/relaxedmodel.hpp index efcb2fc2..1776859e 100644 --- a/src/solvers/gecode/models/relaxedmodel.hpp +++ b/src/solvers/gecode/models/relaxedmodel.hpp @@ -1,7 +1,7 @@ /* * Main authors: * Mikael Almgren - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/models/simplemodel.cpp b/src/solvers/gecode/models/simplemodel.cpp index 336db3d1..f5096cc6 100644 --- a/src/solvers/gecode/models/simplemodel.cpp +++ b/src/solvers/gecode/models/simplemodel.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/models/simplemodel.hpp b/src/solvers/gecode/models/simplemodel.hpp index 665d5529..b57205ee 100644 --- a/src/solvers/gecode/models/simplemodel.hpp +++ b/src/solvers/gecode/models/simplemodel.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/presolver.cpp b/src/solvers/gecode/presolver.cpp index 7897cb2f..1b04fc02 100644 --- a/src/solvers/gecode/presolver.cpp +++ b/src/solvers/gecode/presolver.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * Contributing authors: @@ -44,16 +44,13 @@ #ifdef GRAPHICS #include -#include #endif #include #include -#ifndef GRAPHICS #include "third-party/jsoncpp/json/value.h" #include "third-party/jsoncpp/json/reader.h" -#endif #include "common/definitions.hpp" #include "models/parameters.hpp" @@ -165,18 +162,826 @@ string produce_json(Parameters &input, int presolver_time) << emit_json_line("diffregs", input.diffregs) << emit_json_line("calleesaved_spill", input.calleesaved_spill) << emit_json_line("strictly_congr", input.strictly_congr) - << emit_json_line("predecessors", input.predecessors) - << emit_json_line("successors", input.successors) << emit_json_line("value_precede_chains", input.value_precede_chains) << emit_json_line("quasi_adjacent", input.quasi_adjacent) << emit_json_line("long_latency_index", input.long_latency_index) << emit_json_line("long_latency_def_use", input.long_latency_def_use) + << emit_json_line("subsumed_resources", input.subsumed_resources) + << emit_json_line("temp_domain", input.temp_domain) + << emit_json_line("wcet", input.wcet) << emit_json_line("freq_scale", input.freq_scale) << emit_json_line_last("presolver_time", presolver_time) << "}\n"; return json.str(); } +/*** .dzn generation ***/ + +#define ZEROBASED1 1 +#define ZEROBASED2 2 +#define MINUSONEBASED1 4 + +class FDSet { +public: + FDSet() : vec({}) {} + FDSet(vector vec0) : vec(vec0) {sort(vec.begin(), vec.end());} + FDSet(vector vec0, int inc) : vec(vec0) {sort(vec.begin(), vec.end()); + for (unsigned int ii=0; ii vec; + bool operator<(const FDSet& s) const { + return (vec < s.vec); + } + bool operator==(const FDSet& s) const { + return (vec == s.vec); + } + bool operator!=(const FDSet& s) const { + return (vec != s.vec); + } + friend ostream& operator<<(ostream& os, const FDSet& fd); +}; + +ostream& operator<<(ostream& os, const FDSet& fd) { + if (fd.vec.empty()) { + os << "{}"; + } else { + int n = -1; + int a=0, b=0; + for (int x : fd.vec) { + if (n == -1) { + a = b = x; + n = 0; + } else if (x == b+1) { + b++; + } else { + if (n++) + os << " union "; + os << a << ".." << b; + a = b = x; + } + } + if (n > 0) + os << " union "; + if (n >= 0) + os << a << ".." << b; + } + return os; +} + +class Quad { +public: + Quad() : id(AND_EXPR), arg1(0), arg2(0), arg3(0), children({}) {} + UnisonConstraintExprId id; + int arg1, arg2, arg3; + vector children; + bool operator<(const Quad & e) const { + if(id != e.id) return id < e.id; + else if(arg1 != e.arg1) return arg1 < e.arg1; + else if(arg2 != e.arg2) return arg2 < e.arg2; + else if(arg3 != e.arg3) return arg3 < e.arg3; + else return children < e.children; + } + bool operator==(const Quad& e) const { + return (id == e.id) && (arg1 == e.arg1) && (arg2 == e.arg2) && (arg3 == e.arg3) && (children == e.children); + } + bool operator!=(const Quad& e) const { + return (id != e.id) || (arg1 != e.arg1) || (arg2 != e.arg2) || (arg3 != e.arg3) || (children != e.children); + } +}; + +void toFDSet(vector>& xs, vector& ys) { + for (vector& x : xs) + ys.push_back(FDSet(x)); +} + +void toFDSetInc(vector>& xs, vector& ys) { + for (vector& x : xs) + ys.push_back(FDSet(x, 1)); +} + +int dznEncodeQuad(Quad& quad, map& quadMap, vector& quadList) { + if (quadMap.count(quad)) { + return quadMap[quad]; + } else { + int i = quadList.size(); + quadList.push_back(quad); + quadMap[quad] = i+1; + return i+1; + } +} + +int dznEncodeFDSet(FDSet& set, map& setMap, vector& setList) { + if (setMap.count(set)) { + return setMap[set]; + } else { + int i = setList.size(); + setList.push_back(set); + setMap[set] = i+1; + return i+1; + } +} + +Quad dznQuad(UnisonConstraintExpr& e, map& quadMap, vector& quadList) { + switch (e.id) { + case OR_EXPR: + case AND_EXPR: + { + vector quads; + vector encoded; + for (UnisonConstraintExpr& a : e.children) { + Quad quad = dznQuad(a, quadMap, quadList); + quads.push_back(quad); + encoded.push_back(dznEncodeQuad(quad, quadMap, quadList)); + } + if (quads.size()==1) { + return quads[0]; + } else { + Quad quad; + quad.id = e.id; + sort(encoded.begin(), encoded.end()); + quad.children.insert(quad.children.end(), encoded.begin(), encoded.end()); + return quad; + } + } + case XOR_EXPR: + { + vector quads; + vector encoded; + for (UnisonConstraintExpr& a : e.children) { + Quad quad = dznQuad(a, quadMap, quadList); + quads.push_back(quad); + encoded.push_back(dznEncodeQuad(quad, quadMap, quadList)); + } + Quad quad; + quad.id = e.id; + sort(encoded.begin(), encoded.end()); + quad.arg1 = encoded[0]; + quad.arg2 = encoded[1]; + return quad; + } + case IMPLIES_EXPR: + if (e.children[0].id==OR_EXPR) { + UnisonConstraintExpr y = e.children[1]; + UnisonConstraintExpr f; + f.id = AND_EXPR; + for (UnisonConstraintExpr& a : e.children[0].children) { + UnisonConstraintExpr conjunct; + conjunct.id = e.id; + conjunct.children.push_back(a); + conjunct.children.push_back(y); + f.children.push_back(conjunct); + } + return dznQuad(f, quadMap, quadList); + } else if (e.children[0].id==AND_EXPR) { + UnisonConstraintExpr y = e.children[1]; + UnisonConstraintExpr f; + f.id = OR_EXPR; + f.children.push_back(y); + for (UnisonConstraintExpr& a : e.children[0].children) { + UnisonConstraintExpr disjunct; + if (a.id == NOT_EXPR) { + disjunct = a.children[0]; + } else { + disjunct.id = NOT_EXPR; + disjunct.children.push_back(a); + } + f.children.push_back(disjunct); + } + return dznQuad(f, quadMap, quadList); + } else { + vector quads; + vector encoded; + for (UnisonConstraintExpr& a : e.children) { + Quad quad = dznQuad(a, quadMap, quadList); + quads.push_back(quad); + encoded.push_back(dznEncodeQuad(quad, quadMap, quadList)); + } + Quad quad; + quad.id = e.id; + quad.arg1 = encoded[0]; + quad.arg2 = encoded[1]; + return quad; + } + case NOT_EXPR: + { + Quad q = dznQuad(e.children[0], quadMap, quadList); + int enc = dznEncodeQuad(q, quadMap, quadList); + Quad quad; + quad.id = e.id; + quad.arg1 = enc; + return quad; + } + default: + { + Quad quad; + quad.id = e.id; + quad.arg1 = e.data[0]; + if (e.data.size() > 1) + quad.arg2 = e.data[1]; + if (e.data.size() > 2) + quad.arg3 = e.data[2]; + return quad; + } + } +} + +int dznEncode(UnisonConstraintExpr& e, map& quadMap, vector& quadList) { + Quad quad = dznQuad(e, quadMap, quadList); + return dznEncodeQuad(quad, quadMap, quadList); +} + +string emit_dzn(const bool b, int opt) { + (void)opt; + stringstream s; + s << (b ? "true" : "false"); + return s.str(); +} + +string emit_dzn(const int i, int opt) { + (void)opt; + stringstream s; + s << i; + return s.str(); +} + +string emit_dzn(const FDSet fd, int opt) { + (void)opt; + stringstream s; + s << fd; + return s.str(); +} + +string emit_dzn(const vector xs, int opt) { + stringstream s; + int beg1 = 1; + int dim1 = xs.size(); + if (opt & ZEROBASED1) + beg1 = 0; + else if (opt & MINUSONEBASED1) + beg1 = -1; + if (beg1 != 1) + s << "array1d(" << beg1 << ".." << dim1+beg1-1 << ", "; + s << "["; + int r = 0; + for (bool x : xs) { + if (r++) + s << ", "; + s << (x ? "true" : "false"); + } + s << "]"; + if (beg1 != 1) + s << ")"; + return s.str(); +} + +string emit_dzn(const vector xs, int opt) { + stringstream s; + int beg1 = 1; + int dim1 = xs.size(); + if (opt & ZEROBASED1) + beg1 = 0; + else if (opt & MINUSONEBASED1) + beg1 = -1; + if (beg1 != 1) + s << "array1d(" << beg1 << ".." << dim1+beg1-1 << ", "; + s << "["; + int r = 0; + for (int x : xs) { + if (r++) + s << ", "; + s << x; + } + s << "]"; + if (beg1 != 1) + s << ")"; + return s.str(); +} + +string emit_dzn(const vector xs, int opt) { + stringstream s; + int beg1 = 1; + int dim1 = xs.size(); + if (opt & ZEROBASED1) + beg1 = 0; + else if (opt & MINUSONEBASED1) + beg1 = -1; + if (beg1 != 1) + s << "array1d(" << beg1 << ".." << dim1+beg1-1 << ", "; + s << "["; + int r = 0; + for (FDSet x : xs) { + if (r++) + s << ", "; + s << x; + } + s << "]"; + if (beg1 != 1) + s << ")"; + return s.str(); +} + +string emit_dzn(const vector> xss, int opt) { + stringstream s; + int beg1 = 1; + int beg2 = 1; + int dim1 = xss.size(); + int dim2 = dim1==0 ? 0 : xss[0].size(); + if (opt & ZEROBASED1) + beg1 = 0; + if (opt & ZEROBASED2) + beg2 = 0; + int r = 0; + s << "array2d(" << beg1 << ".." << dim1+beg1-1 << ", " << beg2 << ".." << dim2+beg2-1 << ", ["; + for (vector xs : xss) { + for (int x : xs) { + if (r++) + s << ", "; + s << x; + } + } + s << "])"; + return s.str(); +} + + +string emit_dzn(const vector> xss, int opt) { + stringstream s; + int beg1 = 1; + int beg2 = 1; + int dim1 = xss.size(); + int dim2 = dim1==0 ? 0 : xss[0].size(); + if (opt & ZEROBASED1) + beg1 = 0; + if (opt & ZEROBASED2) + beg2 = 0; + int r = 0; + s << "array2d(" << beg1 << ".." << dim1+beg1-1 << ", " << beg2 << ".." << dim2+beg2-1 << ", ["; + for (vector xs : xss) { + for (FDSet x : xs) { + if (r++) + s << ", "; + s << x; + } + } + s << "])"; + return s.str(); +} + +template +string emit_dzn_line(string e, const T o) { + return e + " = " + emit_dzn(o, 0) + ";\n"; +} + +template +string emit_dzn_line(string e, const T o, int opt) { + return e + " = " + emit_dzn(o, opt) + ";\n"; +} + + +bool at_least_one_table(vector> tuples) { + vector tuple = tuples[0]; + unsigned int n = tuple.size(); + unsigned int m = tuples.size(); + return (tuple.back() && 1U< setMap; + map quadMap; + map,vector> actMap; + stringstream dzn; + vector across_regs, across_items; + vector activator_insns, activator_ops; + vector atom_regs; + vector bb_operands, bb_ops, bb_subsumed, bb_temps; + vector calleesaved_spill; + vector congr; + vector diffreg; + vector difftemp; + vector dominate_instructions, dominate_temps; + vector emptyset; + vector expr_children; + vector exrelated_rows; + vector op_instructions, op_operands; + vector operand_temps; + vector range; + vector related_temps; + vector relation_ops, relation_range, relation_temps; + vector setList; + vector setacross_regs, setacross_tempsets; + vector strictly_congr; + vector table_exists_ops; + vector table_iffall_ops; + vector temp_domain; + vector temp_uses; + vector value_precede_regs; + vector quadList; + vector last_use; + vector mand; + vector across_op, across_item_temp, across_item_cond; + vector bb_order; + vector before_pred, before_succ, before_cond; + vector dominate_ed, dominate_ing; + vector expr_op, expr_arg1, expr_arg2, expr_arg3; + vector exrelated_p, exrelated_q; + vector infinite; + vector ints; + vector maxatom; + vector nogood, precedence, adhoc; + vector operand_definer; + vector preschedule_op, preschedule_cycle; + vector relation_ntuples; + vector setacross_op; + vector space; + vector value_precede_min, value_precede_max, value_precede_temps; + vector> len_bb(input.maxc.size()); + vector> domop(2); + vector> long_latency_index; + vector> adjacent(2); + vector> aligned(4); + vector> bypass_table; + vector> con_transpose(input.cap.size()); + vector> cs_spill_t(2); + vector> domuse(3); + vector> dur_transpose(input.cap.size()); + vector> exrelated_ext; + vector> flat_operands; + vector> lat_table; + vector> long_latency_def_use(2); + vector> off_transpose(input.cap.size()); + vector> operand_atom; + vector> preassign(2); + vector> quasi_adjacent(2); + vector> wcet; + + for (vector& os : input.ops) { + vector ps; + for (int o : os) + ps.insert(ps.end(), input.operands[o].begin(), input.operands[o].end()); + flat_operands.push_back(ps); + } + toFDSet(input.ops, bb_ops); + toFDSet(flat_operands, bb_operands); + toFDSet(input.tmp, bb_temps); + toFDSetInc(input.subsumed_resources, bb_subsumed); + for (unsigned int i=0; i& kb : len_bb) + bb_order.push_back(kb.second); + toFDSet(input.operands, op_operands); + toFDSet(input.instructions, op_instructions); + for (vector& is : input.instructions) + mand.push_back(is[0] > 0); + toFDSet(input.atoms, atom_regs); + emptyset.push_back(FDSet()); + atom_regs.insert(atom_regs.begin(), emptyset.begin(), emptyset.end()); + for (auto& c : input.congr) + if (c.size() > 1) + congr.push_back(FDSet(c)); + for (auto& c : input.strictly_congr) + if (c.size() > 1) + strictly_congr.push_back(FDSet(c)); + for (vector& is : input.range) + range.push_back(FDSet(is[0], is[1])); + for (vector>& row : input.long_latency_index) { + vector long_latency_row; + toFDSet(row, long_latency_row); + long_latency_index.push_back(long_latency_row); + } + toFDSet(input.temps, operand_temps); + map> canonMap; + set optTemps; + for (int p : input.P) + if (!input.use[p] && input.temps[p][0]==-1) + optTemps.insert(input.temps[p][1]); + for (int p : input.P) { + vector ts = input.temps[p]; + int canon = ts[0]; + if (canon>=0 && input.use[p] && !optTemps.count(canon)) + canonMap[canon].insert(canonMap[canon].end(), ts.begin(), ts.end()); + last_use.push_back(ord_contains(input.last_use, p)); + } + for (auto& kv : canonMap) { + sort(kv.second.begin(), kv.second.end()); + kv.second.erase(unique(kv.second.begin(), kv.second.end()), kv.second.end()); + if (kv.second.size() > 1) + related_temps.push_back(FDSet(kv.second)); + } + toFDSet(input.users, temp_uses); + toFDSet(input.difftemps, difftemp); + toFDSet(input.diffregs, diffreg); + toFDSet(input.temp_domain, temp_domain); + for (vector& is : input.calleesaved_spill) { + cs_spill_t[0].push_back(is[0]); + cs_spill_t[1].push_back(is[1]); + calleesaved_spill.push_back(FDSet(is)); + } + for (vector& as : input.atoms) + maxatom.push_back(as.back()); + for (unsigned int i=0; i& cs : input.con) + for (unsigned int i=0; i& cs : input.dur) + for (unsigned int i=0; i& cs : input.off) + for (unsigned int i=0; i& pr : input.preassign) + for (unsigned int i=0; i<2; i++) + preassign[i].push_back(pr[i]); + for (vector& pr : input.aligned) + for (unsigned int i=0; i<4; i++) + aligned[i].push_back(pr[i]); + for (vector& pr : input.adjacent) + for (unsigned int i=0; i<2; i++) + adjacent[i].push_back(pr[i]); + for (vector& pr : input.quasi_adjacent) + for (unsigned int i=0; i<2; i++) + quasi_adjacent[i].push_back(pr[i]); + for (vector& pr : input.long_latency_def_use) + for (unsigned int i=0; i<2; i++) + long_latency_def_use[i].push_back(pr[i]); + for (unsigned int o=0; o opnds = input.operands[o]; + vector insns = input.instructions[o]; + for (unsigned int j=0; j row; + unsigned int ii = 0; + for (int ins : input.I) + if (ii < insns.size() && ins == insns[ii]) + row.push_back(input.rclass[o][ii++][j]); + else + row.push_back(-1); + operand_atom.push_back(row); + } + } + for (PresolverBeforeJSON& bef : input.before) { + before_pred.push_back(bef.p); + before_succ.push_back(bef.q); + before_cond.push_back(dznEncode(bef.e, quadMap, quadList)); + } + for (UnisonConstraintExpr& e : input.nogoods) + nogood.push_back(dznEncode(e, quadMap, quadList)); + for (PresolverAcrossJSON& a : input.across) { + across_op.push_back(a.o); + across_regs.push_back(FDSet(a.ras)); + vector items; + for (PresolverAcrossItemJSON& aitem : a.as) { + int sofar = across_item_temp.size(); + items.push_back(sofar+1); + across_item_temp.push_back(aitem.t); + across_item_cond.push_back(dznEncode(aitem.e, quadMap, quadList)); + } + across_items.push_back(FDSet(items)); + } + for (PresolverSetAcross& sa : input.set_across) { + setacross_op.push_back(sa.o); + setacross_regs.push_back(FDSet(sa.ras)); + vector tempsets; + for (vector& tset : sa.tsets) { + FDSet fd = FDSet(tset); + tempsets.push_back(dznEncodeFDSet(fd, setMap, setList)); + } + setacross_tempsets.push_back(FDSet(tempsets)); + } + for (UnisonConstraintExpr& e : input.precedences) + precedence.push_back(dznEncode(e, quadMap, quadList)); + for (UnisonConstraintExpr& e : input.E) + adhoc.push_back(dznEncode(e, quadMap, quadList)); + for (vector>& pr : input.domops) + for (unsigned int i=0; i<2; i++) + domop[i].push_back(FDSet(pr[i])); + for (vector& pr : input.domuses) + for (unsigned int i=0; i<3; i++) + domuse[i].push_back(pr[i]); + space.push_back(-1); + space.insert(space.end(), input.space.begin(), input.space.end()); + for (PresolverDominates& pd : input.dominates) { + dominate_ing.push_back(pd.o1); + dominate_ed.push_back(pd.o2); + dominate_instructions.push_back(FDSet(pd.ins)); + dominate_temps.push_back(FDSet(pd.temps)); + } + for (const PresolverActiveTable& AT : input.active_tables) { + if (AT.tuples.size() == 2 && + AT.tuples[0].size() == 2 && + AT.tuples[0][0] == AT.tuples[0][1] && + AT.tuples[1][0] == AT.tuples[1][1]) { + table_iffall_ops.push_back(FDSet(AT.os)); + } else if (at_least_one_table(AT.tuples)) { + table_exists_ops.push_back(FDSet(AT.os)); + } else { + relation_ops.push_back(FDSet(AT.os)); + relation_temps.push_back(FDSet()); + relation_ntuples.push_back(AT.tuples.size()); + int a = ints.size(); + for (auto& tuple : AT.tuples) + ints.insert(ints.end(), tuple.begin(), tuple.end()); + int b = ints.size(); + relation_range.push_back(FDSet(a+1, b)); + } + } + for (const PresolverCopyTmpTable& TT : input.tmp_tables) { + relation_ops.push_back(FDSet(TT.os)); + relation_temps.push_back(FDSet(TT.ps)); + relation_ntuples.push_back(TT.tuples.size()); + int a = ints.size(); + for (auto& tuple : TT.tuples) + ints.insert(ints.end(), tuple.begin(), tuple.end()); + int b = ints.size(); + relation_range.push_back(FDSet(a+1, b)); + } + for (unsigned int ii=0; ii& rs : item.rss) { + value_precede_min.push_back(sofar+1); + value_precede_max.push_back(value_precede_temps.size()); + value_precede_regs.push_back(FDSet(rs)); + } + } + int minl = 9999; + int maxl = 0; + for (int o : input.O) + for (unsigned int ii = 0; ii < input.instructions[o].size(); ii++) + for (unsigned int pp = 0; pp < input.operands[o].size(); pp++) { + int l = input.lat[o][ii][pp]; + lat_table.push_back({o, input.instructions[o][ii], input.operands[o][pp], l}); + minl = min(minl, l); + maxl = max(maxl, l); + } + for (vector& is : input.prescheduled) { + preschedule_op.push_back(is[0]); + preschedule_cycle.push_back(is[1]); + } + for (vector& is : input.exrelated) { + exrelated_p.push_back(is[0]); + exrelated_q.push_back(is[1]); + } + for (vector>& item : input.table) { + unsigned int sofar = exrelated_ext.size(); + exrelated_ext.insert(exrelated_ext.end(), item.begin(), item.end()); + exrelated_rows.push_back(FDSet(sofar+1, exrelated_ext.size())); + } + for (int o : input.O) + for (unsigned int ii = 0; ii < input.instructions[o].size(); ii++) + for (unsigned int pp = 0; pp < input.operands[o].size(); pp++) + if (input.bypass[o][ii][pp]) + bypass_table.push_back({o, input.instructions[o][ii], input.operands[o][pp]}); + for (PresolverWCET& w : input.wcet) + wcet.push_back({w.o, w.i, w.d}); + for (Quad& quad : quadList) { + expr_op.push_back(quad.id); + expr_arg1.push_back(quad.arg1); + expr_arg2.push_back(quad.arg2); + expr_arg3.push_back(quad.arg3); + expr_children.push_back(FDSet(quad.children)); + } + + dzn << emit_dzn_line("MAXF", input.maxf[0]) + << emit_dzn_line("MAXO", input.O.back()) + << emit_dzn_line("MAXP", input.P.back()) + << emit_dzn_line("MAXT", input.T.back()) + << emit_dzn_line("MAXI", input.I.back()) + << emit_dzn_line("MAXC", max_of(input.maxc)) + << emit_dzn_line("MAXR", max_of(maxatom)) + << emit_dzn_line("optimize_cycles", (input.optimize_resource.front() == -1)) + << emit_dzn_line("bb_ops", bb_ops) + << emit_dzn_line("bb_operands", bb_operands) + << emit_dzn_line("bb_temps", bb_temps) + << emit_dzn_line("bb_subsumed", bb_subsumed) + << emit_dzn_line("bb_frequency", input.freq) + << emit_dzn_line("bb_maxcycle", input.maxc) + << emit_dzn_line("bb_optional_min", input.optional_min) + << emit_dzn_line("bb_order", bb_order) + << emit_dzn_line("op_operands", op_operands, ZEROBASED1) + << emit_dzn_line("op_instructions", op_instructions, ZEROBASED1) + << emit_dzn_line("op_type", input.type, ZEROBASED1) + << emit_dzn_line("op_mand", mand, ZEROBASED1) + << emit_dzn_line("atom_regs", atom_regs, MINUSONEBASED1) + << emit_dzn_line("calleesaved", FDSet(input.calleesaved)) + << emit_dzn_line("callersaved", FDSet(input.callersaved)) + << emit_dzn_line("infinite", FDSet(infinite)) + << emit_dzn_line("range", range) + << emit_dzn_line("bounded", input.bounded) + << emit_dzn_line("res_cap", input.cap) + << emit_dzn_line("res_con", con_transpose, ZEROBASED2) + << emit_dzn_line("res_dur", dur_transpose, ZEROBASED2) + << emit_dzn_line("res_off", off_transpose, ZEROBASED2) + << emit_dzn_line("congr", congr) + << emit_dzn_line("strictly_congr", strictly_congr) + << emit_dzn_line("preassign_operand", preassign[0]) + << emit_dzn_line("preassign_reg", preassign[1]) + << emit_dzn_line("aligned_def", aligned[0]) + << emit_dzn_line("aligned_use", aligned[2]) + << emit_dzn_line("aligned_defi", aligned[1]) + << emit_dzn_line("aligned_usei", aligned[3]) + << emit_dzn_line("aligned_dist", input.adist) + << emit_dzn_line("adj_from", adjacent[0]) + << emit_dzn_line("adj_to", adjacent[1]) + << emit_dzn_line("quasi_adj_from", quasi_adjacent[0]) + << emit_dzn_line("quasi_adj_to", quasi_adjacent[1]) + << emit_dzn_line("long_latency_index", long_latency_index) + << emit_dzn_line("long_latency_def", long_latency_def_use[0], ZEROBASED1) + << emit_dzn_line("long_latency_use", long_latency_def_use[1], ZEROBASED1) + << emit_dzn_line("operand_definer", operand_definer, ZEROBASED1) + << emit_dzn_line("operand_use", input.use, ZEROBASED1) + << emit_dzn_line("operand_lastuse", last_use, ZEROBASED1) + << emit_dzn_line("operand_temps", operand_temps, ZEROBASED1) + << emit_dzn_line("operand_atom", operand_atom, ZEROBASED1 + ZEROBASED2) + << emit_dzn_line("related_temps", related_temps) + << emit_dzn_line("temp_definer", input.def_opr, ZEROBASED1) + << emit_dzn_line("temp_def", input.definer, ZEROBASED1) + << emit_dzn_line("temp_width", input.width, ZEROBASED1) + << emit_dzn_line("temp_minlive", input.minlive, ZEROBASED1) + << emit_dzn_line("temp_uses", temp_uses, ZEROBASED1) + << emit_dzn_line("packed_pq", input.packed) + << emit_dzn_line("before_pred", before_pred) + << emit_dzn_line("before_succ", before_succ) + << emit_dzn_line("before_cond", before_cond) + << emit_dzn_line("nogood", nogood) + << emit_dzn_line("across_op", across_op) + << emit_dzn_line("across_regs", across_regs) + << emit_dzn_line("across_items", across_items) + << emit_dzn_line("across_item_temp", across_item_temp) + << emit_dzn_line("across_item_cond", across_item_cond) + << emit_dzn_line("setacross_op", setacross_op) + << emit_dzn_line("setacross_regs", setacross_regs) + << emit_dzn_line("setacross_tempsets", setacross_tempsets) + << emit_dzn_line("difftemp", difftemp) + << emit_dzn_line("diffreg", diffreg) + << emit_dzn_line("domop_operands", domop[0]) + << emit_dzn_line("domop_temps", domop[1]) + << emit_dzn_line("domuse_p", domuse[0]) + << emit_dzn_line("domuse_q", domuse[1]) + << emit_dzn_line("domuse_r", domuse[2]) + << emit_dzn_line("infassign", input.infassign) + << emit_dzn_line("space", space, MINUSONEBASED1) + << emit_dzn_line("dominate_ing", dominate_ing) + << emit_dzn_line("dominate_ed", dominate_ed) + << emit_dzn_line("dominate_instructions", dominate_instructions) + << emit_dzn_line("dominate_temps", dominate_temps) + << emit_dzn_line("precedence", precedence) + << emit_dzn_line("table_exists_ops", table_exists_ops) + << emit_dzn_line("table_iffall_ops", table_iffall_ops) + << emit_dzn_line("relation_ops", relation_ops) + << emit_dzn_line("relation_temps", relation_temps) + << emit_dzn_line("relation_ntuples", relation_ntuples) + << emit_dzn_line("relation_range", relation_range) + << emit_dzn_line("ints", ints) + << emit_dzn_line("calleesaved_spill", calleesaved_spill) + << emit_dzn_line("cs_spill_transpose", cs_spill_t) + << emit_dzn_line("activator_insns", activator_insns) + << emit_dzn_line("activator_ops", activator_ops) + << emit_dzn_line("value_precede_min", value_precede_min) + << emit_dzn_line("value_precede_max", value_precede_max) + << emit_dzn_line("value_precede_regs", value_precede_regs) + << emit_dzn_line("value_precede_temps", value_precede_temps) + << emit_dzn_line("lat_table", lat_table) + << emit_dzn_line("MINL", minl) + << emit_dzn_line("MAXL", maxl) + << emit_dzn_line("preschedule_op", preschedule_op) + << emit_dzn_line("preschedule_cycle", preschedule_cycle) + << emit_dzn_line("exrelated_p", exrelated_p) + << emit_dzn_line("exrelated_q", exrelated_q) + << emit_dzn_line("exrelated_rows", exrelated_rows) + << emit_dzn_line("exrelated_ext", exrelated_ext) + << emit_dzn_line("bypass_table", bypass_table) + << emit_dzn_line("adhoc", adhoc) + << emit_dzn_line("temp_domain", temp_domain, ZEROBASED1) + << emit_dzn_line("wcet", wcet) + << emit_dzn_line("expr_op", expr_op) + << emit_dzn_line("expr_arg1", expr_arg1) + << emit_dzn_line("expr_arg2", expr_arg2) + << emit_dzn_line("expr_arg3", expr_arg3) + << emit_dzn_line("expr_children", expr_children) + << emit_dzn_line("sets", setList); + + return dzn.str(); +} + int main(int argc, char* argv[]) { int argc0 = argc; @@ -204,10 +1009,6 @@ int main(int argc, char* argv[]) { exit(EXIT_FAILURE); } -#ifdef GRAPHICS - QApplication *app = new QApplication(argc, argv, false); -#endif - string name(options.instance()); string prefix = name.substr(0,name.find(".json")) .substr(0,name.find(".ext")); @@ -216,10 +1017,6 @@ int main(int argc, char* argv[]) { fin.open(name.c_str(), ios::in); if (fin.fail()) { cerr << "Failed to open " << name << ": " << strerror(errno) << endl; -#ifdef GRAPHICS - cerr << "Working directory: " - << QDir::currentPath().toStdString() << endl; -#endif exit(EXIT_FAILURE); } string json_input ((std::istreambuf_iterator(fin)), @@ -230,25 +1027,6 @@ int main(int argc, char* argv[]) { exit(EXIT_FAILURE); } -#ifdef GRAPHICS - QScriptValue root; - QScriptEngine engine; - root = engine.evaluate("(" + QString::fromStdString(json_input) + ")"); - if (engine.hasUncaughtException()) { - QScriptValue val = engine.uncaughtException(); - if (val.isError()) { - cerr << "Failed to parse " << name << ": " - << val.toString().toStdString() << " at line " - << engine.uncaughtExceptionLineNumber() << endl - << "Backtrace: " - << engine.uncaughtExceptionBacktrace().join("\n").toStdString() - << endl; - } - exit(EXIT_FAILURE); - } - app->exit(); - delete app; -#else Json::Value root; Json::CharReaderBuilder reader; std::stringstream json_input_stream; @@ -258,7 +1036,6 @@ int main(int argc, char* argv[]) { cerr << "Failed to parse " << name << endl << errs; exit(EXIT_FAILURE); } -#endif Parameters input(root); @@ -273,6 +1050,11 @@ int main(int argc, char* argv[]) { fout << produce_json(input, t_pre_ms); fout.close(); } + if (!options.dzn_file().empty()) { + fout.open(options.dzn_file()); + fout << produce_dzn(input); + fout.close(); + } if (options.verbose()) cerr << "presolved in " << t_pre_ms << " ms" << endl; diff --git a/src/solvers/gecode/presolver.mk b/src/solvers/gecode/presolver.mk index e1ccbd39..b7fac420 100644 --- a/src/solvers/gecode/presolver.mk +++ b/src/solvers/gecode/presolver.mk @@ -1,6 +1,6 @@ # # Main authors: -# Roberto Castaneda Lozano +# Roberto Castaneda Lozano # # Contributing authors: # Mats Carlsson diff --git a/src/solvers/gecode/presolver.pro b/src/solvers/gecode/presolver.pro index f1e58612..86e9b904 100644 --- a/src/solvers/gecode/presolver.pro +++ b/src/solvers/gecode/presolver.pro @@ -1,6 +1,6 @@ # # Main authors: -# Roberto Castaneda Lozano +# Roberto Castaneda Lozano # # Contributing authors: # Mats Carlsson @@ -125,7 +125,6 @@ LIBS += -lgecodesearch -lgecodeminimodel -lgecodeset -lgecodefloat -lgecodeint \ TARGET = gecode-presolver CONFIG -= qt CONFIG += warn_on -QT += script CONFIG(graphics) { diff --git a/src/solvers/gecode/presolver/across.cpp b/src/solvers/gecode/presolver/across.cpp index f87e0530..e8f91a19 100644 --- a/src/solvers/gecode/presolver/across.cpp +++ b/src/solvers/gecode/presolver/across.cpp @@ -56,9 +56,8 @@ void presolve_across(PresolverAsserts& PA, gen_across_call(PA, input, oset, b, CondBefore, Across); alt_across_call(PA, input, oset, b, AltAcross); } - for(const PresolverAcrossTuple& acr : Across) { + for(const PresolverAcrossTuple& acr : Across) nogoods_or_across(input, acr, Nogoods, Across1); - } } void alt_across_to_json(Parameters& input, @@ -130,7 +129,7 @@ void across_to_json(Parameters& input, void collect_at_call(const Parameters& input, operation o, vector& P, vector& T) { for(operand p : oper_uses(input, o)) { - if(is_preassigned_callee_saved(input, p)) { + if(p_preassigned_callee_saved(input, p)) { // reserved: EXCLUDED P.push_back(p); for(temporary t : opnd_temps(input, p)) vector_insert(T, t); @@ -164,7 +163,7 @@ void gen_across_call(PresolverAsserts& PA, collect_before_call(PA, input, o1, b, Before); collect_after_call(PA, input, o1, b, After); cond_before_items(PA, input, Before, After, o1, b, CondBefore); - + // rephrased algorithm for(const pair& bef : Before) { if(After.find(bef.first) != After.end()) { @@ -239,7 +238,7 @@ void collect_after_call(PresolverAsserts& PA, const Parameters& input, operation After[tu].push_back(Conj); } } - if(!is_preassigned_callee_saved(input, p)) { // preassigned: not or caller-saved + if(!p_preassigned_callee_saved(input, p)) { // preassigned: not or caller-saved OR RESERVED for(temporary tu : opnd_temps(input, p)) { if(tu!=NULL_TEMPORARY) { if(oper_type(input, temp_oper(input, tu))!=FUN) { @@ -311,8 +310,7 @@ void nogoods_or_across(const Parameters& input, vector& Across) { presolver_disj Disj; temporary t = acr.t; - int r = input.t_preassign[t]; - bool cstemp = r<0 ? false : !input.r_calleesaved[r]; + bool cstemp = t_preassigned_caller_saved(input, t); for(const presolver_conj& c : acr.d) { presolver_conj c2; bool csopnd = false; @@ -322,11 +320,8 @@ void nogoods_or_across(const Parameters& input, vector ts = opnd_temps(input, p); if(ts.size()==1 || (ts.size()==2 && ts[0]==NULL_TEMPORARY)) continue; - if(l.data[1]==t) { - int pr = input.p_preassign[p]; - if(pr>=0 && !input.r_calleesaved[pr]) - csopnd = true; - } + if(l.data[1]==t && p_preassigned_caller_saved(input, p)) + csopnd = true; } c2.push_back(l); } @@ -352,7 +347,7 @@ vector across_candidates(PresolverAsserts& PA, const Parameters& inpu for(operation o : input.ops[b]) { if(o!=o1 && !ord_contains(successors, o)) { for(operand p : oper_defs(input, o)) - if(!is_preassigned_caller_saved(input, p)) { // preassigned: not or non-caller-saved + if(!p_preassigned_caller_saved(input, p)) { // preassigned: not or callee-saved or reserved for(temporary t : opnd_temps(input, p)) { if(t!=NULL_TEMPORARY) { vector_insert(C, t); @@ -364,7 +359,7 @@ vector across_candidates(PresolverAsserts& PA, const Parameters& inpu for(operation o : input.ops[b]) { if(is_mandatory(input, o) && !ord_contains(predecessors, o)) { for(operand p : oper_uses(input, o)) { - if(o!=o1 || is_preassigned_callee_saved(input, p)) { // preassigned: non-caller-saved + if(o!=o1 || p_preassigned_callee_saved(input, p)) { // preassigned: callee-saved, but not reserved for(temporary t : opnd_temps(input, p)) { if(t!=NULL_TEMPORARY) { vector_insert(U, t); @@ -383,23 +378,21 @@ pair cond_caller_saved(const Parameters& input, operand p, temporary t, const presolver_conj& c) { - if(!is_preassigned_not(input, p)) { - if(is_preassigned_callee_saved(input, p)) { // preassigned: non-caller-saved - return make_pair(false, c); - } else { - return make_pair(true, c); - } - } + if (t_preassigned_caller_saved(input, t)) + return make_pair(true, c); + else if (!t_preassigned_not(input, t)) + return make_pair(false, c); + else if(p_preassigned_caller_saved(input, p)) + return make_pair(true, c); + else if(!p_preassigned_not(input, p)) + return make_pair(false, c); for(const UnisonConstraintExpr& l : c) { if(l.id==CONNECTS_EXPR && l.data[1]==t) { operand q = l.data[0]; - if(!is_preassigned_not(input, q)) { - if(is_preassigned_callee_saved(input, q)) { // preassigned: non-caller-saved - return make_pair(false, c); - } else { - return make_pair(true, c); - } - } + if(p_preassigned_caller_saved(input, q)) + return make_pair(true, c); + else if(!p_preassigned_not(input, q)) + return make_pair(false, c); } } UnisonConstraintExpr e(CALLER_SAVED_EXPR, {t}, {}); @@ -433,10 +426,12 @@ void cond_before_items(PresolverAsserts& PA, if (pcs > fuse) pcs = fuse; } } + if (pcs < 0) // can happen if --nocc --noreserved + return; for(const pair& bef : cond_before_filter(input, Before, {})) { temporary t = bef.first; operand p = temp_def(input, t); - if(is_preassigned_not(input, p)) { // not preassigned + if(p_preassigned_not(input, p)) { // not preassigned t2before[t] = kernel_set(bef.second, {}, -1); t2either[t] = 0; } @@ -445,13 +440,13 @@ void cond_before_items(PresolverAsserts& PA, temporary t = aft.first; operand p = temp_def(input, t); presolver_disj kern = kernel_set(aft.second, {}, -1); - if(!is_preassigned_not(input, p)) { // preassigned + if(!p_preassigned_not(input, p)) { // preassigned goto nexta; } if (kern.size()==1) { for(const UnisonConstraintExpr& l : kern[0]) { if(l.id==CONNECTS_EXPR && l.data[1]==aft.first && - !is_preassigned_not(input, l.data[0])) { // eq(p(p),t(t)) where p is preassigned + !p_preassigned_not(input, l.data[0])) { // eq(p(p),t(t)) where p is preassigned goto nexta; } } @@ -501,11 +496,17 @@ map cond_before_filter(const Parameters& input, Filtered[t] = {}; } else { for(const presolver_conj& c : kv.second) { - UnisonConstraintExpr e(CALLER_SAVED_EXPR, {t}, {}); - presolver_conj c2 = {e}; + presolver_conj c2; + if(t_preassigned_caller_saved(input, t)) { + } else if(!t_preassigned_not(input, t)) { + goto nextc; + } else { + UnisonConstraintExpr e(CALLER_SAVED_EXPR, {t}, {}); + c2.push_back(e); + } for(const UnisonConstraintExpr& l : c) { if(l.id==CONNECTS_EXPR && l.data[1]==t && // eq(p(p),t(t)) where - is_preassigned_callee_saved(input, l.data[0])) { // p preassigned non-caller-saved + p_preassigned_callee_saved(input, l.data[0])) { // p preassigned callee-saved, but not reserved goto nextc; } } @@ -541,7 +542,7 @@ void alt_across_call(PresolverAsserts& PA, } for(operation o : successors) { for(operand p : oper_uses(input, o)) { - if(ord_intersection(input.temps[p], PA.remat).empty()) { + if(!ord_intersect(input.temps[p], PA.remat)) { vector_insert(UseAfter, first_temp(input, p)); } } @@ -568,7 +569,7 @@ void alt_across_call(PresolverAsserts& PA, ord_contains(UseOnly, td) && !ord_contains(S, tu) && !ord_contains(S, td) && - ord_intersection(input.temps[pu], PA.remat).empty()) { + !ord_intersect(input.temps[pu], PA.remat)) { S.push_back(tu); S.push_back(td); PresolverSetAcrossTuple T; diff --git a/src/solvers/gecode/presolver/auxiliary.cpp b/src/solvers/gecode/presolver/auxiliary.cpp index 44032476..87aa5a20 100644 --- a/src/solvers/gecode/presolver/auxiliary.cpp +++ b/src/solvers/gecode/presolver/auxiliary.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Erik Ekstrom * Mats Carlsson * @@ -318,33 +318,51 @@ block block_containing(const Parameters& input, const vector& P) { return b; } -bool is_preassigned_not(const Parameters& input, operand p) { +bool p_preassigned_not(const Parameters& input, operand p) { int r = input.p_preassign[p]; return r<0; } -bool is_preassigned_caller_saved(const Parameters& input, operand p) { +bool p_preassigned_caller_saved(const Parameters& input, operand p) { int r = input.p_preassign[p]; - return (r>=0 && !input.r_calleesaved[r]); + return (r>=0 && input.ra_class[r]==RA_CALLER_SAVED); } -bool is_preassigned_callee_saved(const Parameters& input, operand p) { +bool p_preassigned_callee_saved(const Parameters& input, operand p) { int r = input.p_preassign[p]; - return (r>=0 && input.r_calleesaved[r]); + return (r>=0 && input.ra_class[r]==RA_CALLEE_SAVED); +} + +bool t_preassigned_not(const Parameters& input, temporary t) { + int r = input.t_preassign[t]; + return r<0; +} + +bool t_preassigned_caller_saved(const Parameters& input, temporary t) { + int r = input.t_preassign[t]; + return (r>=0 && input.ra_class[r]==RA_CALLER_SAVED); +} + +bool t_preassigned_callee_saved(const Parameters& input, temporary t) { + int r = input.t_preassign[t]; + return (r>=0 && input.ra_class[r]==RA_CALLEE_SAVED); } bool is_mandatory(const Parameters& input, operation o) { - return input.instructions[o][0] != NULL_INSTRUCTION; -#if 0 - return std::any_of( - input.mandatory.begin(), - input.mandatory.end(), - [o](vector block_mandatory_ops) { - return ord_contains(block_mandatory_ops, o); - }); -#endif + return input.instructions[o][0] != NULL_INSTRUCTION; } +void p_finite_register_classes(const Parameters& input, operand p, set& RC) { + operation o = input.oper[p]; + unsigned int nbinsn = input.instructions[o].size(); + int prel = p - input.operands[o][0]; + for(unsigned int j=0; j + * Roberto Castaneda Lozano * Mats Carlsson * Erik Ekstrom * @@ -93,6 +93,22 @@ vector ord_intersection(const vector& v1, const vector& v2){ return i; } +// Returns whether the sorted vectors v1 and v2 intersect +template +bool ord_intersect(const vector& v1, const vector& v2) { + typename vector::const_iterator i = v1.begin(); + typename vector::const_iterator j = v2.begin(); + while (i != v1.end() && j != v2.end()) { + if (*i == *j) + return true; + else if (*i < *j) + ++i; + else + ++j; + } + return false; +} + // Returns the union of the sorted vectors v1 and v2 template vector ord_union(const vector& v1, const vector& v2){ @@ -190,17 +206,28 @@ Digraph dd_graph(const Parameters& input, block b); block block_containing(const Parameters& input, const vector& P); // Is operand not preassigned? -bool is_preassigned_not(const Parameters& input, operand p); +bool p_preassigned_not(const Parameters& input, operand p); // Is operand preassigned caller-saved? -bool is_preassigned_caller_saved(const Parameters& input, operand p); +bool p_preassigned_caller_saved(const Parameters& input, operand p); // Is operand preassigned callee-saved? -bool is_preassigned_callee_saved(const Parameters& input, operand p); +bool p_preassigned_callee_saved(const Parameters& input, operand p); + +// Is temporary not preassigned? +bool t_preassigned_not(const Parameters& input, temporary t); + +// Is temporary preassigned caller-saved? +bool t_preassigned_caller_saved(const Parameters& input, temporary t); + +// Is temporary preassigned callee-saved? +bool t_preassigned_callee_saved(const Parameters& input, temporary t); // Is operation mandatory? bool is_mandatory(const Parameters& input, operation o); +void p_finite_register_classes(const Parameters& input, operand p, set& RC); + presolver_conj normal_conjunction(const Parameters& input, const presolver_conj& c); UnisonConstraintExpr conj_to_expr(const presolver_conj& c); diff --git a/src/solvers/gecode/presolver/before_presolver.cpp b/src/solvers/gecode/presolver/before_presolver.cpp index 56428f3c..623a256a 100644 --- a/src/solvers/gecode/presolver/before_presolver.cpp +++ b/src/solvers/gecode/presolver/before_presolver.cpp @@ -1,7 +1,7 @@ /* * Main authors: * Erik Ekstrom - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * This file is part of Unison, see http://unison-code.github.io @@ -72,11 +72,10 @@ void BeforePresolver::gen_before(beforeset& B) { operand p = C[i]; operand q = C[j]; - // p are in and q are out of the same block and are not copy related + // p are (in) and q are (out) of the same block if(input.pb[p] == input.pb[q] && input.type[input.oper[p]] == IN && - input.type[input.oper[q]] == OUT && - !ord_contains(copy_rel_operands[p],q)) { + input.type[input.oper[q]] == OUT) { // B <- B union Before1(p,q) before1(p,q,B); } @@ -106,7 +105,7 @@ void BeforePresolver::gen_before(beforeset& B) { Digraph G = Digraph(P); Digraph GR = G.reduction(); - // B <- B union { | in R} + // B <- B union { | in R} for(const edge& e : GR.edges()) { PresolverBefore pb; pb.p = e.first; @@ -115,7 +114,7 @@ void BeforePresolver::gen_before(beforeset& B) { } } - // B <- B union { | p in input.last_use && the temporary of + // B <- B union { | p in input.last_use && the temporary of // p can't be live past p, and q is def of the // same operation as p.} for(operand p : input.last_use) { @@ -141,7 +140,7 @@ void BeforePresolver::gen_before(beforeset& B) { } } - // B <- B union { | p defines t, which is not unsafe and has its single use in the operation defining q.} + // B <- B union { | p defines t, which is not unsafe and has its single use in the operation defining q.} for(operand p : input.P) { if(!input.use[p]) { vector ts = input.temps[p]; @@ -188,81 +187,16 @@ void BeforePresolver::gen_before(beforeset& B) { } - void BeforePresolver::before1(operand p, operand q, vector& B) { - // LH <- {OperOpnds(o) | o in Input.O and OperType(o) in {LOW, HIGH, SPLIT2, SPLIT4}} - vector > LH; - for(const operation o : input.O) { - int type = input.type[o]; - if(type == LOW || type == HIGH || type == SPLIT2 || type == SPLIT4) { - vector_insert(LH, input.operands[o]); - } - } - - presolver_conj C; - const vector >& P = lh_descendants(p, C, LH); - const vector >& Q = lh_descendants(q, C, LH); - - for(const pair& pc : P) { - for(const pair& qc : Q) { - PresolverBefore pb; - pb.p = pc.first; - pb.q = qc.first; - - // Only add non-empty - presolver_conj conj; - for(const UnisonConstraintExpr& lit : pc.second) - /* FIXME if(!lit.empty())*/ vector_insert(conj, lit); - for(const UnisonConstraintExpr& lit : qc.second) - /* FIXME if(!lit.empty())*/ vector_insert(conj, lit); - - if(!conj.empty()) { - pb.d.push_back(conj); - } - - B.push_back(pb); - } - } -} - - -vector > -BeforePresolver::lh_descendants(const operand p, - const presolver_conj& C, - const vector >& LH) { - vector > V; - - // V <- {} - vector_insert(V, make_pair(p, C)); - - for(const vector& ud : LH) { - if(ud.size() == 2) { - operand u = ud[0]; - operand d = ud[1]; - - const vector& tp = input.temps[p]; - const vector& tu = input.temps[u]; - - presolver_conj _C = C; - - if(ord_intersection(tp,tu).size() > 0) { - - if(tp != tu){ - UnisonConstraintExpr _l(SHARE_EXPR, {u,p}, {}); - _C.push_back(_l); - } - - for(const pair& lh : lh_descendants(d,_C,LH)) { - vector_insert(V, lh); - } - } - } + if(!ord_contains(copy_rel_operands[p], q)) { + PresolverBefore pb; + pb.p = p; + pb.q = q; + B.push_back(pb); } - return V; } - vector > BeforePresolver::emit_before(const vector >& C) { vector > V; @@ -281,8 +215,7 @@ vector > BeforePresolver::emit_before(const vector > else if(((r + w) > rr) && ((rr + ww) > r) && - ord_intersection(input.temps[p], - input.temps[pp]).empty()) { + !ord_intersect(input.temps[p], input.temps[pp])) { vector_insert(V, {p,pp}); } } @@ -291,19 +224,15 @@ vector > BeforePresolver::emit_before(const vector > return V; } - void BeforePresolver::before_vs_nogoods(beforeset& T, vector& Nogoods) { for(PresolverBefore& t : T) { - // before <- {t | t = in T} + // before <- {t | t = in T} + // nogoods <- {conj union {overlap(p(p), p(q))} | in T where conj = {_|_}} if(t.d.empty()) { UnisonConstraintExpr e(AND_EXPR, {}, {}); PresolverBeforeJSON u(t.p, t.q, e); input.before.push_back(u); - } - - // nogoods <- {Conj union {overlap(p(p), p(q))} | in T - // and conj != ø} - else { + } else { UnisonConstraintExpr e(OPERAND_OVERLAP_EXPR, {t.p,t.q}, {}); presolver_conj _conj = {e}; diff --git a/src/solvers/gecode/presolver/before_presolver.hpp b/src/solvers/gecode/presolver/before_presolver.hpp index c85fed1f..c38cd03e 100644 --- a/src/solvers/gecode/presolver/before_presolver.hpp +++ b/src/solvers/gecode/presolver/before_presolver.hpp @@ -1,7 +1,7 @@ /* * Main authors: * Erik Ekstrom - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Mats Carlsson @@ -76,13 +76,6 @@ class BeforePresolver { // depending on them via a low or high operation void before1(operand p, operand q, beforeset& b); - // Generate set of conditional operands, that functionally - // depending on p via a low or high operation - vector > - lh_descendants(const operand p, - const presolver_conj& C, - const vector >& LH); - // Generate unconditional befores for operands preassigned to // overlapping registers vector > emit_before(const vector >& C); diff --git a/src/solvers/gecode/presolver/congr.cpp b/src/solvers/gecode/presolver/congr.cpp index 1d5b3661..249bed34 100644 --- a/src/solvers/gecode/presolver/congr.cpp +++ b/src/solvers/gecode/presolver/congr.cpp @@ -1,7 +1,7 @@ /* * Main authors: * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Noric Couderc @@ -169,7 +169,9 @@ void gen_calleesaved_spill(Parameters& input) { for(const vector& related : copyrel_star) { if(related.size()>=2 && related[0]==t) { temporary t1 = related[1]; - Si.push_back(input.oper[input.definer[t1]]); + operation oi = input.oper[input.definer[t1]]; + if(input.type[oi] == COPY) + Si.push_back(oi); for(unsigned int j=2; j * * Contributing authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/presolver/debug_print.hpp b/src/solvers/gecode/presolver/debug_print.hpp index 53419c1d..06c6c4dc 100644 --- a/src/solvers/gecode/presolver/debug_print.hpp +++ b/src/solvers/gecode/presolver/debug_print.hpp @@ -1,7 +1,7 @@ /* * Main authors: * Erik Ekstrom - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/presolver/diff_temps.cpp b/src/solvers/gecode/presolver/diff_temps.cpp index d54ca7d5..e018e3e9 100644 --- a/src/solvers/gecode/presolver/diff_temps.cpp +++ b/src/solvers/gecode/presolver/diff_temps.cpp @@ -4,7 +4,7 @@ * Mats Carlsson * * Contributing authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/presolver/diff_temps.hpp b/src/solvers/gecode/presolver/diff_temps.hpp index 27a8fe5f..dc922d85 100644 --- a/src/solvers/gecode/presolver/diff_temps.hpp +++ b/src/solvers/gecode/presolver/diff_temps.hpp @@ -4,7 +4,7 @@ * * Contributing authors: * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/presolver/digraph.cpp b/src/solvers/gecode/presolver/digraph.cpp index 961ef195..1095f135 100644 --- a/src/solvers/gecode/presolver/digraph.cpp +++ b/src/solvers/gecode/presolver/digraph.cpp @@ -3,7 +3,7 @@ * Erik Ekstrom * Mats Carlsson * Noric Couderc - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/presolver/digraph.hpp b/src/solvers/gecode/presolver/digraph.hpp index c16a7c3f..793617bf 100644 --- a/src/solvers/gecode/presolver/digraph.hpp +++ b/src/solvers/gecode/presolver/digraph.hpp @@ -2,7 +2,7 @@ * Main authors: * Erik Ekstrom * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Noric Couderc diff --git a/src/solvers/gecode/presolver/disjoint_set.hpp b/src/solvers/gecode/presolver/disjoint_set.hpp index 76c4abb9..703ba47c 100644 --- a/src/solvers/gecode/presolver/disjoint_set.hpp +++ b/src/solvers/gecode/presolver/disjoint_set.hpp @@ -1,7 +1,7 @@ /* * Main authors: * Erik Ekstrom - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Noric Couderc * * This file is part of Unison, see http://unison-code.github.io diff --git a/src/solvers/gecode/presolver/dominance.cpp b/src/solvers/gecode/presolver/dominance.cpp index c294afe2..891ec2df 100644 --- a/src/solvers/gecode/presolver/dominance.cpp +++ b/src/solvers/gecode/presolver/dominance.cpp @@ -2,7 +2,7 @@ * Main authors: * Mikael Almgren * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -69,11 +69,9 @@ bool compression_1(const vector>& S) { return false; } return true; - } - - // if the rows in S only has one column, return true if - // there are one row with 1 and one with 0 - else if(S[0].size() == 1){ + } else if(S[0].size() == 1) { + // if the rows in S only has one column, return true if + // there are one row with 1 and one with 0 bool ex = false; for(const vector& s1 : S) { ex = false; @@ -128,13 +126,10 @@ bool compression_3(const vector>& S) { return b; } -vector> sort_increasing_T(const map,vector>& M) { - vector> ret_keys; - - // Store all keys in new vector - for(auto it = M.begin(); it != M.end(); it++) { - ret_keys.push_back(it->first); - } +void sort_increasing_T(map,vector>& M, + vector>& ret_keys) { + for (auto& kv : M) + ret_keys.push_back(kv.first); sort(ret_keys.begin(), ret_keys.end(), [M](vector a, vector b) { @@ -146,7 +141,6 @@ vector> sort_increasing_T(const map,vector, vector> k = it->first; vector T2 = get<0>(k); - vector T1 = M.at(k); + vector T1 = M[k]; if(*(T2.begin()) == *(T.begin()) && subseteq(T1, T) && T1.size() >= 2) vector_insert(N[T1], p); @@ -235,16 +229,13 @@ void gen_dominates(Parameters & input) { - JSON.optional_min - JSON.tmp_tables *****************************************************************************/ -void gen_active_tables(Parameters & input, Support::Timer & t, +void gen_active_tables(Parameters & input, Support::Timer & timer, PresolverOptions & options) { - // Post constraints ModelOptions moptions; RelaxedModel * base = new RelaxedModel(&input, &moptions, IPL_DOM); Gecode::SpaceStatus ss = base->status(); assert(ss != SS_FAILED); - vector> keys; - vector> keys2; map, vector> M; for(const vector& copyrel1 : input.copyrel) { @@ -256,13 +247,16 @@ void gen_active_tables(Parameters & input, Support::Timer & t, } } if (copies.size() >= 2) { - temporary th = copies[0]; - vector tmin = {th}; - vector_insert(keys, tmin); - for(temporary tt : copies) - if (tt != th) - vector_insert(M[tmin], tt); + temporary t1 = copies[0]; + block b1 = input.oblock[input.def_opr[t1]]; + vector tkey = {t1}; + vector T1(next(copies.begin()), copies.end()); + for (temporary t : T1) + if (input.oblock[input.def_opr[t]] != b1) + goto next1; + M[tkey] = T1; } + next1: ; } for(const UnisonConstraintExpr& n : input.nogoods) { if(n.id == AND_EXPR && n.children[0].id == CONNECTS_EXPR && n.children[1].id == CONNECTS_EXPR) { @@ -272,61 +266,67 @@ void gen_active_tables(Parameters & input, Support::Timer & t, temporary t1 = first_temp_but_null(input, p1); temporary t2 = first_temp_but_null(input, p2); - - if(t1 != t2) { - vector T1(next(input.temps[p1].begin()), input.temps[p1].end()); - vector T2(next(input.temps[p2].begin()), input.temps[p2].end()); - - for (temporary t3 : ord_union(T1, T2)) { - vector t1t2 = {t1, t2}; - vector_insert(M[t1t2], t3); - vector_insert(keys2, t1t2); - } + block b1 = input.oblock[input.def_opr[t1]]; + block b2 = input.oblock[input.def_opr[t1]]; + + if(t1 != t2 && b1==b2) { + int opt1 = (input.temps[p1][0] == NULL_TEMPORARY); + int opt2 = (input.temps[p2][0] == NULL_TEMPORARY); + vector T1(next(input.temps[p1].begin(), opt1+1), input.temps[p1].end()); + vector T2(next(input.temps[p2].begin(), opt2+1), input.temps[p2].end()); + vector tkey = {t1, t2}; + vector T12 = ord_union(T1, T2); + for (temporary t : T12) + if (input.oblock[input.def_opr[t]] != b1) + goto next12; + M[tkey] = T12; } + next12: ; } } - keys.insert(keys.end(), keys2.begin(), keys2.end()); + vector> ret_keys; + sort_increasing_T(M, ret_keys); // Time quantum for assert_active_tables: 50% of time left - int tqa = (options.timeout() - t.stop()) / 2; - assert_active_tables(input, base, M, keys, tqa); + int tqa = (options.timeout() - timer.stop()) / 2; + assert_active_tables(input, base, M, ret_keys, tqa); // Time quantum for assert_tmp_tables: 95% of time left - int tqt = 19*(options.timeout() - t.stop()) / 20; - assert_tmp_tables(input, base, M, tqt); + int tqt = 19*(options.timeout() - timer.stop()) / 20; + assert_tmp_tables(input, base, M, ret_keys, tqt); delete base; } void assert_active_tables(Parameters & input, RelaxedModel * base, - const map,vector>& M, - const vector>& keys, + map,vector>& M, + vector>& ret_keys, int timeout) { vector active_tables; - Support::Timer t; - for(const vector& k : keys) { + Support::Timer timer; + for(const vector& key : ret_keys) { vector O; + vector P; if(timeout <= 0) break; - for(temporary t : M.at(k)) - O.push_back(input.def_opr[t]); - - vector P; - for(operation o : O) + for(temporary t : M[key]) { + operation o = input.def_opr[t]; + O.push_back(o); for(operand p : input.operands[o]) P.push_back(p); + } - t.start(); + timer.start(); // Solve problem ActiveTableResult result = get_labelings(base, O, P, timeout); - timeout -= (int) t.stop(); + timeout -= (int) timer.stop(); // Store result of no timeout if(result.timeout_status == RELAXED_NO_TIMEOUT) { @@ -338,10 +338,9 @@ void assert_active_tables(Parameters & input, } else { decompose_copy_set(input, O, result.labelings, active_tables); } - } - - else if(result.timeout_status == RELAXED_TIMEOUT) + } else if(result.timeout_status == RELAXED_TIMEOUT) { break; + } } input.active_tables = active_tables; } @@ -368,10 +367,9 @@ void decompose_copy_set(Parameters & input, } decompose_copy_set(input, O1, S1, active_tables); } - + else if((ind = compression_2(S, O)) >= 0) { // i:th variable stuck-at 1 // compression 2 - else if((ind = compression_2(S, O)) >= 0) { PresolverActiveTable tmp{{O[ind]}, {{1}}}; active_tables.push_back(tmp); vector O1; @@ -390,12 +388,9 @@ void decompose_copy_set(Parameters & input, S1.push_back(temp_s); } decompose_copy_set(input, O1, S1, active_tables); - } - + } else if(O.size() >= 3 && compression_3(S)) { // The last variable implies the other variables // compression 3 - else if(O.size() >= 3 && compression_3(S)) { - for(uint o = 0; o < O.size()-1; o++){ PresolverActiveTable tmp{{O[o], O[O.size()-1]}, {{0,0}, {1,0}, {1,1}}}; @@ -412,9 +407,7 @@ void decompose_copy_set(Parameters & input, } decompose_copy_set(input, O1, S1, active_tables); - } - - else if(O.size() >= 1) { + } else if(O.size() >= 1) { PresolverActiveTable tmp{O, S}; active_tables.push_back(tmp); } @@ -423,7 +416,8 @@ void decompose_copy_set(Parameters & input, void assert_tmp_tables(Parameters & input, RelaxedModel * base, - const map,vector>& M, + map,vector>& M, + vector>& ret_keys, int timeout) { map> P2U; @@ -438,25 +432,24 @@ void assert_tmp_tables(Parameters & input, } } - Support::Timer t; - for(const vector& key : sort_increasing_T(M)) { + Support::Timer timer; + for(const vector& key : ret_keys) { if(key.size() == 1) { if(timeout <= 0) break; temporary k = key[0]; vector O; + vector P = P2U[k]; - for(temporary t : M.at(key)) + for(temporary t : M[key]) O.push_back(input.def_opr[t]); - vector P = P2U.at(k); - - t.start(); + timer.start(); // Solve problem TmpTableResult result = get_labelings(input, base, O, P, timeout); - timeout -= (int) t.stop(); + timeout -= (int) timer.stop(); if(result.timeout_status == RELAXED_NO_TIMEOUT) { // if no labeling is produced, fail and return @@ -469,10 +462,9 @@ void assert_tmp_tables(Parameters & input, tmp_table{O, P, trim_tmp_tables(result.labelings, k)}; tmp_tables.push_back(tmp_table); } - } - - else if(result.timeout_status == RELAXED_TIMEOUT) + } else if(result.timeout_status == RELAXED_TIMEOUT) { break; + } } } input.tmp_tables = tmp_tables; diff --git a/src/solvers/gecode/presolver/dominance.hpp b/src/solvers/gecode/presolver/dominance.hpp index a8581d74..858c82ef 100644 --- a/src/solvers/gecode/presolver/dominance.hpp +++ b/src/solvers/gecode/presolver/dominance.hpp @@ -1,7 +1,7 @@ /* * Main authors: * Mikael Almgren - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * This file is part of Unison, see http://unison-code.github.io @@ -67,7 +67,8 @@ bool compression_3(const vector>& S); // Return sorted keys according to the cardinality of their value. If same // cardinality sort according to key -vector> sort_increasing_T(const map,vector>& M); +void sort_increasing_T(map,vector>& M, + vector>& ret_keys); /***************************************************************************** Code related to: @@ -95,8 +96,8 @@ void gen_active_tables(Parameters & input, Support::Timer & t, void assert_active_tables(Parameters & input, RelaxedModel * base, - const map,vector>& M, - const vector>& keys, + map,vector>& M, + vector>& ret_keys, int timeout); void decompose_copy_set(Parameters & input, @@ -106,7 +107,8 @@ void decompose_copy_set(Parameters & input, void assert_tmp_tables(Parameters & input, RelaxedModel * base, - const map,vector>& M, + map,vector>& M, + vector>& ret_keys, int timeout); void tidy(Parameters & input); diff --git a/src/solvers/gecode/presolver/infeasible_presolver.cpp b/src/solvers/gecode/presolver/infeasible_presolver.cpp index 70be22c9..e0e29e8b 100644 --- a/src/solvers/gecode/presolver/infeasible_presolver.cpp +++ b/src/solvers/gecode/presolver/infeasible_presolver.cpp @@ -2,7 +2,7 @@ * Main authors: * Erik Ekstrom * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -198,7 +198,7 @@ void InfeasiblePresolver::setup(void) { for (const operand q : ord_intersection(input.operands[input.ops[b].back()], P_c)) { - if(ord_intersection(input.temps[p], input.temps[q]).empty()) { + if(!ord_intersect(input.temps[p], input.temps[q])) { D_7.push_back({Temporand::p(p), Temporand::p(q)}); } } @@ -341,7 +341,7 @@ void InfeasiblePresolver::redefined_operand_nogoods(vector& Nogo q = qq.first, q2 = qq.second; unsigned int d1i = find_index(input.operands[o1], p2); unsigned int d2i = find_index(input.operands[o2], q2); - if(!ord_intersection(input.temps[p], input.temps[q]).empty()) { + if(ord_intersect(input.temps[p], input.temps[q])) { vector D; unsigned int n = 0; for (unsigned int i1i = 0; i1i < input.instructions[o1].size(); i1i++) { @@ -418,18 +418,17 @@ void InfeasiblePresolver::xchg_nogoods(vector& Nogoods) { } void InfeasiblePresolver::regdomain_nogoods(vector& Nogoods) { - map,vector> M; + map>,vector> M; map> P2D; map> T2D; // group operations by insn set and use, def counts for(operation o : input.O) { - vector is(input.instructions[o]); - is.push_back(input.operands[o].size()); - M[is].push_back(o); + vector> key(input.rclass[o]); + M[key].push_back(o); } // for each group, for each operand, compute its MGRD (most general reg domain) from atoms // for each temp, get its MGRD from its definer - for(const pair,vector> is_os : M) { + for(const pair>,vector>& is_os : M) { map> MGRD; // mgrd_per_operand(is_os.second[0], MGRD); operation o1 = is_os.second[0]; @@ -445,7 +444,6 @@ void InfeasiblePresolver::regdomain_nogoods(vector& Nogoods) { } } for(operation o : is_os.second) { - unsigned int nbopnd = input.operands[o1].size(); for(unsigned int i=0; i& Nogoods) { vector pd = P2D[p]; if(input.use[p]) { for(temporary t : input.temps[p]) { - if(t != NULL_TEMPORARY && ord_intersection(pd, T2D[t]).empty()) { + if(t != NULL_TEMPORARY && !ord_intersect(pd, T2D[t])) { UnisonConstraintExpr e(CONNECTS_EXPR, {p,t}, {}); presolver_conj c = {e}; Nogoods.push_back(c); @@ -479,15 +477,39 @@ void InfeasiblePresolver::regdomain_nogoods(vector& Nogoods) { } } +static void add_adhoc_constraint_instructions(UnisonConstraintExpr& e, vector& A) { + switch (e.id) { + case OR_EXPR: + case AND_EXPR: + case XOR_EXPR: + case IMPLIES_EXPR: + case NOT_EXPR: + for (UnisonConstraintExpr& e0 : e.children) + add_adhoc_constraint_instructions(e0, A); + break; + + case IMPLEMENTS_EXPR: + A.push_back(e.data[1]); + break; + + default: + break; + } +} + void InfeasiblePresolver::dominsn_nogoods(vector& Nogoods) { // exclude instructions that imply alignment and the null instruction - vector A; + vector A; A.push_back(NULL_INSTRUCTION); - for(const vector& tuple : input.aligned) { + for(const vector& tuple : input.aligned) { instruction i = tuple[1], j = tuple[3]; A.push_back(i); A.push_back(j); } + // exclude instructions that are mentioned in adhoc + for (UnisonConstraintExpr& e : input.E) + add_adhoc_constraint_instructions(e, A); + // set as ordered list sort(A.begin(), A.end()); A.erase(unique(A.begin(), A.end()), A.end()); // build M: potential alt. insns, their reg classes, and operations in which they occur @@ -681,7 +703,7 @@ bool InfeasiblePresolver::has_use_proxy(const temporand_set& C, const operation bool InfeasiblePresolver::has_disjoint_temporary_domains(const vector& P) { for(unsigned i = 0; i < P.size()-1; i++) { for(unsigned j = i+1; j < P.size(); j++) { - if(ord_intersection(input.temps[P[i]], input.temps[P[j]]).size() > 0) { + if(ord_intersect(input.temps[P[i]], input.temps[P[j]])) { return false; } } @@ -823,7 +845,7 @@ void InfeasiblePresolver::emit_nogood(const vector >* R, if (R == nullptr) { Nogoods.push_back(Conj); } else { - // M <- P <- ø + // M <- P <- {} map, vector > M; vector P, Q; @@ -888,8 +910,7 @@ void InfeasiblePresolver::emit_nogood(const vector >* R, vector Ps2 = it2->second; // Ts1 and Ts2 belongs to same basic block and are disjoint - if(input.tb[Ts1[0]] == input.tb[Ts2[0]] && - ord_intersection(Ts1,Ts2).size() == 0) { + if(input.tb[Ts1[0]] == input.tb[Ts2[0]] && !ord_intersect(Ts1,Ts2)) { // TODO: this might be a bug, in mpeg2.gethdr.Get_Hdr there is operands // from different blocks in Ps1 or Ps2, thus the order of them // in the vector determines whether the cluse evaluates to true @@ -904,18 +925,6 @@ void InfeasiblePresolver::emit_nogood(const vector >* R, (even_operand[minPs1] && odd_operand[minPs2])) { Nogoods.push_back(Conj); } - - else if(!exist_before(*R, Ps1, Ps2)) { - operand p3 = min(minPs1, minPs2); - operand p4 = max(minPs1, minPs2); - - UnisonConstraintExpr l(OPERAND_OVERLAP_EXPR, {p3,p4}, {}); - presolver_conj C(Conj); - - // Conj union l - vector_insert(C,l); - Nogoods.push_back(C); - } } } } @@ -967,9 +976,9 @@ vector > InfeasiblePresolver::gen_candidates(const vecto // // Psuedo code: // - // DCands <- ø + // DCands <- {} // For every d in D, - // cands <- ø + // cands <- {} // for every x in d, // if there exist a mapping from root(x) in M, // cand.add(M[root(x)]) @@ -1116,7 +1125,7 @@ void InfeasiblePresolver::detect_cycles(void) { cutoff = (options.timeout() + timer.stop()) / 2; for(const UnisonConstraintExpr& prec : input.precedences) { - // T <- { | in input.precedences && i < j & (d = {ø} || d = {{a(i)}})} + // T <- { | in input.precedences && i < j && (d = {{}} || d = {{a(i)}})} UnisonConstraintExpr prec_c(AND_EXPR, {}, {}); vector data = prec.data; diff --git a/src/solvers/gecode/presolver/infeasible_presolver.hpp b/src/solvers/gecode/presolver/infeasible_presolver.hpp index 37bde62c..f7774d52 100644 --- a/src/solvers/gecode/presolver/infeasible_presolver.hpp +++ b/src/solvers/gecode/presolver/infeasible_presolver.hpp @@ -2,7 +2,7 @@ * Main authors: * Erik Ekstrom * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/presolver/last_use.cpp b/src/solvers/gecode/presolver/last_use.cpp index 900d34fe..d066525c 100644 --- a/src/solvers/gecode/presolver/last_use.cpp +++ b/src/solvers/gecode/presolver/last_use.cpp @@ -36,7 +36,8 @@ void last_use(PresolverAsserts& PA, Parameters& input) { map> M; - + unsigned int prev_op_type = IN; + // For all o in JSON.O where o is mandatory for(operation o : input.O) { // For all p in OperUses(o) where p is mandatory @@ -53,7 +54,6 @@ void last_use(PresolverAsserts& PA, Parameters& input) { unsigned int op_type = oper_type(input, o); switch (op_type) { - case TAILCALL: case OUT: case KILL: // For all p in OperUses(o) @@ -64,10 +64,11 @@ void last_use(PresolverAsserts& PA, Parameters& input) { break; // if OperType(o) = FUNCTION case FUN: - // For all p in OperUses(o) - for (operand p : input.operands[o]) - if (input.use[p] && is_preassigned_caller_saved(input, p)) - input.last_use.push_back(p); + if (prev_op_type != TAILCALL) // after tail-recursive (fun), there will be (out) which can reuse operands! + // For all p in OperUses(o) + for (operand p : input.operands[o]) + if (input.use[p] && p_preassigned_caller_saved(input, p)) // caller-saved, but not reserved + input.last_use.push_back(p); break; case LINEAR: // If there exist C in JSON.strictly_congr, def d in C, use u in C @@ -77,6 +78,7 @@ void last_use(PresolverAsserts& PA, Parameters& input) { input.last_use.push_back(ud.first); break; } + prev_op_type = op_type; } // For all _ -> P in M diff --git a/src/solvers/gecode/presolver/last_use.hpp b/src/solvers/gecode/presolver/last_use.hpp index 2eeadbde..5f95657c 100644 --- a/src/solvers/gecode/presolver/last_use.hpp +++ b/src/solvers/gecode/presolver/last_use.hpp @@ -4,7 +4,7 @@ * Mats Carlsson * * Contributing authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/presolver/precedences.cpp b/src/solvers/gecode/presolver/precedences.cpp index 3196d4ec..ad049dfd 100644 --- a/src/solvers/gecode/presolver/precedences.cpp +++ b/src/solvers/gecode/presolver/precedences.cpp @@ -427,33 +427,6 @@ void partition_nodes(Digraph& G, } } -#if 0 -// naive depth-first search -static int longest_path(Digraph& G, - map& pweight, - map& pweight_c, - operation src, - operation sink, - int len) { - if (src > sink) { - return 0; - } else if (src == sink) { - return len; - } else { - int lp = len; - vector ns = G.neighbors(src); - for (operation n : ns) { - unsigned long key = FastPair(src,n); - int weight = (pweight.find(key) != pweight.end() ? pweight[key] : 0); - int weight_c = (pweight_c.find(key) != pweight_c.end() ? pweight_c[key] : 0); - int nl = longest_path(G, pweight, pweight_c, n, sink, len+max(weight,weight_c)); - lp = max(nl,lp); - } - return lp; - } -} -#endif - static bool has_edge_inside(map& pweight_c, operation lb, operation ub) { @@ -485,28 +458,6 @@ void gen_region_per_partition(const Parameters& input, } } } - -#if 0 - if (!ass.empty()) { - operand p = ass[0]; - temporary t = ass[1]; - operation src = focus[0]; - operation sink = focus[1]; - int lat = focus[2]; - int lp = longest_path(G, pweight, pweight_c, src, sink, 0); - - // vector region = ord_union(G.reachables(src), {src}); - // map src_cps = dag_longest_paths_fwd(region, pweight); - // by construction, sink is reachable from src - if(lp>>& b_edges : M) { Digraph G = Digraph(b_edges.second); @@ -592,45 +543,48 @@ void gen_region(const Parameters& input, map src_cps = dag_longest_paths_fwd(region, pweight, pweight_c); map sink_cps = dag_longest_paths_bwd(reverse, pweight, pweight_c); + vector subsumed = input.subsumed_resources[input.oblock[src]]; for (resource r : input.R) { - vector> edges; - for (operation o1 : region) - if (min_con_erg[o1][r][1]>0) - for (operation o2 : G.reachables(o1)) - if (ord_contains(region,o2) && min_con_erg[o2][r][1]>0) - edges.push_back(make_pair(o1,o2)); - Digraph R = Digraph(edges); - vector RV = R.vertices(); - if (RV.size()>0) { - int r1=0, r2=0, r3=0; - vector F; - if (min_con_erg[src][r][1]==0) { - r1 = 1000000000; - for (operation o : RV) { - int cp = src_cps[o]; - r1 = cp < r1 ? cp : r1; + if (!ord_contains(subsumed, r)) { + vector> edges; + for (operation o1 : region) + if (min_con_erg[o1][r][1]>0) + for (operation o2 : G.reachables(o1)) + if (ord_contains(region,o2) && min_con_erg[o2][r][1]>0) + edges.push_back(make_pair(o1,o2)); + Digraph R = Digraph(edges); + vector RV = R.vertices(); + if (RV.size()>0) { + int r1=0, r2=0, r3=0; + vector F; + if (min_con_erg[src][r][1]==0) { + r1 = 1000000000; + for (operation o : RV) { + int cp = src_cps[o]; + r1 = cp < r1 ? cp : r1; + } } - } - if (min_con_erg[sink][r][1]==0) { - r3 = 1000000000; - for (operation o : RV) { - int cp = sink_cps[o]; - r3 = cp < r3 ? cp : r3; + if (min_con_erg[sink][r][1]==0) { + r3 = 1000000000; + for (operation o : RV) { + int cp = sink_cps[o]; + r3 = cp < r3 ? cp : r3; + } } + for (operation o : RV) + if (min_con_erg[o][r][0] < min_con_erg[o][r][1]) { + F = region_finishers(R, r, input.cap[r], min_con_erg); + break; + } + for (operation o : RV) + if (ord_contains(F,o)) + r2 = r2 + min_con_erg[o][r][0]; + else + r2 = r2 + min_con_erg[o][r][1]; + r2 = (r2-1)/input.cap[r]+1; + r2 = r1+r2+r3-1; + glb = r2 > glb ? r2 : glb; } - for (operation o : RV) - if (min_con_erg[o][r][0] < min_con_erg[o][r][1]) { - F = region_finishers(R, r, input.cap[r], min_con_erg); - break; - } - for (operation o : RV) - if (ord_contains(F,o)) - r2 = r2 + min_con_erg[o][r][0]; - else - r2 = r2 + min_con_erg[o][r][1]; - r2 = (r2-1)/input.cap[r]+1; - r2 = r1+r2+r3-1; - glb = r2 > glb ? r2 : glb; } } if (glb <= src_cps[sink]) { @@ -1157,177 +1111,102 @@ void test_redundancy(Parameters & input, GlobalModel * gm) { } } -#if 0 - -/***************************************************************************** - Code related to: - - JSON.predecessors - - JSON.successors -*****************************************************************************/ -void gen_predecessors_successors(Parameters& input) { - Digraph G = Digraph(input.precs); - Digraph H = G.reduction(); - Digraph T = H.transpose(); - - for(operation v : T.vertices()) { - vector N = T.neighbors(v); - if(N.size() >= 2) { - int span = makespan(input, N); - if(span > 1) { - PresolverPred PPi; - PPi.p = N; - PPi.q = v; - PPi.d = span; - input.predecessors.push_back(PPi); - } - } - } - for(operation v : H.vertices()) { - vector N = H.neighbors(v); - if(N.size() >= 2) { - int span = makespan(input, N); - if(span > 1) { - PresolverSucc PSi; - PSi.p = v; - PSi.q = N; - PSi.d = span; - input.successors.push_back(PSi); +// given block b and resource r, is the resource constraint entailed up front? +void subsumed_resources(Parameters& input) { + for(block b : input.B) { + vector entailed; + vector> r2o(input.R.size()); + set bI; + for(operation o : input.ops[b]) + if(!input.delimiter[o]) + for(instruction i : input.instructions[o]) { + bI.insert(input.instructions[o].begin(), input.instructions[o].end()); + if(i != NULL_INSTRUCTION) + for(resource r : input.R) + if (input.con[i][r]>0 && input.dur[i][r]>0) + r2o[r].insert(o); + } + for(resource r : input.R) { + if(r2o[r].size() <= 1) { + entailed.push_back(r); + } else { + for(resource s : input.R) { + if(s != r && input.cap[r] >= input.cap[s] && !ord_contains(entailed, s)) { + for(instruction i : bI) + if(i != NULL_INSTRUCTION && + (input.dur[i][r] > input.dur[i][s] || + input.con[i][r] > input.con[i][s] || + input.off[i][r] != input.off[i][s])) + goto next_s; + entailed.push_back(r); + goto next_r; + } + next_s: ; + } } + next_r: ; } + input.subsumed_resources[b] = entailed; } } -int makespan(Parameters& input, const vector& ops) { - ModelOptions options; - MakeSpanModel * base = new MakeSpanModel(&input, &options, IPL_DOM); - int span = 1; - - base->post(ops); - base->status(); - - // Set timeout = 3s - Search::Stop * relaxedStop = new Search::TimeStop(3000); - Search::Options opt; - opt.stop = relaxedStop; - DFS e(base, opt); - if (MakeSpanModel *r = e.next()) { - span = r->v_span.val(); - delete r; - } - delete relaxedStop; - delete base; - return span; -} - -MakeSpanModel::MakeSpanModel(Parameters * p_input, ModelOptions * p_options, IntPropLevel p_ipl) : - input(p_input), - options(p_options), - ipl(p_ipl) { -} - -MakeSpanModel::MakeSpanModel(MakeSpanModel& m) : - Space(m), - input(m.input), - options(m.options), - ipl(m.ipl) -{ - v_c.update(*this, m.v_c); - v_i.update(*this, m.v_i); - v_span.update(*this, m.v_span); -} - -MakeSpanModel* MakeSpanModel::copy(void) { - return new MakeSpanModel(*this); -} - -void MakeSpanModel::post(const vector& ops) { - int n = ops.size(); - v_c = IntVarArray(*this, n, 0, n); - v_i = IntVarArray(*this, n, 0, input->I.size() - 1); - v_span = IntVar(*this, 1, n); - for(int oi=0; oi > r2tasks; - - for(int oi=0; oi > > > ru2tasks; - map > > emptyMap; - init_vector(ru2tasks, input->R.size(), emptyMap); - - // Complete map with tasks grouped by consumption - for (unsigned int ii = 0; ii < input->instructions[o].size(); ii++) { - instruction i = input->instructions[o][ii]; - for (resource r : input->R) { - int con = input->con[i][r], - dur = input->dur[i][r]; - if (con > 0 && dur > 0) ru2tasks[r][con].push_back(make_pair(ii, dur)); - } - } - - // For each operation, resource and consumption, define a task (possibly - // related to several instructions) - for (resource r : input->R) { - map > >::iterator it; - for (it = ru2tasks[r].begin(); it != ru2tasks[r].end(); it++) { - int maxdur = -1; - IntArgs durs = IntArgs::create(input->instructions[o].size(), 0, 0); - IntArgs iis; - typedef pair OpDur; - for (const OpDur& ou : it->second) { - durs[ou.first] = ou.second; - iis << ou.first; - if (ou.second > maxdur) maxdur = ou.second; - } - UsageTask task; - task.c = v_c[oi]; - IntVar dur(*this, 0, maxdur); - element(*this, durs, v_i[oi], dur); - task.dur = dur; - task.e = var(v_c[oi] + task.dur); - task.con = it->first; - BoolVar opc(*this, 0, 1); - Gecode::dom(*this, v_i[oi], IntSet(iis), opc); - task.o = opc; - r2tasks[r].push_back(task); +void computeWCET(Parameters &input) { + for (int o : input.O) { + if (input.type[o] == OUT) { + input.wcet.push_back(PresolverWCET(o, 0, 0)); + } else { + block b = input.oblock[o]; + int maxminlive = 0; + + for (temporary t : input.tmp[b]) + if (input.def_opr[t] == o && input.minlive[t] > maxminlive) + maxminlive = input.minlive[t]; + for (unsigned int ii = 0; ii < input.instructions[o].size(); ii++) { + instruction i = input.instructions[o][ii]; + vector opdurs; + if (i == NULL_INSTRUCTION) { + opdurs.push_back(0); + } else { + int maxdeflat = 0; + int maxduroff = 0; + + for (resource r : input.R) + if (input.con[i][r]) { + int duroff = input.dur[i][r] + input.off[i][r]; + if (maxduroff < duroff) + maxduroff = duroff; + } + opdurs.push_back(maxduroff); + + for (unsigned pi = 0; pi < input.operands[o].size(); pi++) { + operand p = input.operands[o][pi]; + if (!input.use[p]) { + int l1 = input.lat[o][ii][pi]; + for (operand q : input.users[input.single_temp[p]]) { + operation o2 = input.oper[q]; + for (unsigned qi = 0; qi < input.operands[o2].size(); qi++) { + if (input.operands[o2][qi]==q) + for (unsigned int jj = 0; jj < input.instructions[o2].size(); jj++) { + int l2 = input.lat[o2][jj][qi]; + if (maxdeflat < l1+l2) + maxdeflat = l1+l2; + } + } + } + } + } + opdurs.push_back(maxdeflat); + + int maxdist = 0; + for (unsigned int e = 0; e < input.dep[b].size(); e++) + if ((o == input.dep[b][e][0]) && (input.dist[b][e][ii] > maxdist)) + maxdist = input.dist[b][e][ii]; + opdurs.push_back(maxdist); + opdurs.push_back(maxminlive); + } + input.wcet.push_back(PresolverWCET(o, i, max_of(opdurs))); } } } - - for (resource r : input->R) { - - IntVarArgs rc; // Start time of each task - IntVarArgs rdur; // Duration of each task - IntVarArgs re; // End time of each task - IntArgs rcon; // Consumption of each task - BoolVarArgs ro; // Whether each task is scheduled - - for (const UsageTask& task : r2tasks[r]) { - rc << task.c; - rdur << task.dur; - re << task.e; - rcon << task.con; - ro << task.o; - } - - cumulative(*this, input->cap[r], rc, rdur, re, rcon, ro); - } - - // branching rule - IntVarArgs as; - as << v_span; - for(int i=0; i& N); - -class MakeSpanModel : public Space { - -public: - - Parameters * input; - ModelOptions * options; - IntPropLevel ipl; - - // Decision variables - - IntVarArray v_c; - IntVarArray v_i; - IntVar v_span; - - // convenience - - void constraint(const BoolExpr &e) {rel(*this, e, ipl);} - - IntVar var(const LinIntExpr &e) {return expr(*this, e, ipl);} - - // constructors - - MakeSpanModel(Parameters * p_input, ModelOptions * p_options, IntPropLevel p_ipl); - - MakeSpanModel(MakeSpanModel& cg); - - MakeSpanModel* copy(void); - - // constraints - - void post(const vector& ops); - -}; - -#endif +void computeWCET(Parameters& input); #endif diff --git a/src/solvers/gecode/presolver/presolve.cpp b/src/solvers/gecode/presolver/presolve.cpp index 08a84c10..fb1e6361 100644 --- a/src/solvers/gecode/presolver/presolve.cpp +++ b/src/solvers/gecode/presolver/presolve.cpp @@ -1,7 +1,7 @@ /* * Main authors: * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Erik Ekstrom @@ -90,8 +90,6 @@ void presolve(Parameters & input, PresolverOptions & options) { vector precedences2_ref = input.precedences2; vector> calleesaved_spill_ref = input.calleesaved_spill; vector value_precede_chains_ref = input.value_precede_chains; - vector predecessors_ref = input.predecessors; - vector successors_ref = input.successors; vector > quasi_adjacent_ref = input.quasi_adjacent; vector > > long_latency_index_ref = input.long_latency_index; vector > long_latency_def_use_ref = input.long_latency_def_use; @@ -115,36 +113,41 @@ void presolve(Parameters & input, PresolverOptions & options) { input.precedences2.clear(); input.calleesaved_spill.clear(); input.value_precede_chains.clear(); - input.predecessors.clear(); - input.successors.clear(); input.quasi_adjacent.clear(); input.long_latency_index.clear(); input.long_latency_def_use.clear(); input.active_tables.clear(); input.tmp_tables.clear(); input.dominates.clear(); + input.wcet.clear(); + + // 35: JSON.wcet + // + // Must be run first because it is mandatory in 'minizinc-solver'. Cannot time + // out before the trivial unfeasibility check below. + + computeWCET(input); // Abort if the problem is trivially unfeasible - + t0.start(); - ModelOptions moptions; - GlobalModel * base = new GlobalModel(&input, &moptions, IPL_DOM); - base->post_upper_bound(input.maxf); - Gecode::SpaceStatus ss1 = base->status(); - delete base; - if (ss1 == SS_FAILED) { - if (options.verbose()) - cerr << pre() - << "proven absence of solutions with cost less or equal than " - << show(input.maxf, ", ", "", "{}") << endl; - // ensure infeasible MiniZinc model - input.nogoods.push_back(UnisonConstraintExpr(OR_EXPR, {}, {})); - return; + { + ModelOptions moptions; + GlobalModel * base = new GlobalModel(&input, &moptions, IPL_DOM); + base->post_upper_bound(input.maxf); + Gecode::SpaceStatus ss1 = base->status(); + delete base; + if (ss1 == SS_FAILED) { + if (options.verbose()) + cerr << pre() + << "proven absence of solutions with cost less or equal than " + << show(input.maxf, ", ", "", "{}") << endl; + // ensure infeasible MiniZinc model + input.nogoods.push_back(UnisonConstraintExpr(OR_EXPR, {}, {})); + return; + } } - if (timeout(t, options, "trivial unfeasibility", t0)) - return; - // 1: JSON.strictly_congr <- GENCONGR() t0.start(); @@ -159,11 +162,14 @@ void presolve(Parameters & input, PresolverOptions & options) { if (timeout(t, options, "last_use", t0)) return; - // 4: <- BEFOREVSNOGOODS(GENBEFORE()) + // 4: <- BEFOREVSNOGOODS(GENBEFORE()) + SUPPRESSED COPIES t0.start(); vector Nogoods; BeforePresolver::presolve(input, Nogoods); + temp_domain(input); + for (const block b : input.B) + suppress_copies(input, b, Nogoods); if (timeout(t, options, "before", t0)) return; @@ -433,7 +439,7 @@ void presolve(Parameters & input, PresolverOptions & options) { if (options.tabling()) { // 29: GenActiveTables(), JSON.tmp_tables - + t0.start(); input.compute_derived(); // refresh for Model:: methods gen_active_tables(input, t, options); @@ -458,18 +464,26 @@ void presolve(Parameters & input, PresolverOptions & options) { return; } // end of options.tabling() - // 34: JSON.precedences <- JSON.precedences U NormalizePrecedences(GenRegionPrecedences()) + // 34: JSON.subsumed_resources + + subsumed_resources(input); + + // 36: JSON.temp_domain + + temp_domain(input); + + // 38: JSON.precedences <- JSON.precedences U NormalizePrecedences(GenRegionPrecedences()) if (options.regions()) { t0.start(); precedence_set region_precedences; - gen_region_precedences(input, min_con_erg, precedences, region_precedences); + gen_region_precedences(input, min_con_erg, precedences, region_precedences); normalize_precedences(input, region_precedences, input.precedences); if (timeout(t, options, "region_precedences", t0)) return; } - // 35: Tidy() + // 37: Tidy() tidy(input); // these can cause huge printouts and should be protected from timeouts @@ -495,8 +509,6 @@ void presolve(Parameters & input, PresolverOptions & options) { run_test("precedences2", precedences2_ref, input.precedences2); run_test("calleesaved_spill", calleesaved_spill_ref, input.calleesaved_spill); run_test("value_precede_chains", value_precede_chains_ref, input.value_precede_chains); - run_test("predecessors", predecessors_ref, input.predecessors); - run_test("successors", successors_ref, input.successors); run_test("quasi_adjacent", quasi_adjacent_ref, input.quasi_adjacent); run_test("long_latency_index", long_latency_index_ref, input.long_latency_index); run_test("long_latency_def_use", long_latency_def_use_ref, input.long_latency_def_use); diff --git a/src/solvers/gecode/presolver/presolve.hpp b/src/solvers/gecode/presolver/presolve.hpp index 0eadcfb6..e855962c 100644 --- a/src/solvers/gecode/presolver/presolve.hpp +++ b/src/solvers/gecode/presolver/presolve.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Noric Couderc * Erik Ekstrom * Mats Carlsson diff --git a/src/solvers/gecode/presolver/presolver-options.cpp b/src/solvers/gecode/presolver/presolver-options.cpp index 9b3afb04..6e71780d 100644 --- a/src/solvers/gecode/presolver/presolver-options.cpp +++ b/src/solvers/gecode/presolver/presolver-options.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -38,6 +38,7 @@ PresolverOptions::PresolverOptions(void) : InstanceOptions("Unison presolver"), _output_file("o", "output file", ""), + _dzn_file("dzn", "dzn file", ""), _timeout("t", "timeout", 30000.0), _verbose("verbose", "verbose mode (false)", false), _regions("regions", "find regions (true)", true), @@ -46,6 +47,7 @@ PresolverOptions::PresolverOptions(void) { add(_output_file); + add(_dzn_file); add(_timeout); add(_verbose); add(_regions); diff --git a/src/solvers/gecode/presolver/presolver-options.hpp b/src/solvers/gecode/presolver/presolver-options.hpp index 2c9932f9..e5551566 100644 --- a/src/solvers/gecode/presolver/presolver-options.hpp +++ b/src/solvers/gecode/presolver/presolver-options.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -47,6 +47,7 @@ class PresolverOptions : public InstanceOptions { // Interface Driver::StringValueOption _output_file; // Output file + Driver::StringValueOption _dzn_file; // .dzn file Driver::DoubleOption _timeout; // Timeout Driver::BoolOption _verbose; // Verbose mode Driver::BoolOption _regions; // Find regions @@ -61,6 +62,7 @@ class PresolverOptions : public InstanceOptions { PresolverOptions(void); string output_file(void) const {return _output_file.value();} + string dzn_file(void) const {return _dzn_file.value();} double timeout(void) const {return _timeout.value();} bool verbose(void) const {return _verbose.value();} bool regions(void) const {return _regions.value();} diff --git a/src/solvers/gecode/presolver/presolver_asserts.hpp b/src/solvers/gecode/presolver/presolver_asserts.hpp index 4b0005f8..9fcf0d96 100644 --- a/src/solvers/gecode/presolver/presolver_asserts.hpp +++ b/src/solvers/gecode/presolver/presolver_asserts.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Erik Ekstrom * * Contributing authors: diff --git a/src/solvers/gecode/presolver/unsafe_temp.cpp b/src/solvers/gecode/presolver/unsafe_temp.cpp index bd5fd214..0385dd93 100644 --- a/src/solvers/gecode/presolver/unsafe_temp.cpp +++ b/src/solvers/gecode/presolver/unsafe_temp.cpp @@ -83,3 +83,128 @@ bool temp_is_unsafe(const Parameters& input, const temporary t) { return false; } +void temp_domain(Parameters& input) { + ModelOptions moptions; + RelaxedModel * base = new RelaxedModel(&input, &moptions, IPL_DOM); + // if CompleteModel: base->post_standalone_constraints(); + assert(base->status() != SS_FAILED); + for (temporary t : input.T) + populate_r_domain(base, t, input.temp_domain[t]); + delete base; +} + +void suppress_copies(Parameters& input, block b, vector& Nogoods) { + int calls = 0; + // collect register classes and their sizes + map C2W; + map C2S; + map> C2Inflated; + map> T2Inflated; + for (operation o : input.ops[b]) { + for (unsigned int ii = 0; ii < input.instructions[o].size(); ii++) { + for (unsigned pi = 0; pi < input.operands[o].size(); pi++) { + operand p = input.operands[o][pi]; + if (input.instructions[o][ii] != NULL_INSTRUCTION) { + register_class rc = input.rclass[o][ii][pi]; + if (!input.infinite[input.space[rc]]) + C2W[rc] = input.operand_width[p]; + } + } + } + } + // compute inflated set of register atoms per class + for (const pair& rcw : C2W) { + register_class rc = rcw.first; + int w = rcw.second; + if (rc > 0) { + vector inflated; + for (register_atom a : input.atoms[rc]) + for (int i=0; i& pp : input.redefined[o]) + if (pp.second==p) + usedef = true; + if (!usedef) { + temporary t = input.temps[p][0]; + int w = input.width[t]; + vector inflated; + for (register_atom a : input.temp_domain[t]) + for (int i=0; i= 0 + for (const pair>& rcInf : C2Inflated) { + register_class rc = rcInf.first; + int cw = C2W[rc]; + for (const pair>& tInf : T2Inflated) { + temporary t = tInf.first; + if(ord_intersect(rcInf.second, tInf.second)) + C2S[rc] -= max(input.width[t], cw); + } + } + // find temporaries subject to copy suppression + for (operation o : input.ops[b]) + if (is_mandatory(input, o)) { + unsigned int nbopnd = input.operands[o].size(); + for(unsigned int i=0; i users = input.users[t]; + operand p_store = users[0]; + operation o_store = input.oper[p_store]; + set RCp; + if (input.temps[p_store][0] == NULL_TEMPORARY && input.type[o_store] == COPY) { + p_finite_register_classes(input, first_def(input, o_store), RCp); + } else { + p_finite_register_classes(input, p, RCp); + } + RCp.erase(0); + for (register_class rc : RCp) + if (C2S[rc] < 0) + goto skip_this_p; + int free = 0, constrained = 0; + for (operand q : users) + if (input.temps[q][0] != NULL_TEMPORARY) { + bool is_constrained = true; + if (input.p_preassign[q] < 0 && input.type[input.oper[q]] != OUT && !ord_contains(input.last_use, q)) { + set RCq; + p_finite_register_classes(input, q, RCq); + RCq.erase(0); + if (RCp.size() <= 1 && RCp == RCq) + is_constrained = false; + } + if (is_constrained) + constrained++; + else + free++; + } + int ub = constrained + min(calls+1,free) + 1; + for (operand q : input.users[t]) + if (input.temps[q][0] == NULL_TEMPORARY && input.type[input.oper[q]] == COPY) + if (--ub < 0) { + UnisonConstraintExpr e(ACTIVE_EXPR, {input.oper[q]}, {}); + presolver_conj conj = {e}; + Nogoods.push_back(conj); + } + } + skip_this_p: ; + } + } +} diff --git a/src/solvers/gecode/presolver/unsafe_temp.hpp b/src/solvers/gecode/presolver/unsafe_temp.hpp index cec12218..754853f7 100644 --- a/src/solvers/gecode/presolver/unsafe_temp.hpp +++ b/src/solvers/gecode/presolver/unsafe_temp.hpp @@ -4,7 +4,7 @@ * * Contributing authors: * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -40,10 +40,14 @@ #include "../common/util.hpp" // min_of, etc... #include "../models/parameters.hpp" +#include "models/globalmodel.hpp" +#include "procedures/presolverprocedures.hpp" #include "auxiliary.hpp" // auxiliary functions as defined in the spec #include #include bool temp_is_unsafe(const Parameters& input, const temporary t); +void temp_domain(Parameters& input); +void suppress_copies(Parameters& input, block b, vector& Nogoods); #endif diff --git a/src/solvers/gecode/procedures/commonprocedures.cpp b/src/solvers/gecode/procedures/commonprocedures.cpp index 99617e34..9bddfb7f 100644 --- a/src/solvers/gecode/procedures/commonprocedures.cpp +++ b/src/solvers/gecode/procedures/commonprocedures.cpp @@ -1,7 +1,7 @@ /* * Main authors: * Mats Carlsson - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -124,6 +124,21 @@ Gecode::SpaceStatus status_lb(GlobalModel * base) { return ss; } +double optimality_gap(GlobalModel * base, const GlobalModel * sol, + unsigned int n) { + int cost_lb; + int max_cost = sol->cost()[n].max(); + if (base->status() == SS_FAILED) { + // If the base space is failed that means we have proven optimality and + // the optimality gap should be 0% + assert(sol->cost()[n].assigned()); + cost_lb = sol->cost()[n].val(); + } else { + cost_lb = base->cost()[n].min(); + } + return ((((double)(max_cost - cost_lb)) / (double)cost_lb) * 100.0); +} + void emit_lower_bound(const GlobalModel * base, bool proven) { if (base->options->lower_bound_file().empty()) return; vector lbs; @@ -136,6 +151,20 @@ void emit_lower_bound(const GlobalModel * base, bool proven) { fout.close(); } +void emit_initial_gap(GlobalModel * base, const GlobalModel * sol) { + if (base->options->initial_gap_file().empty()) return; + vector igs; + for (unsigned int n = 0; n < base->input->N; n++) { + double ig = (base->status() == SS_FAILED) ? + 0.0 : optimality_gap(base, sol, n); + igs.push_back(ig / 100.0); + } + ofstream fout; + fout.open(base->options->initial_gap_file()); + fout << "{\"initial_gap\":" << show(igs, ", ", "", "[]") << "}" << endl; + fout.close(); +} + LocalModel * make_local(const GlobalModel * gs, block b) { return make_local(gs, b, gs->ipl); } @@ -153,230 +182,22 @@ bool infinite_register_atom(Parameters & input, register_atom ra) { return false; } -#if 0 - -vector -value_precede_chains(Parameters & input, Model * m, bool global, block b) { - vector chains; - map,vector>> Ts2Rss; - map> R2Cs; - vector PreT; - vector PreP; - vector B(global ? input.B : vector({b})); - vector T(global ? input.T : input.tmp[b]); - int maxw = 1; - - // find largest relevant width - for (temporary t : T) - maxw = max(input.width[t],maxw); - - // collect register classes and their sizes - map C2W; - for (block b : B) { - for (operation o : input.ops[b]) { - for (unsigned int ii = 0; ii < input.instructions[o].size(); ii++) { - for (unsigned pi = 0; pi < input.operands[o].size(); pi++) { - operand p = input.operands[o][pi]; - if (input.instructions[o][ii] != NULL_INSTRUCTION) { - register_class rc = input.rclass[o][ii][pi]; - C2W[rc] = input.operand_width[p]; - } - } - } - } - } - for(const pair& CW : C2W) { - register_class C = CW.first; - int w = CW.second; - vector ras = input.atoms[C]; - if (!infinite_register_atom(input, max_of(ras))) - for (register_atom r : ras) - for (int d=0; d>> defer; - for(const vector& pr : input.preassign) { - operand p = pr[0]; - register_atom r = pr[1]; - if (global || input.pb[p] == b) { - operation o = input.oper[p]; - temporary t = input.temps[p][0]; - vector us = input.users[t]; - int ty = input.type[o]; - PreP.push_back(p); - if (!input.use[p]) - PreT.push_back(t); - if (!input.use[p] && - us.size() == 1 && - input.type[input.oper[us[0]]] == KILL) { - defer[o].push_back(pr); - } else if (binary_search(input.calleesaved.begin(), input.calleesaved.end(), r) && - (ty == IN || ty == OUT)) { - defer[o].push_back(pr); - } else { - int w = input.operand_width[p]; - for (int d=0; d>>& percall : defer) { - for (const vector& pr : percall.second) { - operand p = pr[0]; - register_atom r = pr[1]; - int w = input.operand_width[p]; - for (int d=0; d& pp : input.redefined[o]) - for (temporary t : input.temps[pp.second]) - if (t != NULL_TEMPORARY) - PreT.push_back(t); - - // prevent (pack) operand temporaries from occurring in symmetry chains - for (block b : B) - for (vector ps : input.bpacked[b]) - for (operand p : ps) - for (temporary t : input.temps[p]) - if (t != NULL_TEMPORARY) - PreT.push_back(t); - - // prevent ext. related operand temporaries from occurring in symmetry chains - for (vector ps : input.exrelated) - for (operand p : ps) - for (temporary t : input.temps[p]) - if (t != NULL_TEMPORARY) - PreT.push_back(t); - - // FIXME: this check is added temporarily, needs investigation - // prevent temps defined by callee-saved-load from occurring in symmetry chains - for (operation o : input.callee_saved_loads) - if (global || input.oblock[o]==b) - for (operand p : input.operands[o]) - if (!input.use[p]) - PreT.push_back(input.single_temp[p]); - - sort(PreT.begin(), PreT.end()); // will search - sort(PreP.begin(), PreP.end()); // will search - - // more register classes from fixed (in), (out), except preassigned - if (!global) { - operation inop = input.ops[b][0]; - operation outop = max_of(input.ops[b]); - for (operand p : input.operands[inop]) { - if (!m->ry(p).assigned()) - return chains; - } - for (operand p : input.operands[outop]) { - if (!m->ry(p).assigned()) - return chains; - } - for (operand p : input.operands[inop]) { - if (!infinite_register_atom(input, m->ry(p).val()) && - !binary_search(PreP.begin(), PreP.end(), p)) { - int w = input.operand_width[p]; - for (int d=0; dry(p).val()+d].push_back(C); - C++; - } - } - for (operand p : input.operands[outop]) { - if (!infinite_register_atom(input, m->ry(p).val()) && - !binary_search(PreP.begin(), PreP.end(), p)) { - int w = input.operand_width[p]; - for (int d=0; dry(p).val()+d].push_back(C); - C++; - } - } - } - - for (int curw = 1; curw <= maxw; curw = 2*curw) { - // merge unaligned (wrt. curw) R2Cs items into aligned ones - vector odd; - for(const pair>& RCs : R2Cs) - if (RCs.first % curw > 0) - odd.push_back(RCs.first); - for(register_atom a : odd) { - register_atom e = a - (a % curw); - vector U; - set_union(R2Cs[e].begin(), R2Cs[e].end(), R2Cs[a].begin(), R2Cs[a].end(), back_inserter(U)); - R2Cs[e] = U; - R2Cs.erase(a); - } - - map,vector> Cs2Rs; - - // regroup by set of register class - for(const pair>& RCs : R2Cs) - Cs2Rs[RCs.second].push_back(RCs.first); - - // build the chains - for(const pair,vector>& CsRs : Cs2Rs) { - vector Cs = CsRs.first; - vector Rs = CsRs.second; - if ((int)Rs.size()>1) { - vector Ts; - for(temporary t : T) { - int ty = input.type[input.def_opr[t]]; - if (input.width[t]==curw && - (ty == LINEAR || ty == COPY) && - !binary_search(PreT.begin(), PreT.end(), t)) { - operand p = input.definer[t]; - operation o = input.oper[p]; - unsigned pi = p - input.operands[o][0]; - for (unsigned int ii = 0; ii < input.instructions[o].size(); ii++) { - register_class rc = input.rclass[o][ii][pi]; - if (binary_search(Cs.begin(), Cs.end(), rc)) { - Ts.push_back(t); - goto nextt; - } - } - } - nextt: ; - } - if (!Ts.empty()) - Ts2Rss[Ts].push_back(Rs); - } - } - } - - for(const pair,vector>>& TsRs : Ts2Rss) { - PresolverValuePrecedeChain vpc; - vpc.ts = TsRs.first; - vpc.rss = TsRs.second; - sort(vpc.rss.begin(), vpc.rss.end()); // canonicalize - chains.push_back(vpc); - } - return chains; -} - -#else - -// Idea: values v[1],...,v[n] are symmetric if: -// - they can be taken by the same set of classes -// - no _other_ class take a value that _conflicts_ with any of v[1],...,v[n-1] +// Idea: values v1, v2 are symmetric iff they are _covered_ by identical sets of register classes + preassignments +// Value v is covered by register class rc of width w iff (e <= v < e+w) where e is in rc +// Value v is preassignment p:ra of width w iff (ra <= v < ra+w) +// Preassigned (kill) operands and pressigned callee-saved (in)/(out) operands are clumped per operation +// All other preassignments are counted individually +// Temps defined preassigned are not subject to symmetry breaking +// Temps defined by reassignment, in (pack), or in exrelated operands, are not subject to symmetry breaking +// Temps defined by callee-saved-load are not subject to symmetry breaking, maybe because they get reloaded in reverse order +// Temps not defined by (linear) or (copy) are not subject to symmetry breaking vector value_precede_chains(Parameters & input, Model * m, bool global, block b) { vector chains; map,vector>> SymChainsOfTemps; - map> InClassesOfReg; map> CoveringClassesOfReg; - vector PreT; - vector PreP; + set PreT; + set PreP; vector B(global ? input.B : vector({b})); vector T(global ? input.T : input.tmp[b]); @@ -400,11 +221,9 @@ value_precede_chains(Parameters & input, Model * m, bool global, block b) { int w = CW.second; vector ras = input.atoms[C]; if (!infinite_register_atom(input, max_of(ras))) - for (register_atom r : ras) { - InClassesOfReg[r].push_back(C); + for (register_atom r : ras) for (int d=0; d us = input.users[t]; operation o = input.oper[p]; int ty = input.type[o]; - PreP.push_back(p); + PreP.insert(p); if (!input.use[p]) - PreT.push_back(t); + PreT.insert(t); if (!input.use[p] && us.size() == 1 && input.type[input.oper[us[0]]] == KILL) { @@ -432,7 +251,6 @@ value_precede_chains(Parameters & input, Model * m, bool global, block b) { } else { int w = input.operand_width[p]; C2W[C] = w; - InClassesOfReg[r].push_back(C); for (int d=0; d& pp : input.redefined[o]) for (temporary t : input.temps[pp.second]) if (t != NULL_TEMPORARY) - PreT.push_back(t); + PreT.insert(t); // prevent (pack) operand temporaries from occurring in symmetry chains for (block b : B) @@ -470,14 +287,14 @@ value_precede_chains(Parameters & input, Model * m, bool global, block b) { for (operand p : ps) for (temporary t : input.temps[p]) if (t != NULL_TEMPORARY) - PreT.push_back(t); + PreT.insert(t); // prevent ext. related operand temporaries from occurring in symmetry chains for (vector ps : input.exrelated) for (operand p : ps) for (temporary t : input.temps[p]) if (t != NULL_TEMPORARY) - PreT.push_back(t); + PreT.insert(t); // FIXME: this check is added temporarily, needs investigation // prevent temps defined by callee-saved-load from occurring in symmetry chains @@ -485,10 +302,7 @@ value_precede_chains(Parameters & input, Model * m, bool global, block b) { if (global || input.oblock[o]==b) for (operand p : input.operands[o]) if (!input.use[p]) - PreT.push_back(input.single_temp[p]); - - sort(PreT.begin(), PreT.end()); // will search - sort(PreP.begin(), PreP.end()); // will search + PreT.insert(input.single_temp[p]); // more register classes from fixed (in), (out), except preassigned if (!global) { @@ -505,11 +319,9 @@ value_precede_chains(Parameters & input, Model * m, bool global, block b) { for (operand p : input.operands[inop]) { int r = m->ry(p).val(); if (r >= 0 && - !infinite_register_atom(input, m->ry(p).val()) && - !binary_search(PreP.begin(), PreP.end(), p)) { + !infinite_register_atom(input, m->ry(p).val()) && !PreP.count(p)) { int w = input.operand_width[p]; C2W[C] = w; - InClassesOfReg[r].push_back(C); for (int d=0; dry(p).val(); if (r >= 0 && - !infinite_register_atom(input, m->ry(p).val()) && - !binary_search(PreP.begin(), PreP.end(), p)) { + !infinite_register_atom(input, m->ry(p).val()) && !PreP.count(p)) { int w = input.operand_width[p]; C2W[C] = w; - InClassesOfReg[r].push_back(C); for (int d=0; d,vector> RegsOfClasses; - - // for(const pair>& RCs : InClassesOfReg) - // cerr << "InClassesOfReg[" << RCs.first << "] = " << show(RCs.second) << endl; - // for(const pair>& RCs : CoveringClassesOfReg) - // cerr << "CoveringClassesOfReg[" << RCs.first << "] = " << show(RCs.second) << endl; - // regroup by set of register class - for(const pair>& RCs : InClassesOfReg) + // regroup by set of covering register class + for(const pair>& RCs : CoveringClassesOfReg) RegsOfClasses[RCs.second].push_back(RCs.first); // build the chains for(const pair,vector>& CsRs : RegsOfClasses) { - int w = 0; vector Cs = CsRs.first; vector Rs = CsRs.second; - vector Rs2; - for (register_class C : Cs) - w = max(w,C2W[C]); - for (unsigned int ii = 0; ii < Rs.size(); ii++) - if (ii==Rs.size()-1 || no_conflict(Rs[ii], Cs, w, CoveringClassesOfReg)) - Rs2.push_back(Rs[ii]); - if ((int)Rs2.size()>1) { + if ((int)Rs.size()>1) { vector Ts; for(temporary t : T) { int ty = input.type[input.def_opr[t]]; - if ((ty == LINEAR || ty == COPY) && - !binary_search(PreT.begin(), PreT.end(), t)) { + if ((ty == LINEAR || ty == COPY) && !PreT.count(t)) { operand p = input.definer[t]; operation o = input.oper[p]; unsigned pi = p - input.operands[o][0]; @@ -572,30 +369,35 @@ value_precede_chains(Parameters & input, Model * m, bool global, block b) { nextt: ; } if (!Ts.empty()) - SymChainsOfTemps[Ts].push_back(Rs2); + SymChainsOfTemps[Ts].push_back(Rs); } } for(const pair,vector>>& TsRs : SymChainsOfTemps) { PresolverValuePrecedeChain vpc; - vpc.ts = TsRs.first; - vpc.rss = TsRs.second; - sort(vpc.rss.begin(), vpc.rss.end()); // canonicalize - // cerr << "SYMMETRY " << show(vpc) << endl; - chains.push_back(vpc); + map> w2ts; + vector ts; + int minwidth = 1; + for (temporary t : TsRs.first) // sort temps by decreasing width + w2ts[-input.width[t]].push_back(t); + for (auto wts : w2ts) { + ts.insert(ts.end(), wts.second.begin(), wts.second.end()); + minwidth = -wts.first; + } + for (auto ras1 : TsRs.second) { + vector ras2; + for (register_atom a : ras1) + if ((a % minwidth) == 0) + ras2.push_back(a); + if (ras2.size()>1) + vpc.rss.push_back(ras2); + } + if (!vpc.rss.empty()) { + sort(vpc.rss.begin(), vpc.rss.end()); // canonicalize + vpc.ts = ts; + // cerr << "SYMMETRY " << show(vpc) << endl; + chains.push_back(vpc); + } } return chains; } - -bool -no_conflict(register_atom a, - vector Cs, - int w, - map> CoveringClassesOfReg) { - for (register_atom b = a; b < a+w; b++) - if (!subseteq(CoveringClassesOfReg[b],Cs)) - return false; - return true; -} - -#endif diff --git a/src/solvers/gecode/procedures/commonprocedures.hpp b/src/solvers/gecode/procedures/commonprocedures.hpp index 985b436a..3b76bce8 100644 --- a/src/solvers/gecode/procedures/commonprocedures.hpp +++ b/src/solvers/gecode/procedures/commonprocedures.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Mats Carlsson @@ -120,9 +120,16 @@ vector shave_instructions( // Propagates, possibly emits the lower bound, and returns the status Gecode::SpaceStatus status_lb(GlobalModel * base); +// Gives the optimality gap from a base space, a solution, and a goal index n +double optimality_gap(GlobalModel * base, const GlobalModel * sol, + unsigned int n); + // Emits the lower bound to a file (if specified by the options) void emit_lower_bound(const GlobalModel * base, bool proven = false); +// Emits the initial optimality gap to a file (if specified by the options) +void emit_initial_gap(GlobalModel * base, const GlobalModel * sol); + // Makes a new local space out of a global one LocalModel * make_local(const GlobalModel * gs, block b); LocalModel * make_local(const GlobalModel * gs, block b, IntPropLevel p_ipl); diff --git a/src/solvers/gecode/procedures/globalprocedures.cpp b/src/solvers/gecode/procedures/globalprocedures.cpp index ffd8f5f2..26612330 100644 --- a/src/solvers/gecode/procedures/globalprocedures.cpp +++ b/src/solvers/gecode/procedures/globalprocedures.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/procedures/globalprocedures.hpp b/src/solvers/gecode/procedures/globalprocedures.hpp index 8948107e..b536d5bb 100644 --- a/src/solvers/gecode/procedures/globalprocedures.hpp +++ b/src/solvers/gecode/procedures/globalprocedures.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/procedures/localprocedures.cpp b/src/solvers/gecode/procedures/localprocedures.cpp index 352ece6d..2d78686d 100644 --- a/src/solvers/gecode/procedures/localprocedures.cpp +++ b/src/solvers/gecode/procedures/localprocedures.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/procedures/localprocedures.hpp b/src/solvers/gecode/procedures/localprocedures.hpp index 3ad5f137..cc466fa0 100644 --- a/src/solvers/gecode/procedures/localprocedures.hpp +++ b/src/solvers/gecode/procedures/localprocedures.hpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * diff --git a/src/solvers/gecode/procedures/presolverprocedures.cpp b/src/solvers/gecode/procedures/presolverprocedures.cpp index 4e997e55..1830bdc6 100644 --- a/src/solvers/gecode/procedures/presolverprocedures.cpp +++ b/src/solvers/gecode/procedures/presolverprocedures.cpp @@ -1,7 +1,7 @@ /* * Main authors: * Mikael Almgren - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * Mats Carlsson * * This file is part of Unison, see http://unison-code.github.io @@ -35,28 +35,6 @@ #include "presolverprocedures.hpp" -#if 0 -// Return if e is member in V. -bool member(const std::vector& V, int e); - -template bool member(const std::vector& V, const T& e){ - for(T v : V) { - if(v == e) return true; - } - return false; -} - -// Inserts e into v, if not already in v. -// v is a set stored in a vector -template -void vector_insert(std::vector& v, const T& e){ - typename std::vector::iterator it = std::lower_bound(v.begin(), v.end(), e); - if(it == v.end() || e < *it){ - v.insert(it, e); - } -} -#endif - TmpTableResult get_labelings(Parameters& input, RelaxedModel * base, vector O, vector P, int timeout) { @@ -70,8 +48,8 @@ TmpTableResult get_labelings(Parameters& input, RelaxedModel * base, opt.stop = relaxedStop; RelaxedModel * r_base = (RelaxedModel *) base->clone(); - r_base->post_active_operation_branching(O); r_base->post_operand_temporary_branching(P); + r_base->post_active_operation_branching(O); DFS e(r_base, opt); @@ -211,3 +189,9 @@ void disconnect_operand(Parameters& input, operand p) { // TODO: update 'dist' } } + +void populate_r_domain(Model * m, temporary t, vector& domain) { + domain.clear(); + for (IntVarValues rr(m->r(t)); rr(); ++rr) + domain.push_back(rr.val()); +} diff --git a/src/solvers/gecode/procedures/presolverprocedures.hpp b/src/solvers/gecode/procedures/presolverprocedures.hpp index 22a925c3..650c8a8e 100644 --- a/src/solvers/gecode/procedures/presolverprocedures.hpp +++ b/src/solvers/gecode/procedures/presolverprocedures.hpp @@ -1,7 +1,7 @@ /* * Main authors: * Mikael Almgren - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * This file is part of Unison, see http://unison-code.github.io * @@ -88,4 +88,6 @@ bool propagate(Parameters& input); // Updates the parameters according to the constraint model to reflect that the given operand is disconnected. void disconnect_operand(Parameters& input, operand p); +void populate_r_domain(Model * m, temporary t, vector& domain); + #endif diff --git a/src/solvers/gecode/solver.cpp b/src/solvers/gecode/solver.cpp index 0d8c98e7..e038ae29 100644 --- a/src/solvers/gecode/solver.cpp +++ b/src/solvers/gecode/solver.cpp @@ -1,6 +1,6 @@ /* * Main authors: - * Roberto Castaneda Lozano + * Roberto Castaneda Lozano * * Contributing authors: * Gabriel Hjort Blindell @@ -43,7 +43,6 @@ #ifdef GRAPHICS #include -#include #endif #include @@ -63,10 +62,8 @@ #include "procedures/globalprocedures.hpp" #include "procedures/localprocedures.hpp" -#ifndef GRAPHICS #include "third-party/jsoncpp/json/value.h" #include "third-party/jsoncpp/json/reader.h" -#endif #ifdef GRAPHICS #include "inspectors/registerarrayinspector.hpp" @@ -281,21 +278,6 @@ void emit_local(LocalModel * local, unsigned long int iteration, string prefix) fout.close(); } -double optimality_gap(GlobalModel * base, const GlobalModel * sol, - unsigned int n) { - int cost_lb; - int max_cost = sol->cost()[n].max(); - if (base->status() == SS_FAILED) { - // If the base space is failed that means we have proven optimality and - // the optimality gap should be 0% - assert(sol->cost()[n].assigned()); - cost_lb = sol->cost()[n].val(); - } else { - cost_lb = base->cost()[n].min(); - } - return ((((double)(max_cost - cost_lb)) / (double)cost_lb) * 100.0); -} - string unsat_report(const GlobalModel * base) { stringstream ss; ss << "proven absence of solutions with cost less or equal than " @@ -441,10 +423,6 @@ int main(int argc, char* argv[]) { exit(EXIT_FAILURE); } -#ifdef GRAPHICS - QApplication *app = new QApplication(argc, argv, false); -#endif - string name(options.instance()); string prefix = name.substr(0,name.find(".json")) .substr(0,name.find(".ext")); @@ -452,10 +430,6 @@ int main(int argc, char* argv[]) { fin.open(name.c_str(), ios::in); if (fin.fail()) { cerr << "Failed to open " << name << ": " << strerror(errno) << endl; -#ifdef GRAPHICS - cerr << "Working directory: " - << QDir::currentPath().toStdString() << endl; -#endif exit(EXIT_FAILURE); } string json_input ((std::istreambuf_iterator(fin)), @@ -466,25 +440,6 @@ int main(int argc, char* argv[]) { exit(EXIT_FAILURE); } -#ifdef GRAPHICS - QScriptValue root; - QScriptEngine engine; - root = engine.evaluate("(" + QString::fromStdString(json_input) + ")"); - if (engine.hasUncaughtException()) { - QScriptValue val = engine.uncaughtException(); - if (val.isError()) { - cerr << "Failed to parse " << name << ": " - << val.toString().toStdString() << " at line " - << engine.uncaughtExceptionLineNumber() << endl - << "Backtrace: " - << engine.uncaughtExceptionBacktrace().join("\n").toStdString() - << endl; - } - exit(EXIT_FAILURE); - } - app->exit(); - delete app; -#else Json::Value root; Json::CharReaderBuilder reader; std::stringstream json_input_stream; @@ -494,24 +449,14 @@ int main(int argc, char* argv[]) { cerr << "Failed to parse " << name << endl << errs; exit(EXIT_FAILURE); } -#endif Parameters input(root); bool single_block = input.B.size() == 1; int presolver_time = 0; -#ifdef GRAPHICS - { - QScriptValue property = root.property("presolver_time"); - if (property.isValid()) { - presolver_time = property.toInt32(); - } - } -#else if (root.isMember("presolver_time")) { presolver_time = root["presolver_time"].asInt(); } -#endif GIST_OPTIONS * go = new GIST_OPTIONS(), * lo = new GIST_OPTIONS(); @@ -665,6 +610,10 @@ int main(int argc, char* argv[]) { // Post cost upper bound base->post_upper_bound(input.maxf); Gecode::SpaceStatus ss1 = status_lb(base); + + // Emit initial optimality gap + emit_initial_gap(base, base); + if (ss1 == SS_FAILED) { // The problem has no solution double execution_time = t.stop(); if (options.verbose()) { diff --git a/src/solvers/gecode/solver.mk b/src/solvers/gecode/solver.mk index 068a681c..fc4b09d5 100644 --- a/src/solvers/gecode/solver.mk +++ b/src/solvers/gecode/solver.mk @@ -1,6 +1,6 @@ # # Main authors: -# Roberto Castaneda Lozano +# Roberto Castaneda Lozano # # This file is part of Unison, see http://unison-code.github.io # diff --git a/src/solvers/gecode/solver.pro b/src/solvers/gecode/solver.pro index 56a1a190..5e502c06 100644 --- a/src/solvers/gecode/solver.pro +++ b/src/solvers/gecode/solver.pro @@ -1,6 +1,6 @@ # # Main authors: -# Roberto Castaneda Lozano +# Roberto Castaneda Lozano # # This file is part of Unison, see http://unison-code.github.io # @@ -99,12 +99,13 @@ LIBS += -lgecodesearch -lgecodeminimodel -lgecodeset -lgecodefloat -lgecodeint \ TARGET = gecode-solver CONFIG -= qt CONFIG += warn_on -QT += script CONFIG(graphics) { CONFIG += qt + QT += widgets + DEFINES += GRAPHICS NEWGV HEADERS += inspectors/consoleinspector.hpp \ diff --git a/src/solvers/gecode/third-party/jsoncpp/json_reader.cpp b/src/solvers/gecode/third-party/jsoncpp/json_reader.cpp index 06968fd6..739d85ec 100644 --- a/src/solvers/gecode/third-party/jsoncpp/json_reader.cpp +++ b/src/solvers/gecode/third-party/jsoncpp/json_reader.cpp @@ -1238,6 +1238,7 @@ bool OurReader::readToken(Token& token) { ok = readStringSingleQuote(); break; } // else continue + // fall through case '/': token.type_ = tokenComment; ok = readComment(); diff --git a/src/solvers/multi_backend/common/outfilter.pl b/src/solvers/multi_backend/common/outfilter.pl index 2e872f45..20af7a18 100755 --- a/src/solvers/multi_backend/common/outfilter.pl +++ b/src/solvers/multi_backend/common/outfilter.pl @@ -4,7 +4,7 @@ # Mats Carlsson # # Contributing authors: -# Roberto Castaneda Lozano +# Roberto Castaneda Lozano # # This file is part of Unison, see http://unison-code.github.io # diff --git a/src/solvers/multi_backend/minizinc/code-generation-twophase.mzn b/src/solvers/multi_backend/minizinc/code-generation-twophase.mzn new file mode 100644 index 00000000..77c3901b --- /dev/null +++ b/src/solvers/multi_backend/minizinc/code-generation-twophase.mzn @@ -0,0 +1,1449 @@ +% +% Main authors: +% Mats Carlsson +% +% This file is part of Unison, see http://unison-code.github.io +% +% Copyright (c) 2016, RISE SICS AB +% All rights reserved. +% +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: +% 1. Redistributions of source code must retain the above copyright notice, +% this list of conditions and the following disclaimer. +% 2. Redistributions in binary form must reproduce the above copyright notice, +% this list of conditions and the following disclaimer in the documentation +% and/or other materials provided with the distribution. +% 3. Neither the name of the copyright holder nor the names of its contributors +% may be used to endorse or promote products derived from this software +% without specific prior written permission. +% +% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +% POSSIBILITY OF SUCH DAMAGE. + +include "globals.mzn"; + +%% solver parameters + +bool: good_cumulative; +bool: good_diffn; +bool: good_member; +bool: optimize_cycles; + +% 1 - register allocation, 2 - instruction scheduling +1..2: phase; + +%% some constants +%% N.B. keep in sync with modeler! see also isreal()! + +int: TYPE_LINEAR = 0; +int: TYPE_BRANCH = 1; +int: TYPE_CALL = 2; +int: TYPE_TAIL = 3; +int: TYPE_IN = 4; +int: TYPE_OUT = 5; +int: TYPE_KILL = 6; +int: TYPE_DEFINE = 7; +int: TYPE_COMBINE = 8; +int: TYPE_LOW = 9; +int: TYPE_HIGH = 10; +int: TYPE_SPLIT2 = 11; +int: TYPE_SPLIT4 = 12; +int: TYPE_FUN = 13; +int: TYPE_COPY = 14; + +%% problem parameters + +int: MAXF; +int: MAXO; +int: MAXP; +int: MAXT; +int: MAXC; +int: MAXI; +int: MAXR; +int: MAXB = max(index_set(bb_ops)); +int: MINL; +int: MAXL; +int: MAXINSNS = max(o in 0..MAXO)(card(op_instructions[o])); +int: MAXTEMPS = max(p in 0..MAXP)(card(operand_temps[p])); + +set of int: expr = index_set(expr_op); + +%% see JSON freq, maxc, ins, tmp, operands, optional_min +array[int] of int: bb_order; +array[int] of set of int: bb_ops; +array[int] of set of int: bb_operands; +array[int] of set of int: bb_temps; +array[int] of set of int: bb_subsumed; +array[int] of int: bb_frequency; +array[int] of int: bb_maxcycle; +array[int] of int: bb_optional_min; + +%% see JSON operands, instructions, type +array[int] of set of int: op_operands; +array[int] of set of int: op_instructions; +array[int] of int: op_type; +array[int] of bool: op_mand; + +%% see JSON atoms +array[int] of set of int: atom_regs; % atom -> registers + +%% see JSON calleesaved, callersaved, infinite, bounded, range +set of int: calleesaved; +set of int: callersaved; +set of int: infinite; +array[int] of bool: bounded; +array[int] of set of int: range; + +%% see JSON cap, con, dur, off +array[int] of int: res_cap; +array[int,int] of int: res_con; +array[int,int] of int: res_dur; +array[int,int] of int: res_off; + +%% see JSON congr +array[int] of set of int: congr; + +%% see JSON strictly_congr +array[int] of set of int: strictly_congr; + +%% see JSON preassign +array[int] of int: preassign_operand; +array[int] of int: preassign_reg; + +%% see JSON aligned/adist +array[int] of int: aligned_use; +array[int] of int: aligned_def; +array[int] of int: aligned_usei; +array[int] of int: aligned_defi; +array[int] of int: aligned_dist; + +%% see JSON adjacent +array[int] of int: adj_from; +array[int] of int: adj_to; + +%% see JSON quasi_adjacent +array[int] of int: quasi_adj_from; +array[int] of int: quasi_adj_to; + +%% see JSON long_latency +array[int,int] of set of int: long_latency_index; +array[int] of int: long_latency_def; +array[int] of int: long_latency_use; + +%% see JSON operands +array[int] of int: operand_definer; % operand -> defining op + +%% see JSON use +array[int] of bool: operand_use; + +%% see JSON last_use +array[int] of bool: operand_lastuse; + +%% see JSON temps +array[int] of set of int: operand_temps; + +%% see JSON class, operands, instructions +array[int,int] of int: operand_atom; % operand x operation -> atom + +%% see JSON temps +array[int] of set of int: related_temps; + +%% see JSON definer, temps, width, minlive +array[int] of int: temp_definer; % temp -> defining op +array[int] of int: temp_def; % temp -> defining operand +array[int] of int: temp_width; % temp -> width +array[int] of int: temp_minlive; % temp -> minlive +array[int] of set of int: temp_uses; % temp -> set of use operands +array[int] of set of int: temp_domain; % temp -> domain of regs + +%% see JSON packed, pinstrs +array[int,int] of int: packed_pq; + +%% see JSON before +array[int] of int: before_pred; +array[int] of int: before_succ; +array[int] of expr: before_cond; + +%% see JSON E +array[int] of int: adhoc; + +%% see JSON nogoods +array[int] of expr: nogood; + +%% see JSON across +array[int] of int: across_op; +array[int] of set of int: across_regs; +array[int] of set of int: across_items; +array[int] of int: across_item_temp; +array[int] of expr: across_item_cond; + +%% see JSON set_across +array[int] of int: setacross_op; +array[int] of set of int: setacross_regs; +array[int] of set of int: setacross_tempsets; + +%% see JSON difftemps +array[int] of set of int: difftemp; + +%% see JSON diffregs +array[int] of set of int: diffreg; + +%% see JSON domops +array[int] of set of int: domop_operands; +array[int] of set of int: domop_temps; + +%% see JSON domuse +array[int] of int: domuse_p; +array[int] of int: domuse_q; +array[int] of int: domuse_r; + +%% see JSON infassign +array[int,int] of int: infassign; + +%% see JSON space +array[int] of int: space; + +%% see JSON dominates +array[int] of int: dominate_ing; +array[int] of int: dominate_ed; +array[int] of set of int: dominate_instructions; +array[int] of set of int: dominate_temps; + +%% see JSON precedences +array[int] of expr: precedence; + +%% see JSON active_tables, tmp_tables +array[int] of set of int: table_exists_ops; +array[int] of set of int: table_iffall_ops; +array[int] of set of int: relation_ops; +array[int] of set of int: relation_temps; +array[int] of int: relation_ntuples; +array[int] of set of int: relation_range; + +%% see JSON calleesaved_spill +array[int] of set of int: calleesaved_spill; +array[int,int] of int: cs_spill_transpose; + +%% see JSON activators +array[int] of set of int: activator_insns; +array[int] of set of int: activator_ops; + +%% see JSON value_precede_chain +array[int] of int: value_precede_min; +array[int] of int: value_precede_max; +array[int] of set of int: value_precede_regs; +array[int] of int: value_precede_temps; + +%% see JSON lat +array[int,int] of int: lat_table; + +%% see JSON preschedule +array[int] of int: preschedule_op; +array[int] of int: preschedule_cycle; + +%% see JSON bypass +array[int,int] of int: bypass_table; + +%% see JSON exrelated, table +array[int] of int: exrelated_p; +array[int] of int: exrelated_q; +array[int] of set of int: exrelated_rows; +array[int,int] of int: exrelated_ext; + +%% see JSON wcet +array[int,int] of int: wcet; + +%% extra storage for constraint expressions +array[int] of int: expr_op; +array[int] of int: expr_arg1; +array[int] of int: expr_arg2; +array[int] of int: expr_arg3; +array[int] of set of int: expr_children; + +%% extra store for relations in table constraints +array[int] of int: ints; + +%% extra storage: each set is a set of temporaries +array[int] of set of int: sets; + +%% problem variables + +var 0..MAXF: obj; +array[0..MAXO] of var bool: a; +array[0..MAXO] of var 1..MAXINSNS: ii; % same as in gecode-solver +array[0..MAXO] of var -1..MAXC: c; +array[0..MAXP] of var -1..MAXR: rt; +array[0..MAXP] of var MINL..MAXL: lt; % operand latency +array[0..MAXP] of var -MAXL..MAXL: s; % global operand slack +array[0..MAXP] of var 1..MAXTEMPS: y; % same as in gecode-solver +array[-1..MAXT] of var -1..MAXR: r; +array[-1..MAXT] of var -1..MAXC: ls; +array[-1..MAXT] of var 0..MAXC: ld; +array[-1..MAXT] of var -1..MAXC: le; +array[1..MAXB] of var 0..MAXC: copysum; + +%% input for instruction schedling phase + +array[int] of 0..MAXINSNS: ii_soln; +array[int] of -1..MAXR: rt_soln; +array[int] of 1..MAXTEMPS: y_soln; +array[int] of -1..MAXR: r_soln; + +%% PREDICATES AND TESTS + +test isreal(int: o) = (op_type[o] in + {TYPE_LINEAR, TYPE_BRANCH, TYPE_CALL, TYPE_TAIL, TYPE_FUN, TYPE_COPY}); + +test fixedop(int: o) = ( + op_instructions[o] != {0} /\ card(op_instructions[o]) = 1 +); + +test all_equal_ints(array[int] of int: x) = + forall(i, j in index_set(x) where i < j) ( x[i] = x[j] ); + +var int: res_con_of_op(int: res, int: o) = + let {array[int] of int: I = op_instructions[o]} in + let {array[int] of int: ints = [res_con[res,I[i]] | i in index_set(I)]} in + if all_equal_ints(ints) then ints[1] else ints[ii[o]] endif; + +var int: res_dur_of_op(int: res, int: o) = + let {array[int] of int: I = op_instructions[o]} in + let {array[int] of int: ints = [res_dur[res,I[i]] | i in index_set(I)]} in + if all_equal_ints(ints) then ints[1] else ints[ii[o]] endif; + +var int: res_off_of_op(int: res, int: o) = + let {array[int] of int: I = op_instructions[o]} in + let {array[int] of int: ints = [res_off[res,I[i]] | i in index_set(I)]} in + if all_equal_ints(ints) then ints[1] else ints[ii[o]] endif; + +predicate insn_eq(int: o, int: x) = + let {array[int] of int: I = op_instructions[o]} in + exists(j in index_set(I) where I[j]=x)(ii[o]=j); + +predicate insn_in(int: o, set of int: X) = + if card(X)=0 then + false + else if card(X)=1 then + insn_eq(o, min(X)) + else + let {array[int] of int: I = op_instructions[o]} in + ii[o] in {j | j in index_set(I) where I[j] in X} + endif endif; + +predicate smart_alldiff(array[int] of var int: X) = + if length(X)<2 then + true + else if length(X)=2 then + let {set of int: S = index_set(X)} in + X[min(S)] != X[max(S)] + else + all_different(X) + endif endif; + +predicate ra_diffn_cumu(array[int] of var int: R, + array[int] of int: W, + array[int] of set of int: D, + array[int] of var int: LS, + array[int] of var int: LD, + int: v) = + let {set of int: J = {i | i in index_set(R) where card(D[i] intersect max(0,v-W[i]+1)..v)>0}} + in cumulative([LS[i] | i in J], [LD[i] | i in J], + [if W[i]=1 then R[i]=v else R[i] in max(0,v-W[i]+1)..v endif | i in J], + 1); + +predicate ra_diffn(array[int] of var int: R, + array[int] of int: W, + array[int] of set of int: D, + array[int] of var int: LS, + array[int] of var int: LD, + array[int] of var int: LE) = + if good_cumulative then % [MC] infinite ranges are clash free by construction + let {set of int: atoms = array_union(D)} + in forall(v in atoms intersect (0..min(infinite)-1))( + ra_diffn_cumu(R, W, D, LS, LD, v) + ) /\ + forall(j in index_set(bounded), v in atoms intersect range[j] where bounded[j])( + ra_diffn_cumu(R, W, D, LS, LD, v) + ) + else if good_diffn then + diffn_nonstrict(R, LS, W, LD) + else + forall(i,j in index_set(R) where i < j)( + LD[i] = 0 \/ LD[j] = 0 \/ + R[i] + W[i] <= R[j] \/ LE[i] <= LS[j] \/ + R[j] + W[j] <= R[i] \/ LE[j] <= LS[i] + ) + endif endif ; + +predicate disjoint1(array[int] of var int: x, + array[int] of var int: w) = + diffn(x, [1 | i in index_set(x)], w, [1 | i in index_set(x)]) ; + +predicate noverlap(array[int] of var int: x, + array[int] of var int: w) = ( + if min([lb(z) | z in w]) < max([ub(z) | z in w]) then + disjoint1(x, w) + else if length(x) = 2 then + x[1] != x[2] + else + smart_alldiff(x) + endif endif + ); + +predicate live_overlap(int: k, int: j) = (ls[k] < le[j] /\ ls[j] < le[k]); + +predicate operand_live_overlap(int: p, int: q) = (ls_t(p) < le_t(q) /\ ls_t(q) < le_t(p)); + +predicate operand_live_before(int: p, int: q) = (le_t(p) <= ls_t(q)); + +test operand_related(int: p, int: q) = + operand_temps[p] subset operand_temps[q] \/ operand_temps[q] subset operand_temps[p]; + +predicate same_temp(int: p, int: q) = + assert(operand_related(p,q), "same_temp[\(p),\(q)] with unrelated operands") /\ + y[p] = y[q]; + % let {array[int] of int: ts = operand_temps[p] intersect operand_temps[q]} in + % exists(t in ts)(temp_eq(p,t) /\ temp_eq(q,t)); + +predicate temp_eq(int: p, int: t) = + let {array[int] of int: ts = operand_temps[p]} in + exists(j in index_set(ts) where ts[j]=t)(y[p]=j); + +predicate temp_in(int: p, set of int: T) = + if card(T)=0 then + false + else if card(T)=1 then + temp_eq(p, min(T)) + else + let {array[int] of int: ts = operand_temps[p]} in + y[p] in {j | j in index_set(ts) where ts[j] in T} + endif endif; + +test temp_is_unsafe(int: t) = + if op_type[temp_definer[t]] in {TYPE_IN,TYPE_DEFINE,TYPE_FUN} then + false + else + let {array[int] of int: dlats = [lat_table[j,4] | j in index_set_1of2(lat_table) + where + lat_table[j,2] != 0 /\ + lat_table[j,3] = temp_def[t] + ], + array[int] of int: ulats = [lat_table[j,4] | j in index_set_1of2(lat_table) + where + lat_table[j,2] != 0 /\ + lat_table[j,3] in temp_uses[t] + ]} in + temp_minlive[t] > min(dlats) + min(ulats) + endif; + +test temp_must_be_real(int: p) = + min(operand_temps[p])>=0; + +predicate temp_is_real(int: p) = + if min(operand_temps[p])>=0 then + true + else + y[p]!=1 + endif; + +predicate temp_is_real_reif(int: p, var bool: re) = + if min(operand_temps[p])>=0 then + re + else + re <-> y[p]!=1 + endif; + +predicate insn_is_real_reif(int: o, var bool: re) = + if min(op_instructions[o])>=1 then + re + else + re <-> ii[o]!=1 + endif; + +predicate temp_member_reif(set of int: P, int: t, var bool: re) = + (re <-> exists(p in P)(temp_eq(p,t))); + +var int: t(int: p) = + if card(operand_temps[p])=1 then min(operand_temps[p]) + else if card(operand_temps[p])=2 then + let {int: a = min(operand_temps[p]), + int: b = max(operand_temps[p])} + in (b-a)*y[p] -b+a+a + else + operand_temps[p][y[p]] + endif endif; + +var int: ls_t(int: p) = [ls[t] | t in operand_temps[p]][y[p]]; + +var int: le_t(int: p) = [le[t] | t in operand_temps[p]][y[p]]; + +%% conditions +predicate eval_expr(int: l) = ( + let {int: tag = expr_op[l], + int: arg1 = expr_arg1[l], + int: arg2 = expr_arg2[l], + int: arg3 = expr_arg3[l], + } in ( + if tag=0 then exists(j in expr_children[l])(eval_expr(j)) + else if tag=1 then forall(j in expr_children[l])(eval_expr(j)) + else if tag=2 then eval_expr(arg1) xor eval_expr(arg2) + else if tag=3 then eval_expr(arg1) -> eval_expr(arg2) + else if tag=4 then not eval_expr(arg1) + else if tag=5 then a[arg1] + else if tag=6 then temp_eq(arg1,arg2) + else if tag=7 then insn_eq(arg1,arg2) + else if tag=8 then c[arg2] >= c[arg1] + arg3 + else if tag=9 then same_temp(arg1,arg2) + else if tag=10 then operand_live_overlap(arg1,arg2) + else if tag=11 then live_overlap(arg1,arg2) + else if tag=12 then r[arg1] in callersaved + else if tag=13 then rt[arg1] in atom_regs[arg2] + else false endif endif endif endif endif endif endif endif endif endif endif endif endif endif + ) +); + +test phase1_expr(int: l) = ( + let {int: tag = expr_op[l], + int: arg1 = expr_arg1[l], + int: arg2 = expr_arg2[l], + int: arg3 = expr_arg3[l], + } in ( + if tag=0 then forall(j in expr_children[l])(phase1_expr(j)) + else if tag=1 then forall(j in expr_children[l])(phase1_expr(j)) + else if tag=2 then phase1_expr(arg1) /\ phase1_expr(arg2) + else if tag=3 then phase1_expr(arg1) /\ phase1_expr(arg2) + else if tag=4 then phase1_expr(arg1) + else tag in {5,6,7,9,12,13} + endif endif endif endif endif + ) +); + +var int: ite(var bool: cond, var int: thenval, var int: elseval) = ( + let {array[1..2] of var int: ar = [elseval,thenval]} in + ar[cond+1] +); + +0..MAXT: single_temp(int: p) = max(operand_temps[p]); + +set of 0..MAXT: real_temps(int: p) = operand_temps[p] intersect 0..MAXT; + +%% (mostly) ESSENTIAL CONSTRAINT + +%% basic invariants, null instructions + +test opt_in_temporary(int: v) = + let {int: p = temp_def[v]} in + op_type[temp_definer[v]] = TYPE_IN /\ card(operand_temps[p])>1; + +constraint + if phase=1 then + r[-1] = -1 /\ + forall(o in 0..MAXO where op_mand[o]) (a[o]) /\ + forall(o in 0..MAXO where not op_mand[o]) (insn_is_real_reif(o,a[o])) /\ + forall(p in 0..MAXP where card(operand_temps[p])>1) (rt[p] = [r[v] | v in operand_temps[p]][y[p]]) /\ + forall(p in 0..MAXP where card(operand_temps[p])=1) (rt[p] = r[single_temp(p)]) /\ + forall(p in 0..MAXP where not op_mand[operand_definer[p]]) % rematerialization + (temp_is_real_reif(p,a[operand_definer[p]])) + else true endif /\ + ls[-1] = -1 /\ + ld[-1] = 0 /\ + le[-1] = -1 /\ + forall(o in 0..MAXO) (a[o] <-> c[o] >= 0) /\ + forall(v in 0..MAXT) (ls[v]+ld[v] = le[v]) /\ + forall(v in 0..MAXT where not opt_in_temporary(v)) % rematerialization + (ls[v] = c[temp_definer[v]] /\ + (a[temp_definer[v]] <-> r[v] >= 0)) /\ + forall(v in 0..MAXT where opt_in_temporary(v)) % rematerialization + (ls[v] in -1 .. 0 /\ + (r[v] >= 0 <-> ls[v]=0) /\ + (r[v] >= 0 <-> temp_eq(temp_def[v],v))) /\ + forall(v in 0..MAXT) ( + let {bool: unsafe = temp_is_unsafe(v), + set of int: pset = temp_uses[v], + set of int: prange = 1..card(pset), + array[prange] of int: parr = [p | p in pset], + array[prange] of var -1..MAXC: carr} in ( + forall(p in prange) (carr[p] = ite(temp_eq(parr[p],v), c[operand_definer[parr[p]]], -1)) /\ + if card(pset)=1 /\ not unsafe then + le[v] = carr[1] + else if not unsafe then + maximum(le[v], carr) + else + maximum(le[v], carr++[ls[v]+ % 20130930: live range can extend past last use + temp_minlive[v]*bool2int(a[temp_definer[v]])]) + endif endif + ) + ); + +constraint + if phase=1 then + let {array[0..MAXO] of int: wceto = array1d(0..MAXO, [max(jj in index_set_1of2(wcet) where wcet[jj,1] = o)(wcet[jj,3]) | o in 0..MAXO])} in + forall(b in 1..MAXB)( + forall(o in bb_ops[b])( + if op_mand[o] then + c[o] = sum(j in min(bb_ops[b])..(o-1))(wceto[j]) + else + c[o] in {-1,sum(j in min(bb_ops[b])..(o-1))(wceto[j])} + endif + ) + ) + else true endif; + +constraint + if phase=2 then + forall(o in index_set(a))(a[o] <-> op_mand[o] \/ ii[o]>1) /\ + forall(o in index_set(ii))(ii_soln[o]>0 -> ii[o] = ii_soln[o]) /\ + forall(p in index_set(rt))(rt[p] = rt_soln[p]) /\ + forall(p in index_set(y))(y[p] = y_soln[p]) /\ + forall(t in index_set(r))(r[t] = r_soln[t]) + else true endif; + +%% objective, bounds on (out) cycle + +constraint + forall(b in 1..MAXB) ( + if phase=2 then + forall(o in bb_ops[b])(c[o] in -1..bb_maxcycle[b]) + else true endif + ) /\ + forall(b in 1..MAXB) ( + c[min(bb_ops[b])] = 0 /\ + copysum[b] = sum(o in bb_ops[b] where not op_mand[o])(bool2int(a[o])) /\ + copysum[b] >= bb_optional_min[b] + ) /\ + if not optimize_cycles then + obj = sum(o in 0..MAXO)(res_con_of_op(1,o)) + else if phase=1 then + let {set of int: res = index_set_1of2(res_dur), + set of int: ins = index_set_2of2(res_dur), + array[ins] of int: latency = array1d(ins, [max(r in res)(min(1,res_con[r,j])*res_dur[r,j]) | j in ins])} + in obj = sum(b in 1..MAXB, o in bb_ops[b])(let { + set of int: oI = 1..card(op_instructions[o]), + array[oI] of int: L = [latency[j] | j in op_instructions[o]] + } + in bb_frequency[b] * L[ii[o]]) + else + obj = sum(b in 1..MAXB) (bb_frequency[b] * c[max(bb_ops[b])]) + endif endif; + +%% domains +constraint + forall(o in 0..MAXO) (ii[o] in 1..card(op_instructions[o])); + +constraint + if phase=1 then + forall(q in 0..MAXP) (y[q] in 1..card(operand_temps[q])) + else true endif; + +set of int: temp_insn_regs(int: v, int: j) = + let {int: p = temp_def[v], + int: w = temp_width[v], + int: oa = operand_atom[p,j], + set of int: ks = {k | k in index_set_1of2(infassign) where infassign[k,1]=v /\ infassign[k,2]=space[oa]}, + set of int: unaligned = + if card(ks)>0 then + {r | r in atom_regs[oa]} intersect (infassign[min(ks),3]..infassign[min(ks),4]) + else + {r | r in atom_regs[oa]} + endif} + in {r | r in unaligned /*where r mod w = 0*/}; % currently, that would over-constrain + +set of int: generic_temp_domain(int: t1) = + if card(temp_domain[t1]) > 0 then + temp_domain[t1] + else + let {int: p = temp_def[t1], + set of int: rdom = array_union([temp_insn_regs(t1,j) | j in 1..MAXI]), + set of int: joker = if min(operand_temps[p])>=0 then {} else {-1} endif, % rematerialization + } in rdom union joker + endif; + +constraint + if phase=1 then + forall(t1 in 0..MAXT) (r[t1] in generic_temp_domain(t1)) + else true endif; +% desperate work-around +constraint + if phase=1 then + forall(t1 in 0..MAXT) (exists(v in generic_temp_domain(t1))(r[t1] = v)) + else true endif; + +%% operation selection (register set depending on operation) +constraint + if phase=1 then + forall(p in 0..MAXP)( + let {int: o = operand_definer[p], + set of int: joker = if min(operand_temps[p])>=0 then {} else {-1} endif} in + if fixedop(o) then + rt[p] in atom_regs[operand_atom[p,min(op_instructions[o])]] union joker % rematerialization + else + let {array[int] of set of int: doms = [ if insn=0 then {-1} else atom_regs[operand_atom[p,insn]] endif + | insn in op_instructions[o] + ], + array[int] of int: extension = [ if k=1 then j else r endif + | j in index_set(op_instructions[o]), + r in doms[j], + k in 1..2 + ], + int: nt = length(extension) div 2} in + if forall(i in index_set(doms))(doms[i] = doms[1]) then + rt[p] in doms[1] + else + table([ii[o],rt[p]], array2d(1..nt, 1..2, extension)) + endif + endif + ) + else true endif; + +%% operation selection (register set depending on operation) +constraint + if phase=2 then + forall(p in 0..MAXP)( + let {int: o = operand_definer[p]} in + if ii_soln[o]=0 then + let {array[int] of set of int: doms = [ if insn=0 then {-1} else atom_regs[operand_atom[p,insn]] endif + | insn in op_instructions[o] + ], + array[int] of int: extension = [ if k=1 then j else r endif + | j in index_set(op_instructions[o]), + r in doms[j], + k in 1..2 + ], + int: nt = length(extension) div 2} in + if not forall(i in index_set(doms))(doms[i] = doms[1]) then + table([ii[o],rt[p]], array2d(1..nt, 1..2, extension)) + else true endif + else true endif + ) + else true endif; + +%% preassignments +constraint + if phase=1 then + forall(j in index_set(preassign_reg)) + (rt[preassign_operand[j]] = preassign_reg[j]) + else true endif; + +%% congruences +constraint + if phase=1 then + forall(cgr in strictly_congr) ( + let {int: junior = min(cgr)} in ( + forall(j in cgr where j>junior) (rt[junior] = rt[j]) + ) + ) + else true endif; + +%% adjacencies NEW FOR REMATERIALIZATION +constraint + if phase=1 then + forall( j in index_set(adj_from) + where not({adj_from[j],adj_to[j]} subset array_union(strictly_congr)) + ) ( + let {int: p = adj_from[j], + int: q = adj_to[j]} in + (temp_is_real(q) -> temp_is_real(p)) /\ + (temp_is_real(q) -> rt[p] = rt[q]) /\ + (temp_is_real(p) -> exists(k in index_set(adj_from) where adj_from[k] = p)(temp_is_real(adj_to[k]))) + ) + else true endif; + +constraint + if phase=1 then + forall(j in index_set(quasi_adj_from)) ( + let {int: p = quasi_adj_from[j], + int: q = quasi_adj_to[j]} in + temp_is_real(q) -> temp_is_real(p) + ) + else true endif; + +%% aligned/adist +constraint + if phase=1 then + forall(j in index_set(aligned_use)) ( + let {int: p = aligned_use[j], + int: q = aligned_def[j], + int: pi = aligned_usei[j], + int: qi = aligned_defi[j], + int: offset = aligned_dist[j]} in ( + insn_eq(operand_definer[p],pi) /\ insn_eq(operand_definer[q],qi) -> rt[p] + offset = rt[q] + ) + ) + else true endif; + +%% disjoint live ranges +constraint + forall(T in bb_temps) ( + ra_diffn([r[v] | v in T], + [temp_width[v] | v in T], + [generic_temp_domain(v) | v in T], + [ls[v] | v in T], + [ld[v] | v in T], + [le[v] | v in T]) + ); + +%% precedences (with conditions added by presolver) +constraint + if phase=2 then + forall(P in precedence) ( + eval_expr(P) + ) + else true endif; + +%% slack and balancing + +%% Model::global_operand +test global_operand(int: p) = + exists(j in index_set(adj_from))(adj_from[j]=p) \/ + exists(j in index_set(adj_to))(adj_to[j]=p); + +%% Model::slack +constraint + forall(p in 0..MAXP)(if not global_operand(p) then s[p]=0 else true endif); + +%% CompleteModel::post_slack_balancing_constraints +constraint + forall(j in index_set(adj_from)) ( + s[adj_from[j]] + s[adj_to[j]] = 0 + ); + +%% Model::post_operand_latency_definition +constraint + forall(o in 0..MAXO, p in op_operands[o])( + let {array[int] of int: lcol = [ lat_table[j,4] + | j in index_set_1of2(lat_table) + where lat_table[j,1] = o /\ lat_table[j,3] = p + ], + int: n = length(lcol), + bool: simple = if not op_mand[o] then + forall(k in 2..n)(lcol[k]=lcol[2]) + else + forall(k in 1..n)(lcol[k]=lcol[1]) + endif} in + if simple then + lt[p] = lcol[n] + else + lt[p] = lcol[ii[o]] + endif + ); + +%% Model::post_temporary_use_latency_definition +var -MAXL..3*MAXL: lat(int: q, int: v) = + let {int: p = temp_def[v]} in + lt[p] + s[p] + lt[q] + s[q]; + +%% data precedences with slack and everything + +array[int] of var int: opnd_lbs(int: q) = + [ if v = -1 then -1 + else c[temp_definer[v]] + lat(q,v) + endif + | v in operand_temps[q] + ]; + +predicate post_data_prec(int: q) = + let {int: u = operand_definer[q], + array[int] of var int: lbs = opnd_lbs(q)} in + c[u] >= lbs[1] /\ + c[u] >= lbs[y[q]]; + +%% Model::post_data_precedences_constraints +%% redundant if op_type[operand_definer[q]]!=TYPE_KILL and implied constraints are being posted +constraint + if phase=2 then + forall(q in 0..MAXP where operand_use[q])(post_data_prec(q)) + else true endif; + +%% resources + +test unit_res_dur_cap(int: res, set of int: active) = ( + forall(o in active, oi in op_instructions[o])( + res_con[res,oi]=res_cap[res] /\ + res_dur[res,oi]=1 /\ + res_off[res,oi]=0 + ) +); + +test unit_res_dur(int: res, int: o) = ( + forall(oi in op_instructions[o])(res_dur[res,oi]=1) +); + +test zero_res_off(int: res, int: o) = ( + forall(oi in op_instructions[o])(res_off[res,oi]=0) +); + +int: max_res_dur(int: res, int: o) = ( + max(oi in op_instructions[o])(res_dur[res,oi]) +); + +int: max_res_off(int: res, int: o) = ( + max(oi in op_instructions[o])(res_off[res,oi]) +); + +constraint + if phase=2 then + forall(b in 1..MAXB, res in index_set(res_cap) diff bb_subsumed[b]) ( + let {set of int: active = {o | o in bb_ops[b] where + exists(q in op_instructions[o])(res_con[res,q]>0)}} in ( + if card(active)<=1 then true + else if unit_res_dur_cap(res,active) then + smart_alldiff([c[o] | o in active]) + else if good_cumulative then + cumulative([ if zero_res_off(res,o) then c[o] else c[o]+res_off_of_op(res,o) endif + | o in active + ], + [ if unit_res_dur(res,o) then 1 else res_dur_of_op(res,o) endif + | o in active + ], + [ res_con_of_op(res,o) + | o in active + ], + res_cap[res]) + else let {int: inf = min([lb(c[o]) | o in active]), + int: sup = max([ub(c[o]) | o in active]) + + max([max_res_dur(res,o) | o in active]) + + max([max_res_off(res,o) | o in active]) + } in ( + forall(j in inf..sup)( + sum(o in active, + io in op_instructions[o], + k in j-res_dur[res,io]-res_off[res,io]+1..j-res_off[res,io] + where res_con[res,io]>0 /\ k in lb(c[o])..ub(c[o])) + (res_con[res,io]*bool2int(c[o]=k /\ insn_eq(o,io))) <= res_cap[res] + ) + ) + endif endif endif + ) + ) + else true endif; + + +%% packing constraints +%% see Model::post_packing_constraints() +constraint + if phase=1 then + forall(k in index_set_1of2(packed_pq)) ( + let {int: p = packed_pq[k,1], + int: q = packed_pq[k,2], + int: w = temp_width[single_temp(p)], + array[int] of int: modtab = [-1,-1]++[ if k=1 then v else v + w - 2*(v mod 2*w) endif + | v in 0..MAXR, k in 1..2 + where v mod w = 0 + ], + int: nt = length(modtab) div 2, + } in + table([rt[p], rt[q]], array2d(1..nt, 1..2, modtab)) + ) + else true endif; + +%% activators +constraint + if phase=1 then + forall(x in index_set(activator_insns))( + let {set of int: is = activator_insns[x], + set of int: os = activator_ops[x]} in ( + (a[min(os)] <-> exists(o in 0..MAXO)(insn_in(o,op_instructions[o] intersect is))) /\ + forall(i2 in os where i2>min(os))(a[i2] <-> a[min(os)]) + ) + ) + else true endif; + +%% prescheduling +constraint + if phase=2 then + forall(j in index_set(preschedule_op))( + let {int: oper = preschedule_op[j], + int: cycle = preschedule_cycle[j], + int: bb = min({k | k in index_set(bb_ops) where oper in bb_ops[k]}), + int: outop = max(bb_ops[bb])} + in (a[oper] -> c[oper] = cycle) /\ + (a[oper] <-> c[outop] > cycle) + ) + else true endif; + +%% TO GUARANTEE THE CONDITION, RA + IS MUST BE SOLVED SIMULTANEOUSLY +%% bypass +constraint + forall(j in index_set_1of2(bypass_table))( + let {int: o = bypass_table[j,1], + int: insn = bypass_table[j,2], + int: p = bypass_table[j,3]} + in + if phase=1 then + % adhoc rule: disable instructions like + % o20: [p47{-, t28}] <- {-, J4_cmpgtui_t_jumpnv_t_linear} [p46{-, t21, t22, t23, t26},5] (writes: [control]) + % because we can't guarantee the bypass condition until in phase 2 + if not op_mand[o] /\ op_type[o]=TYPE_LINEAR /\ op_type[o+1]=TYPE_BRANCH /\ op_type[o+2]=TYPE_OUT then + ii[o] = 1 + else true endif + else + insn_eq(o,insn) -> c[o] = ls_t(p) + endif + ); + +%% exrelated +constraint + if phase=1 then + forall(j in index_set(exrelated_p))( + let {int: p = exrelated_p[j], + int: q = exrelated_q[j], + array[int] of int: ext = [exrelated_ext[r,k] | r in exrelated_rows[j], k in 1..2]} + in table([rt[p],rt[q]], array2d(1..(length(ext) div 2), 1..2, ext)) + ) + else true endif; + +%% ad-hoc FIXME: X86 SPECIAL PHASE DEPENDENCY +constraint + forall(L in adhoc) ( + if (phase1_expr(L) \/ phase=2) then + eval_expr(L) + else true endif + ); + +%% IMPLIED CONSTRAINTS + +%% effective copy, handling multiple defs and/or uses +constraint + if phase=1 then + forall(o in 0..MAXO where op_type[o] = TYPE_COPY)( + let {int: src = min([p | p in op_operands[o] where operand_use[p]]), + int: dst = min([p | p in op_operands[o] where not operand_use[p]])} in + a[o] -> rt[src] != rt[dst] + ) + else true endif; + +%% dominating copies +constraint + if phase=1 then + forall(k in index_set(dominate_ing)) ( + let {int: ing = dominate_ing[k], + int: ed = dominate_ed[k], + int: edsrc = min(op_operands[ed]), + set of int: iset = dominate_instructions[k], + set of int: tset = dominate_temps[k]} in ( + a[ing] \/ not a[ed] \/ insn_in(ed,iset) \/ temp_in(edsrc,tset) + ) + ) + else true endif; + +%% disjoint registers +constraint + if phase=1 then + forall(R in diffreg) ( + noverlap([rt[j] | j in R], + [temp_width[min(operand_temps[j])] | j in R]) + ) + else true endif; + +%% different temporaries +constraint + if phase=1 then + forall(T in difftemp) ( + let {array[int] of int: TA = T} in + forall(j in index_set(TA), k in index_set(TA) where j0 /\ operand_atom[P,i]=atm}} in ( +% if (card(insns)>=1) then +% (temp_eq(Q,T) /\ insn_in(I,insns) /\ r[T] in atom_regs[atm] -> temp_eq(P,T)) +% else true endif +% ) +% ) +% else true endif +% ) +% ); + +%% before +constraint + forall(j in index_set(before_pred)) ( + let {int: p = before_pred[j], + int: q = before_succ[j], + expr: bc = before_cond[j]} in ( + eval_expr(bc) -> operand_live_before(p,q) + ) + ); + +%% active_table, tmp_table +constraint + if phase=1 then + forall(E in table_exists_ops) ( + exists(j in E)(a[j]) + ) + else true endif; + +constraint + if phase=1 then + forall(XOR in table_iffall_ops) ( + let {int: j = min(XOR), + int: k = max(XOR)} in ( + a[j] <-> a[k] + ) + ) + else true endif; + +constraint + if phase=1 then + forall(j in index_set(relation_ops)) ( + let{set of int: ops = relation_ops[j], + set of int: temps = relation_temps[j], + int: nt = relation_ntuples[j], + set of int: range = relation_range[j], + set of int: irange = 1..(card(ops)+card(temps)), + array[irange] of var int: vars = [bool2int(a[j]) | j in ops]++ + [t(j) | j in temps]} in ( + table(vars, array2d(1..nt,irange,[ints[j] | j in range])) + ) + ) + else true endif; + +%% combine +constraint + forall(o in 0..MAXO where op_type[o] = TYPE_COMBINE)( + let {array[int] of int: opnds = [x | x in op_operands[o]], + int: src1 = opnds[1], + int: src2 = opnds[2], + int: def = opnds[3]} in ( + minimum(ls_t(def), [le_t(src1), le_t(def)]) /\ + minimum(ls_t(def), [le_t(src2), le_t(def)]) + ) + ); + +%% low/high +constraint + forall(o in 0..MAXO where op_type[o] in {TYPE_HIGH, TYPE_LOW})( + let {int: src = min(op_operands[o]), + int: def = max(op_operands[o])} in ( + minimum(ls_t(def), [le_t(src), le_t(def)]) + ) + ); + +%% useless memory stores +constraint + if phase=1 then + forall(T in related_temps) ( + sum([bool2int(r[v] in infinite) | v in T]) <= 1 + ) + else true endif; + +%% across +constraint + forall(j in index_set(across_op)) ( + let {int: opi = across_op[j], + int: maxwidth = max(temp_width), + set of int: regs = across_regs[j], + set of int: items = across_items[j], + array[items] of int: cand = + array1d(items, [across_item_temp[k] | k in items]), + array[items] of var bool: active, + array[items] of var -maxwidth*(MAXT+1)..MAXR: selected, + array[int] of var int: allreg = + [x | x in callersaved] ++ [x | x in regs] ++ selected, + array[int] of int: allwidth = + [1 | x in callersaved] ++ + [1 | x in regs] ++ + [temp_width[cand[k]] | k in items]} in ( + forall(k in items)( + let {int: ck = cand[k]} in ( + ( active[k] <-> + eval_expr(across_item_cond[k]) \/ + (ls[ck] <= c[opi] /\ c[opi] < le[ck])) /\ + selected[k] = ite(active[k], r[ck], -maxwidth*(ck+1)) + ) + ) /\ + noverlap(allreg, allwidth) + ) + ); + +%% set_across +constraint + forall(j in index_set(setacross_op)) ( + let {int: opi = setacross_op[j], + set of int: regs = setacross_regs[j], + set of int: itemsset = setacross_tempsets[j], + set of int: items = 1..card(itemsset), + array[items] of set of int: cands = [sets[it] | it in itemsset], + array[items] of var 0..MAXR: selected, + array[items] of var 0..max(temp_width): width, + array[int] of var int: allreg = + [x | x in callersaved] ++ [x | x in regs] ++ selected, + array[int] of var int: allwidth = + [1 | x in callersaved] ++ [1 | x in regs] ++ width} in ( + forall(it in items)( + let {set of int: cit = cands[it], + array[int] of int: ws = [temp_width[k] | k in cit], + array[int] of var int: rs = [r[k] | k in cit], + array[int] of var int: lss = [ls[k] | k in cit], + array[int] of var int: les = [le[k] | k in cit], + var 1..card(cit): k} in ( + width[it] = if min(ws) < max(ws) then ws[k] else min(ws) endif /\ + selected[it] = rs[k] /\ + lss[k] <= c[opi] /\ c[opi] < les[k] + ) + ) /\ + noverlap(allreg, allwidth) + ) + ); + +%% spill callee-saved if and only if some temp interfers with it +constraint + if phase=1 /\ card(index_set(calleesaved_spill))>0 then + let {int: nrows = card(index_set_1of2(cs_spill_transpose)), + int: ncols = card(index_set_2of2(cs_spill_transpose)), + set of int: css_ops = {cs_spill_transpose[j,k] | j in 1..nrows, k in 1..ncols}, + set of int: preass_ops = {o | o in 0..MAXO where op_type[o] in {TYPE_IN,TYPE_CALL,TYPE_TAIL,TYPE_FUN}}, + set of int: tcands = {o | o in 0..MAXT where not (temp_definer[o] in css_ops union preass_ops)}} in ( + forall(j in 1..ncols) ( + let {int: theop = cs_spill_transpose[1,j], + int: thepu = min(op_operands[theop]), + int: thetu = single_temp(thepu), + int: thepd = temp_def[thetu], + int: thea = min(k in index_set(preassign_reg) where preassign_operand[k]=thepd)(preassign_reg[k]), + int: thew = temp_width[thetu]} in ( + a[theop] <-> exists(ti in tcands)(r[ti]+temp_width[ti] > thea /\ r[ti] in 0..thea+thew-1) + ) + ) + ) + else true endif; + +%% DISABLED, seems to interact with both phases +%% break symmetries among which callee-saved to spill +% constraint +% if card(index_set(calleesaved_spill))>0 then +% forall(j in index_set(calleesaved_spill)) ( +% let {set of int: cgr = calleesaved_spill[j], +% int: cur = min(cgr)} in ( +% forall(x in cgr where x>cur) (a[cur] <-> a[x]) +% ) +% ) /\ +% let {int: nrows = card(index_set_1of2(cs_spill_transpose)), +% int: ncols = card(index_set_2of2(cs_spill_transpose)), +% set of int: spill = if nrows>=1 then {cs_spill_transpose[1,j] | j in 1..ncols} +% else {} endif, +% set of int: unspill = if nrows>=2 then {cs_spill_transpose[2,j] | j in 1..ncols} +% else {} endif} in ( +% decreasing([a[cs_spill_transpose[1,k]] | k in 1..ncols]) /\ +% forall(k in 2..ncols)( +% a[cs_spill_transpose[1,k]] -> c[cs_spill_transpose[1,k-1]] <= c[cs_spill_transpose[1,k]] +% ) /\ +% if spill subset bb_ops[1] /\ unspill subset bb_ops[1] then +% forall(k in 1..ncols)( +% let {int: u = cs_spill_transpose[2,k], +% int: v = cs_spill_transpose[1,k]} in ( +% a[u] -> c[v] < c[u] +% ) +% ) +% else true endif +% ) +% else true endif; + +%% symmetry breaking from JSON info +%% DISABLED, cannot be trusted +% constraint +% forall(x in index_set(value_precede_min))( +% let {set of int: js = value_precede_min[x]..value_precede_max[x], +% int: nt = sum(j in js)(temp_width[value_precede_temps[j]]), +% array[1..nt] of var int: chain = [r[v]+d | j in js, v in {value_precede_temps[j]}, d in 0..temp_width[v]-1]} in +% value_precede_chain([v | v in value_precede_regs[x]], chain) +% ); + +%% IMPORTED FROM Model:: + +%% Model::post_minimum_temporary_duration_constraints +constraint + forall(o in 0..MAXO, dp in op_operands[o] where not operand_use[dp])( + let {int: v = single_temp(dp)} in + (temp_eq(dp,v) -> ld[v] >= temp_minlive[v]) /\ + forall(up in temp_uses[v])(temp_eq(up,v) -> ld[v] >= lat(up,v)) + ); + +%% Model::post_define_issue_cycle_constraints +constraint + if phase=2 then + forall(o in 0..MAXO where op_type[o]=TYPE_DEFINE)( + let {set of int: js = {operand_definer[q] | p in op_operands[o], + v in {single_temp(p)}, + q in temp_uses[v]}, + array[int] of var int: lats = [lat(q,v) | p in op_operands[o], + v in {single_temp(p)}, + q in temp_uses[v]]} in + if card(js) = 1 then + c[min(js)] = c[o] + max(lats) + else true endif + ) + else true endif; + +%% DOMINATION: live range of temp occurring in (kill) +predicate kill_live_range(int: v) = + (ld[v] = lt[temp_def[v]]); + +%% Model::post_kill_issue_cycle_constraints +constraint + if phase=2 then + forall(o2 in 0..MAXO where op_type[o2] = TYPE_KILL)( + if op_mand[o2] then % e.g. after function call, multiple operands + let {array[int] of var int: lats = [lat(q,v) | q in op_operands[o2], + v in {single_temp(q)}], + array[int] of int: ts = [v | q in op_operands[o2], + v in {single_temp(q)}], + set of int: o1s = {temp_definer[v] | q in op_operands[o2], + v in {single_temp(q)}}, + } in + forall(v in ts)(kill_live_range(v)) /\ + c[o2] = c[min(o1s)] + max(lats) + else % e.g. after move subject to pack, one operand, multiple temps + let {int: q1 = min(op_operands[o2]), + int: p1 = temp_def[single_temp(q1)], + set of int: o1s = {temp_definer[v] | v in real_temps(q1)}, + array[int] of var int: issue = [-1] ++ [c[temp_definer[v]] + lat(q1,v) | v in real_temps(q1)], + } in + card(op_operands[o2]) = 1 /\ % sanity check + forall(v in real_temps(q1))(kill_live_range(v)) /\ + c[o2] = issue[y[q1]] /\ + if card(real_temps(q1))=1 then + same_temp(p1,q1) /\ rt[p1] = rt[q1] + else + sum(o in o1s)(a[o]) <= 1 + endif + endif + ) + else true endif; + +%% [matsc] domination constraint for slack, in fact make it a functional dependency +%% N.B. Subsumes post_slack_lower_bound_constraints +%% N.B. MAY clash with post_reverse_data_precedences_constraints +constraint + if phase=2 then + forall(j in index_set_1of2(long_latency_index))( + let {set of int: inps = long_latency_index[j,1], + set of int: inix = long_latency_index[j,2], + set of int: outps = long_latency_index[j,3], + set of int: outix = long_latency_index[j,4], + array[int] of var int: inubs = [ if temp_eq(q,single_temp(p)) then + c[operand_definer[q]] - lt[q] - s[q] - lt[p] + else MAXL endif + | i in inix, + p in [long_latency_def[i]], + q in [long_latency_use[i]] + ], + array[int] of var int: outubs = [ if temp_eq(q,single_temp(p)) then + ld[single_temp(p)] - lt[q] - lt[p] - s[p] + else MAXL endif + | i in outix, + p in [long_latency_def[i]], + q in [long_latency_use[i]] + ]} in + assert((card(inps)>0 /\ card(outps)>0), "invalid long_latency item") /\ + let {var int: outlb = if length( inubs)>0 then -min( inubs) else -MAXL endif, + var int: outub = if length(outubs)>0 then min(outubs) else MAXL endif} in + outlb <= outub /\ + forall(p in outps)(s[p] = min(outub,max(outlb,0))) + ) + else true endif; + +%% domination constraint: sequential schedule as a makespan UB +%% Model::post_sequential_upper_bound_constraints +constraint + if phase=2 then + forall(bb in index_set(bb_ops))( + let {set of int: os = bb_ops[bb], + array[os] of var 0..MAXC: wc = array1d(os, [o_wcet(o) | o in os])} + in c[max(os)] <= sum(o in os)(wc[o]) + ) + else true endif; + +var 0..MAXC: o_wcet(0..MAXO: o) = + let {array[int] of var int: wcs = [wcet[jj,3] | jj in index_set_1of2(wcet) where wcet[jj,1] = o], + int: nwcs = length(wcs)} + in if forall(jj in 1..nwcs)(wcs[jj] = 1) + then a[o] + else if not op_mand[o] /\ forall(jj in 2..nwcs)(wcs[jj] = 1) + then a[o] + else + wcs[ii[o]] + endif endif; + +%% output + +output + ["\"cost\": "] ++ [show(obj)] ++ ["\n"] ++ + ["\"cycles\": "] ++ [show(c)] ++ ["\n"] ++ + ["\"instructions\": "] ++ [show([op_instructions[o][fix(ii[o])] | o in 0..MAXO])] ++ ["\n"] ++ + ["\"temporaries\": "] ++ [show([operand_temps[p][fix(y[p])] | p in 0..MAXP])] ++ ["\n"] ++ + ["\"registers\": "] ++ [show([r[v] | v in 0..MAXT])] ++ ["\n"] ++ + ["\"live start\": "] ++ [show([ls[v] | v in 0..MAXT])] ++ ["\n"] ++ + ["\"live duration\": "] ++ [show([ld[v] | v in 0..MAXT])] ++ ["\n"] ++ + ["\"live end\": "] ++ [show([le[v] | v in 0..MAXT])] ++ ["\n"] ++ + ["ii_soln = array1d(0..\(MAXO), \([if exists(j in index_set_1of2(bypass_table))(bypass_table[j,1]=o) + then 0 else ii[o] endif | o in 0..MAXO]));\n"] ++ + ["rt_soln = array1d(0..\(MAXP), \([rt[p] | p in 0..MAXP]));\n"] ++ + ["y_soln = array1d(0..\(MAXP), \([y[p] | p in 0..MAXP]));\n"] ++ + ["r_soln = array1d(-1..\(MAXT), \([r[t] | t in -1..MAXT]));\n"] ++ + []; + diff --git a/src/solvers/multi_backend/minizinc/code-generation.mzn b/src/solvers/multi_backend/minizinc/code-generation.mzn index fe1fa77d..f1645412 100644 --- a/src/solvers/multi_backend/minizinc/code-generation.mzn +++ b/src/solvers/multi_backend/minizinc/code-generation.mzn @@ -36,6 +36,7 @@ include "globals.mzn"; bool: good_cumulative; bool: good_diffn; +bool: good_member; bool: optimize_cycles; %% some constants @@ -79,6 +80,7 @@ array[int] of int: bb_order; array[int] of set of int: bb_ops; array[int] of set of int: bb_operands; array[int] of set of int: bb_temps; +array[int] of set of int: bb_subsumed; array[int] of int: bb_frequency; array[int] of int: bb_maxcycle; array[int] of int: bb_optional_min; @@ -88,7 +90,6 @@ array[int] of set of int: op_operands; array[int] of set of int: op_instructions; array[int] of int: op_type; array[int] of bool: op_mand; -array[int] of int: op_order; %% see JSON atoms array[int] of set of int: atom_regs; % atom -> registers @@ -160,6 +161,7 @@ array[int] of int: temp_def; % temp -> defining operand array[int] of int: temp_width; % temp -> width array[int] of int: temp_minlive; % temp -> minlive array[int] of set of int: temp_uses; % temp -> set of use operands +array[int] of set of int: temp_domain; % temp -> domain of regs %% see JSON packed, pinstrs array[int,int] of int: packed_pq; @@ -233,16 +235,6 @@ array[int,int] of int: cs_spill_transpose; array[int] of set of int: activator_insns; array[int] of set of int: activator_ops; -%% see JSON predecessors -array[int] of set of int: predecessors_preds; -array[int] of int: predecessors_succ; -array[int] of int: predecessors_lat; - -%% see JSON successors -array[int] of set of int: successors_succs; -array[int] of int: successors_pred; -array[int] of int: successors_lat; - %% see JSON value_precede_chain array[int] of int: value_precede_min; array[int] of int: value_precede_max; @@ -265,6 +257,9 @@ array[int] of int: exrelated_q; array[int] of set of int: exrelated_rows; array[int,int] of int: exrelated_ext; +%% see JSON wcet +array[int,int] of int: wcet; + %% extra storage for constraint expressions array[int] of int: expr_op; array[int] of int: expr_arg1; @@ -299,11 +294,6 @@ array[1..MAXB] of var 0..MAXC: copysum; test isreal(int: o) = (op_type[o] in {TYPE_LINEAR, TYPE_BRANCH, TYPE_CALL, TYPE_TAIL, TYPE_FUN, TYPE_COPY}); -test can_use(int: p, int: temp) = ( - operand_use[p] /\ - temp in operand_temps[p] -); - test fixedop(int: o) = ( op_instructions[o] != {0} /\ card(op_instructions[o]) = 1 ); @@ -352,26 +342,29 @@ predicate smart_alldiff(array[int] of var int: X) = predicate ra_diffn_cumu(array[int] of var int: R, array[int] of int: W, + array[int] of set of int: D, array[int] of var int: LS, array[int] of var int: LD, int: v) = - let {set of int: J = {i | i in index_set(R) where card(dom(R[i]) intersect max(0,v-W[i]+1)..v)>0}} + let {set of int: J = {i | i in index_set(R) where card(D[i] intersect max(0,v-W[i]+1)..v)>0}} in cumulative([LS[i] | i in J], [LD[i] | i in J], [if W[i]=1 then R[i]=v else R[i] in max(0,v-W[i]+1)..v endif | i in J], 1); predicate ra_diffn(array[int] of var int: R, array[int] of int: W, + array[int] of set of int: D, array[int] of var int: LS, array[int] of var int: LD, array[int] of var int: LE) = if good_cumulative then % [MC] infinite ranges are clash free by construction - forall(v in 0..min(infinite)-1)( - ra_diffn_cumu(R, W, LS, LD, v) - ) /\ - forall(j in index_set(bounded), v in range[j] where bounded[j])( - ra_diffn_cumu(R, W, LS, LD, v) - ) + let {set of int: atoms = array_union(D)} + in forall(v in atoms intersect (0..min(infinite)-1))( + ra_diffn_cumu(R, W, D, LS, LD, v) + ) /\ + forall(j in index_set(bounded), v in atoms intersect range[j] where bounded[j])( + ra_diffn_cumu(R, W, D, LS, LD, v) + ) else if good_diffn then diffn_nonstrict(R, LS, W, LD) else @@ -548,7 +541,7 @@ constraint (r[v] >= 0 <-> temp_eq(temp_def[v],v))) /\ forall(v in 0..MAXT) ( let {bool: unsafe = temp_is_unsafe(v), - set of int: pset = {p | p in 0..MAXP where can_use(p,v)}, + set of int: pset = temp_uses[v], set of int: prange = 1..card(pset), array[prange] of int: parr = [p | p in pset], array[prange] of var -1..MAXC: carr} in ( @@ -599,14 +592,18 @@ set of int: temp_insn_regs(int: v, int: j) = endif} in {r | r in unaligned /*where r mod w = 0*/}; % currently, that would over-constrain +set of int: generic_temp_domain(int: t1) = + if card(temp_domain[t1]) > 0 then + temp_domain[t1] + else + let {int: p = temp_def[t1], + set of int: rdom = array_union([temp_insn_regs(t1,j) | j in 1..MAXI]), + set of int: joker = if min(operand_temps[p])>=0 then {} else {-1} endif, % rematerialization + } in rdom union joker + endif; + constraint - forall(v in 0..MAXT) ( - let {int: p = temp_def[v], - int: w = temp_width[v], - set of int: rdom = array_union([temp_insn_regs(v,j) | j in 1..MAXI]), - set of int: joker = if min(operand_temps[p])>=0 then {} else {-1} endif, % rematerialization - } in r[v] in rdom union joker - ); + forall(t1 in 0..MAXT) (r[t1] in generic_temp_domain(t1)); %% operation selection (register set depending on operation) constraint @@ -665,45 +662,6 @@ constraint temp_is_real(q) -> temp_is_real(p) ); -% DISABLED, in favor of quasi_adjacent -% constraint % connected (out) inheriting from connected (in) -% forall(pout in 0..MAXP where op_type[operand_definer[pout]] = TYPE_OUT)( -% let {set of int: tsout = operand_temps[pout], -% set of int: tsoutbutnull = tsout diff {-1}, -% int: t1 = min(tsoutbutnull), -% int: oin = temp_definer[t1], -% int: pin = temp_def[t1], -% set of int: tsin = operand_temps[pin], -% set of int: tsc = {v | v in tsoutbutnull where op_type[temp_definer[v]] in {TYPE_IN,TYPE_COPY}}} in -% if min(tsout) = -1 /\ min(tsin) = -1 /\ op_type[oin] = TYPE_IN then -% t[pout] in tsc -> t[pin] >= 0 -% else true endif -% ); - -%?% constraint -%?% forall(j in index_set(adj_from)) ( -%?% let {int: p = adj_from[j], -%?% int: q = adj_to[j]} in ( -%?% rt[p] = -1 \/ rt[q] = -1 \/ rt[p] = rt[q] -%?% ) -%?% ); - -%?% adjacencies: (out) is connected iff some adjacent (in) is connected -%?% constraint -%?% forall(j in index_set(adj_from)) ( -%?% let {int: p = adj_from[j]} in ( -%?% rt[p] != -1 <-> exists(k in index_set(adj_from) where adj_from[k] = p)(rt[adj_to[k]] != -1) -%?% ) -%?% ); - -%?% adjacencies: (in) is connected iff all adjacent (out) are connected -%?% constraint -%?% forall(j in index_set(adj_to)) ( -%?% let {int: p = adj_to[j]} in ( -%?% rt[p] != -1 <-> forall(k in index_set(adj_to) where adj_to[k] = p)(rt[adj_from[k]] != -1) -%?% ) -%?% ); - %% aligned/adist constraint forall(j in index_set(aligned_use)) ( @@ -719,7 +677,12 @@ constraint %% disjoint live ranges constraint forall(T in bb_temps) ( - ra_diffn([r[v] | v in T], [temp_width[v] | v in T], [ls[v] | v in T], [ld[v] | v in T], [le[v] | v in T]) + ra_diffn([r[v] | v in T], + [temp_width[v] | v in T], + [generic_temp_domain(v) | v in T], + [ls[v] | v in T], + [ld[v] | v in T], + [le[v] | v in T]) ); %% precedences (with conditions added by presolver) @@ -728,23 +691,6 @@ constraint eval_expr(P) ); -%% ensure that all uses are within the live range -- pretty much subsumed by maximum(le[v], ...) -% constraint -% forall(p in 0..MAXP where operand_use[p]) -% (let {int: iuse = operand_definer[p], -% set of int: temps = operand_temps[p]} in ( -% forall(v in temps where v >= 0)( -% let {int: idef = temp_definer[v]} in ( -% if card(temps) = 1 then -% c[idef] + ld[v] >= c[iuse] -% else -% t[p] = v -> c[idef] + ld[v] >= c[iuse] -% endif -% ) -% ) -% ) -% ); - %% slack and balancing %% Model::global_operand @@ -807,40 +753,8 @@ predicate post_data_prec(int: q) = constraint forall(q in 0..MAXP where operand_use[q])(post_data_prec(q)); -%% Model::post_reverse_data_precedences_constraints -%% DISABLED, because it seems to clash with my slack fixing stuff -% set of int: global_definers(int: q) = {pd | t1 in real_temps(q), -% pd in {temp_def[t1]} -% where global_operand(pd) -% }; - -% var -MAXL..MAXL: slack_of_global_definer(int: q) = -% let {set of int: gds = global_definers(q)} in -% if card(gds)>0 then s[min(gds)] else 0 endif; - - -% constraint -% forall(o in 0..MAXO, p in op_operands[o] where not operand_use[p])( -% let {int: v = single_temp(p), -% array[int] of var int: acs = [ if t[q] = v then c[operand_definer[q]] - lat(q,v) - slack_of_global_definer(q) else 0 endif -% | q in temp_uses[v] -% ]} in -% if r[v] >= 0 then -% c[o] <= max(acs) -% else true endif -% ); - %% resources -% test unit_res_dur_cap(int: res, set of int: active) = ( -% forall(o in active)( -% fixedop(o) /\ -% res_con[res,min(op_instructions[o])]=res_cap[res] /\ -% res_dur[res,min(op_instructions[o])]=1 /\ -% res_off[res,min(op_instructions[o])]=0 -% ) -% ); - test unit_res_dur_cap(int: res, set of int: active) = ( forall(o in active, oi in op_instructions[o])( res_con[res,oi]=res_cap[res] /\ @@ -866,10 +780,9 @@ int: max_res_off(int: res, int: o) = ( ); constraint - forall(res in index_set(res_cap), b in 1..MAXB) ( + forall(b in 1..MAXB, res in index_set(res_cap) diff bb_subsumed[b]) ( let {set of int: active = {o | o in bb_ops[b] where - exists(q in op_instructions[o]) - (res_con[res,q]>0)}} in ( + exists(q in op_instructions[o])(res_con[res,q]>0)}} in ( if card(active)<=1 then true else if unit_res_dur_cap(res,active) then smart_alldiff([c[o] | o in active]) @@ -1011,6 +924,7 @@ constraint %% live temporary bool: hairy_live_temporary = false; +%% Model::post_connected_users_constraints constraint if hairy_live_temporary then forall(T in related_temps) ( @@ -1019,32 +933,39 @@ constraint array[irange] of var 0..card(tset): count, array[irange] of int: tarr = [x | x in tset]} in ( forall(j in irange)(count[j] >= bool2int(a[temp_definer[tarr[j]]])) /\ - global_cardinality([t(p) | p in 0..MAXP where can_use(p,tarr[1])], - tarr, count) + global_cardinality(temp_uses[tarr[1]], tarr, count) ) ) else forall(p in 0..MAXP where not operand_use[p])( let {int: v = single_temp(p)} in ( if temp_must_be_real(p) then - temp_member_reif({q | q in 0..MAXP where can_use(q,v)}, v, true) + temp_member_reif(temp_uses[v], v, true) else if opt_in_temporary(v) then let {var bool: rp} in (temp_is_real_reif(p,rp)) /\ - (temp_member_reif({q | q in 0..MAXP where can_use(q,v)}, v, rp)) + (temp_member_reif(temp_uses[v], v, rp)) else - temp_member_reif({q | q in 0..MAXP where can_use(q,v)}, v, a[operand_definer[p]]) + temp_member_reif(temp_uses[v], v, a[operand_definer[p]]) endif endif ) ) endif; -%% last use -- pretty much subsumed by maximum(le[v], ...) -% constraint -% forall(p in 0..MAXP where operand_use[p]) -% (t[p]>=0 -> le[t[p]] >= c[operand_definer[p]]) % rematerialization -% ; - +%% Model::post_connected_users_constraints +constraint + if good_member then + forall(p in 0..MAXP where not operand_use[p])( + let {int: v = single_temp(p)} in ( + if temp_must_be_real(p) then + member([rt[p] | p in temp_uses[v]], r[v]) + else + member([rt[p] | p in temp_uses[v]]++[-1], r[v]) + endif + ) + ) + else true endif; + %% disjoint live ranges projected on callee-saved regs constraint if good_cumulative then @@ -1062,28 +983,28 @@ constraint value_precede_chain(domop_temps[j], [t(o) | o in domop_operands[j]]) ); -%% mandatory temporary reuse (hairy!) -constraint - forall(j in index_set(domuse_p))( - let {int: P = domuse_p[j], % use operand - int: Q = domuse_q[j], % use operand - int: R = domuse_r[j], % def operand - int: T = min(operand_temps[R]), - int: I = operand_definer[P]} in ( - if not (op_type[I] in {TYPE_COMBINE,TYPE_LOW,TYPE_HIGH}) - % and not operand_lastuse[P] % guaranteed by model2dzn - % and forall(j in index_set(preassign_reg))(preassign_operand[j]!=P) % guaranteed by model2dzn - then - forall(atm in index_set(atom_regs))( - let {set of int: insns = {i | i in op_instructions[I] where i>0 /\ operand_atom[P,i]=atm}} in ( - if (card(insns)>=1) then - (temp_eq(Q,T) /\ insn_in(I,insns) /\ r[T] in atom_regs[atm] -> temp_eq(P,T)) - else true endif - ) - ) - else true endif - ) - ); +%% mandatory temporary reuse (hairy, and most likely useless) +% constraint +% forall(j in index_set(domuse_p))( +% let {int: P = domuse_p[j], % use operand +% int: Q = domuse_q[j], % use operand +% int: R = domuse_r[j], % def operand +% int: T = min(operand_temps[R]), +% int: I = operand_definer[P]} in ( +% if not (op_type[I] in {TYPE_COMBINE,TYPE_LOW,TYPE_HIGH}) +% % and not operand_lastuse[P] % guaranteed by model2dzn +% % and forall(j in index_set(preassign_reg))(preassign_operand[j]!=P) % guaranteed by model2dzn +% then +% forall(atm in index_set(atom_regs))( +% let {set of int: insns = {i | i in op_instructions[I] where i>0 /\ operand_atom[P,i]=atm}} in ( +% if (card(insns)>=1) then +% (temp_eq(Q,T) /\ insn_in(I,insns) /\ r[T] in atom_regs[atm] -> temp_eq(P,T)) +% else true endif +% ) +% ) +% else true endif +% ) +% ); %% before constraint @@ -1159,22 +1080,23 @@ constraint array[items] of int: cand = array1d(items, [across_item_temp[k] | k in items]), array[items] of var bool: active, - array[items] of var -maxwidth*(MAXT+1)..MAXR: selected, array[int] of var int: allreg = - [x | x in callersaved] ++ [x | x in regs] ++ selected, + [x | x in callersaved] ++ [x | x in regs] ++ [r[cand[k]] | k in items], array[int] of int: allwidth = [1 | x in callersaved] ++ [1 | x in regs] ++ - [temp_width[cand[k]] | k in items]} in ( + [temp_width[cand[k]] | k in items], + array[int] of var int: allresource = + [1 | x in callersaved] ++ + [1 | x in regs] ++ + active} in ( forall(k in items)( - let {int: ck = cand[k]} in ( + let {int: ck = cand[k]} in ( active[k] <-> eval_expr(across_item_cond[k]) \/ - (ls[ck] <= c[opi] /\ c[opi] < le[ck])) /\ - selected[k] = ite(active[k], r[ck], -maxwidth*(ck+1)) - ) + (ls[ck] <= c[opi] /\ c[opi] < le[ck])) ) /\ - noverlap(allreg, allwidth) + cumulative(allreg, allwidth, allresource, 1) ) ); @@ -1191,7 +1113,8 @@ constraint array[int] of var int: allreg = [x | x in callersaved] ++ [x | x in regs] ++ selected, array[int] of var int: allwidth = - [1 | x in callersaved] ++ [1 | x in regs] ++ width} in ( + [1 | x in callersaved] ++ [1 | x in regs] ++ width, + array[int] of int: allresource = [1 | x in allreg]} in ( forall(it in items)( let {set of int: cit = cands[it], array[int] of int: ws = [temp_width[k] | k in cit], @@ -1204,10 +1127,14 @@ constraint lss[k] <= c[opi] /\ c[opi] < les[k] ) ) /\ - noverlap(allreg, allwidth) + cumulative(allreg, allwidth, allresource, 1) ) ); +test can_clobber(int: ti, int: thea, int: thew) = + card(generic_temp_domain(ti) intersect (thea-temp_width[ti]+1 .. thea+thew-1))>0; + + %% spill callee-saved if and only if some temp interfers with it constraint if card(index_set(calleesaved_spill))>0 then @@ -1215,15 +1142,16 @@ constraint int: ncols = card(index_set_2of2(cs_spill_transpose)), set of int: css_ops = {cs_spill_transpose[j,k] | j in 1..nrows, k in 1..ncols}, set of int: preass_ops = {o | o in 0..MAXO where op_type[o] in {TYPE_IN,TYPE_CALL,TYPE_TAIL,TYPE_FUN}}, - set of int: tcands = {o | o in 0..MAXT where not (temp_definer[o] in css_ops union preass_ops)}} in ( + set of int: tcands = {t | t in 0..MAXT where not (temp_definer[t] in css_ops union preass_ops)}} in ( forall(j in 1..ncols) ( let {int: theop = cs_spill_transpose[1,j], int: thepu = min(op_operands[theop]), int: thetu = single_temp(thepu), int: thepd = temp_def[thetu], int: thea = min(k in index_set(preassign_reg) where preassign_operand[k]=thepd)(preassign_reg[k]), - int: thew = temp_width[thetu]} in ( - a[theop] <-> exists(ti in tcands)(r[ti]+temp_width[ti] > thea /\ r[ti] in 0..thea+thew-1) + int: thew = temp_width[thetu], + set of int: clcands = {t | t in tcands where can_clobber(t,thea,thew)}} in ( + a[theop] <-> exists(ti in clcands)(r[ti] > max(-1,thea-temp_width[ti]) /\ r[ti] < thea+thew) ) ) ) @@ -1244,15 +1172,9 @@ constraint else {} endif, set of int: unspill = if nrows>=2 then {cs_spill_transpose[2,j] | j in 1..ncols} else {} endif} in ( - forall(j in 1..nrows)( - decreasing([a[cs_spill_transpose[j,k]] | k in 1..ncols]) /\ - forall(k in 2..ncols)( - if j=1 then % spill - a[cs_spill_transpose[j,k]] -> c[cs_spill_transpose[j,k-1]] <= c[cs_spill_transpose[j,k]] - else % unspill - a[cs_spill_transpose[j,k]] -> c[cs_spill_transpose[j,k-1]] >= c[cs_spill_transpose[j,k]] - endif - ) + decreasing([a[cs_spill_transpose[1,k]] | k in 1..ncols]) /\ + forall(k in 2..ncols)( + a[cs_spill_transpose[1,k]] -> c[cs_spill_transpose[1,k-1]] <= c[cs_spill_transpose[1,k]] ) /\ if spill subset bb_ops[1] /\ unspill subset bb_ops[1] then forall(k in 1..ncols)( @@ -1266,33 +1188,17 @@ constraint else true endif; %% symmetry breaking from JSON info -constraint - forall(x in index_set(value_precede_min))( - let {set of int: js = value_precede_min[x]..value_precede_max[x], - int: nt = sum(j in js)(temp_width[value_precede_temps[j]]), - array[1..nt] of var int: chain = [r[v]+d | j in js, v in {value_precede_temps[j]}, d in 0..temp_width[v]-1]} in - value_precede_chain([v | v in value_precede_regs[x]], chain) - ); - -%% predecessors -- DISABLED -constraint - forall(x in index_set(predecessors_preds))( - min([c[o] | o in predecessors_preds[x]]) + predecessors_lat[x] <= c[predecessors_succ[x]] - ); - -%% successors -- DISABLED -constraint - forall(x in index_set(successors_succs))( - c[successors_pred[x]] + successors_lat[x] <= max([c[o] | o in successors_succs[x]]) - ); +%% DISABLED, cannot be trusted +% constraint +% forall(x in index_set(value_precede_min))( +% let {set of int: js = value_precede_min[x]..value_precede_max[x], +% int: nt = sum(j in js)(temp_width[value_precede_temps[j]]), +% array[1..nt] of var int: chain = [r[v]+d | j in js, v in {value_precede_temps[j]}, d in 0..temp_width[v]-1]} in +% value_precede_chain([v | v in value_precede_regs[x]], chain) +% ); %% IMPORTED FROM Model:: -%% live range length -% constraint % rematerialization -% forall(v in 0..MAXT where op_type[temp_definer[v]] != TYPE_IN) -% (a[temp_definer[v]] -> ld[v] >= temp_minlive[v]); - %% Model::post_minimum_temporary_duration_constraints constraint forall(o in 0..MAXO, dp in op_operands[o] where not operand_use[dp])( @@ -1349,27 +1255,6 @@ constraint endif ); -%% Model::post_slack_lower_bound_constraints -% constraint -% forall(C in congr)( -% let {set of int: CG = {p | p in C where global_operand(p)}, -% array[int] of int: ins = [p | p in CG where op_type[operand_definer[p]] = TYPE_IN], -% array[int] of int: outs = [p | p in CG where op_type[operand_definer[p]] = TYPE_OUT], -% array[int] of var int: inlats = [lt[q] | p in ins, -% q in temp_uses[single_temp(p)]], -% array[int] of var int: outlats = [lt[q] | p in outs, -% v in real_temps(p), -% q in {temp_def[v]}]} in -% if (length(ins)>0) then -% let {var int: maxinlat = max(inlats)} in -% forall(p in ins)(trace("s[\(p)] >= -max(\(inlats))\n", s[p] >= - maxinlat)) -% else true endif /\ -% if (length(outs)>0) then -% let {var int: maxoutlat = max(outlats)} in -% forall(p in outs)(trace("s[\(p)] >= -max(\(outlats))\n", s[p] >= - maxoutlat)) -% else true endif -% ); - %% [matsc] domination constraint for slack, in fact make it a functional dependency %% N.B. Subsumes post_slack_lower_bound_constraints %% N.B. MAY clash with post_reverse_data_precedences_constraints @@ -1400,6 +1285,26 @@ constraint forall(p in outps)(s[p] = min(outub,max(outlb,0))) ); +%% domination constraint: sequential schedule as a makespan UB +%% Model::post_sequential_upper_bound_constraints +constraint + forall(bb in index_set(bb_ops))( + let {set of int: os = bb_ops[bb], + array[os] of var 0..MAXC: wc = array1d(os, [o_wcet(o) | o in os])} + in c[max(os)] <= sum(o in os)(wc[o]) + ); + +var 0..MAXC: o_wcet(0..MAXO: o) = + let {array[int] of var int: wcs = [wcet[jj,3] | jj in index_set_1of2(wcet) where wcet[jj,1] = o], + int: nwcs = length(wcs)} + in if forall(jj in 1..nwcs)(wcs[jj] = 1) + then a[o] + else if not op_mand[o] /\ forall(jj in 2..nwcs)(wcs[jj] = 1) + then a[o] + else + wcs[ii[o]] + endif endif; + %% output output diff --git a/src/solvers/multi_backend/minizinc/minizinc-solver b/src/solvers/multi_backend/minizinc/minizinc-solver index dc3ed2d8..bce71cdf 100755 --- a/src/solvers/multi_backend/minizinc/minizinc-solver +++ b/src/solvers/multi_backend/minizinc/minizinc-solver @@ -9,8 +9,10 @@ allsolns='-a' mzn='mzn-gecode' cumulative='true' diffn='true' +member='true' ncores='1' statflag='-s' +lbflag='' toflag='' toprefix='--fzn-flag --time-out --fzn-flag ' freeflag='' @@ -18,6 +20,7 @@ freedefault='--fzn-flag -f' rndflag='' nogoods='' lbfile='-' +dznfile='-' setuponly='false' tail=' ' while [ $# -gt 1 ]; do @@ -44,13 +47,9 @@ while [ $# -gt 1 ]; do --cpx) mzn='mzn-cpx' ;; - --chuffed | --chuffed21) - mzn='mzn-chuffed --fzn-flag --verbosity --fzn-flag 3' - ;; - --chuffed20) + --chuffed) mzn='mzn-chuffed' - statflag='--fzn-flag -verbosity=3' - toprefix='--fzn-flag -time_out=' + lbflag='--fzn-flag --verbosity --fzn-flag 3' ;; --or-tools) mzn='mzn-or-tools' @@ -75,6 +74,15 @@ while [ $# -gt 1 ]; do --no-diffn) diffn='false' ;; + --member) + member='true' + ;; + --no-member) + member='false' + ;; + --no-lb) + lbflag='' + ;; --free) freeflag=$freedefault ;; @@ -103,6 +111,10 @@ while [ $# -gt 1 ]; do lbfile=$1 shift ;; + -dzn) + dznfile=$1 + shift + ;; --fzn-flag) tail=$tail'--fzn-flag '$1' ' shift @@ -113,19 +125,25 @@ while [ $# -gt 1 ]; do esac done DIRBASENAME=${1%.ext.json} -EXTJSON=$1 -shift -echo "json2dzn('${EXTJSON}'),halt." | sicstus -f --nologo --noinfo -l $MINIZINC_DIR/model2dzn.pl +if [ $dznfile == '-' ]; then + EXTJSON=$1 + dznfile=$DIRBASENAME.dzn + shift + echo "json2dzn('${EXTJSON}'),halt." | sicstus -f --nologo --noinfo -l $MINIZINC_DIR/model2dzn.pl +fi cat $MINIZINC_DIR/code-generation.mzn $MINIZINC_DIR/${search} > $DIRBASENAME.mzn -if [ '$mzn' = 'mzn-gecode' ]; then +if [ $mzn = 'mzn-gecode' ]; then pflag='-p' pvalue=${ncores} else pflag='' pvalue='' fi +if [ $lbfile != '-' ]; then + statflag=$statflag' '$lbflag +fi if [ $setuponly = true ]; then exit 0 fi set -x -time ${mzn} ${allsolns} ${statflag} ${pflag} ${pvalue} ${freeflag} ${rndflag} ${toflag} ${nogoods} -D good_cumulative=${cumulative} -D good_diffn=${diffn} ${tail} $DIRBASENAME.mzn $DIRBASENAME.dzn | $COMMON_DIR/outfilter.pl ${OUTJSON}.last ${lbfile} > ${OUTJSON} +time ${mzn} ${allsolns} ${statflag} ${pflag} ${pvalue} ${freeflag} ${rndflag} ${toflag} ${nogoods} -D good_cumulative=${cumulative} -D good_diffn=${diffn} -D good_member=${member} ${tail} $DIRBASENAME.mzn $dznfile | $COMMON_DIR/outfilter.pl ${OUTJSON}.last ${lbfile} | aeson-pretty > ${OUTJSON} diff --git a/src/solvers/multi_backend/minizinc/minizinc-twophase-solver b/src/solvers/multi_backend/minizinc/minizinc-twophase-solver new file mode 100755 index 00000000..17dbb77d --- /dev/null +++ b/src/solvers/multi_backend/minizinc/minizinc-twophase-solver @@ -0,0 +1,168 @@ +#!/bin/bash +# Assumes that the environment variable UNISON_DIR is set to the top of the +# Unison repo +MULTIBACKEND_DIR=$UNISON_DIR/src/solvers/multi_backend +MINIZINC_DIR=$MULTIBACKEND_DIR/minizinc +COMMON_DIR=$MULTIBACKEND_DIR/common +search='topdown.mzn' +allsolns='-a' +mzn='mzn-gecode' +cumulative='true' +diffn='true' +member='true' +ncores='1' +statflag='-s' +lbflag='' +toflag='' +toprefix='--fzn-flag --time-out --fzn-flag ' +freeflag='' +freedefault='--fzn-flag -f' +rndflag='' +nogoods='' +lbfile='-' +dznfile='-' +setuponly='false' +tail=' ' +while [ $# -gt 1 ]; do + opt="$1" + shift + case "${opt}" in + --bottomup | --bottom-up | --bottom_up) + search='bottomup.mzn' + allsolns='' + ;; + --topdown | --top-down | --top_down) + search='topdown.mzn' + allsolns='-a' + ;; + --gecode) + mzn='mzn-gecode' + ;; + --sicstus) + mzn='mzn-sicstus' + ;; + --g12cpx) + mzn='mzn-g12cpx' + ;; + --cpx) + mzn='mzn-cpx' + ;; + --chuffed) + mzn='mzn-chuffed' + lbflag='--fzn-flag --verbosity --fzn-flag 3' + ;; + --or-tools) + mzn='mzn-or-tools' + freedefault='--fzn-flag --free_search' + toprefix='--fzn-flag -time_limit --fzn-flag ' + ;; + --or-tools-sat) + mzn='mzn-or-tools-sat' + statflag='--fzn-flag --fz_logging' + freedefault='--fzn-flag --free_search' + toprefix='--fzn-flag -time_limit --fzn-flag ' + ;; + --cumulative) + cumulative='true' + ;; + --no-cumulative) + cumulative='false' + ;; + --diffn) + diffn='true' + ;; + --no-diffn) + diffn='false' + ;; + --member) + member='true' + ;; + --no-member) + member='false' + ;; + --no-lb) + lbflag='' + ;; + --free) + freeflag=$freedefault + ;; + --rnd) + rndflag='--fzn-flag --rnd-seed --fzn-flag 123456' + ;; + --vsids) + freeflag='--fzn-flag -vsids=true' + ;; + --to) + toflag=$toprefix$1 + shift + ;; + --nogoods) + nogoods='--fzn-flag --learnt-stats-nogood' + ;; + -o) + OUTJSON=$1 + shift + ;; + -p) + ncores=$1 + shift + ;; + -l) + lbfile=$1 + shift + ;; + -dzn) + dznfile=$1 + shift + ;; + --fzn-flag) + tail=$tail'--fzn-flag '$1' ' + shift + ;; + --setuponly) + setuponly=true + ;; + esac +done +DIRBASENAME=${1%.ext.json} +if [ $dznfile == '-' ]; then + EXTJSON=$1 + dznfile=$DIRBASENAME.dzn + shift + echo "json2dzn('${EXTJSON}'),halt." | sicstus -f --nologo --noinfo -l $MINIZINC_DIR/model2dzn.pl +fi +if [ $mzn = 'mzn-gecode' ]; then + pflag='-p' + pvalue=${ncores} +else + pflag='' + pvalue='' +fi +if [ $lbfile != '-' ]; then + statflag=$statflag' '$lbflag +fi +if [ $setuponly = true ]; then + exit 0 +fi + +radznfile=$DIRBASENAME.ra.dzn +isdznfile=$DIRBASENAME.is.dzn + +set -x + +cp $dznfile $radznfile +printf "ii_soln = [];\n" >> $radznfile +printf "rt_soln = [];\n" >> $radznfile +printf "y_soln = [];\n" >> $radznfile +printf "r_soln = [];\n" >> $radznfile + +cat $MINIZINC_DIR/code-generation-twophase.mzn $MINIZINC_DIR/${search} > $DIRBASENAME.mzn + +time ${mzn} ${allsolns} ${statflag} ${pflag} ${pvalue} ${freeflag} ${rndflag} ${toflag} ${nogoods} -D good_cumulative=${cumulative} -D good_diffn=${diffn} -D good_member=${member} -D phase=1 ${tail} $DIRBASENAME.mzn $radznfile | $COMMON_DIR/outfilter.pl ${OUTJSON}.last ${lbfile} > ${OUTJSON}.ra + +cp $dznfile $isdznfile +grep _soln $OUTJSON.ra | sed 's/;,/;/g' >> $isdznfile + +time ${mzn} ${allsolns} ${statflag} ${pflag} ${pvalue} ${freeflag} ${rndflag} ${toflag} ${nogoods} -D good_cumulative=${cumulative} -D good_diffn=${diffn} -D good_member=${member} -D phase=2 ${tail} $DIRBASENAME.mzn $isdznfile | $COMMON_DIR/outfilter.pl ${OUTJSON}.last ${lbfile} > ${OUTJSON}.is + +grep -v _soln $OUTJSON.is | aeson-pretty > $OUTJSON diff --git a/src/solvers/multi_backend/minizinc/model2dzn.pl b/src/solvers/multi_backend/minizinc/model2dzn.pl index 0c1eafca..2acfa40d 100644 --- a/src/solvers/multi_backend/minizinc/model2dzn.pl +++ b/src/solvers/multi_backend/minizinc/model2dzn.pl @@ -71,15 +71,16 @@ ), avl_store(use, AVL0, Use, AVL), compute_bb(AVL, MAXF, MAXO, MAXP, MAXT, MAXC, MAXI, MAXR, - BInsns, BOperands, BTemps, Frequency, MaxCycle, OptionalMin, BBOrder), + BInsns, BOperands, BTemps, BSubsumed, Frequency, MaxCycle, OptionalMin, BBOrder), format('MAXF = ~d;\nMAXO = ~d;\nMAXP = ~d;\nMAXT = ~d;\nMAXC = ~d;\nMAXI = ~d;\nMAXR = ~d;\n', [MAXF, MAXO, MAXP, MAXT, MAXC, MAXI, MAXR]), length(BInsns, Nbb), avl_fetch(optimize_resource, AVL0, OptRes), - (OptRes = [-1] -> OptCyc = true ; OptCyc = false), + (OptRes = [-1|_] -> OptCyc = true; OptCyc = false), format('optimize_cycles = ~w;\n', [OptCyc]), write_array(bb_ops, array(1..Nbb,set(int)), BInsns), write_array(bb_operands, array(1..Nbb,set(int)), BOperands), write_array(bb_temps, array(1..Nbb,set(int)), BTemps), + write_array(bb_subsumed, array(1..Nbb,set(int)), BSubsumed), write_array(bb_frequency, array(1..Nbb,int), Frequency), write_array(bb_maxcycle, array(1..Nbb,int), MaxCycle), write_array(bb_optional_min, array(1..Nbb,int), OptionalMin), @@ -303,6 +304,7 @@ write_array(domop_operands, array(1..Ndomop, set(int)), DomopOpnds), write_array(domop_temps, array(1..Ndomop, set(int)), DomopTemps), % + avl_fetch(preassign, AVL, Preassign), avl_fetch(domuses, AVL, Domuse), ( foreach([P2,Q2,R2],Domuse), fromto(Ps1,Ps2,Ps3,[]), @@ -405,28 +407,6 @@ write_array(activator_insns, array(1.._,set(int)), ActInsns1), write_array(activator_ops, array(1.._,set(int)), ActOps1), % - avl_fetch(predecessors, AVL, Predecessors), - ( foreach([PPred,PSucc,PLat],Predecessors), - foreach(PPredSet,PPredSets), - foreach(PSucc,PSuccs), - foreach(PLat,PLats) - do encode(list(int), set(int), PPred, PPredSet) - ), - write_array(predecessors_preds, array(1.._,set(int)), PPredSets), - write_array(predecessors_succ, array(1.._,int), PSuccs), - write_array(predecessors_lat, array(1.._,int), PLats), - % - avl_fetch(successors, AVL, Successors), - ( foreach([PPred2,PSucc2,PLat2],Successors), - foreach(PSuccSet2,PSuccSets2), - foreach(PPred2,PPreds2), - foreach(PLat2,PLats2) - do encode(list(int), set(int), PSucc2, PSuccSet2) - ), - write_array(successors_succs, array(1.._,set(int)), PSuccSets2), - write_array(successors_pred, array(1.._,int), PPreds2), - write_array(successors_lat, array(1.._,int), PLats2), - % avl_fetch(value_precede_chains, AVL, VPChain), ( foreach([VPTs,VPRss],VPChain), foreach(VPTs,VPTss), @@ -491,6 +471,17 @@ length(Adhoc1, Nadhoc), write_array(adhoc, array(1..Nadhoc,int), Adhoc2), % + avl_fetch(temp_domain, AVL, TempDomain1), + ( foreach(TD1,TempDomain1), + foreach(TD2,TempDomain2) + do list_to_fdset(TD1, TD2) + ), + write_array(temp_domain, array(0..MAXT,set(int)), TempDomain2), + % + compute_wcet(AVL, Wcet), + length(Wcet, WcetLen), + write_array(wcet, array(1..WcetLen,1..2,int), Wcet), + % exprs_postlude(LOp, LArg1, LArg2, LArg3, Lchildren), length(LOp, Nexpr), write_array(expr_op, array(1..Nexpr,int), LOp), @@ -502,6 +493,106 @@ length(Sets, Nset), write_array(sets, array(1..Nset,set(int)), Sets). +compute_wcet(AVL, Wcet1) :- + avl_fetch(ops, AVL, Opss), + avl_fetch(instructions, AVL, Insns), + avl_fetch(operands, AVL, Operands), + avl_fetch(lat, AVL, Lat), + avl_fetch(con, AVL, Con), + avl_fetch(dur, AVL, Dur), + avl_fetch(off, AVL, Off), + avl_fetch(dep, AVL, Dep), + avl_fetch(dist, AVL, Dist), + append(Dep, DepF), + append(Dist, DistF), + avl_fetch(use, AVL, Use), + avl_fetch(def_opr, AVL, DefOpr), + avl_fetch(minlive, AVL, MinLive), + ( foreach(U,Use), + fromto(UseSet1,UseSet2,UseSet3,[]), + count(P,0,_) + do (U = 1 -> UseSet2 = [P|UseSet3] ; UseSet2 = UseSet3) + ), + ( foreach([Src,_],DepF), + foreach(Dis,DistF), + foreach(Src-Dis,Src2Dis1) + do true + ), + keysort(Src2Dis1, Src2Dis2), + keyclumped(Src2Dis2, Src2Dis3), + ord_list_to_avl(Src2Dis3, Src2DisAVL), + ( foreach(DO,DefOpr), + foreach(ML,MinLive), + foreach(DO-ML,O2ML1) + do true + ), + keysort(O2ML1, O2ML2), + keyclumped(O2ML2, O2ML3), + ord_list_to_avl(O2ML3, O2MLAVL), + ( foreach(Ops1,Opss), + foreach(Block1,Blocks), + foreach(Last1,Lasts), + fromto(Insns,InsnsTail1,InsnsTail2,[]), + fromto(Operands,OperandsTail1,OperandsTail2,[]), + fromto(Lat,LatTail1,LatTail2,[]) + do length(Ops1, N), + prefix_length(InsnsTail1, Insns1, N), + length(Insns1, N), + append(Insns1, InsnsTail2, InsnsTail1), + prefix_length(OperandsTail1, Operands1, N), + length(Operands1, N), + append(Operands1, OperandsTail2, OperandsTail1), + prefix_length(LatTail1, Lat1, N), + length(Lat1, N), + append(Lat1, LatTail2, LatTail1), + last(Ops1, Last1), + transpose([Ops1,Insns1,Operands1,Lat1], Block1) + ), + ( foreach(Block2,Blocks), + foreach(Last2,Lasts), + fromto(Wcet1,Wcet2,Wcet7,[]), + param(Con,Dur,Off,UseSet1,Src2DisAVL,O2MLAVL) + do ( foreach([O2,InsnsO2,OperandsO2,LatO2],Block2), + fromto(Wcet2,Wcet3,Wcet6,Wcet7), + param(Con,Dur,Off,UseSet1,Src2DisAVL,O2MLAVL,Last2) + do ( O2 = Last2 -> Wcet3 = [[O2,0]|Wcet6] + ; ( foreach(_,InsnsO2), + foreach([0],Src2DisO2Tdefault) + do true + ), + ( avl_fetch(O2, Src2DisAVL, Src2DisO2) -> transpose(Src2DisO2, Src2DisO2T) ; Src2DisO2T = Src2DisO2Tdefault), + ( avl_fetch(O2, O2MLAVL, MLs) -> max_member(MaxMinLive, MLs) ; MaxMinLive = 0), + ( foreach(I,InsnsO2), + foreach(LatO2II,LatO2), + foreach(Src2DisO2TII,Src2DisO2T), + fromto(Wcet3,Wcet4,Wcet5,Wcet6), + param(O2,Con,Dur,Off,UseSet1,OperandsO2,MaxMinLive) + do Wcet4 = [[O2,W]|Wcet5], + nth0(I, Con, ConI), + nth0(I, Dur, DurI), + nth0(I, Off, OffI), + ( foreach(CI,ConI), + foreach(DI,DurI), + foreach(OI,OffI), + fromto(0,MaxDur1,MaxDur2,MaxDur3) + do (CI = 0 -> MaxDur2 = MaxDur1 ; MaxDur2 is max(MaxDur1,DI + OI)) + ), + ( foreach(LatO2IIP,LatO2II), + foreach(P1,OperandsO2), + fromto(0,MaxUseLat1,MaxUseLat2,MaxUseLat3), + fromto(0,MaxDefLat1,MaxDefLat2,MaxDefLat3), + param(UseSet1) + do ( ord_member(P1, UseSet1) -> MaxUseLat2 is max(MaxUseLat1,LatO2IIP), MaxDefLat2 = MaxDefLat1 + ; otherwise -> MaxDefLat2 is max(MaxDefLat1,LatO2IIP), MaxUseLat2 = MaxUseLat1 + ) + ), + max_member(MaxDist3, Src2DisO2TII), + W is max(MaxDur3, max(MaxUseLat3 + MaxDefLat3, max(MaxDist3, MaxMinLive))) + ) + ) + ) + ). + pairs_to_arrays(AVL, Tag, FirstArr, SecondArr) :- avl_fetch(Tag, AVL, Data), ( foreach([X1,Y1],Data), @@ -525,19 +616,22 @@ write_array(SecondArr, array(0..M,int), DataY). compute_bb(AVL, MAXF, MAXO, MAXP, MAXT, MAXC, MAXI, MAXR, - Insns, Operands, Temps, Frequency, MaxCycle, OptionalMin, BBOrder) :- - avl_fetch(maxf, AVL, MAXF), + Insns, Operands, Temps, Subsumed, Frequency, MaxCycle, OptionalMin, BBOrder) :- + avl_fetch(maxf, AVL, [MAXF|_]), avl_fetch(freq, AVL, Frequency), avl_fetch(maxc, AVL, MaxCycle), avl_fetch(optional_min, AVL, OptionalMin), avl_fetch(ops, AVL, Ops), avl_fetch(tmp, AVL, Tmp), + avl_fetch(subsumed_resources, AVL, Subsumed1), avl_fetch(operands, AVL, AllOperands), ( foreach(Op1,Ops), foreach(Tmp1,Tmp), + foreach(Sub1,Subsumed1), foreach([[OpMin|OpMax]], Insns), - foreach(Opnds1, Operands), - foreach(Tmps1, Temps), + foreach(Opnds1,Operands), + foreach(Tmps1,Temps), + foreach(Sub,Subsumed), fromto(bb(-1,-1,-1),bb(OpPrev,OpndPrev,TmpPrev),bb(OpMax,OpndMax,TmpMax), bb(MAXO,MAXP,MAXT)), foreach(NLen-BB1,KL1), @@ -551,6 +645,11 @@ TmpMin is TmpPrev+1, last(Op1, OpMax), NLen is OpMin-OpMax, + ( foreach(R1,Sub1), + foreach(R2,Sub2) + do R2 is R1+1 + ), + list_to_fdset(Sub2, Sub), ( Tmp1 = [] % no temps, no opnds? -> TmpMax is TmpMin-1, OpndMax is OpndMin-1, diff --git a/src/solvers/multi_backend/portfolio-solver b/src/solvers/multi_backend/portfolio-solver index f7508020..0ce809d9 100755 --- a/src/solvers/multi_backend/portfolio-solver +++ b/src/solvers/multi_backend/portfolio-solver @@ -3,5 +3,5 @@ # Unison repo MULTIBACKEND_DIR=$UNISON_DIR/src/solvers/multi_backend # Assume aeson-pretty-0.7.2 which prints integers without decimals -ghc -O2 --make -threaded $MULTIBACKEND_DIR/portfolio.hs -package aeson-pretty-0.7.2 +ghc -O2 --make -threaded $MULTIBACKEND_DIR/portfolio.hs $MULTIBACKEND_DIR/portfolio "$@" +RTS -N2 diff --git a/src/solvers/multi_backend/portfolio.hs b/src/solvers/multi_backend/portfolio.hs index a4ea019d..be56a338 100644 --- a/src/solvers/multi_backend/portfolio.hs +++ b/src/solvers/multi_backend/portfolio.hs @@ -3,7 +3,7 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Runs 'gecode-solver' and 'minizinc-solver' (with 'chuffed') in parallel, returning the result of the fastest solver. @@ -11,7 +11,7 @@ returning the result of the fastest solver. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -23,6 +23,7 @@ import Data.Aeson.Encode.Pretty import Data.Int import Data.Ord import Data.List +import Data.Maybe import qualified Data.Text.Lazy.Builder as DTB import Data.Scientific import qualified Data.ByteString.Lazy.Char8 as BSL @@ -50,7 +51,8 @@ data Portfolio = chuffedFlags :: String, timeOut :: Maybe Integer, memLimit :: Bool, - lowerBoundFile :: FilePath} + lowerBoundFile :: FilePath, + initialGapFile :: FilePath} deriving (Data, Typeable, Show) data Solver = Gecode | Chuffed | NoSolver deriving Eq @@ -60,11 +62,12 @@ portfolioArgs = cmdArgsMode $ Portfolio inFile = "" &= argPos 1 &= typFile, outFile = "" &= name "o" &= help "Output file name" &= typFile, verbose = False &= name "v" &= help "Run solvers in verbose mode", - gecodeFlags = "" &= help "Flags passed to the Gecode solver", + gecodeFlags = "" &= name "e" &= help "Flags passed to the Gecode solver", chuffedFlags = "" &= help "Flags passed to the Chuffed solver", timeOut = Nothing &= help "Timeout for both solvers (in seconds)", memLimit = True &= help "Limit the use of memory by Chuffed to 16 GB", - lowerBoundFile = "" &= name "l" &= help "Lower bound file" &= typFile + lowerBoundFile = "" &= name "l" &= help "Lower bound file" &= typFile, + initialGapFile = "" &= name "g" &= help "Initial optimality gap file" &= typFile } gecodeFile :: FilePath -> String @@ -72,10 +75,11 @@ gecodeFile outJsonFile = outJsonFile ++ ".gecode" chuffedFile :: FilePath -> String chuffedFile outJsonFile = outJsonFile ++ ".chuffed" -runGecode flags to v extJson lowerBoundFile outJsonFile = +runGecode flags to v extJson lowerBoundFile initialGapFile outJsonFile = do tryUntilSuccess $ callProcess "gecode-solver" (["-o", outJsonFile] ++ (if null lowerBoundFile then [] else ["-l", lowerBoundFile]) ++ + (if null initialGapFile then [] else ["-g", initialGapFile]) ++ ["-verbose" | v] ++ (splitFlags flags) ++ (gecodeTimeoutFlags to) ++ [extJson]) @@ -106,11 +110,12 @@ runChuffed flags to memLimit extJson lowerBoundFile outJsonFile = "--setuponly"] ++ (if null lowerBoundFile then [] else ["-l", lowerBoundFile]) ++ (splitFlags flags) ++ + ["-dzn", prefix extJson ++ ".dzn"] ++ [extJson]) -- now call the underlying 'minizinc' process that is killable (unlike -- what is executed from 'minizinc-solver') let mznChuffed = if memLimit then "mzn-crippled-chuffed" else "mzn-chuffed" - pre = (take (length extJson - 9) extJson) + pre = prefix extJson mzn = pre ++ ".mzn" dzn = pre ++ ".dzn" out = pre ++ ".out" @@ -122,7 +127,8 @@ runChuffed flags to memLimit extJson lowerBoundFile outJsonFile = chuffedTimeoutFlags to) ++ ["-a", "-s", "-D", "good_cumulative=true", - "-D", "good_diffn=false"] ++ + "-D", "good_diffn=false", + "-D", "good_member=true"] ++ [mzn, dzn, "-o", out]) -- finally, invoke 'outfilter' to format the output inf <- openFile out ReadMode @@ -137,6 +143,8 @@ runChuffed flags to memLimit extJson lowerBoundFile outJsonFile = hClose outf return outJsonFile +prefix extJson = take (length extJson - 9) extJson + fznFlag opt = ["--fzn-flag", opt] chuffedTimeoutFlags to @@ -189,6 +197,12 @@ strictHGetContents h = timeoutFactor = 1000000 +checkExecutableExists exe = + do result <- findExecutable exe + let msg = "could not find executable '" ++ exe ++ "'" + when (isNothing result) (ioError (userError msg)) + return () + main = do Portfolio{..} <- cmdArgsRun portfolioArgs let baseOutFile = outFile ++ ".base" @@ -202,11 +216,14 @@ main = then error ("exceeded maximum timeout") else s * timeoutFactor Nothing -> -1 + mapM_ checkExecutableExists + ["gecode-solver", "minizinc-solver", "mzn-crippled-chuffed", + "mzn-chuffed", "fzn-chuffed", "outfilter.pl"] start <- getCurrentTime result <- timeout (fromInteger to) (race (runGecode gecodeFlags to verbose inFile - gecodeLowerBoundFile gecodeOutFile) + gecodeLowerBoundFile initialGapFile gecodeOutFile) (runChuffed chuffedFlags to memLimit inFile chuffedLowerBoundFile chuffedOutFile)) end <- getCurrentTime @@ -297,7 +314,7 @@ cost out = let sol = parseJson out cost = lookupOrFail "sol" sol "cost" -- Assumes a single goal as the minizinc solver does not support more - [c] = (fromJson cost) :: [Integer] + c:_ = (fromJson cost) :: [Integer] in if c == -1 then maxInt else c maxInt = toInteger (maxBound - 1 :: Int32) @@ -305,7 +322,8 @@ maxInt = toInteger (maxBound - 1 :: Int32) lowerBound lowerBoundJson = let json = parseJson lowerBoundJson lbj = lookupOrFail "json" json "lower_bound" - [lb] = (fromJson lbj) :: [Integer] + -- Assumes a single goal as the minizinc solver does not support more + lb:_ = (fromJson lbj) :: [Integer] in lb freqFactor input = diff --git a/src/stack.yaml b/src/stack.yaml new file mode 100644 index 00000000..6a1644d1 --- /dev/null +++ b/src/stack.yaml @@ -0,0 +1,68 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# https://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2018-01-01.yaml +resolver: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/12/26.yaml + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# subdirs: +# - auto-update +# - wai +packages: +- unison +- unison-specsgen +# Dependency packages to be pulled from upstream that are not in the resolver. +# These entries can reference officially published versions as well as +# forks / in-progress versions pinned to a git hash. For example: +# +# extra-deps: +# - acme-missiles-0.3 +# - git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# +# extra-deps: [] + +# Override default flag values for local packages and extra-deps +# flags: {} + +# Extra package databases containing global packages +# extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of Stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=2.9" +# +# Override the architecture used by Stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by Stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor diff --git a/src/stack.yaml.lock b/src/stack.yaml.lock new file mode 100644 index 00000000..75b3ac6a --- /dev/null +++ b/src/stack.yaml.lock @@ -0,0 +1,13 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + sha256: 95f014df58d0679b1c4a2b7bf2b652b61da8d30de5f571abb0d59015ef678646 + size: 509471 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/12/26.yaml + original: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/12/26.yaml diff --git a/src/unison-specsgen/Setup.hs b/src/unison-specsgen/Setup.hs index e1a011ac..796e6b39 100644 --- a/src/unison-specsgen/Setup.hs +++ b/src/unison-specsgen/Setup.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/exec/specsgen/Main.hs b/src/unison-specsgen/exec/specsgen/Main.hs index d64b8dd8..2304fc1e 100644 --- a/src/unison-specsgen/exec/specsgen/Main.hs +++ b/src/unison-specsgen/exec/specsgen/Main.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Daniel Lundén diff --git a/src/unison-specsgen/src/SpecsGen/AlignedPairsGen.hs b/src/unison-specsgen/src/SpecsGen/AlignedPairsGen.hs index 4bb745ad..d4bcf256 100644 --- a/src/unison-specsgen/src/SpecsGen/AlignedPairsGen.hs +++ b/src/unison-specsgen/src/SpecsGen/AlignedPairsGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/AllInstructionsGen.hs b/src/unison-specsgen/src/SpecsGen/AllInstructionsGen.hs index eb4d01f3..550f6a0a 100644 --- a/src/unison-specsgen/src/SpecsGen/AllInstructionsGen.hs +++ b/src/unison-specsgen/src/SpecsGen/AllInstructionsGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/Driver.hs b/src/unison-specsgen/src/SpecsGen/Driver.hs index f70960e5..6d127798 100644 --- a/src/unison-specsgen/src/SpecsGen/Driver.hs +++ b/src/unison-specsgen/src/SpecsGen/Driver.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Daniel Lundén @@ -37,6 +37,7 @@ import SpecsGen.InstructionTypeGen import SpecsGen.AllInstructionsGen import SpecsGen.ItineraryDeclGen import SpecsGen.ParentGen +import SpecsGen.RegisterClassDeclGen data SpecsGen = SpecsGen {files :: [FilePath], targetName :: String, outputDir :: String, @@ -60,7 +61,7 @@ specsgen = cmdArgsMode $ SpecsGen rematFile = Nothing, preProcessFile = Nothing } - &= summary "Generates partial Haskell files (.hs) with target information from the given YAML description (.yaml)\nRoberto Castaneda Lozano roberto.castaneda@ri.se" + &= summary "Generates partial Haskell files (.hs) with target information from the given YAML description (.yaml)\nRoberto Castaneda Lozano rcas@acm.org" runSpecsGen tPreMod tExtension = do sg @ SpecsGen{..} <- cmdArgsRun specsgen @@ -93,6 +94,7 @@ runSpecsGen tPreMod tExtension = writeHsFile outputDir "AllInstructions" (emitAllInstructions targetName is8) writeHsFile outputDir (targetName ++ "ItineraryDecl") (emitItineraryDecl targetName is8) writeHsFile outputDir "Parent" (emitParent targetName is8) + writeHsFile outputDir (targetName ++ "RegisterClassDecl") (emitRegisterClassDecl targetName is8) tExtension sg is8 maybePreProcess "" is = is @@ -113,7 +115,8 @@ maybeUpdateFile _ (Just oldContent) newContent maybeUpdateFile name _ newContent = writeFile name newContent -yamlInstructions = yInstructions . simplify . decodeYaml +yamlInstructions "" = [] +yamlInstructions is = yInstructions $ simplify $ decodeYaml is topComment = "-- This file has been generated by specsgen. Do not modify by hand!\n\n" diff --git a/src/unison-specsgen/src/SpecsGen/HsGen.hs b/src/unison-specsgen/src/SpecsGen/HsGen.hs index 48bbec7c..f54616bf 100644 --- a/src/unison-specsgen/src/SpecsGen/HsGen.hs +++ b/src/unison-specsgen/src/SpecsGen/HsGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -38,6 +38,7 @@ module SpecsGen.HsGen hsFun, hsDataDecl, hsItinDecl, + hsRegClassDecl, hsInstDecl, opcPVar, mkOpcRhs, @@ -325,7 +326,7 @@ itineraryDeclImport targetName = targetName ++ "ItineraryDecl") registerClassDeclImport targetName = - hsImport ("Unison.Target." ++ targetName ++ "." ++ + hsImport ("Unison.Target." ++ targetName ++ ".SpecsGen." ++ targetName ++ "RegisterClassDecl") hsImport n = HsImportDecl dummySrcLoc (Module n) False Nothing Nothing @@ -363,12 +364,17 @@ simpleErrorRhs n = hsDataDecl targetName cs = HsDataDecl dummySrcLoc [] (HsIdent (targetInstructionCon targetName)) [] - [HsConDecl dummySrcLoc (HsIdent c) [] | c <- cs] + [HsConDecl dummySrcLoc (HsIdent (toOpType c)) [] | c <- cs] [name "Eq", name "Ord"] hsItinDecl targetName cs = HsDataDecl dummySrcLoc [] (HsIdent (targetName ++ "Itinerary")) [] - [HsConDecl dummySrcLoc (HsIdent c) [] | c <- cs] + [HsConDecl dummySrcLoc (HsIdent (toOpType c)) [] | c <- cs] + [name "Eq", name "Ord", name "Read", name "Show"] + +hsRegClassDecl targetName cs = + HsDataDecl dummySrcLoc [] (HsIdent (targetName ++ "RegisterClass")) [] + [HsConDecl dummySrcLoc (HsIdent (toOpType c)) [] | c <- cs] [name "Eq", name "Ord", name "Read", name "Show"] hsInstDecl targetName ss = diff --git a/src/unison-specsgen/src/SpecsGen/InstructionDeclGen.hs b/src/unison-specsgen/src/SpecsGen/InstructionDeclGen.hs index 49d7fb4e..2b232c2d 100644 --- a/src/unison-specsgen/src/SpecsGen/InstructionDeclGen.hs +++ b/src/unison-specsgen/src/SpecsGen/InstructionDeclGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/InstructionTypeGen.hs b/src/unison-specsgen/src/SpecsGen/InstructionTypeGen.hs index d5e0fe86..1ecc5477 100644 --- a/src/unison-specsgen/src/SpecsGen/InstructionTypeGen.hs +++ b/src/unison-specsgen/src/SpecsGen/InstructionTypeGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/ItineraryDeclGen.hs b/src/unison-specsgen/src/SpecsGen/ItineraryDeclGen.hs index 6f3ae9b8..111c6e98 100644 --- a/src/unison-specsgen/src/SpecsGen/ItineraryDeclGen.hs +++ b/src/unison-specsgen/src/SpecsGen/ItineraryDeclGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/ItineraryGen.hs b/src/unison-specsgen/src/SpecsGen/ItineraryGen.hs index 4039cf89..ebd13446 100644 --- a/src/unison-specsgen/src/SpecsGen/ItineraryGen.hs +++ b/src/unison-specsgen/src/SpecsGen/ItineraryGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/OperandInfoGen.hs b/src/unison-specsgen/src/SpecsGen/OperandInfoGen.hs index e517d09c..4a87180b 100644 --- a/src/unison-specsgen/src/SpecsGen/OperandInfoGen.hs +++ b/src/unison-specsgen/src/SpecsGen/OperandInfoGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/ParentGen.hs b/src/unison-specsgen/src/SpecsGen/ParentGen.hs index ae2a2f60..aad3d629 100644 --- a/src/unison-specsgen/src/SpecsGen/ParentGen.hs +++ b/src/unison-specsgen/src/SpecsGen/ParentGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/ReadOpGen.hs b/src/unison-specsgen/src/SpecsGen/ReadOpGen.hs index e7ac3486..7213c1ab 100644 --- a/src/unison-specsgen/src/SpecsGen/ReadOpGen.hs +++ b/src/unison-specsgen/src/SpecsGen/ReadOpGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/ReadWriteInfoGen.hs b/src/unison-specsgen/src/SpecsGen/ReadWriteInfoGen.hs index 7dc77609..59e63a18 100644 --- a/src/unison-specsgen/src/SpecsGen/ReadWriteInfoGen.hs +++ b/src/unison-specsgen/src/SpecsGen/ReadWriteInfoGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/RegisterClassDeclGen.hs b/src/unison-specsgen/src/SpecsGen/RegisterClassDeclGen.hs new file mode 100644 index 00000000..c9a2a879 --- /dev/null +++ b/src/unison-specsgen/src/SpecsGen/RegisterClassDeclGen.hs @@ -0,0 +1,32 @@ +{-| +Copyright : Copyright (c) 2019, RISE SICS AB +License : BSD3 (see the LICENSE file) +Maintainer : rcas@acm.org +-} +{- +Main authors: + Roberto Castaneda Lozano + +This file is part of Unison, see http://unison-code.github.io +-} +module SpecsGen.RegisterClassDeclGen (emitRegisterClassDecl) where + +import Data.Maybe +import qualified Data.Map as M +import Data.List + +import SpecsGen.SimpleYaml +import SpecsGen.HsGen + +emitRegisterClassDecl targetName is = + let ids = sort $ nub $ concatMap iRegClasses is + in [hsModule + (moduleName targetName (targetName ++ "RegisterClassDecl")) + (Just [hsExportDataType (targetName ++ "RegisterClass")]) + [] + [hsRegClassDecl targetName ids]] + +iRegClasses i = mapMaybe regClass $ M.toList $ mkOperandMap $ iOperands i + +regClass (_, (YRegisterInfo _ rc _)) = Just rc +regClass _ = Nothing diff --git a/src/unison-specsgen/src/SpecsGen/ShowInstanceGen.hs b/src/unison-specsgen/src/SpecsGen/ShowInstanceGen.hs index d34f18e0..cf5148b9 100644 --- a/src/unison-specsgen/src/SpecsGen/ShowInstanceGen.hs +++ b/src/unison-specsgen/src/SpecsGen/ShowInstanceGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/SimpleYaml.hs b/src/unison-specsgen/src/SpecsGen/SimpleYaml.hs index 6613292c..9018bad4 100644 --- a/src/unison-specsgen/src/SpecsGen/SimpleYaml.hs +++ b/src/unison-specsgen/src/SpecsGen/SimpleYaml.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/src/SpecsGen/SizeGen.hs b/src/unison-specsgen/src/SpecsGen/SizeGen.hs index 27761097..e3783a66 100644 --- a/src/unison-specsgen/src/SpecsGen/SizeGen.hs +++ b/src/unison-specsgen/src/SpecsGen/SizeGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison-specsgen/unison-specsgen.cabal b/src/unison-specsgen/unison-specsgen.cabal index 93348d4a..11ce5909 100644 --- a/src/unison-specsgen/unison-specsgen.cabal +++ b/src/unison-specsgen/unison-specsgen.cabal @@ -3,8 +3,8 @@ Version: 0 Cabal-Version: >= 1.8 License: BSD3 License-file: LICENSE -Author: Roberto Castaneda Lozano -Maintainer: Roberto Castaneda Lozano +Author: Roberto Castaneda Lozano +Maintainer: Roberto Castaneda Lozano Synopsis: An extension to the unison package with automatic generation of target files from a specification Category: Language, Compiler, Code generation, Program Transformation @@ -29,6 +29,7 @@ Library SpecsGen.AllInstructionsGen SpecsGen.ItineraryDeclGen SpecsGen.ParentGen + SpecsGen.RegisterClassDeclGen SpecsGen.HsGen SpecsGen.SimpleYaml SpecsGen.Driver diff --git a/src/unison/Setup.hs b/src/unison/Setup.hs index e1a011ac..796e6b39 100644 --- a/src/unison/Setup.hs +++ b/src/unison/Setup.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/exec/uni/Main.hs b/src/unison/exec/uni/Main.hs index 9d725942..23bc5d9b 100644 --- a/src/unison/exec/uni/Main.hs +++ b/src/unison/exec/uni/Main.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/scripts/pack-hexagon.hs b/src/unison/scripts/pack-hexagon.hs index 2fb63497..faf3e32a 100755 --- a/src/unison/scripts/pack-hexagon.hs +++ b/src/unison/scripts/pack-hexagon.hs @@ -3,14 +3,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Script to pretty-print Hexagon assembly code. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Common/Util.hs b/src/unison/src/Common/Util.hs index bab723e9..abada69d 100644 --- a/src/unison/src/Common/Util.hs +++ b/src/unison/src/Common/Util.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Generic functions used through the entire package. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR.hs b/src/unison/src/MachineIR.hs index 844ff7f7..11227f60 100644 --- a/src/unison/src/MachineIR.hs +++ b/src/unison/src/MachineIR.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Base.hs b/src/unison/src/MachineIR/Base.hs index 67513e22..c662c7e8 100644 --- a/src/unison/src/MachineIR/Base.hs +++ b/src/unison/src/MachineIR/Base.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Basic definitions for LLVM's machine IR program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -288,9 +288,10 @@ data MachineOperand r = } | -- | Frame object (internal use, does not correspond to any LLVM type) MachineFrameObject { - mfoOffset :: Integer, - mfoSize :: Maybe Integer, - mfoAlignment :: Integer + mfoOffset :: Integer, + mfoSize :: Maybe Integer, + mfoAlignment :: Integer, + mfoFixedSpill :: Bool } | -- | Frame size (internal use, does not correspond to any LLVM type) MachineFrameSize | diff --git a/src/unison/src/MachineIR/Constructors.hs b/src/unison/src/MachineIR/Constructors.hs index 59d76f4c..e659cab6 100644 --- a/src/unison/src/MachineIR/Constructors.hs +++ b/src/unison/src/MachineIR/Constructors.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Functions to construct the machine IR program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Instances.hs b/src/unison/src/MachineIR/Instances.hs index c8625e76..e7d80f53 100644 --- a/src/unison/src/MachineIR/Instances.hs +++ b/src/unison/src/MachineIR/Instances.hs @@ -1,7 +1,7 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Instance declarations for the MIR representation (see ). @@ -9,7 +9,7 @@ Instance declarations for the MIR representation (see -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -310,8 +310,8 @@ instance Show r => Show (MachineOperand r) where show (MachineBlockRef id) = inBraces ["mbb", show id] show (MachineFrameIndex index fixed offset) = inBraces ["fi", show index, show fixed, show offset] - show (MachineFrameObject off size align) = - inBraces ["mfo", show off, show size, show align] + show (MachineFrameObject off size align fixedSpill) = + inBraces ["mfo", show off, show size, show align, show fixedSpill] show MachineFrameSize = inBraces ["mfs"] show (MachineExternal name) = inBraces ["ext", name] show (MachineGlobalAddress address offset) = diff --git a/src/unison/src/MachineIR/Parser.hs b/src/unison/src/MachineIR/Parser.hs index d8c51b6f..3b020310 100644 --- a/src/unison/src/MachineIR/Parser.hs +++ b/src/unison/src/MachineIR/Parser.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Support to parse MIR functions (see ). -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Predicates.hs b/src/unison/src/MachineIR/Predicates.hs index 58dda2f3..f9e38c34 100644 --- a/src/unison/src/MachineIR/Predicates.hs +++ b/src/unison/src/MachineIR/Predicates.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Predicate functions for the machine IR program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/AddImplicitRegs.hs b/src/unison/src/MachineIR/Transformations/AddImplicitRegs.hs index b856115f..38cdfdd7 100644 --- a/src/unison/src/MachineIR/Transformations/AddImplicitRegs.hs +++ b/src/unison/src/MachineIR/Transformations/AddImplicitRegs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/DropExplicitFallthroughs.hs b/src/unison/src/MachineIR/Transformations/DropExplicitFallthroughs.hs index e033a223..f21fe7e1 100644 --- a/src/unison/src/MachineIR/Transformations/DropExplicitFallthroughs.hs +++ b/src/unison/src/MachineIR/Transformations/DropExplicitFallthroughs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/DropUnsupportedPseudos.hs b/src/unison/src/MachineIR/Transformations/DropUnsupportedPseudos.hs index 443de4cd..3b61a32d 100644 --- a/src/unison/src/MachineIR/Transformations/DropUnsupportedPseudos.hs +++ b/src/unison/src/MachineIR/Transformations/DropUnsupportedPseudos.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/LiftBlockFreqs.hs b/src/unison/src/MachineIR/Transformations/LiftBlockFreqs.hs index 5c4190aa..04bb4179 100644 --- a/src/unison/src/MachineIR/Transformations/LiftBlockFreqs.hs +++ b/src/unison/src/MachineIR/Transformations/LiftBlockFreqs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/LiftCustomProperties.hs b/src/unison/src/MachineIR/Transformations/LiftCustomProperties.hs index 89c8c86c..3f18892f 100644 --- a/src/unison/src/MachineIR/Transformations/LiftCustomProperties.hs +++ b/src/unison/src/MachineIR/Transformations/LiftCustomProperties.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/LiftJumpTables.hs b/src/unison/src/MachineIR/Transformations/LiftJumpTables.hs index e7a7a1bf..97d08dc0 100644 --- a/src/unison/src/MachineIR/Transformations/LiftJumpTables.hs +++ b/src/unison/src/MachineIR/Transformations/LiftJumpTables.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/MergeBlocks.hs b/src/unison/src/MachineIR/Transformations/MergeBlocks.hs index 5598cd93..fc95ac0f 100644 --- a/src/unison/src/MachineIR/Transformations/MergeBlocks.hs +++ b/src/unison/src/MachineIR/Transformations/MergeBlocks.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/PrepareForEmission.hs b/src/unison/src/MachineIR/Transformations/PrepareForEmission.hs index b6122f10..cc206bb7 100644 --- a/src/unison/src/MachineIR/Transformations/PrepareForEmission.hs +++ b/src/unison/src/MachineIR/Transformations/PrepareForEmission.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/RemoveEmptyBlocks.hs b/src/unison/src/MachineIR/Transformations/RemoveEmptyBlocks.hs index 2a3bb3f1..3e5e1c80 100644 --- a/src/unison/src/MachineIR/Transformations/RemoveEmptyBlocks.hs +++ b/src/unison/src/MachineIR/Transformations/RemoveEmptyBlocks.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/RenameMachineBlocks.hs b/src/unison/src/MachineIR/Transformations/RenameMachineBlocks.hs index 86ecedac..b51c3c18 100644 --- a/src/unison/src/MachineIR/Transformations/RenameMachineBlocks.hs +++ b/src/unison/src/MachineIR/Transformations/RenameMachineBlocks.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/RunPostProcess.hs b/src/unison/src/MachineIR/Transformations/RunPostProcess.hs index b9cafbd9..a96c612e 100644 --- a/src/unison/src/MachineIR/Transformations/RunPostProcess.hs +++ b/src/unison/src/MachineIR/Transformations/RunPostProcess.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/RunPreProcess.hs b/src/unison/src/MachineIR/Transformations/RunPreProcess.hs index 895eb1fc..0444095f 100644 --- a/src/unison/src/MachineIR/Transformations/RunPreProcess.hs +++ b/src/unison/src/MachineIR/Transformations/RunPreProcess.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/SimplifyFallthroughs.hs b/src/unison/src/MachineIR/Transformations/SimplifyFallthroughs.hs index f06393fd..5c40746b 100644 --- a/src/unison/src/MachineIR/Transformations/SimplifyFallthroughs.hs +++ b/src/unison/src/MachineIR/Transformations/SimplifyFallthroughs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Transformations/SplitTerminators.hs b/src/unison/src/MachineIR/Transformations/SplitTerminators.hs index a9bdbd20..e81b09b1 100644 --- a/src/unison/src/MachineIR/Transformations/SplitTerminators.hs +++ b/src/unison/src/MachineIR/Transformations/SplitTerminators.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/MachineIR/Util.hs b/src/unison/src/MachineIR/Util.hs index 43aa4b8c..8c17a5bf 100644 --- a/src/unison/src/MachineIR/Util.hs +++ b/src/unison/src/MachineIR/Util.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Useful functions to manipulate and query the machine IR program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison.hs b/src/unison/src/Unison.hs index 7a0b735c..e3a186d3 100644 --- a/src/unison/src/Unison.hs +++ b/src/unison/src/Unison.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/BoundaryTemporaries.hs b/src/unison/src/Unison/Analysis/BoundaryTemporaries.hs index c5c85512..02d39684 100644 --- a/src/unison/src/Unison/Analysis/BoundaryTemporaries.hs +++ b/src/unison/src/Unison/Analysis/BoundaryTemporaries.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms to compute copy-related pairs of boundary temporaries. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/CallingConvention.hs b/src/unison/src/Unison/Analysis/CallingConvention.hs index 817839c7..b6cde0bc 100644 --- a/src/unison/src/Unison/Analysis/CallingConvention.hs +++ b/src/unison/src/Unison/Analysis/CallingConvention.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms to compute properties related to calling conventions. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/CopyRelated.hs b/src/unison/src/Unison/Analysis/CopyRelated.hs index 4b82679a..f972ea19 100644 --- a/src/unison/src/Unison/Analysis/CopyRelated.hs +++ b/src/unison/src/Unison/Analysis/CopyRelated.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms to compute classes of copy-related operands. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/FrameOffsets.hs b/src/unison/src/Unison/Analysis/FrameOffsets.hs index 2fae9c3e..18b45511 100644 --- a/src/unison/src/Unison/Analysis/FrameOffsets.hs +++ b/src/unison/src/Unison/Analysis/FrameOffsets.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms to compute frame offsets. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/FrequencyEstimation.hs b/src/unison/src/Unison/Analysis/FrequencyEstimation.hs index cef5a588..d010eb04 100644 --- a/src/unison/src/Unison/Analysis/FrequencyEstimation.hs +++ b/src/unison/src/Unison/Analysis/FrequencyEstimation.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms to estimate statically the block execution frequency. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/MakespanBounds.hs b/src/unison/src/Unison/Analysis/MakespanBounds.hs index 03a0fcaa..d98eac8c 100644 --- a/src/unison/src/Unison/Analysis/MakespanBounds.hs +++ b/src/unison/src/Unison/Analysis/MakespanBounds.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms to compute makespan bounds. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/Stalls.hs b/src/unison/src/Unison/Analysis/Stalls.hs index de872329..b8389670 100644 --- a/src/unison/src/Unison/Analysis/Stalls.hs +++ b/src/unison/src/Unison/Analysis/Stalls.hs @@ -1,7 +1,7 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms and data types to analyze the resouce consumption and the latency slack of assembly code. @@ -9,7 +9,7 @@ slack of assembly code. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/TemporaryType.hs b/src/unison/src/Unison/Analysis/TemporaryType.hs index 6543d0fa..62a225d9 100644 --- a/src/unison/src/Unison/Analysis/TemporaryType.hs +++ b/src/unison/src/Unison/Analysis/TemporaryType.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms to infer temporary type information based on a whole function. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Analysis/TransitiveOperations.hs b/src/unison/src/Unison/Analysis/TransitiveOperations.hs index b0411602..66f55951 100644 --- a/src/unison/src/Unison/Analysis/TransitiveOperations.hs +++ b/src/unison/src/Unison/Analysis/TransitiveOperations.hs @@ -1,7 +1,7 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Algorithms to compute register classes, and pre-assignments of a temporary transitively through congruences. @@ -9,7 +9,7 @@ transitively through congruences. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Base.hs b/src/unison/src/Unison/Base.hs index fbf78b51..f622a7c8 100644 --- a/src/unison/src/Unison/Base.hs +++ b/src/unison/src/Unison/Base.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Basic definitions for the Unison program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Daniel Lundén @@ -634,7 +634,11 @@ data HighLevelGoal = -- | Code size optimization (corresponds to 'StaticGoal BundleWidth') Size | -- | Spill code overhead optimization (corresponds to 'DynamicGoal Spill') - Spill + Spill | + -- | Spill code overhead (only for analysis, corresponds to 'DynamicGoal SpillOverhead') + SpOvh | + -- | Number of spills (only for analysis, corresponds to 'StaticGoal SpillAction') + SpNo deriving (Eq, Ord) -- | Types corresponding to 'Operation'. @@ -1065,6 +1069,10 @@ data Goal s = data GoalObject s = -- | Total estimated execution cycles Cycles | + -- | Spill code overhead + SpillOverhead | + -- | Spill action (store) + SpillAction | -- | Usage of a certain resource ResourceUsage s deriving Show diff --git a/src/unison/src/Unison/Construction/AddDelimiters.hs b/src/unison/src/Unison/Construction/AddDelimiters.hs index 008cabc4..734b1bb8 100644 --- a/src/unison/src/Unison/Construction/AddDelimiters.hs +++ b/src/unison/src/Unison/Construction/AddDelimiters.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Construction/BuildFunction.hs b/src/unison/src/Unison/Construction/BuildFunction.hs index 908e2465..c3c7e29d 100644 --- a/src/unison/src/Unison/Construction/BuildFunction.hs +++ b/src/unison/src/Unison/Construction/BuildFunction.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Construction/LiftGoal.hs b/src/unison/src/Unison/Construction/LiftGoal.hs index 2775c1b4..f0a9a7a6 100644 --- a/src/unison/src/Unison/Construction/LiftGoal.hs +++ b/src/unison/src/Unison/Construction/LiftGoal.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Constructors.hs b/src/unison/src/Unison/Constructors.hs index a61be669..b8697e2b 100644 --- a/src/unison/src/Unison/Constructors.hs +++ b/src/unison/src/Unison/Constructors.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Functions to construct the Unison program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Daniel Lundén diff --git a/src/unison/src/Unison/Driver.hs b/src/unison/src/Unison/Driver.hs index c7abb04f..c870081a 100644 --- a/src/unison/src/Unison/Driver.hs +++ b/src/unison/src/Unison/Driver.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Support to build Unison tools. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/BCFG.hs b/src/unison/src/Unison/Graphs/BCFG.hs index 8cf28f82..350c8df6 100644 --- a/src/unison/src/Unison/Graphs/BCFG.hs +++ b/src/unison/src/Unison/Graphs/BCFG.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Block Control-Flow Graph. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Daniel Lundén diff --git a/src/unison/src/Unison/Graphs/CG.hs b/src/unison/src/Unison/Graphs/CG.hs index 8e2e6c94..200fe178 100644 --- a/src/unison/src/Unison/Graphs/CG.hs +++ b/src/unison/src/Unison/Graphs/CG.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Coalescing Graph. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/DG.hs b/src/unison/src/Unison/Graphs/DG.hs index 6e3ea4c0..6fa7e91f 100644 --- a/src/unison/src/Unison/Graphs/DG.hs +++ b/src/unison/src/Unison/Graphs/DG.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Dependency Graph. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -194,12 +194,7 @@ inDistances dg = cg = emap (const (-1)) dg in map (inDistance cg inn) (nodes dg) -inDistance cg inn n = (n, length $ justSp inn n cg) - -justSp s d g = - case sp s d g of - Just p -> p - Nothing -> error ("justSp: did not find any path") +inDistance cg inn n = (n, length $ sp inn n cg) toNodeId = fromIntegral . oId diff --git a/src/unison/src/Unison/Graphs/DT.hs b/src/unison/src/Unison/Graphs/DT.hs index c5194296..f015138c 100644 --- a/src/unison/src/Unison/Graphs/DT.hs +++ b/src/unison/src/Unison/Graphs/DT.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Dominance Tree. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/Hoopl.hs b/src/unison/src/Unison/Graphs/Hoopl.hs index dbbf43d3..75343ef3 100644 --- a/src/unison/src/Unison/Graphs/Hoopl.hs +++ b/src/unison/src/Unison/Graphs/Hoopl.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Hoopl block control-flow graph of a function. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/Hoopl/Liveness.hs b/src/unison/src/Unison/Graphs/Hoopl/Liveness.hs index 0ee67e9c..63059825 100644 --- a/src/unison/src/Unison/Graphs/Hoopl/Liveness.hs +++ b/src/unison/src/Unison/Graphs/Hoopl/Liveness.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Hoopl-based liveness pass. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/Hoopl/ReachingConstants.hs b/src/unison/src/Unison/Graphs/Hoopl/ReachingConstants.hs index 03f173dc..6e19786a 100644 --- a/src/unison/src/Unison/Graphs/Hoopl/ReachingConstants.hs +++ b/src/unison/src/Unison/Graphs/Hoopl/ReachingConstants.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Hoopl-based reaching constants pass. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/Hoopl/ReachingConstantsSSA.hs b/src/unison/src/Unison/Graphs/Hoopl/ReachingConstantsSSA.hs index e1493f06..9fbd35ac 100644 --- a/src/unison/src/Unison/Graphs/Hoopl/ReachingConstantsSSA.hs +++ b/src/unison/src/Unison/Graphs/Hoopl/ReachingConstantsSSA.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Hoopl-based reaching constants on SSA pass. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/Hoopl/ReachingDefinitions.hs b/src/unison/src/Unison/Graphs/Hoopl/ReachingDefinitions.hs index f1d4624f..0dba8bd2 100644 --- a/src/unison/src/Unison/Graphs/Hoopl/ReachingDefinitions.hs +++ b/src/unison/src/Unison/Graphs/Hoopl/ReachingDefinitions.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Hoopl-based reaching definitions pass. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/ICFG.hs b/src/unison/src/Unison/Graphs/ICFG.hs index f182db14..33731f36 100644 --- a/src/unison/src/Unison/Graphs/ICFG.hs +++ b/src/unison/src/Unison/Graphs/ICFG.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Operation Control-Flow Graph. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/OG.hs b/src/unison/src/Unison/Graphs/OG.hs index 0708d248..013eed95 100644 --- a/src/unison/src/Unison/Graphs/OG.hs +++ b/src/unison/src/Unison/Graphs/OG.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Operand Graph. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/PG.hs b/src/unison/src/Unison/Graphs/PG.hs index 0e8cc643..c180f109 100644 --- a/src/unison/src/Unison/Graphs/PG.hs +++ b/src/unison/src/Unison/Graphs/PG.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Precedence Graph. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/Partition.hs b/src/unison/src/Unison/Graphs/Partition.hs index 0d01b7cc..12bf8b13 100644 --- a/src/unison/src/Unison/Graphs/Partition.hs +++ b/src/unison/src/Unison/Graphs/Partition.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Data structure to represent a set partition. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/SG.hs b/src/unison/src/Unison/Graphs/SG.hs index f866fede..4defdfbd 100644 --- a/src/unison/src/Unison/Graphs/SG.hs +++ b/src/unison/src/Unison/Graphs/SG.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Same-placement Graph. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Graphs/ThirdParty.hs b/src/unison/src/Unison/Graphs/ThirdParty.hs index c949a8f5..3dc4b130 100644 --- a/src/unison/src/Unison/Graphs/ThirdParty.hs +++ b/src/unison/src/Unison/Graphs/ThirdParty.hs @@ -1,5 +1,5 @@ {-| -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Graph algorithms extracted from third-party components. diff --git a/src/unison/src/Unison/Graphs/Util.hs b/src/unison/src/Unison/Graphs/Util.hs index d8b750c8..63655dfc 100644 --- a/src/unison/src/Unison/Graphs/Util.hs +++ b/src/unison/src/Unison/Graphs/Util.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Useful functions on FGL graphs. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Instances.hs b/src/unison/src/Unison/Instances.hs index f1e850d2..2b423093 100644 --- a/src/unison/src/Unison/Instances.hs +++ b/src/unison/src/Unison/Instances.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Instance declarations for the Unison program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Daniel Lundén @@ -390,4 +390,6 @@ instance Read HighLevelGoal where readHighLevelGoal "speed" = Speed readHighLevelGoal "size" = Size readHighLevelGoal "spill" = Spill +readHighLevelGoal "spovh" = SpOvh +readHighLevelGoal "spno" = SpNo readHighLevelGoal goal = error ("unmatched: readHighLevelGoal " ++ show goal) diff --git a/src/unison/src/Unison/Parser.hs b/src/unison/src/Unison/Parser.hs index bed76147..68165e5b 100644 --- a/src/unison/src/Unison/Parser.hs +++ b/src/unison/src/Unison/Parser.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Support to parse Unison functions. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Daniel Lundén diff --git a/src/unison/src/Unison/Predicates.hs b/src/unison/src/Unison/Predicates.hs index 0d8cb106..e8d4d465 100644 --- a/src/unison/src/Unison/Predicates.hs +++ b/src/unison/src/Unison/Predicates.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Predicate functions for the Unison program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target.hs b/src/unison/src/Unison/Target.hs index dcff8738..0f884637 100644 --- a/src/unison/src/Unison/Target.hs +++ b/src/unison/src/Unison/Target.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -15,8 +15,10 @@ import Unison.Target.API (Any(..)) import Unison.Target.Hexagon as Hexagon (target) import Unison.Target.ARM as ARM (target) import Unison.Target.Mips as Mips (target) +import Unison.Target.Minimal as Minimal (target) unisonTargets = [("Hexagon", Any Hexagon.target), ("ARM", Any ARM.target), - ("Mips", Any Mips.target)] + ("Mips", Any Mips.target), + ("Minimal", Any Minimal.target)] diff --git a/src/unison/src/Unison/Target/API.hs b/src/unison/src/Unison/Target/API.hs index 3eae960b..ea0fc44a 100644 --- a/src/unison/src/Unison/Target/API.hs +++ b/src/unison/src/Unison/Target/API.hs @@ -1,11 +1,12 @@ + {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -20,6 +21,7 @@ module Unison.Target.API ( AlignedPairsFunction, PackedPairsFunction, RelatedPairsFunction, + CopiesFunction, CopyInstructions, TargetDescription(..), TargetOptions, @@ -59,7 +61,8 @@ module Unison.Target.API ( readWriteLatency, alternativeTemps, expandCopy, - constraints + constraints, + spillOverhead ) where import Data.List @@ -107,7 +110,7 @@ data StackDirection = StackGrowsUp | -- | Adding an object to the stack decreases the stack address StackGrowsDown - deriving Show + deriving (Eq, Show) optionValue option to = case find (\o -> option `isPrefixOf` o) to of @@ -133,11 +136,36 @@ type AlignedPairsFunction i r = type PackedPairsFunction i r = BlockOperation i r -> [(Operand r, Operand r)] -- | Function that gives related pairs in an operation type RelatedPairsFunction i r = BlockOperation i r -> [RegisterTable r] +-- | Function that gives copy instructions to extend a temporary at its +-- definition and use points +type CopiesFunction i r rc = + FunctionInfo i r rc + -- ^ Auxiliary, global analysis information about the function under + -- compilation. This information is computed at the beginning of copy + -- extension, so might become progressively obsolete as copies are introduced. + -> Bool + -- ^ Whether the temporary to be extended is the result of a virtual copy + -- @[t'] <- (copy) [t]@. If this is the case, the given copies substitute the + -- virtual copy: the definition copies are placed after the definition of @t@; + -- the use copies are placed before each use of @t'@. + -> Operand r + -- ^ Temporary to be extended. + -> [r] + -- ^ Registers pre-assigned to the temporary to be extended, possibly by + -- multiple operations. After copy extension, conflicts caused by different + -- pre-assignments to the same temporary should be solved. + -> BlockOperation i r + -- ^ Definer of the temporary to be extended. + -> [BlockOperation i r] + -- ^ Users of the temporary to be extended. + -> CopyInstructions i + -- ^ Copy instructions to be placed after the definition and before each use + -- of the temporary to be extended. -- | Copy instructions after the definition and before each use of a -- temporary type CopyInstructions i = ([Instruction i], [[Instruction i]]) -- | Target-dependent options (typically passed by tools through the --- command line flag @--targetoption@) +-- command-line option @--targetoption@) type TargetOptions = [String] -- | Target description together with target-dependent options type TargetWithOptions i r rc s = (TargetDescription i r rc s, TargetOptions) @@ -167,8 +195,7 @@ postProcess (ti, to) = tPostProcess ti to transforms (ti, to) = tTransforms ti to copies (ti, to) = tCopies ti to rematInstrs (ti, to) = tRematInstrs ti to -fromCopy (ti, to) ro o = - o {oOpr = Natural (tFromCopy ti to (fmap (oNatural . oOpr) ro) (oOpr o))} +fromCopy (ti, to) o = o {oOpr = Natural (tFromCopy ti to (oOpr o))} operandInfo (ti, to) = tOperandInfo ti to alignedPairs (ti, to) o @ SingleOperation {oOpr = (Natural {})} = concat [[(p, q, tai) | (p, q) <- tAlignedPairs ti to i (oUses o, oDefs o)] @@ -195,6 +222,7 @@ readWriteLatency (ti, to) rwo (pi, pa) (ci, ca) = alternativeTemps (ti, to) = tAlternativeTemps ti to expandCopy (ti, to) = tExpandCopy ti to constraints (ti, to) = tConstraints ti to +spillOverhead (ti, to) = tSpillOverhead ti to -- | Container with information about a 'Function' along with the -- function itself. @@ -204,9 +232,12 @@ type FunctionInfo i r rc = BCFGraph i r, Partition (Operand r)) -- | Description of a target processor. Implementing these functions --- is all that is required for a Unison target. The following table specifies --- which processor description functions are invoked by each component in the --- Unison toolchain: +-- is all that is required for a Unison target. The first argument to all +-- functions is a list of target-specific options given by the command-line +-- option @--targetoption@ (the option can be given multiple times). +-- +-- The following table specifies which processor description functions are +-- invoked by each component in the Unison toolchain: -- -- @ -- function import linearize extend augment model export @@ -245,26 +276,35 @@ type FunctionInfo i r rc = -- 'tAlternativeTemps' - - - x - - -- 'tExpandCopy' - - - x - - -- 'tConstraints' - - - - x - +-- 'tSpillOverhead' - - - - - - -- @ data TargetDescription i r rc s = TargetDescription { - -- | Sequence of atomic (one register atom per register) - -- register classes that forms the register array + -- | Sequence of atomic register classes that forms the register array. + -- A register class has one register atom per register. tRegisterArray :: TargetOptions -> [RegisterClass rc], -- | First and last register atoms of the given register tRegisterAtoms :: TargetOptions -> r -> (r, r), - -- | Register classes + -- | Register classes in the target (the order is not relevant) tRegClasses :: TargetOptions -> [RegisterClass rc], - -- | Registers of each register class + -- | Registers of the given register class ordered according to their + -- position in the register array tRegisters :: TargetOptions -> RegisterClass rc -> [r], -- | Number of atoms of each register in the given infinite - -- register class + -- register class. This is a partial function defined only for infinite + -- register classes. Examples of infinite register classes are those + -- modeling the stack frame and the rematerialization space tInfRegClassUsage :: TargetOptions -> RegisterClass rc -> Integer, -- | Possibly an upper bound of the number of register atoms in the given - -- infinite register class + -- infinite register class. This is a partial function defined only for + -- infinite register classes. In most cases, the return value should be + -- 'Nothing', but it can be set to 'Just n' (where 'n' is an 'Integer') to + -- model bounded register classes that are subsets of infinite register + -- classes (for example, the top 'n' locations in a stack frame). See + -- 'Unison.Target.ARM.Registers' for an example. tInfRegClassBound :: TargetOptions -> RegisterClass rc -> Maybe Integer, -- | Chained index type of the given sub-register index (see - -- 'MachineSubRegIndex') for the given register class (in String + -- 'MachineSubRegIndex') for the given register class (in 'String' -- format). A chain [t1, t2, .., tn] is to be interpreted as "the t1 part -- of the t2 part of .. of the tnth part of the register" tSubRegIndexType :: TargetOptions -> String -> SubRegIndex -> [SubRegIndexType], @@ -276,7 +316,8 @@ data TargetDescription i r rc s = TargetDescription { tReserved :: TargetOptions -> [r], -- | Type of the given instruction tInstructionType :: TargetOptions -> i -> InstructionT, - -- | Information about the branch performed by a 'Branch' operation + -- | Information about the branch performed by a 'Branch' operation. This + -- is a partial function defined only for branch operations tBranchInfo :: TargetOptions -> NaturalOperation i r -> BranchInfo, -- | Target-dependent 'MachineIR' transformations to be applied @@ -293,17 +334,17 @@ data TargetDescription i r rc s = TargetDescription { [FunctionTransform i r], -- | Copy instructions to extend the given temporary between the -- given definer and users - tCopies :: TargetOptions -> FunctionInfo i r rc -> Bool -> - Operand r -> [r] -> BlockOperation i r -> - [BlockOperation i r] -> CopyInstructions i, + tCopies :: TargetOptions -> CopiesFunction i r rc, -- | Instructions to rematerialize the value defined by the - -- given instruction (source instruction, dematerialization copy, and - -- rematerialization copy) + -- given instruction 'i' (source instruction, dematerialization copy, and + -- rematerialization copy). Gives 'Nothing' if 'i' is not rematerializable + -- or its corresponding rematerialization instructions are not yet + -- defined. tRematInstrs :: TargetOptions -> i -> Maybe (i, i, i), - -- | Implementation of the given operation (typically a copy) to be - -- applied during the export phase with possibly a supporting remat origin - tFromCopy :: TargetOptions -> Maybe (NaturalOperation i r) -> - Operation i r -> NaturalOperation i r, + -- | Implementation of the given copy operation (introduced during copy + -- extension) as a natural operation with a real target instruction + tFromCopy :: TargetOptions -> Operation i r -> + NaturalOperation i r, -- | Information about the use and definition operands of the given -- instruction tOperandInfo :: TargetOptions -> OperandInfoFunction i rc, @@ -352,7 +393,11 @@ data TargetDescription i r rc s = TargetDescription { BlockOperation i r -> [BlockOperation i r], -- | Custom processor constraints tConstraints :: TargetOptions -> Function i r -> - [ConstraintExpr i rc] + [ConstraintExpr i rc], + -- | Spill sign and overhead of a given instruction and operands + -- (analysis only) + tSpillOverhead :: TargetOptions -> (i, [Operand r], [Operand r]) -> + Maybe (Bool, Latency) } -- | Any 'TargetDescription'. Used to support multiple targets without diff --git a/src/unison/src/Unison/Target/ARM.hs b/src/unison/src/Unison/Target/ARM.hs index 977b1b96..0dfcd7d1 100644 --- a/src/unison/src/Unison/Target/ARM.hs +++ b/src/unison/src/Unison/Target/ARM.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -20,7 +20,6 @@ import Control.Arrow import Common.Util import MachineIR hiding (parse) -import MachineIR.Transformations.AddImplicitRegs import Unison import qualified Unison.Target.API as API @@ -36,8 +35,8 @@ import Unison.Target.ARM.OperandInfo import Unison.Target.ARM.Transforms import Unison.Target.ARM.Usages import Unison.Target.ARM.ARMRegisterDecl -import Unison.Target.ARM.ARMRegisterClassDecl import Unison.Target.ARM.ARMResourceDecl +import Unison.Target.ARM.SpecsGen.ARMRegisterClassDecl import Unison.Target.ARM.SpecsGen.ARMInstructionDecl import Unison.Target.ARM.SpecsGen.ARMItineraryDecl import qualified Unison.Target.ARM.SpecsGen as SpecsGen @@ -77,7 +76,8 @@ target = API.tReadWriteLatency = readWriteLatency, API.tAlternativeTemps = const alternativeTemps, API.tExpandCopy = const expandCopy, - API.tConstraints = const constraints + API.tConstraints = const constraints, + API.tSpillOverhead = const spillOverhead } instance Read ARMInstruction where @@ -223,12 +223,10 @@ isReserved r = r `elem` reserved rematInstrs i | isRematerializable i = Just (sourceInstr i, dematInstr i, rematInstr i) - | otherwise = error ("unmatched: rematInstrs " ++ show i) + | otherwise = Nothing -- | Transforms copy instructions into natural instructions - --- handle regular copies -fromCopy _ Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} +fromCopy Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} | i `elem` [MOVE, MOVE_ALL, MOVE_D] = Linear {oIs = [TargetInstruction (fromCopyInstr i (s, d))], oUs = [s] ++ defaultUniPred, @@ -262,21 +260,8 @@ fromCopy _ Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} Linear {oIs = [TargetInstruction (fromCopyInstr i (s, d))], oUs = [mkOprArmSP] ++ defaultUniPred ++ mkPushRegs i, oDs = [mkOprArmSP]} - --- handle rematerialization copies -fromCopy (Just (Linear {oUs = us})) - Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} - | isDematInstr i = - Linear {oIs = [mkNullInstruction], oUs = [s], oDs = [d]} - | isRematInstr i = - Linear {oIs = [TargetInstruction (originalInstr i)], oUs = us, oDs = [d]} - --- handle rematerialization sources -fromCopy _ (Natural o @ Linear {oIs = [TargetInstruction i]}) - | isSourceInstr i = o {oIs = [mkNullInstruction]} - -fromCopy _ (Natural o) = o -fromCopy _ o = error ("unmatched pattern: fromCopy " ++ show o) +fromCopy (Natural o) = o +fromCopy o = error ("unmatched pattern: fromCopy " ++ show o) mkPushRegs i = map (Register . TargetRegister) (pushRegs i) @@ -284,7 +269,7 @@ mkOprArmSP = Register $ mkTargetRegister SP mkBoundMachineFrameObject i (Register r) = let size = stackSize i - in mkBound (mkMachineFrameObject (infRegPlace r) (Just size) size) + in mkBound (mkMachineFrameObject (infRegPlace r) (Just size) size False) stackSize i | i `elem` [STORE, STORE_T, LOAD, LOAD_T] = 1 @@ -608,7 +593,6 @@ postProcess to = [expandPseudos to, removeAllNops, removeFrameIndex, removeEmptyBundles, reorderImplicitOperands, exposeCPSRRegister, mapToTargetMachineInstruction expandVarOpInstructions, - flip addImplicitRegs (target, []), demoteImplicitOperands] expandPseudos to = mapToMachineBlock (expandBlockPseudos (expandPseudo to)) @@ -897,3 +881,25 @@ altLoadStoreConstraints (_ : code) constraints = (code, constraints) isSingleLoadStore i = i `elem` [TLDRi, T2LDRi12, TSTRi, T2STRi12] isDoubleLoadStore i = i `elem` [T2LDRDi8, T2STRDi8] + +latency i = maybeMax 0 $ map occupation (usages [] i) + +spillOverhead (i, _, _) + | i `elem` [TPUSH, TPUSH_r4_7, TPUSH_r8_11, TPUSH2_r4_7, TPUSH2_r4_11, TPUSH_4, TPUSH_4_5, TPUSH_4_6, TPUSH_4_7] = Just (True, latency i) +spillOverhead (i, _, _) + | i `elem` [TPOP, TPOP_RET, TPOP_r4_7, TPOP_r8_11, TPOP2_r4_7, TPOP2_r4_11, TPOP2_r4_7_RET, TPOP2_r4_11_RET, TPOP_RET_4, TPOP_RET_4_5, TPOP_RET_4_6, TPOP_RET_4_7] = Just (False, latency i) +spillOverhead (i, _, _) + | i `elem` [T2STMDB_UPD, T2STMDB_UPD_4_8, T2STMDB_UPD_4_9, T2STMDB_UPD_4_10, T2STMDB_UPD_4_11] = Just (True, latency i) +spillOverhead (i, _, _) + | i `elem` [T2LDMIA, T2LDMIA_RET, T2LDMIA_UPD, T2LDMIA_4, T2LDMIA_UPD_4, T2LDMIA_UPD_4_4, T2LDMIA_UPD_4_5, T2LDMIA_UPD_4_6, T2LDMIA_UPD_4_7, T2LDMIA_UPD_4_8, T2LDMIA_UPD_4_9, T2LDMIA_UPD_4_10, T2LDMIA_UPD_4_11, T2LDMIA_RET_4_8, T2LDMIA_RET_4_9, T2LDMIA_RET_4_10, T2LDMIA_RET_4_11] = Just (False, latency i) +spillOverhead (i, sp:_, _) + | i `elem` [VLDMDIA_UPD, VLDMDIA_UPD_d8_15] && sp == mkOprArmSP = Just (False, latency i) +spillOverhead (i, sp:_, _) + | i `elem` [VSTMDDB_UPD, VSTMDDB_UPD_d8_15] && sp == mkOprArmSP = Just (True, latency i) +spillOverhead (i, _:sp:_, _) + | i `elem` [T2STRBi12, T2STRi12, TSTRspi, VSTRS, TSTRi] && sp == mkOprArmSP = Just (True, latency i) +spillOverhead (i, _:_:sp:_, _) + | i `elem` [T2STRDi8] && sp == mkOprArmSP = Just (True, latency i) +spillOverhead (i, sp:_, _) + | i `elem` [T2LDRBi12, T2LDRi12, TLDRspi, VLDRD, VLDRS, T2LDR_POST, T2LDRDi8, TLDRi] && sp == mkOprArmSP = Just (False, latency i) +spillOverhead _ = Nothing diff --git a/src/unison/src/Unison/Target/ARM/ARMRegisterClassDecl.hs b/src/unison/src/Unison/Target/ARM/ARMRegisterClassDecl.hs deleted file mode 100644 index 857cb437..00000000 --- a/src/unison/src/Unison/Target/ARM/ARMRegisterClassDecl.hs +++ /dev/null @@ -1,63 +0,0 @@ -{-| -Copyright : Copyright (c) 2016, RISE SICS AB -License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se --} -{- -Main authors: - Roberto Castaneda Lozano - -This file is part of Unison, see http://unison-code.github.io --} -module Unison.Target.ARM.ARMRegisterClassDecl (ARMRegisterClass (..)) where - -data ARMRegisterClass = - ALL | - CCR | - CRS | - CS | - CSL | - CSH | - FCS | - FCRS | - DPair | - DPR | - DPR_8 | - DPR_VFP2 | - GPR | - GPRnopc | - GPRPairOp | - GPRsp | - GPRwithAPSR | - M128 | - M512 | - M32 | - M32t | - M64 | - QPR | - QQPR | - QQQQPR | - RGPR | - RM32 | - RM64 | - SPR | - TcGPR | - TGPR | - VecListDPair | - VecListDPairAllLanes | - VecListDPairSpaced | - VecListDPairSpacedAllLanes | - VecListFourD | - VecListFourDAllLanes | - VecListFourQ | - VecListFourQAllLanes | - VecListOneD | - VecListOneDAllLanes | - VecListThreeD | - VecListThreeDAllLanes | - VecListThreeQ | - VecListThreeQAllLanes | - Unknown | - F32 | - Ptr_rc - deriving (Eq, Ord, Show, Read) diff --git a/src/unison/src/Unison/Target/ARM/ARMRegisterDecl.hs b/src/unison/src/Unison/Target/ARM/ARMRegisterDecl.hs index 0640e49b..21aae44c 100644 --- a/src/unison/src/Unison/Target/ARM/ARMRegisterDecl.hs +++ b/src/unison/src/Unison/Target/ARM/ARMRegisterDecl.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/ARM/Common.hs b/src/unison/src/Unison/Target/ARM/Common.hs index 12372473..4fea1778 100644 --- a/src/unison/src/Unison/Target/ARM/Common.hs +++ b/src/unison/src/Unison/Target/ARM/Common.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/ARM/OperandInfo.hs b/src/unison/src/Unison/Target/ARM/OperandInfo.hs index 75e52dbe..641de14a 100644 --- a/src/unison/src/Unison/Target/ARM/OperandInfo.hs +++ b/src/unison/src/Unison/Target/ARM/OperandInfo.hs @@ -1,18 +1,18 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} module Unison.Target.ARM.OperandInfo (operandInfo) where import Unison -import Unison.Target.ARM.ARMRegisterClassDecl +import Unison.Target.ARM.SpecsGen.ARMRegisterClassDecl import Unison.Target.ARM.SpecsGen.ARMInstructionDecl import qualified Unison.Target.ARM.SpecsGen as SpecsGen diff --git a/src/unison/src/Unison/Target/ARM/Registers.hs b/src/unison/src/Unison/Target/ARM/Registers.hs index 346b71b0..6a3386a2 100644 --- a/src/unison/src/Unison/Target/ARM/Registers.hs +++ b/src/unison/src/Unison/Target/ARM/Registers.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -19,7 +19,7 @@ import qualified Data.Map as M import Unison import Unison.Target.ARM.ARMRegisterDecl -import Unison.Target.ARM.ARMRegisterClassDecl +import Unison.Target.ARM.SpecsGen.ARMRegisterClassDecl -- | Register array diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen.hs b/src/unison/src/Unison/Target/ARM/SpecsGen.hs index c2ce3189..513901fc 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/ARMInstructionDecl.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/ARMInstructionDecl.hs index 39da03c9..58c783e6 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/ARMInstructionDecl.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/ARMInstructionDecl.hs @@ -3067,6 +3067,7 @@ data ARMInstruction = ABS | T2SUBrrcc | T2ADDrrcc | T2ADDrscc + | Register_class_decl_dummy | T2MOVi_source | T2MOVi_demat | T2MOVi_remat diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/ARMRegisterClassDecl.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/ARMRegisterClassDecl.hs new file mode 100644 index 00000000..69a5bbaa --- /dev/null +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/ARMRegisterClassDecl.hs @@ -0,0 +1,55 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.ARM.SpecsGen.ARMRegisterClassDecl + (ARMRegisterClass(..)) where + +data ARMRegisterClass = ALL + | CCR + | CRS + | CS + | CSH + | CSL + | DPR + | DPR_8 + | DPR_VFP2 + | DPair + | F32 + | FCRS + | FCS + | GPR + | GPRPairOp + | GPRnopc + | GPRsp + | GPRwithAPSR + | M128 + | M32 + | M32t + | M512 + | M64 + | QPR + | QQPR + | QQQQPR + | RM32 + | RM64 + | SPR + | Unknown + | VecListDPair + | VecListDPairAllLanes + | VecListDPairSpaced + | VecListDPairSpacedAllLanes + | VecListFourD + | VecListFourDAllLanes + | VecListFourQ + | VecListFourQAllLanes + | VecListOneD + | VecListOneDAllLanes + | VecListThreeD + | VecListThreeDAllLanes + | VecListThreeQ + | VecListThreeQAllLanes + | Ptr_rc + | RGPR + | TGPR + | TcGPR + deriving (Eq, Ord, Read, Show) + diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/AlignedPairs.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/AlignedPairs.hs index b6fa6cc4..79e8c225 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/AlignedPairs.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/AlignedPairs.hs @@ -1012,6 +1012,8 @@ alignedPairs i ([dst, src, _, _], [dst', src']) alignedPairs i ([_, _, _, _], []) | i `elem` [COPY_STRUCT_BYVAL_I32] = [] alignedPairs i ([_], []) | i `elem` [SETEND, TSETEND] = [] +alignedPairs i ([_, _, _], []) + | i `elem` [Register_class_decl_dummy] = [] alignedPairs i ([false', _, _, _, _], [false'']) | i `elem` [T2MOVCCasr, T2MOVCClsl, T2MOVCClsr, T2MOVCCror] = [(false', false'')] diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/AllInstructions.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/AllInstructions.hs index dada0b08..ce7c4d4a 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/AllInstructions.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/AllInstructions.hs @@ -615,8 +615,8 @@ allInstructions T2LDMIA_UPD_4_10, T2LDMIA_UPD_4_11, T2LDMIA_RET_4_8, T2LDMIA_RET_4_9, T2LDMIA_RET_4_10, T2LDMIA_RET_4_11, T2LSLricc, T2ADDricc, T2ANDricc, T2ORRricc, T2SUBricc, T2SUBrrcc, T2ADDrrcc, - T2ADDrscc, T2MOVi_source, T2MOVi_demat, T2MOVi_remat, - T2MOVi16_source, T2MOVi16_demat, T2MOVi16_remat, + T2ADDrscc, Register_class_decl_dummy, T2MOVi_source, T2MOVi_demat, + T2MOVi_remat, T2MOVi16_source, T2MOVi16_demat, T2MOVi16_remat, T2MOVi32imm_source, T2MOVi32imm_demat, T2MOVi32imm_remat, TMOVi8s_source, TMOVi8s_demat, TMOVi8s_remat, T2ADDri_fi_source_fi, T2ADDri_fi_demat_fi, T2ADDri_fi_remat_fi, T2LDRi12_fi_source_fi, diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/InstructionType.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/InstructionType.hs index 77a4cf85..cdbb50ec 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/InstructionType.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/InstructionType.hs @@ -538,20 +538,20 @@ instructionType i VTSTv4i32, VTSTv8i16, VTSTv8i8, VUHTOD, VUHTOS, VUITOD, VUITOS, VULTOD, VULTOS, VUZPd16, VUZPd8, VUZPq16, VUZPq32, VUZPq8, VZIPd16, VZIPd8, VZIPq16, VZIPq32, VZIPq8, WIN__CHKSTK, WIN__DBZCHK, - Load_merge, SysLDMDA, SysLDMDA_UPD, SysLDMDB, SysLDMDB_UPD, - SysLDMIA, SysLDMIA_UPD, SysLDMIB, SysLDMIB_UPD, SysSTMDA, - SysSTMDA_UPD, SysSTMDB, SysSTMDB_UPD, SysSTMIA, SysSTMIA_UPD, - SysSTMIB, SysSTMIB_UPD, T2ABS, T2ADCri, T2ADCrr, T2ADCrs, T2ADDSri, - T2ADDSrr, T2ADDSrs, T2ADDri, T2ADDri12, T2ADDri_cpsr, T2ADDri_fi, - T2ADDri_fi_source_fi, T2ADDricc, T2ADDrr, T2ADDrrcc, T2ADDrs, - T2ADDrscc, T2ADR, T2ANDri, T2ANDri_cpsr, T2ANDricc, T2ANDrr, - T2ANDrs, T2ASRri, T2ASRrr, T2BFC, T2BFI, T2BICri, T2BICrr, T2BICrs, - T2BXJ, T2CDP, T2CDP2, T2CLREX, T2CLZ, T2CMNri, T2CMNri_cpsr, - T2CMNzrr, T2CMNzrs, T2CMPri, T2CMPri_cpsr, T2CMPrr, T2CMPrr_cpsr, - T2CMPrs, T2CMPrs_cpsr, T2CPS1p, T2CPS2p, T2CPS3p, T2CRC32B, - T2CRC32CB, T2CRC32CH, T2CRC32CW, T2CRC32H, T2CRC32W, T2DBG, - T2DCPS1, T2DCPS2, T2DCPS3, T2DMB, T2DSB, T2EORri, T2EORrr, T2EORrs, - T2HINT, T2ISB, T2IT, T2Int_eh_sjlj_setjmp, + Load_merge, Register_class_decl_dummy, SysLDMDA, SysLDMDA_UPD, + SysLDMDB, SysLDMDB_UPD, SysLDMIA, SysLDMIA_UPD, SysLDMIB, + SysLDMIB_UPD, SysSTMDA, SysSTMDA_UPD, SysSTMDB, SysSTMDB_UPD, + SysSTMIA, SysSTMIA_UPD, SysSTMIB, SysSTMIB_UPD, T2ABS, T2ADCri, + T2ADCrr, T2ADCrs, T2ADDSri, T2ADDSrr, T2ADDSrs, T2ADDri, T2ADDri12, + T2ADDri_cpsr, T2ADDri_fi, T2ADDri_fi_source_fi, T2ADDricc, T2ADDrr, + T2ADDrrcc, T2ADDrs, T2ADDrscc, T2ADR, T2ANDri, T2ANDri_cpsr, + T2ANDricc, T2ANDrr, T2ANDrs, T2ASRri, T2ASRrr, T2BFC, T2BFI, + T2BICri, T2BICrr, T2BICrs, T2BXJ, T2CDP, T2CDP2, T2CLREX, T2CLZ, + T2CMNri, T2CMNri_cpsr, T2CMNzrr, T2CMNzrs, T2CMPri, T2CMPri_cpsr, + T2CMPrr, T2CMPrr_cpsr, T2CMPrs, T2CMPrs_cpsr, T2CPS1p, T2CPS2p, + T2CPS3p, T2CRC32B, T2CRC32CB, T2CRC32CH, T2CRC32CW, T2CRC32H, + T2CRC32W, T2DBG, T2DCPS1, T2DCPS2, T2DCPS3, T2DMB, T2DSB, T2EORri, + T2EORrr, T2EORrs, T2HINT, T2ISB, T2IT, T2Int_eh_sjlj_setjmp, T2Int_eh_sjlj_setjmp_nofp, T2LDA, T2LDAB, T2LDAEX, T2LDAEXB, T2LDAEXD, T2LDAEXH, T2LDAH, T2LDC2L_OFFSET, T2LDC2L_OPTION, T2LDC2L_POST, T2LDC2L_PRE, T2LDC2_OFFSET, T2LDC2_OPTION, diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/Itinerary.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/Itinerary.hs index adce539d..b54f7b54 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/Itinerary.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/Itinerary.hs @@ -1001,16 +1001,16 @@ itinerary i VST4qAsm_32, VST4qAsm_8, VST4qWB_fixed_Asm_16, VST4qWB_fixed_Asm_32, VST4qWB_fixed_Asm_8, VST4qWB_register_Asm_16, VST4qWB_register_Asm_32, VST4qWB_register_Asm_8, VSWPd, VSWPq, - WIN__CHKSTK, WIN__DBZCHK, Load_merge, T2ABS, T2ADDri_fi_demat_fi, - T2ADDri_fi_source_fi, T2BXJ, T2CDP, T2CDP2, T2CLREX, T2CPS1p, - T2CPS2p, T2CPS3p, T2CRC32B, T2CRC32CB, T2CRC32CH, T2CRC32CW, - T2CRC32H, T2CRC32W, T2DBG, T2DCPS1, T2DCPS2, T2DCPS3, T2DMB, T2DSB, - T2HINT, T2ISB, T2Int_eh_sjlj_setjmp, T2Int_eh_sjlj_setjmp_nofp, - T2LDA, T2LDAB, T2LDAEX, T2LDAEXB, T2LDAEXD, T2LDAEXH, T2LDAH, - T2LDC2L_OFFSET, T2LDC2L_OPTION, T2LDC2L_POST, T2LDC2L_PRE, - T2LDC2_OFFSET, T2LDC2_OPTION, T2LDC2_POST, T2LDC2_PRE, - T2LDCL_OFFSET, T2LDCL_OPTION, T2LDCL_POST, T2LDCL_PRE, - T2LDC_OFFSET, T2LDC_OPTION, T2LDC_POST, T2LDC_PRE, + WIN__CHKSTK, WIN__DBZCHK, Load_merge, Register_class_decl_dummy, + T2ABS, T2ADDri_fi_demat_fi, T2ADDri_fi_source_fi, T2BXJ, T2CDP, + T2CDP2, T2CLREX, T2CPS1p, T2CPS2p, T2CPS3p, T2CRC32B, T2CRC32CB, + T2CRC32CH, T2CRC32CW, T2CRC32H, T2CRC32W, T2DBG, T2DCPS1, T2DCPS2, + T2DCPS3, T2DMB, T2DSB, T2HINT, T2ISB, T2Int_eh_sjlj_setjmp, + T2Int_eh_sjlj_setjmp_nofp, T2LDA, T2LDAB, T2LDAEX, T2LDAEXB, + T2LDAEXD, T2LDAEXH, T2LDAH, T2LDC2L_OFFSET, T2LDC2L_OPTION, + T2LDC2L_POST, T2LDC2L_PRE, T2LDC2_OFFSET, T2LDC2_OPTION, + T2LDC2_POST, T2LDC2_PRE, T2LDCL_OFFSET, T2LDCL_OPTION, T2LDCL_POST, + T2LDCL_PRE, T2LDC_OFFSET, T2LDC_OPTION, T2LDC_POST, T2LDC_PRE, T2LDRBi12_fi_demat_fi, T2LDRBi12_fi_source_fi, T2LDRBpcrel, T2LDREX, T2LDREXB, T2LDREXD, T2LDREXH, T2LDRHpcrel, T2LDRSBpcrel, T2LDRSHpcrel, T2LDRi12_fi_demat_fi, T2LDRi12_fi_source_fi, diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/OperandInfo.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/OperandInfo.hs index 857393d1..30220150 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/OperandInfo.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/OperandInfo.hs @@ -3,7 +3,7 @@ module Unison.Target.ARM.SpecsGen.OperandInfo (operandInfo) where import Unison import Unison.Target.ARM.SpecsGen.ARMInstructionDecl -import Unison.Target.ARM.ARMRegisterClassDecl +import Unison.Target.ARM.SpecsGen.ARMRegisterClassDecl operandInfo i | i `elem` [CLREX, Int_eh_sjlj_dispatchsetup, Int_eh_sjlj_setup_dispatch, NOP, @@ -367,6 +367,11 @@ operandInfo i TemporaryInfo (RegisterClass GPR) 0 False, BoundInfo, TemporaryInfo (RegisterClass CCR) 0 False], []) + | i `elem` [Register_class_decl_dummy] = + ([TemporaryInfo (RegisterClass F32) 0 False, + TemporaryInfo (RegisterClass CRS) 0 False, + TemporaryInfo (RegisterClass FCRS) 0 False], + []) | i `elem` [VSTMDDB_UPD_d8_15] = ([TemporaryInfo (RegisterClass FCS) 0 False], [TemporaryInfo (InfiniteRegisterClass M512) 1 False]) diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/Parent.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/Parent.hs index a5d86b3a..60d98240 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/Parent.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/Parent.hs @@ -508,18 +508,18 @@ parent i VTSTv4i32, VTSTv8i16, VTSTv8i8, VUHTOD, VUHTOS, VUITOD, VUITOS, VULTOD, VULTOS, VUZPd16, VUZPd8, VUZPq16, VUZPq32, VUZPq8, VZIPd16, VZIPd8, VZIPq16, VZIPq32, VZIPq8, WIN__CHKSTK, WIN__DBZCHK, - Load_merge, SysLDMDA, SysLDMDA_UPD, SysLDMDB, SysLDMDB_UPD, - SysLDMIA, SysLDMIA_UPD, SysLDMIB, SysLDMIB_UPD, SysSTMDA, - SysSTMDA_UPD, SysSTMDB, SysSTMDB_UPD, SysSTMIA, SysSTMIA_UPD, - SysSTMIB, SysSTMIB_UPD, T2ABS, T2ADCri, T2ADCrr, T2ADCrs, T2ADDSri, - T2ADDSrr, T2ADDSrs, T2ADDri, T2ADDri12, T2ADDri_fi, T2ADDrr, - T2ADDrs, T2ADR, T2ANDri, T2ANDrr, T2ANDrs, T2ASRri, T2ASRrr, T2B, - T2BFC, T2BFI, T2BICri, T2BICrr, T2BICrs, T2BR_JT, T2BXJ, T2Bcc, - T2CDP, T2CDP2, T2CLREX, T2CLZ, T2CMNri, T2CMNzrr, T2CMNzrs, - T2CMPri, T2CMPrr, T2CMPrs, T2CPS1p, T2CPS2p, T2CPS3p, T2CRC32B, - T2CRC32CB, T2CRC32CH, T2CRC32CW, T2CRC32H, T2CRC32W, T2DBG, - T2DCPS1, T2DCPS2, T2DCPS3, T2DMB, T2DSB, T2EORri, T2EORrr, T2EORrs, - T2HINT, T2HVC, T2ISB, T2IT, T2Int_eh_sjlj_setjmp, + Load_merge, Register_class_decl_dummy, SysLDMDA, SysLDMDA_UPD, + SysLDMDB, SysLDMDB_UPD, SysLDMIA, SysLDMIA_UPD, SysLDMIB, + SysLDMIB_UPD, SysSTMDA, SysSTMDA_UPD, SysSTMDB, SysSTMDB_UPD, + SysSTMIA, SysSTMIA_UPD, SysSTMIB, SysSTMIB_UPD, T2ABS, T2ADCri, + T2ADCrr, T2ADCrs, T2ADDSri, T2ADDSrr, T2ADDSrs, T2ADDri, T2ADDri12, + T2ADDri_fi, T2ADDrr, T2ADDrs, T2ADR, T2ANDri, T2ANDrr, T2ANDrs, + T2ASRri, T2ASRrr, T2B, T2BFC, T2BFI, T2BICri, T2BICrr, T2BICrs, + T2BR_JT, T2BXJ, T2Bcc, T2CDP, T2CDP2, T2CLREX, T2CLZ, T2CMNri, + T2CMNzrr, T2CMNzrs, T2CMPri, T2CMPrr, T2CMPrs, T2CPS1p, T2CPS2p, + T2CPS3p, T2CRC32B, T2CRC32CB, T2CRC32CH, T2CRC32CW, T2CRC32H, + T2CRC32W, T2DBG, T2DCPS1, T2DCPS2, T2DCPS3, T2DMB, T2DSB, T2EORri, + T2EORrr, T2EORrs, T2HINT, T2HVC, T2ISB, T2IT, T2Int_eh_sjlj_setjmp, T2Int_eh_sjlj_setjmp_nofp, T2LDA, T2LDAB, T2LDAEX, T2LDAEXB, T2LDAEXD, T2LDAEXH, T2LDAH, T2LDC2L_OFFSET, T2LDC2L_OPTION, T2LDC2L_POST, T2LDC2L_PRE, T2LDC2_OFFSET, T2LDC2_OPTION, diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/ReadOp.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/ReadOp.hs index e8c13f2b..f4fc49d4 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/ReadOp.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/ReadOp.hs @@ -3066,6 +3066,7 @@ readOp "t2SUBricc" = T2SUBricc readOp "t2SUBrrcc" = T2SUBrrcc readOp "t2ADDrrcc" = T2ADDrrcc readOp "t2ADDrscc" = T2ADDrscc +readOp "register_class_decl_dummy" = Register_class_decl_dummy readOp "t2MOVi_source" = T2MOVi_source readOp "t2MOVi_demat" = T2MOVi_demat readOp "t2MOVi_remat" = T2MOVi_remat diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/ReadWriteInfo.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/ReadWriteInfo.hs index ace89911..78e7b332 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/ReadWriteInfo.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/ReadWriteInfo.hs @@ -354,21 +354,22 @@ readWriteInfo i VTRNd32, VTRNd8, VTRNq16, VTRNq32, VTRNq8, VTSTv16i8, VTSTv2i32, VTSTv4i16, VTSTv4i32, VTSTv8i16, VTSTv8i8, VUHTOD, VUHTOS, VUITOD, VUITOS, VULTOD, VULTOS, VUZPd16, VUZPd8, VUZPq16, VUZPq32, VUZPq8, - VZIPd16, VZIPd8, VZIPq16, VZIPq32, VZIPq8, Load_merge, T2ADDri, - T2ADDri12, T2ADDri_cpsr, T2ADDri_fi, T2ADDri_fi_demat_fi, - T2ADDri_fi_remat_fi, T2ADDri_fi_source_fi, T2ADDricc, T2ADDrr, - T2ADDrrcc, T2ADDrs, T2ADDrscc, T2ADR, T2ANDri, T2ANDri_cpsr, - T2ANDricc, T2ANDrr, T2ANDrs, T2ASRri, T2ASRrr, T2B, T2BFC, T2BFI, - T2BICri, T2BICrr, T2BICrs, T2BR_JT, T2BXJ, T2Bcc, T2CDP, T2CDP2, - T2CLREX, T2CLZ, T2CMNri_cpsr, T2CMPri_cpsr, T2CMPrr_cpsr, - T2CMPrs_cpsr, T2CPS1p, T2CPS2p, T2CPS3p, T2CRC32B, T2CRC32CB, - T2CRC32CH, T2CRC32CW, T2CRC32H, T2CRC32W, T2DBG, T2DCPS1, T2DCPS2, - T2DCPS3, T2DMB, T2DSB, T2EORri, T2EORrr, T2EORrs, T2HINT, T2HVC, - T2ISB, T2LDA, T2LDAB, T2LDAH, T2LDC2L_OFFSET, T2LDC2L_OPTION, - T2LDC2L_POST, T2LDC2L_PRE, T2LDC2_OFFSET, T2LDC2_OPTION, - T2LDC2_POST, T2LDC2_PRE, T2LDCL_OFFSET, T2LDCL_OPTION, T2LDCL_POST, - T2LDCL_PRE, T2LDC_OFFSET, T2LDC_OPTION, T2LDC_POST, T2LDC_PRE, - T2LDRBT, T2LDRBi12, T2LDRBi12_fi, T2LDRBi12_fi_demat_fi, + VZIPd16, VZIPd8, VZIPq16, VZIPq32, VZIPq8, Load_merge, + Register_class_decl_dummy, T2ADDri, T2ADDri12, T2ADDri_cpsr, + T2ADDri_fi, T2ADDri_fi_demat_fi, T2ADDri_fi_remat_fi, + T2ADDri_fi_source_fi, T2ADDricc, T2ADDrr, T2ADDrrcc, T2ADDrs, + T2ADDrscc, T2ADR, T2ANDri, T2ANDri_cpsr, T2ANDricc, T2ANDrr, + T2ANDrs, T2ASRri, T2ASRrr, T2B, T2BFC, T2BFI, T2BICri, T2BICrr, + T2BICrs, T2BR_JT, T2BXJ, T2Bcc, T2CDP, T2CDP2, T2CLREX, T2CLZ, + T2CMNri_cpsr, T2CMPri_cpsr, T2CMPrr_cpsr, T2CMPrs_cpsr, T2CPS1p, + T2CPS2p, T2CPS3p, T2CRC32B, T2CRC32CB, T2CRC32CH, T2CRC32CW, + T2CRC32H, T2CRC32W, T2DBG, T2DCPS1, T2DCPS2, T2DCPS3, T2DMB, T2DSB, + T2EORri, T2EORrr, T2EORrs, T2HINT, T2HVC, T2ISB, T2LDA, T2LDAB, + T2LDAH, T2LDC2L_OFFSET, T2LDC2L_OPTION, T2LDC2L_POST, T2LDC2L_PRE, + T2LDC2_OFFSET, T2LDC2_OPTION, T2LDC2_POST, T2LDC2_PRE, + T2LDCL_OFFSET, T2LDCL_OPTION, T2LDCL_POST, T2LDCL_PRE, + T2LDC_OFFSET, T2LDC_OPTION, T2LDC_POST, T2LDC_PRE, T2LDRBT, + T2LDRBi12, T2LDRBi12_fi, T2LDRBi12_fi_demat_fi, T2LDRBi12_fi_remat_fi, T2LDRBi12_fi_source_fi, T2LDRBi8, T2LDRBpci, T2LDRBpcrel, T2LDRBs, T2LDRHT, T2LDRHi12, T2LDRHi12_fi, T2LDRHi8, T2LDRHpci, T2LDRHpcrel, T2LDRHs, T2LDRSBT, T2LDRSBi12, T2LDRSBi8, diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/ShowInstance.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/ShowInstance.hs index 73229f66..c3f28d2a 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/ShowInstance.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/ShowInstance.hs @@ -3068,6 +3068,7 @@ instance Show ARMInstruction where show T2SUBrrcc = "t2SUBrrcc" show T2ADDrrcc = "t2ADDrrcc" show T2ADDrscc = "t2ADDrscc" + show Register_class_decl_dummy = "register_class_decl_dummy" show T2MOVi_source = "t2MOVi_source" show T2MOVi_demat = "t2MOVi_demat" show T2MOVi_remat = "t2MOVi_remat" diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/Size.hs b/src/unison/src/Unison/Target/ARM/SpecsGen/Size.hs index 147246e4..17603d8d 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/Size.hs +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/Size.hs @@ -104,8 +104,8 @@ size i VST4qAsm_32, VST4qAsm_8, VST4qWB_fixed_Asm_16, VST4qWB_fixed_Asm_32, VST4qWB_fixed_Asm_8, VST4qWB_register_Asm_16, VST4qWB_register_Asm_32, VST4qWB_register_Asm_8, WIN__CHKSTK, - WIN__DBZCHK, Load_merge, T2ABS, T2ADDri_fi_demat_fi, - T2ADDri_fi_source_fi, T2Int_eh_sjlj_setjmp, + WIN__DBZCHK, Load_merge, Register_class_decl_dummy, T2ABS, + T2ADDri_fi_demat_fi, T2ADDri_fi_source_fi, T2Int_eh_sjlj_setjmp, T2Int_eh_sjlj_setjmp_nofp, T2LDRBi12_fi_demat_fi, T2LDRBi12_fi_source_fi, T2LDRBpcrel, T2LDRHpcrel, T2LDRSBpcrel, T2LDRSHpcrel, T2LDRi12_fi_demat_fi, T2LDRi12_fi_source_fi, diff --git a/src/unison/src/Unison/Target/ARM/SpecsGen/input/arm-manual.yaml b/src/unison/src/Unison/Target/ARM/SpecsGen/input/arm-manual.yaml index bb548773..a9adb78f 100644 --- a/src/unison/src/Unison/Target/ARM/SpecsGen/input/arm-manual.yaml +++ b/src/unison/src/Unison/Target/ARM/SpecsGen/input/arm-manual.yaml @@ -1490,4 +1490,17 @@ instruction-set: - p1: bound - p2: bound - s: [register, use, CCR] - uses: [Rn, ShiftedRm1, ShiftedRm2, Rd, p1, p2, s] \ No newline at end of file + uses: [Rn, ShiftedRm1, ShiftedRm2, Rd, p1, p2, s] + + - id: register_class_decl_dummy + type: linear + operands: + - f32: [register, use, F32] + - crs: [register, use, CRS] + - fcrs: [register, use, FCRS] + uses: [f32, crs, fcrs] + defines: [] + size: 0 + affects: + affected-by: + itinerary: NoItinerary \ No newline at end of file diff --git a/src/unison/src/Unison/Target/ARM/Transforms.hs b/src/unison/src/Unison/Target/ARM/Transforms.hs index 190bb344..809ec665 100644 --- a/src/unison/src/Unison/Target/ARM/Transforms.hs +++ b/src/unison/src/Unison/Target/ARM/Transforms.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -661,7 +661,11 @@ reoderCalleeSavedStores b = moveOperations isCalleeSavedPrologue after isIn b isCalleeSavedPrologue o = any (\i -> isInstr i o) [VSTMDDB_UPD_d8_15, TPUSH2_r4_7, TFP] -moveFP b = moveOperations (isInstr TFP) after (isInstr TPUSH2_r4_7) b +moveFP b + | any isTPushDel (bCode b) = moveOperations (isInstr TFP) after isTPushDel b + | otherwise = b + +isTPushDel = isInstr TPUSH2_r4_7 reoderCalleeSavedLoads b = foldl (\b0 i -> moveOperations (isInstr i) before isTerm b0) diff --git a/src/unison/src/Unison/Target/Hexagon.hs b/src/unison/src/Unison/Target/Hexagon.hs index bba48ec1..9d9feb02 100644 --- a/src/unison/src/Unison/Target/Hexagon.hs +++ b/src/unison/src/Unison/Target/Hexagon.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -21,7 +21,6 @@ import Control.Arrow import Common.Util import MachineIR hiding (parse) -import MachineIR.Transformations.AddImplicitRegs import Unison import qualified Unison.Target.API as API @@ -33,8 +32,8 @@ import Unison.Target.Hexagon.Transforms import Unison.Target.Hexagon.Usages import Unison.Target.Hexagon.Common import Unison.Target.Hexagon.HexagonRegisterDecl -import Unison.Target.Hexagon.HexagonRegisterClassDecl import Unison.Target.Hexagon.HexagonResourceDecl +import Unison.Target.Hexagon.SpecsGen.HexagonRegisterClassDecl import Unison.Target.Hexagon.SpecsGen.HexagonInstructionDecl import qualified Unison.Target.Hexagon.SpecsGen as SpecsGen @@ -78,7 +77,8 @@ target = API.tReadWriteLatency = const readWriteLatency, API.tAlternativeTemps = const alternativeTemps, API.tExpandCopy = const expandCopy, - API.tConstraints = constraints + API.tConstraints = constraints, + API.tSpillOverhead = const spillOverhead } -- | Gives the type of natural operation according to the instruction @@ -248,12 +248,10 @@ isReserved r = r `elem` reserved rematInstrs i | isRematerializable i = Just (sourceInstr i, dematInstr i, rematInstr i) - | otherwise = error ("unmatched: rematInstrs " ++ show i) + | otherwise = Nothing -- | Transforms copy instructions into natural instructions - --- handle regular copies -fromCopy _ Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} +fromCopy Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} | i `elem` [MVW, MVD, MVPR, MVRP] = Linear {oIs = [TargetInstruction (fromCopyInstr i)], oUs = [s], @@ -266,27 +264,14 @@ fromCopy _ Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} Linear {oIs = [TargetInstruction (fromCopyInstr i)], oUs = [mkOprHexagonSP, mkBoundMachineFrameObject i s], oDs = [d]} - --- handle rematerialization copies -fromCopy (Just (Linear {oUs = us})) - Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} - | isDematInstr i = - Linear {oIs = [mkNullInstruction], oUs = [s], oDs = [d]} - | isRematInstr i = - Linear {oIs = [TargetInstruction (originalInstr i)], oUs = us, oDs = [d]} - --- handle rematerialization sources -fromCopy _ (Natural o @ Linear {oIs = [TargetInstruction i]}) - | isSourceInstr i = o {oIs = [mkNullInstruction]} - -fromCopy _ (Natural o) = o -fromCopy _ o = error ("unmatched pattern: fromCopy " ++ show o) +fromCopy (Natural o) = o +fromCopy o = error ("unmatched pattern: fromCopy " ++ show o) mkOprHexagonSP = Register $ mkTargetRegister hexagonSP mkBoundMachineFrameObject i (Register r) = let size = stackSize i - in mkBound (mkMachineFrameObject (infRegPlace r * 4) (Just size) size) + in mkBound (mkMachineFrameObject (infRegPlace r * 4) (Just size) size False) stackSize op | op `elem` [STW, STW_nv, LDW] = 4 @@ -532,8 +517,7 @@ machineInstructionToList MachineBundle {mbInstrs = mis} = mis postProcess = [lintStackAlignment, constantDeExtend, removeFrameIndex, normalizeNewValueCmpJump, normalizeNVJumps, normalizeJRInstrs, - expandCondTransfers, addJumpHints, - flip addImplicitRegs (target, [])] + expandCondTransfers, addJumpHints] lintStackAlignment = mapToTargetMachineInstruction lintStackAlignmentInInstr @@ -806,3 +790,12 @@ isCmpComboTargetInstr _ = False isJumpComboTargetInstr (TargetInstruction i) = isComboNVCJ i isJumpComboTargetInstr _ = False + + +spillOverhead (i, sp:_, _) + | i `elem` [S2_storeri_io, S2_storerd_io, S2_storerinew_io] && + sp == mkOprHexagonSP = Just (True, 1) +spillOverhead (i, sp:_, _) + | i `elem` [L2_loadri_io, L2_loadrd_io] && + sp == mkOprHexagonSP = Just (False, 1) +spillOverhead _ = Nothing diff --git a/src/unison/src/Unison/Target/Hexagon/Common.hs b/src/unison/src/Unison/Target/Hexagon/Common.hs index 6975cbd9..2681b78a 100644 --- a/src/unison/src/Unison/Target/Hexagon/Common.hs +++ b/src/unison/src/Unison/Target/Hexagon/Common.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/Hexagon/HexagonRegisterClassDecl.hs b/src/unison/src/Unison/Target/Hexagon/HexagonRegisterClassDecl.hs deleted file mode 100644 index 81012edd..00000000 --- a/src/unison/src/Unison/Target/Hexagon/HexagonRegisterClassDecl.hs +++ /dev/null @@ -1,39 +0,0 @@ -{-| -Copyright : Copyright (c) 2016, RISE SICS AB -License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se --} -{- -Main authors: - Roberto Castaneda Lozano - -This file is part of Unison, see http://unison-code.github.io --} -module Unison.Target.Hexagon.HexagonRegisterClassDecl - (HexagonRegisterClass (..)) where - -data HexagonRegisterClass = - CtrRegs | - CtrRegs64 | - DoubleRegs | - IntRegs | - IntRegsLow8 | - ModRegs | - PredRegs | - VecDblRegs | - VecDblRegs128B | - VecPredRegs | - VecPredRegs128B | - VectorRegs | - VectorRegs128B | - F32 | - M32 | - M64 | - P64 | - P128 | - G128 | - G256 | - RM32 | - RM64 | - Ptr_rc - deriving (Eq, Ord, Show, Read) diff --git a/src/unison/src/Unison/Target/Hexagon/HexagonRegisterDecl.hs b/src/unison/src/Unison/Target/Hexagon/HexagonRegisterDecl.hs index e3879f4b..85a90a9c 100644 --- a/src/unison/src/Unison/Target/Hexagon/HexagonRegisterDecl.hs +++ b/src/unison/src/Unison/Target/Hexagon/HexagonRegisterDecl.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/Hexagon/Registers.hs b/src/unison/src/Unison/Target/Hexagon/Registers.hs index 8eea38a5..05652b09 100644 --- a/src/unison/src/Unison/Target/Hexagon/Registers.hs +++ b/src/unison/src/Unison/Target/Hexagon/Registers.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -18,7 +18,7 @@ import qualified Data.Map as M import Unison import Unison.Target.Hexagon.HexagonRegisterDecl -import Unison.Target.Hexagon.HexagonRegisterClassDecl +import Unison.Target.Hexagon.SpecsGen.HexagonRegisterClassDecl -- | Register array @@ -146,7 +146,7 @@ reserved = [R29, R30, R31] callerSaved = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R28, - P0, P1, P2, P3] + P0, P1, P2, P3, F0] -- | Registers that are preserved across calls -- | see getCalleeSavedRegs() function in HexagonRegisterInfo.cpp diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen.hs index 56c71fa5..31d7148b 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/AlignedPairs.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/AlignedPairs.hs index 97e5f1c7..342b1817 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/AlignedPairs.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/AlignedPairs.hs @@ -847,6 +847,8 @@ alignedPairs i ([_, _], []) J2_loop1i_ce, J2_loop1iext, J2_loop1iext_ce, J2_loop1r, J2_loop1r_ce, J2_loop1rext, J2_loop1rext_ce] = [] +alignedPairs i ([_, _, _, _], []) + | i `elem` [Register_class_decl_dummy] = [] alignedPairs i ([_, _], []) | i `elem` [J2_ploop1sr, J2_ploop1sr_ce, J2_ploop2sr, J2_ploop2sr_ce, diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/AllInstructions.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/AllInstructions.hs index 81d752d6..22ab8bba 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/AllInstructions.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/AllInstructions.hs @@ -716,38 +716,39 @@ allInstructions Ret_dealloc_merge, JMPret_linear, Jr_merge, C2_mux_tfr, C2_muxii_tfr, C2_muxir_tfr, C2_muxri_tfr, C2_mux_tfr_new, C2_muxii_tfr_new, C2_muxir_tfr_new, C2_muxri_tfr_new, - A2_tfrsi_source, A2_tfrsi_demat, A2_tfrsi_remat, A2_tfrpi_source, - A2_tfrpi_demat, A2_tfrpi_remat, L2_loadri_io_fi_source_fi, - L2_loadri_io_fi_demat_fi, L2_loadri_io_fi_remat_fi, - L2_loadrb_io_fi_source_fi, L2_loadrb_io_fi_demat_fi, - L2_loadrb_io_fi_remat_fi, L2_loadruh_io_fi_source_fi, - L2_loadruh_io_fi_demat_fi, L2_loadruh_io_fi_remat_fi, - L4_loadrb_abs_source, L4_loadrb_abs_demat, L4_loadrb_abs_remat, - L4_loadri_abs_source, L4_loadri_abs_demat, L4_loadri_abs_remat, - L4_loadrh_abs_source, L4_loadrh_abs_demat, L4_loadrh_abs_remat, - L4_loadruh_abs_source, L4_loadruh_abs_demat, L4_loadruh_abs_remat, - L4_loadrub_abs_source, L4_loadrub_abs_demat, L4_loadrub_abs_remat, - TFR_FI_fi_source_fi, TFR_FI_fi_demat_fi, TFR_FI_fi_remat_fi, - L2_loadrigp_source, L2_loadrigp_demat, L2_loadrigp_remat, - L2_loadrhgp_source, L2_loadrhgp_demat, L2_loadrhgp_remat, - L2_loadrubgp_source, L2_loadrubgp_demat, L2_loadrubgp_remat, - L2_loadruhgp_source, L2_loadruhgp_demat, L2_loadruhgp_remat, - CONST64_Int_Real_source, CONST64_Int_Real_demat, - CONST64_Int_Real_remat, L2_loadrd_io_fi_source_fi, - L2_loadrd_io_fi_demat_fi, L2_loadrd_io_fi_remat_fi, - L4_loadrd_abs_source, L4_loadrd_abs_demat, L4_loadrd_abs_remat, - TFR_PdFalse_source, TFR_PdFalse_demat, TFR_PdFalse_remat, - TFR_PdTrue_source, TFR_PdTrue_demat, TFR_PdTrue_remat, A2_addi_ce, - A2_andir_ce, A2_combineii_ce, A2_orir_ce, A2_paddif_ce, - A2_paddifnew_ce, A2_paddit_ce, A2_padditnew_ce, A2_subri_ce, - A2_tfrih_ce, A2_tfril_ce, A2_tfrpi_ce, A2_tfrsi_ce, - A4_bitspliti_ce, A4_cmpbeqi_ce, A4_cmpbgti_ce, A4_cmpbgtui_ce, - A4_cmpheqi_ce, A4_cmphgti_ce, A4_cmphgtui_ce, A4_combineii_ce, - A4_combineir_ce, A4_combineri_ce, A4_cround_ri_ce, A4_ext_ce, - A4_ext_b_ce, A4_ext_c_ce, A4_ext_g_ce, A4_rcmpeqi_ce, - A4_rcmpneqi_ce, A4_round_ri_ce, A4_round_ri_sat_ce, A4_vcmpbeqi_ce, - A4_vcmpbgti_ce, A4_vcmpbgtui_ce, A4_vcmpheqi_ce, A4_vcmphgti_ce, - A4_vcmphgtui_ce, A4_vcmpweqi_ce, A4_vcmpwgti_ce, A4_vcmpwgtui_ce, + Register_class_decl_dummy, A2_tfrsi_source, A2_tfrsi_demat, + A2_tfrsi_remat, A2_tfrpi_source, A2_tfrpi_demat, A2_tfrpi_remat, + L2_loadri_io_fi_source_fi, L2_loadri_io_fi_demat_fi, + L2_loadri_io_fi_remat_fi, L2_loadrb_io_fi_source_fi, + L2_loadrb_io_fi_demat_fi, L2_loadrb_io_fi_remat_fi, + L2_loadruh_io_fi_source_fi, L2_loadruh_io_fi_demat_fi, + L2_loadruh_io_fi_remat_fi, L4_loadrb_abs_source, + L4_loadrb_abs_demat, L4_loadrb_abs_remat, L4_loadri_abs_source, + L4_loadri_abs_demat, L4_loadri_abs_remat, L4_loadrh_abs_source, + L4_loadrh_abs_demat, L4_loadrh_abs_remat, L4_loadruh_abs_source, + L4_loadruh_abs_demat, L4_loadruh_abs_remat, L4_loadrub_abs_source, + L4_loadrub_abs_demat, L4_loadrub_abs_remat, TFR_FI_fi_source_fi, + TFR_FI_fi_demat_fi, TFR_FI_fi_remat_fi, L2_loadrigp_source, + L2_loadrigp_demat, L2_loadrigp_remat, L2_loadrhgp_source, + L2_loadrhgp_demat, L2_loadrhgp_remat, L2_loadrubgp_source, + L2_loadrubgp_demat, L2_loadrubgp_remat, L2_loadruhgp_source, + L2_loadruhgp_demat, L2_loadruhgp_remat, CONST64_Int_Real_source, + CONST64_Int_Real_demat, CONST64_Int_Real_remat, + L2_loadrd_io_fi_source_fi, L2_loadrd_io_fi_demat_fi, + L2_loadrd_io_fi_remat_fi, L4_loadrd_abs_source, + L4_loadrd_abs_demat, L4_loadrd_abs_remat, TFR_PdFalse_source, + TFR_PdFalse_demat, TFR_PdFalse_remat, TFR_PdTrue_source, + TFR_PdTrue_demat, TFR_PdTrue_remat, A2_addi_ce, A2_andir_ce, + A2_combineii_ce, A2_orir_ce, A2_paddif_ce, A2_paddifnew_ce, + A2_paddit_ce, A2_padditnew_ce, A2_subri_ce, A2_tfrih_ce, + A2_tfril_ce, A2_tfrpi_ce, A2_tfrsi_ce, A4_bitspliti_ce, + A4_cmpbeqi_ce, A4_cmpbgti_ce, A4_cmpbgtui_ce, A4_cmpheqi_ce, + A4_cmphgti_ce, A4_cmphgtui_ce, A4_combineii_ce, A4_combineir_ce, + A4_combineri_ce, A4_cround_ri_ce, A4_ext_ce, A4_ext_b_ce, + A4_ext_c_ce, A4_ext_g_ce, A4_rcmpeqi_ce, A4_rcmpneqi_ce, + A4_round_ri_ce, A4_round_ri_sat_ce, A4_vcmpbeqi_ce, A4_vcmpbgti_ce, + A4_vcmpbgtui_ce, A4_vcmpheqi_ce, A4_vcmphgti_ce, A4_vcmphgtui_ce, + A4_vcmpweqi_ce, A4_vcmpwgti_ce, A4_vcmpwgtui_ce, ADJCALLSTACKDOWN_ce, ADJCALLSTACKUP_ce, ALIGNA_ce, ALLOCA_ce, BUNDLE_ce, C2_bitsclri_ce, C2_cmoveif_ce, C2_cmoveit_ce, C2_cmovenewif_ce, C2_cmovenewit_ce, C2_cmpeqi_ce, C2_cmpgei_ce, diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/HexagonInstructionDecl.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/HexagonInstructionDecl.hs index cc2b4954..3b01406d 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/HexagonInstructionDecl.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/HexagonInstructionDecl.hs @@ -2626,6 +2626,7 @@ data HexagonInstruction = A2_abs | C2_muxii_tfr_new | C2_muxir_tfr_new | C2_muxri_tfr_new + | Register_class_decl_dummy | A2_tfrsi_source | A2_tfrsi_demat | A2_tfrsi_remat diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/HexagonRegisterClassDecl.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/HexagonRegisterClassDecl.hs new file mode 100644 index 00000000..f03cc038 --- /dev/null +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/HexagonRegisterClassDecl.hs @@ -0,0 +1,30 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Hexagon.SpecsGen.HexagonRegisterClassDecl + (HexagonRegisterClass(..)) where + +data HexagonRegisterClass = CtrRegs + | CtrRegs64 + | DoubleRegs + | F32 + | G128 + | G256 + | IntRegs + | IntRegsLow8 + | M32 + | M64 + | ModRegs + | P128 + | P64 + | PredRegs + | RM32 + | RM64 + | VecDblRegs + | VecDblRegs128B + | VecPredRegs + | VecPredRegs128B + | VectorRegs + | VectorRegs128B + | Ptr_rc + deriving (Eq, Ord, Read, Show) + diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/InstructionType.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/InstructionType.hs index ca5c8669..21072eaa 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/InstructionType.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/InstructionType.hs @@ -1144,6 +1144,6 @@ instructionType i Y2_isync, Y2_syncht, Y4_l2fetch, Y4_trace, Y5_l2fetch, Y5_l2gclean, Y5_l2gcleaninv, Y5_l2gunlock, Y5_l2locka, Y5_l2unlocka, Y6_l2gcleaninvpa, Y6_l2gcleanpa, Dep_A2_addsat, Dep_A2_subsat, - Dep_S2_packhl, Ret_dealloc_merge] + Dep_S2_packhl, Register_class_decl_dummy, Ret_dealloc_merge] = LinearInstructionType diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/Itinerary.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/Itinerary.hs index 992b94c1..61ff4b92 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/Itinerary.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/Itinerary.hs @@ -893,7 +893,8 @@ itinerary i TFR_FI_fi_demat_fi_ce, TFR_FI_fi_source_fi, TFR_FI_fi_source_fi_ce, TFR_PdFalse_demat, TFR_PdFalse_demat_ce, TFR_PdFalse_source, TFR_PdTrue_demat, TFR_PdTrue_demat_ce, TFR_PdTrue_source, Jr_merge, - Jump_merge, Jump_merge_ce, Ret_dealloc_merge] + Jump_merge, Jump_merge_ce, Register_class_decl_dummy, + Ret_dealloc_merge] = NoItinerary | i `elem` [V4_SA1_addi, V4_SA1_addi_ce, V4_SA1_addrx, V4_SA1_addsp, diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/OperandInfo.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/OperandInfo.hs index c4203b08..68e0efc1 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/OperandInfo.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/OperandInfo.hs @@ -4,7 +4,7 @@ module Unison.Target.Hexagon.SpecsGen.OperandInfo (operandInfo) where import Unison import Unison.Target.Hexagon.SpecsGen.HexagonInstructionDecl -import Unison.Target.Hexagon.HexagonRegisterClassDecl +import Unison.Target.Hexagon.SpecsGen.HexagonRegisterClassDecl operandInfo i | i `elem` [A2_nop, DuplexIClass0, DuplexIClass1, DuplexIClass2, @@ -1170,6 +1170,12 @@ operandInfo i | i `elem` [LDD, LDD_ce] = ([TemporaryInfo (InfiniteRegisterClass M64) 0 False], [TemporaryInfo (RegisterClass DoubleRegs) 1 False]) + | i `elem` [Register_class_decl_dummy] = + ([TemporaryInfo (RegisterClass P64) 0 False, + TemporaryInfo (RegisterClass P128) 0 False, + TemporaryInfo (RegisterClass G128) 0 False, + TemporaryInfo (RegisterClass G256) 0 False], + []) | i `elem` [C2_mux_tfr_new] = ([TemporaryInfo (RegisterClass PredRegs) (-1) True, TemporaryInfo (RegisterClass IntRegs) 0 False, diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/Parent.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/Parent.hs index ae8fbdff..35360823 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/Parent.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/Parent.hs @@ -1070,7 +1070,7 @@ parent i Y5_l2gcleaninv, Y5_l2gunlock, Y5_l2locka, Y5_l2unlocka, Y6_l2gcleaninvpa, Y6_l2gcleanpa, Dep_A2_addsat, Dep_A2_subsat, Dep_S2_packhl, Jr_merge, Jump_merge, Jump_merge_ce, - Ret_dealloc_merge] + Register_class_decl_dummy, Ret_dealloc_merge] = Nothing | i `elem` [MVW, MVW_ce] = Just A2_tfr | i `elem` [MVD, MVD_ce] = Just A2_tfrp diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/ReadOp.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/ReadOp.hs index 91eb0baa..55c789d8 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/ReadOp.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/ReadOp.hs @@ -2633,6 +2633,7 @@ readOp "C2_mux_tfr_new" = C2_mux_tfr_new readOp "C2_muxii_tfr_new" = C2_muxii_tfr_new readOp "C2_muxir_tfr_new" = C2_muxir_tfr_new readOp "C2_muxri_tfr_new" = C2_muxri_tfr_new +readOp "register_class_decl_dummy" = Register_class_decl_dummy readOp "A2_tfrsi_source" = A2_tfrsi_source readOp "A2_tfrsi_demat" = A2_tfrsi_demat readOp "A2_tfrsi_remat" = A2_tfrsi_remat diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/ReadWriteInfo.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/ReadWriteInfo.hs index 82bc2e62..807622b2 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/ReadWriteInfo.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/ReadWriteInfo.hs @@ -483,7 +483,8 @@ readWriteInfo i V6_vzh, V6_vzh_128B, VMULW, VMULW_ACC, VSelectDblPseudo_V6, VSelectPseudo_V6, Y2_barrier, Y2_dcfetchbo, Y2_dcfetchbo_ce, Y2_icinva, Y2_isync, Y4_trace, Dep_A2_addsat, Dep_A2_subsat, - Dep_S2_packhl, Jump_merge, Jump_merge_ce] + Dep_S2_packhl, Jump_merge, Jump_merge_ce, + Register_class_decl_dummy] = ([], []) | i `elem` [S2_pstorerbf_io, S2_pstorerbf_io_ce, S2_pstorerbf_pi, diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/ShowInstance.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/ShowInstance.hs index 9201329e..1a858699 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/ShowInstance.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/ShowInstance.hs @@ -2632,6 +2632,7 @@ instance Show HexagonInstruction where show C2_muxii_tfr_new = "C2_muxii_tfr_new" show C2_muxir_tfr_new = "C2_muxir_tfr_new" show C2_muxri_tfr_new = "C2_muxri_tfr_new" + show Register_class_decl_dummy = "register_class_decl_dummy" show A2_tfrsi_source = "A2_tfrsi_source" show A2_tfrsi_demat = "A2_tfrsi_demat" show A2_tfrsi_remat = "A2_tfrsi_remat" diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/Size.hs b/src/unison/src/Unison/Target/Hexagon/SpecsGen/Size.hs index 265d531a..00237c0a 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/Size.hs +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/Size.hs @@ -42,7 +42,7 @@ size i STATEPOINT_ce, SUBREG_TO_REG, SUBREG_TO_REG_ce, TFR_PdFalse_demat, TFR_PdFalse_demat_ce, TFR_PdFalse_source, TFR_PdTrue_demat, TFR_PdTrue_demat_ce, TFR_PdTrue_source, Jr_merge, Jump_merge, - Jump_merge_ce, Ret_dealloc_merge] + Jump_merge_ce, Register_class_decl_dummy, Ret_dealloc_merge] = 0 | i `elem` [L2_loadrb_io_fi, L2_loadrb_io_fi_ce, L2_loadrb_io_fi_demat_fi, diff --git a/src/unison/src/Unison/Target/Hexagon/SpecsGen/input/hexagon-manual.yaml b/src/unison/src/Unison/Target/Hexagon/SpecsGen/input/hexagon-manual.yaml index 4aee6f47..fd2772e5 100644 --- a/src/unison/src/Unison/Target/Hexagon/SpecsGen/input/hexagon-manual.yaml +++ b/src/unison/src/Unison/Target/Hexagon/SpecsGen/input/hexagon-manual.yaml @@ -652,4 +652,18 @@ instruction-set: - s8: bound - Rs: [register, use, IntRegs] size: 8 - itinerary: ALU32_SLOT0123_2 \ No newline at end of file + itinerary: ALU32_SLOT0123_2 + + - id: register_class_decl_dummy + type: linear + operands: + - p64: [register, use, P64] + - p128: [register, use, P128] + - g128: [register, use, G128] + - g256: [register, use, G256] + uses: [p64, p128, g128, g256] + defines: [] + size: 0 + affects: + affected-by: + itinerary: NoItinerary \ No newline at end of file diff --git a/src/unison/src/Unison/Target/Hexagon/Transforms.hs b/src/unison/src/Unison/Target/Hexagon/Transforms.hs index faf210f7..a0410914 100644 --- a/src/unison/src/Unison/Target/Hexagon/Transforms.hs +++ b/src/unison/src/Unison/Target/Hexagon/Transforms.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/Minimal.hs b/src/unison/src/Unison/Target/Minimal.hs new file mode 100644 index 00000000..bbd11c5a --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal.hs @@ -0,0 +1,256 @@ +{-| +Copyright : Copyright (c) 2020, RISE SICS AB +License : BSD3 (see the LICENSE file) +Maintainer : rcas@acm.org +-} +{- +Main authors: + Roberto Castaneda Lozano + +This file is part of Unison, see http://unison-code.github.io +-} +module Unison.Target.Minimal (target) where + +import qualified Data.Set as S +import Data.Maybe +import qualified Data.Map as M + +import MachineIR hiding (parse) + +import Unison +import qualified Unison.Target.API as API +import Unison.Target.RegisterArray + +import Unison.Target.Minimal.MinimalRegisterDecl +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +import Unison.Target.Minimal.SpecsGen.MinimalRegisterClassDecl +import qualified Unison.Target.Minimal.SpecsGen as SpecsGen + +target = + API.TargetDescription { + API.tRegisterArray = const registerArray, + API.tRegisterAtoms = const registerAtoms, + API.tRegClasses = const regClasses, + API.tRegisters = const registers, + API.tInfRegClassUsage = const infRegClassUsage, + API.tInfRegClassBound = const infRegClassBound, + API.tSubRegIndexType = const subRegIndexType, + API.tCallerSaved = const callerSaved, + API.tCalleeSaved = const calleeSaved, + API.tReserved = const reserved, + API.tInstructionType = const instructionType, + API.tBranchInfo = const branchInfo, + API.tPreProcess = const preProcess, + API.tPostProcess = const postProcess, + API.tTransforms = const transforms, + API.tCopies = const copies, + API.tRematInstrs = const rematInstrs, + API.tFromCopy = const fromCopy, + API.tOperandInfo = const operandInfo, + API.tAlignedPairs = const alignedPairs, + API.tPackedPairs = const packedPairs, + API.tRelatedPairs = const relatedPairs, + -- Pass target options to 'resources' to specify target width + API.tResources = resources, + API.tUsages = const usages, + API.tNop = const nop, + API.tReadWriteInfo = const readWriteInfo, + API.tImplementFrame = const implementFrame, + API.tAddPrologue = const addPrologue, + API.tAddEpilogue = const addEpilogue, + API.tStackDirection = const stackDirection, + API.tReadWriteLatency = const readWriteLatency, + API.tAlternativeTemps = const alternativeTemps, + API.tExpandCopy = const expandCopy, + API.tConstraints = const constraints, + API.tSpillOverhead = const spillOverhead + } + +instance Read MinimalInstruction where + readsPrec _ strOp = [(SpecsGen.readOp strOp, "")] + +-- | Register array +registerArray = [RegisterClass R32, InfiniteRegisterClass M32] + +-- | Register atoms +registerAtoms ra = (ra, ra) + +-- | Register classes +regClasses = [RegisterClass R32, InfiniteRegisterClass M32] + +-- | Individual registers of each register class +registers (RegisterClass R32) = [R0, R1, R2, R3, R4, R5, R6, R7] + +-- | Map from infinite register class to register usage +infRegClassUsage (InfiniteRegisterClass M32) = 1 + +-- | Map from infinite register class to (possibly) register atom upper bound +infRegClassBound = const Nothing + +-- | Index type (low/high/copy) of subregisters +subRegIndexType _ subreg = error ("unmatched: subRegIndexType " ++ show subreg) + +-- | Registers that are not preserved across calls +callerSaved = [R0, R1, R2, R3] + +-- | Registers that are preserved across calls +calleeSaved = [R4, R5, R6] + +-- | Registers whose value cannot be moved around +reserved = [R7] + +instance Read MinimalRegister where + readsPrec _ s = [(readReg s, "")] + +readReg s = case M.lookup s (inverseMap regStrings) of + (Just r) -> r + Nothing -> error $ "unmatched: readReg " ++ s + +instance Show MinimalRegister where + show r = case M.lookup r regStrings of + (Just s) -> s + Nothing -> error $ "unmatched: show MinimalRegister" + +regStrings = M.fromList $ + [(R0, "r0"), (R1, "r1"), (R2, "r2"), (R3, "r3"), + (R4, "r4"), (R5, "r5"), (R6, "r6"), (R7, "r7")] + +-- | Gives the type of natural instruction according to the operation +instructionType = SpecsGen.instructionType + +-- | Gives the target of a branch instruction and the type of branch +branchInfo (Branch {oBranchIs = is, oBranchUs = [_, BlockRef l]}) + | targetInst is `elem` [Bif] = BranchInfo Conditional (Just l) +branchInfo (Branch {oBranchIs = is, oBranchUs = [BlockRef l]}) + | targetInst is `elem` [B] = BranchInfo Unconditional (Just l) +branchInfo (Branch {oBranchIs = is}) + | targetInst is `elem` [Br] = BranchInfo Unconditional Nothing +branchInfo o = error ("unmatched pattern: branchInfo " ++ show (mkSingleOperation (-1) (Natural o))) + +-- | Target dependent MIR pre-processing functions +preProcess = [] + +-- | Target dependent MIR post-processing functions +postProcess = [] + +-- | Gives a list of function transformers +transforms _ = [] + +-- | Set of def copies and list of sets of use copies to extend a temporary + +-- Do not extend temporaries pre-allocated to reserved registers +copies _fInfo _phiTemp _t [r] _d us | r `elem` reserved = + ([], replicate (length us) []) +-- Add only one store for entry calle-saved temporaries +-- Add only one load for exit calle-saved temporaries +-- Do not add copies for intermediate calle-saved temporaries +copies (f, cst, _, _, _, _) False t [_] _d [_u] + | S.member t cst = + ( + if isEntryTemp (fCode f) t + then [mkNullInstruction, TargetInstruction Store] + else [], + [if isExitTemp (fCode f) t + then [mkNullInstruction, TargetInstruction Load] + else []] + ) +copies _ _ _ _ _d us = (defCopies, replicate (length us) useCopies) + +defCopies = [mkNullInstruction] ++ map TargetInstruction [Move, Store] +useCopies = [mkNullInstruction] ++ map TargetInstruction [Move, Load] + +-- | Gives rematerialization instruction triples of an instruction +rematInstrs _ = Nothing + +-- | Transforms copy instructions into natural instructions +fromCopy o @ Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} + | i `elem` [Move] = toLinear o + | i `elem` [Store] = + Linear {oIs = [TargetInstruction (fromCopyInstr i)], + oUs = [s, mkSP, mkBoundMachineFrameObject d], + oDs = []} + | i `elem` [Load] = + Linear {oIs = [TargetInstruction (fromCopyInstr i)], + oUs = [mkSP, mkBoundMachineFrameObject s], + oDs = [d]} +fromCopy (Natural o) = o +fromCopy o = error ("unmatched pattern: fromCopy " ++ show o) + +mkSP = Register $ mkTargetRegister R0 + +mkBoundMachineFrameObject (Register r) = + mkBound (mkMachineFrameObject (infRegPlace r) (Just 4) 4 False) + +fromCopyInstr = fromJust . SpecsGen.parent + +-- | Gives information about the operands of each instruction +operandInfo i = SpecsGen.operandInfo i + +-- | Gives pairs of aligned operands in each instruction +alignedPairs i os = SpecsGen.alignedPairs i os + +-- | Gives pairs of packed operands in each instruction +packedPairs _ _ = [] + +-- | Gives pairs of operands whose registers are related extensionally +relatedPairs _ = [] + +data MinimalResource = + -- Size of each instruction + BundleWidth | + -- Simple resource to enforce single-issue + Issue + deriving (Eq, Ord, Show, Read) + +-- | Declares target architecture resources. An issue width of w can be +-- specified with the option --targetoption=issue-width:w. +resources to = + let w = read $ fromMaybe "1" (API.optionValue "issue-width" to) + in + [ + -- Resource used for code size minimization + Resource BundleWidth w, + -- Issue width (single issue) + Resource Issue w + ] + +-- | Gives usages of the processor resources by each instruction +usages i = [mkUsage Issue 1 1, mkUsage BundleWidth (SpecsGen.size i) 1] + +-- | No-operation instruction +nop = Linear [TargetInstruction Nop] [] [] + +-- | Side-effects of each instruction +readWriteInfo = SpecsGen.readWriteInfo + +-- | Implementation of frame setup and destroy operations +implementFrame = const [] + +-- | Adds function prologue +addPrologue _ code = code + +-- | Adds function epilogue +addEpilogue _ code = code + +-- | Direction in which the stack grows +stackDirection = API.StackGrowsDown + +-- | Latency of read-write dependencies +readWriteLatency _ (_, Read) (_, Write) = 0 +readWriteLatency _ ((_, VirtualType (DelimiterType InType)), _) (_, _) = 1 +readWriteLatency _ ((_, VirtualType FunType), _) (_, _) = 1 +readWriteLatency _ ((_, VirtualType _), _) (_, _) = 0 +readWriteLatency _ ((TargetInstruction p, _), _) (_, _) = + maybeMax 0 $ map occupation (usages p) + +-- | Alternative temporaries of each operand +alternativeTemps _ _ _ ts = map fst ts + +-- | Copy expansion +expandCopy _ _ o = [o] + +-- | Custom processor constraints +constraints _ = [] + +-- | Spill sign and overhead of each instruction and operands +spillOverhead _ = Nothing diff --git a/src/unison/src/Unison/Target/Minimal/MinimalRegisterDecl.hs b/src/unison/src/Unison/Target/Minimal/MinimalRegisterDecl.hs new file mode 100644 index 00000000..0f8de6b6 --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/MinimalRegisterDecl.hs @@ -0,0 +1,23 @@ +{-| +Copyright : Copyright (c) 2020, RISE SICS AB +License : BSD3 (see the LICENSE file) +Maintainer : rcas@acm.org +-} +{- +Main authors: + Roberto Castaneda Lozano + +This file is part of Unison, see http://unison-code.github.io +-} +module Unison.Target.Minimal.MinimalRegisterDecl (MinimalRegister (..)) where + +data MinimalRegister = + R0 | + R1 | + R2 | + R3 | + R4 | + R5 | + R6 | + R7 + deriving (Eq, Ord) diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen.hs new file mode 100644 index 00000000..c9debb9a --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen.hs @@ -0,0 +1,22 @@ +{-| +Copyright : Copyright (c) 2020, RISE SICS AB +License : BSD3 (see the LICENSE file) +Maintainer : rcas@acm.org +-} +{- +Main authors: + Roberto Castaneda Lozano + +This file is part of Unison, see http://unison-code.github.io +-} +module Unison.Target.Minimal.SpecsGen (module X) where + import Unison.Target.Minimal.SpecsGen.ReadWriteInfo as X + import Unison.Target.Minimal.SpecsGen.OperandInfo as X + import Unison.Target.Minimal.SpecsGen.ReadOp as X + import Unison.Target.Minimal.SpecsGen.ShowInstance() + import Unison.Target.Minimal.SpecsGen.AllInstructions as X + import Unison.Target.Minimal.SpecsGen.Itinerary as X + import Unison.Target.Minimal.SpecsGen.InstructionType as X + import Unison.Target.Minimal.SpecsGen.AlignedPairs as X + import Unison.Target.Minimal.SpecsGen.Parent as X + import Unison.Target.Minimal.SpecsGen.Size as X diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/AlignedPairs.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/AlignedPairs.hs new file mode 100644 index 00000000..528345d8 --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/AlignedPairs.hs @@ -0,0 +1,16 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.AlignedPairs (alignedPairs) + where +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +alignedPairs i ([], []) | i `elem` [Nop] = [] +alignedPairs i ([_, _], [_]) | i `elem` [Ld] = [] +alignedPairs i ([_], []) | i `elem` [Br] = [] +alignedPairs i ([_], [_]) | i `elem` [Load, Move, Store] = [] +alignedPairs i ([_, _, _], []) | i `elem` [St] = [] +alignedPairs i ([_], [_]) | i `elem` [Li] = [] +alignedPairs i ([_, _], []) | i `elem` [Bif] = [] +alignedPairs i ([_, _], [_]) | i `elem` [Mul, Sgt, Sub] = [] +alignedPairs i ([_], []) | i `elem` [B] = [] +alignedPairs _ _ = [] + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/AllInstructions.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/AllInstructions.hs new file mode 100644 index 00000000..42f23d21 --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/AllInstructions.hs @@ -0,0 +1,8 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.AllInstructions + (allInstructions) where +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +allInstructions + = [Li, Sub, Mul, Sgt, Nop, Bif, B, Br, St, Ld, Store, Load, Move] + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/InstructionType.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/InstructionType.hs new file mode 100644 index 00000000..0d6436ce --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/InstructionType.hs @@ -0,0 +1,11 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.InstructionType + (instructionType) where +import Unison +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +instructionType i + | i `elem` [B, Bif, Br] = BranchInstructionType + | i `elem` [Load, Move, Store] = CopyInstructionType + | i `elem` [Ld, Li, Mul, Nop, Sgt, St, Sub] = LinearInstructionType + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/Itinerary.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/Itinerary.hs new file mode 100644 index 00000000..739e365d --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/Itinerary.hs @@ -0,0 +1,10 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.Itinerary (itinerary) where +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +import Unison.Target.Minimal.SpecsGen.MinimalItineraryDecl +itinerary i + | i `elem` + [B, Bif, Br, Ld, Li, Load, Move, Mul, Nop, Sgt, St, Store, Sub] + = IT + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalInstructionDecl.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalInstructionDecl.hs new file mode 100644 index 00000000..7560dd9c --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalInstructionDecl.hs @@ -0,0 +1,20 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl + (MinimalInstruction(..)) where + +data MinimalInstruction = Li + | Sub + | Mul + | Sgt + | Nop + | Bif + | B + | Br + | St + | Ld + | Store + | Load + | Move + deriving (Eq, Ord) + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalItineraryDecl.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalItineraryDecl.hs new file mode 100644 index 00000000..ef070fc3 --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalItineraryDecl.hs @@ -0,0 +1,8 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.MinimalItineraryDecl + (MinimalItinerary(..)) where + +data MinimalItinerary = IT + deriving (Eq, Ord, Read, Show) + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalRegisterClassDecl.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalRegisterClassDecl.hs new file mode 100644 index 00000000..bcb4213b --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/MinimalRegisterClassDecl.hs @@ -0,0 +1,9 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.MinimalRegisterClassDecl + (MinimalRegisterClass(..)) where + +data MinimalRegisterClass = M32 + | R32 + deriving (Eq, Ord, Read, Show) + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/OperandInfo.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/OperandInfo.hs new file mode 100644 index 00000000..4e71d426 --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/OperandInfo.hs @@ -0,0 +1,36 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.OperandInfo (operandInfo) + where +import Unison +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +import Unison.Target.Minimal.SpecsGen.MinimalRegisterClassDecl +operandInfo i + | i `elem` [Nop] = ([], []) + | i `elem` [Load] = + ([TemporaryInfo (InfiniteRegisterClass M32) 0 False], + [TemporaryInfo (RegisterClass R32) 1 False]) + | i `elem` [Ld] = + ([TemporaryInfo (InfiniteRegisterClass M32) 0 False, BoundInfo], + [TemporaryInfo (RegisterClass R32) 1 False]) + | i `elem` [Br] = ([TemporaryInfo (RegisterClass R32) 0 False], []) + | i `elem` [Store] = + ([TemporaryInfo (RegisterClass R32) 0 False], + [TemporaryInfo (InfiniteRegisterClass M32) 1 False]) + | i `elem` [Move] = + ([TemporaryInfo (RegisterClass R32) 0 False], + [TemporaryInfo (RegisterClass R32) 1 False]) + | i `elem` [St] = + ([TemporaryInfo (RegisterClass R32) 0 False, + TemporaryInfo (InfiniteRegisterClass M32) 0 False, BoundInfo], + []) + | i `elem` [Mul, Sgt, Sub] = + ([TemporaryInfo (RegisterClass R32) 0 False, + TemporaryInfo (RegisterClass R32) 0 False], + [TemporaryInfo (RegisterClass R32) 1 False]) + | i `elem` [Bif] = + ([TemporaryInfo (RegisterClass R32) 0 False, BlockRefInfo], []) + | i `elem` [Li] = + ([BoundInfo], [TemporaryInfo (RegisterClass R32) 1 False]) + | i `elem` [B] = ([BlockRefInfo], []) + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/Parent.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/Parent.hs new file mode 100644 index 00000000..0f0fba2c --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/Parent.hs @@ -0,0 +1,10 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.Parent (parent) where +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +parent i + | i `elem` [B, Bif, Br, Ld, Li, Move, Mul, Nop, Sgt, St, Sub] = + Nothing + | i `elem` [Load] = Just Ld + | i `elem` [Store] = Just St + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/ReadOp.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/ReadOp.hs new file mode 100644 index 00000000..1b2f58b2 --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/ReadOp.hs @@ -0,0 +1,19 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.ReadOp (readOp) where +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +readOp "li" = Li +readOp "sub" = Sub +readOp "mul" = Mul +readOp "sgt" = Sgt +readOp "nop" = Nop +readOp "bif" = Bif +readOp "b" = B +readOp "br" = Br +readOp "st" = St +readOp "ld" = Ld +readOp "store" = Store +readOp "load" = Load +readOp "move" = Move +readOp a = error ("unmatched: readOp " ++ show a) + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/ReadWriteInfo.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/ReadWriteInfo.hs new file mode 100644 index 00000000..6931b068 --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/ReadWriteInfo.hs @@ -0,0 +1,13 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.ReadWriteInfo (readWriteInfo) + where +import Unison +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +import Unison.Target.Minimal.MinimalRegisterDecl +readWriteInfo i + | i `elem` [B, Bif, Br, Li, Move, Mul, Nop, Sgt, Sub] = ([], []) + | i `elem` [St] = ([], [Memory "mem"]) + | i `elem` [Ld] = ([Memory "mem"], []) + | i `elem` [Load, Store] = ([OtherSideEffect R0], []) + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/ShowInstance.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/ShowInstance.hs new file mode 100644 index 00000000..d1328d8c --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/ShowInstance.hs @@ -0,0 +1,20 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.ShowInstance where +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl + +instance Show MinimalInstruction where + show Li = "li" + show Sub = "sub" + show Mul = "mul" + show Sgt = "sgt" + show Nop = "nop" + show Bif = "bif" + show B = "b" + show Br = "br" + show St = "st" + show Ld = "ld" + show Store = "store" + show Load = "load" + show Move = "move" + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/Size.hs b/src/unison/src/Unison/Target/Minimal/SpecsGen/Size.hs new file mode 100644 index 00000000..5160d57b --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/Size.hs @@ -0,0 +1,9 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Minimal.SpecsGen.Size (size) where +import Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl +size i + | i `elem` + [B, Bif, Br, Ld, Li, Load, Move, Mul, Nop, Sgt, St, Store, Sub] + = 1 + diff --git a/src/unison/src/Unison/Target/Minimal/SpecsGen/input/minimal.yaml b/src/unison/src/Unison/Target/Minimal/SpecsGen/input/minimal.yaml new file mode 100644 index 00000000..eda9d381 --- /dev/null +++ b/src/unison/src/Unison/Target/Minimal/SpecsGen/input/minimal.yaml @@ -0,0 +1,164 @@ +--- +instruction-set: + + - group: allInstructions + instructions: + + - id: li + type: linear + operands: + - dst: [register, def, R32] + - src: bound + uses: [src] + defines: [dst] + size: 1 + affects: + affected-by: + itinerary: IT + + - id: sub + type: linear + operands: + - dst: [register, def, R32] + - src1: [register, use, R32] + - src2: [register, use, R32] + uses: [src1, src2] + defines: [dst] + size: 1 + affects: + affected-by: + itinerary: IT + + - id: mul + type: linear + operands: + - dst: [register, def, R32] + - src1: [register, use, R32] + - src2: [register, use, R32] + uses: [src1, src2] + defines: [dst] + size: 1 + affects: + affected-by: + itinerary: IT + + - id: sgt + type: linear + operands: + - dst: [register, def, R32] + - src1: [register, use, R32] + - src2: [register, use, R32] + uses: [src1, src2] + defines: [dst] + size: 1 + affects: + affected-by: + itinerary: IT + + - id: nop + type: linear + operands: + uses: [] + defines: [] + size: 1 + affects: + affected-by: + itinerary: IT + + - id: bif + type: branch + operands: + - src: [register, use, R32] + - target: label + uses: [src, target] + defines: [] + size: 1 + affects: + affected-by: + itinerary: IT + + - id: b + type: branch + operands: + - target: label + uses: [target] + defines: [] + size: 1 + affects: + affected-by: + itinerary: IT + + - id: br + type: branch + operands: + - dst: [register, use, R32] + uses: [dst] + defines: [] + size: 1 + affects: + affected-by: + itinerary: IT + + - id: st + type: linear + operands: + - rt: [register, use, R32] + - addr1: [register, use, M32] + - addr2: bound + uses: [rt, addr1, addr2] + defines: [] + size: 1 + affects: + - mem: memory + affected-by: + itinerary: IT + + - id: ld + type: linear + operands: + - rt: [register, def, R32] + - addr1: [register, use, M32] + - addr2: bound + uses: [addr1, addr2] + defines: [rt] + size: 1 + affects: + affected-by: + - mem: memory + itinerary: IT + + - id: store + parent: st + type: copy + operands: + - rd: [register, def, M32] + - rt: [register, use, R32] + uses: [rt] + defines: [rd] + affects: + affected-by: + - R0: register + + - id: load + parent: ld + type: copy + operands: + - rd: [register, def, R32] + - rt: [register, use, M32] + uses: [rt] + defines: [rd] + affects: + affected-by: + - R0: register + + - id: move + type: copy + operands: + - rd: [register, def, R32] + - rt: [register, use, R32] + uses: [rt] + defines: [rd] + size: 1 + affects: + affected-by: + itinerary: IT diff --git a/src/unison/src/Unison/Target/Mips.hs b/src/unison/src/Unison/Target/Mips.hs index f029d451..06a69486 100644 --- a/src/unison/src/Unison/Target/Mips.hs +++ b/src/unison/src/Unison/Target/Mips.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -26,15 +26,14 @@ import Unison.Target.Query import Unison.Analysis.TemporaryType import Unison.Analysis.TransitiveOperations import Unison.Transformations.FoldReservedRegisters -import MachineIR.Transformations.AddImplicitRegs import Unison.Target.Mips.Registers import Unison.Target.Mips.Transforms import Unison.Target.Mips.Usages import Unison.Target.Mips.Common import Unison.Target.Mips.MipsRegisterDecl -import Unison.Target.Mips.MipsRegisterClassDecl import Unison.Target.Mips.MipsResourceDecl +import Unison.Target.Mips.SpecsGen.MipsRegisterClassDecl import Unison.Target.Mips.SpecsGen.MipsInstructionDecl import qualified Unison.Target.Mips.SpecsGen as SpecsGen @@ -73,7 +72,8 @@ target = API.tReadWriteLatency = readWriteLatency, API.tAlternativeTemps = const alternativeTemps, API.tExpandCopy = const expandCopy, - API.tConstraints = const constraints + API.tConstraints = const constraints, + API.tSpillOverhead = const spillOverhead } instance Read MipsInstruction where @@ -83,21 +83,20 @@ instance Read MipsInstruction where -- | Gives the target of a jump instruction and the type of jump -branchInfo (Branch {oBranchIs = ops, oBranchUs = [_, BlockRef l]}) - | targetInst ops `elem` [BGEZ, BLTZ, BGTZ, BLEZ, BEQZC, BEQZALC, BNEZC, BNEZALC, BC1F, BC1T] = +branchInfo (Branch {oBranchIs = is, oBranchUs = [_, BlockRef l]}) + | targetInst is `elem` + expandBranches [BGEZ, BLTZ, BGTZ, BLEZ, BEQZC, BEQZALC, BNEZC, BNEZALC, BC1F, BC1T] = BranchInfo Conditional (Just l) -branchInfo (Branch {oBranchIs = ops, oBranchUs = [_, _, BlockRef l]}) - | targetInst ops `elem` [BEQ, BNE] = BranchInfo Conditional (Just l) -branchInfo (Branch {oBranchIs = [TargetInstruction i], oBranchUs = [BlockRef l]}) - | i `elem` [B, J] = BranchInfo Unconditional (Just l) -branchInfo (Branch {oBranchIs = [TargetInstruction JR]}) = - BranchInfo Unconditional Nothing -branchInfo (Branch {oBranchIs = [TargetInstruction RetRA]}) = - BranchInfo Unconditional Nothing -branchInfo (Branch {oBranchIs = [TargetInstruction PseudoIndirectBranch]}) = - BranchInfo Unconditional Nothing -branchInfo (Branch {oBranchIs = [TargetInstruction PseudoReturn]}) = +branchInfo (Branch {oBranchIs = is, oBranchUs = [_, _, BlockRef l]}) + | targetInst is `elem` expandBranches [BEQ, BNE] = BranchInfo Conditional (Just l) +branchInfo (Branch {oBranchIs = is, oBranchUs = [BlockRef l]}) + | targetInst is `elem` expandBranches [B, J] = BranchInfo Unconditional (Just l) +branchInfo (Branch {oBranchIs = is}) + | targetInst is `elem` expandBranches [JR, RetRA, PseudoIndirectBranch, PseudoReturn] = BranchInfo Unconditional Nothing +branchInfo o = error ("unmatched pattern: branchInfo " ++ show (mkSingleOperation (-1) (Natural o))) + +expandBranches = concatMap addDelaySlotNOPInstr -- | Gives a set of def copies and a list of sets of use copies to extend -- the given temporary @@ -132,7 +131,8 @@ copies (f, cst, _, _, _, _) False t [r] _d [_u] -- Extend temporaries defined in acc64 with mflo and mfhi only copies _ False _ [] d us - | isNatural d && targetInst (oInstructions d) `elem` [MULT, MULTu, DIV, MADD] = + | isNatural d && targetInst (oInstructions d) `elem` + [PseudoMULT, PseudoMADD, PseudoMTLOHI, MULT, MULTu, DIV, MADD] = ([], replicate (length us) []) copies _ False t [] d us | isLow d = ([mkNullInstruction, TargetInstruction MFLO], map (accCopy t) us) @@ -232,10 +232,9 @@ isJALRCall SingleOperation { isJALRCall _ = False -- | Transforms copy instructions into natural instructions - --- handle regular copies -fromCopy _ o @ Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} - | i `elem` [MOVE, MFLO, MFHI, MTLO, MTHI, MOVE_F, MOVE_D] = toLinear o +fromCopy o @ Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} + | i `elem` [MOVE, MFLO, MFHI, MTLO, MTHI] = toLinear o + | i `elem` [MOVE_F, MOVE_D] = toLinear (o { oCopyIs = [TargetInstruction $ fromCopyInstr i] }) | i `elem` [STORE, STORE_F, STORE_D] = Linear {oIs = [TargetInstruction (fromCopyInstr i)], oUs = [s, mkOprMipsSP, mkBoundMachineFrameObject i d], @@ -244,27 +243,14 @@ fromCopy _ o @ Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} Linear {oIs = [TargetInstruction (fromCopyInstr i)], oUs = [mkOprMipsSP, mkBoundMachineFrameObject i s], oDs = [d]} - --- handle rematerialization copies -fromCopy (Just (Linear {oUs = us})) - Copy {oCopyIs = [TargetInstruction i], oCopyS = s, oCopyD = d} - | isDematInstr i = - Linear {oIs = [mkNullInstruction], oUs = [s], oDs = [d]} - | isRematInstr i = - Linear {oIs = [TargetInstruction (originalInstr i)], oUs = us, oDs = [d]} - --- handle rematerialization sources -fromCopy _ (Natural o @ Linear {oIs = [TargetInstruction i]}) - | isSourceInstr i = o {oIs = [mkNullInstruction]} - -fromCopy _ (Natural o) = o -fromCopy _ o = error ("unmatched pattern: fromCopy " ++ show o) +fromCopy (Natural o) = o +fromCopy o = error ("unmatched pattern: fromCopy " ++ show o) mkOprMipsSP = Register $ mkTargetRegister SP mkBoundMachineFrameObject i (Register r) = let size = stackSize i - in mkBound (mkMachineFrameObject (infRegPlace r) (Just size) size) + in mkBound (mkMachineFrameObject (infRegPlace r) (Just size) size False) stackSize op | op `elem` [STORE, STORE_F, LOAD, LOAD_F] = 4 @@ -276,7 +262,7 @@ rematInstrs i | i `elem` [CLOBBER_RA] = Nothing | isRematerializable i = Just (sourceInstr i, dematInstr i, rematInstr i) - | otherwise = error ("unmatched: rematInstrs " ++ show i) + | otherwise = Nothing -- | Declares target architecture resources @@ -351,12 +337,14 @@ liftToTOpc f = mkMachineTargetOpc . f . mopcTarget -- | Target dependent post-processing functions -postProcess to = [expandPseudos to, cleanNops, normalizeDelaySlots, - flip addImplicitRegs (target, [])] +postProcess to = [expandPseudosEarly to, if keepNops to then id else cleanNops, + expandPseudos, unbundleSingletons, removeFrameIndex, + normalizeDelaySlots to] -expandPseudos to = mapToMachineBlock (expandBlockPseudos (expandPseudo to)) +expandPseudosEarly to = mapToMachineBlock (expandBlockPseudos + (expandPseudoEarly to)) -expandPseudo to mi @ MachineSingle {msOpcode = MachineTargetOpc LoadGPDisp} +expandPseudoEarly to mi @ MachineSingle {msOpcode = MachineTargetOpc LoadGPDisp} | not (unitLatency to) = let v0 = mkMachineReg V0 gpd = mkMachineExternal "_gp_disp" @@ -364,10 +352,25 @@ expandPseudo to mi @ MachineSingle {msOpcode = MachineTargetOpc LoadGPDisp} mi2 = mi {msOpcode = mkMachineTargetOpc ADDiu, msOperands = [v0, v0, gpd]} in [[mi1],[mi2]] -expandPseudo _ mi @ MachineSingle {msOpcode = MachineTargetOpc i, +expandPseudoEarly _ mi @ MachineSingle {msOpcode = MachineTargetOpc PseudoCVT_S_W, + msOperands = [fi, ri]} = + let mi1 = mi {msOpcode = mkMachineTargetOpc MTC1, msOperands = [fi, ri]} + mi2 = mi {msOpcode = mkMachineTargetOpc CVT_S_W, msOperands = [fi, fi]} + in [[mi1],[mi2]] +expandPseudoEarly _ mi = [[mi]] + +expandPseudos = mapToMachineBlock (expandBlockPseudos expandPseudo) + +expandPseudo mi @ MachineSingle {msOpcode = MachineTargetOpc i} + | isDelaySlotNOPInstr i = + let mi1 = mi {msOpcode = mkMachineTargetOpc (delaySlotInstr i)} + mi2 = mkMachineSingle (mkMachineTargetOpc NOP) [] [] + in [[mi1, mi2]] + +expandPseudo mi @ MachineSingle {msOpcode = MachineTargetOpc i, msOperands = mos} = [[expandSimple mi (i, mos)]] -expandPseudo _ mi = [[mi]] +expandPseudo mi = [[mi]] expandSimple mi (RetRA, _) = mi {msOpcode = MachineTargetOpc PseudoReturn, @@ -396,18 +399,50 @@ cleanNops = filterMachineInstructions (not . isSingleNop) isSingleNop MachineSingle {msOpcode = MachineTargetOpc NOP} = True isSingleNop _ = False -normalizeDelaySlots = mapToMachineBlock normalizeDelaySlotInBlock +-- Unbundle singleton bundles created during pseudo expansion. +unbundleSingletons = mapToMachineBlock unbundleSingletonsInBlock + +unbundleSingletonsInBlock mb @ MachineBlock {mbInstructions = mis} = + mb {mbInstructions = map unbundleSingleton mis} + +unbundleSingleton MachineBundle {mbInstrs = [mi]} = mi +unbundleSingleton mi = mi + +removeFrameIndex = mapToMachineInstruction removeFrameIndexInstr + +removeFrameIndexInstr mi @ MachineSingle {msOpcode = MachineTargetOpc i, + msOperands = mops} + | "_fi" `isSuffixOf` (show i) = + let mops' = case mops of + [r @ MachineReg {}, off @ MachineImm {}, + MachineImm {miValue = 0}] -> + [r, mkMachineReg SP, off] + -- FIXME: post-process other patterns similary. + _ -> mops + in mi {msOpcode = mkMachineTargetOpc $ removeFi i, msOperands = mops'} + | otherwise = mi -normalizeDelaySlotInBlock mb @ MachineBlock {mbInstructions = mis} = - let mis1 = map normalizeDelaySlot mis +removeFi i = read $ dropSuffix "_fi" (show i) + +normalizeDelaySlots to = mapToMachineBlock (normalizeDelaySlotInBlock to) + +normalizeDelaySlotInBlock to mb @ MachineBlock {mbInstructions = mis} = + let mis1 = concatMap (normalizeDelaySlot to) mis mis2 = map removeBundleHead mis1 in mb {mbInstructions = mis2} -normalizeDelaySlot mb @ MachineBundle { +normalizeDelaySlot _ mb @ MachineBundle { + mbInstrs = [mi, mbi @ MachineSingle {msOpcode = MachineTargetOpc i}]} + | isDelaySlotInstr i = [mb {mbInstrs = [mbi, mi]}] +normalizeDelaySlot to MachineBundle { mbInstrs = [mi, mbi @ MachineSingle {msOpcode = MachineTargetOpc i}]} - | isDelaySlotInstr i = mb {mbInstrs = [mbi, mi]} -normalizeDelaySlot mi = mi + | isDelaySlotInstr i && noDelaySlots to = [mi, mbi] +normalizeDelaySlot to MachineBundle { + mbInstrs = [mbi @ MachineSingle {msOpcode = MachineTargetOpc i}, mi]} + | isDelaySlotInstr i && noDelaySlots to = [mi, mbi] +normalizeDelaySlot _ mi = [mi] +-- This assumes all remaining bundles are branches with delay slots. removeBundleHead mb @ MachineBundle {} = mb {mbHead = False} removeBundleHead mi = mi @@ -417,13 +452,16 @@ transforms ImportPreLift = [peephole rs2ts, peephole normalizeCallEpilogue, peephole extractReturnRegs, (\f -> foldReservedRegisters f (target, [])), - mapToOperation hideStackPointer] + mapToOperation hideStackPointer, + coupleAcc64Operations, + mapToOperation addAlternativeInstructions] transforms ImportPostLift = [peephole clobberRAInCall] transforms AugmentPreRW = [peephole insertGPDisp] -transforms AugmentPostRW = [mapToOperation markBarriers] +transforms AugmentPostRW = [mapToOperation markBarriers, + peephole enforceMandatoryFrame] transforms ExportPreLow = [cleanClobbers] @@ -454,7 +492,10 @@ constraints f = -- force RA clobbering operations to be scheduled one cycle before their -- corresponding call operation (that is, two cycles before the corresponding -- (fun) operation): - clobberRASchedulingConstraints f + clobberRASchedulingConstraints f ++ + -- force delay slot operations without bundled NOPs to be scheduled in + -- parallel with other non-virtual operations in their basic blocks: + filledDelaySlotConstraints f clobberRASchedulingConstraints f = let fcode = flatCode f @@ -465,6 +506,25 @@ clobberRASchedulingConstraint fcode clo = [fo] = potentialUsers d fcode in DistanceExpr (oId fo) (oId clo) (-2) +filledDelaySlotConstraints f = mapMaybe filledDelaySlotConstraint (fCode f) + +filledDelaySlotConstraint Block {bCode = code} = + case find isDelaySlotOpr code of + Just o -> + let oid = oId o + i = fromJust $ find (\(TargetInstruction i) -> isDelaySlotNOPInstr i) + (oInstructions o) + os = [oId o' | o' <- code, o' /= o, not (isVirtual o')] + in Just (OrExpr + ([ImplementsExpr oid i] ++ + [AndExpr [ActiveExpr oid', + DistanceExpr oid oid' 0, + DistanceExpr oid' oid 0] | oid' <- os])) + Nothing -> Nothing + +isDelaySlotOpr o = + isNatural o && isDelaySlotInstr (targetInst (oInstructions o)) + operandInfo to i = adjustDefLatency to i $ correctUses i $ SpecsGen.operandInfo i @@ -512,3 +572,19 @@ correctUses i info | otherwise = info adjustDefLatency to i = second (map (applyToLatency (const (latency to i)))) + +latency' i = latency [] i + +spillOverhead (i, _:sp:_, _) + | i `elem` [SW, SB, SDC1, SWC1] && sp == mkOprMipsSP = + Just (True, latency' i) +spillOverhead (i, sp:_, _) + | i `elem` [LW, LBu, LDC1, LWC1] && sp == mkOprMipsSP = + Just (False, latency' i) +spillOverhead (i, _, _) + | i `elem` [SW_fi, SB_fi, SWC1_fi] = + Just (True, latency' i) +spillOverhead (i, _, _) + | i `elem` [LW_fi, LBu_fi, LDC1_fi, LWC1_fi] = + Just (False, latency' i) +spillOverhead _ = Nothing diff --git a/src/unison/src/Unison/Target/Mips/Common.hs b/src/unison/src/Unison/Target/Mips/Common.hs index ce428f16..67a0039a 100644 --- a/src/unison/src/Unison/Target/Mips/Common.hs +++ b/src/unison/src/Unison/Target/Mips/Common.hs @@ -1,8 +1,9 @@ module Unison.Target.Mips.Common - (unitLatency, isBarrierInstr, hiddenStackPointerInstruction, - isDelaySlotInstr, isClobberRA, isRematerializable, isSourceInstr, - isDematInstr, isRematInstr, sourceInstr, dematInstr, rematInstr, - originalInstr) where + (unitLatency, noDelaySlots, keepNops, isBarrierInstr, + hiddenStackPointerInstruction, isDelaySlotInstr, isDelaySlotNOPInstr, + delaySlotInstr, delaySlotNOPInstr, addDelaySlotNOPInstr, isClobberRA, + isRematerializable, isSourceInstr, isDematInstr, isRematInstr, + sourceInstr, dematInstr, rematInstr, originalInstr) where import qualified Data.Map as M @@ -13,6 +14,10 @@ import Unison.Target.Mips.SpecsGen() unitLatency to = API.isBoolOption "unit-latency" to +noDelaySlots to = API.isBoolOption "no-delay-slots" to + +keepNops to = API.isBoolOption "keep-nops" to + isBarrierInstr i = i `elem` barrierInstrs barrierInstrs = [LoadGPDisp] @@ -27,11 +32,21 @@ hiddenStackPointerVersions = M.fromList (SWC1, SWC1_sp), (SDC1, SDC1_sp)] -isDelaySlotInstr i = i `elem` delaySlotInstrs +isDelaySlotInstr i = M.member i delaySlotNOPVersions +isDelaySlotNOPInstr i = M.member i (inverseMap delaySlotNOPVersions) +delaySlotInstr i = (inverseMap delaySlotNOPVersions) M.! i +delaySlotNOPInstr i = delaySlotNOPVersions M.! i + +delaySlotNOPVersions = M.fromList + [(B, B_NOP), (BC1F, BC1F_NOP), (BC1T, BC1T_NOP), (BEQ, BEQ_NOP), + (BGEZ, BGEZ_NOP), (BGTZ, BGTZ_NOP), (BLEZ, BLEZ_NOP), (BLTZ, BLTZ_NOP), + (BNE, BNE_NOP), (JALRPseudo, JALRPseudo_NOP), + (PseudoIndirectBranch, PseudoIndirectBranch_NOP), + (PseudoReturn, PseudoReturn_NOP), (RetRA, RetRA_NOP)] -delaySlotInstrs = - [B, BC1F, BC1T, BEQ, BGEZ, BGTZ, BLEZ, BLTZ, BNE, JALRPseudo, - PseudoIndirectBranch, PseudoReturn, RetRA] +addDelaySlotNOPInstr i + | isDelaySlotInstr i = [i, delaySlotNOPInstr i] + | otherwise = [i] isClobberRA o = isNatural o && (TargetInstruction CLOBBER_RA) `elem` oInstructions o diff --git a/src/unison/src/Unison/Target/Mips/MipsRegisterClassDecl.hs b/src/unison/src/Unison/Target/Mips/MipsRegisterClassDecl.hs deleted file mode 100644 index a741bbed..00000000 --- a/src/unison/src/Unison/Target/Mips/MipsRegisterClassDecl.hs +++ /dev/null @@ -1,64 +0,0 @@ -{-| -Copyright : Copyright (c) 2016, RISE SICS AB -License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se --} -{- -Main authors: - Roberto Castaneda Lozano - -This file is part of Unison, see http://unison-code.github.io --} -module Unison.Target.Mips.MipsRegisterClassDecl (MipsRegisterClass (..)) where - -data MipsRegisterClass = - GPR32Opnd | - GPR32 | - GPR_ATT7 | - GPR_T89 | - GPR_FPRA | - ACC64 | - FGR32Opnd | - FGR32 | - AFGR64Opnd | - AFGR64 | - AFGR_D09 | - FCCRegsOpnd | - MSA128BOpnd | - DSPCC | - ACC128 | - ACC64DSPOpnd | - COP2Opnd | - COP3Opnd | - CPU16Regs | - DSPROpnd | - FGR64Opnd | - GPR64 | - GPR64Opnd | - GPRMM16Opnd | - MSA128DOpnd | - MSA128H | - MSA128HOpnd | - MSA128W | - MSA128WOpnd | - ACC64DSP | - CCROpnd | - COP0Opnd | - CPU16RegsPlusSP | - CPUSPReg | - FGR64 | - FGRCCOpnd | - GPRMM16 | - GPRMM16OpndMoveP | - GPRMM16OpndZero | - HI32DSPOpnd | - HWRegsOpnd | - LO32DSPOpnd | - MSA128B | - MSA128CROpnd | - MSA128D | - M32 | - M64 | - RM32 | - RM64 | - Ptr_rc deriving (Eq, Ord, Show, Read) diff --git a/src/unison/src/Unison/Target/Mips/MipsRegisterDecl.hs b/src/unison/src/Unison/Target/Mips/MipsRegisterDecl.hs index ab18c0aa..aa307e4b 100644 --- a/src/unison/src/Unison/Target/Mips/MipsRegisterDecl.hs +++ b/src/unison/src/Unison/Target/Mips/MipsRegisterDecl.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/Mips/Registers.hs b/src/unison/src/Unison/Target/Mips/Registers.hs index 41ec10be..ce917dac 100644 --- a/src/unison/src/Unison/Target/Mips/Registers.hs +++ b/src/unison/src/Unison/Target/Mips/Registers.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -19,7 +19,7 @@ import qualified Data.Map as M import Unison import Unison.Target.Mips.MipsRegisterDecl -import Unison.Target.Mips.MipsRegisterClassDecl +import Unison.Target.Mips.SpecsGen.MipsRegisterClassDecl -- | Register array configuration diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen.hs b/src/unison/src/Unison/Target/Mips/SpecsGen.hs index ea522ea4..d41c00c6 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/AlignedPairs.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/AlignedPairs.hs index aef7ed6a..0d4375ae 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/AlignedPairs.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/AlignedPairs.hs @@ -8,8 +8,9 @@ alignedPairs i ([], []) [Break16, DERET, DERET_MM, DERET_MMR6, EHB, EHB_MM, EHB_MMR6, ERET, ERETNC, ERETNC_MMR6, ERET_MM, ERET_MMR6, ERet, JrRa16, JrcRa16, LoadGPDisp, NOP, PAUSE, PAUSE_MM, PAUSE_MMR6, RetRA, RetRA16, - SSNOP, SSNOP_MM, SSNOP_MMR6, TLBINV, TLBINVF, TLBP, TLBP_MM, TLBR, - TLBR_MM, TLBWI, TLBWI_MM, TLBWR, TLBWR_MM, TRAP, WAIT] + RetRA_NOP, SSNOP, SSNOP_MM, SSNOP_MMR6, TLBINV, TLBINVF, TLBP, + TLBP_MM, TLBR, TLBR_MM, TLBWI, TLBWI_MM, TLBWR, TLBWR_MM, TRAP, + WAIT] = [] alignedPairs i ([], [_]) | i `elem` [BPOSGE32_PSEUDO, IMPLICIT_DEF, LOAD_STACK_GUARD] = [] @@ -109,7 +110,9 @@ alignedPairs i ([_, _, _], [_]) alignedPairs i ([_], [_]) | i `elem` [CFCMSA] = [] alignedPairs i ([_, _], []) | i `elem` [BC2EQZ, BC2NEZ] = [] alignedPairs i ([_, _], []) - | i `elem` [BC1F, BC1FL, BC1F_MM, BC1T, BC1TL, BC1T_MM] = [] + | i `elem` + [BC1F, BC1FL, BC1F_MM, BC1F_NOP, BC1T, BC1TL, BC1T_MM, BC1T_NOP] + = [] alignedPairs i ([fd_in, _, _], [fd_in']) | i `elem` [MADDF_D, MADDF_D_MMR6, MADDF_S, MADDF_S_MMR6, MSUBF_D, @@ -224,6 +227,8 @@ alignedPairs i ([_, _], [_]) FMUL_S_MMR6, FSUB_D_MMR6, FSUB_S_MMR6] = [] alignedPairs i ([_, _], []) | i `elem` [BC1EQZ, BC1NEZ] = [] +alignedPairs i ([_, _, _, _], []) + | i `elem` [Register_class_decl_dummy] = [] alignedPairs i ([_], [_]) | i `elem` [PseudoMFHI, PseudoMFHI64, PseudoMFLO, PseudoMFLO64] = [] @@ -280,7 +285,7 @@ alignedPairs i ([_], [_]) | i `elem` [RDDSP_MM] = [] alignedPairs i ([_], []) | i `elem` [B, B16_MM, BAL, BALC, BALC_MMR6, BAL_BR, BC, BC16_MMR6, BC_MMR6, - BPOSGE32, B_MMR6_Pseudo, B_MM_Pseudo] + BPOSGE32, B_MMR6_Pseudo, B_MM_Pseudo, B_NOP] = [] alignedPairs i ([_, _], [_]) | i `elem` [LWGP_MM, LWSP_MM] = [] alignedPairs i ([_, _, _], [_]) @@ -321,12 +326,13 @@ alignedPairs i ([_, _], [_]) | i `elem` [DMFC0, DMFC2, MFC0, MFC2] = [] alignedPairs i ([_], []) | i `elem` - [JALR16_MM, JALR64Pseudo, JALRC16_MMR6, JALRPseudo, JALRS16_MM, JR, - JR16_MM, JR64, JRC16_MM, JRC16_MMR6, JR_HB, JR_HB_R6, JR_MM, - JalOneReg, JumpLinkReg16, MTHI, MTHI64, MTHI_MM, MTLO, MTLO64, - MTLO_MM, MTM0, MTM1, MTM2, MTP0, MTP1, MTP2, PseudoIndirectBranch, - PseudoIndirectBranch64, PseudoReturn, PseudoReturn64, TAILCALL64_R, - TAILCALL_R] + [JALR16_MM, JALR64Pseudo, JALRC16_MMR6, JALRPseudo, JALRPseudo_NOP, + JALRS16_MM, JR, JR16_MM, JR64, JRC16_MM, JRC16_MMR6, JR_HB, + JR_HB_R6, JR_MM, JalOneReg, JumpLinkReg16, MTHI, MTHI64, MTHI_MM, + MTLO, MTLO64, MTLO_MM, MTM0, MTM1, MTM2, MTP0, MTP1, MTP2, + PseudoIndirectBranch, PseudoIndirectBranch64, + PseudoIndirectBranch_NOP, PseudoReturn, PseudoReturn64, + PseudoReturn_NOP, TAILCALL64_R, TAILCALL_R] = [] alignedPairs i ([_], [_]) | i `elem` [MTHI_DSP, MTHI_DSP_MM, MTLO_DSP, MTLO_DSP_MM] = [] @@ -381,10 +387,10 @@ alignedPairs i ([_, _], []) | i `elem` [WRDSP] = [] alignedPairs i ([_, _], []) | i `elem` [BEQZ16_MM, BEQZC, BEQZC16_MMR6, BEQZC_MM, BGEZ, BGEZ64, BGEZAL, - BGEZALL, BGEZALS_MM, BGEZAL_MM, BGEZL, BGEZ_MM, BGTZ, BGTZ64, - BGTZL, BGTZ_MM, BLEZ, BLEZ64, BLEZL, BLEZ_MM, BLTZ, BLTZ64, BLTZAL, - BLTZALL, BLTZALS_MM, BLTZAL_MM, BLTZL, BLTZ_MM, BNEZ16_MM, BNEZC, - BNEZC16_MMR6, BNEZC_MM] + BGEZALL, BGEZALS_MM, BGEZAL_MM, BGEZL, BGEZ_MM, BGEZ_NOP, BGTZ, + BGTZ64, BGTZL, BGTZ_MM, BGTZ_NOP, BLEZ, BLEZ64, BLEZL, BLEZ_MM, + BLEZ_NOP, BLTZ, BLTZ64, BLTZAL, BLTZALL, BLTZALS_MM, BLTZAL_MM, + BLTZL, BLTZ_MM, BLTZ_NOP, BNEZ16_MM, BNEZC, BNEZC16_MMR6, BNEZC_MM] = [] alignedPairs i ([_, _, _], []) | i `elem` [BBIT0, BBIT032, BBIT1, BBIT132] = [] @@ -490,10 +496,10 @@ alignedPairs i ([_, _, _], [_]) | i `elem` [DLSA_R6, LSA_MMR6, LSA_R6] = [] alignedPairs i ([_, _, _], []) | i `elem` - [BEQ, BEQ64, BEQC, BEQL, BEQ_MM, BGE, BGEC, BGEL, BGEU, BGEUC, - BGEUL, BGT, BGTL, BGTU, BGTUL, BLE, BLEL, BLEU, BLEUL, BLT, BLTC, - BLTL, BLTU, BLTUC, BLTUL, BNE, BNE64, BNEC, BNEL, BNE_MM, BNVC, - BOVC] + [BEQ, BEQ64, BEQC, BEQL, BEQ_MM, BEQ_NOP, BGE, BGEC, BGEL, BGEU, + BGEUC, BGEUL, BGT, BGTL, BGTU, BGTUL, BLE, BLEL, BLEU, BLEUL, BLT, + BLTC, BLTL, BLTU, BLTUC, BLTUL, BNE, BNE64, BNEC, BNEL, BNE_MM, + BNE_NOP, BNVC, BOVC] = [] alignedPairs i ([_, _, _], []) | i `elem` [DROL, DROR, ROL, ROR] = [] diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/AllInstructions.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/AllInstructions.hs index ebf13613..c81a837a 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/AllInstructions.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/AllInstructions.hs @@ -381,7 +381,10 @@ allInstructions MOVE, STORE_D, LOAD_D, MOVE_D, STORE_F, LOAD_F, MOVE_F, LW_fi, LHu_fi, SW_fi, SWL_fi, SWR_fi, SB_fi, LDC1_fi, LBu_fi, SH_fi, LH_fi, SWC1_fi, LWC1_fi, ADDiu_sp, ADDiu_negsp, SW_sp, SWC1_sp, - SDC1_sp, LoadGPDisp, CLOBBER_RA, LDC1_fi_source_fi, + SDC1_sp, LoadGPDisp, CLOBBER_RA, B_NOP, BC1F_NOP, BC1T_NOP, + BEQ_NOP, BGEZ_NOP, BGTZ_NOP, BLEZ_NOP, BLTZ_NOP, BNE_NOP, + JALRPseudo_NOP, PseudoIndirectBranch_NOP, PseudoReturn_NOP, + RetRA_NOP, Register_class_decl_dummy, LDC1_fi_source_fi, LDC1_fi_demat_fi, LDC1_fi_remat_fi, LEA_ADDiu_source, LEA_ADDiu_demat, LEA_ADDiu_remat, LUi_source, LUi_demat, LUi_remat, LW_fi_source_fi, LW_fi_demat_fi, LW_fi_remat_fi, LBu_fi_source_fi, diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/InstructionType.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/InstructionType.hs index 26e0c058..51edd6b3 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/InstructionType.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/InstructionType.hs @@ -7,33 +7,35 @@ import Unison.Target.Mips.SpecsGen.MipsInstructionDecl instructionType i | i `elem` [B, B16_MM, BAL_BR, BBIT0, BBIT032, BBIT1, BBIT132, BC, BC16_MMR6, - BC1EQZ, BC1F, BC1FL, BC1F_MM, BC1NEZ, BC1T, BC1TL, BC1T_MM, BC2EQZ, - BC2NEZ, BC_MMR6, BEQ, BEQ64, BEQC, BEQL, BEQZ16_MM, BEQZALC, - BEQZALC_MMR6, BEQZC, BEQZC16_MMR6, BEQZC_MM, BEQ_MM, BGEC, BGEUC, - BGEZ, BGEZ64, BGEZALC, BGEZALC_MMR6, BGEZC, BGEZL, BGEZ_MM, BGTZ, - BGTZ64, BGTZALC, BGTZALC_MMR6, BGTZC, BGTZL, BGTZ_MM, BLEZ, BLEZ64, - BLEZALC, BLEZALC_MMR6, BLEZC, BLEZL, BLEZ_MM, BLTC, BLTUC, BLTZ, - BLTZ64, BLTZALC, BLTZALC_MMR6, BLTZC, BLTZL, BLTZ_MM, BNE, BNE64, - BNEC, BNEL, BNEZ16_MM, BNEZALC, BNEZALC_MMR6, BNEZC, BNEZC16_MMR6, - BNEZC_MM, BNE_MM, BNVC, BNZ_B, BNZ_D, BNZ_H, BNZ_V, BNZ_W, BOVC, - BPOSGE32, BZ_B, BZ_D, BZ_H, BZ_V, BZ_W, BeqzRxImm16, BeqzRxImmX16, - Bimm16, BimmX16, BnezRxImm16, BnezRxImmX16, Bteqz16, BteqzT8CmpX16, - BteqzT8CmpiX16, BteqzT8SltX16, BteqzT8SltiX16, BteqzT8SltiuX16, - BteqzT8SltuX16, BteqzX16, Btnez16, BtnezT8CmpX16, BtnezT8CmpiX16, - BtnezT8SltX16, BtnezT8SltiX16, BtnezT8SltiuX16, BtnezT8SltuX16, - BtnezX16, ERet, J, JR, JR16_MM, JR64, JRADDIUSP, JRC16_MM, - JRC16_MMR6, JRCADDIUSP_MMR6, JR_HB, JR_HB_R6, JR_MM, JalB16, - JrRa16, JrcRa16, JrcRx16, MIPSeh_return32, MIPSeh_return64, - PseudoIndirectBranch, PseudoIndirectBranch64, PseudoReturn, - PseudoReturn64, RetRA, RetRA16] + BC1EQZ, BC1F, BC1FL, BC1F_MM, BC1F_NOP, BC1NEZ, BC1T, BC1TL, + BC1T_MM, BC1T_NOP, BC2EQZ, BC2NEZ, BC_MMR6, BEQ, BEQ64, BEQC, BEQL, + BEQZ16_MM, BEQZALC, BEQZALC_MMR6, BEQZC, BEQZC16_MMR6, BEQZC_MM, + BEQ_MM, BEQ_NOP, BGEC, BGEUC, BGEZ, BGEZ64, BGEZALC, BGEZALC_MMR6, + BGEZC, BGEZL, BGEZ_MM, BGEZ_NOP, BGTZ, BGTZ64, BGTZALC, + BGTZALC_MMR6, BGTZC, BGTZL, BGTZ_MM, BGTZ_NOP, BLEZ, BLEZ64, + BLEZALC, BLEZALC_MMR6, BLEZC, BLEZL, BLEZ_MM, BLEZ_NOP, BLTC, + BLTUC, BLTZ, BLTZ64, BLTZALC, BLTZALC_MMR6, BLTZC, BLTZL, BLTZ_MM, + BLTZ_NOP, BNE, BNE64, BNEC, BNEL, BNEZ16_MM, BNEZALC, BNEZALC_MMR6, + BNEZC, BNEZC16_MMR6, BNEZC_MM, BNE_MM, BNE_NOP, BNVC, BNZ_B, BNZ_D, + BNZ_H, BNZ_V, BNZ_W, BOVC, BPOSGE32, BZ_B, BZ_D, BZ_H, BZ_V, BZ_W, + B_NOP, BeqzRxImm16, BeqzRxImmX16, Bimm16, BimmX16, BnezRxImm16, + BnezRxImmX16, Bteqz16, BteqzT8CmpX16, BteqzT8CmpiX16, + BteqzT8SltX16, BteqzT8SltiX16, BteqzT8SltiuX16, BteqzT8SltuX16, + BteqzX16, Btnez16, BtnezT8CmpX16, BtnezT8CmpiX16, BtnezT8SltX16, + BtnezT8SltiX16, BtnezT8SltiuX16, BtnezT8SltuX16, BtnezX16, ERet, J, + JR, JR16_MM, JR64, JRADDIUSP, JRC16_MM, JRC16_MMR6, + JRCADDIUSP_MMR6, JR_HB, JR_HB_R6, JR_MM, JalB16, JrRa16, JrcRa16, + JrcRx16, MIPSeh_return32, MIPSeh_return64, PseudoIndirectBranch, + PseudoIndirectBranch64, PseudoIndirectBranch_NOP, PseudoReturn, + PseudoReturn64, PseudoReturn_NOP, RetRA, RetRA16, RetRA_NOP] = BranchInstructionType | i `elem` [BAL, BALC, BALC_MMR6, BGEZAL, BGEZALL, BGEZALS_MM, BGEZAL_MM, BLTZAL, BLTZALL, BLTZALS_MM, BLTZAL_MM, JAL, JALR, JALR16_MM, - JALR64, JALR64Pseudo, JALRC16_MMR6, JALRPseudo, JALRS16_MM, - JALRS_MM, JALR_MM, JALS_MM, JALX, JALX_MM, JAL_MM, JIALC, - JIALC_MMR6, Jal16, JumpLinkReg16, PATCHPOINT, STACKMAP, STATEPOINT, - TAILCALL, TAILCALL64_R, TAILCALL_R] + JALR64, JALR64Pseudo, JALRC16_MMR6, JALRPseudo, JALRPseudo_NOP, + JALRS16_MM, JALRS_MM, JALR_MM, JALS_MM, JALX, JALX_MM, JAL_MM, + JIALC, JIALC_MMR6, Jal16, JumpLinkReg16, PATCHPOINT, STACKMAP, + STATEPOINT, TAILCALL, TAILCALL64_R, TAILCALL_R] = CallInstructionType | i `elem` [LBu_fi_demat_fi, LBu_fi_remat_fi, LDC1_fi_demat_fi, @@ -396,6 +398,6 @@ instructionType i WAIT_MMR6, WRDSP, WRDSP_MM, WRPGPR_MMR6, WSBH, WSBH_MM, WSBH_MMR6, XOR, XOR16_MM, XOR16_MMR6, XOR64, XORI_B, XORI_MMR6, XOR_MM, XOR_MMR6, XOR_V, XOR_V_D_PSEUDO, XOR_V_H_PSEUDO, XOR_V_W_PSEUDO, - XORi, XORi64, XORi_MM, XorRxRxRy16] + XORi, XORi64, XORi_MM, XorRxRxRy16, Register_class_decl_dummy] = LinearInstructionType diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/Itinerary.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/Itinerary.hs index a8ac8075..39235652 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/Itinerary.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/Itinerary.hs @@ -64,15 +64,16 @@ itinerary i PseudoSELECTFP_T_D32, PseudoSELECTFP_T_D64, PseudoSELECTFP_T_I, PseudoSELECTFP_T_I64, PseudoSELECTFP_T_S, PseudoSELECT_D32, PseudoSELECT_D64, PseudoSELECT_I, PseudoSELECT_I64, PseudoSELECT_S, - ROL, ROLImm, ROR, RORImm, RetRA, RetRA16, SDivMacro, SNZ_B_PSEUDO, - SNZ_D_PSEUDO, SNZ_H_PSEUDO, SNZ_V_PSEUDO, SNZ_W_PSEUDO, SWM_MM, - SZ_B_PSEUDO, SZ_D_PSEUDO, SZ_H_PSEUDO, SZ_V_PSEUDO, SZ_W_PSEUDO, - SelBeqZ, SelBneZ, SelTBteqZCmp, SelTBteqZCmpi, SelTBteqZSlt, - SelTBteqZSlti, SelTBteqZSltiu, SelTBteqZSltu, SelTBtneZCmp, - SelTBtneZCmpi, SelTBtneZSlt, SelTBtneZSlti, SelTBtneZSltiu, - SelTBtneZSltu, SltCCRxRy16, SltiCCRxImmX16, SltiuCCRxImmX16, - SltuCCRxRy16, SltuRxRyRz16, UDivMacro, Ulh, Ulhu, Ulw, - XOR_V_D_PSEUDO, XOR_V_H_PSEUDO, XOR_V_W_PSEUDO] + ROL, ROLImm, ROR, RORImm, RetRA, RetRA16, RetRA_NOP, SDivMacro, + SNZ_B_PSEUDO, SNZ_D_PSEUDO, SNZ_H_PSEUDO, SNZ_V_PSEUDO, + SNZ_W_PSEUDO, SWM_MM, SZ_B_PSEUDO, SZ_D_PSEUDO, SZ_H_PSEUDO, + SZ_V_PSEUDO, SZ_W_PSEUDO, SelBeqZ, SelBneZ, SelTBteqZCmp, + SelTBteqZCmpi, SelTBteqZSlt, SelTBteqZSlti, SelTBteqZSltiu, + SelTBteqZSltu, SelTBtneZCmp, SelTBtneZCmpi, SelTBtneZSlt, + SelTBtneZSlti, SelTBtneZSltiu, SelTBtneZSltu, SltCCRxRy16, + SltiCCRxImmX16, SltiuCCRxImmX16, SltuCCRxRy16, SltuRxRyRz16, + UDivMacro, Ulh, Ulhu, Ulw, XOR_V_D_PSEUDO, XOR_V_H_PSEUDO, + XOR_V_W_PSEUDO] = IIPseudo | i `elem` [ABS_D_MMR6, ABS_S_MMR6, FABS_D32, FABS_D64, FABS_MM, FABS_S, @@ -87,20 +88,23 @@ itinerary i ANDi64] = II_AND | i `elem` [ANDi] = II_ANDI - | i `elem` [B, B16_MM] = II_B + | i `elem` [B, B16_MM, B_NOP] = II_B | i `elem` [BADDu] = II_BADDU | i `elem` [BBIT0, BBIT032, BBIT1, BBIT132] = II_BBIT | i `elem` [BC16_MMR6] = II_BC - | i `elem` [BC1F, BC1F_MM] = II_BC1F + | i `elem` [BC1F, BC1F_MM, BC1F_NOP] = II_BC1F | i `elem` [BC1FL] = II_BC1FL - | i `elem` [BC1T, BC1T_MM] = II_BC1T + | i `elem` [BC1T, BC1T_MM, BC1T_NOP] = II_BC1T | i `elem` [BC1TL] = II_BC1TL - | i `elem` [BEQ, BEQ64, BEQL, BEQ_MM, BNE, BNE64, BNEL, BNE_MM] = - II_BCC | i `elem` - [BEQZ16_MM, BEQZC16_MMR6, BGEZ, BGEZ64, BGEZL, BGEZ_MM, BGTZ, - BGTZ64, BGTZL, BGTZ_MM, BLEZ, BLEZ64, BLEZL, BLEZ_MM, BLTZ, BLTZ64, - BLTZL, BLTZ_MM, BNEZ16_MM, BNEZC16_MMR6] + [BEQ, BEQ64, BEQL, BEQ_MM, BEQ_NOP, BNE, BNE64, BNEL, BNE_MM, + BNE_NOP] + = II_BCC + | i `elem` + [BEQZ16_MM, BEQZC16_MMR6, BGEZ, BGEZ64, BGEZL, BGEZ_MM, BGEZ_NOP, + BGTZ, BGTZ64, BGTZL, BGTZ_MM, BGTZ_NOP, BLEZ, BLEZ64, BLEZL, + BLEZ_MM, BLEZ_NOP, BLTZ, BLTZ64, BLTZL, BLTZ_MM, BLTZ_NOP, + BNEZ16_MM, BNEZC16_MMR6] = II_BCCZ | i `elem` [BAL_BR, BGEZAL, BGEZALL, BGEZAL_MM, BLTZAL, BLTZALL, BLTZAL_MM] @@ -177,13 +181,15 @@ itinerary i FLOOR_W_S_MM, FLOOR_W_S_MMR6] = II_FLOOR | i `elem` [DINS, DINSM, DINSU, INS, INS_MM] = II_INS - | i `elem` [PseudoIndirectBranch, PseudoIndirectBranch64] = - II_IndirectBranchPseudo + | i `elem` + [PseudoIndirectBranch, PseudoIndirectBranch64, + PseudoIndirectBranch_NOP] + = II_IndirectBranchPseudo | i `elem` [J, J_MM, TAILCALL] = II_J | i `elem` [JAL, JALX, JALX_MM, JAL_MM] = II_JAL | i `elem` [JALR, JALR16_MM, JALR64, JALR64Pseudo, JALRC16_MMR6, JALRPseudo, - JALR_MM] + JALRPseudo_NOP, JALR_MM] = II_JALR | i `elem` [JumpLinkReg16] = II_JALRC | i `elem` [JALRS16_MM, JALRS_MM] = II_JALRS @@ -287,7 +293,8 @@ itinerary i ROUND_W_D_MMR6, ROUND_W_MM, ROUND_W_S, ROUND_W_S_MM, ROUND_W_S_MMR6] = II_ROUND - | i `elem` [PseudoReturn, PseudoReturn64] = II_ReturnPseudo + | i `elem` [PseudoReturn, PseudoReturn64, PseudoReturn_NOP] = + II_ReturnPseudo | i `elem` [Save16, SaveX16] = II_SAVE | i `elem` [SB, SB16_MM, SB16_MMR6, SB64, SB_fi, SbRxRyOffMemX16] = II_SB @@ -556,6 +563,7 @@ itinerary i TLTIU_MM, TLTI_MM, TLTU, TLTU_MM, TLT_MM, TNE, TNEI, TNEI_MM, TNE_MM, TRAP, TTLTIU, VSHF_B, VSHF_D, VSHF_H, VSHF_W, WAIT, WAIT_MM, WAIT_MMR6, WRDSP, WRDSP_MM, WRPGPR_MMR6, WSBH_MMR6, - XORI_B, XORI_MMR6, XOR_MMR6, XOR_V, XORi_MM] + XORI_B, XORI_MMR6, XOR_MMR6, XOR_V, XORi_MM, + Register_class_decl_dummy] = NoItinerary diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/MipsInstructionDecl.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/MipsInstructionDecl.hs index 2d139c4d..b1afdcea 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/MipsInstructionDecl.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/MipsInstructionDecl.hs @@ -2259,6 +2259,20 @@ data MipsInstruction = ABSQ_S_PH | SDC1_sp | LoadGPDisp | CLOBBER_RA + | B_NOP + | BC1F_NOP + | BC1T_NOP + | BEQ_NOP + | BGEZ_NOP + | BGTZ_NOP + | BLEZ_NOP + | BLTZ_NOP + | BNE_NOP + | JALRPseudo_NOP + | PseudoIndirectBranch_NOP + | PseudoReturn_NOP + | RetRA_NOP + | Register_class_decl_dummy | LDC1_fi_source_fi | LDC1_fi_demat_fi | LDC1_fi_remat_fi diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/MipsRegisterClassDecl.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/MipsRegisterClassDecl.hs new file mode 100644 index 00000000..c28bb81a --- /dev/null +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/MipsRegisterClassDecl.hs @@ -0,0 +1,56 @@ +-- This file has been generated by specsgen. Do not modify by hand! + +module Unison.Target.Mips.SpecsGen.MipsRegisterClassDecl + (MipsRegisterClass(..)) where + +data MipsRegisterClass = ACC128 + | ACC64 + | ACC64DSP + | ACC64DSPOpnd + | AFGR64 + | AFGR64Opnd + | AFGR_D09 + | CCROpnd + | COP0Opnd + | COP2Opnd + | COP3Opnd + | CPU16Regs + | CPU16RegsPlusSP + | CPUSPReg + | DSPCC + | DSPROpnd + | FCCRegsOpnd + | FGR32 + | FGR32Opnd + | FGR64 + | FGR64Opnd + | FGRCCOpnd + | GPR32 + | GPR32Opnd + | GPR64 + | GPR64Opnd + | GPRMM16 + | GPRMM16Opnd + | GPRMM16OpndMoveP + | GPRMM16OpndZero + | GPR_ATT7 + | GPR_FPRA + | GPR_T89 + | HI32DSPOpnd + | HWRegsOpnd + | LO32DSPOpnd + | MSA128B + | MSA128BOpnd + | MSA128CROpnd + | MSA128D + | MSA128DOpnd + | MSA128H + | MSA128HOpnd + | MSA128W + | MSA128WOpnd + | RM32 + | RM64 + | M32 + | M64 + deriving (Eq, Ord, Read, Show) + diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/OperandInfo.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/OperandInfo.hs index 46a36f59..adbb287c 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/OperandInfo.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/OperandInfo.hs @@ -3,14 +3,15 @@ module Unison.Target.Mips.SpecsGen.OperandInfo (operandInfo) where import Unison import Unison.Target.Mips.SpecsGen.MipsInstructionDecl -import Unison.Target.Mips.MipsRegisterClassDecl +import Unison.Target.Mips.SpecsGen.MipsRegisterClassDecl operandInfo i | i `elem` [Break16, DERET, DERET_MM, DERET_MMR6, EHB, EHB_MM, EHB_MMR6, ERET, ERETNC, ERETNC_MMR6, ERET_MM, ERET_MMR6, ERet, JrRa16, JrcRa16, LoadGPDisp, NOP, PAUSE, PAUSE_MM, PAUSE_MMR6, RetRA, RetRA16, - SSNOP, SSNOP_MM, SSNOP_MMR6, TLBINV, TLBINVF, TLBP, TLBP_MM, TLBR, - TLBR_MM, TLBWI, TLBWI_MM, TLBWR, TLBWR_MM, TRAP, WAIT] + RetRA_NOP, SSNOP, SSNOP_MM, SSNOP_MMR6, TLBINV, TLBINVF, TLBP, + TLBP_MM, TLBR, TLBR_MM, TLBWI, TLBWI_MM, TLBWR, TLBWR_MM, TRAP, + WAIT] = ([], []) | i `elem` [Mfhi16, Mflo16] = ([], [TemporaryInfo (RegisterClass CPU16Regs) 1 False]) @@ -337,7 +338,9 @@ operandInfo i = ([TemporaryInfo (RegisterClass DSPROpnd) 0 False, BoundInfo], [TemporaryInfo (RegisterClass DSPROpnd) 1 False]) - | i `elem` [BC1F, BC1FL, BC1F_MM, BC1T, BC1TL, BC1T_MM] = + | i `elem` + [BC1F, BC1FL, BC1F_MM, BC1F_NOP, BC1T, BC1TL, BC1T_MM, BC1T_NOP] + = ([TemporaryInfo (RegisterClass FCCRegsOpnd) 0 False, BlockRefInfo], []) | i `elem` [FILL_FW_PSEUDO] = @@ -575,9 +578,10 @@ operandInfo i BoundInfo], []) | i `elem` - [JALR16_MM, JALRC16_MMR6, JALRPseudo, JALRS16_MM, JR, JR16_MM, - JRC16_MM, JRC16_MMR6, JR_HB, JR_HB_R6, JR_MM, JalOneReg, MTHI, - MTHI_MM, MTLO, MTLO_MM, PseudoIndirectBranch, PseudoReturn, + [JALR16_MM, JALRC16_MMR6, JALRPseudo, JALRPseudo_NOP, JALRS16_MM, + JR, JR16_MM, JRC16_MM, JRC16_MMR6, JR_HB, JR_HB_R6, JR_MM, + JalOneReg, MTHI, MTHI_MM, MTLO, MTLO_MM, PseudoIndirectBranch, + PseudoIndirectBranch_NOP, PseudoReturn, PseudoReturn_NOP, TAILCALL_R] = ([TemporaryInfo (RegisterClass GPR32Opnd) 0 False], []) | i `elem` [PseudoCVT_D32_W] = @@ -768,9 +772,10 @@ operandInfo i TemporaryInfo (RegisterClass GPR32Opnd) 0 False, BoundInfo], [TemporaryInfo (RegisterClass GPR32Opnd) 1 False]) | i `elem` - [BEQ, BEQC, BEQL, BEQ_MM, BGE, BGEC, BGEL, BGEU, BGEUC, BGEUL, BGT, - BGTL, BGTU, BGTUL, BLE, BLEL, BLEU, BLEUL, BLT, BLTC, BLTL, BLTU, - BLTUC, BLTUL, BNE, BNEC, BNEL, BNE_MM, BNVC, BOVC] + [BEQ, BEQC, BEQL, BEQ_MM, BEQ_NOP, BGE, BGEC, BGEL, BGEU, BGEUC, + BGEUL, BGT, BGTL, BGTU, BGTUL, BLE, BLEL, BLEU, BLEUL, BLT, BLTC, + BLTL, BLTU, BLTUC, BLTUL, BNE, BNEC, BNEL, BNE_MM, BNE_NOP, BNVC, + BOVC] = ([TemporaryInfo (RegisterClass GPR32Opnd) 0 False, TemporaryInfo (RegisterClass GPR32Opnd) 0 False, BlockRefInfo], @@ -847,11 +852,11 @@ operandInfo i | i `elem` [BEQZALC, BEQZALC_MMR6, BEQZC, BEQZC_MM, BGEZ, BGEZAL, BGEZALC, BGEZALC_MMR6, BGEZALL, BGEZALS_MM, BGEZAL_MM, BGEZC, BGEZL, - BGEZ_MM, BGTZ, BGTZALC, BGTZALC_MMR6, BGTZC, BGTZL, BGTZ_MM, BLEZ, - BLEZALC, BLEZALC_MMR6, BLEZC, BLEZL, BLEZ_MM, BLTZ, BLTZAL, - BLTZALC, BLTZALC_MMR6, BLTZALL, BLTZALS_MM, BLTZAL_MM, BLTZC, - BLTZL, BLTZ_MM, BNEZALC, BNEZALC_MMR6, BNEZC, BNEZC_MM, JIC, - JIC_MMR6] + BGEZ_MM, BGEZ_NOP, BGTZ, BGTZALC, BGTZALC_MMR6, BGTZC, BGTZL, + BGTZ_MM, BGTZ_NOP, BLEZ, BLEZALC, BLEZALC_MMR6, BLEZC, BLEZL, + BLEZ_MM, BLEZ_NOP, BLTZ, BLTZAL, BLTZALC, BLTZALC_MMR6, BLTZALL, + BLTZALS_MM, BLTZAL_MM, BLTZC, BLTZL, BLTZ_MM, BLTZ_NOP, BNEZALC, + BNEZALC_MMR6, BNEZC, BNEZC_MM, JIC, JIC_MMR6] = ([TemporaryInfo (RegisterClass GPR32Opnd) 0 False, BlockRefInfo], []) @@ -1008,6 +1013,12 @@ operandInfo i ([TemporaryInfo (RegisterClass GPRMM16OpndZero) 0 False, TemporaryInfo (RegisterClass GPRMM16) 0 False, BoundInfo], []) + | i `elem` [Register_class_decl_dummy] = + ([TemporaryInfo (RegisterClass GPR_ATT7) 0 False, + TemporaryInfo (RegisterClass GPR_T89) 0 False, + TemporaryInfo (RegisterClass GPR_FPRA) 0 False, + TemporaryInfo (RegisterClass AFGR_D09) 0 False], + []) | i `elem` [RDHWR, RDHWR_MM] = ([TemporaryInfo (RegisterClass HWRegsOpnd) 0 False], [TemporaryInfo (RegisterClass GPR32Opnd) 1 False]) @@ -1619,7 +1630,7 @@ operandInfo i [TemporaryInfo (RegisterClass GPR32Opnd) 1 False]) | i `elem` [B, B16_MM, BAL, BALC, BALC_MMR6, BAL_BR, BC, BC16_MMR6, BC_MMR6, - BPOSGE32, B_MMR6_Pseudo, B_MM_Pseudo, Bimm16, BimmX16, J, + BPOSGE32, B_MMR6_Pseudo, B_MM_Pseudo, B_NOP, Bimm16, BimmX16, J, JRADDIUSP, JRCADDIUSP_MMR6, J_MM] = ([BlockRefInfo], []) | i `elem` [LONG_BRANCH_LUi] = diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/Parent.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/Parent.hs index 5f3a5c83..c149f8af 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/Parent.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/Parent.hs @@ -377,11 +377,22 @@ parent i VSHF_W, WAIT, WAIT_MM, WAIT_MMR6, WRDSP, WRDSP_MM, WRPGPR_MMR6, WSBH, WSBH_MM, WSBH_MMR6, XOR, XOR16_MM, XOR16_MMR6, XOR64, XORI_B, XORI_MMR6, XOR_MM, XOR_MMR6, XOR_V, XOR_V_D_PSEUDO, XOR_V_H_PSEUDO, - XOR_V_W_PSEUDO, XORi, XORi64, XORi_MM, XorRxRxRy16] + XOR_V_W_PSEUDO, XORi, XORi64, XORi_MM, XorRxRxRy16, + Register_class_decl_dummy] = Nothing | i `elem` [ADDiu_negsp, ADDiu_sp] = Just ADDiu + | i `elem` [B_NOP] = Just B + | i `elem` [BC1F_NOP] = Just BC1F + | i `elem` [BC1T_NOP] = Just BC1T + | i `elem` [BEQ_NOP] = Just BEQ + | i `elem` [BGEZ_NOP] = Just BGEZ + | i `elem` [BGTZ_NOP] = Just BGTZ + | i `elem` [BLEZ_NOP] = Just BLEZ + | i `elem` [BLTZ_NOP] = Just BLTZ + | i `elem` [BNE_NOP] = Just BNE | i `elem` [MOVE_D] = Just FMOV_D32 | i `elem` [MOVE_F] = Just FMOV_S + | i `elem` [JALRPseudo_NOP] = Just JALRPseudo | i `elem` [LBu_fi] = Just LBu | i `elem` [LBu_fi_demat_fi, LBu_fi_remat_fi, LBu_fi_source_fi] = Just LBu_fi @@ -401,6 +412,9 @@ parent i Just LW_fi | i `elem` [LoadGPDisp] = Just LoadAddrImm32 | i `elem` [MOVE] = Just OR + | i `elem` [PseudoIndirectBranch_NOP] = Just PseudoIndirectBranch + | i `elem` [PseudoReturn_NOP] = Just PseudoReturn + | i `elem` [RetRA_NOP] = Just RetRA | i `elem` [SB_fi] = Just SB | i `elem` [SDC1_sp, STORE_D] = Just SDC1 | i `elem` [SH_fi] = Just SH diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/ReadOp.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/ReadOp.hs index e9786993..9d15bf69 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/ReadOp.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/ReadOp.hs @@ -2258,6 +2258,20 @@ readOp "SWC1_sp" = SWC1_sp readOp "SDC1_sp" = SDC1_sp readOp "LoadGPDisp" = LoadGPDisp readOp "CLOBBER_RA" = CLOBBER_RA +readOp "B_NOP" = B_NOP +readOp "BC1F_NOP" = BC1F_NOP +readOp "BC1T_NOP" = BC1T_NOP +readOp "BEQ_NOP" = BEQ_NOP +readOp "BGEZ_NOP" = BGEZ_NOP +readOp "BGTZ_NOP" = BGTZ_NOP +readOp "BLEZ_NOP" = BLEZ_NOP +readOp "BLTZ_NOP" = BLTZ_NOP +readOp "BNE_NOP" = BNE_NOP +readOp "JALRPseudo_NOP" = JALRPseudo_NOP +readOp "PseudoIndirectBranch_NOP" = PseudoIndirectBranch_NOP +readOp "PseudoReturn_NOP" = PseudoReturn_NOP +readOp "RetRA_NOP" = RetRA_NOP +readOp "register_class_decl_dummy" = Register_class_decl_dummy readOp "LDC1_fi_source_fi" = LDC1_fi_source_fi readOp "LDC1_fi_demat_fi" = LDC1_fi_demat_fi readOp "LDC1_fi_remat_fi" = LDC1_fi_remat_fi diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/ReadWriteInfo.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/ReadWriteInfo.hs index 32fb6183..8eb2b0d3 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/ReadWriteInfo.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/ReadWriteInfo.hs @@ -234,80 +234,81 @@ readWriteInfo i PseudoCMP_LT_PH, PseudoCVT_D32_W, PseudoCVT_D64_L, PseudoCVT_D64_W, PseudoCVT_S_L, PseudoCVT_S_W, PseudoDMULT, PseudoDMULTu, PseudoDSDIV, PseudoDUDIV, PseudoIndirectBranch, - PseudoIndirectBranch64, PseudoMADD, PseudoMADDU, PseudoMFHI, - PseudoMFHI64, PseudoMFLO, PseudoMFLO64, PseudoMSUB, PseudoMSUBU, - PseudoMTLOHI, PseudoMTLOHI64, PseudoMTLOHI_DSP, PseudoMULT, - PseudoMULTu, PseudoPICK_PH, PseudoPICK_QB, PseudoReturn, - PseudoReturn64, PseudoSDIV, PseudoSELECTFP_F_D32, - PseudoSELECTFP_F_D64, PseudoSELECTFP_F_I, PseudoSELECTFP_F_I64, - PseudoSELECTFP_F_S, PseudoSELECTFP_T_D32, PseudoSELECTFP_T_D64, - PseudoSELECTFP_T_I, PseudoSELECTFP_T_I64, PseudoSELECTFP_T_S, - PseudoSELECT_D32, PseudoSELECT_D64, PseudoSELECT_I, - PseudoSELECT_I64, PseudoSELECT_S, PseudoUDIV, RADDU_W_QB, - RADDU_W_QB_MM, RDDSP, RDDSP_MM, RDHWR, RDHWR64, RDHWR_MM, - RDHWR_MMR6, RDPGPR_MMR6, RECIP_D_MMR6, RECIP_S_MMR6, REG_SEQUENCE, - REPLV_PH, REPLV_PH_MM, REPLV_QB, REPLV_QB_MM, REPL_PH, REPL_PH_MM, - REPL_QB, REPL_QB_MM, RINT_D, RINT_D_MMR6, RINT_S, RINT_S_MMR6, ROL, - ROLImm, ROR, RORImm, ROTR, ROTRV, ROTRV_MM, ROTR_MM, ROUND_L_D64, - ROUND_L_D_MMR6, ROUND_L_S, ROUND_L_S_MMR6, ROUND_W_D32, - ROUND_W_D64, ROUND_W_D_MMR6, ROUND_W_MM, ROUND_W_S, ROUND_W_S_MM, - ROUND_W_S_MMR6, RSQRT_D_MMR6, RSQRT_S_MMR6, RetRA, RetRA16, - SAT_S_B, SAT_S_D, SAT_S_H, SAT_S_W, SAT_U_B, SAT_U_D, SAT_U_H, - SAT_U_W, SDBBP, SDBBP16_MM, SDBBP16_MMR6, SDBBP_MM, SDBBP_MMR6, - SDBBP_R6, SDL, SDR, SDXC1, SDXC164, SDivMacro, SEB, SEB64, SEB_MM, - SEB_MMR6, SEH, SEH64, SEH_MM, SEH_MMR6, SELENZ_D_MMR6, - SELENZ_S_MMR6, SELEQZ, SELEQZ64, SELEQZ_D, SELEQZ_D_MMR6, - SELEQZ_MMR6, SELEQZ_S, SELEQZ_S_MMR6, SELNEZ, SELNEZ64, SELNEZ_D, - SELNEZ_MMR6, SELNEZ_S, SEL_D, SEL_D_MMR6, SEL_S, SEL_S_MMR6, SEQ, - SEQi, SHF_B, SHF_H, SHF_W, SHILO, SHILOV, SHILOV_MM, SHILO_MM, - SHRAV_PH, SHRAV_PH_MM, SHRAV_QB, SHRAV_QB_MMR2, SHRAV_R_PH, - SHRAV_R_PH_MM, SHRAV_R_QB, SHRAV_R_QB_MMR2, SHRAV_R_W, - SHRAV_R_W_MM, SHRA_PH, SHRA_PH_MM, SHRA_QB, SHRA_QB_MMR2, - SHRA_R_PH, SHRA_R_PH_MM, SHRA_R_QB, SHRA_R_QB_MMR2, SHRA_R_W, - SHRA_R_W_MM, SHRLV_PH, SHRLV_PH_MMR2, SHRLV_QB, SHRLV_QB_MM, - SHRL_PH, SHRL_PH_MMR2, SHRL_QB, SHRL_QB_MM, SLDI_B, SLDI_D, SLDI_H, - SLDI_W, SLD_B, SLD_D, SLD_H, SLD_W, SLL, SLL16_MM, SLL16_MMR6, - SLL64_32, SLL64_64, SLLI_B, SLLI_D, SLLI_H, SLLI_W, SLLV, SLLV_MM, - SLL_B, SLL_D, SLL_H, SLL_MM, SLL_MMR6, SLL_W, SLT, SLT64, SLT_MM, - SLTi, SLTi64, SLTi_MM, SLTiu, SLTiu64, SLTiu_MM, SLTu, SLTu64, - SLTu_MM, SNE, SNEi, SNZ_B_PSEUDO, SNZ_D_PSEUDO, SNZ_H_PSEUDO, - SNZ_V_PSEUDO, SNZ_W_PSEUDO, SPLATI_B, SPLATI_D, SPLATI_H, SPLATI_W, - SPLAT_B, SPLAT_D, SPLAT_H, SPLAT_W, SQRT_D_MMR6, SQRT_S_MMR6, SRA, - SRAI_B, SRAI_D, SRAI_H, SRAI_W, SRARI_B, SRARI_D, SRARI_H, SRARI_W, - SRAR_B, SRAR_D, SRAR_H, SRAR_W, SRAV, SRAV_MM, SRA_B, SRA_D, SRA_H, - SRA_MM, SRA_W, SRL, SRL16_MM, SRL16_MMR6, SRLI_B, SRLI_D, SRLI_H, - SRLI_W, SRLRI_B, SRLRI_D, SRLRI_H, SRLRI_W, SRLR_B, SRLR_D, SRLR_H, - SRLR_W, SRLV, SRLV_MM, SRL_B, SRL_D, SRL_H, SRL_MM, SRL_W, SSNOP, - SSNOP_MM, SSNOP_MMR6, ST_B, ST_D, ST_H, ST_W, SUB, SUBQH_PH, - SUBQH_PH_MMR2, SUBQH_R_PH, SUBQH_R_PH_MMR2, SUBQH_R_W, - SUBQH_R_W_MMR2, SUBQH_W, SUBQH_W_MMR2, SUBREG_TO_REG, SUBSUS_U_B, - SUBSUS_U_D, SUBSUS_U_H, SUBSUS_U_W, SUBSUU_S_B, SUBSUU_S_D, - SUBSUU_S_H, SUBSUU_S_W, SUBS_S_B, SUBS_S_D, SUBS_S_H, SUBS_S_W, - SUBS_U_B, SUBS_U_D, SUBS_U_H, SUBS_U_W, SUBU16_MM, SUBU16_MMR6, - SUBUH_QB, SUBUH_QB_MMR2, SUBUH_R_QB, SUBUH_R_QB_MMR2, SUBU_MMR6, - SUBVI_B, SUBVI_D, SUBVI_H, SUBVI_W, SUBV_B, SUBV_D, SUBV_H, SUBV_W, - SUB_MM, SUB_MMR6, SUBu, SUBu_MM, SUXC1, SUXC164, SUXC1_MM, SWL, - SWL64, SWLE, SWLE_MM, SWL_MM, SWL_fi, SWM_MM, SWR, SWR64, SWRE, - SWRE_MM, SWR_MM, SWR_fi, SWXC1, SWXC1_MM, SYNC, SYNCI, SYNCI_MMR6, - SYNC_MM, SYNC_MMR6, SYSCALL, SYSCALL_MM, SZ_B_PSEUDO, SZ_D_PSEUDO, - SZ_H_PSEUDO, SZ_V_PSEUDO, SZ_W_PSEUDO, SebRx16, SehRx16, SelBeqZ, - SelBneZ, SelTBteqZCmp, SelTBteqZCmpi, SelTBteqZSlt, SelTBteqZSlti, - SelTBteqZSltiu, SelTBteqZSltu, SelTBtneZCmp, SelTBtneZCmpi, - SelTBtneZSlt, SelTBtneZSlti, SelTBtneZSltiu, SelTBtneZSltu, SllX16, - SllvRxRy16, SltCCRxRy16, SltiCCRxImmX16, SltiuCCRxImmX16, - SltuCCRxRy16, SraX16, SravRxRy16, SrlX16, SrlvRxRy16, SubuRxRyRz16, - TEQ, TEQI, TEQI_MM, TEQ_MM, TGE, TGEI, TGEIU, TGEIU_MM, TGEI_MM, - TGEU, TGEU_MM, TGE_MM, TLBINV, TLBINVF, TLBP, TLBP_MM, TLBR, - TLBR_MM, TLBWI, TLBWI_MM, TLBWR, TLBWR_MM, TLT, TLTI, TLTIU_MM, - TLTI_MM, TLTU, TLTU_MM, TLT_MM, TNE, TNEI, TNEI_MM, TNE_MM, TRAP, - TRUNC_L_D64, TRUNC_L_D_MMR6, TRUNC_L_S, TRUNC_L_S_MMR6, - TRUNC_W_D32, TRUNC_W_D64, TRUNC_W_D_MMR6, TRUNC_W_MM, TRUNC_W_S, - TRUNC_W_S_MM, TRUNC_W_S_MMR6, TTLTIU, UDivMacro, Ulh, Ulhu, Ulw, - VSHF_B, VSHF_D, VSHF_H, VSHF_W, WAIT, WAIT_MM, WAIT_MMR6, WRDSP, - WRDSP_MM, WRPGPR_MMR6, WSBH, WSBH_MM, WSBH_MMR6, XOR, XOR16_MM, - XOR16_MMR6, XOR64, XORI_B, XORI_MMR6, XOR_MM, XOR_MMR6, XOR_V, - XOR_V_D_PSEUDO, XOR_V_H_PSEUDO, XOR_V_W_PSEUDO, XORi, XORi64, - XORi_MM, XorRxRxRy16] + PseudoIndirectBranch64, PseudoIndirectBranch_NOP, PseudoMADD, + PseudoMADDU, PseudoMFHI, PseudoMFHI64, PseudoMFLO, PseudoMFLO64, + PseudoMSUB, PseudoMSUBU, PseudoMTLOHI, PseudoMTLOHI64, + PseudoMTLOHI_DSP, PseudoMULT, PseudoMULTu, PseudoPICK_PH, + PseudoPICK_QB, PseudoReturn, PseudoReturn64, PseudoReturn_NOP, + PseudoSDIV, PseudoSELECTFP_F_D32, PseudoSELECTFP_F_D64, + PseudoSELECTFP_F_I, PseudoSELECTFP_F_I64, PseudoSELECTFP_F_S, + PseudoSELECTFP_T_D32, PseudoSELECTFP_T_D64, PseudoSELECTFP_T_I, + PseudoSELECTFP_T_I64, PseudoSELECTFP_T_S, PseudoSELECT_D32, + PseudoSELECT_D64, PseudoSELECT_I, PseudoSELECT_I64, PseudoSELECT_S, + PseudoUDIV, RADDU_W_QB, RADDU_W_QB_MM, RDDSP, RDDSP_MM, RDHWR, + RDHWR64, RDHWR_MM, RDHWR_MMR6, RDPGPR_MMR6, RECIP_D_MMR6, + RECIP_S_MMR6, REG_SEQUENCE, REPLV_PH, REPLV_PH_MM, REPLV_QB, + REPLV_QB_MM, REPL_PH, REPL_PH_MM, REPL_QB, REPL_QB_MM, RINT_D, + RINT_D_MMR6, RINT_S, RINT_S_MMR6, ROL, ROLImm, ROR, RORImm, ROTR, + ROTRV, ROTRV_MM, ROTR_MM, ROUND_L_D64, ROUND_L_D_MMR6, ROUND_L_S, + ROUND_L_S_MMR6, ROUND_W_D32, ROUND_W_D64, ROUND_W_D_MMR6, + ROUND_W_MM, ROUND_W_S, ROUND_W_S_MM, ROUND_W_S_MMR6, RSQRT_D_MMR6, + RSQRT_S_MMR6, RetRA, RetRA16, RetRA_NOP, SAT_S_B, SAT_S_D, SAT_S_H, + SAT_S_W, SAT_U_B, SAT_U_D, SAT_U_H, SAT_U_W, SDBBP, SDBBP16_MM, + SDBBP16_MMR6, SDBBP_MM, SDBBP_MMR6, SDBBP_R6, SDL, SDR, SDXC1, + SDXC164, SDivMacro, SEB, SEB64, SEB_MM, SEB_MMR6, SEH, SEH64, + SEH_MM, SEH_MMR6, SELENZ_D_MMR6, SELENZ_S_MMR6, SELEQZ, SELEQZ64, + SELEQZ_D, SELEQZ_D_MMR6, SELEQZ_MMR6, SELEQZ_S, SELEQZ_S_MMR6, + SELNEZ, SELNEZ64, SELNEZ_D, SELNEZ_MMR6, SELNEZ_S, SEL_D, + SEL_D_MMR6, SEL_S, SEL_S_MMR6, SEQ, SEQi, SHF_B, SHF_H, SHF_W, + SHILO, SHILOV, SHILOV_MM, SHILO_MM, SHRAV_PH, SHRAV_PH_MM, + SHRAV_QB, SHRAV_QB_MMR2, SHRAV_R_PH, SHRAV_R_PH_MM, SHRAV_R_QB, + SHRAV_R_QB_MMR2, SHRAV_R_W, SHRAV_R_W_MM, SHRA_PH, SHRA_PH_MM, + SHRA_QB, SHRA_QB_MMR2, SHRA_R_PH, SHRA_R_PH_MM, SHRA_R_QB, + SHRA_R_QB_MMR2, SHRA_R_W, SHRA_R_W_MM, SHRLV_PH, SHRLV_PH_MMR2, + SHRLV_QB, SHRLV_QB_MM, SHRL_PH, SHRL_PH_MMR2, SHRL_QB, SHRL_QB_MM, + SLDI_B, SLDI_D, SLDI_H, SLDI_W, SLD_B, SLD_D, SLD_H, SLD_W, SLL, + SLL16_MM, SLL16_MMR6, SLL64_32, SLL64_64, SLLI_B, SLLI_D, SLLI_H, + SLLI_W, SLLV, SLLV_MM, SLL_B, SLL_D, SLL_H, SLL_MM, SLL_MMR6, + SLL_W, SLT, SLT64, SLT_MM, SLTi, SLTi64, SLTi_MM, SLTiu, SLTiu64, + SLTiu_MM, SLTu, SLTu64, SLTu_MM, SNE, SNEi, SNZ_B_PSEUDO, + SNZ_D_PSEUDO, SNZ_H_PSEUDO, SNZ_V_PSEUDO, SNZ_W_PSEUDO, SPLATI_B, + SPLATI_D, SPLATI_H, SPLATI_W, SPLAT_B, SPLAT_D, SPLAT_H, SPLAT_W, + SQRT_D_MMR6, SQRT_S_MMR6, SRA, SRAI_B, SRAI_D, SRAI_H, SRAI_W, + SRARI_B, SRARI_D, SRARI_H, SRARI_W, SRAR_B, SRAR_D, SRAR_H, SRAR_W, + SRAV, SRAV_MM, SRA_B, SRA_D, SRA_H, SRA_MM, SRA_W, SRL, SRL16_MM, + SRL16_MMR6, SRLI_B, SRLI_D, SRLI_H, SRLI_W, SRLRI_B, SRLRI_D, + SRLRI_H, SRLRI_W, SRLR_B, SRLR_D, SRLR_H, SRLR_W, SRLV, SRLV_MM, + SRL_B, SRL_D, SRL_H, SRL_MM, SRL_W, SSNOP, SSNOP_MM, SSNOP_MMR6, + ST_B, ST_D, ST_H, ST_W, SUB, SUBQH_PH, SUBQH_PH_MMR2, SUBQH_R_PH, + SUBQH_R_PH_MMR2, SUBQH_R_W, SUBQH_R_W_MMR2, SUBQH_W, SUBQH_W_MMR2, + SUBREG_TO_REG, SUBSUS_U_B, SUBSUS_U_D, SUBSUS_U_H, SUBSUS_U_W, + SUBSUU_S_B, SUBSUU_S_D, SUBSUU_S_H, SUBSUU_S_W, SUBS_S_B, SUBS_S_D, + SUBS_S_H, SUBS_S_W, SUBS_U_B, SUBS_U_D, SUBS_U_H, SUBS_U_W, + SUBU16_MM, SUBU16_MMR6, SUBUH_QB, SUBUH_QB_MMR2, SUBUH_R_QB, + SUBUH_R_QB_MMR2, SUBU_MMR6, SUBVI_B, SUBVI_D, SUBVI_H, SUBVI_W, + SUBV_B, SUBV_D, SUBV_H, SUBV_W, SUB_MM, SUB_MMR6, SUBu, SUBu_MM, + SUXC1, SUXC164, SUXC1_MM, SWL, SWL64, SWLE, SWLE_MM, SWL_MM, + SWL_fi, SWM_MM, SWR, SWR64, SWRE, SWRE_MM, SWR_MM, SWR_fi, SWXC1, + SWXC1_MM, SYNC, SYNCI, SYNCI_MMR6, SYNC_MM, SYNC_MMR6, SYSCALL, + SYSCALL_MM, SZ_B_PSEUDO, SZ_D_PSEUDO, SZ_H_PSEUDO, SZ_V_PSEUDO, + SZ_W_PSEUDO, SebRx16, SehRx16, SelBeqZ, SelBneZ, SelTBteqZCmp, + SelTBteqZCmpi, SelTBteqZSlt, SelTBteqZSlti, SelTBteqZSltiu, + SelTBteqZSltu, SelTBtneZCmp, SelTBtneZCmpi, SelTBtneZSlt, + SelTBtneZSlti, SelTBtneZSltiu, SelTBtneZSltu, SllX16, SllvRxRy16, + SltCCRxRy16, SltiCCRxImmX16, SltiuCCRxImmX16, SltuCCRxRy16, SraX16, + SravRxRy16, SrlX16, SrlvRxRy16, SubuRxRyRz16, TEQ, TEQI, TEQI_MM, + TEQ_MM, TGE, TGEI, TGEIU, TGEIU_MM, TGEI_MM, TGEU, TGEU_MM, TGE_MM, + TLBINV, TLBINVF, TLBP, TLBP_MM, TLBR, TLBR_MM, TLBWI, TLBWI_MM, + TLBWR, TLBWR_MM, TLT, TLTI, TLTIU_MM, TLTI_MM, TLTU, TLTU_MM, + TLT_MM, TNE, TNEI, TNEI_MM, TNE_MM, TRAP, TRUNC_L_D64, + TRUNC_L_D_MMR6, TRUNC_L_S, TRUNC_L_S_MMR6, TRUNC_W_D32, + TRUNC_W_D64, TRUNC_W_D_MMR6, TRUNC_W_MM, TRUNC_W_S, TRUNC_W_S_MM, + TRUNC_W_S_MMR6, TTLTIU, UDivMacro, Ulh, Ulhu, Ulw, VSHF_B, VSHF_D, + VSHF_H, VSHF_W, WAIT, WAIT_MM, WAIT_MMR6, WRDSP, WRDSP_MM, + WRPGPR_MMR6, WSBH, WSBH_MM, WSBH_MMR6, XOR, XOR16_MM, XOR16_MMR6, + XOR64, XORI_B, XORI_MMR6, XOR_MM, XOR_MMR6, XOR_V, XOR_V_D_PSEUDO, + XOR_V_H_PSEUDO, XOR_V_W_PSEUDO, XORi, XORi64, XORi_MM, XorRxRxRy16, + Register_class_decl_dummy] = ([], []) | i `elem` [SB, SB16_MM, SB16_MMR6, SB64, SBE, SBE_MM, SBE_MMR6, SB_MM, @@ -322,14 +323,15 @@ readWriteInfo i = ([], [Memory "mem"]) | i `elem` [B, B16_MM, BBIT0, BBIT032, BBIT1, BBIT132, BC16_MMR6, BC1F, BC1FL, - BC1F_MM, BC1T, BC1TL, BC1T_MM, BEQ, BEQ64, BEQC, BEQL, BEQZ16_MM, - BEQZC, BEQZC16_MMR6, BEQZC_MM, BEQ_MM, BGEC, BGEUC, BGEZ, BGEZ64, - BGEZC, BGEZL, BGEZ_MM, BGTZ, BGTZ64, BGTZC, BGTZL, BGTZ_MM, BLEZ, - BLEZ64, BLEZC, BLEZL, BLEZ_MM, BLTC, BLTUC, BLTZ, BLTZ64, BLTZC, - BLTZL, BLTZ_MM, BNE, BNE64, BNEC, BNEL, BNEZ16_MM, BNEZC, - BNEZC16_MMR6, BNEZC_MM, BNE_MM, BNVC, BNZ_B, BNZ_D, BNZ_H, BNZ_V, - BNZ_W, BOVC, BZ_B, BZ_D, BZ_H, BZ_V, BZ_W, J, JIC, JIC_MMR6, J_MM, - TAILCALL, TAILCALL64_R, TAILCALL_R] + BC1F_MM, BC1F_NOP, BC1T, BC1TL, BC1T_MM, BC1T_NOP, BEQ, BEQ64, + BEQC, BEQL, BEQZ16_MM, BEQZC, BEQZC16_MMR6, BEQZC_MM, BEQ_MM, + BEQ_NOP, BGEC, BGEUC, BGEZ, BGEZ64, BGEZC, BGEZL, BGEZ_MM, + BGEZ_NOP, BGTZ, BGTZ64, BGTZC, BGTZL, BGTZ_MM, BGTZ_NOP, BLEZ, + BLEZ64, BLEZC, BLEZL, BLEZ_MM, BLEZ_NOP, BLTC, BLTUC, BLTZ, BLTZ64, + BLTZC, BLTZL, BLTZ_MM, BLTZ_NOP, BNE, BNE64, BNEC, BNEL, BNEZ16_MM, + BNEZC, BNEZC16_MMR6, BNEZC_MM, BNE_MM, BNE_NOP, BNVC, BNZ_B, BNZ_D, + BNZ_H, BNZ_V, BNZ_W, BOVC, BZ_B, BZ_D, BZ_H, BZ_V, BZ_W, B_NOP, J, + JIC, JIC_MMR6, J_MM, TAILCALL, TAILCALL64_R, TAILCALL_R] = ([], [OtherSideEffect AT]) | i `elem` [CMPGDU_EQ_QB, CMPGDU_LE_QB, CMPGDU_LT_QB, CMPU_EQ_QB, CMPU_LE_QB, @@ -418,8 +420,8 @@ readWriteInfo i BGTZALC_MMR6, BLEZALC, BLEZALC_MMR6, BLTZAL, BLTZALC, BLTZALC_MMR6, BLTZALL, BLTZALS_MM, BLTZAL_MM, BNEZALC, BNEZALC_MMR6, JAL, JALR, JALR16_MM, JALR64, JALR64Pseudo, JALRC16_MMR6, JALRPseudo, - JALRS16_MM, JALRS_MM, JALR_MM, JALS_MM, JALX, JALX_MM, JAL_MM, - JIALC, JIALC_MMR6, Jal16, JalB16, JumpLinkReg16] + JALRPseudo_NOP, JALRS16_MM, JALRS_MM, JALR_MM, JALS_MM, JALX, + JALX_MM, JAL_MM, JIALC, JIALC_MMR6, Jal16, JalB16, JumpLinkReg16] = ([], [OtherSideEffect RA]) | i `elem` [CmpRxRy16, CmpiRxImm16, CmpiRxImmX16, SltRxRy16, SltiRxImm16, diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/ShowInstance.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/ShowInstance.hs index 55e06eef..3e7ba642 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/ShowInstance.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/ShowInstance.hs @@ -2260,6 +2260,20 @@ instance Show MipsInstruction where show SDC1_sp = "SDC1_sp" show LoadGPDisp = "LoadGPDisp" show CLOBBER_RA = "CLOBBER_RA" + show B_NOP = "B_NOP" + show BC1F_NOP = "BC1F_NOP" + show BC1T_NOP = "BC1T_NOP" + show BEQ_NOP = "BEQ_NOP" + show BGEZ_NOP = "BGEZ_NOP" + show BGTZ_NOP = "BGTZ_NOP" + show BLEZ_NOP = "BLEZ_NOP" + show BLTZ_NOP = "BLTZ_NOP" + show BNE_NOP = "BNE_NOP" + show JALRPseudo_NOP = "JALRPseudo_NOP" + show PseudoIndirectBranch_NOP = "PseudoIndirectBranch_NOP" + show PseudoReturn_NOP = "PseudoReturn_NOP" + show RetRA_NOP = "RetRA_NOP" + show Register_class_decl_dummy = "register_class_decl_dummy" show LDC1_fi_source_fi = "LDC1_fi_source_fi" show LDC1_fi_demat_fi = "LDC1_fi_demat_fi" show LDC1_fi_remat_fi = "LDC1_fi_remat_fi" diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/Size.hs b/src/unison/src/Unison/Target/Mips/SpecsGen/Size.hs index 82b8f1a9..99c459db 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/Size.hs +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/Size.hs @@ -12,7 +12,7 @@ size i LOAD_STACK_GUARD, LOCAL_ESCAPE, LUi_demat, LUi_source, LWC1_fi_demat_fi, LWC1_fi_source_fi, LW_fi_demat_fi, LW_fi_source_fi, PATCHPOINT, PHI, REG_SEQUENCE, STACKMAP, - STATEPOINT, SUBREG_TO_REG] + STATEPOINT, SUBREG_TO_REG, Register_class_decl_dummy] = 0 | i `elem` [ADDIUR1SP_MM, ADDIUR2_MM, ADDIUS5_MM, ADDIUSP_MM, ADDU16_MM, @@ -396,4 +396,9 @@ size i XORi_MM] = 4 | i `elem` [Jal16, JalB16] = 6 + | i `elem` + [BC1F_NOP, BC1T_NOP, BEQ_NOP, BGEZ_NOP, BGTZ_NOP, BLEZ_NOP, + BLTZ_NOP, BNE_NOP, B_NOP, JALRPseudo_NOP, PseudoIndirectBranch_NOP, + PseudoReturn_NOP, RetRA_NOP] + = 8 diff --git a/src/unison/src/Unison/Target/Mips/SpecsGen/input/mips-manual.yaml b/src/unison/src/Unison/Target/Mips/SpecsGen/input/mips-manual.yaml index c2bcfe7e..aca48148 100644 --- a/src/unison/src/Unison/Target/Mips/SpecsGen/input/mips-manual.yaml +++ b/src/unison/src/Unison/Target/Mips/SpecsGen/input/mips-manual.yaml @@ -194,4 +194,70 @@ instruction-set: size: 0 affects: affected-by: - itinerary: NoItinerary \ No newline at end of file + itinerary: NoItinerary + + - id: B_NOP + parent: B + size: 8 + + - id: BC1F_NOP + parent: BC1F + size: 8 + + - id: BC1T_NOP + parent: BC1T + size: 8 + + - id: BEQ_NOP + parent: BEQ + size: 8 + + - id: BGEZ_NOP + parent: BGEZ + size: 8 + + - id: BGTZ_NOP + parent: BGTZ + size: 8 + + - id: BLEZ_NOP + parent: BLEZ + size: 8 + + - id: BLTZ_NOP + parent: BLTZ + size: 8 + + - id: BNE_NOP + parent: BNE + size: 8 + + - id: JALRPseudo_NOP + parent: JALRPseudo + size: 8 + + - id: PseudoIndirectBranch_NOP + parent: PseudoIndirectBranch + size: 8 + + - id: PseudoReturn_NOP + parent: PseudoReturn + size: 8 + + - id: RetRA_NOP + parent: RetRA + size: 8 + + - id: register_class_decl_dummy + type: linear + operands: + - gpr_att7: [register, use, GPR_ATT7] + - gpr_t89: [register, use, GPR_T89] + - gpr_fpra: [register, use, GPR_FPRA] + - gpr_d09: [register, use, AFGR_D09] + uses: [gpr_att7, gpr_t89, gpr_fpra, gpr_d09] + defines: [] + size: 0 + affects: + affected-by: + itinerary: NoItinerary diff --git a/src/unison/src/Unison/Target/Mips/Transforms.hs b/src/unison/src/Unison/Target/Mips/Transforms.hs index 2846036d..00f8d238 100644 --- a/src/unison/src/Unison/Target/Mips/Transforms.hs +++ b/src/unison/src/Unison/Target/Mips/Transforms.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -15,9 +15,12 @@ module Unison.Target.Mips.Transforms normalizeCallEpilogue, extractReturnRegs, hideStackPointer, + coupleAcc64Operations, + addAlternativeInstructions, clobberRAInCall, insertGPDisp, markBarriers, + enforceMandatoryFrame, cleanClobbers) where import Unison @@ -25,10 +28,13 @@ import MachineIR import Unison.Target.Mips.Common import Unison.Target.Mips.MipsRegisterDecl import Unison.Target.Mips.SpecsGen.MipsInstructionDecl +import Unison.Target.Mips.SpecsGen.OperandInfo +import Unison.Target.Mips.SpecsGen.MipsRegisterClassDecl -- | Gives patterns as sequences of instructions and replacements where -- | registers are transformed into temporaries + rs2ts _ ( m @ SingleOperation { oOpr = (Natural mi @ Linear { @@ -329,6 +335,46 @@ hideStackPointer o = o isStackPointer = isTargetReg SP + +{- + Moves MFHI and MFLO instructions next to their definers, to avoid + interfering live ranges in the acc64 register class. This is to prevent + 'splitBlocks' from creating such interferences across block boundaries + (which would not be solvable by instruction scheduling). +-} +coupleAcc64Operations f @ Function {fCode = code} = + f {fCode = map coupleAcc64OprsInBlock code} + +coupleAcc64OprsInBlock b @ Block {bCode = code} = + foldl coupleAcc64UsersOf b (filter (isAcc64Instr snd) code) + +coupleAcc64UsersOf b d = + moveOperations (isMovableUserOf d) after (isIdOf d) b + +isMovableUserOf d u = isAcc64Instr fst u && isUser (oSingleDef d) u + +isAcc64Instr f SingleOperation { + oOpr = (Natural Linear {oIs = [TargetInstruction i]})} = + case f (operandInfo i) of + [TemporaryInfo {oiRegClass = RegisterClass ACC64}] -> True + _ -> False +isAcc64Instr _ _ = False + +{- + For each delay slot branch, add two alternative instructions: the original + instruction (for which there is an ad-hoc constraint requiring something + else scheduled in parallel) and a version of the instruction with a NOP and + twice the size (to be transformed into a bundle during post-processing). +-} +addAlternativeInstructions o + | isNatural o = + case oInstructions o of + [TargetInstruction i] -> + let is = map TargetInstruction (addDelaySlotNOPInstr i) + in mapToInstructions (const is) o + _ -> o + | otherwise = o + {- Redefine $ra by an operation to be scheduled one cycle before function calls, to model that the old $ra value is not accesible to delay slot @@ -384,6 +430,26 @@ markBarriers o @ SingleOperation { | isBarrierInstr i = o {oAs = as {aReads = [], aWrites = [ControlSideEffect]}} markBarriers o = o +{- + Mark stack handling instructions mandatory for functions that include calls + and do not include exit blocks (as at least the return address needs to be + spilled into the stack). +-} + +enforceMandatoryFrame f ( + a @ SingleOperation { + oOpr = (Natural ai @ Linear {oIs = [_, TargetInstruction i]})} + : + rest) _ | i `elem` [ADDiu_sp, ADDiu_negsp] && + any isCall (flatCode f) && + any isReturnBlock (fCode f) && + none isExitBlock (fCode f) = + let a1 = a {oOpr = Natural ai {oIs = [TargetInstruction i]}} + a2 = mapToActivators (const []) a1 + in (rest, [a2]) + +enforceMandatoryFrame _ (o : rest) _ = (rest, [o]) + cleanClobbers f = mapToOperation cleanClobber f cleanClobber o @ SingleOperation {} diff --git a/src/unison/src/Unison/Target/Mips/Usages.hs b/src/unison/src/Unison/Target/Mips/Usages.hs index 38eb3c9a..48ff03bf 100644 --- a/src/unison/src/Unison/Target/Mips/Usages.hs +++ b/src/unison/src/Unison/Target/Mips/Usages.hs @@ -12,21 +12,31 @@ import Unison.Target.Mips.SpecsGen.MipsInstructionDecl usages to i = let it = SpecsGen.itinerary i + -- if we don't model delay slots, all instructions are serialized by the + -- Issue resource + is = if noDelaySlots to then [mkUsage Issue 1 1] + else [mkUsage Issue (issue i) 1 | issue i > 0] in mergeUsages (itineraryUsage' to i it) - ([mkUsage BundleWidth (size i) 1 | size i > 0] ++ - [mkUsage Issue (issue i) 1]) + ([mkUsage BundleWidth (size i) 1 | size i > 0] ++ is) itineraryUsage' to i it = - let us = itineraryUsage i it - in if unitLatency to then - [u {occupation = 1, offset = 0} - | u <- us, resource u /= LongDuration] - else us + let us = itineraryUsage i it + -- if we don't model delay slots, filter out LongDuration resource + us1 = if noDelaySlots to then + [u | u <- us, resource u /= LongDuration] + else us + us2 = if unitLatency to then + [u {occupation = 1, offset = 0} + | u <- us1, resource u /= LongDuration] + else us1 + in us2 itineraryUsage i _ | isDelaySlotInstr i = [mkUsage LongDuration 1 1] itineraryUsage LoadGPDisp IIPseudo = [mkUsage ALU 1 2, Usage LongDuration 1 1 1] +itineraryUsage PseudoCVT_S_W II_CVT = + [mkUsage ALU 1 2, Usage LongDuration 1 1 1] itineraryUsage RetRA IIPseudo = itineraryUsage PseudoReturn (SpecsGen.itinerary PseudoReturn) itineraryUsage NOP IIPseudo = [mkUsage ALU 1 1] @@ -49,7 +59,7 @@ itineraryUsage _ it II_JALR, II_JALRC, II_JALRS, II_JALS, II_JR, II_JRADDIUSP, II_JRC, II_ReturnPseudo, II_CEIL, II_CVT, II_ABS, II_FLOOR, II_NEG, II_ROUND, II_TRUNC, II_SDC1, II_SWC1, II_SDXC1, II_SWXC1, - II_SUXC1] = + II_SUXC1, II_SEB, II_SEH] = [mkUsage ALU 1 1] | it `elem` [II_LB, II_LBU, II_LH, II_LHU, II_LW, II_LWL, II_LWR, II_LD, II_LDL, II_LDR, II_RESTORE, II_C_CC_S, II_C_CC_D, II_LDC1, @@ -87,12 +97,14 @@ itineraryUsage i it = error ("unmatched: itineraryUsage " ++ show i ++ " " ++ show it) size CLOBBER_RA = 0 +size PseudoCVT_S_W = size MTC1 + size CVT_S_W size LoadGPDisp = size LUi + size ADDiu size i | isSourceInstr i || isDematInstr i = 0 size i = case SpecsGen.size i of 4 -> 1 + 8 -> 2 s -> error ("size of instruction " ++ show i ++ " is " ++ show s) issue i diff --git a/src/unison/src/Unison/Target/Query.hs b/src/unison/src/Unison/Target/Query.hs index 2c1ae9c6..db168501 100644 --- a/src/unison/src/Unison/Target/Query.hs +++ b/src/unison/src/Unison/Target/Query.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -178,7 +178,9 @@ mayCrossMemDep rwif d u code = any (\i -> mayLoad rwif i || mayStore rwif i) (oTargetIs d) && any (mayStoreOpr rwif) (operationsInBetween (oId d) (oId u) code) -mayStoreOpr rwif o = isNatural o && any (mayStore rwif) (oTargetIs o) +mayStoreOpr rwif o = + isFun o || + (isNatural o && any (mayStore rwif) (oTargetIs o)) operationsInBetween p s code = let b = fromJust $ find (\b -> any (isId p) (bCode b)) code diff --git a/src/unison/src/Unison/Target/RegisterArray.hs b/src/unison/src/Unison/Target/RegisterArray.hs index a2a486e2..a52585dd 100644 --- a/src/unison/src/Unison/Target/RegisterArray.hs +++ b/src/unison/src/Unison/Target/RegisterArray.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Test/Driver.hs b/src/unison/src/Unison/Test/Driver.hs index ecc48a2b..92716446 100644 --- a/src/unison/src/Unison/Test/Driver.hs +++ b/src/unison/src/Unison/Test/Driver.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Test/Invariants.hs b/src/unison/src/Unison/Test/Invariants.hs index 0bf3f671..451686b4 100644 --- a/src/unison/src/Unison/Test/Invariants.hs +++ b/src/unison/src/Unison/Test/Invariants.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Analyze.hs b/src/unison/src/Unison/Tools/Analyze.hs index eb2c0198..1b259899 100644 --- a/src/unison/src/Unison/Tools/Analyze.hs +++ b/src/unison/src/Unison/Tools/Analyze.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -91,10 +91,10 @@ analyze (estimateFreq, simulateStalls, mirVersion, modelCost, overheadOnly) in (gs, partialFs ++ partialFs') -associateFunction (cf, _) g @ (DynamicGoal Cycles) = (g, cf) -associateFunction (cf, _) g @ (StaticGoal Cycles) = (g, cf) -associateFunction (_, rf) g @ (DynamicGoal (ResourceUsage _)) = (g, rf) -associateFunction (_, rf) g @ (StaticGoal (ResourceUsage _)) = (g, rf) +associateFunction (cf, _) g @ (DynamicGoal Cycles) = (g, cf) +associateFunction (cf, _) g @ (StaticGoal Cycles) = (g, cf) +associateFunction (_, rf) g @ (DynamicGoal {}) = (g, rf) +associateFunction (_, rf) g @ (StaticGoal {}) = (g, rf) analyzerGeneralTransformations (estimateFreq, modelCost, overheadOnly) = [(addDelimiters, "addDelimiters", True), diff --git a/src/unison/src/Unison/Tools/Analyze/ComputeGoal.hs b/src/unison/src/Unison/Tools/Analyze/ComputeGoal.hs index 31ad38a9..7e542ebe 100644 --- a/src/unison/src/Unison/Tools/Analyze/ComputeGoal.hs +++ b/src/unison/src/Unison/Tools/Analyze/ComputeGoal.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -22,34 +22,51 @@ import Unison.Analysis.MakespanBounds computeGoal modelCost factor target (gl, Function {fCode = code}) = let uf = usages target cf = capacityMap target + sof = spillOverhead target b2f = M.fromList $ map (\b -> (bLab b, scaleDown factor (blockFreq b))) code - gs = goal modelCost (uf, cf) b2f code gl + gs = goal sof modelCost (uf, cf) b2f code gl in if any isNothing (map (aFreq . bAs) code) then error ("frequency estimations are not given, use the flag -f to let the analyzer estimate them") else gs -goal modelCost aux b2f code (StaticGoal o) = - goalOb modelCost aux (M.map (const 1) b2f) code o -goal modelCost aux b2f code (DynamicGoal o) = - goalOb modelCost aux b2f code o +goal sof modelCost aux b2f code (StaticGoal o) = + goalOb sof modelCost aux (M.map (const 1) b2f) code o +goal sof modelCost aux b2f code (DynamicGoal o) = + goalOb sof modelCost aux b2f code o -goalOb modelCost aux b2f code go = - sumMap (goalObInBlock modelCost aux b2f go) code +goalOb sof modelCost aux b2f code go = + sumMap (goalObInBlock sof modelCost aux b2f go) code -goalObInBlock modelCost aux b2f go Block {bLab = l, bCode = code} = +goalObInBlock sof modelCost aux b2f go Block {bLab = l, bCode = code} = let f = b2f M.! l - c = sumMap (goalObInOpr modelCost aux go) code + c = sumMap (goalObInOpr sof modelCost aux go) code in f * c -goalObInOpr modelCost _ Cycles o +goalObInOpr _ modelCost _ Cycles o | modelCost && (isIn o || isFun o) = 1 | isVirtual o = 0 | otherwise = 1 -goalObInOpr modelCost aux ru @ (ResourceUsage _) Bundle {bundleOs = os} = - sumMap (goalObInOpr modelCost aux ru) os -goalObInOpr modelCost (uf, cf) (ResourceUsage r) o +goalObInOpr sof modelCost aux ru @ SpillOverhead Bundle {bundleOs = os} = + sumMap (goalObInOpr sof modelCost aux ru) os +goalObInOpr sof _ _ SpillOverhead o + | isVirtual o = 0 + | otherwise = + case sof (targetInst $ oInstructions o, oUses o, oDefs o) of + Just (_, l) -> l + Nothing -> 0 +goalObInOpr sof modelCost aux ru @ SpillAction Bundle {bundleOs = os} = + sumMap (goalObInOpr sof modelCost aux ru) os +goalObInOpr sof _ _ SpillAction o + | isVirtual o = 0 + | otherwise = + case sof (targetInst $ oInstructions o, oUses o, oDefs o) of + Just (True, _) -> 1 + _ -> 0 +goalObInOpr sof modelCost aux ru @ (ResourceUsage _) Bundle {bundleOs = os} = + sumMap (goalObInOpr sof modelCost aux ru) os +goalObInOpr _ modelCost (uf, cf) (ResourceUsage r) o | modelCost && isBarrier o = cf M.! r | isVirtual o = 0 | otherwise = diff --git a/src/unison/src/Unison/Tools/Analyze/FilterOverhead.hs b/src/unison/src/Unison/Tools/Analyze/FilterOverhead.hs index 4c6e3584..f1d0222d 100644 --- a/src/unison/src/Unison/Tools/Analyze/FilterOverhead.hs +++ b/src/unison/src/Unison/Tools/Analyze/FilterOverhead.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Analyze/InsertFuns.hs b/src/unison/src/Unison/Tools/Analyze/InsertFuns.hs index 365972c0..4b8229e1 100644 --- a/src/unison/src/Unison/Tools/Analyze/InsertFuns.hs +++ b/src/unison/src/Unison/Tools/Analyze/InsertFuns.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Analyze/InsertNops.hs b/src/unison/src/Unison/Tools/Analyze/InsertNops.hs index 5b880e41..cc833ffa 100644 --- a/src/unison/src/Unison/Tools/Analyze/InsertNops.hs +++ b/src/unison/src/Unison/Tools/Analyze/InsertNops.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment.hs b/src/unison/src/Unison/Tools/Augment.hs index da5461d1..2abde6c7 100644 --- a/src/unison/src/Unison/Tools/Augment.hs +++ b/src/unison/src/Unison/Tools/Augment.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/AddDataCongruences.hs b/src/unison/src/Unison/Tools/Augment/AddDataCongruences.hs index 3d97c945..82d0ec2f 100644 --- a/src/unison/src/Unison/Tools/Augment/AddDataCongruences.hs +++ b/src/unison/src/Unison/Tools/Augment/AddDataCongruences.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/AddPrologueEpilogue.hs b/src/unison/src/Unison/Tools/Augment/AddPrologueEpilogue.hs index 12a22cdc..3c9583b8 100644 --- a/src/unison/src/Unison/Tools/Augment/AddPrologueEpilogue.hs +++ b/src/unison/src/Unison/Tools/Augment/AddPrologueEpilogue.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/AddReadWrites.hs b/src/unison/src/Unison/Tools/Augment/AddReadWrites.hs index 49b0d3aa..9a940510 100644 --- a/src/unison/src/Unison/Tools/Augment/AddReadWrites.hs +++ b/src/unison/src/Unison/Tools/Augment/AddReadWrites.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/AddRematerialization.hs b/src/unison/src/Unison/Tools/Augment/AddRematerialization.hs index d7fcde35..0c4b3bb2 100644 --- a/src/unison/src/Unison/Tools/Augment/AddRematerialization.hs +++ b/src/unison/src/Unison/Tools/Augment/AddRematerialization.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/AugmentOperands.hs b/src/unison/src/Unison/Tools/Augment/AugmentOperands.hs index b99a6e18..da8fe578 100644 --- a/src/unison/src/Unison/Tools/Augment/AugmentOperands.hs +++ b/src/unison/src/Unison/Tools/Augment/AugmentOperands.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/CleanAttributes.hs b/src/unison/src/Unison/Tools/Augment/CleanAttributes.hs index 986e4a32..ef432f5c 100644 --- a/src/unison/src/Unison/Tools/Augment/CleanAttributes.hs +++ b/src/unison/src/Unison/Tools/Augment/CleanAttributes.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/ExpandCopies.hs b/src/unison/src/Unison/Tools/Augment/ExpandCopies.hs index 96aea7c0..4c33f1a5 100644 --- a/src/unison/src/Unison/Tools/Augment/ExpandCopies.hs +++ b/src/unison/src/Unison/Tools/Augment/ExpandCopies.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/GeneralizeCongruences.hs b/src/unison/src/Unison/Tools/Augment/GeneralizeCongruences.hs index 450f2fb3..b12366d7 100644 --- a/src/unison/src/Unison/Tools/Augment/GeneralizeCongruences.hs +++ b/src/unison/src/Unison/Tools/Augment/GeneralizeCongruences.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/GeneralizeOperands.hs b/src/unison/src/Unison/Tools/Augment/GeneralizeOperands.hs index 341ce322..6a9ceafb 100644 --- a/src/unison/src/Unison/Tools/Augment/GeneralizeOperands.hs +++ b/src/unison/src/Unison/Tools/Augment/GeneralizeOperands.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Augment/LiftMemInfo.hs b/src/unison/src/Unison/Tools/Augment/LiftMemInfo.hs index 2c99f49f..84f616ee 100644 --- a/src/unison/src/Unison/Tools/Augment/LiftMemInfo.hs +++ b/src/unison/src/Unison/Tools/Augment/LiftMemInfo.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Count.hs b/src/unison/src/Unison/Tools/Count.hs index afecdc02..7d44f6f7 100644 --- a/src/unison/src/Unison/Tools/Count.hs +++ b/src/unison/src/Unison/Tools/Count.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export.hs b/src/unison/src/Unison/Tools/Export.hs index 34dbbf59..406d9bf5 100644 --- a/src/unison/src/Unison/Tools/Export.hs +++ b/src/unison/src/Unison/Tools/Export.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -16,6 +16,7 @@ import Data.Aeson import qualified Data.ByteString.Lazy.Char8 as BSL import qualified Data.HashMap.Strict as HM import Control.Monad +import Control.Arrow import MachineIR import Unison @@ -29,6 +30,7 @@ import Unison.Transformations.RunTargetTransforms import MachineIR.Transformations.RunPostProcess import MachineIR.Transformations.SimplifyFallthroughs import MachineIR.Transformations.RenameMachineBlocks +import MachineIR.Transformations.AddImplicitRegs import MachineIR.Transformations.PrepareForEmission import Unison.Tools.Export.SelectTemporaries @@ -64,8 +66,11 @@ run (removeReds, keepNops, baseFile, tight, mirVersion, debug, outJsonFile, (uniTransformations (fromJust sol) (removeReds, keepNops, tight)) target f mf = toMachineFunction f' + -- Pass keepNops option to the target, to control post-processing. + target' = if keepNops then second ((++) ["keep-nops"]) target + else target (mf', partialMfs) = - applyTransformations (mirTransformations mirVersion) target mf + applyTransformations (mirTransformations mirVersion) target' mf mfBase = case baseMir of (Just base) -> base Nothing -> "" @@ -124,5 +129,6 @@ mirTransformations mirVersion = [(simplifyFallthroughs True, "simplifyFallthroughs", True), (renameMachineBlocks, "renameMachineBlocks", True), (runPostProcess, "runPostProcess", True), + (addImplicitRegs, "addImplicitRegs", True), (cleanNops, "cleanNops", True), (prepareForEmission mirVersion, "prepareForEmission", True)] diff --git a/src/unison/src/Unison/Tools/Export/AssignRegisters.hs b/src/unison/src/Unison/Tools/Export/AssignRegisters.hs index 04162e1c..eee9f785 100644 --- a/src/unison/src/Unison/Tools/Export/AssignRegisters.hs +++ b/src/unison/src/Unison/Tools/Export/AssignRegisters.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export/BundleOperations.hs b/src/unison/src/Unison/Tools/Export/BundleOperations.hs index 28f9d36f..f0cb4f16 100644 --- a/src/unison/src/Unison/Tools/Export/BundleOperations.hs +++ b/src/unison/src/Unison/Tools/Export/BundleOperations.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export/CleanNops.hs b/src/unison/src/Unison/Tools/Export/CleanNops.hs index b60b86cf..7241be6d 100644 --- a/src/unison/src/Unison/Tools/Export/CleanNops.hs +++ b/src/unison/src/Unison/Tools/Export/CleanNops.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -28,6 +28,8 @@ cleanBlockNops n mi @ MachineBlock {mbInstructions = mis} = cleanBundleNops n MachineBundle { mbInstrs = [mi @ MachineSingle {msOpcode = MachineTargetOpc n'}]} | n == n' = mi +-- Headless bundles model branches with delay slots and should not be cleaned. +cleanBundleNops _ mb @ MachineBundle {mbHead = False} = mb cleanBundleNops n mb @ MachineBundle {mbInstrs = mis} = case filter (not . hasTargetOpc n) mis of [mi] -> mi diff --git a/src/unison/src/Unison/Tools/Export/ComputeFrameOffsets.hs b/src/unison/src/Unison/Tools/Export/ComputeFrameOffsets.hs index 7201db9d..077f4390 100644 --- a/src/unison/src/Unison/Tools/Export/ComputeFrameOffsets.hs +++ b/src/unison/src/Unison/Tools/Export/ComputeFrameOffsets.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export/DirectFrame.hs b/src/unison/src/Unison/Tools/Export/DirectFrame.hs index 6fde3eb0..e781099a 100644 --- a/src/unison/src/Unison/Tools/Export/DirectFrame.hs +++ b/src/unison/src/Unison/Tools/Export/DirectFrame.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export/LiftFrameObjects.hs b/src/unison/src/Unison/Tools/Export/LiftFrameObjects.hs index fef02591..855df552 100644 --- a/src/unison/src/Unison/Tools/Export/LiftFrameObjects.hs +++ b/src/unison/src/Unison/Tools/Export/LiftFrameObjects.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -39,7 +39,7 @@ liftFrameObjects f @ Function {fCode = code, fFixedStackFrame = fobjs} _target = machineFrameObjects o = [mo | (Bound mo) <- oAllOps o, isMachineFrameObject mo] -mfoAtoms (MachineFrameObject o (Just s) _) = [o..o+s-1] +mfoAtoms (MachineFrameObject o (Just s) _ _) = [o..o+s-1] mfoAtomUnion mfos = S.toList $ S.fromList $ concatMap mfoAtoms mfos @@ -61,6 +61,6 @@ toFrameIndex o2i (Bound mfo) | isMachineFrameObject mfo = in fi toFrameIndex _ op = op -toFrameObject o2i (MachineFrameObject o (Just size) align) = +toFrameObject o2i (MachineFrameObject o (Just size) align _) = let idx = fst $ o2i M.! o in mkFrameObject idx 0 (Just size) align Nothing diff --git a/src/unison/src/Unison/Tools/Export/LowerFrameIndices.hs b/src/unison/src/Unison/Tools/Export/LowerFrameIndices.hs index 5cc469fe..6defd5f0 100644 --- a/src/unison/src/Unison/Tools/Export/LowerFrameIndices.hs +++ b/src/unison/src/Unison/Tools/Export/LowerFrameIndices.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export/LowerFrameSize.hs b/src/unison/src/Unison/Tools/Export/LowerFrameSize.hs index 2492bc96..c96d8825 100644 --- a/src/unison/src/Unison/Tools/Export/LowerFrameSize.hs +++ b/src/unison/src/Unison/Tools/Export/LowerFrameSize.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export/RemoveNops.hs b/src/unison/src/Unison/Tools/Export/RemoveNops.hs index 23f004da..61d2c033 100644 --- a/src/unison/src/Unison/Tools/Export/RemoveNops.hs +++ b/src/unison/src/Unison/Tools/Export/RemoveNops.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export/RemoveRedundancies.hs b/src/unison/src/Unison/Tools/Export/RemoveRedundancies.hs index 97ef94f7..c669d48d 100644 --- a/src/unison/src/Unison/Tools/Export/RemoveRedundancies.hs +++ b/src/unison/src/Unison/Tools/Export/RemoveRedundancies.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Export/SelectInstructions.hs b/src/unison/src/Unison/Tools/Export/SelectInstructions.hs index 116e6d07..e07e0fe0 100644 --- a/src/unison/src/Unison/Tools/Export/SelectInstructions.hs +++ b/src/unison/src/Unison/Tools/Export/SelectInstructions.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -19,18 +19,22 @@ import Unison import Unison.Target.API import Unison.Target.Query +data RematType = Source | Demat | Remat deriving (Eq, Ord, Show) + selectInstructions instructions f @ Function {fCode = code} target = let fcf = fromCopy target + rif = rematInstrs target fcode = flatten code + i2rt = rematTypeMap rif fcode insts = indexedInstructions $ instructionManager fcode i2inst = M.fromList [(o, op) | (IndexedInstruction o op) <- insts] o2inst = M.fromList [(o, i2inst M.! i) | (o, i) <- zip fcode instructions] - code' = mapToOperationInBlocks (selectInstruction fcf fcode o2inst) - code + code' = mapToOperationInBlocks + (selectInstruction fcf i2rt fcode o2inst) code in f {fCode = code'} -selectInstruction fcf fcode o2inst o +selectInstruction fcf i2rt fcode o2inst o | isVirtual o = case o2inst M.! o of -- Handle nullified virtual operations -- e.g. null (pack) @@ -40,11 +44,46 @@ selectInstruction fcf fcode o2inst o | otherwise = let inst = o2inst M.! o o' = mapToInstructions (const [inst]) o - in maybeImplement fcf fcode inst o' + in maybeImplement fcf i2rt fcode inst o' -maybeImplement fcf fcode (TargetInstruction _) +maybeImplement fcf i2rt fcode (TargetInstruction i) o @ SingleOperation {oAs = as} - | isCopy o || isLinear o = - let ro = fmap (\roid -> fromJust $ find (isId roid) fcode) (aRematOrigin as) - in fcf ro o -maybeImplement _ _ _ o = o + | isCopy o = + case M.lookup i i2rt of + -- Demat instructions are just removed from the final code. + Just (Demat, _) -> + o {oOpr = Natural Linear {oIs = [mkNullInstruction], + oUs = [oCopyS $ oOpr o], + oDs = [oCopyD $ oOpr o]}} + -- Remat instructions are replaced by clones of their original operations + -- (except the definition operand which is preserved). + Just (Remat, orig) -> + let roid = fromJust $ aRematOrigin as + ro = fromJust $ find (isId roid) fcode + in o {oOpr = Natural Linear {oIs = [TargetInstruction orig], + oUs = oUses ro, + oDs = [oCopyD $ oOpr o]}} + -- Regular copies are implemented in a target-dependent fashion. + Nothing -> fcf o + | isLinear o = + case M.lookup i i2rt of + -- Source instructions are just removed from the final code. + Just (Source, _) -> mapToInstructions (const [mkNullInstruction]) o + Nothing -> o +maybeImplement _ _ _ _ o = o + +-- Build a map from instructions to maybe their remat type ('source', 'demat', +-- or 'remat'). +rematTypeMap rif fcode = + let ros = [fromJust $ find (isId oid) fcode + | oid <- mapMaybe rematOrigin fcode] + ris = nub $ [oTargetInstr gi | gi <- concatMap oInstructions ros, + isTargetInstruction gi] + i2rt = M.fromList $ concat [rematType i (rif i) | i <- ris] + in i2rt + +rematOrigin SingleOperation {oAs = Attributes {aRematOrigin = ro}} = ro + +rematType _ Nothing = [] +rematType i (Just (si, di, ri)) = + [(si, (Source, i)), (di, (Demat, i)), (ri, (Remat, i))] diff --git a/src/unison/src/Unison/Tools/Export/SelectTemporaries.hs b/src/unison/src/Unison/Tools/Export/SelectTemporaries.hs index f3092f68..9ba6b7d3 100644 --- a/src/unison/src/Unison/Tools/Export/SelectTemporaries.hs +++ b/src/unison/src/Unison/Tools/Export/SelectTemporaries.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Extend.hs b/src/unison/src/Unison/Tools/Extend.hs index 4d95a607..1413c7aa 100644 --- a/src/unison/src/Unison/Tools/Extend.hs +++ b/src/unison/src/Unison/Tools/Extend.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Extend/CleanCongruences.hs b/src/unison/src/Unison/Tools/Extend/CleanCongruences.hs index baab53b0..899cb6a4 100644 --- a/src/unison/src/Unison/Tools/Extend/CleanCongruences.hs +++ b/src/unison/src/Unison/Tools/Extend/CleanCongruences.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Extend/ExtendWithCopies.hs b/src/unison/src/Unison/Tools/Extend/ExtendWithCopies.hs index d769e2e9..1bfed538 100644 --- a/src/unison/src/Unison/Tools/Extend/ExtendWithCopies.hs +++ b/src/unison/src/Unison/Tools/Extend/ExtendWithCopies.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Extend/GroupCalls.hs b/src/unison/src/Unison/Tools/Extend/GroupCalls.hs index 1770d26e..2dd699bf 100644 --- a/src/unison/src/Unison/Tools/Extend/GroupCalls.hs +++ b/src/unison/src/Unison/Tools/Extend/GroupCalls.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Extend/SortCopies.hs b/src/unison/src/Unison/Tools/Extend/SortCopies.hs index f6043633..116694a6 100644 --- a/src/unison/src/Unison/Tools/Extend/SortCopies.hs +++ b/src/unison/src/Unison/Tools/Extend/SortCopies.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import.hs b/src/unison/src/Unison/Tools/Import.hs index 57aa5078..9bb3ea40 100644 --- a/src/unison/src/Unison/Tools/Import.hs +++ b/src/unison/src/Unison/Tools/Import.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -61,6 +61,7 @@ import Unison.Tools.Import.ConnectCalls import Unison.Tools.Import.RemoveUnreachableBlocks import Unison.Tools.Import.CorrectDoubleBranches import Unison.Tools.Import.AdjustPhiLabels +import Unison.Tools.Import.MovePhiUndefs import Unison.Tools.Import.SimplifyCombinations import Unison.Tools.Import.RemoveUselessVirtuals import Unison.Tools.Import.RelocateDefines @@ -141,6 +142,7 @@ uniTransformations (goal, noCC, noReserved, maxBlockSize, estimateFreq, (renameBlocks, "renameBlocks", True), (correctDoubleBranches, "correctDoubleBranches", True), (adjustPhiLabels, "adjustPhiLabels", True), + (movePhiUndefs, "movePhiUndefs", True), (simplifyCombinations, "simplifyCombinations", True), (removeUselessVirtuals, "removeUselessVirtuals", True), (relocateDefines, "relocateDefines", True), diff --git a/src/unison/src/Unison/Tools/Import/AdjustPhiLabels.hs b/src/unison/src/Unison/Tools/Import/AdjustPhiLabels.hs index c6486233..1b959a04 100644 --- a/src/unison/src/Unison/Tools/Import/AdjustPhiLabels.hs +++ b/src/unison/src/Unison/Tools/Import/AdjustPhiLabels.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/AdvancePhis.hs b/src/unison/src/Unison/Tools/Import/AdvancePhis.hs index 2154a4cd..d4757366 100644 --- a/src/unison/src/Unison/Tools/Import/AdvancePhis.hs +++ b/src/unison/src/Unison/Tools/Import/AdvancePhis.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/ConnectCalls.hs b/src/unison/src/Unison/Tools/Import/ConnectCalls.hs index 8e34c1ef..d8088dfe 100644 --- a/src/unison/src/Unison/Tools/Import/ConnectCalls.hs +++ b/src/unison/src/Unison/Tools/Import/ConnectCalls.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/CorrectDoubleBranches.hs b/src/unison/src/Unison/Tools/Import/CorrectDoubleBranches.hs index f0acedc6..6e87e16e 100644 --- a/src/unison/src/Unison/Tools/Import/CorrectDoubleBranches.hs +++ b/src/unison/src/Unison/Tools/Import/CorrectDoubleBranches.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/DropDebugLocations.hs b/src/unison/src/Unison/Tools/Import/DropDebugLocations.hs index c2aa8192..59f995dd 100644 --- a/src/unison/src/Unison/Tools/Import/DropDebugLocations.hs +++ b/src/unison/src/Unison/Tools/Import/DropDebugLocations.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/EnforceCalleeSaved.hs b/src/unison/src/Unison/Tools/Import/EnforceCalleeSaved.hs index 149b4701..7f3de94d 100644 --- a/src/unison/src/Unison/Tools/Import/EnforceCalleeSaved.hs +++ b/src/unison/src/Unison/Tools/Import/EnforceCalleeSaved.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/EnforceCallerSaved.hs b/src/unison/src/Unison/Tools/Import/EnforceCallerSaved.hs index 603b9927..ee00860b 100644 --- a/src/unison/src/Unison/Tools/Import/EnforceCallerSaved.hs +++ b/src/unison/src/Unison/Tools/Import/EnforceCallerSaved.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/ExtractCallRegs.hs b/src/unison/src/Unison/Tools/Import/ExtractCallRegs.hs index c0bf707b..7f92555b 100644 --- a/src/unison/src/Unison/Tools/Import/ExtractCallRegs.hs +++ b/src/unison/src/Unison/Tools/Import/ExtractCallRegs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/ExtractRegs.hs b/src/unison/src/Unison/Tools/Import/ExtractRegs.hs index 6912c728..13850afb 100644 --- a/src/unison/src/Unison/Tools/Import/ExtractRegs.hs +++ b/src/unison/src/Unison/Tools/Import/ExtractRegs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/ExtractSubRegs.hs b/src/unison/src/Unison/Tools/Import/ExtractSubRegs.hs index a98c4c98..519e4bf5 100644 --- a/src/unison/src/Unison/Tools/Import/ExtractSubRegs.hs +++ b/src/unison/src/Unison/Tools/Import/ExtractSubRegs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/FoldCopies.hs b/src/unison/src/Unison/Tools/Import/FoldCopies.hs index 2ef78eea..5f0b2ff0 100644 --- a/src/unison/src/Unison/Tools/Import/FoldCopies.hs +++ b/src/unison/src/Unison/Tools/Import/FoldCopies.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/ImplementFrameOperations.hs b/src/unison/src/Unison/Tools/Import/ImplementFrameOperations.hs index 48d9d7e9..6c471721 100644 --- a/src/unison/src/Unison/Tools/Import/ImplementFrameOperations.hs +++ b/src/unison/src/Unison/Tools/Import/ImplementFrameOperations.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/KillUnusedTemps.hs b/src/unison/src/Unison/Tools/Import/KillUnusedTemps.hs index 40233e26..71d15317 100644 --- a/src/unison/src/Unison/Tools/Import/KillUnusedTemps.hs +++ b/src/unison/src/Unison/Tools/Import/KillUnusedTemps.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/LiftBranchPredictions.hs b/src/unison/src/Unison/Tools/Import/LiftBranchPredictions.hs index 1104f13a..f05a9579 100644 --- a/src/unison/src/Unison/Tools/Import/LiftBranchPredictions.hs +++ b/src/unison/src/Unison/Tools/Import/LiftBranchPredictions.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/LiftMachineUndefs.hs b/src/unison/src/Unison/Tools/Import/LiftMachineUndefs.hs index 2c06ad6e..76bf7436 100644 --- a/src/unison/src/Unison/Tools/Import/LiftMachineUndefs.hs +++ b/src/unison/src/Unison/Tools/Import/LiftMachineUndefs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/LiftMemoryPartitions.hs b/src/unison/src/Unison/Tools/Import/LiftMemoryPartitions.hs index 892d98c8..742cf663 100644 --- a/src/unison/src/Unison/Tools/Import/LiftMemoryPartitions.hs +++ b/src/unison/src/Unison/Tools/Import/LiftMemoryPartitions.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/LiftRegs.hs b/src/unison/src/Unison/Tools/Import/LiftRegs.hs index 78638a21..dc0ca1b9 100644 --- a/src/unison/src/Unison/Tools/Import/LiftRegs.hs +++ b/src/unison/src/Unison/Tools/Import/LiftRegs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/LiftUndefRegs.hs b/src/unison/src/Unison/Tools/Import/LiftUndefRegs.hs index 60776640..2f856eb5 100644 --- a/src/unison/src/Unison/Tools/Import/LiftUndefRegs.hs +++ b/src/unison/src/Unison/Tools/Import/LiftUndefRegs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/LowerCalls.hs b/src/unison/src/Unison/Tools/Import/LowerCalls.hs index 534c54c9..4b88ae35 100644 --- a/src/unison/src/Unison/Tools/Import/LowerCalls.hs +++ b/src/unison/src/Unison/Tools/Import/LowerCalls.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/LowerInsertSubRegs.hs b/src/unison/src/Unison/Tools/Import/LowerInsertSubRegs.hs index 7edc8afe..b8e875f7 100644 --- a/src/unison/src/Unison/Tools/Import/LowerInsertSubRegs.hs +++ b/src/unison/src/Unison/Tools/Import/LowerInsertSubRegs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/LowerSubRegVirtuals.hs b/src/unison/src/Unison/Tools/Import/LowerSubRegVirtuals.hs index 3a1b47cb..1f2ccbfa 100644 --- a/src/unison/src/Unison/Tools/Import/LowerSubRegVirtuals.hs +++ b/src/unison/src/Unison/Tools/Import/LowerSubRegVirtuals.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/MovePhiUndefs.hs b/src/unison/src/Unison/Tools/Import/MovePhiUndefs.hs new file mode 100644 index 00000000..d59df791 --- /dev/null +++ b/src/unison/src/Unison/Tools/Import/MovePhiUndefs.hs @@ -0,0 +1,39 @@ +{-| +Copyright : Copyright (c) 2019, RISE SICS AB +License : BSD3 (see the LICENSE file) +Maintainer : rcas@acm.org +-} +{- +Main authors: + Roberto Castaneda Lozano + +This file is part of Unison, see http://unison-code.github.io +-} +module Unison.Tools.Import.MovePhiUndefs (movePhiUndefs) where + +import Data.List +import Data.Maybe + +import Unison + +movePhiUndefs f @ Function {fCode = code} _ = + let code' = fixpoint movePhiUndef code + in f {fCode = code'} + +movePhiUndef code = + case find (isPhiDefine code) (flatten code) of + Nothing -> code + Just d -> + let code1 = filterCode (not . isIdOf d) code + p = fromJust $ definePhi code d + src = fromJust $ lookup (oSingleDef d) (phiUses p) + code2 = applyToBlock (insertWhen before isBranch [d]) code1 src + in code2 + +isPhiDefine code = isJust . definePhi code + +definePhi code d @ SingleOperation {oOpr = Virtual Define {oDefineDs = [t]}} = + case users t (flatten code) of + [p] | isPhi p && oprBlock code d == oprBlock code p -> Just p + _ -> Nothing +definePhi _ _ = Nothing diff --git a/src/unison/src/Unison/Tools/Import/NormalizePhis.hs b/src/unison/src/Unison/Tools/Import/NormalizePhis.hs index 769dc987..73c00788 100644 --- a/src/unison/src/Unison/Tools/Import/NormalizePhis.hs +++ b/src/unison/src/Unison/Tools/Import/NormalizePhis.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -24,10 +24,17 @@ normalizePhis mf target = normalizePhi itf oif mi | isMachinePhi mi = - toMachineInstruction $ normalizePhiUses $ - fromMachineInstruction itf oif (-1, mi) + let mi1 = toMachineInstruction $ normalizePhiUses $ + fromMachineInstruction itf oif (-1, mi) + mos = map maybeCopyMtFlags (zip (msOperands mi) (msOperands mi1)) + mi2 = mi1 {msOperands = mos} + in mi2 | otherwise = mi normalizePhiUses o = let us = concat [[t, mkBlockRef bid] | (t, bid) <- nub $ phiUses o] in mapToOperands (const us) id o + +maybeCopyMtFlags (MachineTemp {mtFlags = mtfs}, mt @ MachineTemp {}) = + mt {mtFlags = mtfs} +maybeCopyMtFlags (_, mo) = mo diff --git a/src/unison/src/Unison/Tools/Import/RelocateDefines.hs b/src/unison/src/Unison/Tools/Import/RelocateDefines.hs index d78230fb..e758c7f2 100644 --- a/src/unison/src/Unison/Tools/Import/RelocateDefines.hs +++ b/src/unison/src/Unison/Tools/Import/RelocateDefines.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/RemoveUnreachableBlocks.hs b/src/unison/src/Unison/Tools/Import/RemoveUnreachableBlocks.hs index 96af860d..48a04517 100644 --- a/src/unison/src/Unison/Tools/Import/RemoveUnreachableBlocks.hs +++ b/src/unison/src/Unison/Tools/Import/RemoveUnreachableBlocks.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/RemoveUselessVirtuals.hs b/src/unison/src/Unison/Tools/Import/RemoveUselessVirtuals.hs index 50935f54..700941ef 100644 --- a/src/unison/src/Unison/Tools/Import/RemoveUselessVirtuals.hs +++ b/src/unison/src/Unison/Tools/Import/RemoveUselessVirtuals.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/RepairCSSA.hs b/src/unison/src/Unison/Tools/Import/RepairCSSA.hs index 0b2ec636..73346a4c 100644 --- a/src/unison/src/Unison/Tools/Import/RepairCSSA.hs +++ b/src/unison/src/Unison/Tools/Import/RepairCSSA.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/ReserveRegs.hs b/src/unison/src/Unison/Tools/Import/ReserveRegs.hs index 2f5feb30..81a164b3 100644 --- a/src/unison/src/Unison/Tools/Import/ReserveRegs.hs +++ b/src/unison/src/Unison/Tools/Import/ReserveRegs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/SimplifyCombinations.hs b/src/unison/src/Unison/Tools/Import/SimplifyCombinations.hs index 59e6c31d..8eb27558 100644 --- a/src/unison/src/Unison/Tools/Import/SimplifyCombinations.hs +++ b/src/unison/src/Unison/Tools/Import/SimplifyCombinations.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/SplitBlocks.hs b/src/unison/src/Unison/Tools/Import/SplitBlocks.hs index fe352db1..fa46500c 100644 --- a/src/unison/src/Unison/Tools/Import/SplitBlocks.hs +++ b/src/unison/src/Unison/Tools/Import/SplitBlocks.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Import/TagRemats.hs b/src/unison/src/Unison/Tools/Import/TagRemats.hs index 3cc3bd55..138fa15d 100644 --- a/src/unison/src/Unison/Tools/Import/TagRemats.hs +++ b/src/unison/src/Unison/Tools/Import/TagRemats.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Legalize.hs b/src/unison/src/Unison/Tools/Legalize.hs index 8317e9ad..5fbfa32c 100644 --- a/src/unison/src/Unison/Tools/Legalize.hs +++ b/src/unison/src/Unison/Tools/Legalize.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Linearize.hs b/src/unison/src/Unison/Tools/Linearize.hs index b861cb6b..f5f07f01 100644 --- a/src/unison/src/Unison/Tools/Linearize.hs +++ b/src/unison/src/Unison/Tools/Linearize.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Linearize/AddReflexiveCongruences.hs b/src/unison/src/Unison/Tools/Linearize/AddReflexiveCongruences.hs index 33b15748..f936170f 100644 --- a/src/unison/src/Unison/Tools/Linearize/AddReflexiveCongruences.hs +++ b/src/unison/src/Unison/Tools/Linearize/AddReflexiveCongruences.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Linearize/NormalizeCongruences.hs b/src/unison/src/Unison/Tools/Linearize/NormalizeCongruences.hs index fc43dc0c..fddb508a 100644 --- a/src/unison/src/Unison/Tools/Linearize/NormalizeCongruences.hs +++ b/src/unison/src/Unison/Tools/Linearize/NormalizeCongruences.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Linearize/RemovePhis.hs b/src/unison/src/Unison/Tools/Linearize/RemovePhis.hs index 17bf4bf8..9c499245 100644 --- a/src/unison/src/Unison/Tools/Linearize/RemovePhis.hs +++ b/src/unison/src/Unison/Tools/Linearize/RemovePhis.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Linearize/SinkLiveOuts.hs b/src/unison/src/Unison/Tools/Linearize/SinkLiveOuts.hs index 2a82eb1d..c62570d1 100644 --- a/src/unison/src/Unison/Tools/Linearize/SinkLiveOuts.hs +++ b/src/unison/src/Unison/Tools/Linearize/SinkLiveOuts.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Linearize/SourceLiveIns.hs b/src/unison/src/Unison/Tools/Linearize/SourceLiveIns.hs index 076bb843..5ebf602c 100644 --- a/src/unison/src/Unison/Tools/Linearize/SourceLiveIns.hs +++ b/src/unison/src/Unison/Tools/Linearize/SourceLiveIns.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Lint.hs b/src/unison/src/Unison/Tools/Lint.hs index 813e2d30..9691e8be 100644 --- a/src/unison/src/Unison/Tools/Lint.hs +++ b/src/unison/src/Unison/Tools/Lint.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Model.hs b/src/unison/src/Unison/Tools/Model.hs index b2cae719..3b401101 100644 --- a/src/unison/src/Unison/Tools/Model.hs +++ b/src/unison/src/Unison/Tools/Model.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Patric Hedlin diff --git a/src/unison/src/Unison/Tools/Model/Definitions.hs b/src/unison/src/Unison/Tools/Model/Definitions.hs index 747f7369..9f21861c 100644 --- a/src/unison/src/Unison/Tools/Model/Definitions.hs +++ b/src/unison/src/Unison/Tools/Model/Definitions.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Model/InstructionScheduling.hs b/src/unison/src/Unison/Tools/Model/InstructionScheduling.hs index d4069fa0..a43292fa 100644 --- a/src/unison/src/Unison/Tools/Model/InstructionScheduling.hs +++ b/src/unison/src/Unison/Tools/Model/InstructionScheduling.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Patric Hedlin diff --git a/src/unison/src/Unison/Tools/Model/Presolver.hs b/src/unison/src/Unison/Tools/Model/Presolver.hs index dc7098be..7b809837 100644 --- a/src/unison/src/Unison/Tools/Model/Presolver.hs +++ b/src/unison/src/Unison/Tools/Model/Presolver.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Model/PresolverParameters.hs b/src/unison/src/Unison/Tools/Model/PresolverParameters.hs index ddd5e58d..9667c690 100644 --- a/src/unison/src/Unison/Tools/Model/PresolverParameters.hs +++ b/src/unison/src/Unison/Tools/Model/PresolverParameters.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Patric Hedlin @@ -39,6 +39,7 @@ parameters oldModel (_, dgs, _, _, ra, _) r2as = regAtoms ra precs = if oldModel then [] else concatMap (pgPrecs . PG.mandatory . PG.positive) pgs + ts = tUniqueOps $ flatten code assignhints = [(p, head $ r2as M.! r) | (p, r) <- assignmentHints f] interchangeable = sort $ concatMap interchangeableCopies code -- Default (empty presolver parameters) @@ -60,12 +61,13 @@ parameters oldModel (_, dgs, _, _, ra, _) diffregs = [] :: [Integer] calleesaved_spill = [] :: [Integer] strictly_congr = [] :: [Integer] - predecessors = [] :: [Integer] - successors = [] :: [Integer] quasi_adjacent = [] :: [Integer] long_latency_index = [] :: [Integer] long_latency_def_use = [] :: [Integer] + subsumed_resources = map (\_ -> [] :: [Integer]) code + temp_domain = map (\_ -> [] :: [Integer]) ts value_precede_chains = [] :: [Integer] + wcet = [] :: [Integer] in [ -- Parameters not generated by the SICStus-based presolver @@ -110,12 +112,13 @@ parameters oldModel (_, dgs, _, _, ra, _) ("diffregs", toJSON diffregs), ("calleesaved_spill", toJSON calleesaved_spill), ("strictly_congr", toJSON strictly_congr), - ("predecessors", toJSON predecessors), - ("successors", toJSON successors), ("quasi_adjacent", toJSON quasi_adjacent), ("long_latency_index", toJSON long_latency_index), ("long_latency_def_use", toJSON long_latency_def_use), - ("value_precede_chains", toJSON value_precede_chains) + ("subsumed_resources", toJSON subsumed_resources), + ("temp_domain", toJSON temp_domain), + ("value_precede_chains", toJSON value_precede_chains), + ("wcet", toJSON wcet) ] diff --git a/src/unison/src/Unison/Tools/Model/RegisterAllocation.hs b/src/unison/src/Unison/Tools/Model/RegisterAllocation.hs index b9f4d7bd..30f5fda1 100644 --- a/src/unison/src/Unison/Tools/Model/RegisterAllocation.hs +++ b/src/unison/src/Unison/Tools/Model/RegisterAllocation.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano Contributing authors: Patric Hedlin diff --git a/src/unison/src/Unison/Tools/Normalize.hs b/src/unison/src/Unison/Tools/Normalize.hs index 1d9cce8e..b0fd5c84 100644 --- a/src/unison/src/Unison/Tools/Normalize.hs +++ b/src/unison/src/Unison/Tools/Normalize.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -28,6 +28,7 @@ import MachineIR.Transformations.SplitTerminators import MachineIR.Transformations.RenameMachineBlocks import MachineIR.Transformations.DropUnsupportedPseudos import MachineIR.Transformations.RunPostProcess +import MachineIR.Transformations.AddImplicitRegs import MachineIR.Transformations.PrepareForEmission import Unison.Transformations.FinalizeOperations import Unison.Transformations.EstimateFrequency @@ -78,4 +79,5 @@ mirPostTransformations :: (Eq i, Read i, Read r, Eq r) => MIR.MachineFunction i r, String, Bool)] mirPostTransformations mirVersion = [(runPostProcess, "runPostProcess", True), + (addImplicitRegs, "addImplicitRegs", True), (prepareForEmission mirVersion, "prepareForEmission", True)] diff --git a/src/unison/src/Unison/Tools/Plot.hs b/src/unison/src/Unison/Tools/Plot.hs index 6cc45da0..cab70cd7 100644 --- a/src/unison/src/Unison/Tools/Plot.hs +++ b/src/unison/src/Unison/Tools/Plot.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/Run.hs b/src/unison/src/Unison/Tools/Run.hs index 435d681e..2c9ee3d9 100644 --- a/src/unison/src/Unison/Tools/Run.hs +++ b/src/unison/src/Unison/Tools/Run.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -18,6 +18,7 @@ import System.Process import Control.Monad import Data.List.Split import Data.Maybe +import System.Exit import Common.Util import Unison.Driver @@ -166,6 +167,9 @@ runFunction (Left reason) -> do when (verbose && reason == OverSizeThreshold) $ hPutStrLn stderr "Size threshold exceeded, skipping function..." + when (isNothing baseFile') $ + do hPutStrLn stderr "A function has been skipped, please provide a default base file (--basefile FILE)" + exitFailure let unisonMirFile = addExtension "unison.mir" prefix copyFile (fromJust baseFile') unisonMirFile return prefix diff --git a/src/unison/src/Unison/Tools/Uni.hs b/src/unison/src/Unison/Tools/Uni.hs index 75b1efb8..858be868 100644 --- a/src/unison/src/Unison/Tools/Uni.hs +++ b/src/unison/src/Unison/Tools/Uni.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Tools/UniArgs.hs b/src/unison/src/Unison/Tools/UniArgs.hs index 29f71713..cdc0120c 100644 --- a/src/unison/src/Unison/Tools/UniArgs.hs +++ b/src/unison/src/Unison/Tools/UniArgs.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -106,7 +106,7 @@ allModes = [import', linearize', extend', augment', model', export', analyze', normalize', lint', count', legalize', plot', run'] uniArgs = cmdArgsMode $ modes allModes &= program "uni" - &= summary "Unison v0, Roberto Castaneda Lozano [roberto.castaneda@ri.se]" + &= summary "Unison v0, Roberto Castaneda Lozano [rcas@acm.org]" &= help "Generate assembly code using constraint programming" import' = Import { diff --git a/src/unison/src/Unison/Transformations/AddPragmas.hs b/src/unison/src/Unison/Transformations/AddPragmas.hs index 17a6abed..6f359452 100644 --- a/src/unison/src/Unison/Transformations/AddPragmas.hs +++ b/src/unison/src/Unison/Transformations/AddPragmas.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/CleanPragmas.hs b/src/unison/src/Unison/Transformations/CleanPragmas.hs index c5ed2d15..46871b55 100644 --- a/src/unison/src/Unison/Transformations/CleanPragmas.hs +++ b/src/unison/src/Unison/Transformations/CleanPragmas.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/EstimateFrequency.hs b/src/unison/src/Unison/Transformations/EstimateFrequency.hs index 099f10c3..8532b9e3 100644 --- a/src/unison/src/Unison/Transformations/EstimateFrequency.hs +++ b/src/unison/src/Unison/Transformations/EstimateFrequency.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/FinalizeOperations.hs b/src/unison/src/Unison/Transformations/FinalizeOperations.hs index 96694ae5..4cc0e203 100644 --- a/src/unison/src/Unison/Transformations/FinalizeOperations.hs +++ b/src/unison/src/Unison/Transformations/FinalizeOperations.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/FoldReservedRegisters.hs b/src/unison/src/Unison/Transformations/FoldReservedRegisters.hs index 0dc1ea07..7cd2d313 100644 --- a/src/unison/src/Unison/Transformations/FoldReservedRegisters.hs +++ b/src/unison/src/Unison/Transformations/FoldReservedRegisters.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/NormalizeFrequency.hs b/src/unison/src/Unison/Transformations/NormalizeFrequency.hs index 78f01f58..81307215 100644 --- a/src/unison/src/Unison/Transformations/NormalizeFrequency.hs +++ b/src/unison/src/Unison/Transformations/NormalizeFrequency.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/PostponeBranches.hs b/src/unison/src/Unison/Transformations/PostponeBranches.hs index 0e659c4a..0afdfdcc 100644 --- a/src/unison/src/Unison/Transformations/PostponeBranches.hs +++ b/src/unison/src/Unison/Transformations/PostponeBranches.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/PropagatePhiCongruences.hs b/src/unison/src/Unison/Transformations/PropagatePhiCongruences.hs index 0a264fbc..e915b0a3 100644 --- a/src/unison/src/Unison/Transformations/PropagatePhiCongruences.hs +++ b/src/unison/src/Unison/Transformations/PropagatePhiCongruences.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/PropagatePhis.hs b/src/unison/src/Unison/Transformations/PropagatePhis.hs index e77dc20a..08817296 100644 --- a/src/unison/src/Unison/Transformations/PropagatePhis.hs +++ b/src/unison/src/Unison/Transformations/PropagatePhis.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/RenameBlocks.hs b/src/unison/src/Unison/Transformations/RenameBlocks.hs index 9114fad9..92e83cfa 100644 --- a/src/unison/src/Unison/Transformations/RenameBlocks.hs +++ b/src/unison/src/Unison/Transformations/RenameBlocks.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/RenameMOperands.hs b/src/unison/src/Unison/Transformations/RenameMOperands.hs index d00b4cb2..2238d183 100644 --- a/src/unison/src/Unison/Transformations/RenameMOperands.hs +++ b/src/unison/src/Unison/Transformations/RenameMOperands.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/RenameOperations.hs b/src/unison/src/Unison/Transformations/RenameOperations.hs index 35132a4b..bab6a95f 100644 --- a/src/unison/src/Unison/Transformations/RenameOperations.hs +++ b/src/unison/src/Unison/Transformations/RenameOperations.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/RenameTemps.hs b/src/unison/src/Unison/Transformations/RenameTemps.hs index 70122f81..a40260a8 100644 --- a/src/unison/src/Unison/Transformations/RenameTemps.hs +++ b/src/unison/src/Unison/Transformations/RenameTemps.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/ReorderInstructions.hs b/src/unison/src/Unison/Transformations/ReorderInstructions.hs index 46c97c3d..90b50b34 100644 --- a/src/unison/src/Unison/Transformations/ReorderInstructions.hs +++ b/src/unison/src/Unison/Transformations/ReorderInstructions.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2018, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/RunTargetTransforms.hs b/src/unison/src/Unison/Transformations/RunTargetTransforms.hs index ef99eeac..4ff357c3 100644 --- a/src/unison/src/Unison/Transformations/RunTargetTransforms.hs +++ b/src/unison/src/Unison/Transformations/RunTargetTransforms.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/SortGlobalTemps.hs b/src/unison/src/Unison/Transformations/SortGlobalTemps.hs index 3b984a8f..209101bb 100644 --- a/src/unison/src/Unison/Transformations/SortGlobalTemps.hs +++ b/src/unison/src/Unison/Transformations/SortGlobalTemps.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Transformations/UnbundleSingletons.hs b/src/unison/src/Unison/Transformations/UnbundleSingletons.hs index c27e6f27..c8834ab0 100644 --- a/src/unison/src/Unison/Transformations/UnbundleSingletons.hs +++ b/src/unison/src/Unison/Transformations/UnbundleSingletons.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/src/Unison/Util.hs b/src/unison/src/Unison/Util.hs index dd4b9bc5..940151c9 100644 --- a/src/unison/src/Unison/Util.hs +++ b/src/unison/src/Unison/Util.hs @@ -1,14 +1,14 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org Useful functions to manipulate and query the Unison program representation. -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} @@ -122,6 +122,7 @@ module Unison.Util preAssignments, toCongruenceOp, tempBlock, + oprBlock, tempOperand, isAugmented, mapToOperation, @@ -854,6 +855,11 @@ tempBlock code t = let defined p b = any (isDefiner p) (bCode b) in fromJust $ find (defined t) code +oprBlock :: [Block i r] -> BlockOperation i r -> Block i r +oprBlock code o = + let blockOf o b = any (isIdOf o) (bCode b) + in fromJust $ find (blockOf o) code + tempOperand :: Eq r => Operand r -> BlockOperation i r -> Operand r tempOperand t o = fromJust $ find (\p -> t `elem` extractTemps p) (oAllOperands o) @@ -1444,3 +1450,5 @@ lowerGoal :: Read s => HighLevelGoal -> Goal s lowerGoal Speed = DynamicGoal Cycles lowerGoal Size = StaticGoal (ResourceUsage (read "BundleWidth")) lowerGoal Spill = DynamicGoal (ResourceUsage (read "SpillCost")) +lowerGoal SpOvh = DynamicGoal SpillOverhead +lowerGoal SpNo = StaticGoal SpillAction diff --git a/src/unison/test/Main.hs b/src/unison/test/Main.hs index d46df120..95196122 100644 --- a/src/unison/test/Main.hs +++ b/src/unison/test/Main.hs @@ -1,11 +1,11 @@ {-| Copyright : Copyright (c) 2016, RISE SICS AB License : BSD3 (see the LICENSE file) -Maintainer : roberto.castaneda@ri.se +Maintainer : rcas@acm.org -} {- Main authors: - Roberto Castaneda Lozano + Roberto Castaneda Lozano This file is part of Unison, see http://unison-code.github.io -} diff --git a/src/unison/test/fast/Mips/size/functions.mk b/src/unison/test/fast/Mips/size/functions.mk new file mode 100644 index 00000000..fc7cd675 --- /dev/null +++ b/src/unison/test/fast/Mips/size/functions.mk @@ -0,0 +1,23 @@ +EXP_FUNCTIONS = \ +gcc.alias.get_frame_alias_set \ +gcc.expmed.ceil_log2 \ +gcc.insn-output.output_51 \ +gcc.jump.unsigned_condition \ +gcc.rtlanal.insn_dependent_p_1 \ +gcc.rtlanal.parms_set \ +gcc.xexit.xexit \ +gobmk.board.get_last_player \ +gobmk.interface.init_gnugo \ +gobmk.owl_attackpat.autohelperowl_attackpat68 \ +gobmk.owl_defendpat.autohelperowl_defendpat421 \ +gobmk.owl_vital_apat.autohelperowl_vital_apat34 \ +gobmk.patterns.autohelperpat1088 \ +gobmk.patterns.autohelperpat301 \ +h264ref.memalloc.no_mem_exit \ +h264ref.sei.UpdateRandomAccess \ +h264ref.vlc.symbol2uvlc \ +hmmer.tophits.AllocFancyAli \ +mesa.api.glIndexd \ +mesa.api.glVertex2i \ +sphinx3.glist.glist_tail \ +sphinx3.profile.ptmr_init diff --git a/src/unison/test/fast/Mips/size/gcc.alias.get_frame_alias_set.mir b/src/unison/test/fast/Mips/size/gcc.alias.get_frame_alias_set.mir index 9bde9125..97c55f9d 100644 --- a/src/unison/test/fast/Mips/size/gcc.alias.get_frame_alias_set.mir +++ b/src/unison/test/fast/Mips/size/gcc.alias.get_frame_alias_set.mir @@ -91,7 +91,7 @@ unison-test-target: Mips unison-test-goal: - size unison-test-expected-cost: -- 17 +- 19 unison-test-function: null unison-test-expected-proven: true unison-test-strictly-better: null diff --git a/src/unison/test/fast/Mips/size/gcc.insn-output.output_51.mir b/src/unison/test/fast/Mips/size/gcc.insn-output.output_51.mir index 094a229f..da5cc0e6 100644 --- a/src/unison/test/fast/Mips/size/gcc.insn-output.output_51.mir +++ b/src/unison/test/fast/Mips/size/gcc.insn-output.output_51.mir @@ -100,9 +100,9 @@ unison-test-target: Mips unison-test-goal: - size unison-test-expected-cost: -- 28 +- 30 unison-test-function: null -unison-test-expected-proven: true +unison-test-expected-proven: false unison-test-strictly-better: null -unison-test-expected-has-solution: true +unison-test-expected-has-solution: false ... diff --git a/src/unison/test/fast/Mips/size/gcc.jump.unsigned_condition.mir b/src/unison/test/fast/Mips/size/gcc.jump.unsigned_condition.mir index a43f882c..17ec646b 100644 --- a/src/unison/test/fast/Mips/size/gcc.jump.unsigned_condition.mir +++ b/src/unison/test/fast/Mips/size/gcc.jump.unsigned_condition.mir @@ -87,7 +87,7 @@ unison-test-target: Mips unison-test-goal: - size unison-test-expected-cost: -- 16 +- 17 unison-test-function: null unison-test-expected-proven: true unison-test-strictly-better: null diff --git a/src/unison/test/fast/Mips/size/gcc.rtlanal.parms_set.mir b/src/unison/test/fast/Mips/size/gcc.rtlanal.parms_set.mir index a6f65dcd..ccbff467 100644 --- a/src/unison/test/fast/Mips/size/gcc.rtlanal.parms_set.mir +++ b/src/unison/test/fast/Mips/size/gcc.rtlanal.parms_set.mir @@ -98,7 +98,7 @@ unison-test-target: Mips unison-test-goal: - size unison-test-expected-cost: -- 20 +- 24 unison-test-function: null unison-test-expected-proven: true unison-test-strictly-better: null diff --git a/src/unison/test/fast/Mips/size/gcc.xexit.xexit.mir b/src/unison/test/fast/Mips/size/gcc.xexit.xexit.mir index 7f9d2941..dbbe2b82 100644 --- a/src/unison/test/fast/Mips/size/gcc.xexit.xexit.mir +++ b/src/unison/test/fast/Mips/size/gcc.xexit.xexit.mir @@ -73,7 +73,7 @@ unison-test-target: Mips unison-test-goal: - size unison-test-expected-cost: -- 12 +- 13 unison-test-function: null unison-test-expected-proven: true unison-test-strictly-better: null diff --git a/src/unison/test/fast/Mips/size/gobmk.board.get_last_player.mir b/src/unison/test/fast/Mips/size/gobmk.board.get_last_player.mir index 1ea2d344..f96be9eb 100644 --- a/src/unison/test/fast/Mips/size/gobmk.board.get_last_player.mir +++ b/src/unison/test/fast/Mips/size/gobmk.board.get_last_player.mir @@ -72,7 +72,7 @@ unison-test-target: Mips unison-test-goal: - size unison-test-expected-cost: -- 12 +- 13 unison-test-function: null unison-test-expected-proven: true unison-test-strictly-better: null diff --git a/src/unison/test/fast/Mips/size/mesa.api.glVertex2i.mir b/src/unison/test/fast/Mips/size/mesa.api.glVertex2i.mir index 7cf50e99..96cd3f91 100644 --- a/src/unison/test/fast/Mips/size/mesa.api.glVertex2i.mir +++ b/src/unison/test/fast/Mips/size/mesa.api.glVertex2i.mir @@ -80,7 +80,7 @@ unison-test-target: Mips unison-test-goal: - size unison-test-expected-cost: -- 19 +- 21 unison-test-function: null unison-test-expected-proven: true unison-test-strictly-better: null diff --git a/src/unison/test/fast/Mips/size/sphinx3.glist.glist_tail.mir b/src/unison/test/fast/Mips/size/sphinx3.glist.glist_tail.mir index 1599cc65..02eddb6c 100644 --- a/src/unison/test/fast/Mips/size/sphinx3.glist.glist_tail.mir +++ b/src/unison/test/fast/Mips/size/sphinx3.glist.glist_tail.mir @@ -66,7 +66,7 @@ unison-test-target: Mips unison-test-goal: - size unison-test-expected-cost: -- 6 +- 8 unison-test-function: null unison-test-expected-proven: true unison-test-strictly-better: null diff --git a/src/unison/test/fast/Mips/speed/functions.mk b/src/unison/test/fast/Mips/speed/functions.mk new file mode 100644 index 00000000..c087eada --- /dev/null +++ b/src/unison/test/fast/Mips/speed/functions.mk @@ -0,0 +1,18 @@ +EXP_FUNCTIONS = \ +gcc.alias.get_frame_alias_set \ +gcc.expmed.ceil_log2 \ +gcc.jump.unsigned_condition \ +gcc.rtlanal.parms_set \ +gcc.xexit.xexit \ +gobmk.board.get_last_player \ +gobmk.owl_attackpat.autohelperowl_attackpat68 \ +gobmk.owl_defendpat.autohelperowl_defendpat421 \ +gobmk.owl_vital_apat.autohelperowl_vital_apat34 \ +gobmk.patterns.autohelperpat1088 \ +h264ref.sei.UpdateRandomAccess \ +h264ref.vlc.symbol2uvlc \ +hmmer.tophits.AllocFancyAli \ +mesa.api.glIndexd \ +mesa.api.glVertex2i \ +sphinx3.glist.glist_tail \ +sphinx3.profile.ptmr_init diff --git a/src/unison/test/fast/Mips/speed/mesa.api.glVertex2i.mir b/src/unison/test/fast/Mips/speed/mesa.api.glVertex2i.mir index 3cab5287..35a0b84a 100644 --- a/src/unison/test/fast/Mips/speed/mesa.api.glVertex2i.mir +++ b/src/unison/test/fast/Mips/speed/mesa.api.glVertex2i.mir @@ -80,7 +80,7 @@ unison-test-target: Mips unison-test-goal: - speed unison-test-expected-cost: -- 27 +- 31 unison-test-function: null unison-test-expected-proven: true unison-test-strictly-better: null diff --git a/src/unison/unison.cabal b/src/unison/unison.cabal index eb680351..374c2dca 100644 --- a/src/unison/unison.cabal +++ b/src/unison/unison.cabal @@ -3,8 +3,8 @@ Version: 0 Cabal-Version: >= 1.8 License: BSD3 License-file: LICENSE -Author: Roberto Castaneda Lozano -Maintainer: Roberto Castaneda Lozano +Author: Roberto Castaneda Lozano +Maintainer: Roberto Castaneda Lozano Synopsis: A package for constraint-based code generation Category: Language, Compiler, Code generation, Program Transformation Build-Type: Simple @@ -34,6 +34,7 @@ Library Unison.Target.Hexagon Unison.Target.ARM Unison.Target.Mips + Unison.Target.Minimal Unison.Graphs.Util Unison.Graphs.BCFG @@ -129,6 +130,7 @@ Library Other-modules: Unison.Tools.Import.ConnectCalls Unison.Tools.Import.AdjustPhiLabels + Unison.Tools.Import.MovePhiUndefs Unison.Tools.Import.RemoveUnreachableBlocks Unison.Tools.Import.CorrectDoubleBranches Unison.Tools.Import.DropDebugLocations @@ -202,11 +204,11 @@ Library Unison.Target.Hexagon.Transforms Unison.Target.Hexagon.Usages Unison.Target.Hexagon.HexagonRegisterDecl - Unison.Target.Hexagon.HexagonRegisterClassDecl Unison.Target.Hexagon.HexagonResourceDecl Unison.Target.Hexagon.SpecsGen Unison.Target.Hexagon.SpecsGen.HexagonInstructionDecl Unison.Target.Hexagon.SpecsGen.HexagonItineraryDecl + Unison.Target.Hexagon.SpecsGen.HexagonRegisterClassDecl Unison.Target.Hexagon.SpecsGen.ReadWriteInfo Unison.Target.Hexagon.SpecsGen.OperandInfo Unison.Target.Hexagon.SpecsGen.ReadOp @@ -223,11 +225,11 @@ Library Unison.Target.ARM.Transforms Unison.Target.ARM.Usages Unison.Target.ARM.ARMRegisterDecl - Unison.Target.ARM.ARMRegisterClassDecl Unison.Target.ARM.ARMResourceDecl Unison.Target.ARM.SpecsGen Unison.Target.ARM.SpecsGen.ARMInstructionDecl Unison.Target.ARM.SpecsGen.ARMItineraryDecl + Unison.Target.ARM.SpecsGen.ARMRegisterClassDecl Unison.Target.ARM.SpecsGen.ReadWriteInfo Unison.Target.ARM.SpecsGen.OperandInfo Unison.Target.ARM.SpecsGen.ReadOp @@ -243,11 +245,11 @@ Library Unison.Target.Mips.Transforms Unison.Target.Mips.Usages Unison.Target.Mips.MipsRegisterDecl - Unison.Target.Mips.MipsRegisterClassDecl Unison.Target.Mips.MipsResourceDecl Unison.Target.Mips.SpecsGen Unison.Target.Mips.SpecsGen.MipsInstructionDecl Unison.Target.Mips.SpecsGen.MipsItineraryDecl + Unison.Target.Mips.SpecsGen.MipsRegisterClassDecl Unison.Target.Mips.SpecsGen.ReadWriteInfo Unison.Target.Mips.SpecsGen.OperandInfo Unison.Target.Mips.SpecsGen.ReadOp @@ -259,18 +261,27 @@ Library Unison.Target.Mips.SpecsGen.AllInstructions Unison.Target.Mips.SpecsGen.Parent - if impl(ghc <= 7.4.2) - Build-Depends: transformers-compat == 0.5.*, - cmdargs == 0.10.14, - yaml == 0.8.27, - parsec == 3.1.11 - else - Build-Depends: cmdargs >= 0.10, - yaml >= 0.8, - parsec >= 3.1 + Unison.Target.Minimal.MinimalRegisterDecl + Unison.Target.Minimal.SpecsGen + Unison.Target.Minimal.SpecsGen.MinimalInstructionDecl + Unison.Target.Minimal.SpecsGen.MinimalItineraryDecl + Unison.Target.Minimal.SpecsGen.MinimalRegisterClassDecl + Unison.Target.Minimal.SpecsGen.ReadWriteInfo + Unison.Target.Minimal.SpecsGen.OperandInfo + Unison.Target.Minimal.SpecsGen.ReadOp + Unison.Target.Minimal.SpecsGen.ShowInstance + Unison.Target.Minimal.SpecsGen.Itinerary + Unison.Target.Minimal.SpecsGen.InstructionType + Unison.Target.Minimal.SpecsGen.AlignedPairs + Unison.Target.Minimal.SpecsGen.Size + Unison.Target.Minimal.SpecsGen.AllInstructions + Unison.Target.Minimal.SpecsGen.Parent - Build-Depends: base >= 4.0, - fgl >= 5.6.0, + Build-Depends: cmdargs >= 0.10, + yaml >= 0.8, + parsec >= 3.1, + base >= 4.0, + fgl >= 5.5.0, pretty >= 1.0, graphviz >= 2999.17, split >= 0.1, @@ -279,7 +290,7 @@ Library filepath >= 1.1, text >= 1.0, aeson >= 0.7, - aeson-pretty == 0.7.2, + aeson-pretty >= 0.7.2, bytestring >= 0.9, unordered-containers >= 0.2, directory >= 1.2, diff --git a/src/unison/utils/unison-mode.el b/src/unison/utils/unison-mode.el index 734db0fa..53c8a31a 100644 --- a/src/unison/utils/unison-mode.el +++ b/src/unison/utils/unison-mode.el @@ -1,7 +1,7 @@ ;;; unison-mode.el --- Major mode for Unison (based on LLVM's). -;; Roberto Castaneda Lozano -;; http://www.sics.se/people/rcas +;; Roberto Castaneda Lozano +;; https://robcasloz.github.io/ (defvar unison-bound-face 'unison-bound-face) (defface unison-bound-face