mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 01:56:43 +00:00

fir.call side effects are hard to describe in a useful way using `MemoryEffectOpInterface` because it is impossible to list which memory location a user procedure read/write without doing a data flow analysis of its body (even PURE procedures may read from any module variable, Fortran SIMPLE procedure from F2023 will allow that, but they are far from common at that point). Fortran language specifications allow the compiler to deduce that a procedure call cannot access a variable in many cases This patch leverages this to extend `fir::AliasAnalysis::getModRef` to deal with fir.call. This will allow implementing "array = array_function()" optimization in a future patch.
27 lines
674 B
Python
Executable File
27 lines
674 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""
|
|
Add attributes hook in an HLFIR code to test fir.call ModRef effects
|
|
with the test-fir-alias-analysis-modref pass.
|
|
|
|
This will insert mod ref test hook:
|
|
- to any fir.call to a function which name starts with "test_effect_"
|
|
- to any hlfir.declare for variable which name starts with "test_var_"
|
|
"""
|
|
|
|
import sys
|
|
import re
|
|
|
|
for line in sys.stdin:
|
|
line = re.sub(
|
|
r"(fir.call @_\w*P)(test_effect_\w*)(\(.*) : ",
|
|
r'\1\2\3 {test.ptr ="\2"} : ',
|
|
line,
|
|
)
|
|
line = re.sub(
|
|
r'(hlfir.declare .*uniq_name =.*E)(test_var_\w*)"',
|
|
r'\1\2", test.ptr ="\2"',
|
|
line,
|
|
)
|
|
sys.stdout.write(line)
|