diff options
author | Dan Gohman <sunfish@google.com> | 2014-02-25 11:20:37 -0800 |
---|---|---|
committer | Dan Gohman <sunfish@google.com> | 2014-02-25 11:58:56 -0800 |
commit | 06c4eaa6ecd6ed4d93c9fc1da3e03ad3ee900bec (patch) | |
tree | ba183abdfe44c8a7e300ae2bda7e2dfd6468199f | |
parent | 868e67812c09905c35ee6e09393d4646c1364505 (diff) |
Re-introduce ConstantExpr expansion for constants containing illegal types.
-rw-r--r-- | lib/Transforms/NaCl/ExpandConstantExpr.cpp | 30 | ||||
-rw-r--r-- | lib/Transforms/NaCl/PNaClABISimplify.cpp | 2 |
2 files changed, 27 insertions, 5 deletions
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<User>(Expr)) { + for (User::const_op_iterator I = U->op_begin(), E = U->op_end(); I != E; ++I) { + if (Constant *C = dyn_cast<Constant>(*I)) { + if (!isa<GlobalValue>(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<ConstantExpr>(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()); |