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"
|
2014-06-06 03:29:43 +08:00
|
|
|
#include "llvm/CodeGen/JumpInstrTables.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"
|
2014-01-12 19:10:32 +08:00
|
|
|
#include "llvm/IR/IRPrintingPasses.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"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/PassManager.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/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/Target/TargetSubtargetInfo.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"));
|
|
|
|
|
2013-05-13 09:16:13 +08:00
|
|
|
void LLVMTargetMachine::initAsmInfo() {
|
2014-08-05 05:25:23 +08:00
|
|
|
MCAsmInfo *TmpAsmInfo = TheTarget.createMCAsmInfo(
|
|
|
|
*getSubtargetImpl()->getRegisterInfo(), getTargetTriple());
|
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)
|
|
|
|
TmpAsmInfo->setCompressDebugSections(true);
|
|
|
|
|
2014-02-13 22:44:26 +08:00
|
|
|
AsmInfo = TmpAsmInfo;
|
2009-08-12 15:22:17 +08:00
|
|
|
}
|
|
|
|
|
2013-05-13 09:16:13 +08:00
|
|
|
LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple,
|
|
|
|
StringRef CPU, StringRef FS,
|
|
|
|
TargetOptions Options,
|
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
|
|
|
: TargetMachine(T, Triple, CPU, FS, Options) {
|
|
|
|
CodeGenInfo = T.createMCCodeGenInfo(Triple, RM, CM, OL);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void LLVMTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
|
2013-06-20 04:51:24 +08:00
|
|
|
PM.add(createBasicTargetTransformInfoPass(this));
|
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.
|
|
|
|
static MCContext *addPassesToGenerateCode(LLVMTargetMachine *TM,
|
|
|
|
PassManagerBase &PM,
|
2012-07-03 03:48:45 +08:00
|
|
|
bool DisableVerify,
|
|
|
|
AnalysisID StartAfter,
|
|
|
|
AnalysisID StopAfter) {
|
2014-06-06 03:29:43 +08:00
|
|
|
|
2014-01-24 03:23:28 +08:00
|
|
|
// Add internal analysis passes from the target machine.
|
|
|
|
TM->addAnalysisPasses(PM);
|
|
|
|
|
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);
|
2012-07-03 03:48:45 +08:00
|
|
|
PassConfig->setStartStopPasses(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();
|
|
|
|
|
|
|
|
// Install a MachineModuleInfo class, which is an immutable pass that holds
|
|
|
|
// all the per-module stuff we're generating, including MCContext.
|
2014-08-05 05:25:23 +08:00
|
|
|
MachineModuleInfo *MMI = new MachineModuleInfo(
|
|
|
|
*TM->getMCAsmInfo(), *TM->getSubtargetImpl()->getRegisterInfo(),
|
|
|
|
&TM->getSubtargetImpl()->getTargetLowering()->getObjFileLowering());
|
2012-02-04 10:56:59 +08:00
|
|
|
PM.add(MMI);
|
|
|
|
|
|
|
|
// Set up a MachineFunction for the rest of CodeGen to work on.
|
|
|
|
PM.add(new MachineFunctionAnalysis(*TM));
|
|
|
|
|
|
|
|
// Enable FastISel with -fast, but allow that to be overridden.
|
|
|
|
if (EnableFastISelOption == cl::BOU_TRUE ||
|
|
|
|
(TM->getOptLevel() == CodeGenOpt::None &&
|
|
|
|
EnableFastISelOption != cl::BOU_FALSE))
|
|
|
|
TM->setFastISel(true);
|
|
|
|
|
|
|
|
// Ask the target for an isel.
|
|
|
|
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();
|
|
|
|
|
2013-06-20 04:51:24 +08:00
|
|
|
return &MMI->getContext();
|
2012-02-04 10:56:59 +08:00
|
|
|
}
|
|
|
|
|
2010-02-03 13:55:08 +08:00
|
|
|
bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
|
|
|
|
formatted_raw_ostream &Out,
|
|
|
|
CodeGenFileType FileType,
|
2012-07-03 03:48:45 +08:00
|
|
|
bool DisableVerify,
|
|
|
|
AnalysisID StartAfter,
|
|
|
|
AnalysisID StopAfter) {
|
2014-06-06 03:29:43 +08:00
|
|
|
// Passes to handle jumptable function annotations. These can't be handled at
|
|
|
|
// JIT time, so we don't add them directly to addPassesToGenerateCode.
|
|
|
|
PM.add(createJumpInstrTableInfoPass());
|
|
|
|
PM.add(createJumpInstrTablesPass(Options.JTType));
|
|
|
|
|
2008-09-25 08:37:07 +08:00
|
|
|
// Add common CodeGen passes.
|
2012-07-03 03:48:45 +08:00
|
|
|
MCContext *Context = addPassesToGenerateCode(this, PM, DisableVerify,
|
|
|
|
StartAfter, StopAfter);
|
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) {
|
|
|
|
// FIXME: The intent is that this should eventually write out a YAML file,
|
|
|
|
// containing the LLVM IR, the machine-level IR (when stopping after a
|
|
|
|
// machine-level pass), and whatever other information is needed to
|
|
|
|
// deserialize the code and resume compilation. For now, just write the
|
|
|
|
// LLVM IR.
|
2014-01-12 19:30:46 +08:00
|
|
|
PM.add(createPrintModulePass(Out));
|
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);
|
|
|
|
|
2011-09-08 01:24:38 +08:00
|
|
|
const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
|
2014-08-05 05:25:23 +08:00
|
|
|
const MCAsmInfo &MAI = *getMCAsmInfo();
|
|
|
|
const MCRegisterInfo &MRI = *getSubtargetImpl()->getRegisterInfo();
|
|
|
|
const MCInstrInfo &MII = *getSubtargetImpl()->getInstrInfo();
|
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: {
|
|
|
|
MCInstPrinter *InstPrinter =
|
2012-03-06 03:33:20 +08:00
|
|
|
getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI,
|
2013-06-18 14:07:26 +08:00
|
|
|
MII, MRI, STI);
|
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)
|
2013-06-18 14:07:26 +08:00
|
|
|
MCE = getTarget().createMCCodeEmitter(MII, MRI, STI, *Context);
|
2010-05-19 01:22:19 +08:00
|
|
|
|
2013-09-10 03:48:37 +08:00
|
|
|
MCAsmBackend *MAB = getTarget().createMCAsmBackend(MRI, getTargetTriple(),
|
|
|
|
TargetCPU);
|
2014-05-16 07:27:49 +08:00
|
|
|
MCStreamer *S = getTarget().createAsmStreamer(
|
2014-05-21 07:59:50 +08:00
|
|
|
*Context, Out, Options.MCOptions.AsmVerbose,
|
|
|
|
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.
|
2013-06-18 14:07:26 +08:00
|
|
|
MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(MII, MRI, STI,
|
|
|
|
*Context);
|
2013-09-09 10:37:14 +08:00
|
|
|
MCAsmBackend *MAB = getTarget().createMCAsmBackend(MRI, getTargetTriple(),
|
2012-11-22 22:10:40 +08:00
|
|
|
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
|
|
|
|
2014-10-16 00:12:52 +08:00
|
|
|
AsmStreamer.reset(
|
|
|
|
getTarget()
|
|
|
|
.createMCObjectStreamer(getTargetTriple(), *Context, *MAB, Out, MCE,
|
|
|
|
STI, Options.MCOptions.MCRelaxAll));
|
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.
|
2010-04-04 16:18:47 +08:00
|
|
|
FunctionPass *Printer = getTarget().createAsmPrinter(*this, *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-03-14 04:55:24 +08:00
|
|
|
// If successful, createAsmPrinter took ownership of AsmStreamer.
|
2014-03-05 18:19:29 +08:00
|
|
|
AsmStreamer.release();
|
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.
|
|
|
|
///
|
|
|
|
bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM,
|
|
|
|
MCContext *&Ctx,
|
2011-03-19 06:48:41 +08:00
|
|
|
raw_ostream &Out,
|
2010-07-22 13:58:53 +08:00
|
|
|
bool DisableVerify) {
|
|
|
|
// Add common CodeGen passes.
|
2014-04-14 08:51:57 +08:00
|
|
|
Ctx = addPassesToGenerateCode(this, PM, DisableVerify, 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.
|
2014-08-05 05:25:23 +08:00
|
|
|
const MCRegisterInfo &MRI = *getSubtargetImpl()->getRegisterInfo();
|
2011-07-11 11:57:24 +08:00
|
|
|
const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
|
2014-08-05 05:25:23 +08:00
|
|
|
MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(
|
|
|
|
*getSubtargetImpl()->getInstrInfo(), MRI, STI, *Ctx);
|
2013-09-09 10:37:14 +08:00
|
|
|
MCAsmBackend *MAB = getTarget().createMCAsmBackend(MRI, getTargetTriple(),
|
|
|
|
TargetCPU);
|
2014-04-14 08:51:57 +08:00
|
|
|
if (!MCE || !MAB)
|
2011-03-19 06:48:41 +08:00
|
|
|
return true;
|
|
|
|
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<MCStreamer> AsmStreamer;
|
2014-10-16 00:12:52 +08:00
|
|
|
AsmStreamer.reset(getTarget()
|
|
|
|
.createMCObjectStreamer(getTargetTriple(), *Ctx, *MAB,
|
|
|
|
Out, MCE, STI,
|
|
|
|
Options.MCOptions.MCRelaxAll));
|
2011-03-19 06:48:41 +08:00
|
|
|
|
|
|
|
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
|
|
|
|
FunctionPass *Printer = getTarget().createAsmPrinter(*this, *AsmStreamer);
|
2014-04-14 08:51:57 +08:00
|
|
|
if (!Printer)
|
2011-03-19 06:48:41 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// If successful, createAsmPrinter took ownership of AsmStreamer.
|
2014-03-05 18:19:29 +08:00
|
|
|
AsmStreamer.release();
|
2011-03-19 06:48:41 +08:00
|
|
|
|
|
|
|
PM.add(Printer);
|
|
|
|
|
2010-07-22 13:58:53 +08:00
|
|
|
return false; // success!
|
|
|
|
}
|