31#define DEBUG_TYPE "lower-emutls"
42 bool runOnModule(
Module &M)
override;
62 for (
const auto &
G : M.globals()) {
63 if (
G.isThreadLocal())
66 for (
const auto *
G : TlsVars)
78char LowerEmuTLS::ID = 0;
81 "Add __emutls_[vt]. variables for emultated TLS model",
false,
86bool LowerEmuTLS::runOnModule(
Module &M) {
90 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
95 if (!
TM.useEmulatedTLS())
100 for (
const auto &
G :
M.globals()) {
101 if (
G.isThreadLocal())
104 for (
const auto *
const G : TlsVars)
113 std::string EmuTlsVarName = (
"__emutls_v." + GV->
getName()).str();
122 const Constant *InitValue =
nullptr;
129 (InitIntValue && InitIntValue->
isZero()))
141 Type *ElementTypes[4] = {WordType, WordType, VoidPtrType, InitPtrType};
143 EmuTlsVar = M.getOrInsertGlobal(EmuTlsVarName, EmuTlsVarType);
151 Align GVAlignment =
DL.getValueOrABITypeAlignment(GV->
getAlign(), GVType);
156 std::string EmuTlsTmplName = (
"__emutls_t." + GV->
getName()).str();
157 EmuTlsTmplVar = M.getOrInsertGlobal(EmuTlsTmplName, GVType);
158 assert(EmuTlsTmplVar &&
"Failed to create emualted TLS initializer");
167 ConstantInt::get(WordType,
DL.getTypeStoreSize(GVType)),
168 ConstantInt::get(WordType, GVAlignment.
value()), NullPtr,
169 EmuTlsTmplVar ? EmuTlsTmplVar : NullPtr};
172 std::max(
DL.getABITypeAlign(WordType),
DL.getABITypeAlign(VoidPtrType));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This is the interface for a simple mod/ref and alias analysis over globals.
Module.h This file contains the declarations for the Module class.
static void copyLinkageVisibility(Module &M, const GlobalVariable *from, GlobalVariable *to)
static bool addEmuTlsVar(Module &M, const GlobalVariable *GV)
This is the interface to build a ModuleSummaryIndex for a module.
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
Target-Independent Code Generator Pass Configuration Options pass.
void setSelectionKind(SelectionKind Val)
SelectionKind getSelectionKind() const
This is the shared class of boolean and integer constants.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
LLVM_ABI void setComdat(Comdat *C)
const Comdat * getComdat() const
VisibilityTypes getVisibility() const
LinkageTypes getLinkage() const
void setLinkage(LinkageTypes LT)
void setDSOLocal(bool Local)
void setVisibility(VisibilityTypes V)
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
void setConstant(bool Val)
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
Analysis pass providing a never-invalidated alias analysis result.
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Analysis pass to provide the ModuleSummaryIndex object.
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & abandon()
Mark an analysis as abandoned.
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This pass performs the global (interprocedural) stack safety analysis (new pass manager).
Class to represent struct types.
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Primary interface to the complete machine description for the target machine.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void initializeLowerEmuTLSPass(PassRegistry &)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI ModulePass * createLowerEmuTLSPass()
LowerEmuTLS - This pass generates __emutls_[vt].xyz variables for all TLS variables for the emulated ...
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.