PPCTargetMachine.cpp 20 KB

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