Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions clang/lib/Analysis/LifetimeSafety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,13 @@ template <typename T>
static llvm::ImmutableSet<T> join(llvm::ImmutableSet<T> A,
llvm::ImmutableSet<T> B,
typename llvm::ImmutableSet<T>::Factory &F) {
if (A == B)
return A;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would the add() on line 918 also possibly do more allocation than desired (and cost more than checking if contains first), if E was already in A ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this check as well.

if (A.getHeight() < B.getHeight())
std::swap(A, B);
for (const T &E : B)
A = F.add(A, E);
if (!A.contains(E))
A = F.add(A, E);
return A;
}

Expand Down Expand Up @@ -947,10 +950,11 @@ join(llvm::ImmutableMap<K, V> A, llvm::ImmutableMap<K, V> B,
for (const auto &Entry : B) {
const K &Key = Entry.first;
const V &ValB = Entry.second;
if (const V *ValA = A.lookup(Key))
A = F.add(A, Key, JoinValues(*ValA, ValB));
else
const V *ValA = A.lookup(Key);
if (!ValA)
A = F.add(A, Key, ValB);
else if (*ValA != ValB)
A = F.add(A, Key, JoinValues(*ValA, ValB));
}
return A;
}
Expand Down
11 changes: 6 additions & 5 deletions clang/test/Analysis/LifetimeSafety/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def generate_markdown_report(results: dict) -> str:
report.append(" ".join(row))

report.append("\n**Complexity Analysis:**\n")
report.append("| Analysis Phase | Complexity O(n<sup>k</sup>) |")
report.append("| Analysis Phase | Complexity O(n<sup>k</sup>) | ")
report.append("|:------------------|:--------------------------|")

analysis_phases = {
Expand Down Expand Up @@ -302,7 +302,7 @@ def run_single_test(
source_file,
]

result = subprocess.run(clang_command, capture_output=True, text=True)
result = subprocess.run(clang_command, capture_output=True, text=True, timeout=60)

if result.returncode != 0:
print(f"Compilation failed for N={n}!", file=sys.stderr)
Expand Down Expand Up @@ -334,24 +334,25 @@ def run_single_test(
os.makedirs(args.output_dir, exist_ok=True)
print(f"Benchmark files will be saved in: {os.path.abspath(args.output_dir)}\n")

# Maximize 'n' values while keeping execution time under 10s.
test_configurations = [
{
"name": "cycle",
"title": "Pointer Cycle in Loop",
"generator_func": generate_cpp_cycle_test,
"n_values": [10, 25, 50, 75, 100, 150],
"n_values": [25, 50, 75, 100],
},
{
"name": "merge",
"title": "CFG Merges",
"generator_func": generate_cpp_merge_test,
"n_values": [10, 50, 100, 200, 400, 800],
"n_values": [400, 1000, 2000, 5000],
},
{
"name": "nested_loops",
"title": "Deeply Nested Loops",
"generator_func": generate_cpp_nested_loop_test,
"n_values": [10, 50, 100, 200, 400, 800],
"n_values": [50, 100, 150, 200],
},
]

Expand Down
Loading