| 111 | } |
| 112 | |
| 113 | std::vector<unsigned> memoryIndices(llvm::Value &V) const { |
| 114 | |
| 115 | std::vector<unsigned> MemoryIndices; |
| 116 | std::vector<llvm::Value *> GEPIndices; |
| 117 | |
| 118 | if (auto *GEPI = dyn_cast<GetElementPtrInst>(&V)) { |
| 119 | for (auto &Index : GEPI->indices()) { |
| 120 | GEPIndices.push_back(Index.get()); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if (auto *CE = dyn_cast<ConstantExpr>(&V)) { |
| 125 | for (unsigned S = 1, E = CE->getNumOperands(); S < E; ++S) { |
| 126 | GEPIndices.push_back(CE->getOperand(S)); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (GEPIndices.size() > 1) { |
| 131 | auto *Index = GEPIndices[0]; |
| 132 | assert(Index && "Unexpected Program State"); |
| 133 | |
| 134 | if (!isa<ConstantInt>(Index)) { |
| 135 | llvm::outs() << "Unexpected Memory Access Instruction: " << V << "\n"; |
| 136 | assert(false && "Unexpected Program State"); |
| 137 | } |
| 138 | |
| 139 | auto &CI = *dyn_cast<ConstantInt>(Index); |
| 140 | auto RealValue = CI.getZExtValue(); |
| 141 | if (RealValue != 0) { |
| 142 | llvm::outs() << "Unexpected Memory Access Instruction: " << V << "\n"; |
| 143 | assert(false && "Unexpected Program State"); |
| 144 | } |
| 145 | |
| 146 | GEPIndices.erase(GEPIndices.begin()); |
| 147 | } |
| 148 | |
| 149 | for (unsigned S = 0, E = GEPIndices.size(); S < E; ++S) { |
| 150 | auto *Index = GEPIndices[S]; |
| 151 | assert(Index && "Unexpected Program State"); |
| 152 | |
| 153 | if (!isa<ConstantInt>(Index)) { |
| 154 | GEPIndices.clear(); |
| 155 | return MemoryIndices; |
| 156 | } |
| 157 | |
| 158 | auto &CI = *dyn_cast<ConstantInt>(Index); |
| 159 | auto RealValue = CI.getZExtValue(); |
| 160 | MemoryIndices.push_back(RealValue); |
| 161 | } |
| 162 | |
| 163 | return MemoryIndices; |
| 164 | } |
| 165 | |
| 166 | std::stack<std::shared_ptr<Node>> Stack; |
| 167 | std::set<llvm::Value *> Visit; |