diff --git a/llvm/include/llvm/CodeGen/ExpandISelPseudos.h b/llvm/include/llvm/CodeGen/ExpandISelPseudos.h new file mode 100644 --- /dev/null +++ b/llvm/include/llvm/CodeGen/ExpandISelPseudos.h @@ -0,0 +1,29 @@ +//===-- llvm/CodeGen/ExpandISelPseudos.h ----------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Expand Pseudo-instructions produced by ISel. These are usually to allow +// the expansion to contain control flow, such as a conditional move +// implemented with a conditional branch and a phi, or an atomic operation +// implemented with a loop. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CODEGEN_EXPAND_ISEL_PSEUDOS_H +#define LLVM_CODEGEN_EXPAND_ISEL_PSEUDOS_H + +#include "llvm/CodeGen/PassManager.h" +#include "llvm/IR/PassManager.h" + +namespace llvm { + +struct ExpandISelPseudosPass : PassInfoMixin { + PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &); +}; +} // namespace llvm + +#endif // LLVM_CODEGEN_EXPAND_ISEL_PSEUDOS_H diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -137,7 +137,7 @@ void initializeEdgeBundlesPass(PassRegistry&); void initializeEliminateAvailableExternallyLegacyPassPass(PassRegistry&); void initializeEntryExitInstrumenterPass(PassRegistry&); -void initializeExpandISelPseudosPass(PassRegistry&); +void initializeExpandISelPseudosLegacyPassPass(PassRegistry&); void initializeExpandMemCmpPassPass(PassRegistry&); void initializeExpandPostRAPass(PassRegistry&); void initializeExpandReductionsPass(PassRegistry&); diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp --- a/llvm/lib/CodeGen/CodeGen.cpp +++ b/llvm/lib/CodeGen/CodeGen.cpp @@ -30,7 +30,7 @@ initializeEarlyIfConverterPass(Registry); initializeEarlyMachineLICMPass(Registry); initializeEarlyTailDuplicatePass(Registry); - initializeExpandISelPseudosPass(Registry); + initializeExpandISelPseudosLegacyPassPass(Registry); initializeExpandMemCmpPassPass(Registry); initializeExpandPostRAPass(Registry); initializeFEntryInserterPass(Registry); diff --git a/llvm/lib/CodeGen/ExpandISelPseudos.cpp b/llvm/lib/CodeGen/ExpandISelPseudos.cpp --- a/llvm/lib/CodeGen/ExpandISelPseudos.cpp +++ b/llvm/lib/CodeGen/ExpandISelPseudos.cpp @@ -13,6 +13,8 @@ // //===----------------------------------------------------------------------===// +#include "llvm/CodeGen/ExpandISelPseudos.h" + #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/Passes.h" @@ -24,10 +26,10 @@ #define DEBUG_TYPE "expand-isel-pseudos" namespace { - class ExpandISelPseudos : public MachineFunctionPass { + class ExpandISelPseudosLegacyPass : public MachineFunctionPass { public: static char ID; // Pass identification, replacement for typeid - ExpandISelPseudos() : MachineFunctionPass(ID) {} + ExpandISelPseudosLegacyPass() : MachineFunctionPass(ID) {} private: bool runOnMachineFunction(MachineFunction &MF) override; @@ -38,12 +40,12 @@ }; } // end anonymous namespace -char ExpandISelPseudos::ID = 0; -char &llvm::ExpandISelPseudosID = ExpandISelPseudos::ID; -INITIALIZE_PASS(ExpandISelPseudos, DEBUG_TYPE, +char ExpandISelPseudosLegacyPass::ID = 0; +char &llvm::ExpandISelPseudosID = ExpandISelPseudosLegacyPass::ID; +INITIALIZE_PASS(ExpandISelPseudosLegacyPass, DEBUG_TYPE, "Expand ISel Pseudo-instructions", false, false) -bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) { +static bool expandISelPseudos(MachineFunction &MF) { bool Changed = false; const TargetLowering *TLI = MF.getSubtarget().getTargetLowering(); @@ -68,6 +70,15 @@ } } } - return Changed; } + +PreservedAnalyses +ExpandISelPseudosPass::run(MachineFunction &MF, + MachineFunctionAnalysisManager &) { + return expandISelPseudos(MF) ? PreservedAnalyses::all() : PreservedAnalyses::none(); +} + +bool ExpandISelPseudosLegacyPass::runOnMachineFunction(MachineFunction &MF) { + return expandISelPseudos(MF); +} diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -316,4 +316,6 @@ #define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) #endif MACHINE_FUNCTION_PASS("machine-cp", MachineCopyPropagationPass()) +MACHINE_FUNCTION_PASS("expand-isel-pseudos", ExpandISelPseudosPass()) +MACHINE_FUNCTION_PASS("machine-cse", MachineCSEPass()) #undef MACHINE_FUNCTION_PASS