[llvm-branch-commits] [llvm] [DirectX] Implement the resource.load.rawbuffer intrinsic (PR #121012)
@@ -542,6 +542,48 @@ class OpLowerer { }); } + [[nodiscard]] bool lowerRawBufferLoad(Function &F) { +Triple TT(Triple(M.getTargetTriple())); +VersionTuple DXILVersion = TT.getDXILVersion(); +const DataLayout &DL = F.getDataLayout(); +IRBuilder<> &IRB = OpBuilder.getIRB(); +Type *Int8Ty = IRB.getInt8Ty(); +Type *Int32Ty = IRB.getInt32Ty(); + +return replaceFunction(F, [&](CallInst *CI) -> Error { + IRB.SetInsertPoint(CI); + + Type *OldTy = cast(CI->getType())->getElementType(0); + Type *ScalarTy = OldTy->getScalarType(); + Type *NewRetTy = OpBuilder.getResRetType(ScalarTy); + + Value *Handle = + createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType()); + Value *Index0 = CI->getArgOperand(1); + Value *Index1 = CI->getArgOperand(2); + uint64_t NumElements = + DL.getTypeSizeInBits(OldTy) / DL.getTypeSizeInBits(ScalarTy); + Value *Mask = ConstantInt::get(Int8Ty, ~(~0U << NumElements)); + Value *Align = + ConstantInt::get(Int32Ty, DL.getPrefTypeAlign(ScalarTy).value()); + + Expected OpCall = + DXILVersion >= VersionTuple(1, 2) + ? OpBuilder.tryCreateOp(OpCode::RawBufferLoad, + {Handle, Index0, Index1, Mask, Align}, + CI->getName(), NewRetTy) + : OpBuilder.tryCreateOp(OpCode::BufferLoad, + {Handle, Index0, Index1}, CI->getName(), + NewRetTy); + if (Error E = OpCall.takeError()) +return E; llvm-beanz wrote: nit: personal preference, take or leave it. ```suggestion if (!OpCall) return OpCall.takeError(); ``` https://github.com/llvm/llvm-project/pull/121012 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Implement the resource.load.rawbuffer intrinsic (PR #121012)
https://github.com/llvm-beanz approved this pull request. LGTM. One extremely small nit that you can take or leave. https://github.com/llvm/llvm-project/pull/121012 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Implement the resource.load.rawbuffer intrinsic (PR #121012)
https://github.com/llvm-beanz edited https://github.com/llvm/llvm-project/pull/121012 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for `BinLAnd` and `BinLOr` (PR #113113)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113113 >From 16e2bb8b73bcde1c2618bb358a905a9f463c1217 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 20 Oct 2024 16:24:26 +0900 Subject: [PATCH 1/3] [Coverage][Single] Enable Branch coverage for `BinLAnd` and `BinLOr` --- clang/lib/CodeGen/CGExprScalar.cpp | 83 +++- clang/lib/CodeGen/CGStmt.cpp | 4 -- clang/lib/CodeGen/CodeGenFunction.cpp| 43 ++-- clang/lib/CodeGen/CoverageMappingGen.cpp | 6 -- 4 files changed, 104 insertions(+), 32 deletions(-) diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 11d4ec8a267605..83962ba96aa484 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -4918,6 +4918,9 @@ Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) { } Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { + auto HasLHSSkip = CGF.getIsCounterPair(E); + auto HasRHSSkip = CGF.getIsCounterPair(E->getRHS()); + // Perform vector logical and on comparisons with zero vectors. if (E->getType()->isVectorType()) { CGF.incrementProfileCounter(E); @@ -4964,11 +4967,17 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { CodeGenFunction::isInstrumentedCondition(E->getRHS())) { CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond); llvm::BasicBlock *FBlock = CGF.createBasicBlock("land.end"); +llvm::BasicBlock *RHSSkip = +(HasRHSSkip.second ? CGF.createBasicBlock("land.rhsskip") : FBlock); llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt"); -Builder.CreateCondBr(RHSCond, RHSBlockCnt, FBlock); +Builder.CreateCondBr(RHSCond, RHSBlockCnt, RHSSkip); CGF.EmitBlock(RHSBlockCnt); -CGF.incrementProfileCounter(E->getRHS()); +CGF.incrementProfileCounter(false, E->getRHS()); CGF.EmitBranch(FBlock); +if (HasRHSSkip.second) { + CGF.EmitBlock(RHSSkip); + CGF.incrementProfileCounter(true, E->getRHS()); +} CGF.EmitBlock(FBlock); } @@ -4997,12 +5006,21 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { llvm::BasicBlock *ContBlock = CGF.createBasicBlock("land.end"); llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("land.rhs"); + llvm::BasicBlock *LHSFalseBlock = + (HasLHSSkip.second ? CGF.createBasicBlock("land.lhsskip") : ContBlock); + CodeGenFunction::ConditionalEvaluation eval(CGF); // Branch on the LHS first. If it is false, go to the failure (cont) block. - CGF.EmitBranchOnBoolExpr(E->getLHS(), RHSBlock, ContBlock, + CGF.EmitBranchOnBoolExpr(E->getLHS(), RHSBlock, LHSFalseBlock, CGF.getProfileCount(E->getRHS())); + if (HasLHSSkip.second) { +CGF.EmitBlock(LHSFalseBlock); +CGF.incrementProfileCounter(true, E); +CGF.EmitBranch(ContBlock); + } + // Any edges into the ContBlock are now from an (indeterminate number of) // edges from this first condition. All of these values will be false. Start // setting up the PHI node in the Cont Block for this. @@ -5014,7 +5032,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(false, E); Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); eval.end(CGF); @@ -5024,15 +5042,24 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { // If we're generating for profiling or coverage, generate a branch on the // RHS to a block that increments the RHS true counter needed to track branch // condition coverage. + llvm::BasicBlock *ContIncoming = RHSBlock; if (InstrumentRegions && CodeGenFunction::isInstrumentedCondition(E->getRHS())) { CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond); llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt"); -Builder.CreateCondBr(RHSCond, RHSBlockCnt, ContBlock); +llvm::BasicBlock *RHSBlockSkip = +(HasRHSSkip.second ? CGF.createBasicBlock("land.rhsskip") : ContBlock); +Builder.CreateCondBr(RHSCond, RHSBlockCnt, RHSBlockSkip); CGF.EmitBlock(RHSBlockCnt); -CGF.incrementProfileCounter(E->getRHS()); +CGF.incrementProfileCounter(false, E->getRHS()); CGF.EmitBranch(ContBlock); PN->addIncoming(RHSCond, RHSBlockCnt); +if (HasRHSSkip.second) { + CGF.EmitBlock(RHSBlockSkip); + CGF.incrementProfileCounter(true, E->getRHS()); + CGF.EmitBranch(ContBlock); + ContIncoming = RHSBlockSkip; +} } // Emit an unconditional branch from this block to ContBlock. @@ -5042,7 +5069,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { CGF.EmitBlock(ContBlock); } // Insert an entry into the phi node for the edge with the value of RHSCond.
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for loop statements (PR #113109)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113109 >From 5d19c77551c6fc585d1b15c4c2a71c3c3f99ef8a Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Fri, 18 Oct 2024 09:33:51 +0900 Subject: [PATCH 1/4] [Coverage][Single] Enable Branch coverage for loop statements --- clang/lib/CodeGen/CGStmt.cpp | 82 --- clang/lib/CodeGen/CodeGenFunction.cpp | 11 +- clang/lib/CodeGen/CodeGenPGO.cpp | 79 +-- clang/lib/CodeGen/CoverageMappingGen.cpp | 130 +- .../CoverageMapping/single-byte-counters.cpp | 53 +++ 5 files changed, 97 insertions(+), 258 deletions(-) diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index dbc1ce9bf993cd..7d778ce58a1487 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -1039,15 +1039,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, SourceLocToDebugLoc(R.getEnd()), checkIfLoopMustProgress(S.getCond(), hasEmptyLoopBody(S))); - // When single byte coverage mode is enabled, add a counter to loop condition. - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(S.getCond()); - // As long as the condition is true, go to the loop body. llvm::BasicBlock *LoopBody = createBasicBlock("while.body"); if (EmitBoolCondBranch) { llvm::BasicBlock *ExitBlock = LoopExit.getBlock(); -if (ConditionScope.requiresCleanups()) +if (getIsCounterPair(&S).second || ConditionScope.requiresCleanups()) ExitBlock = createBasicBlock("while.exit"); llvm::MDNode *Weights = createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody())); @@ -1058,6 +1054,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, if (ExitBlock != LoopExit.getBlock()) { EmitBlock(ExitBlock); + incrementProfileCounter(true, &S); EmitBranchThroughCleanup(LoopExit); } } else if (const Attr *A = Stmt::getLikelihoodAttr(S.getBody())) { @@ -1075,11 +1072,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, { RunCleanupsScope BodyScope(*this); EmitBlock(LoopBody); -// When single byte coverage mode is enabled, add a counter to the body. -if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getBody()); -else - incrementProfileCounter(&S); +incrementProfileCounter(false, &S); EmitStmt(S.getBody()); } @@ -1099,13 +1092,10 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, // The LoopHeader typically is just a branch if we skipped emitting // a branch, try to erase it. - if (!EmitBoolCondBranch) + if (!EmitBoolCondBranch) { SimplifyForwardingBlocks(LoopHeader.getBlock()); - - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(&S); +PGO.markStmtAsUsed(true, &S); + } if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.pop_back(); @@ -1124,10 +1114,7 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, // Emit the body of the loop. llvm::BasicBlock *LoopBody = createBasicBlock("do.body"); - if (llvm::EnableSingleByteCoverage) -EmitBlockWithFallThrough(LoopBody, S.getBody()); - else -EmitBlockWithFallThrough(LoopBody, &S); + EmitBlockWithFallThrough(LoopBody, &S); if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.push_back( @@ -1139,9 +1126,6 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, } EmitBlock(LoopCond.getBlock()); - // When single byte coverage mode is enabled, add a counter to loop condition. - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(S.getCond()); // C99 6.8.5.2: "The evaluation of the controlling expression takes place // after each execution of the loop body." @@ -1164,16 +1148,25 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, SourceLocToDebugLoc(R.getEnd()), checkIfLoopMustProgress(S.getCond(), hasEmptyLoopBody(S))); + auto *LoopFalse = + (getIsCounterPair(&S).second ? createBasicBlock("do.loopfalse") + : LoopExit.getBlock()); + // As long as the condition is true, iterate the loop. if (EmitBoolCondBranch) { uint64_t BackedgeCount = getProfileCount(S.getBody()) - ParentCount; Builder.CreateCondBr( -BoolCondVal, LoopBody, LoopExit.getBlock(), +BoolCondVal, LoopBody, LoopFalse, createProfileWeightsForLoop(S.getCond(), BackedgeCount)); } LoopStack.pop(); + if (LoopFalse != LoopExit.getBlock()) { +EmitBlock(LoopFalse); +incrementProfileCounter(true, &S, true); + } + // Emit the exit block. EmitBlock(LoopExit.getBlock()); @@ -1182,11 +1175,6 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, if (!EmitBoolCondBranch) SimplifyForwardingBlocks(LoopCond.getBlock());
[llvm-branch-commits] [flang] 32dc6f5 - Revert "Reland '[flang] Allow to pass an async id to allocate the descriptor …"
Author: Valentin Clement (バレンタイン クレメン) Date: 2024-12-23T21:26:29-08:00 New Revision: 32dc6f5f1b38f09f43fa4d1b697f102723ceb3ca URL: https://github.com/llvm/llvm-project/commit/32dc6f5f1b38f09f43fa4d1b697f102723ceb3ca DIFF: https://github.com/llvm/llvm-project/commit/32dc6f5f1b38f09f43fa4d1b697f102723ceb3ca.diff LOG: Revert "Reland '[flang] Allow to pass an async id to allocate the descriptor …" This reverts commit 5b74fb75d90ef6620741af45f146cefacbd9ecef. Added: Modified: flang/include/flang/Runtime/CUDA/allocator.h flang/include/flang/Runtime/CUDA/common.h flang/include/flang/Runtime/allocatable.h flang/include/flang/Runtime/allocator-registry.h flang/include/flang/Runtime/descriptor.h flang/lib/Lower/Allocatable.cpp flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp flang/runtime/CUDA/allocatable.cpp flang/runtime/CUDA/allocator.cpp flang/runtime/CUDA/descriptor.cpp flang/runtime/allocatable.cpp flang/runtime/array-constructor.cpp flang/runtime/descriptor.cpp flang/test/HLFIR/elemental-codegen.fir flang/test/Lower/OpenACC/acc-declare.f90 flang/test/Lower/allocatable-polymorphic.f90 flang/test/Lower/allocatable-runtime.f90 flang/test/Lower/allocate-mold.f90 flang/test/Lower/polymorphic.f90 flang/unittests/Runtime/CUDA/Allocatable.cpp flang/unittests/Runtime/CUDA/AllocatorCUF.cpp flang/unittests/Runtime/CUDA/Memory.cpp Removed: diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h index b6f0e7f303176c..4fb4c94c5e9b0a 100644 --- a/flang/include/flang/Runtime/CUDA/allocator.h +++ b/flang/include/flang/Runtime/CUDA/allocator.h @@ -20,16 +20,16 @@ extern "C" { void RTDECL(CUFRegisterAllocator)(); } -void *CUFAllocPinned(std::size_t, std::int64_t = kCudaNoStream); +void *CUFAllocPinned(std::size_t); void CUFFreePinned(void *); -void *CUFAllocDevice(std::size_t, std::int64_t); +void *CUFAllocDevice(std::size_t); void CUFFreeDevice(void *); -void *CUFAllocManaged(std::size_t, std::int64_t = kCudaNoStream); +void *CUFAllocManaged(std::size_t); void CUFFreeManaged(void *); -void *CUFAllocUnified(std::size_t, std::int64_t = kCudaNoStream); +void *CUFAllocUnified(std::size_t); void CUFFreeUnified(void *); } // namespace Fortran::runtime::cuda diff --git a/flang/include/flang/Runtime/CUDA/common.h b/flang/include/flang/Runtime/CUDA/common.h index 9c95f727ee6734..474f8e6578b891 100644 --- a/flang/include/flang/Runtime/CUDA/common.h +++ b/flang/include/flang/Runtime/CUDA/common.h @@ -23,9 +23,6 @@ static constexpr unsigned kHostToDevice = 0; static constexpr unsigned kDeviceToHost = 1; static constexpr unsigned kDeviceToDevice = 2; -/// Value used for asyncId when no specific stream is specified. -static constexpr std::int64_t kCudaNoStream = -1; - #define CUDA_REPORT_IF_ERROR(expr) \ [](cudaError_t err) { \ if (err == cudaSuccess) \ diff --git a/flang/include/flang/Runtime/allocatable.h b/flang/include/flang/Runtime/allocatable.h index 121c31af963aa0..58061d9862095e 100644 --- a/flang/include/flang/Runtime/allocatable.h +++ b/flang/include/flang/Runtime/allocatable.h @@ -94,9 +94,9 @@ int RTDECL(AllocatableCheckLengthParameter)(Descriptor &, // Successfully allocated memory is initialized if the allocatable has a // derived type, and is always initialized by AllocatableAllocateSource(). // Performs all necessary coarray synchronization and validation actions. -int RTDECL(AllocatableAllocate)(Descriptor &, std::int64_t asyncId = -1, -bool hasStat = false, const Descriptor *errMsg = nullptr, -const char *sourceFile = nullptr, int sourceLine = 0); +int RTDECL(AllocatableAllocate)(Descriptor &, bool hasStat = false, +const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr, +int sourceLine = 0); int RTDECL(AllocatableAllocateSource)(Descriptor &, const Descriptor &source, bool hasStat = false, const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr, int sourceLine = 0); diff --git a/flang/include/flang/Runtime/allocator-registry.h b/flang/include/flang/Runtime/allocator-registry.h index 4c3295edf13d9a..29302c5d825bc9 100644 --- a/flang/include/flang/Runtime/allocator-registry.h +++ b/flang/include/flang/Runtime/allocator-registry.h @@ -11,7 +11,6 @@ #include "flang/Common/api-attrs.h" #include "flang/Runtime/allocator-registry-consts.h" -#include #include #include @@ -19,7 +18,7 @@ namespace Fortran::runtime { -using AllocFct = void *(*)(std::size_t, std::int64_t); +using AllocFct = void *(*)(std::size_t); using FreeFct = void (*)(void *); typedef struct Allocator_t { @@ -27,11 +26,10 @@ typedef struct Allocator_t { FreeFct free{nullptr}; } Allocator_t; -static RT_API_ATTRS void *MallocWrapper( -std::size_t size, [[maybe_unused]] std::int64_t) { +#ifdef RT_DE
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for CondOp (PR #113110)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113110 >From 744c5b634de08f9214c82d6fcfde7179bc4edfb0 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 20 Oct 2024 14:46:07 +0900 Subject: [PATCH 1/4] [Coverage][Single] Enable Branch coverage for CondOp --- clang/lib/CodeGen/CGExpr.cpp | 6 +-- clang/lib/CodeGen/CGExprAgg.cpp | 14 +-- clang/lib/CodeGen/CGExprComplex.cpp | 15 +--- clang/lib/CodeGen/CGExprScalar.cpp| 37 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 3 +- clang/lib/CodeGen/CodeGenPGO.cpp | 8 clang/lib/CodeGen/CoverageMappingGen.cpp | 16 ++-- .../CoverageMapping/single-byte-counters.cpp | 11 +++--- 8 files changed, 25 insertions(+), 85 deletions(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index cc85f05ad9f70c..67e3a1de17e679 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -5137,8 +5137,7 @@ std::optional HandleConditionalOperatorLValueSimpleCase( if (!CGF.ContainsLabel(Dead)) { // If the true case is live, we need to track its region. - if (CondExprBool) -CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(!CondExprBool, E, true); CGF.markStmtMaybeUsed(Dead); // If a throw expression we emit it and return an undefined lvalue // because it can't be used. @@ -5177,7 +5176,7 @@ ConditionalInfo EmitConditionalBlocks(CodeGenFunction &CGF, // Any temporaries created here are conditional. CGF.EmitBlock(Info.lhsBlock); - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(false, E); eval.begin(CGF); Info.LHS = BranchGenFunc(CGF, E->getTrueExpr()); eval.end(CGF); @@ -5188,6 +5187,7 @@ ConditionalInfo EmitConditionalBlocks(CodeGenFunction &CGF, // Any temporaries created here are conditional. CGF.EmitBlock(Info.rhsBlock); + CGF.incrementProfileCounter(true, E); eval.begin(CGF); Info.RHS = BranchGenFunc(CGF, E->getFalseExpr()); eval.end(CGF); diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 2ad6587089f101..0c778ef185532f 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -36,10 +36,6 @@ using namespace CodeGen; //Aggregate Expression Emitter //===--===// -namespace llvm { -extern cl::opt EnableSingleByteCoverage; -} // namespace llvm - namespace { class AggExprEmitter : public StmtVisitor { CodeGenFunction &CGF; @@ -1293,10 +1289,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(LHSBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E->getTrueExpr()); - else -CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(false, E); Visit(E->getTrueExpr()); eval.end(CGF); @@ -1311,8 +1304,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E->getFalseExpr()); + CGF.incrementProfileCounter(true, E); Visit(E->getFalseExpr()); eval.end(CGF); @@ -1321,8 +1313,6 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { E->getType()); CGF.EmitBlock(ContBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E); } void AggExprEmitter::VisitChooseExpr(const ChooseExpr *CE) { diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index fef26e7b4ccdbd..bcece9431de764 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -28,10 +28,6 @@ using namespace CodeGen; //Complex Expression Emitter //===--===// -namespace llvm { -extern cl::opt EnableSingleByteCoverage; -} // namespace llvm - typedef CodeGenFunction::ComplexPairTy ComplexPairTy; /// Return the complex type that we are meant to emit. @@ -1381,11 +1377,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(LHSBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E->getTrueExpr()); - else -CGF.incrementProfileCounter(E); - + CGF.incrementProfileCounter(false, E); ComplexPairTy LHS = Visit(E->getTrueExpr()); LHSBlock = Builder.GetInsertBlock(); CGF.EmitBranch(ContBlock); @@ -1393,13 +1385,10 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E->getFalseExpr()); + CGF.incrementProfileCounter(true, E); Com
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for IfStmt (PR #113111)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113111 >From 3ea6383e2142889550f37389dfaaee81e5ae7d9c Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 20 Oct 2024 15:15:03 +0900 Subject: [PATCH 1/3] [Coverage][Single] Enable Branch coverage for IfStmt --- clang/lib/CodeGen/CGStmt.cpp | 31 +++- clang/lib/CodeGen/CodeGenPGO.cpp | 12 --- clang/lib/CodeGen/CoverageMappingGen.cpp | 21 +++ .../CoverageMapping/single-byte-counters.cpp | 36 ++- 4 files changed, 38 insertions(+), 62 deletions(-) diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index dbc1ce9bf993cd..c511e5f4f4213a 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -840,8 +840,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { // If the skipped block has no labels in it, just emit the executed block. // This avoids emitting dead code and simplifies the CFG substantially. if (S.isConstexpr() || !ContainsLabel(Skipped)) { - if (CondConstant) -incrementProfileCounter(&S); + incrementProfileCounter(!CondConstant, &S, true); if (Executed) { RunCleanupsScope ExecutedScope(*this); EmitStmt(Executed); @@ -851,14 +850,14 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { } } + auto HasSkip = getIsCounterPair(&S); + // Otherwise, the condition did not fold, or we couldn't elide it. Just emit // the conditional branch. llvm::BasicBlock *ThenBlock = createBasicBlock("if.then"); llvm::BasicBlock *ContBlock = createBasicBlock("if.end"); - llvm::BasicBlock *ElseBlock = ContBlock; - if (Else) -ElseBlock = createBasicBlock("if.else"); - + llvm::BasicBlock *ElseBlock = + (Else || HasSkip.second ? createBasicBlock("if.else") : ContBlock); // Prefer the PGO based weights over the likelihood attribute. // When the build isn't optimized the metadata isn't used, so don't generate // it. @@ -891,10 +890,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { // Emit the 'then' code. EmitBlock(ThenBlock); - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(S.getThen()); - else -incrementProfileCounter(&S); + incrementProfileCounter(false, &S); { RunCleanupsScope ThenScope(*this); EmitStmt(S.getThen()); @@ -908,9 +904,9 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { auto NL = ApplyDebugLocation::CreateEmpty(*this); EmitBlock(ElseBlock); } -// When single byte coverage mode is enabled, add a counter to else block. -if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(Else); +// Add a counter to else block unless it has CounterExpr. +if (HasSkip.second) + incrementProfileCounter(true, &S); { RunCleanupsScope ElseScope(*this); EmitStmt(Else); @@ -920,15 +916,14 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { auto NL = ApplyDebugLocation::CreateEmpty(*this); EmitBranch(ContBlock); } + } else if (HasSkip.second) { +EmitBlock(ElseBlock); +incrementProfileCounter(true, &S); +EmitBranch(ContBlock); } // Emit the continuation block for code after the if. EmitBlock(ContBlock, true); - - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(&S); } bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression, diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 0f2090da47a374..f6b9b5c82952c4 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -366,18 +366,6 @@ struct MapRegionCounters : public RecursiveASTVisitor { if (Hash.getHashVersion() == PGO_HASH_V1) return Base::TraverseIfStmt(If); -// When single byte coverage mode is enabled, add a counter to then and -// else. -bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage; -for (Stmt *CS : If->children()) { - if (!CS || NoSingleByteCoverage) -continue; - if (CS == If->getThen()) -CounterMap[If->getThen()] = NextCounter++; - else if (CS == If->getElse()) -CounterMap[If->getElse()] = NextCounter++; -} - // Otherwise, keep track of which branch we're in while traversing. VisitStmt(If); diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index a331d5bc68286b..6c6aecb9994c6b 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -2050,12 +2050,7 @@ struct CounterCoverageMappingBuilder extendRegion(S->getCond()); Counter ParentCount = getRegion().getCounter(); -auto [ThenCount, ElseCount] = -(llvm::EnableSingleByteCoverage - ? std::make_pair(getRegionCounter(S->getThen())
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for SwitchStmt (PR #113112)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113112 >From ec05cc37e1177f06c9a44a1e39dadc9306cc5c68 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Mon, 21 Oct 2024 08:09:31 +0900 Subject: [PATCH 1/2] [Coverage][Single] Enable Branch coverage for SwitchStmt --- clang/lib/CodeGen/CGStmt.cpp | 12 ++ clang/lib/CodeGen/CoverageMappingGen.cpp | 22 ++- .../CoverageMapping/single-byte-counters.cpp | 13 ++- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index dbc1ce9bf993cd..80fe5cf183de16 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -2259,6 +2259,18 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) { ConditionScope.ForceCleanup(); + // Close the last case (or DefaultBlock). + EmitBranch(SwitchExit.getBlock()); + + // Insert a False Counter if SwitchStmt doesn't have DefaultStmt. + if (getIsCounterPair(S.getCond()).second) { +auto *ImplicitDefaultBlock = createBasicBlock("sw.false"); +EmitBlock(ImplicitDefaultBlock); +incrementProfileCounter(true, S.getCond()); +Builder.CreateBr(SwitchInsn->getDefaultDest()); +SwitchInsn->setDefaultDest(ImplicitDefaultBlock); + } + // Emit continuation. EmitBlock(SwitchExit.getBlock(), true); incrementProfileCounter(&S); diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index a331d5bc68286b..c5fdf23299e4e9 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -958,6 +958,14 @@ struct CounterCoverageMappingBuilder return {ExecCnt, SkipCnt}; } + Counter getSwitchImplicitDefaultCounter(const Stmt *Cond, Counter ParentCount, + Counter CaseCountSum) { +return ( +llvm::EnableSingleByteCoverage +? Counter::getCounter(CounterMap[Cond].second = NextCounterNum++) +: subtractCounters(ParentCount, CaseCountSum)); + } + bool IsCounterEqual(Counter OutCount, Counter ParentCount) { if (OutCount == ParentCount) return true; @@ -1885,7 +1893,7 @@ struct CounterCoverageMappingBuilder propagateCounts(Counter::getZero(), Body); BreakContinue BC = BreakContinueStack.pop_back_val(); -if (!BreakContinueStack.empty() && !llvm::EnableSingleByteCoverage) +if (!BreakContinueStack.empty()) BreakContinueStack.back().ContinueCount = addCounters( BreakContinueStack.back().ContinueCount, BC.ContinueCount); @@ -1900,11 +1908,6 @@ struct CounterCoverageMappingBuilder MostRecentLocation = getStart(S); handleFileExit(ExitLoc); -// When single byte coverage mode is enabled, do not create branch region by -// early returning. -if (llvm::EnableSingleByteCoverage) - return; - // Create a Branch Region around each Case. Subtract the case's // counter from the Parent counter to track the "False" branch count. Counter CaseCountSum; @@ -1920,7 +1923,8 @@ struct CounterCoverageMappingBuilder // the hidden branch, which will be added later by the CodeGen. This region // will be associated with the switch statement's condition. if (!HasDefaultCase) { - Counter DefaultCount = subtractCounters(ParentCount, CaseCountSum); + Counter DefaultCount = getSwitchImplicitDefaultCounter( + S->getCond(), ParentCount, CaseCountSum); createBranchRegion(S->getCond(), Counter::getZero(), DefaultCount); } } @@ -1929,9 +1933,7 @@ struct CounterCoverageMappingBuilder extendRegion(S); SourceMappingRegion &Parent = getRegion(); -Counter Count = llvm::EnableSingleByteCoverage -? getRegionCounter(S) -: addCounters(Parent.getCounter(), getRegionCounter(S)); +Counter Count = addCounters(Parent.getCounter(), getRegionCounter(S)); // Reuse the existing region if it starts at our label. This is typical of // the first case in a switch. diff --git a/clang/test/CoverageMapping/single-byte-counters.cpp b/clang/test/CoverageMapping/single-byte-counters.cpp index d20b695bc2636a..464fa370d86f09 100644 --- a/clang/test/CoverageMapping/single-byte-counters.cpp +++ b/clang/test/CoverageMapping/single-byte-counters.cpp @@ -34,19 +34,22 @@ int testIfElseReturn(int x) { // CHECK-NEXT: File 0, [[@LINE]]:29 -> [[@LINE+9]] } // CHECK-NEXT: testSwitch -int testSwitch(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+17]]:2 = [[C30:#0]] +int testSwitch(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+20]]:2 = [[C30:#0]] int result; switch (x) { -// CHECK-NEXT: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE+10]]:15 = 0 - case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = [[C31:#2]] +// CHECK-NEXT: Gap,File
[llvm-branch-commits] [clang] [compiler-rt] [llvm] [Coverage] Move SingleByteCoverage out of CountedRegion (PR #110966)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/110966 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [compiler-rt] [llvm] [Coverage] Move SingleByteCoverage out of CountedRegion (PR #110966)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/110966 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (PR #118462)
@@ -56,20 +58,80 @@ class DefaultPriorityAdvisor : public RegAllocPriorityAdvisor { unsigned getPriority(const LiveInterval &LI) const override; }; -class RegAllocPriorityAdvisorAnalysis : public ImmutablePass { +/// Common provider for getting the priority advisor and logging rewards. +/// Legacy analysis forwards all calls to this provider. +/// New analysis serves the provider as the analysis result. +/// Expensive setup is done in the constructor, so that the advisor can be +/// created quickly for every machine function. +/// TODO: Remove once legacy PM support is dropped. +class RegAllocPriorityAdvisorProvider { public: enum class AdvisorMode : int { Default, Release, Development }; - RegAllocPriorityAdvisorAnalysis(AdvisorMode Mode) - : ImmutablePass(ID), Mode(Mode){}; - static char ID; + RegAllocPriorityAdvisorProvider(AdvisorMode Mode) : Mode(Mode) {} + + virtual ~RegAllocPriorityAdvisorProvider() = default; + + virtual void logRewardIfNeeded(const MachineFunction &MF, + llvm::function_ref GetReward) {}; - /// Get an advisor for the given context (i.e. machine function, etc) virtual std::unique_ptr getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0; + + void setAnalyses(SlotIndexes *SI) { this->SI = SI; } optimisan wrote: This provider is initialized only once for the pipeline and we just set the new analysis results while running Greedy. https://github.com/llvm/llvm-project/pull/118462 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [Coverage] Make additional counters available for BranchRegion. NFC. (PR #120930)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/120930 >From 5e460594c8a2550c38c759b2e6f1c5dc4152f820 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Thu, 17 Oct 2024 22:15:12 +0900 Subject: [PATCH 1/8] [Coverage] Make additional counters available for BranchRegion. NFC. `getBranchCounterPair()` allocates an additional Counter to SkipPath in `SingleByteCoverage`. `IsCounterEqual()` calculates the comparison with rewinding counter replacements. `NumRegionCounters` is updated to take additional counters in account. `incrementProfileCounter()` has a few additiona arguments. - `UseSkipPath=true`, to specify setting counters for SkipPath. It assumes `UseSkipPath=false` is used together. - `UseBoth` may be specified for marking another path. It introduces the same effect as issueing `markStmtAsUsed(!SkipPath, S)`. `llvm-cov` discovers counters in `FalseCount` to allocate `MaxCounterID` for empty profile data. --- clang/lib/CodeGen/CodeGenFunction.h | 8 - clang/lib/CodeGen/CodeGenPGO.cpp | 31 +-- clang/lib/CodeGen/CodeGenPGO.h| 1 + clang/lib/CodeGen/CoverageMappingGen.cpp | 31 ++- .../ProfileData/Coverage/CoverageMapping.cpp | 4 +++ 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 89ac3b342d0a7c..cb1192bf6e11fe 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1629,11 +1629,17 @@ class CodeGenFunction : public CodeGenTypeCache { /// Increment the profiler's counter for the given statement by \p StepV. /// If \p StepV is null, the default increment is 1. void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { +incrementProfileCounter(false, S, false, StepV); + } + + void incrementProfileCounter(bool UseSkipPath, const Stmt *S, + bool UseBoth = false, + llvm::Value *StepV = nullptr) { if (CGM.getCodeGenOpts().hasProfileClangInstr() && !CurFn->hasFnAttribute(llvm::Attribute::NoProfile) && !CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) { auto AL = ApplyDebugLocation::CreateArtificial(*this); - PGO.emitCounterSetOrIncrement(Builder, S, StepV); + PGO.emitCounterSetOrIncrement(Builder, S, UseSkipPath, UseBoth, StepV); } PGO.setCurrentStmt(S); } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 069469e3de856b..aefd53e12088b4 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1138,6 +1138,19 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) { if (CoverageMapping.empty()) return; + // Scan max(FalseCnt) and update NumRegionCounters. + unsigned MaxNumCounters = NumRegionCounters; + for (const auto [_, V] : *RegionCounterMap) { +auto HasCounters = V.getIsCounterPair(); +assert((!HasCounters.first || +MaxNumCounters > (V.first & CounterPair::Mask)) && + "TrueCnt should not be reassigned"); +if (HasCounters.second) + MaxNumCounters = + std::max(MaxNumCounters, (V.second & CounterPair::Mask) + 1); + } + NumRegionCounters = MaxNumCounters; + CGM.getCoverageMapping()->addFunctionMappingRecord( FuncNameVar, FuncName, FunctionHash, CoverageMapping); } @@ -1193,11 +1206,25 @@ std::pair CodeGenPGO::getIsCounterPair(const Stmt *S) const { } void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseSkipPath, bool UseBoth, llvm::Value *StepV) { - if (!RegionCounterMap || !Builder.GetInsertBlock()) + if (!RegionCounterMap) return; - unsigned Counter = (*RegionCounterMap)[S].first; + unsigned Counter; + auto &TheMap = (*RegionCounterMap)[S]; + auto IsCounter = TheMap.getIsCounterPair(); + if (!UseSkipPath) { +assert(IsCounter.first); +Counter = (TheMap.first & CounterPair::Mask); + } else { +if (!IsCounter.second) + return; +Counter = (TheMap.second & CounterPair::Mask); + } + + if (!Builder.GetInsertBlock()) +return; // Make sure that pointer to global is passed in with zero addrspace // This is relevant during GPU profiling diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h index 83f35785e5327d..8b769dd88d7f1e 100644 --- a/clang/lib/CodeGen/CodeGenPGO.h +++ b/clang/lib/CodeGen/CodeGenPGO.h @@ -112,6 +112,7 @@ class CodeGenPGO { public: std::pair getIsCounterPair(const Stmt *S) const; void emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseFalsePath, bool UseBoth, llvm::Value *StepV); void emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder, const Expr *S,
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (PR #118462)
@@ -150,12 +138,48 @@ class ReleaseModePriorityAdvisorAnalysis final InteractiveChannelBaseName + ".out", InteractiveChannelBaseName + ".in"); } -return std::make_unique( -MF, RA, &getAnalysis().getSI(), Runner.get()); +assert(SI && "SlotIndexes result must be set"); +return std::make_unique(MF, RA, SI, Runner.get()); } + +private: std::unique_ptr Runner; }; +RegAllocPriorityAdvisorProvider *createReleaseModePriorityAdvisorProvider() { + return new ReleaseModePriorityAdvisorProvider(); +} + +class ReleaseModePriorityAdvisorAnalysisLegacy final +: public RegAllocPriorityAdvisorAnalysisLegacy { +public: + ReleaseModePriorityAdvisorAnalysisLegacy() + : RegAllocPriorityAdvisorAnalysisLegacy(AdvisorMode::Release) {} + // support for isa<> and dyn_cast. + static bool classof(const RegAllocPriorityAdvisorAnalysisLegacy *R) { +return R->getAdvisorMode() == AdvisorMode::Release; + } + +private: + void getAnalysisUsage(AnalysisUsage &AU) const override { +AU.setPreservesAll(); +AU.addRequired(); +RegAllocPriorityAdvisorAnalysisLegacy::getAnalysisUsage(AU); + } + + std::unique_ptr &getProvider() override { +Provider->setAnalyses(&getAnalysis().getSI()); +return Provider; + } + + bool doInitialization(Module &M) override { +Provider = std::make_unique(); +return false; + } + + // std::unique_ptr Provider; arsenm wrote: Commented out code https://github.com/llvm/llvm-project/pull/118462 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (PR #118462)
@@ -20,76 +20,138 @@ using namespace llvm; -static cl::opt Mode( +static cl::opt Mode( "regalloc-enable-priority-advisor", cl::Hidden, -cl::init(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default), +cl::init(RegAllocPriorityAdvisorProvider::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values( -clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default, +clEnumValN(RegAllocPriorityAdvisorProvider::AdvisorMode::Default, "default", "Default"), -clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Release, +clEnumValN(RegAllocPriorityAdvisorProvider::AdvisorMode::Release, "release", "precompiled"), -clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Development, +clEnumValN(RegAllocPriorityAdvisorProvider::AdvisorMode::Development, "development", "for training"))); -char RegAllocPriorityAdvisorAnalysis::ID = 0; -INITIALIZE_PASS(RegAllocPriorityAdvisorAnalysis, "regalloc-priority", +char RegAllocPriorityAdvisorAnalysisLegacy::ID = 0; +INITIALIZE_PASS(RegAllocPriorityAdvisorAnalysisLegacy, "regalloc-priority", "Regalloc priority policy", false, true) namespace { -class DefaultPriorityAdvisorAnalysis final -: public RegAllocPriorityAdvisorAnalysis { + +class DefaultPriorityAdvisorProvider final +: public RegAllocPriorityAdvisorProvider { public: - DefaultPriorityAdvisorAnalysis(bool NotAsRequested) - : RegAllocPriorityAdvisorAnalysis(AdvisorMode::Default), + DefaultPriorityAdvisorProvider(bool NotAsRequested, LLVMContext &Ctx) + : RegAllocPriorityAdvisorProvider(AdvisorMode::Default) { +if (NotAsRequested) + Ctx.emitError("Requested regalloc priority advisor analysis " +"could be created. Using default"); + } + + // support for isa<> and dyn_cast. + static bool classof(const RegAllocPriorityAdvisorProvider *R) { +return R->getAdvisorMode() == AdvisorMode::Default; + } + + std::unique_ptr + getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override { +assert(SI && "SlotIndexes result must be set"); +return std::make_unique(MF, RA, SI); + } +}; + +class DefaultPriorityAdvisorAnalysisLegacy final +: public RegAllocPriorityAdvisorAnalysisLegacy { +public: + DefaultPriorityAdvisorAnalysisLegacy(bool NotAsRequested) + : RegAllocPriorityAdvisorAnalysisLegacy(AdvisorMode::Default), NotAsRequested(NotAsRequested) {} // support for isa<> and dyn_cast. - static bool classof(const RegAllocPriorityAdvisorAnalysis *R) { + static bool classof(const RegAllocPriorityAdvisorAnalysisLegacy *R) { return R->getAdvisorMode() == AdvisorMode::Default; } private: void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired(); -RegAllocPriorityAdvisorAnalysis::getAnalysisUsage(AU); +RegAllocPriorityAdvisorAnalysisLegacy::getAnalysisUsage(AU); } - std::unique_ptr - getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override { -return std::make_unique( -MF, RA, &getAnalysis().getSI()); + + std::unique_ptr &getProvider() override { +Provider->setAnalyses(&getAnalysis().getSI()); +return Provider; } + bool doInitialization(Module &M) override { -if (NotAsRequested) - M.getContext().emitError("Requested regalloc priority advisor analysis " - "could be created. Using default"); -return RegAllocPriorityAdvisorAnalysis::doInitialization(M); +Provider.reset( +new DefaultPriorityAdvisorProvider(NotAsRequested, M.getContext())); +return false; } + const bool NotAsRequested; + // std::unique_ptr Provider; }; } // namespace -template <> Pass *llvm::callDefaultCtor() { +void RegAllocPriorityAdvisorAnalysis::initializeProvider(LLVMContext &Ctx) { + if (Provider) +return; + + switch (Mode) { + case RegAllocPriorityAdvisorProvider::AdvisorMode::Default: +Provider.reset( +new DefaultPriorityAdvisorProvider(/*NotAsRequested*/ false, Ctx)); +break; + case RegAllocPriorityAdvisorProvider::AdvisorMode::Development: +#if defined(LLVM_HAVE_TFLITE) +Provider.reset(createDevelopmentModePriorityAdvisorProvider(Ctx)); +#endif +break; + case RegAllocPriorityAdvisorProvider::AdvisorMode::Release: +Provider.reset(createReleaseModePriorityAdvisorProvider()); +break; + } + if (!Provider) +Provider.reset( +new DefaultPriorityAdvisorProvider(/*NotAsRequested*/ true, Ctx)); arsenm wrote: ```suggestion new DefaultPriorityAdvisorProvider(/*NotAsRequested=*/ true, Ctx)); ``` This "NotAsRequested" name is bad, I don't know what it means https://github.com/llvm/llvm-project/pull/118462 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailma
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (PR #118462)
@@ -56,20 +58,80 @@ class DefaultPriorityAdvisor : public RegAllocPriorityAdvisor { unsigned getPriority(const LiveInterval &LI) const override; }; -class RegAllocPriorityAdvisorAnalysis : public ImmutablePass { +/// Common provider for getting the priority advisor and logging rewards. +/// Legacy analysis forwards all calls to this provider. +/// New analysis serves the provider as the analysis result. +/// Expensive setup is done in the constructor, so that the advisor can be +/// created quickly for every machine function. +/// TODO: Remove once legacy PM support is dropped. +class RegAllocPriorityAdvisorProvider { public: enum class AdvisorMode : int { Default, Release, Development }; - RegAllocPriorityAdvisorAnalysis(AdvisorMode Mode) - : ImmutablePass(ID), Mode(Mode){}; - static char ID; + RegAllocPriorityAdvisorProvider(AdvisorMode Mode) : Mode(Mode) {} + + virtual ~RegAllocPriorityAdvisorProvider() = default; + + virtual void logRewardIfNeeded(const MachineFunction &MF, + llvm::function_ref GetReward) {}; arsenm wrote: ```suggestion function_ref GetReward) {}; ``` https://github.com/llvm/llvm-project/pull/118462 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (PR #118462)
@@ -56,20 +58,80 @@ class DefaultPriorityAdvisor : public RegAllocPriorityAdvisor { unsigned getPriority(const LiveInterval &LI) const override; }; -class RegAllocPriorityAdvisorAnalysis : public ImmutablePass { +/// Common provider for getting the priority advisor and logging rewards. +/// Legacy analysis forwards all calls to this provider. +/// New analysis serves the provider as the analysis result. +/// Expensive setup is done in the constructor, so that the advisor can be +/// created quickly for every machine function. +/// TODO: Remove once legacy PM support is dropped. +class RegAllocPriorityAdvisorProvider { public: enum class AdvisorMode : int { Default, Release, Development }; - RegAllocPriorityAdvisorAnalysis(AdvisorMode Mode) - : ImmutablePass(ID), Mode(Mode){}; - static char ID; + RegAllocPriorityAdvisorProvider(AdvisorMode Mode) : Mode(Mode) {} + + virtual ~RegAllocPriorityAdvisorProvider() = default; + + virtual void logRewardIfNeeded(const MachineFunction &MF, + llvm::function_ref GetReward) {}; - /// Get an advisor for the given context (i.e. machine function, etc) virtual std::unique_ptr getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0; + + void setAnalyses(SlotIndexes *SI) { this->SI = SI; } arsenm wrote: Why can't this just be set at construction time? https://github.com/llvm/llvm-project/pull/118462 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (PR #118462)
@@ -254,7 +249,22 @@ class DevelopmentModePriorityAdvisorAnalysis final Log = std::make_unique(std::move(OS), LFS, Reward, /*IncludeReward*/ true); -return false; + } + + void logRewardIfNeeded(const MachineFunction &MF, + llvm::function_ref GetReward) override { +if (!Log || !Log->hasAnyObservationForContext(MF.getName())) + return; +// The function pass manager would run all the function passes for a +// function, so we assume the last context belongs to this function. If +// this invariant ever changes, we can implement at that time switching +// contexts. At this point, it'd be an error +if (Log->currentContext() != MF.getName()) { + MF.getFunction().getContext().emitError( + "The training log context shouldn't have had changed."); arsenm wrote: Errors should start with lowercase and should not use contractions https://github.com/llvm/llvm-project/pull/118462 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RegAllocGreedy: Fix subrange based instruction split logic (PR #120199)
@@ -1387,18 +1357,34 @@ static bool readsLaneSubset(const MachineRegisterInfo &MRI, DestSrc->Destination->getSubReg() == DestSrc->Source->getSubReg()) return false; + Register Reg = VirtReg.reg(); + // FIXME: We're only considering uses, but should be consider defs too? - LaneBitmask ReadMask = getInstReadLaneMask(MRI, *TRI, *MI, VirtReg.reg()); + LaneBitmask UseMask; + SmallVector, 8> Ops; + (void)AnalyzeVirtRegInBundle(const_cast(*MI), Reg, &Ops); - LaneBitmask LiveAtMask; - for (const LiveInterval::SubRange &S : VirtReg.subranges()) { -if (S.liveAt(Use)) - LiveAtMask |= S.LaneMask; + for (auto [MI, OpIdx] : Ops) { +const MachineOperand &MO = MI->getOperand(OpIdx); +assert(MO.isReg() && MO.getReg() == Reg); +unsigned SubReg = MO.getSubReg(); +if (SubReg == 0 && MO.isUse()) { + if (MO.isUndef()) +continue; + return false; qcolombet wrote: Ah that makes sense. Thanks for updating the comment of the function. https://github.com/llvm/llvm-project/pull/120199 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RegAllocGreedy: Fix subrange based instruction split logic (PR #120199)
https://github.com/qcolombet approved this pull request. https://github.com/llvm/llvm-project/pull/120199 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)
https://github.com/TIFitis created https://github.com/llvm/llvm-project/pull/120994 This patch adds the mapper field to the omp.map.info op. >From 21178b07176869e000f7e027bc5c9593b715b5ad Mon Sep 17 00:00:00 2001 From: Akash Banerjee Date: Mon, 23 Dec 2024 19:05:30 + Subject: [PATCH] Add mapper field to mapInfoOp. --- mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 2 ++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 2 +- mlir/test/Dialect/OpenMP/ops.mlir | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 881f28d42e6312..7cc2c8fa8ce1e1 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -1000,6 +1000,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { OptionalAttr:$members_index, Variadic:$bounds, /* rank-0 to rank-{n-1} */ OptionalAttr:$map_type, + OptionalAttr:$mapper_id, OptionalAttr:$map_capture_type, OptionalAttr:$name, DefaultValuedAttr:$partial_map); @@ -1064,6 +1065,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { `var_ptr` `(` $var_ptr `:` type($var_ptr) `,` $var_type `)` oilist( `var_ptr_ptr` `(` $var_ptr_ptr `:` type($var_ptr_ptr) `)` + | `mapper` `(` $mapper_id `)` | `map_clauses` `(` custom($map_type) `)` | `capture` `(` custom($map_capture_type) `)` | `members` `(` $members `:` custom($members_index) `:` type($members) `)` diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index b15d6ed15244ed..92233654ba1ddc 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -1592,7 +1592,7 @@ static LogicalResult verifyMapClause(Operation *op, OperandRange mapVars) { to ? updateToVars.insert(updateVar) : updateFromVars.insert(updateVar); } -} else { +} else if (!isa(op)) { emitError(op->getLoc(), "map argument is not a map entry operation"); } } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index a167c8bd1abbf9..97ef132f6dfa53 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -2523,13 +2523,13 @@ func.func @omp_targets_with_map_bounds(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> () // CHECK: %[[C_12:.*]] = llvm.mlir.constant(2 : index) : i64 // CHECK: %[[C_13:.*]] = llvm.mlir.constant(2 : index) : i64 // CHECK: %[[BOUNDS1:.*]] = omp.map.bounds lower_bound(%[[C_11]] : i64) upper_bound(%[[C_10]] : i64) stride(%[[C_12]] : i64) start_idx(%[[C_13]] : i64) - // CHECK: %[[MAP1:.*]] = omp.map.info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""} + // CHECK: %[[MAP1:.*]] = omp.map.info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.array<10 x i32>) mapper(@my_mapper) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""} %6 = llvm.mlir.constant(9 : index) : i64 %7 = llvm.mlir.constant(1 : index) : i64 %8 = llvm.mlir.constant(2 : index) : i64 %9 = llvm.mlir.constant(2 : index) : i64 %10 = omp.map.bounds lower_bound(%7 : i64) upper_bound(%6 : i64) stride(%8 : i64) start_idx(%9 : i64) -%mapv2 = omp.map.info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""} +%mapv2 = omp.map.info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) mapper(@my_mapper) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""} // CHECK: omp.target map_entries(%[[MAP0]] -> {{.*}}, %[[MAP1]] -> {{.*}} : !llvm.ptr, !llvm.ptr) omp.target map_entries(%mapv1 -> %arg2, %mapv2 -> %arg3 : !llvm.ptr, !llvm.ptr) { ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)
llvmbot wrote: @llvm/pr-subscribers-flang-openmp Author: Akash Banerjee (TIFitis) Changes This patch adds the mapper field to the omp.map.info op. --- Full diff: https://github.com/llvm/llvm-project/pull/120994.diff 3 Files Affected: - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+2) - (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+1-1) - (modified) mlir/test/Dialect/OpenMP/ops.mlir (+2-2) ``diff diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 881f28d42e6312..7cc2c8fa8ce1e1 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -1000,6 +1000,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { OptionalAttr:$members_index, Variadic:$bounds, /* rank-0 to rank-{n-1} */ OptionalAttr:$map_type, + OptionalAttr:$mapper_id, OptionalAttr:$map_capture_type, OptionalAttr:$name, DefaultValuedAttr:$partial_map); @@ -1064,6 +1065,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { `var_ptr` `(` $var_ptr `:` type($var_ptr) `,` $var_type `)` oilist( `var_ptr_ptr` `(` $var_ptr_ptr `:` type($var_ptr_ptr) `)` + | `mapper` `(` $mapper_id `)` | `map_clauses` `(` custom($map_type) `)` | `capture` `(` custom($map_capture_type) `)` | `members` `(` $members `:` custom($members_index) `:` type($members) `)` diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index b15d6ed15244ed..92233654ba1ddc 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -1592,7 +1592,7 @@ static LogicalResult verifyMapClause(Operation *op, OperandRange mapVars) { to ? updateToVars.insert(updateVar) : updateFromVars.insert(updateVar); } -} else { +} else if (!isa(op)) { emitError(op->getLoc(), "map argument is not a map entry operation"); } } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index a167c8bd1abbf9..97ef132f6dfa53 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -2523,13 +2523,13 @@ func.func @omp_targets_with_map_bounds(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> () // CHECK: %[[C_12:.*]] = llvm.mlir.constant(2 : index) : i64 // CHECK: %[[C_13:.*]] = llvm.mlir.constant(2 : index) : i64 // CHECK: %[[BOUNDS1:.*]] = omp.map.bounds lower_bound(%[[C_11]] : i64) upper_bound(%[[C_10]] : i64) stride(%[[C_12]] : i64) start_idx(%[[C_13]] : i64) - // CHECK: %[[MAP1:.*]] = omp.map.info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""} + // CHECK: %[[MAP1:.*]] = omp.map.info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.array<10 x i32>) mapper(@my_mapper) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""} %6 = llvm.mlir.constant(9 : index) : i64 %7 = llvm.mlir.constant(1 : index) : i64 %8 = llvm.mlir.constant(2 : index) : i64 %9 = llvm.mlir.constant(2 : index) : i64 %10 = omp.map.bounds lower_bound(%7 : i64) upper_bound(%6 : i64) stride(%8 : i64) start_idx(%9 : i64) -%mapv2 = omp.map.info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""} +%mapv2 = omp.map.info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) mapper(@my_mapper) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""} // CHECK: omp.target map_entries(%[[MAP0]] -> {{.*}}, %[[MAP1]] -> {{.*}} : !llvm.ptr, !llvm.ptr) omp.target map_entries(%mapv1 -> %arg2, %mapv2 -> %arg3 : !llvm.ptr, !llvm.ptr) { `` https://github.com/llvm/llvm-project/pull/120994 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)
llvmbot wrote: @llvm/pr-subscribers-mlir-openmp Author: Akash Banerjee (TIFitis) Changes This patch adds the mapper field to the omp.map.info op. --- Full diff: https://github.com/llvm/llvm-project/pull/120994.diff 3 Files Affected: - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+2) - (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+1-1) - (modified) mlir/test/Dialect/OpenMP/ops.mlir (+2-2) ``diff diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 881f28d42e6312..7cc2c8fa8ce1e1 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -1000,6 +1000,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { OptionalAttr:$members_index, Variadic:$bounds, /* rank-0 to rank-{n-1} */ OptionalAttr:$map_type, + OptionalAttr:$mapper_id, OptionalAttr:$map_capture_type, OptionalAttr:$name, DefaultValuedAttr:$partial_map); @@ -1064,6 +1065,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { `var_ptr` `(` $var_ptr `:` type($var_ptr) `,` $var_type `)` oilist( `var_ptr_ptr` `(` $var_ptr_ptr `:` type($var_ptr_ptr) `)` + | `mapper` `(` $mapper_id `)` | `map_clauses` `(` custom($map_type) `)` | `capture` `(` custom($map_capture_type) `)` | `members` `(` $members `:` custom($members_index) `:` type($members) `)` diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index b15d6ed15244ed..92233654ba1ddc 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -1592,7 +1592,7 @@ static LogicalResult verifyMapClause(Operation *op, OperandRange mapVars) { to ? updateToVars.insert(updateVar) : updateFromVars.insert(updateVar); } -} else { +} else if (!isa(op)) { emitError(op->getLoc(), "map argument is not a map entry operation"); } } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index a167c8bd1abbf9..97ef132f6dfa53 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -2523,13 +2523,13 @@ func.func @omp_targets_with_map_bounds(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> () // CHECK: %[[C_12:.*]] = llvm.mlir.constant(2 : index) : i64 // CHECK: %[[C_13:.*]] = llvm.mlir.constant(2 : index) : i64 // CHECK: %[[BOUNDS1:.*]] = omp.map.bounds lower_bound(%[[C_11]] : i64) upper_bound(%[[C_10]] : i64) stride(%[[C_12]] : i64) start_idx(%[[C_13]] : i64) - // CHECK: %[[MAP1:.*]] = omp.map.info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""} + // CHECK: %[[MAP1:.*]] = omp.map.info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.array<10 x i32>) mapper(@my_mapper) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""} %6 = llvm.mlir.constant(9 : index) : i64 %7 = llvm.mlir.constant(1 : index) : i64 %8 = llvm.mlir.constant(2 : index) : i64 %9 = llvm.mlir.constant(2 : index) : i64 %10 = omp.map.bounds lower_bound(%7 : i64) upper_bound(%6 : i64) stride(%8 : i64) start_idx(%9 : i64) -%mapv2 = omp.map.info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""} +%mapv2 = omp.map.info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) mapper(@my_mapper) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""} // CHECK: omp.target map_entries(%[[MAP0]] -> {{.*}}, %[[MAP1]] -> {{.*}} : !llvm.ptr, !llvm.ptr) omp.target map_entries(%mapv1 -> %arg2, %mapv2 -> %arg3 : !llvm.ptr, !llvm.ptr) { `` https://github.com/llvm/llvm-project/pull/120994 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)
llvmbot wrote: @llvm/pr-subscribers-mlir Author: Akash Banerjee (TIFitis) Changes This patch adds the mapper field to the omp.map.info op. --- Full diff: https://github.com/llvm/llvm-project/pull/120994.diff 3 Files Affected: - (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+2) - (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+1-1) - (modified) mlir/test/Dialect/OpenMP/ops.mlir (+2-2) ``diff diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 881f28d42e6312..7cc2c8fa8ce1e1 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -1000,6 +1000,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { OptionalAttr:$members_index, Variadic:$bounds, /* rank-0 to rank-{n-1} */ OptionalAttr:$map_type, + OptionalAttr:$mapper_id, OptionalAttr:$map_capture_type, OptionalAttr:$name, DefaultValuedAttr:$partial_map); @@ -1064,6 +1065,7 @@ def MapInfoOp : OpenMP_Op<"map.info", [AttrSizedOperandSegments]> { `var_ptr` `(` $var_ptr `:` type($var_ptr) `,` $var_type `)` oilist( `var_ptr_ptr` `(` $var_ptr_ptr `:` type($var_ptr_ptr) `)` + | `mapper` `(` $mapper_id `)` | `map_clauses` `(` custom($map_type) `)` | `capture` `(` custom($map_capture_type) `)` | `members` `(` $members `:` custom($members_index) `:` type($members) `)` diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index b15d6ed15244ed..92233654ba1ddc 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -1592,7 +1592,7 @@ static LogicalResult verifyMapClause(Operation *op, OperandRange mapVars) { to ? updateToVars.insert(updateVar) : updateFromVars.insert(updateVar); } -} else { +} else if (!isa(op)) { emitError(op->getLoc(), "map argument is not a map entry operation"); } } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index a167c8bd1abbf9..97ef132f6dfa53 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -2523,13 +2523,13 @@ func.func @omp_targets_with_map_bounds(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> () // CHECK: %[[C_12:.*]] = llvm.mlir.constant(2 : index) : i64 // CHECK: %[[C_13:.*]] = llvm.mlir.constant(2 : index) : i64 // CHECK: %[[BOUNDS1:.*]] = omp.map.bounds lower_bound(%[[C_11]] : i64) upper_bound(%[[C_10]] : i64) stride(%[[C_12]] : i64) start_idx(%[[C_13]] : i64) - // CHECK: %[[MAP1:.*]] = omp.map.info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""} + // CHECK: %[[MAP1:.*]] = omp.map.info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.array<10 x i32>) mapper(@my_mapper) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""} %6 = llvm.mlir.constant(9 : index) : i64 %7 = llvm.mlir.constant(1 : index) : i64 %8 = llvm.mlir.constant(2 : index) : i64 %9 = llvm.mlir.constant(2 : index) : i64 %10 = omp.map.bounds lower_bound(%7 : i64) upper_bound(%6 : i64) stride(%8 : i64) start_idx(%9 : i64) -%mapv2 = omp.map.info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""} +%mapv2 = omp.map.info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) mapper(@my_mapper) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""} // CHECK: omp.target map_entries(%[[MAP0]] -> {{.*}}, %[[MAP1]] -> {{.*}} : !llvm.ptr, !llvm.ptr) omp.target map_entries(%mapv1 -> %arg2, %mapv2 -> %arg3 : !llvm.ptr, !llvm.ptr) { `` https://github.com/llvm/llvm-project/pull/120994 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)
https://github.com/TIFitis updated https://github.com/llvm/llvm-project/pull/120994 >From 0b54cafc829119b931d04d1d9ec3e790e50f7b08 Mon Sep 17 00:00:00 2001 From: Akash Banerjee Date: Mon, 23 Dec 2024 19:05:30 + Subject: [PATCH] Add mapper field to mapInfoOp. --- flang/lib/Lower/OpenMP/Utils.cpp | 3 ++- flang/lib/Lower/OpenMP/Utils.h| 3 ++- .../lib/Optimizer/OpenMP/MapInfoFinalization.cpp | 5 - .../Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp | 1 + flang/test/Lower/OpenMP/map-mapper.f90| 15 +++ mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 2 ++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 2 +- mlir/test/Dialect/OpenMP/ops.mlir | 4 ++-- 8 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 flang/test/Lower/OpenMP/map-mapper.f90 diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index 9971dc8e0b0014..af3a3df825fb88 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -125,7 +125,7 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, llvm::ArrayRef members, mlir::ArrayAttr membersIndex, uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy, -bool partialMap) { +bool partialMap, mlir::FlatSymbolRefAttr mapperId) { if (auto boxTy = llvm::dyn_cast(baseAddr.getType())) { baseAddr = builder.create(loc, baseAddr); retTy = baseAddr.getType(); @@ -144,6 +144,7 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, mlir::omp::MapInfoOp op = builder.create( loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds, builder.getIntegerAttr(builder.getIntegerType(64, false), mapType), + mapperId, builder.getAttr(mapCaptureType), builder.getStringAttr(name), builder.getBoolAttr(partialMap)); return op; diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h index f2e378443e5f29..3943eb633b04e3 100644 --- a/flang/lib/Lower/OpenMP/Utils.h +++ b/flang/lib/Lower/OpenMP/Utils.h @@ -116,7 +116,8 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, llvm::ArrayRef members, mlir::ArrayAttr membersIndex, uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy, -bool partialMap = false); +bool partialMap = false, +mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr()); void insertChildMapInfoIntoParent( Fortran::lower::AbstractConverter &converter, diff --git a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp b/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp index b08ccf3b88eb46..247ea6383cacda 100644 --- a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp +++ b/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp @@ -171,6 +171,7 @@ class MapInfoFinalizationPass baseAddrAddr, /*members=*/mlir::SmallVector{}, /*membersIndex=*/mlir::ArrayAttr{}, bounds, builder.getIntegerAttr(builder.getIntegerType(64, false), mapType), +/*mapperId*/ mlir::FlatSymbolRefAttr(), builder.getAttr( mlir::omp::VariableCaptureKind::ByRef), /*name=*/builder.getStringAttr(""), @@ -316,7 +317,8 @@ class MapInfoFinalizationPass builder.getIntegerAttr( builder.getIntegerType(64, false), getDescriptorMapType(op.getMapType().value_or(0), target)), -op.getMapCaptureTypeAttr(), op.getNameAttr(), +/*mapperId*/ mlir::FlatSymbolRefAttr(), op.getMapCaptureTypeAttr(), +op.getNameAttr(), /*partial_map=*/builder.getBoolAttr(false)); op.replaceAllUsesWith(newDescParentMapOp.getResult()); op->erase(); @@ -611,6 +613,7 @@ class MapInfoFinalizationPass /*members=*/mlir::ValueRange{}, /*members_index=*/mlir::ArrayAttr{}, /*bounds=*/bounds, op.getMapTypeAttr(), + /*mapperId*/ mlir::FlatSymbolRefAttr(), builder.getAttr( mlir::omp::VariableCaptureKind::ByRef), builder.getStringAttr(op.getNameAttr().strref() + "." + diff --git a/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp b/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp index c990bebcabde42..9f3b4dcdd898f4 100644 --- a/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp +++ b/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp @@ -89,6 +89,7 @@ class MapsForPrivatizedSymbolsPass /*bounds=*/ValueRange{}, builder.getIntegerAttr(builder.getIntegerType(64, /*isSigned=*/false), mapTypeTo), +/*mapperId*/ mlir::FlatSymbolRefAttr(), builder.getAttr( omp
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)
https://github.com/TIFitis updated https://github.com/llvm/llvm-project/pull/120994 >From 002d7153f4029c02722b6a4f45bbde8fad83ba95 Mon Sep 17 00:00:00 2001 From: Akash Banerjee Date: Mon, 23 Dec 2024 20:53:47 + Subject: [PATCH] Add mapper field to mapInfoOp. --- flang/lib/Lower/OpenMP/Utils.cpp| 3 ++- flang/lib/Lower/OpenMP/Utils.h | 3 ++- flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp | 5 - flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp | 1 + mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 2 ++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp| 2 +- mlir/test/Dialect/OpenMP/ops.mlir | 4 ++-- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index 9971dc8e0b0014..af3a3df825fb88 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -125,7 +125,7 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, llvm::ArrayRef members, mlir::ArrayAttr membersIndex, uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy, -bool partialMap) { +bool partialMap, mlir::FlatSymbolRefAttr mapperId) { if (auto boxTy = llvm::dyn_cast(baseAddr.getType())) { baseAddr = builder.create(loc, baseAddr); retTy = baseAddr.getType(); @@ -144,6 +144,7 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, mlir::omp::MapInfoOp op = builder.create( loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds, builder.getIntegerAttr(builder.getIntegerType(64, false), mapType), + mapperId, builder.getAttr(mapCaptureType), builder.getStringAttr(name), builder.getBoolAttr(partialMap)); return op; diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h index f2e378443e5f29..3943eb633b04e3 100644 --- a/flang/lib/Lower/OpenMP/Utils.h +++ b/flang/lib/Lower/OpenMP/Utils.h @@ -116,7 +116,8 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, llvm::ArrayRef members, mlir::ArrayAttr membersIndex, uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy, -bool partialMap = false); +bool partialMap = false, +mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr()); void insertChildMapInfoIntoParent( Fortran::lower::AbstractConverter &converter, diff --git a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp b/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp index b08ccf3b88eb46..247ea6383cacda 100644 --- a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp +++ b/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp @@ -171,6 +171,7 @@ class MapInfoFinalizationPass baseAddrAddr, /*members=*/mlir::SmallVector{}, /*membersIndex=*/mlir::ArrayAttr{}, bounds, builder.getIntegerAttr(builder.getIntegerType(64, false), mapType), +/*mapperId*/ mlir::FlatSymbolRefAttr(), builder.getAttr( mlir::omp::VariableCaptureKind::ByRef), /*name=*/builder.getStringAttr(""), @@ -316,7 +317,8 @@ class MapInfoFinalizationPass builder.getIntegerAttr( builder.getIntegerType(64, false), getDescriptorMapType(op.getMapType().value_or(0), target)), -op.getMapCaptureTypeAttr(), op.getNameAttr(), +/*mapperId*/ mlir::FlatSymbolRefAttr(), op.getMapCaptureTypeAttr(), +op.getNameAttr(), /*partial_map=*/builder.getBoolAttr(false)); op.replaceAllUsesWith(newDescParentMapOp.getResult()); op->erase(); @@ -611,6 +613,7 @@ class MapInfoFinalizationPass /*members=*/mlir::ValueRange{}, /*members_index=*/mlir::ArrayAttr{}, /*bounds=*/bounds, op.getMapTypeAttr(), + /*mapperId*/ mlir::FlatSymbolRefAttr(), builder.getAttr( mlir::omp::VariableCaptureKind::ByRef), builder.getStringAttr(op.getNameAttr().strref() + "." + diff --git a/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp b/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp index c990bebcabde42..9f3b4dcdd898f4 100644 --- a/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp +++ b/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp @@ -89,6 +89,7 @@ class MapsForPrivatizedSymbolsPass /*bounds=*/ValueRange{}, builder.getIntegerAttr(builder.getIntegerType(64, /*isSigned=*/false), mapTypeTo), +/*mapperId*/ mlir::FlatSymbolRefAttr(), builder.getAttr( omp::VariableCaptureKind::ByRef), StringAttr(), builder.getBoolAttr(false)); diff --git a/
[llvm-branch-commits] [clang] [llvm] [Coverage] Make additional counters available for BranchRegion. NFC. (PR #120930)
https://github.com/Fznamznon edited https://github.com/llvm/llvm-project/pull/120930 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [MLIR][OpenMP] Add Lowering support for OpenMP custom mappers in map clause (PR #121001)
https://github.com/TIFitis created https://github.com/llvm/llvm-project/pull/121001 Add Lowering support for OpenMP mapper field in mapInfoOp. Depends on #120994. >From 30611f81421028ccc8fceed006e06f8afc6848b9 Mon Sep 17 00:00:00 2001 From: Akash Banerjee Date: Mon, 23 Dec 2024 19:05:30 + Subject: [PATCH 1/2] Add mapper field to mapInfoOp. --- flang/test/Lower/OpenMP/map-mapper.f90 | 15 +++ 1 file changed, 15 insertions(+) create mode 100644 flang/test/Lower/OpenMP/map-mapper.f90 diff --git a/flang/test/Lower/OpenMP/map-mapper.f90 b/flang/test/Lower/OpenMP/map-mapper.f90 new file mode 100644 index 00..e7fded3034406e --- /dev/null +++ b/flang/test/Lower/OpenMP/map-mapper.f90 @@ -0,0 +1,15 @@ +! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s +program p + integer, parameter :: n = 256 + real(8) :: a(256) + type t1 + integer :: x + end type t1 + !$omp declare mapper(xx : t1 :: nn) map(nn, nn%x) + !$omp target map(mapper(xx), from:a) +!CHECK: not yet implemented: Support for mapper modifiers is not implemented yet + do i = 1, n + a(i) = 4.2 + end do + !$omp end target +end program p >From ea048f78cdec2ea749562f17ae6d3614c2ef1f46 Mon Sep 17 00:00:00 2001 From: Akash Banerjee Date: Mon, 23 Dec 2024 21:13:42 + Subject: [PATCH 2/2] Add flang lowering changes for mapper field in map clause. --- flang/lib/Lower/OpenMP/ClauseProcessor.cpp | 32 + flang/lib/Lower/OpenMP/ClauseProcessor.h| 3 +- flang/test/Lower/OpenMP/Todo/map-mapper.f90 | 16 --- flang/test/Lower/OpenMP/map-mapper.f90 | 20 + 4 files changed, 43 insertions(+), 28 deletions(-) delete mode 100644 flang/test/Lower/OpenMP/Todo/map-mapper.f90 diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 3c9831120351ee..0bc9f4919330e4 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -936,8 +936,10 @@ void ClauseProcessor::processMapObjects( llvm::omp::OpenMPOffloadMappingFlags mapTypeBits, std::map &parentMemberIndices, llvm::SmallVectorImpl &mapVars, -llvm::SmallVectorImpl &mapSyms) const { +llvm::SmallVectorImpl &mapSyms, +std::string mapperIdName) const { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); + mlir::FlatSymbolRefAttr mapperId; for (const omp::Object &object : objects) { llvm::SmallVector bounds; @@ -970,6 +972,20 @@ void ClauseProcessor::processMapObjects( } } +if (!mapperIdName.empty()) { + if (mapperIdName == "default") { +auto &typeSpec = object.sym()->owner().IsDerivedType() + ? *object.sym()->owner().derivedTypeSpec() + : object.sym()->GetType()->derivedTypeSpec(); +mapperIdName = typeSpec.name().ToString() + ".default"; +mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope()); + } + assert(converter.getMLIRSymbolTable()->lookup(mapperIdName) && + "mapper not found"); + mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(), + mapperIdName); + mapperIdName.clear(); +} // Explicit map captures are captured ByRef by default, // optimisation passes may alter this to ByCopy or other capture // types to optimise @@ -983,7 +999,8 @@ void ClauseProcessor::processMapObjects( static_cast< std::underlying_type_t>( mapTypeBits), -mlir::omp::VariableCaptureKind::ByRef, baseOp.getType()); +mlir::omp::VariableCaptureKind::ByRef, baseOp.getType(), false, +mapperId); if (parentObj.has_value()) { parentMemberIndices[parentObj.value()].addChildIndexAndMapToParent( @@ -1014,6 +1031,7 @@ bool ClauseProcessor::processMap( const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t; llvm::omp::OpenMPOffloadMappingFlags mapTypeBits = llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE; +std::string mapperIdName; // If the map type is specified, then process it else Tofrom is the // default. Map::MapType type = mapType.value_or(Map::MapType::Tofrom); @@ -1057,13 +1075,17 @@ bool ClauseProcessor::processMap( "Support for iterator modifiers is not implemented yet"); } if (mappers) { - TODO(currentLocation, - "Support for mapper modifiers is not implemented yet"); + assert(mappers->size() == 1 && "more than one mapper"); + mapperIdName = mappers->front().v.id().symbol->name().ToString(); + if (mapperIdName != "default") +mapperIdName = converter.mangleName( +mapperIdName, mappers->front().v.id().symbol->owner()); } processMapObjects(stmtCtx, clauseLocation, std::get(clause.t), mapTypeBits, -
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (PR #120994)
https://github.com/TIFitis edited https://github.com/llvm/llvm-project/pull/120994 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [MLIR][OpenMP] Add Lowering support for OpenMP custom mappers in map clause (PR #121001)
llvmbot wrote: @llvm/pr-subscribers-flang-fir-hlfir Author: Akash Banerjee (TIFitis) Changes Add Lowering support for OpenMP mapper field in mapInfoOp. Depends on #120994. --- Full diff: https://github.com/llvm/llvm-project/pull/121001.diff 4 Files Affected: - (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+27-5) - (modified) flang/lib/Lower/OpenMP/ClauseProcessor.h (+2-1) - (removed) flang/test/Lower/OpenMP/Todo/map-mapper.f90 (-16) - (added) flang/test/Lower/OpenMP/map-mapper.f90 (+23) ``diff diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 3c9831120351ee..0bc9f4919330e4 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -936,8 +936,10 @@ void ClauseProcessor::processMapObjects( llvm::omp::OpenMPOffloadMappingFlags mapTypeBits, std::map &parentMemberIndices, llvm::SmallVectorImpl &mapVars, -llvm::SmallVectorImpl &mapSyms) const { +llvm::SmallVectorImpl &mapSyms, +std::string mapperIdName) const { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); + mlir::FlatSymbolRefAttr mapperId; for (const omp::Object &object : objects) { llvm::SmallVector bounds; @@ -970,6 +972,20 @@ void ClauseProcessor::processMapObjects( } } +if (!mapperIdName.empty()) { + if (mapperIdName == "default") { +auto &typeSpec = object.sym()->owner().IsDerivedType() + ? *object.sym()->owner().derivedTypeSpec() + : object.sym()->GetType()->derivedTypeSpec(); +mapperIdName = typeSpec.name().ToString() + ".default"; +mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope()); + } + assert(converter.getMLIRSymbolTable()->lookup(mapperIdName) && + "mapper not found"); + mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(), + mapperIdName); + mapperIdName.clear(); +} // Explicit map captures are captured ByRef by default, // optimisation passes may alter this to ByCopy or other capture // types to optimise @@ -983,7 +999,8 @@ void ClauseProcessor::processMapObjects( static_cast< std::underlying_type_t>( mapTypeBits), -mlir::omp::VariableCaptureKind::ByRef, baseOp.getType()); +mlir::omp::VariableCaptureKind::ByRef, baseOp.getType(), false, +mapperId); if (parentObj.has_value()) { parentMemberIndices[parentObj.value()].addChildIndexAndMapToParent( @@ -1014,6 +1031,7 @@ bool ClauseProcessor::processMap( const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t; llvm::omp::OpenMPOffloadMappingFlags mapTypeBits = llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE; +std::string mapperIdName; // If the map type is specified, then process it else Tofrom is the // default. Map::MapType type = mapType.value_or(Map::MapType::Tofrom); @@ -1057,13 +1075,17 @@ bool ClauseProcessor::processMap( "Support for iterator modifiers is not implemented yet"); } if (mappers) { - TODO(currentLocation, - "Support for mapper modifiers is not implemented yet"); + assert(mappers->size() == 1 && "more than one mapper"); + mapperIdName = mappers->front().v.id().symbol->name().ToString(); + if (mapperIdName != "default") +mapperIdName = converter.mangleName( +mapperIdName, mappers->front().v.id().symbol->owner()); } processMapObjects(stmtCtx, clauseLocation, std::get(clause.t), mapTypeBits, - parentMemberIndices, result.mapVars, *ptrMapSyms); + parentMemberIndices, result.mapVars, *ptrMapSyms, + mapperIdName); }; bool clauseFound = findRepeatableClause(process); diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h index 7b047d4a7567ad..34eebf16ca17b0 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.h +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h @@ -171,7 +171,8 @@ class ClauseProcessor { llvm::omp::OpenMPOffloadMappingFlags mapTypeBits, std::map &parentMemberIndices, llvm::SmallVectorImpl &mapVars, - llvm::SmallVectorImpl &mapSyms) const; + llvm::SmallVectorImpl &mapSyms, + std::string mapperIdName = "") const; lower::AbstractConverter &converter; semantics::SemanticsContext &semaCtx; diff --git a/flang/test/Lower/OpenMP/Todo/map-mapper.f90 b/flang/test/Lower/OpenMP/Todo/map-mapper.f90 deleted file mode 100644 index 9554ffd5fda7bd..00 --- a/flang/test/Lower/OpenMP/Todo/map-mapper.f90 +++ /dev/null @@ -1,16 +0,0 @@ -! RUN: not %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 %s 2>&1 | FileCheck %s -program p - integer, parameter :: n = 256 - rea
[llvm-branch-commits] [flang] [MLIR][OpenMP] Add Lowering support for OpenMP custom mappers in map clause (PR #121001)
llvmbot wrote: @llvm/pr-subscribers-flang-openmp Author: Akash Banerjee (TIFitis) Changes Add Lowering support for OpenMP mapper field in mapInfoOp. Depends on #120994. --- Full diff: https://github.com/llvm/llvm-project/pull/121001.diff 4 Files Affected: - (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+27-5) - (modified) flang/lib/Lower/OpenMP/ClauseProcessor.h (+2-1) - (removed) flang/test/Lower/OpenMP/Todo/map-mapper.f90 (-16) - (added) flang/test/Lower/OpenMP/map-mapper.f90 (+23) ``diff diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 3c9831120351ee..0bc9f4919330e4 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -936,8 +936,10 @@ void ClauseProcessor::processMapObjects( llvm::omp::OpenMPOffloadMappingFlags mapTypeBits, std::map &parentMemberIndices, llvm::SmallVectorImpl &mapVars, -llvm::SmallVectorImpl &mapSyms) const { +llvm::SmallVectorImpl &mapSyms, +std::string mapperIdName) const { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); + mlir::FlatSymbolRefAttr mapperId; for (const omp::Object &object : objects) { llvm::SmallVector bounds; @@ -970,6 +972,20 @@ void ClauseProcessor::processMapObjects( } } +if (!mapperIdName.empty()) { + if (mapperIdName == "default") { +auto &typeSpec = object.sym()->owner().IsDerivedType() + ? *object.sym()->owner().derivedTypeSpec() + : object.sym()->GetType()->derivedTypeSpec(); +mapperIdName = typeSpec.name().ToString() + ".default"; +mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope()); + } + assert(converter.getMLIRSymbolTable()->lookup(mapperIdName) && + "mapper not found"); + mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(), + mapperIdName); + mapperIdName.clear(); +} // Explicit map captures are captured ByRef by default, // optimisation passes may alter this to ByCopy or other capture // types to optimise @@ -983,7 +999,8 @@ void ClauseProcessor::processMapObjects( static_cast< std::underlying_type_t>( mapTypeBits), -mlir::omp::VariableCaptureKind::ByRef, baseOp.getType()); +mlir::omp::VariableCaptureKind::ByRef, baseOp.getType(), false, +mapperId); if (parentObj.has_value()) { parentMemberIndices[parentObj.value()].addChildIndexAndMapToParent( @@ -1014,6 +1031,7 @@ bool ClauseProcessor::processMap( const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t; llvm::omp::OpenMPOffloadMappingFlags mapTypeBits = llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE; +std::string mapperIdName; // If the map type is specified, then process it else Tofrom is the // default. Map::MapType type = mapType.value_or(Map::MapType::Tofrom); @@ -1057,13 +1075,17 @@ bool ClauseProcessor::processMap( "Support for iterator modifiers is not implemented yet"); } if (mappers) { - TODO(currentLocation, - "Support for mapper modifiers is not implemented yet"); + assert(mappers->size() == 1 && "more than one mapper"); + mapperIdName = mappers->front().v.id().symbol->name().ToString(); + if (mapperIdName != "default") +mapperIdName = converter.mangleName( +mapperIdName, mappers->front().v.id().symbol->owner()); } processMapObjects(stmtCtx, clauseLocation, std::get(clause.t), mapTypeBits, - parentMemberIndices, result.mapVars, *ptrMapSyms); + parentMemberIndices, result.mapVars, *ptrMapSyms, + mapperIdName); }; bool clauseFound = findRepeatableClause(process); diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h index 7b047d4a7567ad..34eebf16ca17b0 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.h +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h @@ -171,7 +171,8 @@ class ClauseProcessor { llvm::omp::OpenMPOffloadMappingFlags mapTypeBits, std::map &parentMemberIndices, llvm::SmallVectorImpl &mapVars, - llvm::SmallVectorImpl &mapSyms) const; + llvm::SmallVectorImpl &mapSyms, + std::string mapperIdName = "") const; lower::AbstractConverter &converter; semantics::SemanticsContext &semaCtx; diff --git a/flang/test/Lower/OpenMP/Todo/map-mapper.f90 b/flang/test/Lower/OpenMP/Todo/map-mapper.f90 deleted file mode 100644 index 9554ffd5fda7bd..00 --- a/flang/test/Lower/OpenMP/Todo/map-mapper.f90 +++ /dev/null @@ -1,16 +0,0 @@ -! RUN: not %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 %s 2>&1 | FileCheck %s -program p - integer, parameter :: n = 256 - real(8
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper (PR #121005)
https://github.com/TIFitis created https://github.com/llvm/llvm-project/pull/121005 Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper. >From 8a90d208ace9b8fe34f427f6268968e8b4b08976 Mon Sep 17 00:00:00 2001 From: Akash Banerjee Date: Mon, 23 Dec 2024 21:50:03 + Subject: [PATCH] Add OpenMP to LLVM dialect conversion support for DeclareMapperOp. --- .../Fir/convert-to-llvm-openmp-and-fir.fir| 27 -- .../Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp | 50 +++ .../OpenMPToLLVM/convert-to-llvmir.mlir | 13 + 3 files changed, 75 insertions(+), 15 deletions(-) diff --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir index 8e4e1fe824d9f5..82f2aea3ad983c 100644 --- a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir +++ b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir @@ -936,9 +936,9 @@ func.func @omp_map_info_descriptor_type_conversion(%arg0 : !fir.ref>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.llvm_ptr> {name = ""} // CHECK: %[[DESC_MAP:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(always, delete) capture(ByRef) members(%[[MEMBER_MAP]] : [0] : !llvm.ptr) -> !llvm.ptr {name = ""} %2 = omp.map.info var_ptr(%arg0 : !fir.ref>>, !fir.box>) map_clauses(always, delete) capture(ByRef) members(%1 : [0] : !fir.llvm_ptr>) -> !fir.ref>> {name = ""} - // CHECK: omp.target_exit_data map_entries(%[[DESC_MAP]] : !llvm.ptr) + // CHECK: omp.target_exit_data map_entries(%[[DESC_MAP]] : !llvm.ptr) omp.target_exit_data map_entries(%2 : !fir.ref>>) - return + return } // - @@ -956,8 +956,8 @@ func.func @omp_map_info_derived_type_explicit_member_conversion(%arg0 : !fir.ref %3 = fir.field_index real, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}> %4 = fir.coordinate_of %arg0, %3 : (!fir.ref,int:i32}>>, !fir.field) -> !fir.ref // CHECK: %[[MAP_MEMBER_2:.*]] = omp.map.info var_ptr(%[[GEP_2]] : !llvm.ptr, f32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "dtype%real"} - %5 = omp.map.info var_ptr(%4 : !fir.ref, f32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "dtype%real"} - // CHECK: %[[MAP_PARENT:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP_MEMBER_1]], %[[MAP_MEMBER_2]] : [2], [0] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "dtype", partial_map = true} + %5 = omp.map.info var_ptr(%4 : !fir.ref, f32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "dtype%real"} + // CHECK: %[[MAP_PARENT:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP_MEMBER_1]], %[[MAP_MEMBER_2]] : [2], [0] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "dtype", partial_map = true} %6 = omp.map.info var_ptr(%arg0 : !fir.ref,int:i32}>>, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>) map_clauses(tofrom) capture(ByRef) members(%2, %5 : [2], [0] : !fir.ref, !fir.ref) -> !fir.ref,int:i32}>> {name = "dtype", partial_map = true} // CHECK: omp.target map_entries(%[[MAP_MEMBER_1]] -> %[[ARG_1:.*]], %[[MAP_MEMBER_2]] -> %[[ARG_2:.*]], %[[MAP_PARENT]] -> %[[ARG_3:.*]] : !llvm.ptr, !llvm.ptr, !llvm.ptr) { omp.target map_entries(%2 -> %arg1, %5 -> %arg2, %6 -> %arg3 : !fir.ref, !fir.ref, !fir.ref,int:i32}>>) { @@ -1275,3 +1275,22 @@ func.func @map_nested_dtype_alloca_mem2(%arg0 : !fir.ref { +omp.declare_mapper @my_mapper : !fir.type<_QFdeclare_mapperTmy_type{data:i32}> { +// CHECK: ^bb0(%[[VAL_0:.*]]: !llvm.ptr): +^bb0(%0: !fir.ref>): +// CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(0 : i32) : i32 + %1 = fir.field_index data, !fir.type<_QFdeclare_mapperTmy_type{data:i32}> +// CHECK: %[[VAL_2:.*]] = llvm.getelementptr %[[VAL_0]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFdeclare_mapperTmy_type", (i32)> + %2 = fir.coordinate_of %0, %1 : (!fir.ref>, !fir.field) -> !fir.ref +// CHECK: %[[VAL_3:.*]] = omp.map.info var_ptr(%[[VAL_2]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "var%[[VAL_4:.*]]"} + %3 = omp.map.info var_ptr(%2 : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "var%data"} +// CHECK: %[[VAL_5:.*]] = omp.map.info var_ptr(%[[VAL_0]] : !llvm.ptr, !llvm.struct<"_QFdeclare_mapperTmy_type", (i32)>) map_clauses(tofrom) capture(ByRef) members(%[[VAL_3]] : [0] : !llvm.ptr) -> !llvm.ptr {name = "var", partial_map = true} + %4 = omp.map.info var_ptr(%0 : !fir.ref>, !fir.type<_QFdeclare_mapperTmy_type{data:i32}>) map_clauses(tofrom) capture(ByRef) members(%3 : [0] : !fir.ref) -> !fir.ref> {name = "var", partial_map = true} +// CHECK: omp.declare_mapper_info map_entries
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper (PR #121005)
llvmbot wrote: @llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-openmp Author: Akash Banerjee (TIFitis) Changes Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper. --- Full diff: https://github.com/llvm/llvm-project/pull/121005.diff 3 Files Affected: - (modified) flang/test/Fir/convert-to-llvm-openmp-and-fir.fir (+23-4) - (modified) mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp (+39-11) - (modified) mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir (+13) ``diff diff --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir index 8e4e1fe824d9f5..82f2aea3ad983c 100644 --- a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir +++ b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir @@ -936,9 +936,9 @@ func.func @omp_map_info_descriptor_type_conversion(%arg0 : !fir.ref>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.llvm_ptr> {name = ""} // CHECK: %[[DESC_MAP:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(always, delete) capture(ByRef) members(%[[MEMBER_MAP]] : [0] : !llvm.ptr) -> !llvm.ptr {name = ""} %2 = omp.map.info var_ptr(%arg0 : !fir.ref>>, !fir.box>) map_clauses(always, delete) capture(ByRef) members(%1 : [0] : !fir.llvm_ptr>) -> !fir.ref>> {name = ""} - // CHECK: omp.target_exit_data map_entries(%[[DESC_MAP]] : !llvm.ptr) + // CHECK: omp.target_exit_data map_entries(%[[DESC_MAP]] : !llvm.ptr) omp.target_exit_data map_entries(%2 : !fir.ref>>) - return + return } // - @@ -956,8 +956,8 @@ func.func @omp_map_info_derived_type_explicit_member_conversion(%arg0 : !fir.ref %3 = fir.field_index real, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}> %4 = fir.coordinate_of %arg0, %3 : (!fir.ref,int:i32}>>, !fir.field) -> !fir.ref // CHECK: %[[MAP_MEMBER_2:.*]] = omp.map.info var_ptr(%[[GEP_2]] : !llvm.ptr, f32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "dtype%real"} - %5 = omp.map.info var_ptr(%4 : !fir.ref, f32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "dtype%real"} - // CHECK: %[[MAP_PARENT:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP_MEMBER_1]], %[[MAP_MEMBER_2]] : [2], [0] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "dtype", partial_map = true} + %5 = omp.map.info var_ptr(%4 : !fir.ref, f32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "dtype%real"} + // CHECK: %[[MAP_PARENT:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP_MEMBER_1]], %[[MAP_MEMBER_2]] : [2], [0] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "dtype", partial_map = true} %6 = omp.map.info var_ptr(%arg0 : !fir.ref,int:i32}>>, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>) map_clauses(tofrom) capture(ByRef) members(%2, %5 : [2], [0] : !fir.ref, !fir.ref) -> !fir.ref,int:i32}>> {name = "dtype", partial_map = true} // CHECK: omp.target map_entries(%[[MAP_MEMBER_1]] -> %[[ARG_1:.*]], %[[MAP_MEMBER_2]] -> %[[ARG_2:.*]], %[[MAP_PARENT]] -> %[[ARG_3:.*]] : !llvm.ptr, !llvm.ptr, !llvm.ptr) { omp.target map_entries(%2 -> %arg1, %5 -> %arg2, %6 -> %arg3 : !fir.ref, !fir.ref, !fir.ref,int:i32}>>) { @@ -1275,3 +1275,22 @@ func.func @map_nested_dtype_alloca_mem2(%arg0 : !fir.ref { +omp.declare_mapper @my_mapper : !fir.type<_QFdeclare_mapperTmy_type{data:i32}> { +// CHECK: ^bb0(%[[VAL_0:.*]]: !llvm.ptr): +^bb0(%0: !fir.ref>): +// CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(0 : i32) : i32 + %1 = fir.field_index data, !fir.type<_QFdeclare_mapperTmy_type{data:i32}> +// CHECK: %[[VAL_2:.*]] = llvm.getelementptr %[[VAL_0]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFdeclare_mapperTmy_type", (i32)> + %2 = fir.coordinate_of %0, %1 : (!fir.ref>, !fir.field) -> !fir.ref +// CHECK: %[[VAL_3:.*]] = omp.map.info var_ptr(%[[VAL_2]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "var%[[VAL_4:.*]]"} + %3 = omp.map.info var_ptr(%2 : !fir.ref, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref {name = "var%data"} +// CHECK: %[[VAL_5:.*]] = omp.map.info var_ptr(%[[VAL_0]] : !llvm.ptr, !llvm.struct<"_QFdeclare_mapperTmy_type", (i32)>) map_clauses(tofrom) capture(ByRef) members(%[[VAL_3]] : [0] : !llvm.ptr) -> !llvm.ptr {name = "var", partial_map = true} + %4 = omp.map.info var_ptr(%0 : !fir.ref>, !fir.type<_QFdeclare_mapperTmy_type{data:i32}>) map_clauses(tofrom) capture(ByRef) members(%3 : [0] : !fir.ref) -> !fir.ref> {name = "var", partial_map = true} +// CHECK: omp.declare_mapper_info map_entries(%[[VAL_5]], %[[VAL_3]] : !llvm.ptr, !llvm.ptr) + omp.declare_mapper_info map_entries(%4, %3 : !fir
[llvm-branch-commits] [llvm] 5337f1c - Revert "Reapply "[llvm]Add a simple Telemetry framework" (#120769) (#121003)"
Author: Vy Nguyen Date: 2024-12-23T19:29:03-05:00 New Revision: 5337f1cc44dfa6b39c02eaf2a2dc3dec567018bc URL: https://github.com/llvm/llvm-project/commit/5337f1cc44dfa6b39c02eaf2a2dc3dec567018bc DIFF: https://github.com/llvm/llvm-project/commit/5337f1cc44dfa6b39c02eaf2a2dc3dec567018bc.diff LOG: Revert "Reapply "[llvm]Add a simple Telemetry framework" (#120769) (#121003)" This reverts commit dbae7176a6ecf558dc5e92016cdda387c9d74d66. Added: Modified: llvm/docs/UserGuides.rst llvm/lib/CMakeLists.txt llvm/unittests/CMakeLists.txt Removed: llvm/docs/Telemetry.rst llvm/docs/llvm_telemetry_design.png llvm/include/llvm/Telemetry/Telemetry.h llvm/lib/Telemetry/CMakeLists.txt llvm/lib/Telemetry/Telemetry.cpp llvm/unittests/Telemetry/CMakeLists.txt llvm/unittests/Telemetry/TelemetryTest.cpp diff --git a/llvm/docs/Telemetry.rst b/llvm/docs/Telemetry.rst deleted file mode 100644 index 4f30ae82b5628f..00 --- a/llvm/docs/Telemetry.rst +++ /dev/null @@ -1,257 +0,0 @@ -=== -Telemetry framework in LLVM -=== - -.. contents:: - :local: - -.. toctree:: - :hidden: - -Objective -= - -Provides a common framework in LLVM for collecting various usage and performance -metrics. -It is located at ``llvm/Telemetry/Telemetry.h``. - -Characteristics -* Configurable and extensible by: - - * Tools: any tool that wants to use Telemetry can extend and customize it. - * Vendors: Toolchain vendors can also provide custom implementation of the -library, which could either override or extend the given tool's upstream -implementation, to best fit their organization's usage and privacy models. - * End users of such tool can also configure Telemetry (as allowed by their -vendor). - -Important notes - -* There is no concrete implementation of a Telemetry library in upstream LLVM. - We only provide the abstract API here. Any tool that wants telemetry will - implement one. - - The rationale for this is that all the tools in LLVM are very diff erent in - what they care about (what/where/when to instrument data). Hence, it might not - be practical to have a single implementation. - However, in the future, if we see enough common pattern, we can extract them - into a shared place. This is TBD - contributions are welcome. - -* No implementation of Telemetry in upstream LLVM shall store any of the - collected data due to privacy and security reasons: - - * Different organizations have diff erent privacy models: - -* Which data is sensitive, which is not? -* Whether it is acceptable for instrumented data to be stored anywhere? - (to a local file, what not?) - - * Data ownership and data collection consents are hard to accommodate from -LLVM developers' point of view: - -* E.g., data collected by Telemetry is not necessarily owned by the user - of an LLVM tool with Telemetry enabled, hence the user's consent to data - collection is not meaningful. On the other hand, LLVM developers have no - reasonable ways to request consent from the "real" owners. - - -High-level design -= - -Key components --- - -The framework consists of four important classes: - -* ``llvm::telemetry::Manager``: The class responsible for collecting and - transmitting telemetry data. This is the main point of interaction between the - framework and any tool that wants to enable telemetry. -* ``llvm::telemetry::TelemetryInfo``: Data courier -* ``llvm::telemetry::Destination``: Data sink to which the Telemetry framework - sends data. - Its implementation is transparent to the framework. - It is up to the vendor to decide which pieces of data to forward and where - to forward them to for their final storage. -* ``llvm::telemetry::Config``: Configurations for the ``Manager``. - -.. image:: llvm_telemetry_design.png - -How to implement and interact with the API --- - -To use Telemetry in your tool, you need to provide a concrete implementation of the ``Manager`` class and ``Destination``. - -1) Define a custom ``Serializer``, ``Manager``, ``Destination`` and optionally a subclass of ``TelemetryInfo`` - -.. code-block:: c++ - - class JsonSerializer : public Serializer { - public: -json::Object *getOutputObject() { return Out.get(); } - -Error init() override { - if (Started) -return createStringError("Serializer already in use"); - started = true; - Out = std::make_unique(); - return Error::success(); -} - -// Serialize the given value. -void write(StringRef KeyName, bool Value) override { - writeHelper(KeyName, Value); -} - -void write(StringRef KeyName, int Value) override { - writeHelper(KeyName, Value); -} - -void wri
[llvm-branch-commits] [llvm] [DirectX] Implement the resource.load.rawbuffer intrinsic (PR #121012)
https://github.com/bogner created https://github.com/llvm/llvm-project/pull/121012 This introduces `@llvm.dx.resource.load.rawbuffer` and generalizes the buffer load docs under DirectX/DXILResources. This resolves the "load" parts of #106188 >From 53bba63c6a55464ac1872dc60f39510eff426d64 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 19 Dec 2024 16:33:48 -0700 Subject: [PATCH] [DirectX] Implement the resource.load.rawbuffer intrinsic This introduces `@llvm.dx.resource.load.rawbuffer` and generalizes the buffer load docs under DirectX/DXILResources. This resolves the "load" parts of #106188 --- llvm/docs/DirectX/DXILResources.rst | 151 ++-- llvm/include/llvm/IR/IntrinsicsDirectX.td | 4 + llvm/lib/Target/DirectX/DXIL.td | 19 ++ llvm/lib/Target/DirectX/DXILOpBuilder.cpp | 4 + llvm/lib/Target/DirectX/DXILOpLowering.cpp| 45 llvm/test/CodeGen/DirectX/BufferLoad-sm61.ll | 60 + .../CodeGen/DirectX/RawBufferLoad-error64.ll | 24 ++ llvm/test/CodeGen/DirectX/RawBufferLoad.ll| 232 ++ llvm/utils/TableGen/DXILEmitter.cpp | 4 +- 9 files changed, 516 insertions(+), 27 deletions(-) create mode 100644 llvm/test/CodeGen/DirectX/BufferLoad-sm61.ll create mode 100644 llvm/test/CodeGen/DirectX/RawBufferLoad-error64.ll create mode 100644 llvm/test/CodeGen/DirectX/RawBufferLoad.ll diff --git a/llvm/docs/DirectX/DXILResources.rst b/llvm/docs/DirectX/DXILResources.rst index fafcb247f49c94..bcce1b52d9a485 100644 --- a/llvm/docs/DirectX/DXILResources.rst +++ b/llvm/docs/DirectX/DXILResources.rst @@ -321,36 +321,40 @@ Examples: 16-byte Loads, Samples, and Gathers --- -*relevant types: TypedBuffer, CBuffer, and Textures* - -TypedBuffer, CBuffer, and Texture loads, as well as samples and gathers, can -return 1 to 4 elements from the given resource, to a maximum of 16 bytes of -data. DXIL's modeling of this is influenced by DirectX and DXBC's history and -it generally treats these operations as returning 4 32-bit values. For 16-bit -elements the values are 16-bit values, and for 64-bit values the operations -return 4 32-bit integers and emit further code to construct the double. - -In DXIL, these operations return `ResRet`_ and `CBufRet`_ values, are structs -containing 4 elements of the same type, and in the case of `ResRet` a 5th -element that is used by the `CheckAccessFullyMapped`_ operation. - -In LLVM IR the intrinsics will return the contained type of the resource -instead. That is, ``llvm.dx.resource.load.typedbuffer`` from a -``Buffer`` would return a single float, from ``Buffer`` a vector -of 4 floats, and from ``Buffer`` a vector of two doubles, etc. The -operations are then expanded out to match DXIL's format during lowering. - -In order to support ``CheckAccessFullyMapped``, we need these intrinsics to -return an anonymous struct with element-0 being the contained type, and -element-1 being the ``i1`` result of a ``CheckAccessFullyMapped`` call. We -don't have a separate call to ``CheckAccessFullyMapped`` at all, since that's -the only operation that can possibly be done on this value. In practice this -may mean we insert a DXIL operation for the check when this was missing in the -HLSL source, but this actually matches DXC's behaviour in practice. +*relevant types: Buffers, CBuffers, and Textures* + +All load, sample, and gather operations in DXIL return a `ResRet`_ type, and +CBuffer loads return a similar `CBufRet`_ type. These types are structs +containing 4 elements of some basic type, and in the case of `ResRet` a 5th +element that is used by the `CheckAccessFullyMapped`_ operation. Some of these +operations, like `RawBufferLoad`_ include a mask and/or alignment that tell us +some information about how to interpret those four values. + +In the LLVM IR representations of these operations we instead return scalars or +vectors, but we keep the requirement that we only return up to 4 elements of a +basic type. This avoids some unnecessary casting and structure manipulation in +the intermediate format while also keeping lowering to DXIL straightforward. + +LLVM intrinsics that map to operations returning `ResRet` return an anonymous +struct with element-0 being the scalar or vector type, and element-1 being the +``i1`` result of a ``CheckAccessFullyMapped`` call. We don't have a separate +call to ``CheckAccessFullyMapped`` at all, since that's the only operation that +can possibly be done on this value. In practice this may mean we insert a DXIL +operation for the check when this was missing in the HLSL source, but this +actually matches DXC's behaviour in practice. + +For TypedBuffer and Texture, we map directly from the contained type of the +resource to the return value of the intrinsic. Since these resources are +constrained to contain only scalars and vectors of up to 4 elements, the +lowering to DXIL ops is generally straightforward. The one exception we ha
[llvm-branch-commits] [llvm] [DirectX] Implement the resource.load.rawbuffer intrinsic (PR #121012)
llvmbot wrote: @llvm/pr-subscribers-tablegen Author: Justin Bogner (bogner) Changes This introduces `@llvm.dx.resource.load.rawbuffer` and generalizes the buffer load docs under DirectX/DXILResources. This resolves the "load" parts of #106188 --- Patch is 28.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/121012.diff 9 Files Affected: - (modified) llvm/docs/DirectX/DXILResources.rst (+125-26) - (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+4) - (modified) llvm/lib/Target/DirectX/DXIL.td (+19) - (modified) llvm/lib/Target/DirectX/DXILOpBuilder.cpp (+4) - (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+45) - (added) llvm/test/CodeGen/DirectX/BufferLoad-sm61.ll (+60) - (added) llvm/test/CodeGen/DirectX/RawBufferLoad-error64.ll (+24) - (added) llvm/test/CodeGen/DirectX/RawBufferLoad.ll (+232) - (modified) llvm/utils/TableGen/DXILEmitter.cpp (+3-1) ``diff diff --git a/llvm/docs/DirectX/DXILResources.rst b/llvm/docs/DirectX/DXILResources.rst index fafcb247f49c94..bcce1b52d9a485 100644 --- a/llvm/docs/DirectX/DXILResources.rst +++ b/llvm/docs/DirectX/DXILResources.rst @@ -321,36 +321,40 @@ Examples: 16-byte Loads, Samples, and Gathers --- -*relevant types: TypedBuffer, CBuffer, and Textures* - -TypedBuffer, CBuffer, and Texture loads, as well as samples and gathers, can -return 1 to 4 elements from the given resource, to a maximum of 16 bytes of -data. DXIL's modeling of this is influenced by DirectX and DXBC's history and -it generally treats these operations as returning 4 32-bit values. For 16-bit -elements the values are 16-bit values, and for 64-bit values the operations -return 4 32-bit integers and emit further code to construct the double. - -In DXIL, these operations return `ResRet`_ and `CBufRet`_ values, are structs -containing 4 elements of the same type, and in the case of `ResRet` a 5th -element that is used by the `CheckAccessFullyMapped`_ operation. - -In LLVM IR the intrinsics will return the contained type of the resource -instead. That is, ``llvm.dx.resource.load.typedbuffer`` from a -``Buffer`` would return a single float, from ``Buffer`` a vector -of 4 floats, and from ``Buffer`` a vector of two doubles, etc. The -operations are then expanded out to match DXIL's format during lowering. - -In order to support ``CheckAccessFullyMapped``, we need these intrinsics to -return an anonymous struct with element-0 being the contained type, and -element-1 being the ``i1`` result of a ``CheckAccessFullyMapped`` call. We -don't have a separate call to ``CheckAccessFullyMapped`` at all, since that's -the only operation that can possibly be done on this value. In practice this -may mean we insert a DXIL operation for the check when this was missing in the -HLSL source, but this actually matches DXC's behaviour in practice. +*relevant types: Buffers, CBuffers, and Textures* + +All load, sample, and gather operations in DXIL return a `ResRet`_ type, and +CBuffer loads return a similar `CBufRet`_ type. These types are structs +containing 4 elements of some basic type, and in the case of `ResRet` a 5th +element that is used by the `CheckAccessFullyMapped`_ operation. Some of these +operations, like `RawBufferLoad`_ include a mask and/or alignment that tell us +some information about how to interpret those four values. + +In the LLVM IR representations of these operations we instead return scalars or +vectors, but we keep the requirement that we only return up to 4 elements of a +basic type. This avoids some unnecessary casting and structure manipulation in +the intermediate format while also keeping lowering to DXIL straightforward. + +LLVM intrinsics that map to operations returning `ResRet` return an anonymous +struct with element-0 being the scalar or vector type, and element-1 being the +``i1`` result of a ``CheckAccessFullyMapped`` call. We don't have a separate +call to ``CheckAccessFullyMapped`` at all, since that's the only operation that +can possibly be done on this value. In practice this may mean we insert a DXIL +operation for the check when this was missing in the HLSL source, but this +actually matches DXC's behaviour in practice. + +For TypedBuffer and Texture, we map directly from the contained type of the +resource to the return value of the intrinsic. Since these resources are +constrained to contain only scalars and vectors of up to 4 elements, the +lowering to DXIL ops is generally straightforward. The one exception we have +here is that `double` types in the elements are special - these are allowed in +the LLVM intrinsics, but are lowered to pairs of `i32` followed by +``MakeDouble`` operations for DXIL. .. _ResRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#resource-operation-return-types .. _CBufRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#cbufferloadlegacy .. _CheckAccessFullyMap
[llvm-branch-commits] [llvm] [DirectX] Implement the resource.load.rawbuffer intrinsic (PR #121012)
llvmbot wrote: @llvm/pr-subscribers-llvm-ir Author: Justin Bogner (bogner) Changes This introduces `@llvm.dx.resource.load.rawbuffer` and generalizes the buffer load docs under DirectX/DXILResources. This resolves the "load" parts of #106188 --- Patch is 28.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/121012.diff 9 Files Affected: - (modified) llvm/docs/DirectX/DXILResources.rst (+125-26) - (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+4) - (modified) llvm/lib/Target/DirectX/DXIL.td (+19) - (modified) llvm/lib/Target/DirectX/DXILOpBuilder.cpp (+4) - (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+45) - (added) llvm/test/CodeGen/DirectX/BufferLoad-sm61.ll (+60) - (added) llvm/test/CodeGen/DirectX/RawBufferLoad-error64.ll (+24) - (added) llvm/test/CodeGen/DirectX/RawBufferLoad.ll (+232) - (modified) llvm/utils/TableGen/DXILEmitter.cpp (+3-1) ``diff diff --git a/llvm/docs/DirectX/DXILResources.rst b/llvm/docs/DirectX/DXILResources.rst index fafcb247f49c94..bcce1b52d9a485 100644 --- a/llvm/docs/DirectX/DXILResources.rst +++ b/llvm/docs/DirectX/DXILResources.rst @@ -321,36 +321,40 @@ Examples: 16-byte Loads, Samples, and Gathers --- -*relevant types: TypedBuffer, CBuffer, and Textures* - -TypedBuffer, CBuffer, and Texture loads, as well as samples and gathers, can -return 1 to 4 elements from the given resource, to a maximum of 16 bytes of -data. DXIL's modeling of this is influenced by DirectX and DXBC's history and -it generally treats these operations as returning 4 32-bit values. For 16-bit -elements the values are 16-bit values, and for 64-bit values the operations -return 4 32-bit integers and emit further code to construct the double. - -In DXIL, these operations return `ResRet`_ and `CBufRet`_ values, are structs -containing 4 elements of the same type, and in the case of `ResRet` a 5th -element that is used by the `CheckAccessFullyMapped`_ operation. - -In LLVM IR the intrinsics will return the contained type of the resource -instead. That is, ``llvm.dx.resource.load.typedbuffer`` from a -``Buffer`` would return a single float, from ``Buffer`` a vector -of 4 floats, and from ``Buffer`` a vector of two doubles, etc. The -operations are then expanded out to match DXIL's format during lowering. - -In order to support ``CheckAccessFullyMapped``, we need these intrinsics to -return an anonymous struct with element-0 being the contained type, and -element-1 being the ``i1`` result of a ``CheckAccessFullyMapped`` call. We -don't have a separate call to ``CheckAccessFullyMapped`` at all, since that's -the only operation that can possibly be done on this value. In practice this -may mean we insert a DXIL operation for the check when this was missing in the -HLSL source, but this actually matches DXC's behaviour in practice. +*relevant types: Buffers, CBuffers, and Textures* + +All load, sample, and gather operations in DXIL return a `ResRet`_ type, and +CBuffer loads return a similar `CBufRet`_ type. These types are structs +containing 4 elements of some basic type, and in the case of `ResRet` a 5th +element that is used by the `CheckAccessFullyMapped`_ operation. Some of these +operations, like `RawBufferLoad`_ include a mask and/or alignment that tell us +some information about how to interpret those four values. + +In the LLVM IR representations of these operations we instead return scalars or +vectors, but we keep the requirement that we only return up to 4 elements of a +basic type. This avoids some unnecessary casting and structure manipulation in +the intermediate format while also keeping lowering to DXIL straightforward. + +LLVM intrinsics that map to operations returning `ResRet` return an anonymous +struct with element-0 being the scalar or vector type, and element-1 being the +``i1`` result of a ``CheckAccessFullyMapped`` call. We don't have a separate +call to ``CheckAccessFullyMapped`` at all, since that's the only operation that +can possibly be done on this value. In practice this may mean we insert a DXIL +operation for the check when this was missing in the HLSL source, but this +actually matches DXC's behaviour in practice. + +For TypedBuffer and Texture, we map directly from the contained type of the +resource to the return value of the intrinsic. Since these resources are +constrained to contain only scalars and vectors of up to 4 elements, the +lowering to DXIL ops is generally straightforward. The one exception we have +here is that `double` types in the elements are special - these are allowed in +the LLVM intrinsics, but are lowered to pairs of `i32` followed by +``MakeDouble`` operations for DXIL. .. _ResRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#resource-operation-return-types .. _CBufRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#cbufferloadlegacy .. _CheckAccessFullyMapp
[llvm-branch-commits] [llvm] [DirectX] Implement the resource.load.rawbuffer intrinsic (PR #121012)
llvmbot wrote: @llvm/pr-subscribers-backend-directx Author: Justin Bogner (bogner) Changes This introduces `@llvm.dx.resource.load.rawbuffer` and generalizes the buffer load docs under DirectX/DXILResources. This resolves the "load" parts of #106188 --- Patch is 28.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/121012.diff 9 Files Affected: - (modified) llvm/docs/DirectX/DXILResources.rst (+125-26) - (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+4) - (modified) llvm/lib/Target/DirectX/DXIL.td (+19) - (modified) llvm/lib/Target/DirectX/DXILOpBuilder.cpp (+4) - (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+45) - (added) llvm/test/CodeGen/DirectX/BufferLoad-sm61.ll (+60) - (added) llvm/test/CodeGen/DirectX/RawBufferLoad-error64.ll (+24) - (added) llvm/test/CodeGen/DirectX/RawBufferLoad.ll (+232) - (modified) llvm/utils/TableGen/DXILEmitter.cpp (+3-1) ``diff diff --git a/llvm/docs/DirectX/DXILResources.rst b/llvm/docs/DirectX/DXILResources.rst index fafcb247f49c94..bcce1b52d9a485 100644 --- a/llvm/docs/DirectX/DXILResources.rst +++ b/llvm/docs/DirectX/DXILResources.rst @@ -321,36 +321,40 @@ Examples: 16-byte Loads, Samples, and Gathers --- -*relevant types: TypedBuffer, CBuffer, and Textures* - -TypedBuffer, CBuffer, and Texture loads, as well as samples and gathers, can -return 1 to 4 elements from the given resource, to a maximum of 16 bytes of -data. DXIL's modeling of this is influenced by DirectX and DXBC's history and -it generally treats these operations as returning 4 32-bit values. For 16-bit -elements the values are 16-bit values, and for 64-bit values the operations -return 4 32-bit integers and emit further code to construct the double. - -In DXIL, these operations return `ResRet`_ and `CBufRet`_ values, are structs -containing 4 elements of the same type, and in the case of `ResRet` a 5th -element that is used by the `CheckAccessFullyMapped`_ operation. - -In LLVM IR the intrinsics will return the contained type of the resource -instead. That is, ``llvm.dx.resource.load.typedbuffer`` from a -``Buffer`` would return a single float, from ``Buffer`` a vector -of 4 floats, and from ``Buffer`` a vector of two doubles, etc. The -operations are then expanded out to match DXIL's format during lowering. - -In order to support ``CheckAccessFullyMapped``, we need these intrinsics to -return an anonymous struct with element-0 being the contained type, and -element-1 being the ``i1`` result of a ``CheckAccessFullyMapped`` call. We -don't have a separate call to ``CheckAccessFullyMapped`` at all, since that's -the only operation that can possibly be done on this value. In practice this -may mean we insert a DXIL operation for the check when this was missing in the -HLSL source, but this actually matches DXC's behaviour in practice. +*relevant types: Buffers, CBuffers, and Textures* + +All load, sample, and gather operations in DXIL return a `ResRet`_ type, and +CBuffer loads return a similar `CBufRet`_ type. These types are structs +containing 4 elements of some basic type, and in the case of `ResRet` a 5th +element that is used by the `CheckAccessFullyMapped`_ operation. Some of these +operations, like `RawBufferLoad`_ include a mask and/or alignment that tell us +some information about how to interpret those four values. + +In the LLVM IR representations of these operations we instead return scalars or +vectors, but we keep the requirement that we only return up to 4 elements of a +basic type. This avoids some unnecessary casting and structure manipulation in +the intermediate format while also keeping lowering to DXIL straightforward. + +LLVM intrinsics that map to operations returning `ResRet` return an anonymous +struct with element-0 being the scalar or vector type, and element-1 being the +``i1`` result of a ``CheckAccessFullyMapped`` call. We don't have a separate +call to ``CheckAccessFullyMapped`` at all, since that's the only operation that +can possibly be done on this value. In practice this may mean we insert a DXIL +operation for the check when this was missing in the HLSL source, but this +actually matches DXC's behaviour in practice. + +For TypedBuffer and Texture, we map directly from the contained type of the +resource to the return value of the intrinsic. Since these resources are +constrained to contain only scalars and vectors of up to 4 elements, the +lowering to DXIL ops is generally straightforward. The one exception we have +here is that `double` types in the elements are special - these are allowed in +the LLVM intrinsics, but are lowered to pairs of `i32` followed by +``MakeDouble`` operations for DXIL. .. _ResRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#resource-operation-return-types .. _CBufRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#cbufferloadlegacy .. _CheckAccessF