StringRef getData() const { return Data; }
};
-using SharedInstrument = std::shared_ptr<Instrument>;
+using UniqueInstrument = std::unique_ptr<Instrument>;
/// This class allows targets to optionally customize the logic that resolves
/// scheduling class IDs. Targets can use information encoded in Instrument
// Instrument.Desc equal to Type
virtual bool supportsInstrumentType(StringRef Type) const { return false; }
- /// Allocate an Instrument, and return a shared pointer to it.
- virtual SharedInstrument createInstrument(StringRef Desc, StringRef Data);
+ /// Allocate an Instrument, and return a unique pointer to it.
+ virtual UniqueInstrument createInstrument(StringRef Desc, StringRef Data);
/// Given an MCInst and a vector of Instrument, a target can
/// return a SchedClassID. This can be used by a subtarget to return a
/// BaseInstruction This can be useful when a BaseInstruction does not convey
/// the correct scheduling information without additional data. By default,
/// it returns the SchedClassID that belongs to MCI.
- virtual unsigned
- getSchedClassID(const MCInstrInfo &MCII, const MCInst &MCI,
- const SmallVector<SharedInstrument> &IVec) const;
+ virtual unsigned getSchedClassID(const MCInstrInfo &MCII, const MCInst &MCI,
+ const SmallVector<Instrument *> &IVec) const;
};
} // namespace mca
InstRecycleCallback InstRecycleCB;
Expected<const InstrDesc &>
- createInstrDescImpl(const MCInst &MCI,
- const SmallVector<SharedInstrument> &IVec);
+ createInstrDescImpl(const MCInst &MCI, const SmallVector<Instrument *> &IVec);
Expected<const InstrDesc &>
getOrCreateInstrDesc(const MCInst &MCI,
- const SmallVector<SharedInstrument> &IVec);
+ const SmallVector<Instrument *> &IVec);
InstrBuilder(const InstrBuilder &) = delete;
InstrBuilder &operator=(const InstrBuilder &) = delete;
void setInstRecycleCallback(InstRecycleCallback CB) { InstRecycleCB = CB; }
Expected<std::unique_ptr<Instruction>>
- createInstruction(const MCInst &MCI,
- const SmallVector<SharedInstrument> &IVec);
+ createInstruction(const MCInst &MCI, const SmallVector<Instrument *> &IVec);
};
} // namespace mca
} // namespace llvm
return std::vector<std::unique_ptr<View>>();
}
-SharedInstrument InstrumentManager::createInstrument(llvm::StringRef Desc,
+UniqueInstrument InstrumentManager::createInstrument(llvm::StringRef Desc,
llvm::StringRef Data) {
- return std::make_shared<Instrument>(Desc, Data);
+ return std::make_unique<Instrument>(Desc, Data);
}
unsigned InstrumentManager::getSchedClassID(
const MCInstrInfo &MCII, const MCInst &MCI,
- const llvm::SmallVector<SharedInstrument> &IVec) const {
+ const llvm::SmallVector<Instrument *> &IVec) const {
return MCII.get(MCI.getOpcode()).getSchedClass();
}
Expected<const InstrDesc &>
InstrBuilder::createInstrDescImpl(const MCInst &MCI,
- const SmallVector<SharedInstrument> &IVec) {
+ const SmallVector<Instrument *> &IVec) {
assert(STI.getSchedModel().hasInstrSchedModel() &&
"Itineraries are not yet supported!");
Expected<const InstrDesc &>
InstrBuilder::getOrCreateInstrDesc(const MCInst &MCI,
- const SmallVector<SharedInstrument> &IVec) {
+ const SmallVector<Instrument *> &IVec) {
// Cache lookup using SchedClassID from Instrumentation
unsigned SchedClassID = IM.getSchedClassID(MCII, MCI, IVec);
Expected<std::unique_ptr<Instruction>>
InstrBuilder::createInstruction(const MCInst &MCI,
- const SmallVector<SharedInstrument> &IVec) {
+ const SmallVector<Instrument *> &IVec) {
Expected<const InstrDesc &> DescOrErr = getOrCreateInstrDesc(MCI, IVec);
if (!DescOrErr)
return DescOrErr.takeError();
return Type == RISCVLMULInstrument::DESC_NAME;
}
-SharedInstrument
+UniqueInstrument
RISCVInstrumentManager::createInstrument(llvm::StringRef Desc,
llvm::StringRef Data) {
if (Desc != RISCVLMULInstrument::DESC_NAME) {
<< Data << '\n');
return nullptr;
}
- return std::make_shared<RISCVLMULInstrument>(Data);
+ return std::make_unique<RISCVLMULInstrument>(Data);
}
unsigned RISCVInstrumentManager::getSchedClassID(
const MCInstrInfo &MCII, const MCInst &MCI,
- const llvm::SmallVector<SharedInstrument> &IVec) const {
+ const llvm::SmallVector<Instrument *> &IVec) const {
unsigned short Opcode = MCI.getOpcode();
unsigned SchedClassID = MCII.get(Opcode).getSchedClass();
for (const auto &I : IVec) {
// Unknown Instrument kind
if (I->getDesc() == RISCVLMULInstrument::DESC_NAME) {
- uint8_t LMUL = static_cast<RISCVLMULInstrument *>(I.get())->getLMUL();
+ uint8_t LMUL = static_cast<RISCVLMULInstrument *>(I)->getLMUL();
const RISCVVInversePseudosTable::PseudoInfo *RVV =
RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL);
// Not a RVV instr
bool supportsInstrumentType(StringRef Type) const override;
/// Create a Instrument for RISC-V target
- SharedInstrument createInstrument(StringRef Desc, StringRef Data) override;
+ UniqueInstrument createInstrument(StringRef Desc, StringRef Data) override;
/// Using the Instrument, returns a SchedClassID to use instead of
/// the SchedClassID that belongs to the MCI or the original SchedClassID.
unsigned
getSchedClassID(const MCInstrInfo &MCII, const MCInst &MCI,
- const SmallVector<SharedInstrument> &IVec) const override;
+ const SmallVector<Instrument *> &IVec) const override;
};
} // namespace mca
InstrumentRegions::InstrumentRegions(llvm::SourceMgr &S) : CodeRegions(S) {}
void InstrumentRegions::beginRegion(StringRef Description, SMLoc Loc,
- SharedInstrument I) {
+ UniqueInstrument I) {
if (Description.empty()) {
SM.PrintMessage(Loc, llvm::SourceMgr::DK_Error,
"anonymous instrumentation regions are not permitted");
}
ActiveRegions[Description] = Regions.size();
- Regions.emplace_back(std::make_unique<InstrumentRegion>(Description, Loc, I));
+ Regions.emplace_back(
+ std::make_unique<InstrumentRegion>(Description, Loc, std::move(I)));
}
void InstrumentRegions::endRegion(StringRef Description, SMLoc Loc) {
}
}
-const SmallVector<SharedInstrument>
+const SmallVector<Instrument *>
InstrumentRegions::getActiveInstruments(SMLoc Loc) const {
- SmallVector<SharedInstrument> AI;
+ SmallVector<Instrument *> AI;
for (auto &R : Regions) {
if (R->isLocInRange(Loc)) {
InstrumentRegion *IR = static_cast<InstrumentRegion *>(R.get());
- AI.emplace_back(IR->getInstrument());
+ AI.push_back(IR->getInstrument());
}
}
return AI;
CodeRegion(llvm::StringRef Desc, llvm::SMLoc Start)
: Description(Desc), RangeStart(Start) {}
+ virtual ~CodeRegion() = default;
+
void addInstruction(const llvm::MCInst &Instruction) {
Instructions.emplace_back(Instruction);
}
/// in analysis of the region.
class InstrumentRegion : public CodeRegion {
/// Instrument for this region.
- SharedInstrument Instrument;
+ UniqueInstrument I;
public:
- InstrumentRegion(llvm::StringRef Desc, llvm::SMLoc Start, SharedInstrument I)
- : CodeRegion(Desc, Start), Instrument(I) {}
+ InstrumentRegion(llvm::StringRef Desc, llvm::SMLoc Start, UniqueInstrument I)
+ : CodeRegion(Desc, Start), I(std::move(I)) {}
public:
- SharedInstrument getInstrument() const { return Instrument; }
+ Instrument *getInstrument() const { return I.get(); }
};
class CodeRegionParseError final : public Error {};
public:
CodeRegions(llvm::SourceMgr &S) : SM(S), FoundErrors(false) {}
+ virtual ~CodeRegions() = default;
typedef std::vector<UniqueCodeRegion>::iterator iterator;
typedef std::vector<UniqueCodeRegion>::const_iterator const_iterator;
};
struct InstrumentRegions : public CodeRegions {
+
InstrumentRegions(llvm::SourceMgr &S);
void beginRegion(llvm::StringRef Description, llvm::SMLoc Loc,
- SharedInstrument Instrument);
+ UniqueInstrument Instrument);
void endRegion(llvm::StringRef Description, llvm::SMLoc Loc);
- const SmallVector<SharedInstrument>
- getActiveInstruments(llvm::SMLoc Loc) const;
+ const SmallVector<Instrument *> getActiveInstruments(llvm::SMLoc Loc) const;
};
} // namespace mca
return;
}
- SharedInstrument I = IM.createInstrument(InstrumentKind, Data);
+ UniqueInstrument I = IM.createInstrument(InstrumentKind, Data);
if (!I) {
if (Data.empty())
SM.PrintMessage(Loc, llvm::SourceMgr::DK_Error,
if (Regions.isRegionActive(InstrumentKind))
Regions.endRegion(InstrumentKind, Loc);
// Start new instrumentation region
- Regions.beginRegion(InstrumentKind, Loc, I);
+ Regions.beginRegion(InstrumentKind, Loc, std::move(I));
}
} // namespace mca
SmallVector<std::unique_ptr<mca::Instruction>> LoweredSequence;
for (const MCInst &MCI : Insts) {
SMLoc Loc = MCI.getLoc();
- const SmallVector<mca::SharedInstrument> Instruments =
+ const SmallVector<mca::Instrument *> Instruments =
InstrumentRegions.getActiveInstruments(Loc);
Expected<std::unique_ptr<mca::Instruction>> Inst =
auto IM = std::make_unique<mca::InstrumentManager>(*STI, *MCII);
mca::InstrBuilder IB(*STI, *MCII, *MRI, MCIA.get(), *IM);
- const SmallVector<mca::SharedInstrument> Instruments;
+ const SmallVector<mca::Instrument *> Instruments;
SmallVector<std::unique_ptr<mca::Instruction>> LoweredInsts;
for (const auto &MCI : Insts) {
Expected<std::unique_ptr<mca::Instruction>> Inst =
auto IM = std::make_unique<mca::InstrumentManager>(*STI, *MCII);
mca::InstrBuilder IB(*STI, *MCII, *MRI, MCIA.get(), *IM);
- const SmallVector<mca::SharedInstrument> Instruments;
+ const SmallVector<mca::Instrument *> Instruments;
// Tile size = 7
for (unsigned i = 0U, E = MCIs.size(); i < E;) {
for (unsigned TE = i + 7; i < TE && i < E; ++i) {
mca::InstrBuilder IB(*STI, *MCII, *MRI, MCIA.get(), *IM);
IB.setInstRecycleCallback(GetRecycledInst);
- const SmallVector<mca::SharedInstrument> Instruments;
+ const SmallVector<mca::Instrument *> Instruments;
// Tile size = 7
for (unsigned i = 0U, E = MCIs.size(); i < E;) {
for (unsigned TE = i + 7; i < TE && i < E; ++i) {