Skip to content

Commit c307946

Browse files
committed
address some comments
1 parent 05ad348 commit c307946

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

mlir/lib/CAPI/Dialect/LLVM.cpp

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
#include "mlir/CAPI/Wrap.h"
1414
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
1515
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
16-
#include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.h.inc"
1716
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
18-
#include "mlir/IR/Attributes.h"
19-
#include "mlir/IR/BuiltinAttributes.h"
20-
#include "mlir/Support/LLVM.h"
21-
#include <stdint.h>
17+
#include "llvm/ADT/SmallVector.h"
18+
#include "llvm/ADT/SmallVectorExtras.h"
2219

2320
using namespace mlir;
2421
using namespace mlir::LLVM;
@@ -124,25 +121,20 @@ MlirAttribute mlirLLVMDIExpressionElemAttrGet(MlirContext ctx,
124121
unsigned int opcode,
125122
intptr_t nArguments,
126123
uint64_t const *arguments) {
127-
auto list = mlir::ArrayRef<uint64_t>(arguments, nArguments);
124+
auto list = ArrayRef<uint64_t>(arguments, nArguments);
128125
return wrap(DIExpressionElemAttr::get(unwrap(ctx), opcode, list));
129126
}
130127

131128
MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations,
132129
MlirAttribute const *operations) {
133130
SmallVector<Attribute, 2> attrStorage;
134131
attrStorage.reserve(nOperations);
135-
mlir::ArrayRef<Attribute> tempList =
136-
unwrapList(nOperations, operations, attrStorage);
137132

138-
SmallVector<DIExpressionElemAttr, 2> diExpressionElemStorage;
139-
diExpressionElemStorage.reserve(tempList.size());
140-
141-
for (auto attr : tempList) {
142-
diExpressionElemStorage.push_back(attr.cast<DIExpressionElemAttr>());
143-
}
144-
145-
return wrap(DIExpressionAttr::get(unwrap(ctx), diExpressionElemStorage));
133+
return wrap(DIExpressionAttr::get(
134+
unwrap(ctx),
135+
llvm::map_to_vector(
136+
unwrapList(nOperations, operations, attrStorage),
137+
[](Attribute a) { return a.cast<DIExpressionElemAttr>(); })));
146138
}
147139

148140
MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx) {
@@ -165,7 +157,7 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
165157
SmallVector<Attribute, 2> elementsStorage;
166158
elementsStorage.reserve(nElements);
167159

168-
mlir::ArrayRef<Attribute> tempList =
160+
ArrayRef<Attribute> tempList =
169161
unwrapList(nElements, elements, elementsStorage);
170162

171163
SmallVector<DINodeAttr, 2> diNodesStorage;
@@ -269,17 +261,11 @@ MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
269261
MlirAttribute const *types) {
270262
SmallVector<Attribute, 2> attrStorage;
271263
attrStorage.reserve(nTypes);
272-
mlir::ArrayRef<Attribute> tempList = unwrapList(nTypes, types, attrStorage);
273-
274-
SmallVector<DITypeAttr, 2> diTypesStorage;
275-
diTypesStorage.reserve(tempList.size());
276-
277-
for (auto attr : tempList) {
278-
diTypesStorage.push_back(attr.cast<DITypeAttr>());
279-
}
280264

281-
return wrap(DISubroutineTypeAttr::get(unwrap(ctx), callingConvention,
282-
diTypesStorage));
265+
return wrap(DISubroutineTypeAttr::get(
266+
unwrap(ctx), callingConvention,
267+
llvm::map_to_vector(unwrapList(nTypes, types, attrStorage),
268+
[](Attribute a) { return a.cast<DITypeAttr>(); })));
283269
}
284270

285271
MlirAttribute mlirLLVMDISubprogramAttrGet(

0 commit comments

Comments
 (0)