xref: /llvm-project/llvm/tools/llvm-reduce/deltas/ReduceMemoryOperations.cpp (revision 596fdf75d99f83473295e6a619ffac5afa23dd8e)
1 //===- ReduceOpcodes.cpp - Specialized Delta Pass -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ReduceMemoryOperations.h"
10 #include "Delta.h"
11 #include "llvm/IR/InstIterator.h"
12 #include "llvm/IR/Instructions.h"
13 #include "llvm/IR/IntrinsicInst.h"
14 
15 static void removeVolatileInFunction(Oracle &O, Function &F) {
16   LLVMContext &Ctx = F.getContext();
17   for (Instruction &I : instructions(F)) {
18     if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
19       if (LI->isVolatile() && !O.shouldKeep())
20         LI->setVolatile(false);
21     } else if (StoreInst *SI = dyn_cast<StoreInst>(&I)) {
22       if (SI->isVolatile() && !O.shouldKeep())
23         SI->setVolatile(false);
24     } else if (AtomicRMWInst *RMW = dyn_cast<AtomicRMWInst>(&I)) {
25       if (RMW->isVolatile() && !O.shouldKeep())
26         RMW->setVolatile(false);
27     } else if (AtomicCmpXchgInst *CmpXChg = dyn_cast<AtomicCmpXchgInst>(&I)) {
28       if (CmpXChg->isVolatile() && !O.shouldKeep())
29         CmpXChg->setVolatile(false);
30     } else if (MemIntrinsic *MemIntrin = dyn_cast<MemIntrinsic>(&I)) {
31       if (MemIntrin->isVolatile() && !O.shouldKeep())
32         MemIntrin->setVolatile(ConstantInt::getFalse(Ctx));
33     }
34   }
35 }
36 
37 static void removeVolatileInModule(Oracle &O, Module &Mod) {
38   for (Function &F : Mod)
39     removeVolatileInFunction(O, F);
40 }
41 
42 void llvm::reduceVolatileInstructionsDeltaPass(TestRunner &Test) {
43   runDeltaPass(Test, removeVolatileInModule, "Reducing Volatile Instructions");
44 }
45