Skip to content

Commit 1d7266c

Browse files
committed
Another round of review
1 parent 9073ddb commit 1d7266c

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,32 +1078,35 @@ ModuleImport::convertGlobalCtorsAndDtors(llvm::GlobalVariable *globalVar) {
10781078
if (!knownInit)
10791079
return failure();
10801080

1081+
// ConstantAggregateZero does not engage with the operand initialization
1082+
// in the loop that follows - there should be no operands. This implies
1083+
// empty ctor/dtor lists.
1084+
if (auto *caz = dyn_cast<llvm::ConstantAggregateZero>(initializer)) {
1085+
if (caz->getElementCount().getFixedValue() != 0)
1086+
return failure();
1087+
}
1088+
10811089
SmallVector<Attribute> funcs;
10821090
SmallVector<int32_t> priorities;
1083-
if (isa<llvm::ConstantArray>(initializer)) {
1084-
for (llvm::Value *operand : initializer->operands()) {
1085-
auto *aggregate = dyn_cast<llvm::ConstantAggregate>(operand);
1086-
if (!aggregate || aggregate->getNumOperands() != 3)
1087-
return failure();
1091+
for (llvm::Value *operand : initializer->operands()) {
1092+
auto *aggregate = dyn_cast<llvm::ConstantAggregate>(operand);
1093+
if (!aggregate || aggregate->getNumOperands() != 3)
1094+
return failure();
10881095

1089-
auto *priority = dyn_cast<llvm::ConstantInt>(aggregate->getOperand(0));
1090-
auto *func = dyn_cast<llvm::Function>(aggregate->getOperand(1));
1091-
auto *data = dyn_cast<llvm::Constant>(aggregate->getOperand(2));
1092-
if (!priority || !func || !data)
1093-
return failure();
1096+
auto *priority = dyn_cast<llvm::ConstantInt>(aggregate->getOperand(0));
1097+
auto *func = dyn_cast<llvm::Function>(aggregate->getOperand(1));
1098+
auto *data = dyn_cast<llvm::Constant>(aggregate->getOperand(2));
1099+
if (!priority || !func || !data)
1100+
return failure();
10941101

1095-
// GlobalCtorsOps and GlobalDtorsOps do not support non-null data fields.
1096-
if (!data->isNullValue())
1097-
return failure();
1102+
// GlobalCtorsOps and GlobalDtorsOps do not support non-null data fields.
1103+
if (!data->isNullValue())
1104+
return failure();
10981105

1099-
funcs.push_back(FlatSymbolRefAttr::get(context, func->getName()));
1100-
priorities.push_back(priority->getValue().getZExtValue());
1101-
}
1106+
funcs.push_back(FlatSymbolRefAttr::get(context, func->getName()));
1107+
priorities.push_back(priority->getValue().getZExtValue());
11021108
}
11031109

1104-
// Note: no action needed for ConstantAggregateZero, which implies empty
1105-
// ctor/dtor lists.
1106-
11071110
// Insert the global after the last one or at the start of the module.
11081111
OpBuilder::InsertionGuard guard = setGlobalInsertionPoint();
11091112

0 commit comments

Comments
 (0)