2006-09-04 12:16:09 +08:00
|
|
|
//===-- LLVMTargetMachine.cpp - Implement the LLVMTargetMachine class -----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-09-04 12:16:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the LLVMTargetMachine class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
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/MachineFunctionAnalysis.h"
|
|
|
|
#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"
|
2014-01-12 19:10:32 +08:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2015-02-13 18:01:29 +08:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2014-06-06 03:29:43 +08:00
|
|
|
#include "llvm/IR/Verifier.h"
|
2009-08-23 04:48:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.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"
|
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"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2006-09-04 12:16:09 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2012-02-04 10:56:59 +08:00
|
|
|
// Enable or disable FastISel. Both options are needed, because
|
|
|
|
// FastISel is enabled by default with -fast, and we wish to be
|
|
|
|
// able to enable or disable fast-isel independently from -O0.
|
|
|
|
static cl::opt<cl::boolOrDefault>
|
|
|
|
EnableFastISelOption("fast-isel", cl::Hidden,
|
|
|
|
cl::desc("Enable the \"fast\" instruction selector"));
|
|
|
|
|
2016-02-12 01:57:22 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
EnableGlobalISel("global-isel", cl::Hidden, cl::init(false),
|
|
|
|
cl::desc("Enable the \"global\" instruction selector"));
|
|
|
|
|
2013-05-13 09:16:13 +08:00
|
|
|
void LLVMTargetMachine::initAsmInfo() {
|
2015-06-16 21:15:50 +08:00
|
|
|
MRI = TheTarget.createMCRegInfo(getTargetTriple().str());
|
2015-03-20 06:36:32 +08:00
|
|
|
MII = 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.
|
2015-06-16 21:15:50 +08:00
|
|
|
STI = TheTarget.createMCSubtargetInfo(getTargetTriple().str(), getTargetCPU(),
|
2015-03-20 06:36:37 +08:00
|
|
|
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);
|
|
|
|
|
2014-03-28 04:45:41 +08:00
|
|
|
if (Options.CompressDebugSections)
|
2016-05-27 20:27:32 +08:00
|
|
|
TmpAsmInfo->setCompressDebugSections(DebugCompressionType::DCT_ZlibGnu);
|
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);
|
|
|
|
|
2014-02-13 22:44:26 +08:00
|
|
|
AsmInfo = TmpAsmInfo;
|
2009-08-12 15:22:17 +08:00
|
|
|
}
|
|
|
|
|
2015-03-12 08:07:24 +08:00
|
|
|
LLVMTargetMachine::LLVMTargetMachine(const Target &T,
|
|
|
|
StringRef DataLayoutString,
|
2015-06-12 03:41:26 +08:00
|
|
|
const Triple &TT, StringRef CPU,
|
2015-03-12 08:07:24 +08:00
|
|
|
StringRef FS, TargetOptions Options,
|
2013-05-13 09:16:13 +08:00
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
2015-06-12 03:41:26 +08:00
|
|
|
: TargetMachine(T, DataLayoutString, TT, CPU, FS, Options) {
|
|
|
|
CodeGenInfo = T.createMCCodeGenInfo(TT.str(), RM, CM, OL);
|
2013-05-13 09:16:13 +08:00
|
|
|
}
|
|
|
|
|
2015-02-01 21:20:00 +08:00
|
|
|
TargetIRAnalysis LLVMTargetMachine::getTargetIRAnalysis() {
|
2015-09-17 07:38:13 +08:00
|
|
|
return TargetIRAnalysis([this](const Function &F) {
|
2015-02-01 22:22:17 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-05-10 09:32:40 +08:00
|
|
|
MachineModuleInfo &
|
|
|
|
LLVMTargetMachine::addMachineModuleInfo(PassManagerBase &PM) const {
|
|
|
|
MachineModuleInfo *MMI = new MachineModuleInfo(*getMCAsmInfo(),
|
|
|
|
*getMCRegisterInfo(),
|
|
|
|
getObjFileLowering());
|
|
|
|
PM.add(MMI);
|
|
|
|
return *MMI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMTargetMachine::addMachineFunctionAnalysis(PassManagerBase &PM,
|
|
|
|
MachineFunctionInitializer *MFInitializer) const {
|
|
|
|
PM.add(new MachineFunctionAnalysis(*this, MFInitializer));
|
|
|
|
}
|
|
|
|
|
2012-02-04 10:56:59 +08:00
|
|
|
/// addPassesToX helper drives creation and initialization of TargetPassConfig.
|
2015-06-16 04:30:22 +08:00
|
|
|
static MCContext *
|
|
|
|
addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
|
2015-07-07 01:44:26 +08:00
|
|
|
bool DisableVerify, AnalysisID StartBefore,
|
|
|
|
AnalysisID StartAfter, AnalysisID StopAfter,
|
2015-06-16 04:30:22 +08:00
|
|
|
MachineFunctionInitializer *MFInitializer = nullptr) {
|
2014-06-06 03:29:43 +08:00
|
|
|
|
2016-01-14 07:56:37 +08:00
|
|
|
// When in emulated TLS mode, add the LowerEmuTLS pass.
|
|
|
|
if (TM->Options.EmulatedTLS)
|
|
|
|
PM.add(createLowerEmuTLSPass(TM));
|
|
|
|
|
2016-04-23 05:18:02 +08:00
|
|
|
PM.add(createPreISelIntrinsicLoweringPass());
|
|
|
|
|
2014-01-24 03:23:28 +08:00
|
|
|
// Add internal analysis passes from the target machine.
|
2015-02-01 20:26:09 +08:00
|
|
|
PM.add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
|
2014-01-24 03:23:28 +08:00
|
|
|
|
2014-05-20 05:18:47 +08:00
|
|
|
// Targets may override createPassConfig to provide a target-specific
|
|
|
|
// subclass.
|
2012-02-04 10:56:59 +08:00
|
|
|
TargetPassConfig *PassConfig = TM->createPassConfig(PM);
|
2015-07-07 01:44:26 +08:00
|
|
|
PassConfig->setStartStopPasses(StartBefore, StartAfter, StopAfter);
|
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);
|
|
|
|
|
2012-02-04 10:56:59 +08:00
|
|
|
PassConfig->addIRPasses();
|
|
|
|
|
2012-12-01 06:08:55 +08:00
|
|
|
PassConfig->addCodeGenPrepare();
|
|
|
|
|
2012-07-03 03:48:31 +08:00
|
|
|
PassConfig->addPassesToHandleExceptions();
|
2012-02-04 10:56:59 +08:00
|
|
|
|
|
|
|
PassConfig->addISelPrepare();
|
|
|
|
|
2016-05-10 09:32:40 +08:00
|
|
|
MachineModuleInfo &MMI = TM->addMachineModuleInfo(PM);
|
|
|
|
TM->addMachineFunctionAnalysis(PM, MFInitializer);
|
2012-02-04 10:56:59 +08:00
|
|
|
|
|
|
|
// Enable FastISel with -fast, but allow that to be overridden.
|
2015-12-01 05:56:16 +08:00
|
|
|
TM->setO0WantsFastISel(EnableFastISelOption != cl::BOU_FALSE);
|
2012-02-04 10:56:59 +08:00
|
|
|
if (EnableFastISelOption == cl::BOU_TRUE ||
|
|
|
|
(TM->getOptLevel() == CodeGenOpt::None &&
|
2015-12-01 05:56:16 +08:00
|
|
|
TM->getO0WantsFastISel()))
|
2012-02-04 10:56:59 +08:00
|
|
|
TM->setFastISel(true);
|
|
|
|
|
2016-02-13 04:41:24 +08:00
|
|
|
// Ask the target for an isel.
|
|
|
|
if (LLVM_UNLIKELY(EnableGlobalISel)) {
|
2016-02-12 01:57:22 +08:00
|
|
|
if (PassConfig->addIRTranslator())
|
|
|
|
return nullptr;
|
2016-04-08 04:27:33 +08:00
|
|
|
|
|
|
|
// Before running the register bank selector, ask the target if it
|
|
|
|
// wants to run some passes.
|
|
|
|
PassConfig->addPreRegBankSelect();
|
|
|
|
|
|
|
|
if (PassConfig->addRegBankSelect())
|
|
|
|
return nullptr;
|
|
|
|
|
2016-02-13 04:41:24 +08:00
|
|
|
} else if (PassConfig->addInstSelector())
|
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();
|
|
|
|
|
2016-05-10 09:32:40 +08:00
|
|
|
return &MMI.getContext();
|
2012-02-04 10:56:59 +08:00
|
|
|
}
|
|
|
|
|
2015-04-10 05:06:08 +08:00
|
|
|
bool LLVMTargetMachine::addPassesToEmitFile(
|
2015-04-15 06:14:34 +08:00
|
|
|
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
|
2015-07-07 01:44:26 +08:00
|
|
|
bool DisableVerify, AnalysisID StartBefore, AnalysisID StartAfter,
|
|
|
|
AnalysisID StopAfter, MachineFunctionInitializer *MFInitializer) {
|
2008-09-25 08:37:07 +08:00
|
|
|
// Add common CodeGen passes.
|
2015-07-07 01:44:26 +08:00
|
|
|
MCContext *Context =
|
|
|
|
addPassesToGenerateCode(this, PM, DisableVerify, StartBefore, StartAfter,
|
|
|
|
StopAfter, MFInitializer);
|
2012-02-04 10:56:59 +08:00
|
|
|
if (!Context)
|
2010-02-03 13:55:08 +08:00
|
|
|
return true;
|
2007-02-08 09:36:53 +08:00
|
|
|
|
2012-07-03 03:48:45 +08:00
|
|
|
if (StopAfter) {
|
2016-02-19 08:18:46 +08:00
|
|
|
PM.add(createPrintMIRPass(errs()));
|
2012-07-03 03:48:45 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-16 08:32:52 +08:00
|
|
|
if (Options.MCOptions.MCSaveTempLabels)
|
2011-03-29 06:49:19 +08:00
|
|
|
Context->setAllowTemporaryLabels(false);
|
|
|
|
|
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.
|
2014-04-14 08:51:57 +08:00
|
|
|
MCCodeEmitter *MCE = nullptr;
|
2014-05-16 07:27:49 +08:00
|
|
|
if (Options.MCOptions.ShowMCEncoding)
|
2015-03-11 06:03:14 +08:00
|
|
|
MCE = getTarget().createMCCodeEmitter(MII, MRI, *Context);
|
2010-05-19 01:22:19 +08:00
|
|
|
|
2015-06-16 21:15:50 +08:00
|
|
|
MCAsmBackend *MAB =
|
|
|
|
getTarget().createMCAsmBackend(MRI, getTargetTriple().str(), TargetCPU);
|
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(
|
2015-04-10 05:06:08 +08:00
|
|
|
*Context, std::move(FOut), Options.MCOptions.AsmVerbose,
|
2015-04-09 23:54:59 +08:00
|
|
|
Options.MCOptions.MCUseDwarfDirectory, InstPrinter, MCE, 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.
|
2015-03-11 06:03:14 +08:00
|
|
|
MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(MII, MRI, *Context);
|
2015-06-16 21:15:50 +08:00
|
|
|
MCAsmBackend *MAB =
|
|
|
|
getTarget().createMCAsmBackend(MRI, getTargetTriple().str(), TargetCPU);
|
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.
|
|
|
|
Context->setUseNamesOnTempLabels(false);
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
Triple T(getTargetTriple().str());
|
2015-03-17 06:29:29 +08:00
|
|
|
AsmStreamer.reset(getTarget().createMCObjectStreamer(
|
2015-03-21 04:00:01 +08:00
|
|
|
T, *Context, *MAB, Out, 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.
|
2014-06-20 21:11:28 +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);
|
2010-08-14 00:55:08 +08:00
|
|
|
|
2010-02-03 13:55:08 +08:00
|
|
|
return false;
|
2008-09-25 08:37:07 +08:00
|
|
|
}
|
|
|
|
|
2010-07-22 13:58:53 +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.
|
|
|
|
///
|
2015-04-15 06:14:34 +08:00
|
|
|
bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
|
|
|
|
raw_pwrite_stream &Out,
|
2010-07-22 13:58:53 +08:00
|
|
|
bool DisableVerify) {
|
|
|
|
// Add common CodeGen passes.
|
2015-07-07 01:44:26 +08:00
|
|
|
Ctx = addPassesToGenerateCode(this, PM, DisableVerify, nullptr, nullptr,
|
|
|
|
nullptr);
|
2012-02-04 10:56:59 +08:00
|
|
|
if (!Ctx)
|
2010-07-22 13:58:53 +08:00
|
|
|
return true;
|
2011-03-19 06:48:41 +08:00
|
|
|
|
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.
|
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 =
|
|
|
|
getTarget().createMCAsmBackend(MRI, getTargetTriple().str(), TargetCPU);
|
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-03-20 06:36:37 +08:00
|
|
|
const MCSubtargetInfo &STI = *getMCSubtargetInfo();
|
2015-01-19 04:29:04 +08:00
|
|
|
std::unique_ptr<MCStreamer> AsmStreamer(getTarget().createMCObjectStreamer(
|
2015-09-16 00:17:27 +08:00
|
|
|
T, *Ctx, *MAB, Out, 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);
|
|
|
|
|
2010-07-22 13:58:53 +08:00
|
|
|
return false; // success!
|
|
|
|
}
|