/// @brief Return true if this statement does not contain any accesses.
bool isEmpty() const { return MemAccs.empty(); }
- /// @brief Return the only array access for @p Inst.
+ /// @brief Return the only array access for @p Inst, if existing.
///
/// @param Inst The instruction for which to look up the access.
- /// @returns The unique array memory access related to Inst.
- MemoryAccess &getArrayAccessFor(const Instruction *Inst) const {
+ /// @returns The unique array memory access related to Inst or nullptr if
+ /// no array access exists
+ MemoryAccess *getArrayAccessOrNULLFor(const Instruction *Inst) const {
auto It = InstructionToAccess.find(Inst);
- assert(It != InstructionToAccess.end() &&
- "No memory accesses found for instruction");
+ if (It == InstructionToAccess.end())
+ return nullptr;
MemoryAccess *ArrayAccess = nullptr;
ArrayAccess = Access;
}
- assert(ArrayAccess && "No array access found for instruction!");
- return *ArrayAccess;
+ return ArrayAccess;
}
- /// @brief Get the number of array accesses associated with an instruction.
+ /// @brief Return the only array access for @p Inst.
///
- /// @param Inst The instruction for which to obtain the access count.
- /// @returns The number of array accesses associated with this instruction.
- size_t getNumberOfArrayAccessesFor(const Instruction *Inst) const {
- size_t NumAccesses = 0;
- auto It = InstructionToAccess.find(Inst);
- if (It == InstructionToAccess.end())
- return 0;
-
- for (auto Access : It->getSecond()) {
- if (Access->isArrayKind())
- NumAccesses++;
- }
+ /// @param Inst The instruction for which to look up the access.
+ /// @returns The unique array memory access related to Inst.
+ MemoryAccess &getArrayAccessFor(const Instruction *Inst) const {
+ MemoryAccess *ArrayAccess = getArrayAccessOrNULLFor(Inst);
- return NumAccesses;
+ assert(ArrayAccess && "No array access found for instruction!");
+ return *ArrayAccess;
}
void setBasicBlock(BasicBlock *Block) {
for (LoadInst *LI : RIL) {
assert(LI && getRegion().contains(LI));
ScopStmt *Stmt = getStmtForBasicBlock(LI->getParent());
- if (Stmt && Stmt->getNumberOfArrayAccessesFor(LI) > 0) {
+ if (Stmt && Stmt->getArrayAccessOrNULLFor(LI)) {
invalidate(INVARIANTLOAD, LI->getDebugLoc());
return;
}