1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

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
This commit is contained in:
Benjamin Kramer 2014-03-29 19:21:20 +00:00
parent 7263b8300e
commit d93b192769
4 changed files with 49 additions and 68 deletions

View File

@ -97,30 +97,30 @@ static inline int MCLOHIdToNbArgs(MCLOHType Kind) {
} }
/// Store Linker Optimization Hint information (LOH). /// Store Linker Optimization Hint information (LOH).
template<typename T> class MCLOHDirective {
class LOHDirective {
private:
MCLOHType Kind; MCLOHType Kind;
/// Arguments of this directive. Order matters. /// Arguments of this directive. Order matters.
SmallVector<T *, 3> Args; SmallVector<MCSymbol *, 3> Args;
/// Emit this directive in @p OutStream using the information available /// Emit this directive in @p OutStream using the information available
/// in the given @p ObjWriter and @p Layout to get the address of the /// in the given @p ObjWriter and @p Layout to get the address of the
/// arguments within the object file. /// arguments within the object file.
/// This function is currently specialized for T = MCSymbol. /// This function is currently specialized for T = MCSymbol.
void Emit_impl(raw_ostream &OutStream, const MachObjectWriter &ObjWriter, void Emit_impl(raw_ostream &OutStream, const MachObjectWriter &ObjWriter,
const MCAsmLayout &Layout) const { } const MCAsmLayout &Layout) const;
public: public:
typedef SmallVectorImpl<T *> LOHArgs; typedef SmallVectorImpl<MCSymbol *> LOHArgs;
LOHDirective(MCLOHType Kind, const LOHArgs &Args) MCLOHDirective(MCLOHType Kind, const LOHArgs &Args)
: Kind(Kind), Args(Args.begin(), Args.end()) {}; : Kind(Kind), Args(Args.begin(), Args.end()) {
assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
}
MCLOHType getKind() const { return Kind; } MCLOHType getKind() const { return Kind; }
const LOHArgs & getArgs() const { return Args; } const LOHArgs &getArgs() const { return Args; }
/// Emit this directive as: /// Emit this directive as:
/// <kind, numArgs, addr1, ..., addrN> /// <kind, numArgs, addr1, ..., addrN>
@ -140,44 +140,35 @@ public:
} }
}; };
template<typename T> class MCLOHContainer {
class LOHContainer {
public:
typedef SmallVectorImpl<LOHDirective<T> > LOHDirectives;
private:
/// Keep track of the emit size of all the LOHs. /// Keep track of the emit size of all the LOHs.
mutable uint64_t EmitSize; mutable uint64_t EmitSize;
/// Keep track of all LOH directives. /// Keep track of all LOH directives.
SmallVector<LOHDirective<T>, 32> Directives; SmallVector<MCLOHDirective, 32> Directives;
/// Accessor to the directives.
LOHDirectives &getDirectives() { return Directives; }
public: public:
LOHContainer() : EmitSize(0) {}; typedef SmallVectorImpl<MCLOHDirective> LOHDirectives;
MCLOHContainer() : EmitSize(0) {};
/// Const accessor to the directives. /// Const accessor to the directives.
const LOHDirectives &getDirectives() const { const LOHDirectives &getDirectives() const {
return const_cast<LOHContainer *>(this)->getDirectives(); return Directives;
} }
/// Add the directive of the given kind @p Kind with the given arguments /// Add the directive of the given kind @p Kind with the given arguments
/// @p Args to the container. /// @p Args to the container.
void addDirective(MCLOHType Kind, void addDirective(MCLOHType Kind, const MCLOHDirective::LOHArgs &Args) {
const typename LOHDirective<T>::LOHArgs &Args) { Directives.push_back(MCLOHDirective(Kind, Args));
assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
getDirectives().push_back(LOHDirective<T>(Kind, Args));
} }
/// Get the size of the directives if emitted. /// Get the size of the directives if emitted.
uint64_t getEmitSize(const MachObjectWriter &ObjWriter, uint64_t getEmitSize(const MachObjectWriter &ObjWriter,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
if (!EmitSize) { if (!EmitSize) {
for (typename LOHDirectives::const_iterator It = getDirectives().begin(), for (const MCLOHDirective &D : Directives)
EndIt = getDirectives().end(); It != EndIt; ++It) EmitSize += D.getEmitSize(ObjWriter, Layout);
EmitSize += It->getEmitSize(ObjWriter, Layout);
} }
return EmitSize; return EmitSize;
} }
@ -185,30 +176,20 @@ public:
/// Emit all Linker Optimization Hint in one big table. /// Emit all Linker Optimization Hint in one big table.
/// Each line of the table is emitted by LOHDirective::Emit. /// Each line of the table is emitted by LOHDirective::Emit.
void Emit(MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const { void Emit(MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const {
for (typename LOHDirectives::const_iterator It = getDirectives().begin(), for (const MCLOHDirective &D : Directives)
EndIt = getDirectives().end(); It != EndIt; ++It) D.Emit(ObjWriter, Layout);
It->Emit(ObjWriter, Layout);
} }
void reset() { void reset() {
getDirectives().clear(); Directives.clear();
EmitSize = 0; EmitSize = 0;
} }
}; };
// Add types for specialized template using MCSymbol. // Add types for specialized template using MCSymbol.
typedef LOHDirective<MCSymbol> MCLOHDirective; typedef MCLOHDirective::LOHArgs MCLOHArgs;
typedef LOHDirective<MCSymbol>::LOHArgs MCLOHArgs; typedef MCLOHContainer::LOHDirectives MCLOHDirectives;
typedef LOHContainer<MCLOHDirective>::LOHDirectives MCLOHDirectives;
typedef LOHContainer<MCSymbol> MCLOHContainer;
// Declare the specialization for MCSymbol.
template<>
void MCLOHDirective::Emit_impl(raw_ostream &OutStream,
const MachObjectWriter &ObjWriter,
const MCAsmLayout &Layout) const;
} // end namespace llvm } // end namespace llvm
#endif #endif

View File

@ -14,8 +14,6 @@
using namespace llvm; using namespace llvm;
namespace llvm {
template<>
void MCLOHDirective::Emit_impl(raw_ostream &OutStream, void MCLOHDirective::Emit_impl(raw_ostream &OutStream,
const MachObjectWriter &ObjWriter, const MachObjectWriter &ObjWriter,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
@ -27,4 +25,3 @@ void MCLOHDirective::Emit_impl(raw_ostream &OutStream,
encodeULEB128(ObjWriter.getSymbolAddress(&Asm.getSymbolData(**It), Layout), encodeULEB128(ObjWriter.getSymbolAddress(&Asm.getSymbolData(**It), Layout),
OutStream); OutStream);
} }
} // end namespace llvm

View File

@ -135,26 +135,16 @@ ARM64AsmPrinter::getDebugValueLocation(const MachineInstr *MI) const {
} }
void ARM64AsmPrinter::EmitLOHs() { void ARM64AsmPrinter::EmitLOHs() {
const ARM64FunctionInfo::MILOHDirectives &LOHs =
const_cast<const ARM64FunctionInfo *>(ARM64FI)
->getLOHContainer()
.getDirectives();
SmallVector<MCSymbol *, 3> MCArgs; SmallVector<MCSymbol *, 3> MCArgs;
for (ARM64FunctionInfo::MILOHDirectives::const_iterator It = LOHs.begin(), for (const auto &D : ARM64FI->getLOHContainer()) {
EndIt = LOHs.end(); for (const MachineInstr *MI : D.getArgs()) {
It != EndIt; ++It) { MInstToMCSymbol::iterator LabelIt = LOHInstToLabel.find(MI);
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);
assert(LabelIt != LOHInstToLabel.end() && assert(LabelIt != LOHInstToLabel.end() &&
"Label hasn't been inserted for LOH related instruction"); "Label hasn't been inserted for LOH related instruction");
MCArgs.push_back(LabelIt->second); MCArgs.push_back(LabelIt->second);
} }
OutStreamer.EmitLOHDirective(It->getKind(), MCArgs); OutStreamer.EmitLOHDirective(D.getKind(), MCArgs);
MCArgs.clear(); MCArgs.clear();
} }
} }

View File

@ -100,20 +100,33 @@ public:
const SetOfInstructions &getLOHRelated() const { return LOHRelated; } const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
// Shortcuts for LOH related types. // Shortcuts for LOH related types.
typedef LOHDirective<const MachineInstr> MILOHDirective; class MILOHDirective {
typedef MILOHDirective::LOHArgs MILOHArgs; MCLOHType Kind;
typedef LOHContainer<const MachineInstr> MILOHContainer; /// Arguments of this directive. Order matters.
typedef MILOHContainer::LOHDirectives MILOHDirectives; SmallVector<const MachineInstr *, 3> Args;
public:
typedef SmallVectorImpl<const MachineInstr *> 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<MILOHDirective, 32> MILOHContainer;
const MILOHContainer &getLOHContainer() const { return LOHContainerSet; } const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
/// Add a LOH directive of this @p Kind and this @p Args. /// Add a LOH directive of this @p Kind and this @p Args.
void addLOHDirective(MCLOHType Kind, const MILOHArgs &Args) { void addLOHDirective(MCLOHType Kind, const MILOHArgs &Args) {
LOHContainerSet.addDirective(Kind, Args); LOHContainerSet.push_back(MILOHDirective(Kind, Args));
for (MILOHArgs::const_iterator It = Args.begin(), EndIt = Args.end(); LOHRelated.insert(Args.begin(), Args.end());
It != EndIt; ++It)
LOHRelated.insert(*It);
} }
private: private: