diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-03-29 17:42:10 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-03-29 17:42:10 -0700 |
commit | cd93e1afec966dba60433f8df5f78f10ef217f93 (patch) | |
tree | 97c1b68239f23dedd72f5283e37a4957af9d10a1 /lib/Transforms/NaCl/ExpandTls.cpp | |
parent | 946417b9fe7da9334c76182f28020ff4f46e11f8 (diff) |
PNaCl: Fix ExpandTls to handle a couple of corner cases involving PHI nodes
ExpandTls's use of replaceUsesOfWith() didn't work for PHI nodes
containing the same Constant twice (which needs to work for same or
differing incoming BasicBlocks). The same applies to
ExpandTlsConstantExpr.
I noticed this while implementing ExpandConstantExpr.
Fix this and factor out some common code that all three passes can
use.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=2837
TEST=test/Transforms/NaCl/*.ll
Review URL: https://codereview.chromium.org/13128002
Diffstat (limited to 'lib/Transforms/NaCl/ExpandTls.cpp')
-rw-r--r-- | lib/Transforms/NaCl/ExpandTls.cpp | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/Transforms/NaCl/ExpandTls.cpp b/lib/Transforms/NaCl/ExpandTls.cpp index 929b2e0a15..53e1c92a96 100644 --- a/lib/Transforms/NaCl/ExpandTls.cpp +++ b/lib/Transforms/NaCl/ExpandTls.cpp @@ -250,15 +250,8 @@ static void rewriteTlsVars(Module &M, std::vector<VarInfo> *TlsVars, ++VarInfo) { GlobalVariable *Var = VarInfo->TlsVar; while (!Var->use_empty()) { - Instruction *U = cast<Instruction>(*Var->use_begin()); - Instruction *InsertPt = U; - if (PHINode *PN = dyn_cast<PHINode>(InsertPt)) { - // We cannot insert instructions before a PHI node, so insert - // before the incoming block's terminator. Note that if the - // terminator is conditional, this could be suboptimal, - // because we might be calling ReadTpFunc unnecessarily. - InsertPt = PN->getIncomingBlock(Var->use_begin())->getTerminator(); - } + Use *U = &Var->use_begin().getUse(); + Instruction *InsertPt = PhiSafeInsertPt(U); Value *RawThreadPtr = CallInst::Create(ReadTpFunc, "tls_raw", InsertPt); Value *TypedThreadPtr = new BitCastInst(RawThreadPtr, TemplatePtrType, "tls_struct", InsertPt); @@ -279,7 +272,7 @@ static void rewriteTlsVars(Module &M, std::vector<VarInfo> *TlsVars, M.getContext(), APInt(32, VarInfo->TemplateIndex))); Value *TlsField = GetElementPtrInst::Create(TypedThreadPtr, Indexes, "field", InsertPt); - U->replaceUsesOfWith(Var, TlsField); + PhiSafeReplaceUses(U, TlsField); } VarInfo->TlsVar->eraseFromParent(); } |