Skip to content

Commit 95c9aa7

Browse files
committed
address reviewer comments
1 parent ac65fb6 commit 95c9aa7

File tree

1 file changed

+58
-54
lines changed

1 file changed

+58
-54
lines changed

mlir/lib/Target/LLVMIR/Dialect/Ptr/PtrToLLVMIRTranslation.cpp

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace {
2929

3030
/// Converts ptr::AtomicOrdering to llvm::AtomicOrdering
3131
static llvm::AtomicOrdering
32-
convertAtomicOrdering(ptr::AtomicOrdering ordering) {
32+
translateAtomicOrdering(ptr::AtomicOrdering ordering) {
3333
switch (ordering) {
3434
case ptr::AtomicOrdering::not_atomic:
3535
return llvm::AtomicOrdering::NotAtomic;
@@ -49,10 +49,10 @@ convertAtomicOrdering(ptr::AtomicOrdering ordering) {
4949
llvm_unreachable("Unknown atomic ordering");
5050
}
5151

52-
/// Convert ptr.ptr_add operation
52+
/// Translate ptr.ptr_add operation to LLVM IR.
5353
static LogicalResult
54-
convertPtrAddOp(PtrAddOp ptrAddOp, llvm::IRBuilderBase &builder,
55-
LLVM::ModuleTranslation &moduleTranslation) {
54+
translatePtrAddOp(PtrAddOp ptrAddOp, llvm::IRBuilderBase &builder,
55+
LLVM::ModuleTranslation &moduleTranslation) {
5656
llvm::Value *basePtr = moduleTranslation.lookupValue(ptrAddOp.getBase());
5757
llvm::Value *offset = moduleTranslation.lookupValue(ptrAddOp.getOffset());
5858

@@ -83,26 +83,27 @@ convertPtrAddOp(PtrAddOp ptrAddOp, llvm::IRBuilderBase &builder,
8383
return success();
8484
}
8585

86-
/// Convert ptr.load operation
87-
static LogicalResult convertLoadOp(LoadOp loadOp, llvm::IRBuilderBase &builder,
88-
LLVM::ModuleTranslation &moduleTranslation) {
86+
/// Translate ptr.load operation to LLVM IR.
87+
static LogicalResult
88+
translateLoadOp(LoadOp loadOp, llvm::IRBuilderBase &builder,
89+
LLVM::ModuleTranslation &moduleTranslation) {
8990
llvm::Value *ptr = moduleTranslation.lookupValue(loadOp.getPtr());
9091
if (!ptr)
9192
return loadOp.emitError("Failed to lookup pointer operand");
9293

93-
// Convert result type to LLVM type
94+
// Translate result type to LLVM type
9495
llvm::Type *resultType =
9596
moduleTranslation.convertType(loadOp.getValue().getType());
9697
if (!resultType)
97-
return loadOp.emitError("Failed to convert result type");
98+
return loadOp.emitError("Failed to translate result type");
9899

99100
// Create the load instruction.
100101
llvm::MaybeAlign alignment(loadOp.getAlignment().value_or(0));
101102
llvm::LoadInst *loadInst = builder.CreateAlignedLoad(
102103
resultType, ptr, alignment, loadOp.getVolatile_());
103104

104105
// Set op flags and metadata.
105-
loadInst->setAtomic(convertAtomicOrdering(loadOp.getOrdering()));
106+
loadInst->setAtomic(translateAtomicOrdering(loadOp.getOrdering()));
106107
// Set sync scope if specified
107108
if (loadOp.getSyncscope().has_value()) {
108109
llvm::LLVMContext &ctx = builder.getContext();
@@ -135,10 +136,10 @@ static LogicalResult convertLoadOp(LoadOp loadOp, llvm::IRBuilderBase &builder,
135136
return success();
136137
}
137138

138-
/// Convert ptr.store operation
139+
/// Translate ptr.store operation to LLVM IR.
139140
static LogicalResult
140-
convertStoreOp(StoreOp storeOp, llvm::IRBuilderBase &builder,
141-
LLVM::ModuleTranslation &moduleTranslation) {
141+
translateStoreOp(StoreOp storeOp, llvm::IRBuilderBase &builder,
142+
LLVM::ModuleTranslation &moduleTranslation) {
142143
llvm::Value *value = moduleTranslation.lookupValue(storeOp.getValue());
143144
llvm::Value *ptr = moduleTranslation.lookupValue(storeOp.getPtr());
144145

@@ -151,7 +152,7 @@ convertStoreOp(StoreOp storeOp, llvm::IRBuilderBase &builder,
151152
builder.CreateAlignedStore(value, ptr, alignment, storeOp.getVolatile_());
152153

153154
// Set op flags and metadata.
154-
storeInst->setAtomic(convertAtomicOrdering(storeOp.getOrdering()));
155+
storeInst->setAtomic(translateAtomicOrdering(storeOp.getOrdering()));
155156
// Set sync scope if specified
156157
if (storeOp.getSyncscope().has_value()) {
157158
llvm::LLVMContext &ctx = builder.getContext();
@@ -178,21 +179,21 @@ convertStoreOp(StoreOp storeOp, llvm::IRBuilderBase &builder,
178179
return success();
179180
}
180181

181-
/// Convert ptr.type_offset operation
182+
/// Translate ptr.type_offset operation to LLVM IR.
182183
static LogicalResult
183-
convertTypeOffsetOp(TypeOffsetOp typeOffsetOp, llvm::IRBuilderBase &builder,
184-
LLVM::ModuleTranslation &moduleTranslation) {
185-
// Convert the element type to LLVM type
184+
translateTypeOffsetOp(TypeOffsetOp typeOffsetOp, llvm::IRBuilderBase &builder,
185+
LLVM::ModuleTranslation &moduleTranslation) {
186+
// Translate the element type to LLVM type
186187
llvm::Type *elementType =
187188
moduleTranslation.convertType(typeOffsetOp.getElementType());
188189
if (!elementType)
189-
return typeOffsetOp.emitError("Failed to convert the element type");
190+
return typeOffsetOp.emitError("Failed to translate the element type");
190191

191-
// Convert result type
192+
// Translate result type
192193
llvm::Type *resultType =
193194
moduleTranslation.convertType(typeOffsetOp.getResult().getType());
194195
if (!resultType)
195-
return typeOffsetOp.emitError("Failed to convert the result type");
196+
return typeOffsetOp.emitError("Failed to translate the result type");
196197

197198
// Use GEP with null pointer to compute type size/offset.
198199
llvm::Value *nullPtr = llvm::Constant::getNullValue(builder.getPtrTy(0));
@@ -204,10 +205,10 @@ convertTypeOffsetOp(TypeOffsetOp typeOffsetOp, llvm::IRBuilderBase &builder,
204205
return success();
205206
}
206207

207-
/// Convert ptr.gather operation
208+
/// Translate ptr.gather operation to LLVM IR.
208209
static LogicalResult
209-
convertGatherOp(GatherOp gatherOp, llvm::IRBuilderBase &builder,
210-
LLVM::ModuleTranslation &moduleTranslation) {
210+
translateGatherOp(GatherOp gatherOp, llvm::IRBuilderBase &builder,
211+
LLVM::ModuleTranslation &moduleTranslation) {
211212
llvm::Value *ptrs = moduleTranslation.lookupValue(gatherOp.getPtrs());
212213
llvm::Value *mask = moduleTranslation.lookupValue(gatherOp.getMask());
213214
llvm::Value *passthrough =
@@ -216,11 +217,11 @@ convertGatherOp(GatherOp gatherOp, llvm::IRBuilderBase &builder,
216217
if (!ptrs || !mask || !passthrough)
217218
return gatherOp.emitError("Failed to lookup operands");
218219

219-
// Convert result type to LLVM type.
220+
// Translate result type to LLVM type.
220221
llvm::Type *resultType =
221222
moduleTranslation.convertType(gatherOp.getResult().getType());
222223
if (!resultType)
223-
return gatherOp.emitError("Failed to convert result type");
224+
return gatherOp.emitError("Failed to translate result type");
224225

225226
// Get the alignment.
226227
llvm::MaybeAlign alignment(gatherOp.getAlignment().value_or(0));
@@ -233,10 +234,10 @@ convertGatherOp(GatherOp gatherOp, llvm::IRBuilderBase &builder,
233234
return success();
234235
}
235236

236-
/// Convert ptr.masked_load operation
237+
/// Translate ptr.masked_load operation to LLVM IR.
237238
static LogicalResult
238-
convertMaskedLoadOp(MaskedLoadOp maskedLoadOp, llvm::IRBuilderBase &builder,
239-
LLVM::ModuleTranslation &moduleTranslation) {
239+
translateMaskedLoadOp(MaskedLoadOp maskedLoadOp, llvm::IRBuilderBase &builder,
240+
LLVM::ModuleTranslation &moduleTranslation) {
240241
llvm::Value *ptr = moduleTranslation.lookupValue(maskedLoadOp.getPtr());
241242
llvm::Value *mask = moduleTranslation.lookupValue(maskedLoadOp.getMask());
242243
llvm::Value *passthrough =
@@ -245,11 +246,11 @@ convertMaskedLoadOp(MaskedLoadOp maskedLoadOp, llvm::IRBuilderBase &builder,
245246
if (!ptr || !mask || !passthrough)
246247
return maskedLoadOp.emitError("Failed to lookup operands");
247248

248-
// Convert result type to LLVM type.
249+
// Translate result type to LLVM type.
249250
llvm::Type *resultType =
250251
moduleTranslation.convertType(maskedLoadOp.getResult().getType());
251252
if (!resultType)
252-
return maskedLoadOp.emitError("Failed to convert result type");
253+
return maskedLoadOp.emitError("Failed to translate result type");
253254

254255
// Get the alignment.
255256
llvm::MaybeAlign alignment(maskedLoadOp.getAlignment().value_or(0));
@@ -262,10 +263,11 @@ convertMaskedLoadOp(MaskedLoadOp maskedLoadOp, llvm::IRBuilderBase &builder,
262263
return success();
263264
}
264265

265-
/// Convert ptr.masked_store operation
266+
/// Translate ptr.masked_store operation to LLVM IR.
266267
static LogicalResult
267-
convertMaskedStoreOp(MaskedStoreOp maskedStoreOp, llvm::IRBuilderBase &builder,
268-
LLVM::ModuleTranslation &moduleTranslation) {
268+
translateMaskedStoreOp(MaskedStoreOp maskedStoreOp,
269+
llvm::IRBuilderBase &builder,
270+
LLVM::ModuleTranslation &moduleTranslation) {
269271
llvm::Value *value = moduleTranslation.lookupValue(maskedStoreOp.getValue());
270272
llvm::Value *ptr = moduleTranslation.lookupValue(maskedStoreOp.getPtr());
271273
llvm::Value *mask = moduleTranslation.lookupValue(maskedStoreOp.getMask());
@@ -281,10 +283,10 @@ convertMaskedStoreOp(MaskedStoreOp maskedStoreOp, llvm::IRBuilderBase &builder,
281283
return success();
282284
}
283285

284-
/// Convert ptr.scatter operation
286+
/// Translate ptr.scatter operation to LLVM IR.
285287
static LogicalResult
286-
convertScatterOp(ScatterOp scatterOp, llvm::IRBuilderBase &builder,
287-
LLVM::ModuleTranslation &moduleTranslation) {
288+
translateScatterOp(ScatterOp scatterOp, llvm::IRBuilderBase &builder,
289+
LLVM::ModuleTranslation &moduleTranslation) {
288290
llvm::Value *value = moduleTranslation.lookupValue(scatterOp.getValue());
289291
llvm::Value *ptrs = moduleTranslation.lookupValue(scatterOp.getPtrs());
290292
llvm::Value *mask = moduleTranslation.lookupValue(scatterOp.getMask());
@@ -300,11 +302,11 @@ convertScatterOp(ScatterOp scatterOp, llvm::IRBuilderBase &builder,
300302
return success();
301303
}
302304

303-
/// Convert ptr.constant operation
305+
/// Translate ptr.constant operation to LLVM IR.
304306
static LogicalResult
305-
convertConstantOp(ConstantOp constantOp, llvm::IRBuilderBase &builder,
306-
LLVM::ModuleTranslation &moduleTranslation) {
307-
// Convert result type to LLVM type
307+
translateConstantOp(ConstantOp constantOp, llvm::IRBuilderBase &builder,
308+
LLVM::ModuleTranslation &moduleTranslation) {
309+
// Translate result type to LLVM type
308310
llvm::PointerType *resultType = dyn_cast_or_null<llvm::PointerType>(
309311
moduleTranslation.convertType(constantOp.getResult().getType()));
310312
if (!resultType)
@@ -317,7 +319,7 @@ convertConstantOp(ConstantOp constantOp, llvm::IRBuilderBase &builder,
317319
// Create a null pointer constant
318320
result = llvm::ConstantPointerNull::get(resultType);
319321
} else if (auto addressAttr = dyn_cast<ptr::AddressAttr>(value)) {
320-
// Create an integer constant and convert it to pointer
322+
// Create an integer constant and translate it to pointer
321323
llvm::APInt addressValue = addressAttr.getValue();
322324

323325
// Determine the integer type width based on the target's pointer size
@@ -337,7 +339,7 @@ convertConstantOp(ConstantOp constantOp, llvm::IRBuilderBase &builder,
337339
: addressValue.trunc(pointerSizeInBits);
338340
}
339341

340-
// Create integer constant and convert to pointer
342+
// Create integer constant and translate to pointer
341343
llvm::Type *intType = builder.getIntNTy(pointerSizeInBits);
342344
llvm::Value *intValue = llvm::ConstantInt::get(intType, addressValue);
343345
result = builder.CreateIntToPtr(intValue, resultType);
@@ -349,7 +351,7 @@ convertConstantOp(ConstantOp constantOp, llvm::IRBuilderBase &builder,
349351
return success();
350352
}
351353

352-
/// Implementation of the dialect interface that converts operations belonging
354+
/// Implementation of the dialect interface that translates operations belonging
353355
/// to the `ptr` dialect to LLVM IR.
354356
class PtrDialectLLVMIRTranslationInterface
355357
: public LLVMTranslationDialectInterface {
@@ -364,32 +366,34 @@ class PtrDialectLLVMIRTranslationInterface
364366

365367
return llvm::TypeSwitch<Operation *, LogicalResult>(op)
366368
.Case([&](ConstantOp constantOp) {
367-
return convertConstantOp(constantOp, builder, moduleTranslation);
369+
return translateConstantOp(constantOp, builder, moduleTranslation);
368370
})
369371
.Case([&](PtrAddOp ptrAddOp) {
370-
return convertPtrAddOp(ptrAddOp, builder, moduleTranslation);
372+
return translatePtrAddOp(ptrAddOp, builder, moduleTranslation);
371373
})
372374
.Case([&](LoadOp loadOp) {
373-
return convertLoadOp(loadOp, builder, moduleTranslation);
375+
return translateLoadOp(loadOp, builder, moduleTranslation);
374376
})
375377
.Case([&](StoreOp storeOp) {
376-
return convertStoreOp(storeOp, builder, moduleTranslation);
378+
return translateStoreOp(storeOp, builder, moduleTranslation);
377379
})
378380
.Case([&](TypeOffsetOp typeOffsetOp) {
379-
return convertTypeOffsetOp(typeOffsetOp, builder, moduleTranslation);
381+
return translateTypeOffsetOp(typeOffsetOp, builder,
382+
moduleTranslation);
380383
})
381384
.Case<GatherOp>([&](GatherOp gatherOp) {
382-
return convertGatherOp(gatherOp, builder, moduleTranslation);
385+
return translateGatherOp(gatherOp, builder, moduleTranslation);
383386
})
384387
.Case<MaskedLoadOp>([&](MaskedLoadOp maskedLoadOp) {
385-
return convertMaskedLoadOp(maskedLoadOp, builder, moduleTranslation);
388+
return translateMaskedLoadOp(maskedLoadOp, builder,
389+
moduleTranslation);
386390
})
387391
.Case<MaskedStoreOp>([&](MaskedStoreOp maskedStoreOp) {
388-
return convertMaskedStoreOp(maskedStoreOp, builder,
389-
moduleTranslation);
392+
return translateMaskedStoreOp(maskedStoreOp, builder,
393+
moduleTranslation);
390394
})
391395
.Case<ScatterOp>([&](ScatterOp scatterOp) {
392-
return convertScatterOp(scatterOp, builder, moduleTranslation);
396+
return translateScatterOp(scatterOp, builder, moduleTranslation);
393397
})
394398
.Default([&](Operation *op) {
395399
return op->emitError("Translation for operation '")

0 commit comments

Comments
 (0)