@@ -80,18 +80,7 @@ class OpenACCClauseCIREmitter final
8080 }
8181
8282 mlir::Value emitIntExpr (const Expr *intExpr) {
83- mlir::Value expr = cgf.emitScalarExpr (intExpr);
84- mlir::Location exprLoc = cgf.cgm .getLoc (intExpr->getBeginLoc ());
85-
86- mlir::IntegerType targetType = mlir::IntegerType::get (
87- &cgf.getMLIRContext (), cgf.getContext ().getIntWidth (intExpr->getType ()),
88- intExpr->getType ()->isSignedIntegerOrEnumerationType ()
89- ? mlir::IntegerType::SignednessSemantics::Signed
90- : mlir::IntegerType::SignednessSemantics::Unsigned);
91-
92- auto conversionOp = builder.create <mlir::UnrealizedConversionCastOp>(
93- exprLoc, targetType, expr);
94- return conversionOp.getResult (0 );
83+ return cgf.emitOpenACCIntExpr (intExpr);
9584 }
9685
9786 // 'condition' as an OpenACC grammar production is used for 'if' and (some
@@ -111,6 +100,7 @@ class OpenACCClauseCIREmitter final
111100
112101 mlir::Value createConstantInt (mlir::Location loc, unsigned width,
113102 int64_t value) {
103+ return cgf.createOpenACCConstantInt (loc, width, value);
114104 mlir::IntegerType ty = mlir::IntegerType::get (
115105 &cgf.getMLIRContext (), width,
116106 mlir::IntegerType::SignednessSemantics::Signless);
@@ -184,105 +174,6 @@ class OpenACCClauseCIREmitter final
184174 dataOperands.append (computeEmitter.dataOperands );
185175 }
186176
187- struct DataOperandInfo {
188- mlir::Location beginLoc;
189- mlir::Value varValue;
190- std::string name;
191- llvm::SmallVector<mlir::Value> bounds;
192- };
193-
194- mlir::Value createBound (mlir::Location boundLoc, mlir::Value lowerBound,
195- mlir::Value upperBound, mlir::Value extent) {
196- // Arrays always have a start-idx of 0.
197- mlir::Value startIdx = createConstantInt (boundLoc, 64 , 0 );
198- // Stride is always 1 in C/C++.
199- mlir::Value stride = createConstantInt (boundLoc, 64 , 1 );
200-
201- auto bound = builder.create <mlir::acc::DataBoundsOp>(boundLoc, lowerBound,
202- upperBound);
203- bound.getStartIdxMutable ().assign (startIdx);
204- if (extent)
205- bound.getExtentMutable ().assign (extent);
206- bound.getStrideMutable ().assign (stride);
207-
208- return bound;
209- }
210-
211- // A helper function that gets the information from an operand to a data
212- // clause, so that it can be used to emit the data operations.
213- DataOperandInfo getDataOperandInfo (OpenACCDirectiveKind dk, const Expr *e) {
214- // TODO: OpenACC: Cache was different enough as to need a separate
215- // `ActOnCacheVar`, so we are going to need to do some investigations here
216- // when it comes to implement this for cache.
217- if (dk == OpenACCDirectiveKind::Cache) {
218- cgf.cgm .errorNYI (e->getSourceRange (),
219- " OpenACC data operand for 'cache' directive" );
220- return {cgf.cgm .getLoc (e->getBeginLoc ()), {}, {}, {}};
221- }
222-
223- const Expr *curVarExpr = e->IgnoreParenImpCasts ();
224-
225- mlir::Location exprLoc = cgf.cgm .getLoc (curVarExpr->getBeginLoc ());
226- llvm::SmallVector<mlir::Value> bounds;
227-
228- std::string exprString;
229- llvm::raw_string_ostream os (exprString);
230- e->printPretty (os, nullptr , cgf.getContext ().getPrintingPolicy ());
231-
232- // Assemble the list of bounds.
233- while (isa<ArraySectionExpr, ArraySubscriptExpr>(curVarExpr)) {
234- mlir::Location boundLoc = cgf.cgm .getLoc (curVarExpr->getBeginLoc ());
235- mlir::Value lowerBound;
236- mlir::Value upperBound;
237- mlir::Value extent;
238-
239- if (const auto *section = dyn_cast<ArraySectionExpr>(curVarExpr)) {
240- if (const Expr *lb = section->getLowerBound ())
241- lowerBound = emitIntExpr (lb);
242- else
243- lowerBound = createConstantInt (boundLoc, 64 , 0 );
244-
245- if (const Expr *len = section->getLength ()) {
246- extent = emitIntExpr (len);
247- } else {
248- QualType baseTy = ArraySectionExpr::getBaseOriginalType (
249- section->getBase ()->IgnoreParenImpCasts ());
250- // We know this is the case as implicit lengths are only allowed for
251- // array types with a constant size, or a dependent size. AND since
252- // we are codegen we know we're not dependent.
253- auto *arrayTy = cgf.getContext ().getAsConstantArrayType (baseTy);
254- // Rather than trying to calculate the extent based on the
255- // lower-bound, we can just emit this as an upper bound.
256- upperBound =
257- createConstantInt (boundLoc, 64 , arrayTy->getLimitedSize () - 1 );
258- }
259-
260- curVarExpr = section->getBase ()->IgnoreParenImpCasts ();
261- } else {
262- const auto *subscript = cast<ArraySubscriptExpr>(curVarExpr);
263-
264- lowerBound = emitIntExpr (subscript->getIdx ());
265- // Length of an array index is always 1.
266- extent = createConstantInt (boundLoc, 64 , 1 );
267- curVarExpr = subscript->getBase ()->IgnoreParenImpCasts ();
268- }
269-
270- bounds.push_back (createBound (boundLoc, lowerBound, upperBound, extent));
271- }
272-
273- if (const auto *memExpr = dyn_cast<MemberExpr>(curVarExpr))
274- return {exprLoc, cgf.emitMemberExpr (memExpr).getPointer (), exprString,
275- std::move (bounds)};
276-
277- // Sema has made sure that only 4 types of things can get here, array
278- // subscript, array section, member expr, or DRE to a var decl (or the
279- // former 3 wrapping a var-decl), so we should be able to assume this is
280- // right.
281- const auto *dre = cast<DeclRefExpr>(curVarExpr);
282- return {exprLoc, cgf.emitDeclRefLValue (dre).getPointer (), exprString,
283- std::move (bounds)};
284- }
285-
286177 mlir::acc::DataClauseModifier
287178 convertModifiers (OpenACCModifierKind modifiers) {
288179 using namespace mlir ::acc;
@@ -314,7 +205,8 @@ class OpenACCClauseCIREmitter final
314205 void addDataOperand (const Expr *varOperand, mlir::acc::DataClause dataClause,
315206 OpenACCModifierKind modifiers, bool structured,
316207 bool implicit) {
317- DataOperandInfo opInfo = getDataOperandInfo (dirKind, varOperand);
208+ CIRGenFunction::OpenACCDataOperandInfo opInfo =
209+ cgf.getOpenACCDataOperandInfo (varOperand);
318210
319211 auto beforeOp =
320212 builder.create <BeforeOpTy>(opInfo.beginLoc , opInfo.varValue , structured,
@@ -355,7 +247,8 @@ class OpenACCClauseCIREmitter final
355247 void addDataOperand (const Expr *varOperand, mlir::acc::DataClause dataClause,
356248 OpenACCModifierKind modifiers, bool structured,
357249 bool implicit) {
358- DataOperandInfo opInfo = getDataOperandInfo (dirKind, varOperand);
250+ CIRGenFunction::OpenACCDataOperandInfo opInfo =
251+ cgf.getOpenACCDataOperandInfo (varOperand);
359252 auto beforeOp =
360253 builder.create <BeforeOpTy>(opInfo.beginLoc , opInfo.varValue , structured,
361254 implicit, opInfo.name , opInfo.bounds );
0 commit comments