llvm.org GIT mirror llvm / 8b7d706
Documentation clarifications for isSafeToSpeculativelyExecute. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76168 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Friedman 10 years ago
1 changed file(s) with 17 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
181181
182182 /// mayHaveSideEffects - Return true if the instruction may have side effects.
183183 ///
184 /// Note that this does not consider malloc and alloca to have side
185 /// effects because the newly allocated memory is completely invisible to
186 /// instructions which don't used the returned value. For cases where this
187 /// matters, isSafeToSpeculativelyExecute may be more appropriate.
184188 bool mayHaveSideEffects() const {
185189 return mayWriteToMemory() || mayThrow();
186190 }
187191
188192 /// isSafeToSpeculativelyExecute - Return true if the instruction does not
189193 /// have any effects besides calculating the result and does not have
190 /// undefined behavior. Unlike in mayHaveSideEffects(), allocating memory
191 /// is considered an effect.
194 /// undefined behavior.
195 ///
196 /// This method never returns true for an instruction that returns true for
197 /// mayHaveSideEffects; however, this method also does some other checks in
198 /// addition. It checks for undefined behavior, like dividing by zero or
199 /// loading from an invalid pointer (but not for undefined results, like a
200 /// shift with a shift amount larger than the width of the result). It checks
201 /// for malloc and alloca because speculatively executing them might cause a
202 /// memory leak. It also returns false for instructions related to control
203 /// flow, specifically terminators and PHI nodes.
192204 ///
193205 /// This method only looks at the instruction itself and its operands, so if
194206 /// this method returns true, it is safe to move the instruction as long as
195 /// the operands still dominate it. However, care must be taken with
196 /// instructions which read memory.
207 /// the correct dominance relationships for the operands and users hold.
208 /// However, this method can return true for instructions that read memory;
209 /// for such instructions, moving them may change the resulting value.
197210 bool isSafeToSpeculativelyExecute() const;
198211
199212 /// Methods for support type inquiry through isa, cast, and dyn_cast: