2019-08-20 16:50:12 -04:00
|
|
|
//===-- llvm/CodeGen/FinalizeISel.cpp ---------------------------*- C++ -*-===//
|
2011-02-20 07:57:14 -05:00
|
|
|
//
|
2019-08-20 16:50:12 -04:00
|
|
|
// 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
|
2011-02-20 07:57:14 -05:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
2019-08-20 16:50:12 -04:00
|
|
|
/// This pass expands Pseudo-instructions produced by ISel, fixes register
|
|
|
|
|
/// reservations and may do machine frame information adjustments.
|
|
|
|
|
/// The pseudo instructions are used 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.
|
2011-02-20 07:57:14 -05:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2017-06-10 09:44:06 -04:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2017-12-18 15:10:56 -05:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2020-01-17 15:45:01 -05:00
|
|
|
#include "llvm/InitializePasses.h"
|
2013-04-08 14:41:23 -04:00
|
|
|
#include "llvm/Support/Debug.h"
|
2011-02-20 07:57:14 -05:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
2019-08-20 16:50:12 -04:00
|
|
|
#define DEBUG_TYPE "finalize-isel"
|
2014-11-24 04:08:18 -05:00
|
|
|
|
2011-02-20 07:57:14 -05:00
|
|
|
namespace {
|
2019-08-20 16:50:12 -04:00
|
|
|
class FinalizeISel : public MachineFunctionPass {
|
2011-02-20 07:57:14 -05:00
|
|
|
public:
|
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2019-08-20 16:50:12 -04:00
|
|
|
FinalizeISel() : MachineFunctionPass(ID) {}
|
2011-02-20 07:57:14 -05:00
|
|
|
|
|
|
|
|
private:
|
2014-11-24 04:08:18 -05:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2011-02-20 07:57:14 -05:00
|
|
|
|
2014-11-24 04:08:18 -05:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2011-02-20 07:57:14 -05:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
2019-08-20 16:50:12 -04:00
|
|
|
char FinalizeISel::ID = 0;
|
|
|
|
|
char &llvm::FinalizeISelID = FinalizeISel::ID;
|
|
|
|
|
INITIALIZE_PASS(FinalizeISel, DEBUG_TYPE,
|
|
|
|
|
"Finalize ISel and expand pseudo-instructions", false, false)
|
2011-02-20 07:57:14 -05:00
|
|
|
|
2019-08-20 16:50:12 -04:00
|
|
|
bool FinalizeISel::runOnMachineFunction(MachineFunction &MF) {
|
2011-02-20 07:57:14 -05:00
|
|
|
bool Changed = false;
|
2015-01-18 11:17:27 -05:00
|
|
|
const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
|
2011-02-20 07:57:14 -05:00
|
|
|
|
|
|
|
|
// Iterate through each instruction in the function, looking for pseudos.
|
|
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
2015-12-30 06:46:15 -05:00
|
|
|
MachineBasicBlock *MBB = &*I;
|
2011-02-20 07:57:14 -05:00
|
|
|
for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
|
|
|
|
|
MBBI != MBBE; ) {
|
2016-07-23 16:41:05 -04:00
|
|
|
MachineInstr &MI = *MBBI++;
|
2011-02-20 07:57:14 -05:00
|
|
|
|
|
|
|
|
// If MI is a pseudo, expand it.
|
2016-07-23 16:41:05 -04:00
|
|
|
if (MI.usesCustomInsertionHook()) {
|
2011-02-20 07:57:14 -05:00
|
|
|
Changed = true;
|
2016-07-23 16:41:05 -04:00
|
|
|
MachineBasicBlock *NewMBB = TLI->EmitInstrWithCustomInserter(MI, MBB);
|
2011-02-20 07:57:14 -05:00
|
|
|
// The expansion may involve new basic blocks.
|
|
|
|
|
if (NewMBB != MBB) {
|
|
|
|
|
MBB = NewMBB;
|
2015-12-30 06:46:15 -05:00
|
|
|
I = NewMBB->getIterator();
|
2011-02-20 07:57:14 -05:00
|
|
|
MBBI = NewMBB->begin();
|
|
|
|
|
MBBE = NewMBB->end();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 16:50:12 -04:00
|
|
|
TLI->finalizeLowering(MF);
|
|
|
|
|
|
2011-02-20 07:57:14 -05:00
|
|
|
return Changed;
|
|
|
|
|
}
|