From 8665715bdd6c1e02832e93137ce88eed22184153 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 25 Nov 2014 06:11:24 +0000 Subject: [PATCH] Style fix: don't indent inside a namemespace. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222729 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 237 +++++++++++++++++++------------------ 1 file changed, 119 insertions(+), 118 deletions(-) diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index aa0f961e3da..037b1b86453 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -364,147 +364,148 @@ Type *TypeMapTy::getImpl(Type *Ty) { //===----------------------------------------------------------------------===// namespace { - class ModuleLinker; - - /// Creates prototypes for functions that are lazily linked on the fly. This - /// speeds up linking for modules with many/ lazily linked functions of which - /// few get used. - class ValueMaterializerTy : public ValueMaterializer { - TypeMapTy &TypeMap; - Module *DstM; - std::vector &LazilyLinkFunctions; - public: - ValueMaterializerTy(TypeMapTy &TypeMap, Module *DstM, - std::vector &LazilyLinkFunctions) : - ValueMaterializer(), TypeMap(TypeMap), DstM(DstM), - LazilyLinkFunctions(LazilyLinkFunctions) { - } +class ModuleLinker; - Value *materializeValueFor(Value *V) override; - }; +/// Creates prototypes for functions that are lazily linked on the fly. This +/// speeds up linking for modules with many/ lazily linked functions of which +/// few get used. +class ValueMaterializerTy : public ValueMaterializer { + TypeMapTy &TypeMap; + Module *DstM; + std::vector &LazilyLinkFunctions; - class LinkDiagnosticInfo : public DiagnosticInfo { - const Twine &Msg; +public: + ValueMaterializerTy(TypeMapTy &TypeMap, Module *DstM, + std::vector &LazilyLinkFunctions) + : ValueMaterializer(), TypeMap(TypeMap), DstM(DstM), + LazilyLinkFunctions(LazilyLinkFunctions) {} - public: - LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg); - void print(DiagnosticPrinter &DP) const override; - }; - LinkDiagnosticInfo::LinkDiagnosticInfo(DiagnosticSeverity Severity, - const Twine &Msg) - : DiagnosticInfo(DK_Linker, Severity), Msg(Msg) {} - void LinkDiagnosticInfo::print(DiagnosticPrinter &DP) const { DP << Msg; } + Value *materializeValueFor(Value *V) override; +}; - /// This is an implementation class for the LinkModules function, which is the - /// entrypoint for this file. - class ModuleLinker { - Module *DstM, *SrcM; +class LinkDiagnosticInfo : public DiagnosticInfo { + const Twine &Msg; - TypeMapTy TypeMap; - ValueMaterializerTy ValMaterializer; +public: + LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg); + void print(DiagnosticPrinter &DP) const override; +}; +LinkDiagnosticInfo::LinkDiagnosticInfo(DiagnosticSeverity Severity, + const Twine &Msg) + : DiagnosticInfo(DK_Linker, Severity), Msg(Msg) {} +void LinkDiagnosticInfo::print(DiagnosticPrinter &DP) const { DP << Msg; } + +/// This is an implementation class for the LinkModules function, which is the +/// entrypoint for this file. +class ModuleLinker { + Module *DstM, *SrcM; + + TypeMapTy TypeMap; + ValueMaterializerTy ValMaterializer; + + /// Mapping of values from what they used to be in Src, to what they are now + /// in DstM. ValueToValueMapTy is a ValueMap, which involves some overhead + /// due to the use of Value handles which the Linker doesn't actually need, + /// but this allows us to reuse the ValueMapper code. + ValueToValueMapTy ValueMap; + + struct AppendingVarInfo { + GlobalVariable *NewGV; // New aggregate global in dest module. + const Constant *DstInit; // Old initializer from dest module. + const Constant *SrcInit; // Old initializer from src module. + }; - /// Mapping of values from what they used to be in Src, to what they are now - /// in DstM. ValueToValueMapTy is a ValueMap, which involves some overhead - /// due to the use of Value handles which the Linker doesn't actually need, - /// but this allows us to reuse the ValueMapper code. - ValueToValueMapTy ValueMap; + std::vector AppendingVars; - struct AppendingVarInfo { - GlobalVariable *NewGV; // New aggregate global in dest module. - const Constant *DstInit; // Old initializer from dest module. - const Constant *SrcInit; // Old initializer from src module. - }; + // Set of items not to link in from source. + SmallPtrSet DoNotLinkFromSource; - std::vector AppendingVars; + // Vector of functions to lazily link in. + std::vector LazilyLinkFunctions; - // Set of items not to link in from source. - SmallPtrSet DoNotLinkFromSource; + Linker::DiagnosticHandlerFunction DiagnosticHandler; - // Vector of functions to lazily link in. - std::vector LazilyLinkFunctions; +public: + ModuleLinker(Module *dstM, TypeSet &Set, Module *srcM, + Linker::DiagnosticHandlerFunction DiagnosticHandler) + : DstM(dstM), SrcM(srcM), TypeMap(Set), + ValMaterializer(TypeMap, DstM, LazilyLinkFunctions), + DiagnosticHandler(DiagnosticHandler) {} - Linker::DiagnosticHandlerFunction DiagnosticHandler; + bool run(); - public: - ModuleLinker(Module *dstM, TypeSet &Set, Module *srcM, - Linker::DiagnosticHandlerFunction DiagnosticHandler) - : DstM(dstM), SrcM(srcM), TypeMap(Set), - ValMaterializer(TypeMap, DstM, LazilyLinkFunctions), - DiagnosticHandler(DiagnosticHandler) {} +private: + bool shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest, + const GlobalValue &Src); - bool run(); + /// Helper method for setting a message and returning an error code. + bool emitError(const Twine &Message) { + DiagnosticHandler(LinkDiagnosticInfo(DS_Error, Message)); + return true; + } - private: - bool shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest, - const GlobalValue &Src); + void emitWarning(const Twine &Message) { + DiagnosticHandler(LinkDiagnosticInfo(DS_Warning, Message)); + } - /// Helper method for setting a message and returning an error code. - bool emitError(const Twine &Message) { - DiagnosticHandler(LinkDiagnosticInfo(DS_Error, Message)); - return true; - } + bool getComdatLeader(Module *M, StringRef ComdatName, + const GlobalVariable *&GVar); + bool computeResultingSelectionKind(StringRef ComdatName, + Comdat::SelectionKind Src, + Comdat::SelectionKind Dst, + Comdat::SelectionKind &Result, + bool &LinkFromSrc); + std::map> + ComdatsChosen; + bool getComdatResult(const Comdat *SrcC, Comdat::SelectionKind &SK, + bool &LinkFromSrc); + + /// Given a global in the source module, return the global in the + /// destination module that is being linked to, if any. + GlobalValue *getLinkedToGlobal(const GlobalValue *SrcGV) { + // If the source has no name it can't link. If it has local linkage, + // there is no name match-up going on. + if (!SrcGV->hasName() || SrcGV->hasLocalLinkage()) + return nullptr; + + // Otherwise see if we have a match in the destination module's symtab. + GlobalValue *DGV = DstM->getNamedValue(SrcGV->getName()); + if (!DGV) + return nullptr; - void emitWarning(const Twine &Message) { - DiagnosticHandler(LinkDiagnosticInfo(DS_Warning, Message)); - } + // If we found a global with the same name in the dest module, but it has + // internal linkage, we are really not doing any linkage here. + if (DGV->hasLocalLinkage()) + return nullptr; - bool getComdatLeader(Module *M, StringRef ComdatName, - const GlobalVariable *&GVar); - bool computeResultingSelectionKind(StringRef ComdatName, - Comdat::SelectionKind Src, - Comdat::SelectionKind Dst, - Comdat::SelectionKind &Result, - bool &LinkFromSrc); - std::map> - ComdatsChosen; - bool getComdatResult(const Comdat *SrcC, Comdat::SelectionKind &SK, - bool &LinkFromSrc); - - /// Given a global in the source module, return the global in the - /// destination module that is being linked to, if any. - GlobalValue *getLinkedToGlobal(const GlobalValue *SrcGV) { - // If the source has no name it can't link. If it has local linkage, - // there is no name match-up going on. - if (!SrcGV->hasName() || SrcGV->hasLocalLinkage()) - return nullptr; - - // Otherwise see if we have a match in the destination module's symtab. - GlobalValue *DGV = DstM->getNamedValue(SrcGV->getName()); - if (!DGV) return nullptr; - - // If we found a global with the same name in the dest module, but it has - // internal linkage, we are really not doing any linkage here. - if (DGV->hasLocalLinkage()) - return nullptr; - - // Otherwise, we do in fact link to the destination global. - return DGV; - } + // Otherwise, we do in fact link to the destination global. + return DGV; + } - void computeTypeMapping(); + void computeTypeMapping(); - void upgradeMismatchedGlobalArray(StringRef Name); - void upgradeMismatchedGlobals(); + void upgradeMismatchedGlobalArray(StringRef Name); + void upgradeMismatchedGlobals(); - bool linkAppendingVarProto(GlobalVariable *DstGV, - const GlobalVariable *SrcGV); + bool linkAppendingVarProto(GlobalVariable *DstGV, + const GlobalVariable *SrcGV); - bool linkGlobalValueProto(GlobalValue *GV); - GlobalValue *linkGlobalVariableProto(const GlobalVariable *SGVar, - GlobalValue *DGV, bool LinkFromSrc); - GlobalValue *linkFunctionProto(const Function *SF, GlobalValue *DGV, - bool LinkFromSrc); - GlobalValue *linkGlobalAliasProto(const GlobalAlias *SGA, GlobalValue *DGV, - bool LinkFromSrc); + bool linkGlobalValueProto(GlobalValue *GV); + GlobalValue *linkGlobalVariableProto(const GlobalVariable *SGVar, + GlobalValue *DGV, bool LinkFromSrc); + GlobalValue *linkFunctionProto(const Function *SF, GlobalValue *DGV, + bool LinkFromSrc); + GlobalValue *linkGlobalAliasProto(const GlobalAlias *SGA, GlobalValue *DGV, + bool LinkFromSrc); - bool linkModuleFlagsMetadata(); + bool linkModuleFlagsMetadata(); - void linkAppendingVarInit(const AppendingVarInfo &AVI); - void linkGlobalInits(); - void linkFunctionBody(Function *Dst, Function *Src); - void linkAliasBodies(); - void linkNamedMDNodes(); - }; + void linkAppendingVarInit(const AppendingVarInfo &AVI); + void linkGlobalInits(); + void linkFunctionBody(Function *Dst, Function *Src); + void linkAliasBodies(); + void linkNamedMDNodes(); +}; } /// The LLVM SymbolTable class autorenames globals that conflict in the symbol -- 2.34.1