[llvm-branch-commits] [flang] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-15 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak edited 
https://github.com/llvm/llvm-project/pull/77761
___
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] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-15 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak commented:

Thanks Krzysztof! This looks ok to me, but I suggest waiting for approval from 
a second reviewer.

https://github.com/llvm/llvm-project/pull/77761
___
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] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-15 Thread Sergio Afonso via llvm-branch-commits


@@ -0,0 +1,19 @@
+! RUN: bbc -fopenmp -o - %s | FileCheck %s
+
+! Check that this test can be lowered successfully.
+! See https://github.com/llvm/llvm-project/issues/74348
+
+! CHECK-LABEL: func.func @_QPsb
+! CHECK: omp.parallel

skatrak wrote:

I think it would be a bit better to also check the general structure inside of 
omp.parallel. That is, checking the blocks and terminators that are created.

https://github.com/llvm/llvm-project/pull/77761
___
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] [SPARC] Prefer RDPC over CALL to implement GETPCX for 64-bit target (PR #77196)

2024-01-15 Thread via llvm-branch-commits

koachan wrote:

Uh oh, seems like I couldn't merge it with the tool either...
Guess I'll open a new PR to merge this, would that be okay? @brad0 
@s-barannikov 

https://github.com/llvm/llvm-project/pull/77196
___
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] 91eb719 - Revert "[mlir][ExecutionEngine] Add support for global constructors and destructors"

2024-01-15 Thread via llvm-branch-commits

Author: Cullen Rhodes
Date: 2024-01-15T14:10:08Z
New Revision: 91eb719cae57c7787af56401d2e63545cc53bc75

URL: 
https://github.com/llvm/llvm-project/commit/91eb719cae57c7787af56401d2e63545cc53bc75
DIFF: 
https://github.com/llvm/llvm-project/commit/91eb719cae57c7787af56401d2e63545cc53bc75.diff

LOG: Revert "[mlir][ExecutionEngine] Add support for global constructors and 
destructors"

Added: 


Modified: 
mlir/lib/ExecutionEngine/ExecutionEngine.cpp

Removed: 
mlir/test/mlir-cpu-runner/global-constructors.mlir



diff  --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp 
b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
index d4ad2da045e2c4..267ec236d3fd59 100644
--- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -219,9 +219,6 @@ ExecutionEngine::ExecutionEngine(bool enableObjectDump,
 }
 
 ExecutionEngine::~ExecutionEngine() {
-  // Execute the global destructors from the module being processed.
-  if (jit)
-llvm::consumeError(jit->deinitialize(jit->getMainJITDylib()));
   // Run all dynamic library destroy callbacks to prepare for the shutdown.
   for (LibraryDestroyFn destroy : destroyFns)
 destroy();
@@ -399,9 +396,6 @@ ExecutionEngine::create(Operation *m, const 
ExecutionEngineOptions &options,
   };
   engine->registerSymbols(runtimeSymbolMap);
 
-  // Execute the global constructors from the module being processed.
-  cantFail(engine->jit->initialize(engine->jit->getMainJITDylib()));
-
   return std::move(engine);
 }
 

diff  --git a/mlir/test/mlir-cpu-runner/global-constructors.mlir 
b/mlir/test/mlir-cpu-runner/global-constructors.mlir
deleted file mode 100644
index 3ebcaeccc83e32..00
--- a/mlir/test/mlir-cpu-runner/global-constructors.mlir
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: mlir-cpu-runner %s -e entry -entry-point-result=void  \
-// RUN: -shared-libs=%mlir_c_runner_utils | \
-// RUN: FileCheck %s
-
-// Test that the `ctor` executes before `entry` and that `dtor` executes last.
-module {
-  llvm.func @printNewline()
-  llvm.func @printI64(i64)
-  llvm.mlir.global_ctors {ctors = [@ctor], priorities = [0 : i32]}
-  llvm.mlir.global_dtors {dtors = [@dtor], priorities = [0 : i32]}
-  llvm.func @ctor() {
-%0 = llvm.mlir.constant(1 : i64) : i64
-llvm.call @printI64(%0) : (i64) -> ()
-llvm.call @printNewline() : () -> ()
-// CHECK: 1
-llvm.return
-  }
-  llvm.func @entry() {
-%0 = llvm.mlir.constant(2 : i64) : i64
-llvm.call @printI64(%0) : (i64) -> ()
-llvm.call @printNewline() : () -> ()
-// CHECK: 2
-llvm.return
-  }
-  llvm.func @dtor() {
-%0 = llvm.mlir.constant(3 : i64) : i64
-llvm.call @printI64(%0) : (i64) -> ()
-llvm.call @printNewline() : () -> ()
-// CHECK: 3
-llvm.return
-  }
-}



___
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] [SPARC] Prefer RDPC over CALL to implement GETPCX for 64-bit target (PR #77196)

2024-01-15 Thread Sergei Barannikov via llvm-branch-commits

s-barannikov wrote:

Yes, sure 

https://github.com/llvm/llvm-project/pull/77196
___
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] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-15 Thread Kiran Chandramohan via llvm-branch-commits

kiranchandramohan wrote:

@tblah mentions that this patch fixes the unstructured code issue in 
worksharing loop with collapse. https://github.com/llvm/llvm-project/pull/77329.

https://github.com/llvm/llvm-project/pull/77761
___
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] [compiler-rt] [llvm] [clang-tools-extra] [clang] [flang] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-15 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/77761

>From 1b5524ae8874e389d373a55417919afa56beb2b5 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 8 Jan 2024 15:53:07 -0600
Subject: [PATCH] [Flang][OpenMP] Restructure recursive lowering in
 `createBodyOfOp`

This brings `createBodyOfOp` to its final intended form. First, input
privatization is performed, then the recursive lowering takes place,
and finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an
OpenMP region, and the fix is included in this patch.

Fixes https://github.com/llvm/llvm-project/issues/74348.

Recursive lowering [5/5]
---
 flang/include/flang/Lower/OpenMP.h|   4 +-
 flang/lib/Lower/OpenMP.cpp| 133 --
 flang/test/Lower/OpenMP/FIR/sections.f90  |   6 +-
 .../OpenMP/infinite-loop-in-construct.f90 |  19 +++
 flang/test/Lower/OpenMP/sections.f90  |   6 +-
 5 files changed, 119 insertions(+), 49 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/infinite-loop-in-construct.f90

diff --git a/flang/include/flang/Lower/OpenMP.h 
b/flang/include/flang/Lower/OpenMP.h
index 6e772c43d8c46e7..477d3e7d9da3a8f 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -50,8 +50,8 @@ struct Variable;
 } // namespace pft
 
 // Generate the OpenMP terminator for Operation at Location.
-void genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
- mlir::Location);
+mlir::Operation *genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
+ mlir::Location);
 
 void genOpenMPConstruct(AbstractConverter &, Fortran::lower::SymMap &,
 semantics::SemanticsContext &, pft::Evaluation &,
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 6e93387fbff7cc9..bb92fdce4ac56ef 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -383,7 +383,8 @@ void 
DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
 // construct
 mlir::OpBuilder::InsertPoint unstructuredSectionsIP =
 firOpBuilder.saveInsertionPoint();
-firOpBuilder.setInsertionPointToStart(&op->getRegion(0).back());
+mlir::Operation *lastOper = 
op->getRegion(0).back().getTerminator();
+firOpBuilder.setInsertionPoint(lastOper);
 lastPrivIP = firOpBuilder.saveInsertionPoint();
 firOpBuilder.restoreInsertionPoint(unstructuredSectionsIP);
   }
@@ -2133,15 +2134,6 @@ static mlir::Type 
getLoopVarType(Fortran::lower::AbstractConverter &converter,
   return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
 }
 
-static void resetBeforeTerminator(fir::FirOpBuilder &firOpBuilder,
-  mlir::Operation *storeOp,
-  mlir::Block &block) {
-  if (storeOp)
-firOpBuilder.setInsertionPointAfter(storeOp);
-  else
-firOpBuilder.setInsertionPointToStart(&block);
-}
-
 static mlir::Operation *
 createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
   mlir::Location loc, mlir::Value indexVal,
@@ -2183,11 +2175,43 @@ static void createBodyOfOp(
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+
+  auto insertMarker = [](fir::FirOpBuilder &builder) {
+mlir::Value undef = builder.create(builder.getUnknownLoc(),
+ builder.getIndexType());
+return undef.getDefiningOp();
+  };
+
+  // Find the block where the OMP terminator should go. In simple cases
+  // it is the single block in the operation's region. When the region
+  // is more complicated, especially with unstructured control flow, there
+  // may be multiple blocks, and some of them may have non-OMP terminators
+  // resulting from lowering of the code contained within the operation.
+  // By OpenMP rules, there should be a single exit point from the region:
+  // here exit means transfering control to the code following the operation.
+  // STOP statement is allowed and does not count as exit for the purpose of
+  // inserting terminators.
+  auto findExitBlock = [&](mlir::Region ®ion) -> mlir::Block * {
+auto isTerminated = [](mlir::Block &block) -> bool {
+  if (block.empty())
+return false;
+  return block.back().hasTrait();
+};
+
+mlir::Block *exit = nullptr;
+for (auto &block : region) {
+  if (!isTerminated(block)) {
+assert(exit == nullptr && "Multiple exit block in OpenMP region");
+exit = █
+  }
+}
+return exit;
+  };
+
   // If an argument for the region is provided then create the block with that
   // argument. Also up

[llvm-branch-commits] [compiler-rt] [clang-tools-extra] [clang] [flang] [llvm] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

2024-01-15 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/77761

>From 1b5524ae8874e389d373a55417919afa56beb2b5 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Mon, 8 Jan 2024 15:53:07 -0600
Subject: [PATCH 1/3] [Flang][OpenMP] Restructure recursive lowering in
 `createBodyOfOp`

This brings `createBodyOfOp` to its final intended form. First, input
privatization is performed, then the recursive lowering takes place,
and finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an
OpenMP region, and the fix is included in this patch.

Fixes https://github.com/llvm/llvm-project/issues/74348.

Recursive lowering [5/5]
---
 flang/include/flang/Lower/OpenMP.h|   4 +-
 flang/lib/Lower/OpenMP.cpp| 133 --
 flang/test/Lower/OpenMP/FIR/sections.f90  |   6 +-
 .../OpenMP/infinite-loop-in-construct.f90 |  19 +++
 flang/test/Lower/OpenMP/sections.f90  |   6 +-
 5 files changed, 119 insertions(+), 49 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/infinite-loop-in-construct.f90

diff --git a/flang/include/flang/Lower/OpenMP.h 
b/flang/include/flang/Lower/OpenMP.h
index 6e772c43d8c46e..477d3e7d9da3a8 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -50,8 +50,8 @@ struct Variable;
 } // namespace pft
 
 // Generate the OpenMP terminator for Operation at Location.
-void genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
- mlir::Location);
+mlir::Operation *genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
+ mlir::Location);
 
 void genOpenMPConstruct(AbstractConverter &, Fortran::lower::SymMap &,
 semantics::SemanticsContext &, pft::Evaluation &,
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 6e93387fbff7cc..bb92fdce4ac56e 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -383,7 +383,8 @@ void 
DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
 // construct
 mlir::OpBuilder::InsertPoint unstructuredSectionsIP =
 firOpBuilder.saveInsertionPoint();
-firOpBuilder.setInsertionPointToStart(&op->getRegion(0).back());
+mlir::Operation *lastOper = 
op->getRegion(0).back().getTerminator();
+firOpBuilder.setInsertionPoint(lastOper);
 lastPrivIP = firOpBuilder.saveInsertionPoint();
 firOpBuilder.restoreInsertionPoint(unstructuredSectionsIP);
   }
@@ -2133,15 +2134,6 @@ static mlir::Type 
getLoopVarType(Fortran::lower::AbstractConverter &converter,
   return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
 }
 
-static void resetBeforeTerminator(fir::FirOpBuilder &firOpBuilder,
-  mlir::Operation *storeOp,
-  mlir::Block &block) {
-  if (storeOp)
-firOpBuilder.setInsertionPointAfter(storeOp);
-  else
-firOpBuilder.setInsertionPointToStart(&block);
-}
-
 static mlir::Operation *
 createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
   mlir::Location loc, mlir::Value indexVal,
@@ -2183,11 +2175,43 @@ static void createBodyOfOp(
 const llvm::SmallVector &args = {},
 bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+
+  auto insertMarker = [](fir::FirOpBuilder &builder) {
+mlir::Value undef = builder.create(builder.getUnknownLoc(),
+ builder.getIndexType());
+return undef.getDefiningOp();
+  };
+
+  // Find the block where the OMP terminator should go. In simple cases
+  // it is the single block in the operation's region. When the region
+  // is more complicated, especially with unstructured control flow, there
+  // may be multiple blocks, and some of them may have non-OMP terminators
+  // resulting from lowering of the code contained within the operation.
+  // By OpenMP rules, there should be a single exit point from the region:
+  // here exit means transfering control to the code following the operation.
+  // STOP statement is allowed and does not count as exit for the purpose of
+  // inserting terminators.
+  auto findExitBlock = [&](mlir::Region ®ion) -> mlir::Block * {
+auto isTerminated = [](mlir::Block &block) -> bool {
+  if (block.empty())
+return false;
+  return block.back().hasTrait();
+};
+
+mlir::Block *exit = nullptr;
+for (auto &block : region) {
+  if (!isTerminated(block)) {
+assert(exit == nullptr && "Multiple exit block in OpenMP region");
+exit = █
+  }
+}
+return exit;
+  };
+
   // If an argument for the region is provided then create the block with that
   // argument. Also up

[llvm-branch-commits] [llvm] [clang] [SPARC] Prefer RDPC over CALL to implement GETPCX for 64-bit target (PR #77196)

2024-01-15 Thread Brad Smith via llvm-branch-commits

brad0 wrote:

> Uh oh, seems like I couldn't merge it with the tool either... Guess I'll open 
> a new PR to merge this, would that be okay? @brad0 @s-barannikov

Ya, sure. Whatever path is easier and quickest for you.

https://github.com/llvm/llvm-project/pull/77196
___
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] 1b922e1 - Revert "[DFAJumpThreading] Extends the bitwidth of state from uint64_t to APInt"

2024-01-15 Thread via llvm-branch-commits

Author: Vitaly Buka
Date: 2024-01-15T17:50:16-08:00
New Revision: 1b922e19e3c0047206e7f6ba62e44d1f17880ec5

URL: 
https://github.com/llvm/llvm-project/commit/1b922e19e3c0047206e7f6ba62e44d1f17880ec5
DIFF: 
https://github.com/llvm/llvm-project/commit/1b922e19e3c0047206e7f6ba62e44d1f17880ec5.diff

LOG: Revert "[DFAJumpThreading] Extends the bitwidth of state from uint64_t to 
APInt"

Added: 


Modified: 
llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
llvm/test/Transforms/DFAJumpThreading/dfa-jump-threading-transform.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp 
b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
index 0219f65618d8d8..c5bf913cda301b 100644
--- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
@@ -307,7 +307,7 @@ void unfold(DomTreeUpdater *DTU, SelectInstToUnfold 
SIToUnfold,
 
 struct ClonedBlock {
   BasicBlock *BB;
-  APInt State; ///< \p State corresponds to the next value of a switch stmnt.
+  uint64_t State; ///< \p State corresponds to the next value of a switch 
stmnt.
 };
 
 typedef std::deque PathType;
@@ -344,9 +344,9 @@ inline raw_ostream &operator<<(raw_ostream &OS, const 
PathType &Path) {
 /// exit state, and the block that determines the next state.
 struct ThreadingPath {
   /// Exit value is DFA's exit state for the given path.
-  APInt getExitValue() const { return ExitVal; }
+  uint64_t getExitValue() const { return ExitVal; }
   void setExitValue(const ConstantInt *V) {
-ExitVal = V->getValue();
+ExitVal = V->getZExtValue();
 IsExitValSet = true;
   }
   bool isExitValueSet() const { return IsExitValSet; }
@@ -365,7 +365,7 @@ struct ThreadingPath {
 
 private:
   PathType Path;
-  APInt ExitVal;
+  uint64_t ExitVal;
   const BasicBlock *DBB = nullptr;
   bool IsExitValSet = false;
 };
@@ -744,7 +744,7 @@ struct TransformDFA {
 
 for (ThreadingPath &TPath : SwitchPaths->getThreadingPaths()) {
   PathType PathBBs = TPath.getPath();
-  APInt NextState = TPath.getExitValue();
+  uint64_t NextState = TPath.getExitValue();
   const BasicBlock *Determinator = TPath.getDeterminatorBB();
 
   // Update Metrics for the Switch block, this is always cloned
@@ -901,7 +901,7 @@ struct TransformDFA {
   DuplicateBlockMap &DuplicateMap,
   SmallSet &BlocksToClean,
   DomTreeUpdater *DTU) {
-APInt NextState = Path.getExitValue();
+uint64_t NextState = Path.getExitValue();
 const BasicBlock *Determinator = Path.getDeterminatorBB();
 PathType PathBBs = Path.getPath();
 
@@ -993,14 +993,13 @@ struct TransformDFA {
   /// This function also includes updating phi nodes in the successors of the
   /// BB, and remapping uses that were defined locally in the cloned BB.
   BasicBlock *cloneBlockAndUpdatePredecessor(BasicBlock *BB, BasicBlock 
*PrevBB,
- const APInt &NextState,
+ uint64_t NextState,
  DuplicateBlockMap &DuplicateMap,
  DefMap &NewDefs,
  DomTreeUpdater *DTU) {
 ValueToValueMapTy VMap;
 BasicBlock *NewBB = CloneBasicBlock(
-BB, VMap, ".jt" + std::to_string(NextState.getLimitedValue()),
-BB->getParent());
+BB, VMap, ".jt" + std::to_string(NextState), BB->getParent());
 NewBB->moveAfter(BB);
 NumCloned++;
 
@@ -1035,7 +1034,7 @@ struct TransformDFA {
   /// This means creating a new incoming value from NewBB with the new
   /// instruction wherever there is an incoming value from BB.
   void updateSuccessorPhis(BasicBlock *BB, BasicBlock *ClonedBB,
-   const APInt &NextState, ValueToValueMapTy &VMap,
+   uint64_t NextState, ValueToValueMapTy &VMap,
DuplicateBlockMap &DuplicateMap) {
 std::vector BlocksToUpdate;
 
@@ -1145,7 +1144,7 @@ struct TransformDFA {
   void updateLastSuccessor(ThreadingPath &TPath,
DuplicateBlockMap &DuplicateMap,
DomTreeUpdater *DTU) {
-APInt NextState = TPath.getExitValue();
+uint64_t NextState = TPath.getExitValue();
 BasicBlock *BB = TPath.getPath().back();
 BasicBlock *LastBlock = getClonedBB(BB, NextState, DuplicateMap);
 
@@ -1199,7 +1198,7 @@ struct TransformDFA {
 
   /// Checks if BB was already cloned for a particular next state value. If it
   /// was then it returns this cloned block, and otherwise null.
-  BasicBlock *getClonedBB(BasicBlock *BB, const APInt &NextState,
+  BasicBlock *getClonedBB(BasicBlock *BB, uint64_t NextState,
   DuplicateBlockMap &DuplicateMap) {
 CloneList ClonedBBs = DuplicateMap[BB];
 
@@ -1213,10 +1

[llvm-branch-commits] [llvm] [DirectX] Move DXIL ResourceKind and ElementType to DXILABI.h. NFC (PR #78225)

2024-01-15 Thread Justin Bogner via llvm-branch-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/78225

None


___
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] Move DXIL ResourceKind and ElementType to DXILABI.h. NFC (PR #78225)

2024-01-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-directx

Author: Justin Bogner (bogner)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/78225.diff


4 Files Affected:

- (modified) llvm/include/llvm/Frontend/HLSL/HLSLResource.h (+4-48) 
- (modified) llvm/include/llvm/Support/DXILABI.h (+48) 
- (modified) llvm/lib/Target/DirectX/DXILResource.cpp (+46-46) 
- (modified) llvm/lib/Target/DirectX/DXILResource.h (+11-10) 


``diff
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h 
b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
index 068b4c66711e467..dcf78ec856a9d64 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -14,6 +14,7 @@
 #define LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
 
 #include "llvm/IR/Metadata.h"
+#include "llvm/Support/DXILABI.h"
 
 namespace llvm {
 class GlobalVariable;
@@ -29,54 +30,9 @@ enum class ResourceClass : uint8_t {
   NumClasses = Invalid,
 };
 
-// The value ordering of this enumeration is part of the DXIL ABI. Elements
-// can only be added to the end, and not removed.
-enum class ResourceKind : uint32_t {
-  Invalid = 0,
-  Texture1D,
-  Texture2D,
-  Texture2DMS,
-  Texture3D,
-  TextureCube,
-  Texture1DArray,
-  Texture2DArray,
-  Texture2DMSArray,
-  TextureCubeArray,
-  TypedBuffer,
-  RawBuffer,
-  StructuredBuffer,
-  CBuffer,
-  Sampler,
-  TBuffer,
-  RTAccelerationStructure,
-  FeedbackTexture2D,
-  FeedbackTexture2DArray,
-  NumEntries,
-};
-
-// The value ordering of this enumeration is part of the DXIL ABI. Elements
-// can only be added to the end, and not removed.
-enum class ElementType : uint32_t {
-  Invalid = 0,
-  I1,
-  I16,
-  U16,
-  I32,
-  U32,
-  I64,
-  U64,
-  F16,
-  F32,
-  F64,
-  SNormF16,
-  UNormF16,
-  SNormF32,
-  UNormF32,
-  SNormF64,
-  UNormF64,
-  PackedS8x32,
-  PackedU8x32,
-};
+// For now we use DXIL ABI enum values directly. This may change in the future.
+using dxil::ResourceKind;
+using dxil::ElementType;
 
 class FrontendResource {
   MDNode *Entry;
diff --git a/llvm/include/llvm/Support/DXILABI.h 
b/llvm/include/llvm/Support/DXILABI.h
index e2a8fbad16bb3f7..c1d81775b6711e3 100644
--- a/llvm/include/llvm/Support/DXILABI.h
+++ b/llvm/include/llvm/Support/DXILABI.h
@@ -39,6 +39,54 @@ enum class ParameterKind : uint8_t {
   DXIL_HANDLE,
 };
 
+/// The kind of resource for an SRV or UAV resource. Sometimes referred to as
+/// "Shape" in the DXIL docs.
+enum class ResourceKind : uint32_t {
+  Invalid = 0,
+  Texture1D,
+  Texture2D,
+  Texture2DMS,
+  Texture3D,
+  TextureCube,
+  Texture1DArray,
+  Texture2DArray,
+  Texture2DMSArray,
+  TextureCubeArray,
+  TypedBuffer,
+  RawBuffer,
+  StructuredBuffer,
+  CBuffer,
+  Sampler,
+  TBuffer,
+  RTAccelerationStructure,
+  FeedbackTexture2D,
+  FeedbackTexture2DArray,
+  NumEntries,
+};
+
+/// The element type of an SRV or UAV resource.
+enum class ElementType : uint32_t {
+  Invalid = 0,
+  I1,
+  I16,
+  U16,
+  I32,
+  U32,
+  I64,
+  U64,
+  F16,
+  F32,
+  F64,
+  SNormF16,
+  UNormF16,
+  SNormF32,
+  UNormF32,
+  SNormF64,
+  UNormF64,
+  PackedS8x32,
+  PackedU8x32,
+};
+
 } // namespace dxil
 } // namespace llvm
 
diff --git a/llvm/lib/Target/DirectX/DXILResource.cpp 
b/llvm/lib/Target/DirectX/DXILResource.cpp
index 621852f2453ff51..8e5b9867e6661bf 100644
--- a/llvm/lib/Target/DirectX/DXILResource.cpp
+++ b/llvm/lib/Target/DirectX/DXILResource.cpp
@@ -21,7 +21,6 @@
 
 using namespace llvm;
 using namespace llvm::dxil;
-using namespace llvm::hlsl;
 
 template  void ResourceTable::collect(Module &M) {
   NamedMDNode *Entry = M.getNamedMetadata(MDName);
@@ -30,7 +29,7 @@ template  void ResourceTable::collect(Module 
&M) {
 
   uint32_t Counter = 0;
   for (auto *Res : Entry->operands()) {
-Data.push_back(T(Counter++, FrontendResource(cast(Res;
+Data.push_back(T(Counter++, hlsl::FrontendResource(cast(Res;
   }
 }
 
@@ -42,7 +41,7 @@ template <> void 
ResourceTable::collect(Module &M) {
   uint32_t Counter = 0;
   for (auto *Res : Entry->operands()) {
 Data.push_back(
-ConstantBuffer(Counter++, FrontendResource(cast(Res;
+ConstantBuffer(Counter++, hlsl::FrontendResource(cast(Res;
   }
   // FIXME: share CBufferDataLayout with CBuffer load lowering.
   //   See https://github.com/llvm/llvm-project/issues/58381
@@ -56,7 +55,7 @@ void Resources::collect(Module &M) {
   CBuffers.collect(M);
 }
 
-ResourceBase::ResourceBase(uint32_t I, FrontendResource R)
+ResourceBase::ResourceBase(uint32_t I, hlsl::FrontendResource R)
 : ID(I), GV(R.getGlobalVariable()), Name(""), Space(R.getSpace()),
   LowerBound(R.getResourceIndex()), RangeSize(1) {
   if (auto *ArrTy = dyn_cast(GV->getValueType()))
@@ -107,83 +106,84 @@ StringRef ResourceBase::getElementTypeName(ElementType 
ElTy) {
   llvm_unreachable("All ElementType enums are handled in switch");
 }
 
-void ResourceBase::printElementType(Kinds Kind, ElementType ElTy,
+void ResourceBase::printElementT

[llvm-branch-commits] [llvm] [DirectX] Move DXIL ResourceKind and ElementType to DXILABI.h. NFC (PR #78225)

2024-01-15 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff b0fff11ff5d46deb5df3485b87b22bb61e93910f 
edca247b1dec13f7549ad7d43881d0c2b8f34d62 -- 
llvm/include/llvm/Frontend/HLSL/HLSLResource.h 
llvm/include/llvm/Support/DXILABI.h llvm/lib/Target/DirectX/DXILResource.cpp 
llvm/lib/Target/DirectX/DXILResource.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h 
b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
index dcf78ec856..edfcbda0a3 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -31,8 +31,8 @@ enum class ResourceClass : uint8_t {
 };
 
 // For now we use DXIL ABI enum values directly. This may change in the future.
-using dxil::ResourceKind;
 using dxil::ElementType;
+using dxil::ResourceKind;
 
 class FrontendResource {
   MDNode *Entry;

``




https://github.com/llvm/llvm-project/pull/78225
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits