[llvm-commits] [Patch] Make GlobalOpt conservative with TLS vars (PR14309, 3.2-blocker)
Eli Friedman
eli.friedman at gmail.com
Mon Nov 12 11:31:39 PST 2012
On Mon, Nov 12, 2012 at 8:20 AM, Hans Wennborg <hans at chromium.org> wrote:
> Hi all,
>
> The attached patch takes a stab at fixing PR14309 which was marked as
> a 3.2-blocker.
>
> For global variables which get the same value stored into them
> everywhere, GlobalOpt will replace them with a constant. The problem
> is that a thread-local GlobalVariable looks like one value, but is
> different between threads.
>
> My patch introduces Constant::isThreadDependent() which returns true
> for thread-local variables and constants which depend on them (e.g. a
> GEP into a thread-local array), and teaches GlobalOpt not to track
> such values.
>
> Please take a look!
>
> Also, if anyone thinks there are more passes which assume that
> thread-local GlobalVariables have the same value everywhere, please
> let me know.
+/// isThreadDependent - Return true if the value can vary between threads.
+bool Constant::isThreadDependent() const {
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
+ return GV->isThreadLocal();
+
+ for (unsigned I = 0, E = getNumOperands(); I != E; ++I) {
+ if (const Constant *C = dyn_cast<Constant>(getOperand(I))) {
+ if (C->isThreadDependent())
+ return true;
+ }
+ }
+
+ return false;
+}
Dumb recursion is exponential time over an arbitrary ConstantExpr.
-Eli
More information about the llvm-commits
mailing list