2019-06-19 00:25:39 +00:00
|
|
|
//===-- llvm/CodeGen/FinalizeISel.cpp ---------------------------*- C++ -*-===//
|
2010-11-16 21:02:37 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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
|
2010-11-16 21:02:37 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2019-06-19 00:25:39 +00: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.
|
2010-11-16 21:02:37 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2017-06-06 11:49:48 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2017-11-17 01:07:10 +00:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-13 21:15:01 +00:00
|
|
|
#include "llvm/InitializePasses.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2010-11-16 21:02:37 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2019-06-19 00:25:39 +00:00
|
|
|
#define DEBUG_TYPE "finalize-isel"
|
2014-04-22 02:02:50 +00:00
|
|
|
|
2010-11-16 21:02:37 +00:00
|
|
|
namespace {
|
2019-06-19 00:25:39 +00:00
|
|
|
class FinalizeISel : public MachineFunctionPass {
|
2010-11-16 21:02:37 +00:00
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2019-06-19 00:25:39 +00:00
|
|
|
FinalizeISel() : MachineFunctionPass(ID) {}
|
2010-11-16 21:02:37 +00:00
|
|
|
|
|
|
|
private:
|
2014-03-07 09:26:03 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2010-11-16 21:02:37 +00:00
|
|
|
|
2014-03-07 09:26:03 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2010-11-16 21:02:37 +00:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2019-06-19 00:25:39 +00:00
|
|
|
char FinalizeISel::ID = 0;
|
|
|
|
char &llvm::FinalizeISelID = FinalizeISel::ID;
|
|
|
|
INITIALIZE_PASS(FinalizeISel, DEBUG_TYPE,
|
|
|
|
"Finalize ISel and expand pseudo-instructions", false, false)
|
2010-11-16 21:02:37 +00:00
|
|
|
|
2019-06-19 00:25:39 +00:00
|
|
|
bool FinalizeISel::runOnMachineFunction(MachineFunction &MF) {
|
2010-11-16 21:02:37 +00:00
|
|
|
bool Changed = false;
|
2014-08-05 02:39:49 +00:00
|
|
|
const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
|
2010-11-16 21:02:37 +00:00
|
|
|
|
|
|
|
// Iterate through each instruction in the function, looking for pseudos.
|
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
2015-10-09 18:44:40 +00:00
|
|
|
MachineBasicBlock *MBB = &*I;
|
2010-11-16 21:02:37 +00:00
|
|
|
for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
|
|
|
|
MBBI != MBBE; ) {
|
2016-06-30 23:09:39 +00:00
|
|
|
MachineInstr &MI = *MBBI++;
|
2010-11-16 21:02:37 +00:00
|
|
|
|
|
|
|
// If MI is a pseudo, expand it.
|
2016-06-30 23:09:39 +00:00
|
|
|
if (MI.usesCustomInsertionHook()) {
|
2010-11-16 21:02:37 +00:00
|
|
|
Changed = true;
|
2016-06-30 23:09:39 +00:00
|
|
|
MachineBasicBlock *NewMBB = TLI->EmitInstrWithCustomInserter(MI, MBB);
|
2010-11-16 21:02:37 +00:00
|
|
|
// The expansion may involve new basic blocks.
|
|
|
|
if (NewMBB != MBB) {
|
|
|
|
MBB = NewMBB;
|
2015-10-09 18:44:40 +00:00
|
|
|
I = NewMBB->getIterator();
|
2010-11-16 21:02:37 +00:00
|
|
|
MBBI = NewMBB->begin();
|
|
|
|
MBBE = NewMBB->end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 00:25:39 +00:00
|
|
|
TLI->finalizeLowering(MF);
|
|
|
|
|
2010-11-16 21:02:37 +00:00
|
|
|
return Changed;
|
|
|
|
}
|