#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/TLSVariableHoist.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iterator>
#include <utility>
usingnamespacellvm;
usingnamespacetlshoist;
#define DEBUG_TYPE …
static cl::opt<bool> TLSLoadHoist(
"tls-load-hoist", cl::init(false), cl::Hidden,
cl::desc("hoist the TLS loads in PIC model to eliminate redundant "
"TLS address calculation."));
namespace {
class TLSVariableHoistLegacyPass : public FunctionPass { … };
}
char TLSVariableHoistLegacyPass::ID = …;
INITIALIZE_PASS_BEGIN(TLSVariableHoistLegacyPass, "tlshoist",
"TLS Variable Hoist", false, false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_END(TLSVariableHoistLegacyPass, "tlshoist",
"TLS Variable Hoist", false, false)
FunctionPass *llvm::createTLSVariableHoistPass() { … }
bool TLSVariableHoistLegacyPass::runOnFunction(Function &Fn) { … }
void TLSVariableHoistPass::collectTLSCandidate(Instruction *Inst) { … }
void TLSVariableHoistPass::collectTLSCandidates(Function &Fn) { … }
static bool oneUseOutsideLoop(tlshoist::TLSCandidate &Cand, LoopInfo *LI) { … }
Instruction *TLSVariableHoistPass::getNearestLoopDomInst(BasicBlock *BB,
Loop *L) { … }
Instruction *TLSVariableHoistPass::getDomInst(Instruction *I1,
Instruction *I2) { … }
BasicBlock::iterator TLSVariableHoistPass::findInsertPos(Function &Fn,
GlobalVariable *GV,
BasicBlock *&PosBB) { … }
Instruction *TLSVariableHoistPass::genBitCastInst(Function &Fn,
GlobalVariable *GV) { … }
bool TLSVariableHoistPass::tryReplaceTLSCandidate(Function &Fn,
GlobalVariable *GV) { … }
bool TLSVariableHoistPass::tryReplaceTLSCandidates(Function &Fn) { … }
bool TLSVariableHoistPass::runImpl(Function &Fn, DominatorTree &DT,
LoopInfo &LI) { … }
PreservedAnalyses TLSVariableHoistPass::run(Function &F,
FunctionAnalysisManager &AM) { … }