Home | History | Annotate | Download | only in llvm_gpu_backend
      1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_GPU_LLVM_GPU_BACKEND_DUMP_IR_PASS_H_
     17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_LLVM_GPU_BACKEND_DUMP_IR_PASS_H_
     18 
     19 #include <string>
     20 
     21 #include "llvm/IR/LegacyPassManager.h"
     22 #include "llvm/Pass.h"
     23 #include "tensorflow/compiler/xla/types.h"
     24 
     25 namespace xla {
     26 namespace gpu {
     27 
     28 // Pass manager which optionally dumps the IR to a sequence of files before each
     29 // pass.
     30 class IrDumpingPassManager : public llvm::legacy::PassManager {
     31  public:
     32   IrDumpingPassManager(const string& input_filename, const string& output_dir,
     33                        bool dump_ir)
     34       : llvm::legacy::PassManager(),
     35         input_filename_(input_filename),
     36         output_dir_(output_dir),
     37         dump_ir_(dump_ir) {}
     38   void add(llvm::Pass* P) { passes_.push_back(P); }
     39   void run(llvm::Module& module);  // NOLINT(runtime/references)
     40 
     41  private:
     42   string input_filename_;
     43   string output_dir_;
     44   bool dump_ir_;
     45   std::vector<llvm::Pass*> passes_;
     46 };
     47 
     48 }  // namespace gpu
     49 }  // namespace xla
     50 
     51 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_LLVM_GPU_BACKEND_DUMP_IR_PASS_H_
     52