diff options
author | James Molloy <james.molloy@arm.com> | 2012-12-20 16:04:27 +0000 |
---|---|---|
committer | James Molloy <james.molloy@arm.com> | 2012-12-20 16:04:27 +0000 |
commit | 67ae13575900e8efd056672987249fd0adbf5e73 (patch) | |
tree | c297968f698f92b4b2d7b06c6d892a2299061887 /include | |
parent | 6af228a92a7b8414fa3c1b3c37ee659d32e66e1b (diff) |
Add a new attribute, 'noduplicate'. If a function contains a noduplicate call, the call cannot be duplicated - Jump threading, loop unrolling, loop unswitching, and loop rotation are inhibited if they would duplicate the call.
Similarly inlining of the function is inhibited, if that would duplicate the call (in particular inlining is still allowed when there is only one callsite and the function has internal linkage).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Analysis/CodeMetrics.h | 9 | ||||
-rw-r--r-- | include/llvm/Attributes.h | 4 | ||||
-rw-r--r-- | include/llvm/Function.h | 8 | ||||
-rw-r--r-- | include/llvm/Instructions.h | 7 |
4 files changed, 24 insertions, 4 deletions
diff --git a/include/llvm/Analysis/CodeMetrics.h b/include/llvm/Analysis/CodeMetrics.h index 4398faa20a..35eabec6ee 100644 --- a/include/llvm/Analysis/CodeMetrics.h +++ b/include/llvm/Analysis/CodeMetrics.h @@ -46,8 +46,11 @@ namespace llvm { /// \brief True if this function calls itself. bool isRecursive; - /// \brief True if this function contains one or more indirect branches. - bool containsIndirectBr; + /// \brief True if this function cannot be duplicated. + /// + /// True if this function contains one or more indirect branches, or it contains + /// one or more 'noduplicate' instructions. + bool notDuplicatable; /// \brief True if this function calls alloca (in the C sense). bool usesDynamicAlloca; @@ -79,7 +82,7 @@ namespace llvm { unsigned NumRets; CodeMetrics() : exposesReturnsTwice(false), isRecursive(false), - containsIndirectBr(false), usesDynamicAlloca(false), + notDuplicatable(false), usesDynamicAlloca(false), NumInsts(0), NumBlocks(0), NumCalls(0), NumInlineCandidates(0), NumVectorInsts(0), NumRets(0) {} diff --git a/include/llvm/Attributes.h b/include/llvm/Attributes.h index e158d7e8f2..ab4735fe36 100644 --- a/include/llvm/Attributes.h +++ b/include/llvm/Attributes.h @@ -67,6 +67,7 @@ public: Nest, ///< Nested function static chain NoAlias, ///< Considered to not alias after call NoCapture, ///< Function creates no aliases of pointer + NoDuplicate, ///< Call cannot be duplicated NoImplicitFloat, ///< Disable implicit floating point insts NoInline, ///< inline=never NonLazyBind, ///< Function is called early and/or @@ -223,7 +224,8 @@ public: .removeAttribute(Attribute::NonLazyBind) .removeAttribute(Attribute::ReturnsTwice) .removeAttribute(Attribute::AddressSafety) - .removeAttribute(Attribute::MinSize); + .removeAttribute(Attribute::MinSize) + .removeAttribute(Attribute::NoDuplicate); } uint64_t Raw() const { return Bits; } diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 2f555e89d8..f665db2a04 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -250,6 +250,14 @@ public: addFnAttr(Attribute::NoUnwind); } + /// @brief Determine if the call cannot be duplicated. + bool cannotDuplicate() const { + return getFnAttributes().hasAttribute(Attribute::NoDuplicate); + } + void setCannotDuplicate() { + addFnAttr(Attribute::NoDuplicate); + } + /// @brief True if the ABI mandates (or the user requested) that this /// function be in a unwind table. bool hasUWTable() const { diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index be865a1047..b8ce3a3b78 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -1336,6 +1336,13 @@ public: Attribute::get(getContext(), Attribute::NoUnwind)); } + /// \brief Determine if the call cannot be duplicated. + bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); } + void setCannotDuplicate() { + addAttribute(AttributeSet::FunctionIndex, + Attribute::get(getContext(), Attribute::NoDuplicate)); + } + /// \brief Determine if the call returns a structure through first /// pointer argument. bool hasStructRetAttr() const { |