[PATCH] D126800: Write output sections in parallel

Michael Eisel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 12:36:11 PDT 2022


michaeleisel added a comment.

@thakis so it seems like we have some options:

- collect the diagnostics emitted in all of those writeTo() functions into a mutexed vector (does this mean making new versions of helper functions that they call, like checkInt? it seems like a lot of work potentially)
- have an override in the error handler to buffer output temporarily
- in the test code, sort the actual output, and compare it to the expected output sorted

what would you prefer?

sketch of #2:

  diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp
  index 4cacd82c9f35..0f3fe8ce843d 100644
  --- a/lld/Common/ErrorHandler.cpp
  +++ b/lld/Common/ErrorHandler.cpp
  @@ -47,6 +47,7 @@ void ErrorHandler::initialize(llvm::raw_ostream &stdoutOS,
   
   void ErrorHandler::flushStreams() {
     std::lock_guard<std::mutex> lock(mu);
  +  // flush buffered streams here
     outs().flush();
     errs().flush();
   }
  @@ -75,9 +76,21 @@ raw_ostream &lld::errs() {
     return e.errs();
   }
   
  +
  +void ErrorHandler::beginBufferingOutput() {
  +  bufferOutput = true;
  +}
  +
  +void ErrorHandler::finishBufferingOutput() {
  +  // have each buffer write to its corresponding output stream
  +  bufferOutput = false;
  +}
  +
   raw_ostream &ErrorHandler::outs() {
     if (disableOutput)
       return llvm::nulls();
  +  if (bufferOutput)
  +    return bufferedOutWrites;
     return stdoutOS ? *stdoutOS : llvm::outs();
   }
   
  diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
  index 0ba4787e5888..56f9edc4c7be 100644
  --- a/lld/include/lld/Common/ErrorHandler.h
  +++ b/lld/include/lld/Common/ErrorHandler.h
  @@ -115,6 +115,8 @@ public:
   
     raw_ostream &outs();
     raw_ostream &errs();
  +  void beginBufferingOutput();
  +  void finishBufferingOutput();
     void flushStreams();
   
     std::unique_ptr<llvm::FileOutputBuffer> outputBuffer;
  @@ -138,6 +140,27 @@ private:
     std::mutex mu;
     llvm::raw_ostream *stdoutOS{};
     llvm::raw_ostream *stderrOS{};
  +
  +  bool bufferOutput = false;
  +  class MyStream : llvm::raw_ostream {
  +    std::vector<std::string> writes;
  +    void write_impl(const char *Ptr, size_t Size) override {
  +      writes.push_back(std::string(Ptr, Size));
  +    }
  +    uint64_t current_pos() const override {
  +      return 0;
  +    }
  +    std::string sortedWrites() {
  +      std::sort(writes.begin(), writes.end());
  +      std::string sortedWrites;
  +      for (const std::string &write : writes) {
  +        sortedWrites.append(write);
  +      }
  +      return sortedWrites;
  +    }
  +  };
  +  MyStream bufferedOutWrites;
  +  MyStream bufferedErrWrites;
   };
   
   /// Returns the default error handler.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126800/new/

https://reviews.llvm.org/D126800



More information about the llvm-commits mailing list