Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:38

0001 //===- InstCombine.h - InstCombine pass -------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 /// \file
0009 ///
0010 /// This file provides the primary interface to the instcombine pass. This pass
0011 /// is suitable for use in the new pass manager. For a pass that works with the
0012 /// legacy pass manager, use \c createInstructionCombiningPass().
0013 ///
0014 //===----------------------------------------------------------------------===//
0015 
0016 #ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
0017 #define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
0018 
0019 #include "llvm/IR/Function.h"
0020 #include "llvm/IR/PassManager.h"
0021 #include "llvm/Pass.h"
0022 
0023 #define DEBUG_TYPE "instcombine"
0024 #include "llvm/Transforms/Utils/InstructionWorklist.h"
0025 
0026 namespace llvm {
0027 
0028 static constexpr unsigned InstCombineDefaultMaxIterations = 1;
0029 
0030 struct InstCombineOptions {
0031   // Verify that a fix point has been reached after MaxIterations.
0032   bool VerifyFixpoint = false;
0033   unsigned MaxIterations = InstCombineDefaultMaxIterations;
0034 
0035   InstCombineOptions() = default;
0036 
0037   InstCombineOptions &setVerifyFixpoint(bool Value) {
0038     VerifyFixpoint = Value;
0039     return *this;
0040   }
0041 
0042   InstCombineOptions &setMaxIterations(unsigned Value) {
0043     MaxIterations = Value;
0044     return *this;
0045   }
0046 };
0047 
0048 class InstCombinePass : public PassInfoMixin<InstCombinePass> {
0049 private:
0050   InstructionWorklist Worklist;
0051   InstCombineOptions Options;
0052   static char ID;
0053 
0054 public:
0055   explicit InstCombinePass(InstCombineOptions Opts = {});
0056   void printPipeline(raw_ostream &OS,
0057                      function_ref<StringRef(StringRef)> MapClassName2PassName);
0058 
0059   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
0060 };
0061 
0062 /// The legacy pass manager's instcombine pass.
0063 ///
0064 /// This is a basic whole-function wrapper around the instcombine utility. It
0065 /// will try to combine all instructions in the function.
0066 class InstructionCombiningPass : public FunctionPass {
0067   InstructionWorklist Worklist;
0068 
0069 public:
0070   static char ID; // Pass identification, replacement for typeid
0071 
0072   explicit InstructionCombiningPass();
0073 
0074   void getAnalysisUsage(AnalysisUsage &AU) const override;
0075   bool runOnFunction(Function &F) override;
0076 };
0077 
0078 //===----------------------------------------------------------------------===//
0079 //
0080 // InstructionCombining - Combine instructions to form fewer, simple
0081 // instructions. This pass does not modify the CFG, and has a tendency to make
0082 // instructions dead, so a subsequent DCE pass is useful.
0083 //
0084 // This pass combines things like:
0085 //    %Y = add int 1, %X
0086 //    %Z = add int 1, %Y
0087 // into:
0088 //    %Z = add int 2, %X
0089 //
0090 FunctionPass *createInstructionCombiningPass();
0091 }
0092 
0093 #undef DEBUG_TYPE
0094 
0095 #endif