From d93b192769f7f83dee8883b10227b7a02436e0de Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 29 Mar 2014 19:21:20 +0000 Subject: [PATCH] Detemplatize LOHDirective. The ARM64 backend uses it only as a container to keep an MCLOHType and Arguments around so give it its own little copy. The other functionality isn't used and we had a crazy method specialization hack in place to keep it working. Unfortunately that was incompatible with MSVC. Also range-ify a couple of loops while at it. llvm-svn: 205114 --- include/llvm/MC/MCLinkerOptimizationHint.h | 67 ++++++++------------- lib/MC/MCLinkerOptimizationHint.cpp | 3 - lib/Target/ARM64/ARM64AsmPrinter.cpp | 18 ++---- lib/Target/ARM64/ARM64MachineFunctionInfo.h | 29 ++++++--- 4 files changed, 49 insertions(+), 68 deletions(-) diff --git a/include/llvm/MC/MCLinkerOptimizationHint.h b/include/llvm/MC/MCLinkerOptimizationHint.h index eb37d158e40..52b46131ea5 100644 --- a/include/llvm/MC/MCLinkerOptimizationHint.h +++ b/include/llvm/MC/MCLinkerOptimizationHint.h @@ -97,30 +97,30 @@ static inline int MCLOHIdToNbArgs(MCLOHType Kind) { } /// Store Linker Optimization Hint information (LOH). -template -class LOHDirective { -private: +class MCLOHDirective { MCLOHType Kind; /// Arguments of this directive. Order matters. - SmallVector Args; + SmallVector Args; /// Emit this directive in @p OutStream using the information available /// in the given @p ObjWriter and @p Layout to get the address of the /// arguments within the object file. /// This function is currently specialized for T = MCSymbol. void Emit_impl(raw_ostream &OutStream, const MachObjectWriter &ObjWriter, - const MCAsmLayout &Layout) const { } + const MCAsmLayout &Layout) const; public: - typedef SmallVectorImpl LOHArgs; + typedef SmallVectorImpl LOHArgs; - LOHDirective(MCLOHType Kind, const LOHArgs &Args) - : Kind(Kind), Args(Args.begin(), Args.end()) {}; + MCLOHDirective(MCLOHType Kind, const LOHArgs &Args) + : Kind(Kind), Args(Args.begin(), Args.end()) { + assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!"); + } MCLOHType getKind() const { return Kind; } - const LOHArgs & getArgs() const { return Args; } + const LOHArgs &getArgs() const { return Args; } /// Emit this directive as: /// @@ -140,44 +140,35 @@ public: } }; -template -class LOHContainer { -public: - typedef SmallVectorImpl > LOHDirectives; - -private: +class MCLOHContainer { /// Keep track of the emit size of all the LOHs. mutable uint64_t EmitSize; /// Keep track of all LOH directives. - SmallVector, 32> Directives; - - /// Accessor to the directives. - LOHDirectives &getDirectives() { return Directives; } + SmallVector Directives; public: - LOHContainer() : EmitSize(0) {}; + typedef SmallVectorImpl LOHDirectives; + + MCLOHContainer() : EmitSize(0) {}; /// Const accessor to the directives. const LOHDirectives &getDirectives() const { - return const_cast(this)->getDirectives(); + return Directives; } /// Add the directive of the given kind @p Kind with the given arguments /// @p Args to the container. - void addDirective(MCLOHType Kind, - const typename LOHDirective::LOHArgs &Args) { - assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!"); - getDirectives().push_back(LOHDirective(Kind, Args)); + void addDirective(MCLOHType Kind, const MCLOHDirective::LOHArgs &Args) { + Directives.push_back(MCLOHDirective(Kind, Args)); } /// Get the size of the directives if emitted. uint64_t getEmitSize(const MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const { if (!EmitSize) { - for (typename LOHDirectives::const_iterator It = getDirectives().begin(), - EndIt = getDirectives().end(); It != EndIt; ++It) - EmitSize += It->getEmitSize(ObjWriter, Layout); + for (const MCLOHDirective &D : Directives) + EmitSize += D.getEmitSize(ObjWriter, Layout); } return EmitSize; } @@ -185,30 +176,20 @@ public: /// Emit all Linker Optimization Hint in one big table. /// Each line of the table is emitted by LOHDirective::Emit. void Emit(MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const { - for (typename LOHDirectives::const_iterator It = getDirectives().begin(), - EndIt = getDirectives().end(); It != EndIt; ++It) - It->Emit(ObjWriter, Layout); + for (const MCLOHDirective &D : Directives) + D.Emit(ObjWriter, Layout); } void reset() { - getDirectives().clear(); + Directives.clear(); EmitSize = 0; } }; // Add types for specialized template using MCSymbol. -typedef LOHDirective MCLOHDirective; -typedef LOHDirective::LOHArgs MCLOHArgs; +typedef MCLOHDirective::LOHArgs MCLOHArgs; +typedef MCLOHContainer::LOHDirectives MCLOHDirectives; -typedef LOHContainer::LOHDirectives MCLOHDirectives; - -typedef LOHContainer MCLOHContainer; - -// Declare the specialization for MCSymbol. -template<> -void MCLOHDirective::Emit_impl(raw_ostream &OutStream, - const MachObjectWriter &ObjWriter, - const MCAsmLayout &Layout) const; } // end namespace llvm #endif diff --git a/lib/MC/MCLinkerOptimizationHint.cpp b/lib/MC/MCLinkerOptimizationHint.cpp index 628a6156fd8..dceda68433e 100644 --- a/lib/MC/MCLinkerOptimizationHint.cpp +++ b/lib/MC/MCLinkerOptimizationHint.cpp @@ -14,8 +14,6 @@ using namespace llvm; -namespace llvm { -template<> void MCLOHDirective::Emit_impl(raw_ostream &OutStream, const MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const { @@ -27,4 +25,3 @@ void MCLOHDirective::Emit_impl(raw_ostream &OutStream, encodeULEB128(ObjWriter.getSymbolAddress(&Asm.getSymbolData(**It), Layout), OutStream); } -} // end namespace llvm diff --git a/lib/Target/ARM64/ARM64AsmPrinter.cpp b/lib/Target/ARM64/ARM64AsmPrinter.cpp index d01108d259d..d0aa6af9c0c 100644 --- a/lib/Target/ARM64/ARM64AsmPrinter.cpp +++ b/lib/Target/ARM64/ARM64AsmPrinter.cpp @@ -135,26 +135,16 @@ ARM64AsmPrinter::getDebugValueLocation(const MachineInstr *MI) const { } void ARM64AsmPrinter::EmitLOHs() { - const ARM64FunctionInfo::MILOHDirectives &LOHs = - const_cast(ARM64FI) - ->getLOHContainer() - .getDirectives(); SmallVector MCArgs; - for (ARM64FunctionInfo::MILOHDirectives::const_iterator It = LOHs.begin(), - EndIt = LOHs.end(); - It != EndIt; ++It) { - const ARM64FunctionInfo::MILOHArgs &MIArgs = It->getArgs(); - for (ARM64FunctionInfo::MILOHArgs::const_iterator - MIArgsIt = MIArgs.begin(), - EndMIArgsIt = MIArgs.end(); - MIArgsIt != EndMIArgsIt; ++MIArgsIt) { - MInstToMCSymbol::iterator LabelIt = LOHInstToLabel.find(*MIArgsIt); + for (const auto &D : ARM64FI->getLOHContainer()) { + for (const MachineInstr *MI : D.getArgs()) { + MInstToMCSymbol::iterator LabelIt = LOHInstToLabel.find(MI); assert(LabelIt != LOHInstToLabel.end() && "Label hasn't been inserted for LOH related instruction"); MCArgs.push_back(LabelIt->second); } - OutStreamer.EmitLOHDirective(It->getKind(), MCArgs); + OutStreamer.EmitLOHDirective(D.getKind(), MCArgs); MCArgs.clear(); } } diff --git a/lib/Target/ARM64/ARM64MachineFunctionInfo.h b/lib/Target/ARM64/ARM64MachineFunctionInfo.h index 59538ea40e9..02bf7cf6fd0 100644 --- a/lib/Target/ARM64/ARM64MachineFunctionInfo.h +++ b/lib/Target/ARM64/ARM64MachineFunctionInfo.h @@ -100,20 +100,33 @@ public: const SetOfInstructions &getLOHRelated() const { return LOHRelated; } // Shortcuts for LOH related types. - typedef LOHDirective MILOHDirective; - typedef MILOHDirective::LOHArgs MILOHArgs; + class MILOHDirective { + MCLOHType Kind; - typedef LOHContainer MILOHContainer; - typedef MILOHContainer::LOHDirectives MILOHDirectives; + /// Arguments of this directive. Order matters. + SmallVector Args; + + public: + typedef SmallVectorImpl LOHArgs; + + MILOHDirective(MCLOHType Kind, const LOHArgs &Args) + : Kind(Kind), Args(Args.begin(), Args.end()) { + assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!"); + } + + MCLOHType getKind() const { return Kind; } + const LOHArgs &getArgs() const { return Args; } + }; + + typedef MILOHDirective::LOHArgs MILOHArgs; + typedef SmallVector MILOHContainer; const MILOHContainer &getLOHContainer() const { return LOHContainerSet; } /// Add a LOH directive of this @p Kind and this @p Args. void addLOHDirective(MCLOHType Kind, const MILOHArgs &Args) { - LOHContainerSet.addDirective(Kind, Args); - for (MILOHArgs::const_iterator It = Args.begin(), EndIt = Args.end(); - It != EndIt; ++It) - LOHRelated.insert(*It); + LOHContainerSet.push_back(MILOHDirective(Kind, Args)); + LOHRelated.insert(Args.begin(), Args.end()); } private: