1 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Top-level implementation for the PowerPC target. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "PPCTargetMachine.h" 14 #include "MCTargetDesc/PPCMCTargetDesc.h" 15 #include "PPC.h" 16 #include "PPCMachineScheduler.h" 17 #include "PPCMacroFusion.h" 18 #include "PPCSubtarget.h" 19 #include "PPCTargetObjectFile.h" 20 #include "PPCTargetTransformInfo.h" 21 #include "TargetInfo/PowerPCTargetInfo.h" 22 #include "llvm/ADT/Optional.h" 23 #include "llvm/ADT/STLExtras.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/ADT/Triple.h" 26 #include "llvm/Analysis/TargetTransformInfo.h" 27 #include "llvm/CodeGen/GlobalISel/IRTranslator.h" 28 #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" 29 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h" 30 #include "llvm/CodeGen/GlobalISel/Legalizer.h" 31 #include "llvm/CodeGen/GlobalISel/Localizer.h" 32 #include "llvm/CodeGen/GlobalISel/RegBankSelect.h" 33 #include "llvm/CodeGen/MachineScheduler.h" 34 #include "llvm/CodeGen/Passes.h" 35 #include "llvm/CodeGen/TargetPassConfig.h" 36 #include "llvm/IR/Attributes.h" 37 #include "llvm/IR/DataLayout.h" 38 #include "llvm/IR/Function.h" 39 #include "llvm/InitializePasses.h" 40 #include "llvm/MC/TargetRegistry.h" 41 #include "llvm/Pass.h" 42 #include "llvm/Support/CodeGen.h" 43 #include "llvm/Support/CommandLine.h" 44 #include "llvm/Target/TargetLoweringObjectFile.h" 45 #include "llvm/Target/TargetOptions.h" 46 #include "llvm/Transforms/Scalar.h" 47 #include <cassert> 48 #include <memory> 49 #include <string> 50 51 using namespace llvm; 52 53 54 static cl::opt<bool> 55 EnableBranchCoalescing("enable-ppc-branch-coalesce", cl::Hidden, 56 cl::desc("enable coalescing of duplicate branches for PPC")); 57 static cl:: 58 opt<bool> DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden, 59 cl::desc("Disable CTR loops for PPC")); 60 61 static cl:: 62 opt<bool> DisableInstrFormPrep("disable-ppc-instr-form-prep", cl::Hidden, 63 cl::desc("Disable PPC loop instr form prep")); 64 65 static cl::opt<bool> 66 VSXFMAMutateEarly("schedule-ppc-vsx-fma-mutation-early", 67 cl::Hidden, cl::desc("Schedule VSX FMA instruction mutation early")); 68 69 static cl:: 70 opt<bool> DisableVSXSwapRemoval("disable-ppc-vsx-swap-removal", cl::Hidden, 71 cl::desc("Disable VSX Swap Removal for PPC")); 72 73 static cl:: 74 opt<bool> DisableMIPeephole("disable-ppc-peephole", cl::Hidden, 75 cl::desc("Disable machine peepholes for PPC")); 76 77 static cl::opt<bool> 78 EnableGEPOpt("ppc-gep-opt", cl::Hidden, 79 cl::desc("Enable optimizations on complex GEPs"), 80 cl::init(true)); 81 82 static cl::opt<bool> 83 EnablePrefetch("enable-ppc-prefetching", 84 cl::desc("enable software prefetching on PPC"), 85 cl::init(false), cl::Hidden); 86 87 static cl::opt<bool> 88 EnableExtraTOCRegDeps("enable-ppc-extra-toc-reg-deps", 89 cl::desc("Add extra TOC register dependencies"), 90 cl::init(true), cl::Hidden); 91 92 static cl::opt<bool> 93 EnableMachineCombinerPass("ppc-machine-combiner", 94 cl::desc("Enable the machine combiner pass"), 95 cl::init(true), cl::Hidden); 96 97 static cl::opt<bool> 98 ReduceCRLogical("ppc-reduce-cr-logicals", 99 cl::desc("Expand eligible cr-logical binary ops to branches"), 100 cl::init(true), cl::Hidden); 101 102 static cl::opt<bool> EnablePPCGenScalarMASSEntries( 103 "enable-ppc-gen-scalar-mass", cl::init(false), 104 cl::desc("Enable lowering math functions to their corresponding MASS " 105 "(scalar) entries"), 106 cl::Hidden); 107 108 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCTarget() { 109 // Register the targets 110 RegisterTargetMachine<PPCTargetMachine> A(getThePPC32Target()); 111 RegisterTargetMachine<PPCTargetMachine> B(getThePPC32LETarget()); 112 RegisterTargetMachine<PPCTargetMachine> C(getThePPC64Target()); 113 RegisterTargetMachine<PPCTargetMachine> D(getThePPC64LETarget()); 114 115 PassRegistry &PR = *PassRegistry::getPassRegistry(); 116 #ifndef NDEBUG 117 initializePPCCTRLoopsVerifyPass(PR); 118 #endif 119 initializePPCLoopInstrFormPrepPass(PR); 120 initializePPCTOCRegDepsPass(PR); 121 initializePPCEarlyReturnPass(PR); 122 initializePPCVSXCopyPass(PR); 123 initializePPCVSXFMAMutatePass(PR); 124 initializePPCVSXSwapRemovalPass(PR); 125 initializePPCReduceCRLogicalsPass(PR); 126 initializePPCBSelPass(PR); 127 initializePPCBranchCoalescingPass(PR); 128 initializePPCBoolRetToIntPass(PR); 129 initializePPCExpandISELPass(PR); 130 initializePPCPreEmitPeepholePass(PR); 131 initializePPCTLSDynamicCallPass(PR); 132 initializePPCMIPeepholePass(PR); 133 initializePPCLowerMASSVEntriesPass(PR); 134 initializePPCGenScalarMASSEntriesPass(PR); 135 initializePPCExpandAtomicPseudoPass(PR); 136 initializeGlobalISel(PR); 137 initializePPCCTRLoopsPass(PR); 138 } 139 140 static bool isLittleEndianTriple(const Triple &T) { 141 return T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle; 142 } 143 144 /// Return the datalayout string of a subtarget. 145 static std::string getDataLayoutString(const Triple &T) { 146 bool is64Bit = T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le; 147 std::string Ret; 148 149 // Most PPC* platforms are big endian, PPC(64)LE is little endian. 150 if (isLittleEndianTriple(T)) 151 Ret = "e"; 152 else 153 Ret = "E"; 154 155 Ret += DataLayout::getManglingComponent(T); 156 157 // PPC32 has 32 bit pointers. The PS3 (OS Lv2) is a PPC64 machine with 32 bit 158 // pointers. 159 if (!is64Bit || T.getOS() == Triple::Lv2) 160 Ret += "-p:32:32"; 161 162 // Note, the alignment values for f64 and i64 on ppc64 in Darwin 163 // documentation are wrong; these are correct (i.e. "what gcc does"). 164 Ret += "-i64:64"; 165 166 // PPC64 has 32 and 64 bit registers, PPC32 has only 32 bit ones. 167 if (is64Bit) 168 Ret += "-n32:64"; 169 else 170 Ret += "-n32"; 171 172 // Specify the vector alignment explicitly. For v256i1 and v512i1, the 173 // calculated alignment would be 256*alignment(i1) and 512*alignment(i1), 174 // which is 256 and 512 bytes - way over aligned. 175 if (is64Bit && (T.isOSAIX() || T.isOSLinux())) 176 Ret += "-S128-v256:256:256-v512:512:512"; 177 178 return Ret; 179 } 180 181 static std::string computeFSAdditions(StringRef FS, CodeGenOpt::Level OL, 182 const Triple &TT) { 183 std::string FullFS = std::string(FS); 184 185 // Make sure 64-bit features are available when CPUname is generic 186 if (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le) { 187 if (!FullFS.empty()) 188 FullFS = "+64bit," + FullFS; 189 else 190 FullFS = "+64bit"; 191 } 192 193 if (OL >= CodeGenOpt::Default) { 194 if (!FullFS.empty()) 195 FullFS = "+crbits," + FullFS; 196 else 197 FullFS = "+crbits"; 198 } 199 200 if (OL != CodeGenOpt::None) { 201 if (!FullFS.empty()) 202 FullFS = "+invariant-function-descriptors," + FullFS; 203 else 204 FullFS = "+invariant-function-descriptors"; 205 } 206 207 if (TT.isOSAIX()) { 208 if (!FullFS.empty()) 209 FullFS = "+aix," + FullFS; 210 else 211 FullFS = "+aix"; 212 } 213 214 return FullFS; 215 } 216 217 static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) { 218 if (TT.isOSAIX()) 219 return std::make_unique<TargetLoweringObjectFileXCOFF>(); 220 221 return std::make_unique<PPC64LinuxTargetObjectFile>(); 222 } 223 224 static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT, 225 const TargetOptions &Options) { 226 if (Options.MCOptions.getABIName().startswith("elfv1")) 227 return PPCTargetMachine::PPC_ABI_ELFv1; 228 else if (Options.MCOptions.getABIName().startswith("elfv2")) 229 return PPCTargetMachine::PPC_ABI_ELFv2; 230 231 assert(Options.MCOptions.getABIName().empty() && 232 "Unknown target-abi option!"); 233 234 if (TT.isMacOSX()) { 235 return PPCTargetMachine::PPC_ABI_UNKNOWN; 236 } else if (TT.isOSFreeBSD() && TT.getArch() == Triple::ppc64 && (TT.getOSMajorVersion() == 0 || TT.getOSMajorVersion() >= 13)) { 237 return PPCTargetMachine::PPC_ABI_ELFv2; 238 } 239 240 switch (TT.getArch()) { 241 case Triple::ppc64le: 242 return PPCTargetMachine::PPC_ABI_ELFv2; 243 case Triple::ppc64: 244 return PPCTargetMachine::PPC_ABI_ELFv1; 245 default: 246 return PPCTargetMachine::PPC_ABI_UNKNOWN; 247 } 248 } 249 250 static Reloc::Model getEffectiveRelocModel(const Triple &TT, 251 Optional<Reloc::Model> RM) { 252 assert((!TT.isOSAIX() || !RM || *RM == Reloc::PIC_) && 253 "Invalid relocation model for AIX."); 254 255 if (RM) 256 return *RM; 257 258 // Big Endian PPC and AIX default to PIC. 259 if (TT.getArch() == Triple::ppc64 || TT.isOSAIX()) 260 return Reloc::PIC_; 261 262 // Rest are static by default. 263 return Reloc::Static; 264 } 265 266 static CodeModel::Model getEffectivePPCCodeModel(const Triple &TT, 267 Optional<CodeModel::Model> CM, 268 bool JIT) { 269 if (CM) { 270 if (*CM == CodeModel::Tiny) 271 report_fatal_error("Target does not support the tiny CodeModel", false); 272 if (*CM == CodeModel::Kernel) 273 report_fatal_error("Target does not support the kernel CodeModel", false); 274 return *CM; 275 } 276 277 if (JIT) 278 return CodeModel::Small; 279 if (TT.isOSAIX()) 280 return CodeModel::Small; 281 282 assert(TT.isOSBinFormatELF() && "All remaining PPC OSes are ELF based."); 283 284 if (TT.isArch32Bit()) 285 return CodeModel::Small; 286 287 assert(TT.isArch64Bit() && "Unsupported PPC architecture."); 288 return CodeModel::Medium; 289 } 290 291 292 static ScheduleDAGInstrs *createPPCMachineScheduler(MachineSchedContext *C) { 293 const PPCSubtarget &ST = C->MF->getSubtarget<PPCSubtarget>(); 294 ScheduleDAGMILive *DAG = 295 new ScheduleDAGMILive(C, ST.usePPCPreRASchedStrategy() ? 296 std::make_unique<PPCPreRASchedStrategy>(C) : 297 std::make_unique<GenericScheduler>(C)); 298 // add DAG Mutations here. 299 DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI)); 300 if (ST.hasStoreFusion()) 301 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI)); 302 if (ST.hasFusion()) 303 DAG->addMutation(createPowerPCMacroFusionDAGMutation()); 304 305 return DAG; 306 } 307 308 static ScheduleDAGInstrs *createPPCPostMachineScheduler( 309 MachineSchedContext *C) { 310 const PPCSubtarget &ST = C->MF->getSubtarget<PPCSubtarget>(); 311 ScheduleDAGMI *DAG = 312 new ScheduleDAGMI(C, ST.usePPCPostRASchedStrategy() ? 313 std::make_unique<PPCPostRASchedStrategy>(C) : 314 std::make_unique<PostGenericScheduler>(C), true); 315 // add DAG Mutations here. 316 if (ST.hasStoreFusion()) 317 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI)); 318 if (ST.hasFusion()) 319 DAG->addMutation(createPowerPCMacroFusionDAGMutation()); 320 return DAG; 321 } 322 323 // The FeatureString here is a little subtle. We are modifying the feature 324 // string with what are (currently) non-function specific overrides as it goes 325 // into the LLVMTargetMachine constructor and then using the stored value in the 326 // Subtarget constructor below it. 327 PPCTargetMachine::PPCTargetMachine(const Target &T, const Triple &TT, 328 StringRef CPU, StringRef FS, 329 const TargetOptions &Options, 330 Optional<Reloc::Model> RM, 331 Optional<CodeModel::Model> CM, 332 CodeGenOpt::Level OL, bool JIT) 333 : LLVMTargetMachine(T, getDataLayoutString(TT), TT, CPU, 334 computeFSAdditions(FS, OL, TT), Options, 335 getEffectiveRelocModel(TT, RM), 336 getEffectivePPCCodeModel(TT, CM, JIT), OL), 337 TLOF(createTLOF(getTargetTriple())), 338 TargetABI(computeTargetABI(TT, Options)), 339 Endianness(isLittleEndianTriple(TT) ? Endian::LITTLE : Endian::BIG) { 340 initAsmInfo(); 341 } 342 343 PPCTargetMachine::~PPCTargetMachine() = default; 344 345 const PPCSubtarget * 346 PPCTargetMachine::getSubtargetImpl(const Function &F) const { 347 Attribute CPUAttr = F.getFnAttribute("target-cpu"); 348 Attribute FSAttr = F.getFnAttribute("target-features"); 349 350 std::string CPU = 351 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU; 352 std::string FS = 353 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS; 354 355 // FIXME: This is related to the code below to reset the target options, 356 // we need to know whether or not the soft float flag is set on the 357 // function before we can generate a subtarget. We also need to use 358 // it as a key for the subtarget since that can be the only difference 359 // between two functions. 360 bool SoftFloat = F.getFnAttribute("use-soft-float").getValueAsBool(); 361 // If the soft float attribute is set on the function turn on the soft float 362 // subtarget feature. 363 if (SoftFloat) 364 FS += FS.empty() ? "-hard-float" : ",-hard-float"; 365 366 auto &I = SubtargetMap[CPU + FS]; 367 if (!I) { 368 // This needs to be done before we create a new subtarget since any 369 // creation will depend on the TM and the code generation flags on the 370 // function that reside in TargetOptions. 371 resetTargetOptions(F); 372 I = std::make_unique<PPCSubtarget>( 373 TargetTriple, CPU, 374 // FIXME: It would be good to have the subtarget additions here 375 // not necessary. Anything that turns them on/off (overrides) ends 376 // up being put at the end of the feature string, but the defaults 377 // shouldn't require adding them. Fixing this means pulling Feature64Bit 378 // out of most of the target cpus in the .td file and making it set only 379 // as part of initialization via the TargetTriple. 380 computeFSAdditions(FS, getOptLevel(), getTargetTriple()), *this); 381 } 382 return I.get(); 383 } 384 385 //===----------------------------------------------------------------------===// 386 // Pass Pipeline Configuration 387 //===----------------------------------------------------------------------===// 388 389 namespace { 390 391 /// PPC Code Generator Pass Configuration Options. 392 class PPCPassConfig : public TargetPassConfig { 393 public: 394 PPCPassConfig(PPCTargetMachine &TM, PassManagerBase &PM) 395 : TargetPassConfig(TM, PM) { 396 // At any optimization level above -O0 we use the Machine Scheduler and not 397 // the default Post RA List Scheduler. 398 if (TM.getOptLevel() != CodeGenOpt::None) 399 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID); 400 } 401 402 PPCTargetMachine &getPPCTargetMachine() const { 403 return getTM<PPCTargetMachine>(); 404 } 405 406 void addIRPasses() override; 407 bool addPreISel() override; 408 bool addILPOpts() override; 409 bool addInstSelector() override; 410 void addMachineSSAOptimization() override; 411 void addPreRegAlloc() override; 412 void addPreSched2() override; 413 void addPreEmitPass() override; 414 void addPreEmitPass2() override; 415 // GlobalISEL 416 bool addIRTranslator() override; 417 bool addLegalizeMachineIR() override; 418 bool addRegBankSelect() override; 419 bool addGlobalInstructionSelect() override; 420 421 ScheduleDAGInstrs * 422 createMachineScheduler(MachineSchedContext *C) const override { 423 return createPPCMachineScheduler(C); 424 } 425 ScheduleDAGInstrs * 426 createPostMachineScheduler(MachineSchedContext *C) const override { 427 return createPPCPostMachineScheduler(C); 428 } 429 }; 430 431 } // end anonymous namespace 432 433 TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) { 434 return new PPCPassConfig(*this, PM); 435 } 436 437 void PPCPassConfig::addIRPasses() { 438 if (TM->getOptLevel() != CodeGenOpt::None) 439 addPass(createPPCBoolRetToIntPass()); 440 addPass(createAtomicExpandPass()); 441 442 // Lower generic MASSV routines to PowerPC subtarget-specific entries. 443 addPass(createPPCLowerMASSVEntriesPass()); 444 445 // Generate PowerPC target-specific entries for scalar math functions 446 // that are available in IBM MASS (scalar) library. 447 if (TM->getOptLevel() == CodeGenOpt::Aggressive && 448 EnablePPCGenScalarMASSEntries) { 449 TM->Options.PPCGenScalarMASSEntries = EnablePPCGenScalarMASSEntries; 450 addPass(createPPCGenScalarMASSEntriesPass()); 451 } 452 453 // If explicitly requested, add explicit data prefetch intrinsics. 454 if (EnablePrefetch.getNumOccurrences() > 0) 455 addPass(createLoopDataPrefetchPass()); 456 457 if (TM->getOptLevel() >= CodeGenOpt::Default && EnableGEPOpt) { 458 // Call SeparateConstOffsetFromGEP pass to extract constants within indices 459 // and lower a GEP with multiple indices to either arithmetic operations or 460 // multiple GEPs with single index. 461 addPass(createSeparateConstOffsetFromGEPPass(true)); 462 // Call EarlyCSE pass to find and remove subexpressions in the lowered 463 // result. 464 addPass(createEarlyCSEPass()); 465 // Do loop invariant code motion in case part of the lowered result is 466 // invariant. 467 addPass(createLICMPass()); 468 } 469 470 TargetPassConfig::addIRPasses(); 471 } 472 473 bool PPCPassConfig::addPreISel() { 474 if (!DisableInstrFormPrep && getOptLevel() != CodeGenOpt::None) 475 addPass(createPPCLoopInstrFormPrepPass(getPPCTargetMachine())); 476 477 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None) 478 addPass(createHardwareLoopsPass()); 479 480 return false; 481 } 482 483 bool PPCPassConfig::addILPOpts() { 484 addPass(&EarlyIfConverterID); 485 486 if (EnableMachineCombinerPass) 487 addPass(&MachineCombinerID); 488 489 return true; 490 } 491 492 bool PPCPassConfig::addInstSelector() { 493 // Install an instruction selector. 494 addPass(createPPCISelDag(getPPCTargetMachine(), getOptLevel())); 495 496 #ifndef NDEBUG 497 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None) 498 addPass(createPPCCTRLoopsVerify()); 499 #endif 500 501 addPass(createPPCVSXCopyPass()); 502 return false; 503 } 504 505 void PPCPassConfig::addMachineSSAOptimization() { 506 // PPCBranchCoalescingPass need to be done before machine sinking 507 // since it merges empty blocks. 508 if (EnableBranchCoalescing && getOptLevel() != CodeGenOpt::None) 509 addPass(createPPCBranchCoalescingPass()); 510 TargetPassConfig::addMachineSSAOptimization(); 511 // For little endian, remove where possible the vector swap instructions 512 // introduced at code generation to normalize vector element order. 513 if (TM->getTargetTriple().getArch() == Triple::ppc64le && 514 !DisableVSXSwapRemoval) 515 addPass(createPPCVSXSwapRemovalPass()); 516 // Reduce the number of cr-logical ops. 517 if (ReduceCRLogical && getOptLevel() != CodeGenOpt::None) 518 addPass(createPPCReduceCRLogicalsPass()); 519 // Target-specific peephole cleanups performed after instruction 520 // selection. 521 if (!DisableMIPeephole) { 522 addPass(createPPCMIPeepholePass()); 523 addPass(&DeadMachineInstructionElimID); 524 } 525 } 526 527 void PPCPassConfig::addPreRegAlloc() { 528 if (getOptLevel() != CodeGenOpt::None) { 529 initializePPCVSXFMAMutatePass(*PassRegistry::getPassRegistry()); 530 insertPass(VSXFMAMutateEarly ? &RegisterCoalescerID : &MachineSchedulerID, 531 &PPCVSXFMAMutateID); 532 } 533 534 // FIXME: We probably don't need to run these for -fPIE. 535 if (getPPCTargetMachine().isPositionIndependent()) { 536 // FIXME: LiveVariables should not be necessary here! 537 // PPCTLSDynamicCallPass uses LiveIntervals which previously dependent on 538 // LiveVariables. This (unnecessary) dependency has been removed now, 539 // however a stage-2 clang build fails without LiveVariables computed here. 540 addPass(&LiveVariablesID); 541 addPass(createPPCTLSDynamicCallPass()); 542 } 543 if (EnableExtraTOCRegDeps) 544 addPass(createPPCTOCRegDepsPass()); 545 546 // Run CTR loops pass before MachinePipeliner pass. 547 // MachinePipeliner will pipeline all instructions before the terminator, but 548 // we don't want DecreaseCTRPseudo to be pipelined. 549 // Note we may lose some MachinePipeliner opportunities if we run CTR loops 550 // generation pass before MachinePipeliner and the loop is converted back to 551 // a normal loop. We can revisit this later for running PPCCTRLoops after 552 // MachinePipeliner and handling DecreaseCTRPseudo in MachinePipeliner pass. 553 if (getOptLevel() != CodeGenOpt::None) 554 addPass(createPPCCTRLoopsPass()); 555 556 if (getOptLevel() != CodeGenOpt::None) 557 addPass(&MachinePipelinerID); 558 } 559 560 void PPCPassConfig::addPreSched2() { 561 if (getOptLevel() != CodeGenOpt::None) 562 addPass(&IfConverterID); 563 } 564 565 void PPCPassConfig::addPreEmitPass() { 566 addPass(createPPCPreEmitPeepholePass()); 567 addPass(createPPCExpandISELPass()); 568 569 if (getOptLevel() != CodeGenOpt::None) 570 addPass(createPPCEarlyReturnPass()); 571 } 572 573 void PPCPassConfig::addPreEmitPass2() { 574 // Schedule the expansion of AMOs at the last possible moment, avoiding the 575 // possibility for other passes to break the requirements for forward 576 // progress in the LL/SC block. 577 addPass(createPPCExpandAtomicPseudoPass()); 578 // Must run branch selection immediately preceding the asm printer. 579 addPass(createPPCBranchSelectionPass()); 580 } 581 582 TargetTransformInfo 583 PPCTargetMachine::getTargetTransformInfo(const Function &F) const { 584 return TargetTransformInfo(PPCTTIImpl(this, F)); 585 } 586 587 bool PPCTargetMachine::isLittleEndian() const { 588 assert(Endianness != Endian::NOT_DETECTED && 589 "Unable to determine endianness"); 590 return Endianness == Endian::LITTLE; 591 } 592 593 static MachineSchedRegistry 594 PPCPreRASchedRegistry("ppc-prera", 595 "Run PowerPC PreRA specific scheduler", 596 createPPCMachineScheduler); 597 598 static MachineSchedRegistry 599 PPCPostRASchedRegistry("ppc-postra", 600 "Run PowerPC PostRA specific scheduler", 601 createPPCPostMachineScheduler); 602 603 // Global ISEL 604 bool PPCPassConfig::addIRTranslator() { 605 addPass(new IRTranslator()); 606 return false; 607 } 608 609 bool PPCPassConfig::addLegalizeMachineIR() { 610 addPass(new Legalizer()); 611 return false; 612 } 613 614 bool PPCPassConfig::addRegBankSelect() { 615 addPass(new RegBankSelect()); 616 return false; 617 } 618 619 bool PPCPassConfig::addGlobalInstructionSelect() { 620 addPass(new InstructionSelect(getOptLevel())); 621 return false; 622 } 623