2006-09-04 04:16:09 +00:00
|
|
|
//===-- LLVMTargetMachine.cpp - Implement the LLVMTargetMachine class -----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-09-04 04:16:09 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the LLVMTargetMachine class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
2009-08-13 23:48:47 +00:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2012-02-04 02:56:59 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2014-01-12 11:10:32 +00:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2009-08-22 20:48:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2012-02-04 02:56:48 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2011-07-11 03:57:24 +00:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2010-02-02 23:37:42 +00:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-07-11 03:57:24 +00:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/PassManager.h"
|
2007-03-31 00:24:43 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2012-02-04 02:56:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2011-08-24 18:08:43 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2012-12-03 16:50:05 +00: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 04:16:09 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2012-02-04 02:56:59 +00: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"));
|
|
|
|
|
2010-05-18 17:22:19 +00:00
|
|
|
static cl::opt<bool> ShowMCEncoding("show-mc-encoding", cl::Hidden,
|
|
|
|
cl::desc("Show encoding in .s output"));
|
|
|
|
static cl::opt<bool> ShowMCInst("show-mc-inst", cl::Hidden,
|
|
|
|
cl::desc("Show instruction structure in .s output"));
|
2007-06-19 05:47:49 +00:00
|
|
|
|
2010-02-02 22:54:51 +00:00
|
|
|
static cl::opt<cl::boolOrDefault>
|
|
|
|
AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
|
|
|
|
cl::init(cl::BOU_UNSET));
|
|
|
|
|
2010-02-02 22:58:13 +00:00
|
|
|
static bool getVerboseAsm() {
|
2010-02-02 22:54:51 +00:00
|
|
|
switch (AsmVerbose) {
|
2010-02-02 22:58:13 +00:00
|
|
|
case cl::BOU_UNSET: return TargetMachine::getAsmVerbosityDefault();
|
|
|
|
case cl::BOU_TRUE: return true;
|
|
|
|
case cl::BOU_FALSE: return false;
|
2010-08-13 16:55:08 +00:00
|
|
|
}
|
2012-01-10 18:08:01 +00:00
|
|
|
llvm_unreachable("Invalid verbose asm state");
|
2010-02-02 22:54:51 +00:00
|
|
|
}
|
2010-01-13 00:30:23 +00:00
|
|
|
|
2013-05-13 01:16:13 +00:00
|
|
|
void LLVMTargetMachine::initAsmInfo() {
|
2014-02-13 14:44:26 +00:00
|
|
|
MCAsmInfo *TmpAsmInfo = TheTarget.createMCAsmInfo(*getRegisterInfo(),
|
|
|
|
TargetTriple);
|
2011-09-30 13:07:47 +00: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 14:44:26 +00:00
|
|
|
assert(TmpAsmInfo && "MCAsmInfo not initialized. "
|
2011-10-25 20:30:48 +00:00
|
|
|
"Make sure you include the correct TargetSelect.h"
|
|
|
|
"and that InitializeAllTargetMCs() is being invoked!");
|
2014-02-13 14:44:26 +00:00
|
|
|
|
2014-02-21 03:13:54 +00:00
|
|
|
if (Options.DisableIntegratedAS)
|
2014-02-13 14:44:26 +00:00
|
|
|
TmpAsmInfo->setUseIntegratedAssembler(false);
|
|
|
|
|
|
|
|
AsmInfo = TmpAsmInfo;
|
2009-08-12 07:22:17 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 01:16:13 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171681 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-07 01:37:14 +00:00
|
|
|
void LLVMTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
|
2013-06-19 20:51:24 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171681 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-07 01:37:14 +00:00
|
|
|
}
|
|
|
|
|
2012-02-04 02:56:59 +00:00
|
|
|
/// addPassesToX helper drives creation and initialization of TargetPassConfig.
|
|
|
|
static MCContext *addPassesToGenerateCode(LLVMTargetMachine *TM,
|
|
|
|
PassManagerBase &PM,
|
2012-07-02 19:48:45 +00:00
|
|
|
bool DisableVerify,
|
|
|
|
AnalysisID StartAfter,
|
|
|
|
AnalysisID StopAfter) {
|
2014-01-23 19:23:28 +00:00
|
|
|
// Add internal analysis passes from the target machine.
|
|
|
|
TM->addAnalysisPasses(PM);
|
|
|
|
|
2012-02-04 02:56:59 +00:00
|
|
|
// Targets may override createPassConfig to provide a target-specific sublass.
|
|
|
|
TargetPassConfig *PassConfig = TM->createPassConfig(PM);
|
2012-07-02 19:48:45 +00:00
|
|
|
PassConfig->setStartStopPasses(StartAfter, StopAfter);
|
2012-02-04 02:56:59 +00:00
|
|
|
|
|
|
|
// Set PassConfig options provided by TargetMachine.
|
|
|
|
PassConfig->setDisableVerify(DisableVerify);
|
|
|
|
|
2012-02-06 22:51:15 +00:00
|
|
|
PM.add(PassConfig);
|
|
|
|
|
2012-02-04 02:56:59 +00:00
|
|
|
PassConfig->addIRPasses();
|
|
|
|
|
2012-11-30 22:08:55 +00:00
|
|
|
PassConfig->addCodeGenPrepare();
|
|
|
|
|
2012-07-02 19:48:31 +00:00
|
|
|
PassConfig->addPassesToHandleExceptions();
|
2012-02-04 02:56:59 +00:00
|
|
|
|
|
|
|
PassConfig->addISelPrepare();
|
|
|
|
|
|
|
|
// Install a MachineModuleInfo class, which is an immutable pass that holds
|
|
|
|
// all the per-module stuff we're generating, including MCContext.
|
|
|
|
MachineModuleInfo *MMI =
|
|
|
|
new MachineModuleInfo(*TM->getMCAsmInfo(), *TM->getRegisterInfo(),
|
|
|
|
&TM->getTargetLowering()->getObjFileLowering());
|
|
|
|
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())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
PassConfig->addMachinePasses();
|
|
|
|
|
2012-02-08 21:22:39 +00:00
|
|
|
PassConfig->setInitialized();
|
|
|
|
|
2013-06-19 20:51:24 +00:00
|
|
|
return &MMI->getContext();
|
2012-02-04 02:56:59 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 05:55:08 +00:00
|
|
|
bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
|
|
|
|
formatted_raw_ostream &Out,
|
|
|
|
CodeGenFileType FileType,
|
2012-07-02 19:48:45 +00:00
|
|
|
bool DisableVerify,
|
|
|
|
AnalysisID StartAfter,
|
|
|
|
AnalysisID StopAfter) {
|
2008-09-25 00:37:07 +00:00
|
|
|
// Add common CodeGen passes.
|
2012-07-02 19:48:45 +00:00
|
|
|
MCContext *Context = addPassesToGenerateCode(this, PM, DisableVerify,
|
|
|
|
StartAfter, StopAfter);
|
2012-02-04 02:56:59 +00:00
|
|
|
if (!Context)
|
2010-02-03 05:55:08 +00:00
|
|
|
return true;
|
2007-02-08 01:36:53 +00:00
|
|
|
|
2012-07-02 19:48:45 +00: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 11:30:46 +00:00
|
|
|
PM.add(createPrintModulePass(Out));
|
2012-07-02 19:48:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-28 22:49:19 +00:00
|
|
|
if (hasMCSaveTempLabels())
|
|
|
|
Context->setAllowTemporaryLabels(false);
|
|
|
|
|
2010-03-11 22:53:35 +00:00
|
|
|
const MCAsmInfo &MAI = *getMCAsmInfo();
|
2012-05-20 11:24:27 +00:00
|
|
|
const MCRegisterInfo &MRI = *getRegisterInfo();
|
2013-06-18 06:07:26 +00:00
|
|
|
const MCInstrInfo &MII = *getInstrInfo();
|
2011-09-07 17:24:38 +00:00
|
|
|
const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
|
2010-02-02 23:45:17 +00:00
|
|
|
OwningPtr<MCStreamer> AsmStreamer;
|
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
switch (FileType) {
|
2010-02-03 00:29:55 +00:00
|
|
|
case CGFT_AssemblyFile: {
|
|
|
|
MCInstPrinter *InstPrinter =
|
2012-03-05 19:33:20 +00:00
|
|
|
getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI,
|
2013-06-18 06:07:26 +00:00
|
|
|
MII, MRI, STI);
|
2010-05-18 17:22:19 +00:00
|
|
|
|
|
|
|
// Create a code emitter if asked to show the encoding.
|
|
|
|
MCCodeEmitter *MCE = 0;
|
2013-09-09 19:48:37 +00:00
|
|
|
if (ShowMCEncoding)
|
2013-06-18 06:07:26 +00:00
|
|
|
MCE = getTarget().createMCCodeEmitter(MII, MRI, STI, *Context);
|
2010-05-18 17:22:19 +00:00
|
|
|
|
2013-09-09 19:48:37 +00:00
|
|
|
MCAsmBackend *MAB = getTarget().createMCAsmBackend(MRI, getTargetTriple(),
|
|
|
|
TargetCPU);
|
2010-12-10 07:39:47 +00:00
|
|
|
MCStreamer *S = getTarget().createAsmStreamer(*Context, Out,
|
|
|
|
getVerboseAsm(),
|
2011-04-30 03:44:37 +00:00
|
|
|
hasMCUseCFI(),
|
2011-10-17 23:05:28 +00:00
|
|
|
hasMCUseDwarfDirectory(),
|
2010-12-10 07:39:47 +00:00
|
|
|
InstPrinter,
|
2011-07-25 23:24:55 +00:00
|
|
|
MCE, MAB,
|
2011-06-17 20:55:01 +00:00
|
|
|
ShowMCInst);
|
2010-11-19 02:26:16 +00:00
|
|
|
AsmStreamer.reset(S);
|
2010-02-02 19:14:27 +00:00
|
|
|
break;
|
2010-02-03 00:29:55 +00:00
|
|
|
}
|
2010-02-02 23:57:42 +00:00
|
|
|
case CGFT_ObjectFile: {
|
|
|
|
// Create the code emitter for the target if it exists. If not, .o file
|
|
|
|
// emission fails.
|
2013-06-18 06:07:26 +00:00
|
|
|
MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(MII, MRI, STI,
|
|
|
|
*Context);
|
2013-09-09 02:37:14 +00:00
|
|
|
MCAsmBackend *MAB = getTarget().createMCAsmBackend(MRI, getTargetTriple(),
|
2012-11-22 14:10:40 +00:00
|
|
|
TargetCPU);
|
2011-07-25 23:24:55 +00:00
|
|
|
if (MCE == 0 || MAB == 0)
|
2010-02-03 05:55:08 +00:00
|
|
|
return true;
|
2010-05-26 21:48:55 +00:00
|
|
|
|
2014-01-26 06:38:58 +00:00
|
|
|
AsmStreamer.reset(getTarget().createMCObjectStreamer(
|
|
|
|
getTargetTriple(), *Context, *MAB, Out, MCE, STI, hasMCRelaxAll(),
|
|
|
|
hasMCNoExecStack()));
|
2010-02-02 23:57:42 +00:00
|
|
|
break;
|
2010-02-02 18:44:12 +00:00
|
|
|
}
|
2010-02-03 05:55:08 +00:00
|
|
|
case CGFT_Null:
|
|
|
|
// The Null output is intended for use for performance analysis and testing,
|
|
|
|
// not real users.
|
|
|
|
AsmStreamer.reset(createNullStreamer(*Context));
|
|
|
|
break;
|
2006-09-04 04:16:09 +00:00
|
|
|
}
|
2010-05-23 17:44:06 +00:00
|
|
|
|
2010-03-13 20:55:24 +00:00
|
|
|
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
|
2010-04-04 08:18:47 +00:00
|
|
|
FunctionPass *Printer = getTarget().createAsmPrinter(*this, *AsmStreamer);
|
2010-02-02 23:45:17 +00:00
|
|
|
if (Printer == 0)
|
2010-02-03 05:55:08 +00:00
|
|
|
return true;
|
2010-08-13 16:55:08 +00:00
|
|
|
|
2010-03-13 20:55:24 +00:00
|
|
|
// If successful, createAsmPrinter took ownership of AsmStreamer.
|
|
|
|
AsmStreamer.take();
|
2010-08-13 16:55:08 +00:00
|
|
|
|
2010-02-02 23:45:17 +00:00
|
|
|
PM.add(Printer);
|
2010-08-13 16:55:08 +00:00
|
|
|
|
2010-02-03 05:55:08 +00:00
|
|
|
return false;
|
2008-09-25 00:37:07 +00:00
|
|
|
}
|
|
|
|
|
2009-05-30 20:51:52 +00:00
|
|
|
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
|
2010-02-02 22:31:11 +00:00
|
|
|
/// get machine code emitted. This uses a JITCodeEmitter object to handle
|
2009-05-30 20:51:52 +00:00
|
|
|
/// actually outputting the machine code and resolving things like the address
|
2013-10-08 16:47:11 +00:00
|
|
|
/// of functions. This method should return true if machine code emission is
|
2009-05-30 20:51:52 +00:00
|
|
|
/// not supported.
|
|
|
|
///
|
|
|
|
bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
|
|
|
|
JITCodeEmitter &JCE,
|
2010-02-28 00:41:59 +00:00
|
|
|
bool DisableVerify) {
|
2009-05-30 20:51:52 +00:00
|
|
|
// Add common CodeGen passes.
|
2012-07-02 19:48:45 +00:00
|
|
|
MCContext *Context = addPassesToGenerateCode(this, PM, DisableVerify, 0, 0);
|
2012-02-04 02:56:59 +00:00
|
|
|
if (!Context)
|
2009-05-30 20:51:52 +00:00
|
|
|
return true;
|
|
|
|
|
2011-11-16 08:38:26 +00:00
|
|
|
addCodeEmitter(PM, JCE);
|
2009-05-30 20:51:52 +00:00
|
|
|
|
|
|
|
return false; // success!
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:58:53 +00: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-18 22:48:41 +00:00
|
|
|
raw_ostream &Out,
|
2010-07-22 05:58:53 +00:00
|
|
|
bool DisableVerify) {
|
|
|
|
// Add common CodeGen passes.
|
2012-07-02 19:48:45 +00:00
|
|
|
Ctx = addPassesToGenerateCode(this, PM, DisableVerify, 0, 0);
|
2012-02-04 02:56:59 +00:00
|
|
|
if (!Ctx)
|
2010-07-22 05:58:53 +00:00
|
|
|
return true;
|
2011-03-18 22:48:41 +00:00
|
|
|
|
2011-03-28 22:49:19 +00:00
|
|
|
if (hasMCSaveTempLabels())
|
|
|
|
Ctx->setAllowTemporaryLabels(false);
|
|
|
|
|
2011-03-18 22:48:41 +00:00
|
|
|
// Create the code emitter for the target if it exists. If not, .o file
|
|
|
|
// emission fails.
|
2012-05-20 17:24:08 +00:00
|
|
|
const MCRegisterInfo &MRI = *getRegisterInfo();
|
2011-07-11 03:57:24 +00:00
|
|
|
const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
|
2012-05-15 17:35:52 +00:00
|
|
|
MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(*getInstrInfo(), MRI,
|
|
|
|
STI, *Ctx);
|
2013-09-09 02:37:14 +00:00
|
|
|
MCAsmBackend *MAB = getTarget().createMCAsmBackend(MRI, getTargetTriple(),
|
|
|
|
TargetCPU);
|
2011-07-25 23:24:55 +00:00
|
|
|
if (MCE == 0 || MAB == 0)
|
2011-03-18 22:48:41 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
OwningPtr<MCStreamer> AsmStreamer;
|
2014-01-26 06:38:58 +00:00
|
|
|
AsmStreamer.reset(getTarget().createMCObjectStreamer(
|
|
|
|
getTargetTriple(), *Ctx, *MAB, Out, MCE, STI, hasMCRelaxAll(),
|
|
|
|
hasMCNoExecStack()));
|
2011-03-18 22:48:41 +00:00
|
|
|
|
|
|
|
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
|
|
|
|
FunctionPass *Printer = getTarget().createAsmPrinter(*this, *AsmStreamer);
|
|
|
|
if (Printer == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If successful, createAsmPrinter took ownership of AsmStreamer.
|
|
|
|
AsmStreamer.take();
|
|
|
|
|
|
|
|
PM.add(Printer);
|
|
|
|
|
2010-07-22 05:58:53 +00:00
|
|
|
return false; // success!
|
|
|
|
}
|