2017-10-13 06:57:28 +08:00
|
|
|
//===-- LLVMTargetMachine.cpp - Implement the LLVMTargetMachine class -----===//
|
2006-09-04 12:16:09 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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
|
2006-09-04 12:16:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2017-10-13 06:57:28 +08:00
|
|
|
// This file implements the LLVMTargetMachine class.
|
2006-09-04 12:16:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-06-06 03:29:43 +08:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
2009-08-14 07:48:47 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2015-01-31 19:17:59 +08:00
|
|
|
#include "llvm/CodeGen/BasicTTIImpl.h"
|
2012-02-04 10:56:59 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2016-05-10 11:21:59 +08:00
|
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
2015-02-13 18:01:29 +08:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2017-10-11 09:57:21 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2009-08-23 04:48:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2017-10-12 07:34:47 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2012-02-04 10:56:48 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2011-07-11 11:57:24 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2018-05-19 02:26:45 +08:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2010-02-03 07:37:42 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-07-11 11:57:24 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2007-03-31 08:24:43 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2012-02-04 10:56:48 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2018-03-24 07:58:19 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2017-10-13 06:57:28 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2006-09-04 12:16:09 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2018-02-12 19:06:27 +08:00
|
|
|
static cl::opt<bool> EnableTrapUnreachable("trap-unreachable",
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Enable generating trap for unreachable"));
|
|
|
|
|
2017-10-13 06:57:28 +08:00
|
|
|
void LLVMTargetMachine::initAsmInfo() {
|
2018-09-25 14:19:31 +08:00
|
|
|
MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str()));
|
|
|
|
MII.reset(TheTarget.createMCInstrInfo());
|
2015-03-20 06:36:37 +08:00
|
|
|
// FIXME: Having an MCSubtargetInfo on the target machine is a hack due
|
|
|
|
// to some backends having subtarget feature dependent module level
|
|
|
|
// code generation. This is similar to the hack in the AsmPrinter for
|
|
|
|
// module level assembly etc.
|
2018-09-25 14:19:31 +08:00
|
|
|
STI.reset(TheTarget.createMCSubtargetInfo(
|
|
|
|
getTargetTriple().str(), getTargetCPU(), getTargetFeatureString()));
|
2015-03-20 06:36:32 +08:00
|
|
|
|
2015-06-16 21:15:50 +08:00
|
|
|
MCAsmInfo *TmpAsmInfo =
|
|
|
|
TheTarget.createMCAsmInfo(*MRI, getTargetTriple().str());
|
2011-09-30 21:07:47 +08:00
|
|
|
// TargetSelect.h moved to a different directory between LLVM 2.9 and 3.0,
|
|
|
|
// and if the old one gets included then MCAsmInfo will be NULL and
|
|
|
|
// we'll crash later.
|
|
|
|
// Provide the user with a useful error message about what's wrong.
|
2014-02-13 22:44:26 +08:00
|
|
|
assert(TmpAsmInfo && "MCAsmInfo not initialized. "
|
2011-10-26 04:30:48 +08:00
|
|
|
"Make sure you include the correct TargetSelect.h"
|
|
|
|
"and that InitializeAllTargetMCs() is being invoked!");
|
2014-02-13 22:44:26 +08:00
|
|
|
|
2014-02-21 11:13:54 +08:00
|
|
|
if (Options.DisableIntegratedAS)
|
2014-02-13 22:44:26 +08:00
|
|
|
TmpAsmInfo->setUseIntegratedAssembler(false);
|
|
|
|
|
2016-07-11 20:42:14 +08:00
|
|
|
TmpAsmInfo->setPreserveAsmComments(Options.MCOptions.PreserveAsmComments);
|
|
|
|
|
2017-06-09 08:40:19 +08:00
|
|
|
TmpAsmInfo->setCompressDebugSections(Options.CompressDebugSections);
|
2014-03-28 04:45:41 +08:00
|
|
|
|
2016-05-29 09:57:20 +08:00
|
|
|
TmpAsmInfo->setRelaxELFRelocations(Options.RelaxELFRelocations);
|
|
|
|
|
2016-05-31 09:48:07 +08:00
|
|
|
if (Options.ExceptionModel != ExceptionHandling::None)
|
|
|
|
TmpAsmInfo->setExceptionsType(Options.ExceptionModel);
|
|
|
|
|
2018-09-25 14:19:31 +08:00
|
|
|
AsmInfo.reset(TmpAsmInfo);
|
2009-08-12 15:22:17 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 06:57:28 +08:00
|
|
|
LLVMTargetMachine::LLVMTargetMachine(const Target &T,
|
|
|
|
StringRef DataLayoutString,
|
|
|
|
const Triple &TT, StringRef CPU,
|
|
|
|
StringRef FS, const TargetOptions &Options,
|
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
|
|
|
: TargetMachine(T, DataLayoutString, TT, CPU, FS, Options) {
|
|
|
|
this->RM = RM;
|
|
|
|
this->CMModel = CM;
|
|
|
|
this->OptLevel = OL;
|
2018-02-12 19:06:27 +08:00
|
|
|
|
|
|
|
if (EnableTrapUnreachable)
|
|
|
|
this->Options.TrapUnreachable = true;
|
2017-10-13 06:57:28 +08:00
|
|
|
}
|
|
|
|
|
(Re-landing) Expose a TargetMachine::getTargetTransformInfo function
Re-land r321234. It had to be reverted because it broke the shared
library build. The shared library build broke because there was a
missing LLVMBuild dependency from lib/Passes (which calls
TargetMachine::getTargetIRAnalysis) to lib/Target. As far as I can
tell, this problem was always there but was somehow masked
before (perhaps because TargetMachine::getTargetIRAnalysis was a
virtual function).
Original commit message:
This makes the TargetMachine interface a bit simpler. We still need
the std::function in TargetIRAnalysis to avoid having to add a
dependency from Analysis to Target.
See discussion:
http://lists.llvm.org/pipermail/llvm-dev/2017-December/119749.html
I avoided adding all of the backend owners to this review since the
change is simple, but let me know if you feel differently about this.
Reviewers: echristo, MatzeB, hfinkel
Reviewed By: hfinkel
Subscribers: jholewinski, jfb, arsenm, dschuff, mcrosier, sdardis, nemanjai, nhaehnle, javed.absar, sbc100, jgravelle-google, aheejin, kbarton, llvm-commits
Differential Revision: https://reviews.llvm.org/D41464
llvm-svn: 321375
2017-12-23 02:21:59 +08:00
|
|
|
TargetTransformInfo
|
|
|
|
LLVMTargetMachine::getTargetTransformInfo(const Function &F) {
|
|
|
|
return TargetTransformInfo(BasicTTIImpl(this, F));
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 09:37:14 +08:00
|
|
|
}
|
|
|
|
|
2012-02-04 10:56:59 +08:00
|
|
|
/// addPassesToX helper drives creation and initialization of TargetPassConfig.
|
2018-11-02 09:31:50 +08:00
|
|
|
static TargetPassConfig *
|
|
|
|
addPassesToGenerateCode(LLVMTargetMachine &TM, PassManagerBase &PM,
|
|
|
|
bool DisableVerify, MachineModuleInfo &MMI) {
|
2014-05-20 05:18:47 +08:00
|
|
|
// Targets may override createPassConfig to provide a target-specific
|
|
|
|
// subclass.
|
2018-11-02 09:31:50 +08:00
|
|
|
TargetPassConfig *PassConfig = TM.createPassConfig(PM);
|
2012-02-04 10:56:59 +08:00
|
|
|
// Set PassConfig options provided by TargetMachine.
|
|
|
|
PassConfig->setDisableVerify(DisableVerify);
|
2012-02-07 06:51:15 +08:00
|
|
|
PM.add(PassConfig);
|
2018-11-02 09:31:50 +08:00
|
|
|
PM.add(&MMI);
|
2012-02-04 10:56:59 +08:00
|
|
|
|
2017-06-06 08:26:13 +08:00
|
|
|
if (PassConfig->addISelPasses())
|
2014-04-14 08:51:57 +08:00
|
|
|
return nullptr;
|
2012-02-04 10:56:59 +08:00
|
|
|
PassConfig->addMachinePasses();
|
2012-02-09 05:22:39 +08:00
|
|
|
PassConfig->setInitialized();
|
2018-11-02 09:31:50 +08:00
|
|
|
return PassConfig;
|
2012-02-04 10:56:59 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 06:57:28 +08:00
|
|
|
bool LLVMTargetMachine::addAsmPrinter(PassManagerBase &PM,
|
2018-05-22 04:16:41 +08:00
|
|
|
raw_pwrite_stream &Out,
|
|
|
|
raw_pwrite_stream *DwoOut,
|
|
|
|
CodeGenFileType FileType,
|
|
|
|
MCContext &Context) {
|
2014-05-16 08:32:52 +08:00
|
|
|
if (Options.MCOptions.MCSaveTempLabels)
|
2017-06-06 08:26:13 +08:00
|
|
|
Context.setAllowTemporaryLabels(false);
|
2011-03-29 06:49:19 +08:00
|
|
|
|
2015-03-20 06:36:37 +08:00
|
|
|
const MCSubtargetInfo &STI = *getMCSubtargetInfo();
|
2014-08-05 05:25:23 +08:00
|
|
|
const MCAsmInfo &MAI = *getMCAsmInfo();
|
2015-03-20 06:36:32 +08:00
|
|
|
const MCRegisterInfo &MRI = *getMCRegisterInfo();
|
|
|
|
const MCInstrInfo &MII = *getMCInstrInfo();
|
|
|
|
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<MCStreamer> AsmStreamer;
|
2010-02-03 07:45:17 +08:00
|
|
|
|
2006-09-04 12:16:09 +08:00
|
|
|
switch (FileType) {
|
2010-02-03 08:29:55 +08:00
|
|
|
case CGFT_AssemblyFile: {
|
2015-03-20 06:36:32 +08:00
|
|
|
MCInstPrinter *InstPrinter = getTarget().createMCInstPrinter(
|
2015-09-16 00:17:27 +08:00
|
|
|
getTargetTriple(), MAI.getAssemblerDialect(), MAI, MII, MRI);
|
2010-05-19 01:22:19 +08:00
|
|
|
|
|
|
|
// Create a code emitter if asked to show the encoding.
|
2018-04-27 23:45:54 +08:00
|
|
|
std::unique_ptr<MCCodeEmitter> MCE;
|
2014-05-16 07:27:49 +08:00
|
|
|
if (Options.MCOptions.ShowMCEncoding)
|
2018-04-27 23:45:54 +08:00
|
|
|
MCE.reset(getTarget().createMCCodeEmitter(MII, MRI, Context));
|
2010-05-19 01:22:19 +08:00
|
|
|
|
2018-04-27 23:45:54 +08:00
|
|
|
std::unique_ptr<MCAsmBackend> MAB(
|
|
|
|
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions));
|
2015-04-10 05:06:08 +08:00
|
|
|
auto FOut = llvm::make_unique<formatted_raw_ostream>(Out);
|
2014-05-16 07:27:49 +08:00
|
|
|
MCStreamer *S = getTarget().createAsmStreamer(
|
2017-06-06 08:26:13 +08:00
|
|
|
Context, std::move(FOut), Options.MCOptions.AsmVerbose,
|
2018-04-27 23:45:54 +08:00
|
|
|
Options.MCOptions.MCUseDwarfDirectory, InstPrinter, std::move(MCE),
|
|
|
|
std::move(MAB), Options.MCOptions.ShowMCInst);
|
2010-11-19 10:26:16 +08:00
|
|
|
AsmStreamer.reset(S);
|
2010-02-03 03:14:27 +08:00
|
|
|
break;
|
2010-02-03 08:29:55 +08:00
|
|
|
}
|
2010-02-03 07:57:42 +08:00
|
|
|
case CGFT_ObjectFile: {
|
|
|
|
// Create the code emitter for the target if it exists. If not, .o file
|
|
|
|
// emission fails.
|
2017-06-06 08:26:13 +08:00
|
|
|
MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(MII, MRI, Context);
|
2015-06-16 21:15:50 +08:00
|
|
|
MCAsmBackend *MAB =
|
2018-01-03 16:53:05 +08:00
|
|
|
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions);
|
2014-04-14 08:51:57 +08:00
|
|
|
if (!MCE || !MAB)
|
2010-02-03 13:55:08 +08:00
|
|
|
return true;
|
2010-05-27 05:48:55 +08:00
|
|
|
|
2015-05-07 05:34:34 +08:00
|
|
|
// Don't waste memory on names of temp labels.
|
2017-06-06 08:26:13 +08:00
|
|
|
Context.setUseNamesOnTempLabels(false);
|
2015-05-07 05:34:34 +08:00
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
Triple T(getTargetTriple().str());
|
2015-03-17 06:29:29 +08:00
|
|
|
AsmStreamer.reset(getTarget().createMCObjectStreamer(
|
2018-05-19 02:26:45 +08:00
|
|
|
T, Context, std::unique_ptr<MCAsmBackend>(MAB),
|
2018-05-22 04:16:41 +08:00
|
|
|
DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut)
|
|
|
|
: MAB->createObjectWriter(Out),
|
|
|
|
std::unique_ptr<MCCodeEmitter>(MCE), STI, Options.MCOptions.MCRelaxAll,
|
2015-12-22 06:09:27 +08:00
|
|
|
Options.MCOptions.MCIncrementalLinkerCompatible,
|
2015-03-21 04:00:01 +08:00
|
|
|
/*DWARFMustBeAtTheEnd*/ true));
|
2010-02-03 07:57:42 +08:00
|
|
|
break;
|
2010-02-03 02:44:12 +08:00
|
|
|
}
|
2010-02-03 13:55:08 +08:00
|
|
|
case CGFT_Null:
|
|
|
|
// The Null output is intended for use for performance analysis and testing,
|
|
|
|
// not real users.
|
2017-06-06 08:26:13 +08:00
|
|
|
AsmStreamer.reset(getTarget().createNullStreamer(Context));
|
2010-02-03 13:55:08 +08:00
|
|
|
break;
|
2006-09-04 12:16:09 +08:00
|
|
|
}
|
2010-05-24 01:44:06 +08:00
|
|
|
|
2010-03-14 04:55:24 +08:00
|
|
|
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
|
2015-01-19 04:29:04 +08:00
|
|
|
FunctionPass *Printer =
|
|
|
|
getTarget().createAsmPrinter(*this, std::move(AsmStreamer));
|
2014-04-14 08:51:57 +08:00
|
|
|
if (!Printer)
|
2010-02-03 13:55:08 +08:00
|
|
|
return true;
|
2010-08-14 00:55:08 +08:00
|
|
|
|
2010-02-03 07:45:17 +08:00
|
|
|
PM.add(Printer);
|
2017-06-06 08:26:13 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-08-14 00:55:08 +08:00
|
|
|
|
2017-10-13 06:57:28 +08:00
|
|
|
bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
|
|
|
|
raw_pwrite_stream &Out,
|
2018-05-22 04:16:41 +08:00
|
|
|
raw_pwrite_stream *DwoOut,
|
2017-10-13 06:57:28 +08:00
|
|
|
CodeGenFileType FileType,
|
|
|
|
bool DisableVerify,
|
|
|
|
MachineModuleInfo *MMI) {
|
2017-06-06 08:26:13 +08:00
|
|
|
// Add common CodeGen passes.
|
2018-11-02 09:31:50 +08:00
|
|
|
if (!MMI)
|
|
|
|
MMI = new MachineModuleInfo(this);
|
|
|
|
TargetPassConfig *PassConfig =
|
|
|
|
addPassesToGenerateCode(*this, PM, DisableVerify, *MMI);
|
|
|
|
if (!PassConfig)
|
2017-06-06 08:26:13 +08:00
|
|
|
return true;
|
|
|
|
|
2018-11-02 09:31:50 +08:00
|
|
|
if (!TargetPassConfig::willCompleteCodeGenPipeline()) {
|
2019-06-07 03:13:36 +08:00
|
|
|
if (this->getTargetTriple().isOSAIX()) {
|
|
|
|
// On AIX, we might manifest MCSymbols during SDAG lowering. For MIR
|
|
|
|
// testing to be meaningful, we need to ensure that the symbols created
|
|
|
|
// are MCSymbolXCOFF variants, which requires that
|
|
|
|
// the TargetLoweringObjectFile instance has been initialized.
|
|
|
|
MCContext &Ctx = MMI->getContext();
|
|
|
|
const_cast<TargetLoweringObjectFile &>(*this->getObjFileLowering())
|
|
|
|
.Initialize(Ctx, *this);
|
|
|
|
}
|
2018-11-02 09:31:50 +08:00
|
|
|
PM.add(createPrintMIRPass(Out));
|
|
|
|
} else if (addAsmPrinter(PM, Out, DwoOut, FileType, MMI->getContext()))
|
2017-08-01 02:24:07 +08:00
|
|
|
return true;
|
2017-06-06 08:26:13 +08:00
|
|
|
|
|
|
|
PM.add(createFreeMachineFunctionPass());
|
2010-02-03 13:55:08 +08:00
|
|
|
return false;
|
2008-09-25 08:37:07 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 06:57:28 +08:00
|
|
|
/// addPassesToEmitMC - Add passes to the specified pass manager to get
|
|
|
|
/// machine code emitted with the MCJIT. This method returns true if machine
|
|
|
|
/// code is not supported. It fills the MCContext Ctx pointer which can be
|
|
|
|
/// used to build custom MCStreamer.
|
|
|
|
///
|
|
|
|
bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
|
|
|
|
raw_pwrite_stream &Out,
|
|
|
|
bool DisableVerify) {
|
2010-07-22 13:58:53 +08:00
|
|
|
// Add common CodeGen passes.
|
2018-11-02 09:31:50 +08:00
|
|
|
MachineModuleInfo *MMI = new MachineModuleInfo(this);
|
|
|
|
TargetPassConfig *PassConfig =
|
|
|
|
addPassesToGenerateCode(*this, PM, DisableVerify, *MMI);
|
|
|
|
if (!PassConfig)
|
2010-07-22 13:58:53 +08:00
|
|
|
return true;
|
2018-11-02 09:31:50 +08:00
|
|
|
assert(TargetPassConfig::willCompleteCodeGenPipeline() &&
|
|
|
|
"Cannot emit MC with limited codegen pipeline");
|
2011-03-19 06:48:41 +08:00
|
|
|
|
2018-11-02 09:31:50 +08:00
|
|
|
Ctx = &MMI->getContext();
|
2014-05-16 08:32:52 +08:00
|
|
|
if (Options.MCOptions.MCSaveTempLabels)
|
2011-03-29 06:49:19 +08:00
|
|
|
Ctx->setAllowTemporaryLabels(false);
|
|
|
|
|
2011-03-19 06:48:41 +08:00
|
|
|
// Create the code emitter for the target if it exists. If not, .o file
|
|
|
|
// emission fails.
|
2018-01-03 16:53:05 +08:00
|
|
|
const MCSubtargetInfo &STI = *getMCSubtargetInfo();
|
2015-03-20 06:36:32 +08:00
|
|
|
const MCRegisterInfo &MRI = *getMCRegisterInfo();
|
|
|
|
MCCodeEmitter *MCE =
|
|
|
|
getTarget().createMCCodeEmitter(*getMCInstrInfo(), MRI, *Ctx);
|
2015-06-16 21:15:50 +08:00
|
|
|
MCAsmBackend *MAB =
|
2018-01-03 16:53:05 +08:00
|
|
|
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions);
|
2014-04-14 08:51:57 +08:00
|
|
|
if (!MCE || !MAB)
|
2011-03-19 06:48:41 +08:00
|
|
|
return true;
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
const Triple &T = getTargetTriple();
|
2015-01-19 04:29:04 +08:00
|
|
|
std::unique_ptr<MCStreamer> AsmStreamer(getTarget().createMCObjectStreamer(
|
2018-05-19 02:26:45 +08:00
|
|
|
T, *Ctx, std::unique_ptr<MCAsmBackend>(MAB), MAB->createObjectWriter(Out),
|
2017-10-12 07:34:47 +08:00
|
|
|
std::unique_ptr<MCCodeEmitter>(MCE), STI, Options.MCOptions.MCRelaxAll,
|
2015-12-22 06:09:27 +08:00
|
|
|
Options.MCOptions.MCIncrementalLinkerCompatible,
|
2015-03-21 04:00:01 +08:00
|
|
|
/*DWARFMustBeAtTheEnd*/ true));
|
2011-03-19 06:48:41 +08:00
|
|
|
|
|
|
|
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
|
2015-01-19 04:29:04 +08:00
|
|
|
FunctionPass *Printer =
|
|
|
|
getTarget().createAsmPrinter(*this, std::move(AsmStreamer));
|
2014-04-14 08:51:57 +08:00
|
|
|
if (!Printer)
|
2011-03-19 06:48:41 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
PM.add(Printer);
|
2016-08-24 09:52:46 +08:00
|
|
|
PM.add(createFreeMachineFunctionPass());
|
2011-03-19 06:48:41 +08:00
|
|
|
|
2010-07-22 13:58:53 +08:00
|
|
|
return false; // success!
|
|
|
|
}
|