From 06c4eaa6ecd6ed4d93c9fc1da3e03ad3ee900bec Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 25 Feb 2014 11:20:37 -0800 Subject: Re-introduce ConstantExpr expansion for constants containing illegal types. --- lib/Transforms/NaCl/ExpandConstantExpr.cpp | 30 +++++++++++++++++++++++++++--- lib/Transforms/NaCl/PNaClABISimplify.cpp | 2 -- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'lib/Transforms') diff --git a/lib/Transforms/NaCl/ExpandConstantExpr.cpp b/lib/Transforms/NaCl/ExpandConstantExpr.cpp index 2856a9d7e4..75098a1572 100644 --- a/lib/Transforms/NaCl/ExpandConstantExpr.cpp +++ b/lib/Transforms/NaCl/ExpandConstantExpr.cpp @@ -56,6 +56,25 @@ static Value *expandConstantExpr(Instruction *InsertPt, ConstantExpr *Expr) { return NewInst; } +// XXX Emscripten: Utilities for illegal expressions. +static bool isIllegal(Type *T) { + return T->isIntegerTy() && T->getIntegerBitWidth() > 32; +} +static bool ContainsIllegalTypes(const Value *Expr) { + if (isIllegal(Expr->getType())) + return true; + if (const User *U = dyn_cast(Expr)) { + for (User::const_op_iterator I = U->op_begin(), E = U->op_end(); I != E; ++I) { + if (Constant *C = dyn_cast(*I)) { + if (!isa(C) && ContainsIllegalTypes(C)) { + return true; + } + } + } + } + return false; +} + static bool expandInstruction(Instruction *Inst) { // A landingpad can only accept ConstantExprs, so it should remain // unmodified. @@ -66,9 +85,14 @@ static bool expandInstruction(Instruction *Inst) { for (unsigned OpNum = 0; OpNum < Inst->getNumOperands(); OpNum++) { if (ConstantExpr *Expr = dyn_cast(Inst->getOperand(OpNum))) { - Modified = true; - Use *U = &Inst->getOperandUse(OpNum); - PhiSafeReplaceUses(U, expandConstantExpr(PhiSafeInsertPt(U), Expr)); + // XXX Emscripten: Only do the expansion of the expression contains + // illegal types, for now, since we can handle legal ConstantExprs + // in the backend directly. + if (ContainsIllegalTypes(Expr)) { + Modified = true; + Use *U = &Inst->getOperandUse(OpNum); + PhiSafeReplaceUses(U, expandConstantExpr(PhiSafeInsertPt(U), Expr)); + } } } return Modified; diff --git a/lib/Transforms/NaCl/PNaClABISimplify.cpp b/lib/Transforms/NaCl/PNaClABISimplify.cpp index 416c38dd17..e7dcba353f 100644 --- a/lib/Transforms/NaCl/PNaClABISimplify.cpp +++ b/lib/Transforms/NaCl/PNaClABISimplify.cpp @@ -116,11 +116,9 @@ void llvm::PNaClABISimplifyAddPostOptPasses(PassManager &PM) { // are expanded out later. PM.add(createFlattenGlobalsPass()); -#if 0 // XXX EMSCRIPTEN: We can handle ConstantExprs in our backend. // We should not place arbitrary passes after ExpandConstantExpr // because they might reintroduce ConstantExprs. PM.add(createExpandConstantExprPass()); -#endif // PromoteIntegersPass does not handle constexprs and creates GEPs, // so it goes between those passes. PM.add(createPromoteIntegersPass()); -- cgit v1.2.3-70-g09d2