[llvm] r266564 - Keep only the splitCodegen version that takes a factory.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 17 12:03:40 PDT 2016


On Sun, Apr 17, 2016 at 11:42 AM, Rafael Espindola via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: rafael
> Date: Sun Apr 17 13:42:27 2016
> New Revision: 266564
>
> URL: http://llvm.org/viewvc/llvm-project?rev=266564&view=rev
> Log:
> Keep only the splitCodegen version that takes a factory.
>
> This makes it much easier to see that all created TargetMachines are
> equivalent.
>

Thanks!

> Modified:
>     llvm/trunk/include/llvm/CodeGen/ParallelCG.h
>     llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
>     llvm/trunk/lib/CodeGen/ParallelCG.cpp
>     llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
>     llvm/trunk/tools/gold/gold-plugin.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/ParallelCG.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ParallelCG.h?rev=266564&r1=266563&r2=266564&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/ParallelCG.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/ParallelCG.h Sun Apr 17 13:42:27 2016
> @@ -26,31 +26,17 @@ class Module;
>  class TargetOptions;
>  class raw_pwrite_stream;
>
> -/// Split M into OSs.size() partitions, and generate code for each. Writes
> -/// OSs.size() output files to the output streams in OSs. The resulting output
> -/// files if linked together are intended to be equivalent to the single output
> -/// file that would have been code generated from M.
> +/// Split M into OSs.size() partitions, and generate code for each. Takes a
> +/// factory function for the TargetMachine TMFactory. Writes OSs.size() output
> +/// files to the output streams in OSs. The resulting output files if linked
> +/// together are intended to be equivalent to the single output file that would
> +/// have been code generated from M.
>  ///
>  /// Writes bitcode for individual partitions into output streams in BCOSs, if
>  /// BCOSs is not empty.
>  ///
>  /// \returns M if OSs.size() == 1, otherwise returns std::unique_ptr<Module>().
>  std::unique_ptr<Module>
> -splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
> -             ArrayRef<llvm::raw_pwrite_stream *> BCOSs, StringRef CPU,
> -             StringRef Features, const TargetOptions &Options,
> -             Reloc::Model RM = Reloc::Default,
> -             CodeModel::Model CM = CodeModel::Default,
> -             CodeGenOpt::Level OL = CodeGenOpt::Default,
> -             TargetMachine::CodeGenFileType FT = TargetMachine::CGFT_ObjectFile,
> -             bool PreserveLocals = false);
> -
> -/// Split M into OSs.size() partitions, and generate code for each.
> -/// It is a variant that takes a factory function for the TargetMachine
> -/// TMFactory. See the other splitCodeGen() for a more detailed description.
> -///
> -/// \returns M if OSs.size() == 1, otherwise returns std::unique_ptr<Module>().
> -std::unique_ptr<Module>
>  splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
>               ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
>               const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
>
> Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=266564&r1=266563&r2=266564&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
> +++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Sun Apr 17 13:42:27 2016
> @@ -175,6 +175,7 @@ private:
>    void restoreLinkageForExternals();
>    void applyScopeRestrictions();
>    bool determineTarget();
> +  std::unique_ptr<TargetMachine> createTargetMachine();
>
>    static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context);
>
> @@ -199,6 +200,8 @@ private:
>    std::string NativeObjectPath;
>    TargetOptions Options;
>    CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
> +  const Target *MArch = nullptr;
> +  std::string TripleStr;
>    unsigned OptLevel = 2;
>    lto_diagnostic_handler_t DiagHandler = nullptr;
>    void *DiagContext = nullptr;
>
> Modified: llvm/trunk/lib/CodeGen/ParallelCG.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ParallelCG.cpp?rev=266564&r1=266563&r2=266564&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/ParallelCG.cpp (original)
> +++ llvm/trunk/lib/CodeGen/ParallelCG.cpp Sun Apr 17 13:42:27 2016
> @@ -36,25 +36,6 @@ codegen(Module *M, llvm::raw_pwrite_stre
>    CodeGenPasses.run(*M);
>  }
>
> -std::unique_ptr<Module>
> -llvm::splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
> -                   ArrayRef<llvm::raw_pwrite_stream *> BCOSs, StringRef CPU,
> -                   StringRef Features, const TargetOptions &Options,
> -                   Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL,
> -                   TargetMachine::CodeGenFileType FileType,
> -                   bool PreserveLocals) {
> -  std::string TripleStr = M->getTargetTriple();
> -  std::string ErrMsg;
> -
> -  const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
> -  if (!TheTarget)
> -    report_fatal_error(Twine("Target not found: ") + ErrMsg);
> -  return splitCodeGen(std::move(M), OSs, BCOSs, [&]() {
> -    return std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
> -        TripleStr, CPU, Features, Options, RM, CM, OL));
> -  }, FileType, PreserveLocals);
> -}
> -
>  std::unique_ptr<Module> llvm::splitCodeGen(
>      std::unique_ptr<Module> M, ArrayRef<llvm::raw_pwrite_stream *> OSs,
>      ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
>
> Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=266564&r1=266563&r2=266564&view=diff
> ==============================================================================
> --- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
> +++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Sun Apr 17 13:42:27 2016
> @@ -299,7 +299,7 @@ bool LTOCodeGenerator::determineTarget()
>    if (TargetMach)
>      return true;
>
> -  std::string TripleStr = MergedModule->getTargetTriple();
> +  TripleStr = MergedModule->getTargetTriple();
>    if (TripleStr.empty()) {
>      TripleStr = sys::getDefaultTargetTriple();
>      MergedModule->setTargetTriple(TripleStr);
> @@ -308,8 +308,8 @@ bool LTOCodeGenerator::determineTarget()
>
>    // create target machine from info for merged modules
>    std::string ErrMsg;
> -  const Target *march = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
> -  if (!march) {
> +  MArch = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
> +  if (!MArch) {
>      emitError(ErrMsg);
>      return false;
>    }
> @@ -329,12 +329,16 @@ bool LTOCodeGenerator::determineTarget()
>        MCpu = "cyclone";
>    }
>
> -  TargetMach.reset(march->createTargetMachine(TripleStr, MCpu, FeatureStr,
> -                                              Options, RelocModel,
> -                                              CodeModel::Default, CGOptLevel));
> +  TargetMach = createTargetMachine();
>    return true;
>  }
>
> +std::unique_ptr<TargetMachine> LTOCodeGenerator::createTargetMachine() {
> +  return std::unique_ptr<TargetMachine>(
> +      MArch->createTargetMachine(TripleStr, MCpu, FeatureStr, Options,
> +                                 RelocModel, CodeModel::Default, CGOptLevel));
> +}
> +
>  void LTOCodeGenerator::applyScopeRestrictions() {
>    if (ScopeRestrictionsDone || !ShouldInternalize)
>      return;
> @@ -473,9 +477,9 @@ bool LTOCodeGenerator::compileOptimized(
>    // parallelism level 1. This is achieved by having splitCodeGen return the
>    // original module at parallelism level 1 which we then assign back to
>    // MergedModule.
> -  MergedModule = splitCodeGen(
> -      std::move(MergedModule), Out, {}, MCpu, FeatureStr, Options, RelocModel,
> -      CodeModel::Default, CGOptLevel, FileType, ShouldRestoreGlobalsLinkage);
> +  MergedModule = splitCodeGen(std::move(MergedModule), Out, {},
> +                              [&]() { return createTargetMachine(); }, FileType,
> +                              ShouldRestoreGlobalsLinkage);
>
>    // If statistics were requested, print them out after codegen.
>    if (llvm::AreStatisticsEnabled())
>
> Modified: llvm/trunk/tools/gold/gold-plugin.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=266564&r1=266563&r2=266564&view=diff
> ==============================================================================
> --- llvm/trunk/tools/gold/gold-plugin.cpp (original)
> +++ llvm/trunk/tools/gold/gold-plugin.cpp Sun Apr 17 13:42:27 2016
> @@ -879,10 +879,16 @@ public:
>    void runCodegenPasses();
>
>  private:
> +  const Target *TheTarget;
> +  std::string FeaturesString;
> +  TargetOptions Options;
> +
>    /// Create a target machine for the module. Must be unique for each
>    /// module/task.
>    void initTargetMachine();
>
> +  std::unique_ptr<TargetMachine> createTargetMachine();
> +
>    /// Run all LTO passes on the module.
>    void runLTOPasses();
>
> @@ -921,16 +927,23 @@ void CodeGen::initTargetMachine() {
>    Triple TheTriple(TripleStr);
>
>    std::string ErrMsg;
> -  const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
> +  TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
>    if (!TheTarget)
>      message(LDPL_FATAL, "Target not found: %s", ErrMsg.c_str());
>
>    SubtargetFeatures Features = getFeatures(TheTriple);
> -  TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
> +  FeaturesString = Features.getString();
> +  Options = InitTargetOptionsFromCodeGenFlags();
> +
> +  TM = createTargetMachine();
> +}
> +
> +std::unique_ptr<TargetMachine> CodeGen::createTargetMachine() {
> +  const std::string &TripleStr = M->getTargetTriple();
>    CodeGenOpt::Level CGOptLevel = getCGOptLevel();
>
> -  TM.reset(TheTarget->createTargetMachine(
> -      TripleStr, options::mcpu, Features.getString(), Options, RelocationModel,
> +  return std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
> +      TripleStr, options::mcpu, FeaturesString, Options, RelocationModel,
>        CodeModel::Default, CGOptLevel));
>  }
>
> @@ -990,14 +1003,6 @@ void CodeGen::runCodegenPasses() {
>  }
>
>  void CodeGen::runSplitCodeGen(const SmallString<128> &BCFilename) {
> -  const std::string &TripleStr = M->getTargetTriple();
> -  Triple TheTriple(TripleStr);
> -
> -  SubtargetFeatures Features = getFeatures(TheTriple);
> -
> -  TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
> -  CodeGenOpt::Level CGOptLevel = getCGOptLevel();
> -
>    SmallString<128> Filename;
>    // Note that openOutputFile will append a unique ID for each task
>    if (!options::obj_path.empty())
> @@ -1038,8 +1043,8 @@ void CodeGen::runSplitCodeGen(const Smal
>      }
>
>      // Run backend tasks.
> -    splitCodeGen(std::move(M), OSPtrs, BCOSPtrs, options::mcpu, Features.getString(),
> -                 Options, RelocationModel, CodeModel::Default, CGOptLevel);
> +    splitCodeGen(std::move(M), OSPtrs, BCOSPtrs,
> +                 [&]() { return createTargetMachine(); });
>    }
>
>    for (auto &Filename : Filenames)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list