================
@@ -402,6 +402,28 @@ static LogicalResult verifyProducedBy(Operation *op, Value
operand,
return success();
}
+std::optional<llvm::Triple> cir::getTripleFromModule(
+ mlir::ModuleOp mod,
+ llvm::function_ref<mlir::InFlightDiagnostic()> emitDiag) {
+ if (!mod->hasAttr(cir::CIRDialect::getTripleAttrName())) {
+ if (emitDiag)
+ emitDiag() << "module is missing " <<
cir::CIRDialect::getTripleAttrName()
+ << " attribute";
+ return std::nullopt;
+ }
+
+ auto tripleAttr = mod->getAttrOfType<mlir::StringAttr>(
+ cir::CIRDialect::getTripleAttrName());
+ if (!tripleAttr) {
+ if (emitDiag)
+ emitDiag() << "expected a string from module attribute "
+ << cir::CIRDialect::getTripleAttrName();
+ return std::nullopt;
+ }
+
+ return llvm::Triple{tripleAttr.getValue()};
----------------
ianayl wrote:
I'm thinking it might be prudent to also confirm whether or not the triple
defined here is actually valid. But I'm mulling over:
- How far should I go with triple checking in CIR? At what point is it CIR's
responsibility, and at what point is it not?
- Should I only check arch, or should I be concerned with validating every
other field too? (and would this be overkill?)
- Should users be able to pass e.g. `unknown-unknown-unknown` into `cir-opt`
for testing purposes?
- I noticed most places that try to query `cir.triple` don't actually check
triple types, i.e. `-cir-to-llvm` hands `cir.triple` directly to LLVM without
validation, but then LLVM crashes if the triple provided isn't valid. Should
CIR bear the responsibility of checking this triple, or should it actually go
in LLVM instead?
https://github.com/llvm/llvm-project/pull/230003
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits