2017-08-02 05:20:10 +08:00
|
|
|
//===- HexagonShuffler.h - Instruction bundle shuffling ---------*- C++ -*-===//
|
2015-06-01 05:57:09 +08:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONSHUFFLER_H
|
|
|
|
#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONSHUFFLER_H
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
#include "Hexagon.h"
|
2017-12-12 02:57:54 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
2017-08-02 05:20:10 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2015-06-01 05:57:09 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2017-08-02 05:20:10 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/SMLoc.h"
|
|
|
|
#include <cstdint>
|
|
|
|
#include <utility>
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-08-02 05:20:10 +08:00
|
|
|
|
|
|
|
class MCContext;
|
|
|
|
class MCInst;
|
|
|
|
class MCInstrInfo;
|
|
|
|
class MCSubtargetInfo;
|
|
|
|
|
2015-06-01 05:57:09 +08:00
|
|
|
// 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:
|
2017-08-02 05:20:10 +08:00
|
|
|
HexagonResource(unsigned s) { setUnits(s); }
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
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);
|
2017-08-02 05:20:10 +08:00
|
|
|
}
|
|
|
|
|
2015-06-01 05:57:09 +08:00
|
|
|
unsigned setWeight(unsigned s);
|
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
unsigned getUnits() const { return (Slots); }
|
|
|
|
unsigned getWeight() const { return (Weight); }
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
// 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()));
|
2017-08-02 05:20:10 +08:00
|
|
|
}
|
|
|
|
|
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());
|
2017-08-02 05:20:10 +08:00
|
|
|
}
|
2015-06-01 05:57:09 +08:00
|
|
|
};
|
|
|
|
|
2015-12-04 05:44:28 +08:00
|
|
|
// HVX insn resources.
|
|
|
|
class HexagonCVIResource : public HexagonResource {
|
2016-01-09 06:07:25 +08:00
|
|
|
public:
|
2017-08-02 05:20:10 +08:00
|
|
|
using UnitsAndLanes = std::pair<unsigned, unsigned>;
|
|
|
|
using TypeUnitsAndLanes = DenseMap<unsigned, UnitsAndLanes>;
|
2015-12-04 05:44:28 +08:00
|
|
|
|
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,
|
2018-12-06 04:18:09 +08:00
|
|
|
CVI_MPY1 = 1 << 3,
|
|
|
|
CVI_ZW = 1 << 4
|
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;
|
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
void setLanes(unsigned l) { Lanes = l; }
|
|
|
|
void setLoad(bool f = true) { Load = f; }
|
|
|
|
void setStore(bool f = true) { Store = f; }
|
2015-12-04 05:44:28 +08:00
|
|
|
|
|
|
|
public:
|
2016-01-09 06:07:25 +08:00
|
|
|
HexagonCVIResource(TypeUnitsAndLanes *TUL, MCInstrInfo const &MCII,
|
|
|
|
unsigned s, MCInst const *id);
|
2017-08-02 05:20:10 +08:00
|
|
|
|
2016-01-09 06:07:25 +08:00
|
|
|
static void SetupTUL(TypeUnitsAndLanes *TUL, StringRef CPU);
|
2015-12-04 05:44:28 +08:00
|
|
|
|
2017-08-02 05:20:10 +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)
|
2017-08-02 05:20:10 +08:00
|
|
|
: ID(id), Extender(Extender), Core(s), CVI(T, MCII, s, id) {}
|
2015-06-01 05:57:09 +08:00
|
|
|
|
2017-08-02 05:20:10 +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));
|
2017-08-02 05:20:10 +08:00
|
|
|
}
|
|
|
|
|
2015-06-01 05:57:09 +08:00
|
|
|
// 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));
|
2017-08-02 05:20:10 +08:00
|
|
|
}
|
|
|
|
|
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));
|
2017-08-02 05:20:10 +08:00
|
|
|
}
|
2015-06-01 05:57:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Bundle shuffler.
|
|
|
|
class HexagonShuffler {
|
2017-08-02 05:20:10 +08:00
|
|
|
using HexagonPacket =
|
|
|
|
SmallVector<HexagonInstr, HEXAGON_PRESHUFFLE_PACKET_SIZE>;
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
// 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;
|
2017-12-12 02:57:54 +08:00
|
|
|
std::vector<std::pair<SMLoc, std::string>> AppliedRestrictions;
|
|
|
|
void applySlotRestrictions();
|
|
|
|
void restrictSlot1AOK();
|
|
|
|
void restrictNoSlot1Store();
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
public:
|
2017-08-02 05:20:10 +08:00
|
|
|
using iterator = HexagonPacket::iterator;
|
2015-06-01 05:57:09 +08:00
|
|
|
|
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();
|
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
unsigned size() const { return (Packet.size()); }
|
2015-06-01 05:57:09 +08:00
|
|
|
|
2017-12-12 02:57:54 +08:00
|
|
|
bool isMemReorderDisabled() const {
|
|
|
|
return (BundleFlags & HexagonMCInstrInfo::memReorderDisabledMask) != 0;
|
|
|
|
}
|
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
iterator begin() { return (Packet.begin()); }
|
|
|
|
iterator end() { return (Packet.end()); }
|
2015-06-01 05:57:09 +08:00
|
|
|
|
|
|
|
// 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-08-02 05:20:10 +08:00
|
|
|
void reportError(Twine const &Msg);
|
2015-06-01 05:57:09 +08:00
|
|
|
};
|
|
|
|
|
2017-08-02 05:20:10 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONSHUFFLER_H
|