33import com .dat3m .dartagnan .expression .Expression ;
44import com .dat3m .dartagnan .expression .ExpressionFactory ;
55import com .dat3m .dartagnan .expression .ExpressionVisitor ;
6- import com .dat3m .dartagnan .expression .integers .IntLiteral ;
76import com .dat3m .dartagnan .expression .processing .ExprTransformer ;
87import com .dat3m .dartagnan .expression .processing .ExpressionInspector ;
9- import com .dat3m .dartagnan .expression .type .IntegerType ;
10- import com .dat3m .dartagnan .expression .type .TypeFactory ;
118import com .dat3m .dartagnan .program .Function ;
129import com .dat3m .dartagnan .program .IRHelper ;
1310import com .dat3m .dartagnan .program .Program ;
@@ -40,8 +37,6 @@ public class NaiveDevirtualisation implements ProgramProcessor {
4037
4138 private static final Logger logger = LogManager .getLogger (NaiveDevirtualisation .class );
4239
43- private int nextAvailableFuncAddress = 8 ; // We use 8-aligned addresses
44-
4540 private NaiveDevirtualisation () {
4641 }
4742
@@ -97,16 +92,16 @@ private void findAndTransformAddressTakenFunctions(
9792 }
9893 }
9994
100- private boolean assignAddressToFunction (Function func , Map <Function , IntLiteral > func2AddressMap ) {
101- final IntegerType ptrType = TypeFactory .getInstance ().getArchType ();
102- final ExpressionFactory expressions = ExpressionFactory .getInstance ();
103- if (!func2AddressMap .containsKey (func )) {
104- logger .debug ("Assigned address \" {}\" to function \" {}\" " , nextAvailableFuncAddress , func );
105- func2AddressMap .put (func , expressions .makeValue (nextAvailableFuncAddress , ptrType ));
106- nextAvailableFuncAddress += 8 ;
107- return true ;
95+ private boolean assignAddressToFunction (Function func , Map <Function , MemoryObject > func2AddressMap ) {
96+ if (func2AddressMap .containsKey (func )) {
97+ return false ;
10898 }
109- return false ;
99+
100+ final MemoryObject funcAddr = func .getProgram ().getMemory ().allocate (1 );
101+ funcAddr .setName (String .format ("__funcAddr_%s" , func .getName ()));
102+ func2AddressMap .put (func , funcAddr );
103+ logger .debug ("Assigned address to function \" {}\" " , func );
104+ return true ;
110105 }
111106
112107 private void applyTransformerToEvent (Event e , ExpressionVisitor <Expression > transformer ) {
@@ -119,7 +114,7 @@ private void applyTransformerToEvent(Event e, ExpressionVisitor<Expression> tran
119114 }
120115 }
121116
122- private void devirtualise (Function function , Map <Function , IntLiteral > func2AddressMap ) {
117+ private void devirtualise (Function function , Map <Function , MemoryObject > func2AddressMap ) {
123118 final ExpressionFactory expressions = ExpressionFactory .getInstance ();
124119
125120 int devirtCounter = 0 ;
@@ -147,8 +142,8 @@ private void devirtualise(Function function, Map<Function, IntLiteral> func2Addr
147142 final Expression funcPtr = call .getCallTarget ();
148143 // Construct call table
149144 for (Function possibleTarget : possibleTargets ) {
150- final IntLiteral targetAddress = func2AddressMap .get (possibleTarget );
151- final Label caseLabel = EventFactory .newLabel (String .format ("__Ldevirt_%s#%s" , targetAddress . getValue (), devirtCounter ));
145+ final MemoryObject targetAddress = func2AddressMap .get (possibleTarget );
146+ final Label caseLabel = EventFactory .newLabel (String .format ("__Ldevirt_%s#%s" , possibleTarget . getName (), devirtCounter ));
152147 final CondJump caseJump = EventFactory .newJump (expressions .makeEQ (funcPtr , targetAddress ), caseLabel );
153148 caseLabels .add (caseLabel );
154149 caseJumps .add (caseJump );
@@ -178,7 +173,7 @@ private boolean needsDevirtualization(CallEvent call) {
178173 return !call .isDirectCall ();
179174 }
180175
181- private List <Function > getPossibleTargets (CallEvent call , Map <Function , IntLiteral > func2AddressMap ) {
176+ private List <Function > getPossibleTargets (CallEvent call , Map <Function , MemoryObject > func2AddressMap ) {
182177 Preconditions .checkArgument (needsDevirtualization (call ));
183178 return func2AddressMap .keySet ().stream ()
184179 .filter (f -> f .getFunctionType () == call .getCallType ())
@@ -210,7 +205,7 @@ public Expression visitFunction(Function function) {
210205
211206 private static class FunctionToAddressTransformer extends ExprTransformer {
212207
213- private final Map <Function , IntLiteral > func2AddressMap = new HashMap <>();
208+ private final Map <Function , MemoryObject > func2AddressMap = new HashMap <>();
214209
215210 @ Override
216211 public Expression visitFunction (Function function ) {
0 commit comments