16 #include "llvm/MC/MCSubtargetInfo.h"
20 #define GEN_PASS_DEF_LLVMTARGETTOTARGETFEATURES
21 #include "mlir/Target/LLVMIR/Transforms/Passes.h.inc"
29 TargetToTargetFeaturesPass> {
36 if (initializeLLVMTargets)
40 LLVM::LLVMDialect::getTargetAttrName());
42 op->
emitError() <<
"no LLVM::TargetAttr attribute at key \""
43 << LLVM::LLVMDialect::getTargetAttrName() <<
"\"";
44 return signalPassFailure();
47 FailureOr<std::unique_ptr<llvm::TargetMachine>> targetMachine =
49 if (
failed(targetMachine)) {
50 op->
emitError() <<
"failed to obtain llvm::TargetMachine for "
52 return signalPassFailure();
55 llvm::MCSubtargetInfo
const *subTargetInfo =
56 (*targetMachine)->getMCSubtargetInfo();
58 const std::vector<llvm::SubtargetFeatureKV> enabledFeatures =
59 subTargetInfo->getEnabledProcessorFeatures();
61 auto plussedFeatures = llvm::to_vector(
62 llvm::map_range(enabledFeatures, [](llvm::SubtargetFeatureKV feature) {
63 return std::string(
"+") + feature.Key;
66 auto plussedFeaturesRefs = llvm::to_vector(llvm::map_range(
67 plussedFeatures, [](
auto &it) {
return StringRef(it.c_str()); }));
69 auto fullTargetFeaturesAttr =
72 auto updatedTargetAttr =
74 targetAttr.getChip(), fullTargetFeaturesAttr);
76 op->
setAttr(LLVM::LLVMDialect::getTargetAttrName(), updatedTargetAttr);
static MLIRContext * getContext(OpFoldResult val)
Operation is the basic unit of execution within MLIR.
AttrClass getAttrOfType(StringAttr name)
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
FailureOr< std::unique_ptr< llvm::TargetMachine > > getTargetMachine(mlir::LLVM::TargetAttrInterface attr)
Helper to obtain the TargetMachine specified by the properties of the TargetAttrInterface-implementin...
void initializeBackendsOnce()
Idempotent helper to register/initialize all backends that LLVM has been configured to support.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
void runOnOperation() override