Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/CodeGen/LLVMTargetMachine.cpp
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | |||||
TargetTransformInfo | TargetTransformInfo | ||||
LLVMTargetMachine::getTargetTransformInfo(const Function &F) { | LLVMTargetMachine::getTargetTransformInfo(const Function &F) { | ||||
return TargetTransformInfo(BasicTTIImpl(this, F)); | return TargetTransformInfo(BasicTTIImpl(this, F)); | ||||
} | } | ||||
/// addPassesToX helper drives creation and initialization of TargetPassConfig. | /// addPassesToX helper drives creation and initialization of TargetPassConfig. | ||||
static TargetPassConfig * | static TargetPassConfig * | ||||
addPassesToGenerateCode(LLVMTargetMachine &TM, PassManagerBase &PM, | addPassesToGenerateCode(LLVMTargetMachine &TM, PassManagerBase &PM, | ||||
bool DisableVerify, MachineModuleInfo &MMI) { | bool DisableVerify, | ||||
MachineModuleInfoWrapperPass &MMIWP) { | |||||
// Targets may override createPassConfig to provide a target-specific | // Targets may override createPassConfig to provide a target-specific | ||||
// subclass. | // subclass. | ||||
TargetPassConfig *PassConfig = TM.createPassConfig(PM); | TargetPassConfig *PassConfig = TM.createPassConfig(PM); | ||||
// Set PassConfig options provided by TargetMachine. | // Set PassConfig options provided by TargetMachine. | ||||
PassConfig->setDisableVerify(DisableVerify); | PassConfig->setDisableVerify(DisableVerify); | ||||
PM.add(PassConfig); | PM.add(PassConfig); | ||||
PM.add(&MMI); | PM.add(&MMIWP); | ||||
if (PassConfig->addISelPasses()) | if (PassConfig->addISelPasses()) | ||||
return nullptr; | return nullptr; | ||||
PassConfig->addMachinePasses(); | PassConfig->addMachinePasses(); | ||||
PassConfig->setInitialized(); | PassConfig->setInitialized(); | ||||
return PassConfig; | return PassConfig; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | FunctionPass *Printer = | ||||
getTarget().createAsmPrinter(*this, std::move(AsmStreamer)); | getTarget().createAsmPrinter(*this, std::move(AsmStreamer)); | ||||
if (!Printer) | if (!Printer) | ||||
return true; | return true; | ||||
PM.add(Printer); | PM.add(Printer); | ||||
return false; | return false; | ||||
} | } | ||||
bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, | bool LLVMTargetMachine::addPassesToEmitFile( | ||||
raw_pwrite_stream &Out, | PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, | ||||
raw_pwrite_stream *DwoOut, | CodeGenFileType FileType, bool DisableVerify, | ||||
CodeGenFileType FileType, | MachineModuleInfoWrapperPass *MMIWP) { | ||||
bool DisableVerify, | |||||
MachineModuleInfo *MMI) { | |||||
// Add common CodeGen passes. | // Add common CodeGen passes. | ||||
if (!MMI) | if (!MMIWP) | ||||
MMI = new MachineModuleInfo(this); | MMIWP = new MachineModuleInfoWrapperPass(this); | ||||
TargetPassConfig *PassConfig = | TargetPassConfig *PassConfig = | ||||
addPassesToGenerateCode(*this, PM, DisableVerify, *MMI); | addPassesToGenerateCode(*this, PM, DisableVerify, *MMIWP); | ||||
if (!PassConfig) | if (!PassConfig) | ||||
return true; | return true; | ||||
if (!TargetPassConfig::willCompleteCodeGenPipeline()) { | if (!TargetPassConfig::willCompleteCodeGenPipeline()) { | ||||
if (this->getTargetTriple().isOSAIX()) { | if (this->getTargetTriple().isOSAIX()) { | ||||
// On AIX, we might manifest MCSymbols during SDAG lowering. For MIR | // On AIX, we might manifest MCSymbols during SDAG lowering. For MIR | ||||
// testing to be meaningful, we need to ensure that the symbols created | // testing to be meaningful, we need to ensure that the symbols created | ||||
// are MCSymbolXCOFF variants, which requires that | // are MCSymbolXCOFF variants, which requires that | ||||
// the TargetLoweringObjectFile instance has been initialized. | // the TargetLoweringObjectFile instance has been initialized. | ||||
MCContext &Ctx = MMI->getContext(); | MCContext &Ctx = MMIWP->getMMI().getContext(); | ||||
const_cast<TargetLoweringObjectFile &>(*this->getObjFileLowering()) | const_cast<TargetLoweringObjectFile &>(*this->getObjFileLowering()) | ||||
.Initialize(Ctx, *this); | .Initialize(Ctx, *this); | ||||
} | } | ||||
PM.add(createPrintMIRPass(Out)); | PM.add(createPrintMIRPass(Out)); | ||||
} else if (addAsmPrinter(PM, Out, DwoOut, FileType, MMI->getContext())) | } else if (addAsmPrinter(PM, Out, DwoOut, FileType, | ||||
MMIWP->getMMI().getContext())) | |||||
return true; | return true; | ||||
PM.add(createFreeMachineFunctionPass()); | PM.add(createFreeMachineFunctionPass()); | ||||
return false; | return false; | ||||
} | } | ||||
/// addPassesToEmitMC - Add passes to the specified pass manager to get | /// addPassesToEmitMC - Add passes to the specified pass manager to get | ||||
/// machine code emitted with the MCJIT. This method returns true if machine | /// 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 | /// code is not supported. It fills the MCContext Ctx pointer which can be | ||||
/// used to build custom MCStreamer. | /// used to build custom MCStreamer. | ||||
/// | /// | ||||
bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx, | bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx, | ||||
raw_pwrite_stream &Out, | raw_pwrite_stream &Out, | ||||
bool DisableVerify) { | bool DisableVerify) { | ||||
// Add common CodeGen passes. | // Add common CodeGen passes. | ||||
MachineModuleInfo *MMI = new MachineModuleInfo(this); | MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass(this); | ||||
TargetPassConfig *PassConfig = | TargetPassConfig *PassConfig = | ||||
addPassesToGenerateCode(*this, PM, DisableVerify, *MMI); | addPassesToGenerateCode(*this, PM, DisableVerify, *MMIWP); | ||||
if (!PassConfig) | if (!PassConfig) | ||||
return true; | return true; | ||||
assert(TargetPassConfig::willCompleteCodeGenPipeline() && | assert(TargetPassConfig::willCompleteCodeGenPipeline() && | ||||
"Cannot emit MC with limited codegen pipeline"); | "Cannot emit MC with limited codegen pipeline"); | ||||
Ctx = &MMI->getContext(); | Ctx = &MMIWP->getMMI().getContext(); | ||||
if (Options.MCOptions.MCSaveTempLabels) | if (Options.MCOptions.MCSaveTempLabels) | ||||
Ctx->setAllowTemporaryLabels(false); | Ctx->setAllowTemporaryLabels(false); | ||||
// Create the code emitter for the target if it exists. If not, .o file | // Create the code emitter for the target if it exists. If not, .o file | ||||
// emission fails. | // emission fails. | ||||
const MCSubtargetInfo &STI = *getMCSubtargetInfo(); | const MCSubtargetInfo &STI = *getMCSubtargetInfo(); | ||||
const MCRegisterInfo &MRI = *getMCRegisterInfo(); | const MCRegisterInfo &MRI = *getMCRegisterInfo(); | ||||
MCCodeEmitter *MCE = | MCCodeEmitter *MCE = | ||||
Show All 24 Lines |