diff --git a/llvm/include/llvm/MCA/CustomBehaviour.h b/llvm/include/llvm/MCA/CustomBehaviour.h --- a/llvm/include/llvm/MCA/CustomBehaviour.h +++ b/llvm/include/llvm/MCA/CustomBehaviour.h @@ -133,7 +133,7 @@ StringRef getData() const { return Data; } }; -using SharedInstrument = std::shared_ptr; +using UniqueInstrument = std::unique_ptr; /// This class allows targets to optionally customize the logic that resolves /// scheduling class IDs. Targets can use information encoded in Instrument @@ -157,7 +157,7 @@ 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); + 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 @@ -167,7 +167,7 @@ /// it returns the SchedClassID that belongs to MCI. virtual unsigned getSchedClassID(const MCInstrInfo &MCII, const MCInst &MCI, - const SmallVector &IVec) const; + const SmallVector &IVec) const; }; } // namespace mca diff --git a/llvm/include/llvm/MCA/InstrBuilder.h b/llvm/include/llvm/MCA/InstrBuilder.h --- a/llvm/include/llvm/MCA/InstrBuilder.h +++ b/llvm/include/llvm/MCA/InstrBuilder.h @@ -85,10 +85,10 @@ Expected createInstrDescImpl(const MCInst &MCI, - const SmallVector &IVec); + const SmallVector &IVec); Expected getOrCreateInstrDesc(const MCInst &MCI, - const SmallVector &IVec); + const SmallVector &IVec); InstrBuilder(const InstrBuilder &) = delete; InstrBuilder &operator=(const InstrBuilder &) = delete; @@ -115,7 +115,7 @@ Expected> createInstruction(const MCInst &MCI, - const SmallVector &IVec); + const SmallVector &IVec); }; } // namespace mca } // namespace llvm diff --git a/llvm/lib/MCA/CustomBehaviour.cpp b/llvm/lib/MCA/CustomBehaviour.cpp --- a/llvm/lib/MCA/CustomBehaviour.cpp +++ b/llvm/lib/MCA/CustomBehaviour.cpp @@ -42,14 +42,14 @@ return std::vector>(); } -SharedInstrument InstrumentManager::createInstrument(llvm::StringRef Desc, +UniqueInstrument InstrumentManager::createInstrument(llvm::StringRef Desc, llvm::StringRef Data) { - return std::make_shared(Desc, Data); + return std::make_unique(Desc, Data); } unsigned InstrumentManager::getSchedClassID( const MCInstrInfo &MCII, const MCInst &MCI, - const llvm::SmallVector &IVec) const { + const llvm::SmallVector &IVec) const { return MCII.get(MCI.getOpcode()).getSchedClass(); } diff --git a/llvm/lib/MCA/InstrBuilder.cpp b/llvm/lib/MCA/InstrBuilder.cpp --- a/llvm/lib/MCA/InstrBuilder.cpp +++ b/llvm/lib/MCA/InstrBuilder.cpp @@ -511,7 +511,7 @@ Expected InstrBuilder::createInstrDescImpl(const MCInst &MCI, - const SmallVector &IVec) { + const SmallVector &IVec) { assert(STI.getSchedModel().hasInstrSchedModel() && "Itineraries are not yet supported!"); @@ -601,7 +601,7 @@ Expected InstrBuilder::getOrCreateInstrDesc(const MCInst &MCI, - const SmallVector &IVec) { + const SmallVector &IVec) { // Cache lookup using SchedClassID from Instrumentation unsigned SchedClassID = IM.getSchedClassID(MCII, MCI, IVec); @@ -622,7 +622,7 @@ Expected> InstrBuilder::createInstruction(const MCInst &MCI, - const SmallVector &IVec) { + const SmallVector &IVec) { Expected DescOrErr = getOrCreateInstrDesc(MCI, IVec); if (!DescOrErr) return DescOrErr.takeError(); diff --git a/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.h b/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.h --- a/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.h +++ b/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.h @@ -47,13 +47,13 @@ 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 &IVec) const override; + const SmallVector &IVec) const override; }; } // namespace mca diff --git a/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.cpp b/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.cpp --- a/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.cpp +++ b/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.cpp @@ -73,7 +73,7 @@ return Type == RISCVLMULInstrument::DESC_NAME; } -SharedInstrument +UniqueInstrument RISCVInstrumentManager::createInstrument(llvm::StringRef Desc, llvm::StringRef Data) { if (Desc != RISCVLMULInstrument::DESC_NAME) { @@ -86,19 +86,19 @@ << Data << '\n'); return nullptr; } - return std::make_shared(Data); + return std::make_unique(Data); } unsigned RISCVInstrumentManager::getSchedClassID( const MCInstrInfo &MCII, const MCInst &MCI, - const llvm::SmallVector &IVec) const { + const llvm::SmallVector &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(I.get())->getLMUL(); + if ((*I)->getDesc() == RISCVLMULInstrument::DESC_NAME) { + uint8_t LMUL = static_cast((*I).get())->getLMUL(); const RISCVVInversePseudosTable::PseudoInfo *RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL); // Not a RVV instr @@ -106,7 +106,7 @@ LLVM_DEBUG( dbgs() << "RVCB: Could not find PseudoInstruction for Opcode " - << MCII.getName(Opcode) << ", LMUL=" << I->getData() + << MCII.getName(Opcode) << ", LMUL=" << (*I)->getData() << ". Ignoring instrumentation and using original SchedClassID=" << SchedClassID << '\n'); return SchedClassID; @@ -114,7 +114,7 @@ // Override using pseudo LLVM_DEBUG(dbgs() << "RVCB: Found Pseudo Instruction for Opcode " - << MCII.getName(Opcode) << ", LMUL=" << I->getData() + << MCII.getName(Opcode) << ", LMUL=" << (*I)->getData() << ". Overriding original SchedClassID=" << SchedClassID << " with " << MCII.getName(RVV->Pseudo) << '\n'); return MCII.get(RVV->Pseudo).getSchedClass(); diff --git a/llvm/tools/llvm-mca/CodeRegion.h b/llvm/tools/llvm-mca/CodeRegion.h --- a/llvm/tools/llvm-mca/CodeRegion.h +++ b/llvm/tools/llvm-mca/CodeRegion.h @@ -115,14 +115,14 @@ /// in analysis of the region. class InstrumentRegion : public CodeRegion { /// Instrument for this region. - SharedInstrument Instrument; + UniqueInstrument &Instrument; public: - InstrumentRegion(llvm::StringRef Desc, llvm::SMLoc Start, SharedInstrument I) + InstrumentRegion(llvm::StringRef Desc, llvm::SMLoc Start, UniqueInstrument &I) : CodeRegion(Desc, Start), Instrument(I) {} public: - SharedInstrument getInstrument() const { return Instrument; } + UniqueInstrument &getInstrument() const { return Instrument; } }; class CodeRegionParseError final : public Error {}; @@ -182,10 +182,10 @@ 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 + const SmallVector getActiveInstruments(llvm::SMLoc Loc) const; }; diff --git a/llvm/tools/llvm-mca/CodeRegion.cpp b/llvm/tools/llvm-mca/CodeRegion.cpp --- a/llvm/tools/llvm-mca/CodeRegion.cpp +++ b/llvm/tools/llvm-mca/CodeRegion.cpp @@ -115,7 +115,7 @@ 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"); @@ -158,13 +158,13 @@ } } -const SmallVector +const SmallVector InstrumentRegions::getActiveInstruments(SMLoc Loc) const { - SmallVector AI; + SmallVector AI; for (auto &R : Regions) { if (R->isLocInRange(Loc)) { InstrumentRegion *IR = static_cast(R.get()); - AI.emplace_back(IR->getInstrument()); + AI.emplace_back(&IR->getInstrument()); } } return AI; diff --git a/llvm/tools/llvm-mca/CodeRegionGenerator.cpp b/llvm/tools/llvm-mca/CodeRegionGenerator.cpp --- a/llvm/tools/llvm-mca/CodeRegionGenerator.cpp +++ b/llvm/tools/llvm-mca/CodeRegionGenerator.cpp @@ -184,7 +184,7 @@ 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, @@ -202,7 +202,7 @@ 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 diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -574,7 +574,7 @@ SmallVector> LoweredSequence; for (const MCInst &MCI : Insts) { SMLoc Loc = MCI.getLoc(); - const SmallVector Instruments = + const SmallVector Instruments = InstrumentRegions.getActiveInstruments(Loc); Expected> Inst =