diff options
author | Alon Zakai <azakai@google.com> | 2019-04-26 16:59:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-26 16:59:41 -0700 |
commit | db9124f1de0478dcac525009b6f1589b44a7edd8 (patch) | |
tree | fa26395a0f6cca53cf5cb6e10189f989c5bfa847 /src/dataflow | |
parent | 87636dccd404a340d75acb1d96301581343f29ca (diff) | |
download | binaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.tar.gz binaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.tar.bz2 binaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.zip |
Apply format changes from #2048 (#2059)
Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
Diffstat (limited to 'src/dataflow')
-rw-r--r-- | src/dataflow/graph.h | 135 | ||||
-rw-r--r-- | src/dataflow/node.h | 75 | ||||
-rw-r--r-- | src/dataflow/users.h | 8 | ||||
-rw-r--r-- | src/dataflow/utils.h | 38 |
4 files changed, 147 insertions, 109 deletions
diff --git a/src/dataflow/graph.h b/src/dataflow/graph.h index 85b37b7b0..f93621a91 100644 --- a/src/dataflow/graph.h +++ b/src/dataflow/graph.h @@ -25,11 +25,11 @@ #ifndef wasm_dataflow_graph_h #define wasm_dataflow_graph_h -#include "wasm.h" +#include "dataflow/node.h" #include "ir/abstract.h" #include "ir/iteration.h" #include "ir/literal-utils.h" -#include "dataflow/node.h" +#include "wasm.h" namespace wasm { @@ -99,7 +99,8 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { struct FlowState { Locals locals; Node* condition; - FlowState(Locals locals, Node* condition) : locals(locals), condition(condition) {} + FlowState(Locals locals, Node* condition) + : locals(locals), condition(condition) {} }; // API @@ -109,11 +110,13 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { module = moduleInit; auto numLocals = func->getNumLocals(); - if (numLocals == 0) return; // nothing to do + if (numLocals == 0) + return; // nothing to do // Set up initial local state IR. setInReachable(); for (Index i = 0; i < numLocals; i++) { - if (!isRelevantType(func->getLocalType(i))) continue; + if (!isRelevantType(func->getLocalType(i))) + continue; Node* node; auto type = func->getLocalType(i); if (func->isParam(i)) { @@ -141,7 +144,7 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { Node* makeConst(Literal value) { auto iter = constantNodes.find(value); - if (iter!= constantNodes.end()) { + if (iter != constantNodes.end()) { return iter->second; } // Create one for this literal. @@ -152,9 +155,7 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { return ret; } - Node* makeZero(wasm::Type type) { - return makeConst(Literal::makeZero(type)); - } + Node* makeZero(wasm::Type type) { return makeConst(Literal::makeZero(type)); } // Add a new node to our list of owned nodes. Node* addNode(Node* node) { @@ -166,34 +167,26 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { assert(!node->isBad()); Builder builder(*module); auto type = node->getWasmType(); - if (!isConcreteType(type)) return &bad; + if (!isConcreteType(type)) + return &bad; auto* zero = makeZero(type); auto* expr = builder.makeBinary( Abstract::getBinary(type, equal ? Abstract::Eq : Abstract::Ne), makeUse(node), - makeUse(zero) - ); + makeUse(zero)); auto* check = addNode(Node::makeExpr(expr, origin)); check->addValue(expandFromI1(node, origin)); check->addValue(zero); return check; } - void setInUnreachable() { - locals.clear(); - } + void setInUnreachable() { locals.clear(); } - void setInReachable() { - locals.resize(func->getNumLocals()); - } + void setInReachable() { locals.resize(func->getNumLocals()); } - bool isInUnreachable() { - return isInUnreachable(locals); - } + bool isInUnreachable() { return isInUnreachable(locals); } - bool isInUnreachable(const Locals& state) { - return state.empty(); - } + bool isInUnreachable(const Locals& state) { return state.empty(); } bool isInUnreachable(const FlowState& state) { return isInUnreachable(state.locals); @@ -320,7 +313,8 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { auto& breaks = breakStates[curr->name]; // Phis are possible, check for them. for (Index i = 0; i < numLocals; i++) { - if (!isRelevantType(func->getLocalType(i))) continue; + if (!isRelevantType(func->getLocalType(i))) + continue; bool needPhi = false; // We replaced the proper value with a Var. If it's still that // Var - or it's the original proper value, which can happen with @@ -413,9 +407,7 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { } return &bad; } - Node* doVisitConst(Const* curr) { - return makeConst(curr->value); - } + Node* doVisitConst(Const* curr) { return makeConst(curr->value); } Node* doVisitUnary(Unary* curr) { // First, check if we support this op. switch (curr->op) { @@ -428,7 +420,8 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { // These are ok as-is. // Check if our child is supported. auto* value = expandFromI1(visit(curr->value), curr); - if (value->isBad()) return value; + if (value->isBad()) + return value; // Great, we are supported! auto* ret = addNode(Node::makeExpr(curr, curr)); ret->addValue(value); @@ -439,7 +432,8 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { // These can be implemented using a binary. // Check if our child is supported. auto* value = expandFromI1(visit(curr->value), curr); - if (value->isBad()) return value; + if (value->isBad()) + return value; // Great, we are supported! return makeZeroComp(value, true, curr); } @@ -449,7 +443,7 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { } } } - Node* doVisitBinary(Binary *curr) { + Node* doVisitBinary(Binary* curr) { // First, check if we support this op. switch (curr->op) { case AddInt32: @@ -497,9 +491,11 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { // These are ok as-is. // Check if our children are supported. auto* left = expandFromI1(visit(curr->left), curr); - if (left->isBad()) return left; + if (left->isBad()) + return left; auto* right = expandFromI1(visit(curr->right), curr); - if (right->isBad()) return right; + if (right->isBad()) + return right; // Great, we are supported! auto* ret = addNode(Node::makeExpr(curr, curr)); ret->addValue(left); @@ -518,19 +514,37 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { Builder builder(*module); BinaryOp opposite; switch (curr->op) { - case GtSInt32: opposite = LtSInt32; break; - case GtSInt64: opposite = LtSInt64; break; - case GeSInt32: opposite = LeSInt32; break; - case GeSInt64: opposite = LeSInt64; break; - case GtUInt32: opposite = LtUInt32; break; - case GtUInt64: opposite = LtUInt64; break; - case GeUInt32: opposite = LeUInt32; break; - case GeUInt64: opposite = LeUInt64; break; - default: WASM_UNREACHABLE(); + case GtSInt32: + opposite = LtSInt32; + break; + case GtSInt64: + opposite = LtSInt64; + break; + case GeSInt32: + opposite = LeSInt32; + break; + case GeSInt64: + opposite = LeSInt64; + break; + case GtUInt32: + opposite = LtUInt32; + break; + case GtUInt64: + opposite = LtUInt64; + break; + case GeUInt32: + opposite = LeUInt32; + break; + case GeUInt64: + opposite = LeUInt64; + break; + default: + WASM_UNREACHABLE(); } - auto* ret = visitBinary(builder.makeBinary(opposite, curr->right, curr->left)); - // We just created a new binary node, but we need to set the origin properly - // to the original. + auto* ret = + visitBinary(builder.makeBinary(opposite, curr->right, curr->left)); + // We just created a new binary node, but we need to set the origin + // properly to the original. ret->origin = curr; return ret; } @@ -542,11 +556,14 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { } Node* doVisitSelect(Select* curr) { auto* ifTrue = expandFromI1(visit(curr->ifTrue), curr); - if (ifTrue->isBad()) return ifTrue; + if (ifTrue->isBad()) + return ifTrue; auto* ifFalse = expandFromI1(visit(curr->ifFalse), curr); - if (ifFalse->isBad()) return ifFalse; + if (ifFalse->isBad()) + return ifFalse; auto* condition = ensureI1(visit(curr->condition), curr); - if (condition->isBad()) return condition; + if (condition->isBad()) + return condition; // Great, we are supported! auto* ret = addNode(Node::makeExpr(curr, curr)); ret->addValue(condition); @@ -575,16 +592,18 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { // Helpers. - bool isRelevantType(wasm::Type type) { - return isIntegerType(type); - } + bool isRelevantType(wasm::Type type) { return isIntegerType(type); } bool isRelevantLocal(Index index) { return isRelevantType(func->getLocalType(index)); } // Merge local state for an if, also creating a block and conditions. - void mergeIf(Locals& aState, Locals& bState, Node* condition, Expression* expr, Locals& out) { + void mergeIf(Locals& aState, + Locals& bState, + Node* condition, + Expression* expr, + Locals& out) { // Create the conditions (if we can). Node* ifTrue; Node* ifFalse; @@ -642,7 +661,8 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { Index numLocals = func->getNumLocals(); Node* block = nullptr; for (Index i = 0; i < numLocals; i++) { - if (!isRelevantType(func->getLocalType(i))) continue; + if (!isRelevantType(func->getLocalType(i))) + continue; // Process the inputs. If any is bad, the phi is bad. bool bad = false; for (auto& state : states) { @@ -653,7 +673,8 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { break; } } - if (bad) continue; + if (bad) + continue; // Nothing is bad, proceed. Node* first = nullptr; for (auto& state : states) { @@ -703,14 +724,16 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { // the set. SetLocal* getSet(Node* node) { auto iter = nodeParentMap.find(node); - if (iter == nodeParentMap.end()) return nullptr; + if (iter == nodeParentMap.end()) + return nullptr; return iter->second->dynCast<SetLocal>(); } // Given an expression, return the parent if such exists. Expression* getParent(Expression* curr) { auto iter = expressionParentMap.find(curr); - if (iter == expressionParentMap.end()) return nullptr; + if (iter == expressionParentMap.end()) + return nullptr; return iter->second; } diff --git a/src/dataflow/node.h b/src/dataflow/node.h index d6514588e..8977ab41c 100644 --- a/src/dataflow/node.h +++ b/src/dataflow/node.h @@ -25,6 +25,7 @@ #ifndef wasm_dataflow_node_h #define wasm_dataflow_node_h +#include "ir/utils.h" #include "wasm.h" namespace wasm { @@ -34,11 +35,11 @@ namespace DataFlow { // // The core IR representation in DataFlow: a Node. // -// We reuse the Binaryen IR as much as possible: when things are identical between -// the two IRs, we just create an Expr node, which stores the opcode and other -// details, and we can emit them to Souper by reading the Binaryen Expression. -// Other node types here are special things from Souper IR that we can't -// represent that way. +// We reuse the Binaryen IR as much as possible: when things are identical +// between the two IRs, we just create an Expr node, which stores the opcode and +// other details, and we can emit them to Souper by reading the Binaryen +// Expression. Other node types here are special things from Souper IR that we +// can't represent that way. // // * Souper comparisons return an i1. We extend them immediately if they are // going to be used as i32s or i64s. @@ -52,15 +53,17 @@ namespace DataFlow { struct Node { enum Type { - Var, // an unknown variable number (not to be confused with var/param/local in wasm) - Expr, // a value represented by a Binaryen Expression - Phi, // a phi from converging control flow - Cond, // a blockpc, representing one of the branchs for a Block + Var, // an unknown variable number (not to be confused with var/param/local + // in wasm) + Expr, // a value represented by a Binaryen Expression + Phi, // a phi from converging control flow + Cond, // a blockpc, representing one of the branchs for a Block Block, // a source of phis - Zext, // zero-extend an i1 (from an op where Souper returns i1 but wasm does not, - // and so we need a special way to get back to an i32/i64 if we operate - // on that value instead of just passing it straight to Souper). - Bad // something we can't handle and should ignore + Zext, // zero-extend an i1 (from an op where Souper returns i1 but wasm does + // not, and so we need a special way to get back to an i32/i64 if we + // operate on that value instead of just passing it straight to + // Souper). + Bad // something we can't handle and should ignore } type; Node(Type type) : type(type) {} @@ -144,50 +147,56 @@ struct Node { // Helpers - void addValue(Node* value) { - values.push_back(value); - } - Node* getValue(Index i) { - return values.at(i); - } + void addValue(Node* value) { values.push_back(value); } + Node* getValue(Index i) { return values.at(i); } // Gets the wasm type of the node. If there isn't a valid one, // return unreachable. wasm::Type getWasmType() { switch (type) { - case Var: return wasmType; - case Expr: return expr->type; - case Phi: return getValue(1)->getWasmType(); - case Zext: return getValue(0)->getWasmType(); - case Bad: return unreachable; - default: WASM_UNREACHABLE(); + case Var: + return wasmType; + case Expr: + return expr->type; + case Phi: + return getValue(1)->getWasmType(); + case Zext: + return getValue(0)->getWasmType(); + case Bad: + return unreachable; + default: + WASM_UNREACHABLE(); } } bool operator==(const Node& other) { - if (type != other.type) return false; + if (type != other.type) + return false; switch (type) { case Var: - case Block: return this == &other; + case Block: + return this == &other; case Expr: { if (!ExpressionAnalyzer::equal(expr, other.expr)) { return false; } break; } - case Cond: if (index != other.index) return false; + case Cond: + if (index != other.index) + return false; default: {} } - if (values.size() != other.values.size()) return false; + if (values.size() != other.values.size()) + return false; for (Index i = 0; i < values.size(); i++) { - if (*(values[i]) != *(other.values[i])) return false; + if (*(values[i]) != *(other.values[i])) + return false; } return true; } - bool operator!=(const Node& other) { - return !(*this == other); - } + bool operator!=(const Node& other) { return !(*this == other); } // As mentioned above, comparisons return i1. This checks // if an operation is of that sort. diff --git a/src/dataflow/users.h b/src/dataflow/users.h index ab9a2ccef..369d18bbb 100644 --- a/src/dataflow/users.h +++ b/src/dataflow/users.h @@ -89,14 +89,10 @@ public: } // Adds a new user to a node. Called when we add or change a value of a node. - void addUser(Node* node, Node* newUser) { - users[node].insert(newUser); - } + void addUser(Node* node, Node* newUser) { users[node].insert(newUser); } // Remove all uses of a node. Called when a node is being removed. - void removeAllUsesOf(Node* node) { - users.erase(node); - } + void removeAllUsesOf(Node* node) { users.erase(node); } }; } // namespace DataFlow diff --git a/src/dataflow/utils.h b/src/dataflow/utils.h index 5328e6ab7..337dfec5e 100644 --- a/src/dataflow/utils.h +++ b/src/dataflow/utils.h @@ -25,9 +25,9 @@ #ifndef wasm_dataflow_utils_h #define wasm_dataflow_utils_h -#include "wasm.h" -#include "wasm-printing.h" #include "dataflow/node.h" +#include "wasm-printing.h" +#include "wasm.h" namespace wasm { @@ -35,27 +35,39 @@ namespace DataFlow { inline std::ostream& dump(Node* node, std::ostream& o, size_t indent = 0) { auto doIndent = [&]() { - for (size_t i = 0; i < indent; i++) o << ' '; + for (size_t i = 0; i < indent; i++) + o << ' '; }; doIndent(); o << '[' << node << ' '; switch (node->type) { - case Node::Type::Var: o << "var " << printType(node->wasmType) << ' ' << node; break; - case Node::Type::Expr: { + case Node::Type::Var: + o << "var " << printType(node->wasmType) << ' ' << node; + break; + case Node::Type::Expr: { o << "expr "; WasmPrinter::printExpression(node->expr, o, true); break; } - case Node::Type::Phi: o << "phi " << node->index; break; - case Node::Type::Cond: o << "cond " << node->index; break; + case Node::Type::Phi: + o << "phi " << node->index; + break; + case Node::Type::Cond: + o << "cond " << node->index; + break; case Node::Type::Block: { // don't print the conds - they would recurse o << "block (" << node->values.size() << " conds)]\n"; return o; } - case Node::Type::Zext: o << "zext"; break; - case Node::Type::Bad: o << "bad"; break; - default: WASM_UNREACHABLE(); + case Node::Type::Zext: + o << "zext"; + break; + case Node::Type::Bad: + o << "bad"; + break; + default: + WASM_UNREACHABLE(); } if (!node->values.empty()) { o << '\n'; @@ -115,11 +127,9 @@ inline bool allInputsConstant(Node* node) { if (node->expr->is<Unary>()) { return node->getValue(0)->isConst(); } else if (node->expr->is<Binary>()) { - return node->getValue(0)->isConst() && - node->getValue(1)->isConst(); + return node->getValue(0)->isConst() && node->getValue(1)->isConst(); } else if (node->expr->is<Select>()) { - return node->getValue(0)->isConst() && - node->getValue(1)->isConst() && + return node->getValue(0)->isConst() && node->getValue(1)->isConst() && node->getValue(2)->isConst(); } break; |