forked from OSchip/llvm-project
[Hexagon] Fixing memory leak during relaxation by allocating MCInst in MCContext.
llvm-svn: 253090
This commit is contained in:
parent
c26332abbd
commit
655489433c
|
|
@ -14,9 +14,11 @@
|
||||||
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
||||||
#include "llvm/MC/MCAsmBackend.h"
|
#include "llvm/MC/MCAsmBackend.h"
|
||||||
#include "llvm/MC/MCAssembler.h"
|
#include "llvm/MC/MCAssembler.h"
|
||||||
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCELFObjectWriter.h"
|
#include "llvm/MC/MCELFObjectWriter.h"
|
||||||
#include "llvm/MC/MCFixupKindInfo.h"
|
#include "llvm/MC/MCFixupKindInfo.h"
|
||||||
#include "llvm/MC/MCInstrInfo.h"
|
#include "llvm/MC/MCInstrInfo.h"
|
||||||
|
#include "llvm/MC/MCAsmLayout.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/TargetRegistry.h"
|
#include "llvm/Support/TargetRegistry.h"
|
||||||
|
|
||||||
|
|
@ -33,14 +35,28 @@ class HexagonAsmBackend : public MCAsmBackend {
|
||||||
mutable uint64_t relaxedCnt;
|
mutable uint64_t relaxedCnt;
|
||||||
std::unique_ptr <MCInstrInfo> MCII;
|
std::unique_ptr <MCInstrInfo> MCII;
|
||||||
std::unique_ptr <MCInst *> RelaxTarget;
|
std::unique_ptr <MCInst *> RelaxTarget;
|
||||||
|
MCInst * Extender;
|
||||||
public:
|
public:
|
||||||
HexagonAsmBackend(Target const &T, uint8_t OSABI, StringRef CPU) :
|
HexagonAsmBackend(Target const &T, uint8_t OSABI, StringRef CPU) :
|
||||||
OSABI(OSABI), MCII (T.createMCInstrInfo()), RelaxTarget(new MCInst *){}
|
OSABI(OSABI), MCII (T.createMCInstrInfo()), RelaxTarget(new MCInst *),
|
||||||
|
Extender(nullptr) {}
|
||||||
|
|
||||||
MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override {
|
MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override {
|
||||||
return createHexagonELFObjectWriter(OS, OSABI, CPU);
|
return createHexagonELFObjectWriter(OS, OSABI, CPU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setExtender(MCContext &Context) const {
|
||||||
|
if (Extender == nullptr)
|
||||||
|
const_cast<HexagonAsmBackend *>(this)->Extender = new (Context) MCInst;
|
||||||
|
}
|
||||||
|
|
||||||
|
MCInst *takeExtender() const {
|
||||||
|
assert(Extender != nullptr);
|
||||||
|
MCInst * Result = Extender;
|
||||||
|
const_cast<HexagonAsmBackend *>(this)->Extender = nullptr;
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned getNumFixupKinds() const override {
|
unsigned getNumFixupKinds() const override {
|
||||||
return Hexagon::NumTargetFixupKinds;
|
return Hexagon::NumTargetFixupKinds;
|
||||||
}
|
}
|
||||||
|
|
@ -222,6 +238,7 @@ public:
|
||||||
if (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_SIZE) {
|
if (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_SIZE) {
|
||||||
++relaxedCnt;
|
++relaxedCnt;
|
||||||
*RelaxTarget = &MCI;
|
*RelaxTarget = &MCI;
|
||||||
|
setExtender(Layout.getAssembler().getContext());
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -262,6 +279,7 @@ public:
|
||||||
if (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_SIZE) {
|
if (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_SIZE) {
|
||||||
++relaxedCnt;
|
++relaxedCnt;
|
||||||
*RelaxTarget = &MCI;
|
*RelaxTarget = &MCI;
|
||||||
|
setExtender(Layout.getAssembler().getContext());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -293,11 +311,10 @@ public:
|
||||||
assert((HexagonMCInstrInfo::bundleSize(Res) < HEXAGON_PACKET_SIZE) &&
|
assert((HexagonMCInstrInfo::bundleSize(Res) < HEXAGON_PACKET_SIZE) &&
|
||||||
"No room to insert extender for relaxation");
|
"No room to insert extender for relaxation");
|
||||||
|
|
||||||
MCInst *HMIx =
|
MCInst *HMIx = takeExtender();
|
||||||
new MCInst(HexagonMCInstrInfo::deriveExtender(
|
*HMIx = HexagonMCInstrInfo::deriveExtender(
|
||||||
*MCII, CrntHMI,
|
*MCII, CrntHMI,
|
||||||
HexagonMCInstrInfo::getExtendableOperand(*MCII, CrntHMI)));
|
HexagonMCInstrInfo::getExtendableOperand(*MCII, CrntHMI));
|
||||||
|
|
||||||
Res.addOperand(MCOperand::createInst(HMIx));
|
Res.addOperand(MCOperand::createInst(HMIx));
|
||||||
*RelaxTarget = nullptr;
|
*RelaxTarget = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue