diff options
author | Farzon Lotfi <1802579+farzonl@users.noreply.github.com> | 2024-07-11 17:08:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-11 17:08:13 -0400 |
commit | 92fc1eb0c1ae3813f2ac9208e2c74207aae9d23f (patch) | |
tree | 9457a5ad3c489ea85629fbe4509e6a6ef82d8231 /clang/lib/CodeGen/CGLoopInfo.cpp | |
parent | 8901c1c2801018ec3efa042a3acc8bada7b790e3 (diff) | |
download | llvm-92fc1eb0c1ae3813f2ac9208e2c74207aae9d23f.zip llvm-92fc1eb0c1ae3813f2ac9208e2c74207aae9d23f.tar.gz llvm-92fc1eb0c1ae3813f2ac9208e2c74207aae9d23f.tar.bz2 |
[HLSL] add loop unroll (#93879)
spec: https://github.com/microsoft/hlsl-specs/pull/263
- `Attr.td` - Define the HLSL loop attribute hints (unroll and loop)
- `AttrDocs.td` - Add documentation for unroll and loop
- `CGLoopInfo.cpp` - Add codegen for HLSL unroll that maps to clang
unroll expectations
- `ParseStmt.cpp` - For statements if HLSL define DeclSpecAttrs via
MaybeParseMicrosoftAttributes
- `SemaStmtAttr.cpp` - Add the HLSL loop unroll handeling
resolves #70114
dxc examples:
- for loop: https://hlsl.godbolt.org/z/8EK6Pa139
- while loop: https://hlsl.godbolt.org/z/ebr5MvEcK
- do while: https://hlsl.godbolt.org/z/be8cedoTs
Documentation:

Diffstat (limited to 'clang/lib/CodeGen/CGLoopInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGLoopInfo.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp index 0d4800b..6b886bd 100644 --- a/clang/lib/CodeGen/CGLoopInfo.cpp +++ b/clang/lib/CodeGen/CGLoopInfo.cpp @@ -612,9 +612,9 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx, const LoopHintAttr *LH = dyn_cast<LoopHintAttr>(Attr); const OpenCLUnrollHintAttr *OpenCLHint = dyn_cast<OpenCLUnrollHintAttr>(Attr); - + const HLSLLoopHintAttr *HLSLLoopHint = dyn_cast<HLSLLoopHintAttr>(Attr); // Skip non loop hint attributes - if (!LH && !OpenCLHint) { + if (!LH && !OpenCLHint && !HLSLLoopHint) { continue; } @@ -635,6 +635,17 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx, Option = LoopHintAttr::UnrollCount; State = LoopHintAttr::Numeric; } + } else if (HLSLLoopHint) { + ValueInt = HLSLLoopHint->getDirective(); + if (HLSLLoopHint->getSemanticSpelling() == + HLSLLoopHintAttr::Spelling::Microsoft_unroll) { + if (ValueInt == 0) + State = LoopHintAttr::Enable; + if (ValueInt > 0) { + Option = LoopHintAttr::UnrollCount; + State = LoopHintAttr::Numeric; + } + } } else if (LH) { auto *ValueExpr = LH->getValue(); if (ValueExpr) { |