LLVM API Documentation
00001 //===-- SystemZTargetMachine.cpp - Define TargetMachine for SystemZ -------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #include "SystemZTargetMachine.h" 00011 #include "llvm/CodeGen/Passes.h" 00012 #include "llvm/Support/TargetRegistry.h" 00013 #include "llvm/Transforms/Scalar.h" 00014 00015 using namespace llvm; 00016 00017 extern "C" void LLVMInitializeSystemZTarget() { 00018 // Register the target. 00019 RegisterTargetMachine<SystemZTargetMachine> X(TheSystemZTarget); 00020 } 00021 00022 SystemZTargetMachine::SystemZTargetMachine(const Target &T, StringRef TT, 00023 StringRef CPU, StringRef FS, 00024 const TargetOptions &Options, 00025 Reloc::Model RM, CodeModel::Model CM, 00026 CodeGenOpt::Level OL) 00027 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), 00028 Subtarget(TT, CPU, FS, *this) { 00029 initAsmInfo(); 00030 } 00031 00032 namespace { 00033 /// SystemZ Code Generator Pass Configuration Options. 00034 class SystemZPassConfig : public TargetPassConfig { 00035 public: 00036 SystemZPassConfig(SystemZTargetMachine *TM, PassManagerBase &PM) 00037 : TargetPassConfig(TM, PM) {} 00038 00039 SystemZTargetMachine &getSystemZTargetMachine() const { 00040 return getTM<SystemZTargetMachine>(); 00041 } 00042 00043 void addIRPasses() override; 00044 bool addInstSelector() override; 00045 bool addPreSched2() override; 00046 bool addPreEmitPass() override; 00047 }; 00048 } // end anonymous namespace 00049 00050 void SystemZPassConfig::addIRPasses() { 00051 TargetPassConfig::addIRPasses(); 00052 } 00053 00054 bool SystemZPassConfig::addInstSelector() { 00055 addPass(createSystemZISelDag(getSystemZTargetMachine(), getOptLevel())); 00056 return false; 00057 } 00058 00059 bool SystemZPassConfig::addPreSched2() { 00060 if (getOptLevel() != CodeGenOpt::None && 00061 getSystemZTargetMachine().getSubtargetImpl()->hasLoadStoreOnCond()) 00062 addPass(&IfConverterID); 00063 return true; 00064 } 00065 00066 bool SystemZPassConfig::addPreEmitPass() { 00067 // We eliminate comparisons here rather than earlier because some 00068 // transformations can change the set of available CC values and we 00069 // generally want those transformations to have priority. This is 00070 // especially true in the commonest case where the result of the comparison 00071 // is used by a single in-range branch instruction, since we will then 00072 // be able to fuse the compare and the branch instead. 00073 // 00074 // For example, two-address NILF can sometimes be converted into 00075 // three-address RISBLG. NILF produces a CC value that indicates whether 00076 // the low word is zero, but RISBLG does not modify CC at all. On the 00077 // other hand, 64-bit ANDs like NILL can sometimes be converted to RISBG. 00078 // The CC value produced by NILL isn't useful for our purposes, but the 00079 // value produced by RISBG can be used for any comparison with zero 00080 // (not just equality). So there are some transformations that lose 00081 // CC values (while still being worthwhile) and others that happen to make 00082 // the CC result more useful than it was originally. 00083 // 00084 // Another reason is that we only want to use BRANCH ON COUNT in cases 00085 // where we know that the count register is not going to be spilled. 00086 // 00087 // Doing it so late makes it more likely that a register will be reused 00088 // between the comparison and the branch, but it isn't clear whether 00089 // preventing that would be a win or not. 00090 if (getOptLevel() != CodeGenOpt::None) 00091 addPass(createSystemZElimComparePass(getSystemZTargetMachine())); 00092 if (getOptLevel() != CodeGenOpt::None) 00093 addPass(createSystemZShortenInstPass(getSystemZTargetMachine())); 00094 addPass(createSystemZLongBranchPass(getSystemZTargetMachine())); 00095 return true; 00096 } 00097 00098 TargetPassConfig *SystemZTargetMachine::createPassConfig(PassManagerBase &PM) { 00099 return new SystemZPassConfig(this, PM); 00100 }