diff options
author | Atmn Patel <a335pate@uwaterloo.ca> | 2020-11-02 16:03:21 -0500 |
---|---|---|
committer | Atmn Patel <a335pate@uwaterloo.ca> | 2020-11-04 22:03:14 -0500 |
commit | ac73b73c16526c9e51943759ea6cab285a57e33f (patch) | |
tree | 0002a0e6b5a0ae7368d355a729e32294d33224aa /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | bbd4ebffd4a634a9256f5eb33b3cce06ade8d809 (diff) | |
download | llvm-ac73b73c16526c9e51943759ea6cab285a57e33f.zip llvm-ac73b73c16526c9e51943759ea6cab285a57e33f.tar.gz llvm-ac73b73c16526c9e51943759ea6cab285a57e33f.tar.bz2 |
[clang] Add mustprogress and llvm.loop.mustprogress attribute deduction
Since C++11, the C++ standard has a forward progress guarantee
[intro.progress], so all such functions must have the `mustprogress`
requirement. In addition, from C11 and onwards, loops without a non-zero
constant conditional or no conditional are also required to make
progress (C11 6.8.5p6). This patch implements these attribute deductions
so they can be used by the optimization passes.
Differential Revision: https://reviews.llvm.org/D86841
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index f1fe8f9..ea33ea0 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1159,10 +1159,18 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, void CodeGenFunction::EmitFunctionBody(const Stmt *Body) { incrementProfileCounter(Body); + if (CPlusPlusWithProgress()) + FnIsMustProgress = true; + if (const CompoundStmt *S = dyn_cast<CompoundStmt>(Body)) EmitCompoundStmtWithoutScope(*S); else EmitStmt(Body); + + // This is checked after emitting the function body so we know if there + // are any permitted infinite loops. + if (FnIsMustProgress) + CurFn->addFnAttr(llvm::Attribute::MustProgress); } /// When instrumenting to collect profile data, the counts for some blocks |