@@ -78,7 +78,7 @@ struct TestPointerLikeTypeInterfacePass
7878 void testGenLoad (Operation *op, Value result, PointerLikeType pointerType,
7979 OpBuilder &builder);
8080 void testGenStore (Operation *op, Value result, PointerLikeType pointerType,
81- OpBuilder &builder);
81+ OpBuilder &builder, Value providedValue = {} );
8282
8383 struct PointerCandidate {
8484 Operation *op;
@@ -100,6 +100,8 @@ void TestPointerLikeTypeInterfacePass::runOnOperation() {
100100 testMode == " store" ) {
101101 // Collect all candidates first
102102 SmallVector<PointerCandidate> candidates;
103+ // For store mode, also look for a test value to use
104+ Value testValue;
103105 func.walk ([&](Operation *op) {
104106 if (op->hasAttr (" test.ptr" )) {
105107 for (auto result : op->getResults ()) {
@@ -110,6 +112,11 @@ void TestPointerLikeTypeInterfacePass::runOnOperation() {
110112 }
111113 }
112114 }
115+ // Collect value marked with test.value for store tests
116+ if (testMode == " store" && op->hasAttr (" test.value" )) {
117+ if (op->getNumResults () > 0 )
118+ testValue = op->getResult (0 );
119+ }
113120 });
114121
115122 // Now test all candidates
@@ -125,7 +132,7 @@ void TestPointerLikeTypeInterfacePass::runOnOperation() {
125132 builder);
126133 else if (testMode == " store" )
127134 testGenStore (candidate.op , candidate.result , candidate.pointerType ,
128- builder);
135+ builder, testValue );
129136 }
130137 } else if (testMode == " copy" ) {
131138 // Collect all source and destination candidates
@@ -341,7 +348,8 @@ void TestPointerLikeTypeInterfacePass::testGenLoad(Operation *op, Value result,
341348
342349void TestPointerLikeTypeInterfacePass::testGenStore (Operation *op, Value result,
343350 PointerLikeType pointerType,
344- OpBuilder &builder) {
351+ OpBuilder &builder,
352+ Value providedValue) {
345353 Location loc = op->getLoc ();
346354
347355 // Create a new builder with the listener and set insertion point
@@ -350,28 +358,32 @@ void TestPointerLikeTypeInterfacePass::testGenStore(Operation *op, Value result,
350358 newBuilder.setListener (&tracker);
351359 newBuilder.setInsertionPointAfter (op);
352360
353- // Create a test value to store - use a constant matching the element type
354- Type elementType = pointerType.getElementType ();
355- if (!elementType) {
356- llvm::errs () << " Failed to generate store for operation: " ;
357- op->print (llvm::errs ());
358- llvm::errs () << " \n " ;
359- return ;
360- }
361+ // Use provided value if available, otherwise create a constant
362+ Value valueToStore = providedValue;
363+ if (!valueToStore) {
364+ // Create a test value to store - use a constant matching the element type
365+ Type elementType = pointerType.getElementType ();
366+ if (!elementType) {
367+ llvm::errs () << " Failed to generate store for operation: " ;
368+ op->print (llvm::errs ());
369+ llvm::errs () << " \n " ;
370+ return ;
371+ }
361372
362- Value valueToStore;
363- if (elementType.isIntOrIndex ()) {
364- auto attr = newBuilder.getIntegerAttr (elementType, 42 );
365- valueToStore =
366- arith::ConstantOp::create (newBuilder, loc, elementType, attr);
367- } else if (auto floatType = dyn_cast<FloatType>(elementType)) {
368- auto attr = newBuilder.getFloatAttr (floatType, 42.0 );
369- valueToStore = arith::ConstantOp::create (newBuilder, loc, floatType, attr);
370- } else {
371- llvm::errs () << " Failed to generate store for operation: " ;
372- op->print (llvm::errs ());
373- llvm::errs () << " \n " ;
374- return ;
373+ if (elementType.isIntOrIndex ()) {
374+ auto attr = newBuilder.getIntegerAttr (elementType, 42 );
375+ valueToStore =
376+ arith::ConstantOp::create (newBuilder, loc, elementType, attr);
377+ } else if (auto floatType = dyn_cast<FloatType>(elementType)) {
378+ auto attr = newBuilder.getFloatAttr (floatType, 42.0 );
379+ valueToStore =
380+ arith::ConstantOp::create (newBuilder, loc, floatType, attr);
381+ } else {
382+ llvm::errs () << " Failed to generate store for operation: " ;
383+ op->print (llvm::errs ());
384+ llvm::errs () << " \n " ;
385+ return ;
386+ }
375387 }
376388
377389 // Call the genStore API
0 commit comments