Пример #1
0
def test_MakeAliasSetGraphs_may_alias_set():
  # https://llvm.org/docs/AliasAnalysis.html
  input_pair = CSourceToInputPair(
    """
void A() {
  char C[2];
  char A[10];
  for (int i = 0; i != 10; ++i) {
    C[0] = A[i];          /* One byte store */
    C[1] = A[9-i];        /* One byte store */
  }
}
"""
  )
  graphs = list(alias_set.MakeAliasSetGraphs(*input_pair))
  assert len(graphs) == 1
  # Computed manually.
  identifiers_in_alias_set = {"A_%16_operand", "A_%10_operand"}
  for node, data in graphs[0].nodes(data=True):
    # Test the 'selector' node.
    assert data["x"][1] in {0, 1}
    # Test the labels.
    if node in identifiers_in_alias_set:
      assert np.array_equal(data["y"], [0, 1, 0])
    else:
      assert np.array_equal(data["y"], [1, 0, 0])
Пример #2
0
def test_MakeAliasSetGraphs_multiple_functions():
  """Test alias """
  # https://llvm.org/docs/AliasAnalysis.html
  input_pair = CSourceToInputPair(
    """
void A() {
  char C[2];
  char A[10];
  for (int i = 0; i != 10; ++i) {
    C[0] = A[i];          /* One byte store */
    C[1] = A[9-i];        /* One byte store */
  }
}

void B() {
  char C[2];
  char A[10];
  for (int i = 0; i != 10; ++i) {
    C[0] = A[i];          /* One byte store */
    C[1] = A[9-i];        /* One byte store */
  }
}
"""
  )
  graphs = list(alias_set.MakeAliasSetGraphs(*input_pair))
  identifiers_in_alias_sets = [
    {"A_%16_operand", "A_%10_operand"},
    {"B_%16_operand", "B_%10_operand"},
  ]
  assert len(graphs) == 2
  # Computed manually.
  for identifiers_in_alias_set, graph in zip(identifiers_in_alias_sets, graphs):
    for node, data in graph.nodes(data=True):
      # Test the 'selector' node.
      assert data["x"][1] in {0, 1}
      # Test the labels.
      if node in identifiers_in_alias_set:
        assert np.array_equal(data["y"], [0, 1, 0])
      else:
        assert np.array_equal(data["y"], [1, 0, 0])
Пример #3
0
def test_MakeAliasSetGraphs_invalid_bytecode():
    graph = nx.MultiDiGraph()
    bytecode = "invalid bytecode!"
    with test.Raises(opt.OptException):
        list(alias_set.MakeAliasSetGraphs(graph, bytecode))