Index: lib/Transforms/NaCl/ExpandTls.cpp |
diff --git a/lib/Transforms/NaCl/ExpandTls.cpp b/lib/Transforms/NaCl/ExpandTls.cpp |
index fc7db7c0ba1cba3e72e2b6e4624941b4e70f79f4..ada9a4aa6d2c464cb97611998c1f85e2164be3c5 100644 |
--- a/lib/Transforms/NaCl/ExpandTls.cpp |
+++ b/lib/Transforms/NaCl/ExpandTls.cpp |
@@ -116,7 +116,7 @@ static void addVarToTlsTemplate(PassState *State, |
State->DL.getTypeAllocSize(TlsVar->getType()->getElementType()); |
} |
-static PointerType *buildTlsTemplate(Module &M, std::vector<VarInfo> *TlsVars) { |
+static StructType *buildTlsTemplate(Module &M, std::vector<VarInfo> *TlsVars) { |
std::vector<Type*> FieldBssTypes; |
std::vector<Type*> FieldInitTypes; |
std::vector<Constant*> FieldInitValues; |
@@ -203,11 +203,13 @@ static PointerType *buildTlsTemplate(Module &M, std::vector<VarInfo> *TlsVars) { |
TemplateDataVar->setName(StartSymbol); |
Constant *TdataEnd = ConstantExpr::getGetElementPtr( |
+ InitTemplateType, |
TemplateDataVar, |
ConstantInt::get(M.getContext(), APInt(32, 1))); |
setGlobalVariableValue(M, "__tls_template_tdata_end", TdataEnd); |
Constant *TotalEnd = ConstantExpr::getGetElementPtr( |
+ TemplateType, |
ConstantExpr::getBitCast(TemplateDataVar, TemplatePtrType), |
ConstantInt::get(M.getContext(), APInt(32, 1))); |
setGlobalVariableValue(M, "__tls_template_end", TotalEnd); |
@@ -221,11 +223,11 @@ static PointerType *buildTlsTemplate(Module &M, std::vector<VarInfo> *TlsVars) { |
setGlobalVariableValue(M, AlignmentSymbol, AlignmentVar); |
AlignmentVar->setName(AlignmentSymbol); |
- return TemplatePtrType; |
+ return TemplateType; |
} |
static void rewriteTlsVars(Module &M, std::vector<VarInfo> *TlsVars, |
- PointerType *TemplatePtrType) { |
+ StructType *TemplateType) { |
// Set up the intrinsic that reads the thread pointer. |
Function *ReadTpFunc = Intrinsic::getDeclaration(&M, Intrinsic::nacl_read_tp); |
@@ -237,8 +239,8 @@ static void rewriteTlsVars(Module &M, std::vector<VarInfo> *TlsVars, |
Use *U = &*Var->use_begin(); |
Instruction *InsertPt = PhiSafeInsertPt(U); |
Value *RawThreadPtr = CallInst::Create(ReadTpFunc, "tls_raw", InsertPt); |
- Value *TypedThreadPtr = new BitCastInst(RawThreadPtr, TemplatePtrType, |
- "tls_struct", InsertPt); |
+ Value *TypedThreadPtr = new BitCastInst( |
+ RawThreadPtr, TemplateType->getPointerTo(), "tls_struct", InsertPt); |
SmallVector<Value*, 3> Indexes; |
// We use -1 because we use the x86-style TLS layout in which |
// the TLS data is stored at addresses below the thread pointer. |
@@ -254,8 +256,8 @@ static void rewriteTlsVars(Module &M, std::vector<VarInfo> *TlsVars, |
M.getContext(), APInt(32, VarInfo->IsBss ? 1 : 0))); |
Indexes.push_back(ConstantInt::get( |
M.getContext(), APInt(32, VarInfo->TemplateIndex))); |
- Value *TlsField = GetElementPtrInst::Create(TypedThreadPtr, Indexes, |
- "field", InsertPt); |
+ Value *TlsField = GetElementPtrInst::Create( |
+ TemplateType, TypedThreadPtr, Indexes, "field", InsertPt); |
PhiSafeReplaceUses(U, TlsField); |
} |
VarInfo->TlsVar->eraseFromParent(); |
@@ -321,8 +323,8 @@ bool ExpandTls::runOnModule(Module &M) { |
delete Pass; |
std::vector<VarInfo> TlsVars; |
- PointerType *TemplatePtrType = buildTlsTemplate(M, &TlsVars); |
- rewriteTlsVars(M, &TlsVars, TemplatePtrType); |
+ StructType *TemplateType = buildTlsTemplate(M, &TlsVars); |
+ rewriteTlsVars(M, &TlsVars, TemplateType); |
defineTlsLayoutFunctions(M); |