2011-02-20 12:57:14 +00:00
|
|
|
//===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-05-02 19:34:44 +00:00
|
|
|
// Expand Pseudo-instructions produced by ISel. These are usually to allow
|
2011-02-20 12:57:14 +00:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2015-01-18 16:17:27 +00:00
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
#define DEBUG_TYPE "expand-isel-pseudos"
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
namespace {
|
|
|
|
class ExpandISelPseudos : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
ExpandISelPseudos() : MachineFunctionPass(ID) {}
|
|
|
|
|
|
|
|
private:
|
2014-11-24 09:08:18 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2011-02-20 12:57:14 +00:00
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2011-02-20 12:57:14 +00:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char ExpandISelPseudos::ID = 0;
|
2012-04-14 13:54:10 +00:00
|
|
|
char &llvm::ExpandISelPseudosID = ExpandISelPseudos::ID;
|
2011-02-20 12:57:14 +00:00
|
|
|
INITIALIZE_PASS(ExpandISelPseudos, "expand-isel-pseudos",
|
2012-04-14 13:54:10 +00:00
|
|
|
"Expand ISel Pseudo-instructions", false, false)
|
2011-02-20 12:57:14 +00:00
|
|
|
|
|
|
|
bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
bool Changed = false;
|
2015-01-18 16:17:27 +00:00
|
|
|
const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
|
2011-02-20 12:57:14 +00:00
|
|
|
|
|
|
|
// Iterate through each instruction in the function, looking for pseudos.
|
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
|
|
|
MachineBasicBlock *MBB = I;
|
|
|
|
for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
|
|
|
|
MBBI != MBBE; ) {
|
|
|
|
MachineInstr *MI = MBBI++;
|
|
|
|
|
|
|
|
// If MI is a pseudo, expand it.
|
2012-04-14 13:54:10 +00:00
|
|
|
if (MI->usesCustomInsertionHook()) {
|
2011-02-20 12:57:14 +00:00
|
|
|
Changed = true;
|
|
|
|
MachineBasicBlock *NewMBB =
|
|
|
|
TLI->EmitInstrWithCustomInserter(MI, MBB);
|
|
|
|
// The expansion may involve new basic blocks.
|
|
|
|
if (NewMBB != MBB) {
|
|
|
|
MBB = NewMBB;
|
|
|
|
I = NewMBB;
|
|
|
|
MBBI = NewMBB->begin();
|
|
|
|
MBBE = NewMBB->end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|