From f95f945fb00ea7fb33adab917ceb022451e9f2a5 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Sat, 20 Sep 2008 16:45:58 +0000 Subject: [PATCH] Implement review feedback from Devang: make use of mayReadFromMemory and mayWriteToMemory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56387 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/AddReadAttrs.cpp | 39 +++++++++-------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/lib/Transforms/IPO/AddReadAttrs.cpp b/lib/Transforms/IPO/AddReadAttrs.cpp index 1052e06b72f..8f7fd6e6a8c 100644 --- a/lib/Transforms/IPO/AddReadAttrs.cpp +++ b/lib/Transforms/IPO/AddReadAttrs.cpp @@ -54,7 +54,7 @@ bool AddReadAttrs::runOnSCC(const std::vector &SCC) { Function *F = SCC[i]->getFunction(); if (F == 0) - // May write memory. + // External node - may write memory. return false; if (F->doesNotAccessMemory()) @@ -72,34 +72,19 @@ bool AddReadAttrs::runOnSCC(const std::vector &SCC) { continue; } - // Scan the function body for explicit loads and stores, or calls to - // functions that may read or write memory. + // Scan the function body for instructions that may read or write memory. for (inst_iterator II = inst_begin(F), E = inst_end(F); II != E; ++II) { - Instruction *I = &*II; - if (LoadInst *LI = dyn_cast(I)) { - if (LI->isVolatile()) - // Volatile loads may have side-effects, so treat them as writing - // memory. - return false; - ReadsMemory = true; - } else if (isa(I) || isa(I) || isa(I)) { - // Writes memory. + CallSite CS = CallSite::get(&*II); + + // Ignore calls to functions in the same SCC. + if (CS.getInstruction() && + std::find(SCC.begin(), SCC.end(), CG[CS.getCalledFunction()]) != + SCC.end()) + continue; + + if (II->mayWriteToMemory()) return false; - } else if (isa(I) || isa(I)) { - CallSite CS(I); - - if (std::find(SCC.begin(), SCC.end(), CG[CS.getCalledFunction()]) != - SCC.end()) - // The callee is inside our current SCC - ignore it. - continue; - - if (!CS.onlyReadsMemory()) - // May write memory. - return false; - - if (!CS.doesNotAccessMemory()) - ReadsMemory = true; - } + ReadsMemory |= II->mayReadFromMemory(); } }