diff options
author | Colin LeMahieu <colinl@codeaurora.org> | 2015-11-13 21:45:50 +0000 |
---|---|---|
committer | Colin LeMahieu <colinl@codeaurora.org> | 2015-11-13 21:45:50 +0000 |
commit | 655489433c336d78685e5a4f302b480a2ff3d89c (patch) | |
tree | a962e7fe81771e7470b10c00c0eb0685992f9542 /llvm/lib | |
parent | c26332abbd75f926d24078f13a33ccb235edde41 (diff) | |
download | bcm5719-llvm-655489433c336d78685e5a4f302b480a2ff3d89c.tar.gz bcm5719-llvm-655489433c336d78685e5a4f302b480a2ff3d89c.zip |
[Hexagon] Fixing memory leak during relaxation by allocating MCInst in MCContext.
llvm-svn: 253090
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp index b97d616eb49..2f3521bfd71 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp @@ -14,9 +14,11 @@ #include "MCTargetDesc/HexagonMCInstrInfo.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAssembler.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/MC/MCFixupKindInfo.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCAsmLayout.h" #include "llvm/Support/Debug.h" #include "llvm/Support/TargetRegistry.h" @@ -33,14 +35,28 @@ class HexagonAsmBackend : public MCAsmBackend { mutable uint64_t relaxedCnt; std::unique_ptr <MCInstrInfo> MCII; std::unique_ptr <MCInst *> RelaxTarget; + MCInst * Extender; public: 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 { 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 { return Hexagon::NumTargetFixupKinds; } @@ -222,6 +238,7 @@ public: if (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_SIZE) { ++relaxedCnt; *RelaxTarget = &MCI; + setExtender(Layout.getAssembler().getContext()); return true; } else { return false; @@ -262,6 +279,7 @@ public: if (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_SIZE) { ++relaxedCnt; *RelaxTarget = &MCI; + setExtender(Layout.getAssembler().getContext()); return true; } } @@ -293,11 +311,10 @@ public: assert((HexagonMCInstrInfo::bundleSize(Res) < HEXAGON_PACKET_SIZE) && "No room to insert extender for relaxation"); - MCInst *HMIx = - new MCInst(HexagonMCInstrInfo::deriveExtender( + MCInst *HMIx = takeExtender(); + *HMIx = HexagonMCInstrInfo::deriveExtender( *MCII, CrntHMI, - HexagonMCInstrInfo::getExtendableOperand(*MCII, CrntHMI))); - + HexagonMCInstrInfo::getExtendableOperand(*MCII, CrntHMI)); Res.addOperand(MCOperand::createInst(HMIx)); *RelaxTarget = nullptr; } |