2
0

ExpandISelPseudos.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // Expand Pseudo-instructions produced by ISel. These are usually to allow
  11. // the expansion to contain control flow, such as a conditional move
  12. // implemented with a conditional branch and a phi, or an atomic operation
  13. // implemented with a loop.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #include "llvm/CodeGen/Passes.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. #include "llvm/CodeGen/MachineFunctionPass.h"
  19. #include "llvm/Support/Debug.h"
  20. #include "llvm/Target/TargetLowering.h"
  21. #include "llvm/Target/TargetSubtargetInfo.h"
  22. using namespace llvm;
  23. #define DEBUG_TYPE "expand-isel-pseudos"
  24. namespace {
  25. class ExpandISelPseudos : public MachineFunctionPass {
  26. public:
  27. static char ID; // Pass identification, replacement for typeid
  28. ExpandISelPseudos() : MachineFunctionPass(ID) {}
  29. private:
  30. bool runOnMachineFunction(MachineFunction &MF) override;
  31. void getAnalysisUsage(AnalysisUsage &AU) const override {
  32. MachineFunctionPass::getAnalysisUsage(AU);
  33. }
  34. };
  35. } // end anonymous namespace
  36. char ExpandISelPseudos::ID = 0;
  37. char &llvm::ExpandISelPseudosID = ExpandISelPseudos::ID;
  38. INITIALIZE_PASS(ExpandISelPseudos, "expand-isel-pseudos",
  39. "Expand ISel Pseudo-instructions", false, false)
  40. bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) {
  41. bool Changed = false;
  42. const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
  43. // Iterate through each instruction in the function, looking for pseudos.
  44. for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
  45. MachineBasicBlock *MBB = I;
  46. for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
  47. MBBI != MBBE; ) {
  48. MachineInstr *MI = MBBI++;
  49. // If MI is a pseudo, expand it.
  50. if (MI->usesCustomInsertionHook()) {
  51. Changed = true;
  52. MachineBasicBlock *NewMBB =
  53. TLI->EmitInstrWithCustomInserter(MI, MBB);
  54. // The expansion may involve new basic blocks.
  55. if (NewMBB != MBB) {
  56. MBB = NewMBB;
  57. I = NewMBB;
  58. MBBI = NewMBB->begin();
  59. MBBE = NewMBB->end();
  60. }
  61. }
  62. }
  63. }
  64. return Changed;
  65. }