//===-- SystemZLDCleanup.cpp - Clean up local-dynamic TLS accesses --------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This pass combines multiple accesses to local-dynamic TLS variables so that // the TLS base address for the module is only fetched once per execution path // through the function. // //===----------------------------------------------------------------------===// #include "SystemZMachineFunctionInfo.h" #include "SystemZTargetMachine.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/Target/TargetMachine.h" usingnamespacellvm; namespace { class SystemZLDCleanup : public MachineFunctionPass { … }; char SystemZLDCleanup::ID = …; } // end anonymous namespace INITIALIZE_PASS(…) FunctionPass *llvm::createSystemZLDCleanupPass(SystemZTargetMachine &TM) { … } void SystemZLDCleanup::getAnalysisUsage(AnalysisUsage &AU) const { … } bool SystemZLDCleanup::runOnMachineFunction(MachineFunction &F) { … } // Visit the dominator subtree rooted at Node in pre-order. // If TLSBaseAddrReg is non-null, then use that to replace any // TLS_LDCALL instructions. Otherwise, create the register // when the first such instruction is seen, and then use it // as we encounter more instructions. bool SystemZLDCleanup::VisitNode(MachineDomTreeNode *Node, unsigned TLSBaseAddrReg) { … } // Replace the TLS_LDCALL instruction I with a copy from TLSBaseAddrReg, // returning the new instruction. MachineInstr *SystemZLDCleanup::ReplaceTLSCall(MachineInstr *I, unsigned TLSBaseAddrReg) { … } // Create a virtual register in *TLSBaseAddrReg, and populate it by // inserting a copy instruction after I. Returns the new instruction. MachineInstr *SystemZLDCleanup::SetRegister(MachineInstr *I, unsigned *TLSBaseAddrReg) { … }