2015-06-01 05:57:09 +08:00
|
|
|
//===----- HexagonShuffler.h - Instruction bundle shuffling ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements the shuffling of insns inside a bundle according to the
|
|
|
|
// packet formation rules of the Hexagon ISA.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef HEXAGONSHUFFLER_H
|
|
|
|
#define HEXAGONSHUFFLER_H
|
|
|
|
|
|
|
|
#include "Hexagon.h"
|
|
|
|
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2016-01-09 06:07:25 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
// Insn resources.
|
|
|
|
class HexagonResource {
|
|
|
|
// Mask of the slots or units that may execute the insn and
|
|
|
|
// the weight or priority that the insn requires to be assigned a slot.
|
|
|
|
unsigned Slots, Weight;
|
|
|
|
|
|
|
|
public:
|
|
|
|
HexagonResource(unsigned s) { setUnits(s); };
|
|
|
|
|
|
|
|
void setUnits(unsigned s) {
|
2017-02-07 10:31:53 +08:00
|
|
|
Slots = s & ((1u << HEXAGON_PACKET_SIZE) - 1);
|
2017-02-07 03:35:46 +08:00
|
|
|
setWeight(s);
|
2015-06-01 05:57:09 +08:00
|
|
|
};
|
|
|
|
unsigned setWeight(unsigned s);
|
|
|
|
|
|
|
|
unsigned getUnits() const { return (Slots); };
|
|
|
|
unsigned getWeight() const { return (Weight); };
|
|
|
|
|
|
|
|
// Check if the resources are in ascending slot order.
|
|
|
|
static bool lessUnits(const HexagonResource &A, const HexagonResource &B) {
|
2017-05-02 03:41:43 +08:00
|
|
|
return (countPopulation(A.getUnits()) < countPopulation(B.getUnits()));
|
2015-06-01 05:57:09 +08:00
|
|
|
};
|
|
|
|
// Check if the resources are in ascending weight order.
|
|
|
|
static bool lessWeight(const HexagonResource &A, const HexagonResource &B) {
|
|
|
|
return (A.getWeight() < B.getWeight());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-12-04 05:44:28 +08:00
|
|
|
// HVX insn resources.
|
|
|
|
class HexagonCVIResource : public HexagonResource {
|
2016-01-09 06:07:25 +08:00
|
|
|
public:
|
2015-12-04 05:44:28 +08:00
|
|
|
typedef std::pair<unsigned, unsigned> UnitsAndLanes;
|
|
|
|
typedef llvm::DenseMap<unsigned, UnitsAndLanes> TypeUnitsAndLanes;
|
|
|
|
|
2016-01-09 06:07:25 +08:00
|
|
|
private:
|
2015-12-04 05:44:28 +08:00
|
|
|
// Available HVX slots.
|
|
|
|
enum {
|
|
|
|
CVI_NONE = 0,
|
|
|
|
CVI_XLANE = 1 << 0,
|
|
|
|
CVI_SHIFT = 1 << 1,
|
|
|
|
CVI_MPY0 = 1 << 2,
|
|
|
|
CVI_MPY1 = 1 << 3
|
|
|
|
};
|
|
|
|
|
2016-01-09 06:07:25 +08:00
|
|
|
TypeUnitsAndLanes *TUL;
|
2015-12-04 05:44:28 +08:00
|
|
|
|
|
|
|
// Count of adjacent slots that the insn requires to be executed.
|
|
|
|
unsigned Lanes;
|
|
|
|
// Flag whether the insn is a load or a store.
|
|
|
|
bool Load, Store;
|
|
|
|
// Flag whether the HVX resources are valid.
|
|
|
|
bool Valid;
|
|
|
|
|
|
|
|
void setLanes(unsigned l) { Lanes = l; };
|
|
|
|
void setLoad(bool f = true) { Load = f; };
|
|
|
|
void setStore(bool f = true) { Store = f; };
|
|
|
|
|
|
|
|
public:
|
2016-01-09 06:07:25 +08:00
|
|
|
HexagonCVIResource(TypeUnitsAndLanes *TUL, MCInstrInfo const &MCII,
|
|
|
|
unsigned s, MCInst const *id);
|
|
|
|
static void SetupTUL(TypeUnitsAndLanes *TUL, StringRef CPU);
|
2015-12-04 05:44:28 +08:00
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
bool isValid() const { return Valid; };
|
|
|
|
unsigned getLanes() const { return Lanes; };
|
|
|
|
bool mayLoad() const { return Load; };
|
|
|
|
bool mayStore() const { return Store; };
|
2015-12-04 05:44:28 +08:00
|
|
|
};
|
|
|
|
|
2015-06-01 05:57:09 +08:00
|
|
|
// Handle to an insn used by the shuffling algorithm.
|
|
|
|
class HexagonInstr {
|
|
|
|
friend class HexagonShuffler;
|
|
|
|
|
|
|
|
MCInst const *ID;
|
|
|
|
MCInst const *Extender;
|
|
|
|
HexagonResource Core;
|
2015-12-04 05:44:28 +08:00
|
|
|
HexagonCVIResource CVI;
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
public:
|
2016-01-09 06:07:25 +08:00
|
|
|
HexagonInstr(HexagonCVIResource::TypeUnitsAndLanes *T,
|
|
|
|
MCInstrInfo const &MCII, MCInst const *id,
|
2017-05-03 01:58:52 +08:00
|
|
|
MCInst const *Extender, unsigned s)
|
|
|
|
: ID(id), Extender(Extender), Core(s), CVI(T, MCII, s, id) {};
|
2015-06-01 05:57:09 +08:00
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
MCInst const &getDesc() const { return *ID; };
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
MCInst const *getExtender() const { return Extender; }
|
|
|
|
|
|
|
|
// Check if the handles are in ascending order for shuffling purposes.
|
|
|
|
bool operator<(const HexagonInstr &B) const {
|
|
|
|
return (HexagonResource::lessWeight(B.Core, Core));
|
|
|
|
};
|
|
|
|
// Check if the handles are in ascending order by core slots.
|
|
|
|
static bool lessCore(const HexagonInstr &A, const HexagonInstr &B) {
|
|
|
|
return (HexagonResource::lessUnits(A.Core, B.Core));
|
|
|
|
};
|
2015-12-04 05:44:28 +08:00
|
|
|
// Check if the handles are in ascending order by HVX slots.
|
|
|
|
static bool lessCVI(const HexagonInstr &A, const HexagonInstr &B) {
|
|
|
|
return (HexagonResource::lessUnits(A.CVI, B.CVI));
|
|
|
|
};
|
2015-06-01 05:57:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Bundle shuffler.
|
|
|
|
class HexagonShuffler {
|
|
|
|
typedef SmallVector<HexagonInstr, HEXAGON_PRESHUFFLE_PACKET_SIZE>
|
|
|
|
HexagonPacket;
|
|
|
|
|
|
|
|
// Insn handles in a bundle.
|
|
|
|
HexagonPacket Packet;
|
2017-02-07 03:35:46 +08:00
|
|
|
HexagonPacket PacketSave;
|
2015-06-01 05:57:09 +08:00
|
|
|
|
2016-01-09 06:07:25 +08:00
|
|
|
HexagonCVIResource::TypeUnitsAndLanes TUL;
|
|
|
|
|
2015-06-01 05:57:09 +08:00
|
|
|
protected:
|
2017-05-02 03:41:43 +08:00
|
|
|
MCContext &Context;
|
2015-06-01 05:57:09 +08:00
|
|
|
int64_t BundleFlags;
|
|
|
|
MCInstrInfo const &MCII;
|
|
|
|
MCSubtargetInfo const &STI;
|
2017-05-02 03:41:43 +08:00
|
|
|
SMLoc Loc;
|
|
|
|
bool ReportErrors;
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef HexagonPacket::iterator iterator;
|
|
|
|
|
2017-05-02 03:41:43 +08:00
|
|
|
HexagonShuffler(MCContext &Context, bool ReportErrors,
|
|
|
|
MCInstrInfo const &MCII, MCSubtargetInfo const &STI);
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
// Reset to initial state.
|
|
|
|
void reset();
|
|
|
|
// Check if the bundle may be validly shuffled.
|
|
|
|
bool check();
|
|
|
|
// Reorder the insn handles in the bundle.
|
|
|
|
bool shuffle();
|
|
|
|
|
|
|
|
unsigned size() const { return (Packet.size()); };
|
|
|
|
|
|
|
|
iterator begin() { return (Packet.begin()); };
|
|
|
|
iterator end() { return (Packet.end()); };
|
|
|
|
|
|
|
|
// Add insn handle to the bundle .
|
2017-02-07 03:35:46 +08:00
|
|
|
void append(MCInst const &ID, MCInst const *Extender, unsigned S);
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
// Return the error code for the last check or shuffling of the bundle.
|
2017-05-02 03:41:43 +08:00
|
|
|
void reportError(llvm::Twine const &Msg);
|
2015-06-01 05:57:09 +08:00
|
|
|
};
|
2017-05-02 03:41:43 +08:00
|
|
|
} // namespace llvm
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
#endif // HEXAGONSHUFFLER_H
|