[clang] [llvm] CodeGen, IR: Add target-{cpu,features} attributes to functions created via createWithDefaultAttr(). (PR #96721)

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 25 19:28:11 PDT 2024


================
@@ -327,6 +327,26 @@ class LLVMContext {
   [[deprecated("Always returns false")]]
   bool supportsTypedPointers() const;
 
+  /// Get the current "default" target CPU (target-cpu function attribute). The
+  /// intent is that compiler frontends will set this to a value that reflects
+  /// the attribute that a function would get "by default" without any specific
+  /// function attributes, and compiler passes will attach the attribute to
+  /// newly created functions that are not associated with a particular
+  /// function, such as global initializers. Function::createWithDefaultAttr()
+  /// will create functions with this attribute. This function should only be
+  /// called by passes that run at compile time and not by the backend or LTO
+  /// passes.
+  StringRef getDefaultTargetCPU();
+
+  /// See getDefaultTargetCPU().
+  void setDefaultTargetCPU(StringRef CPU);
+
+  /// Similar to getDefaultTargetCPU() but for default target-features instead.
+  StringRef getDefaultTargetFeatures();
+
+  /// See getDefaultTargetFeatures().
+  void setDefaultTargetFeatures(StringRef Features);
+
----------------
MaskRay wrote:

I agree with your analysis about "no serialization". I think we may have a lot of getters/setters.

Perhaps make a pair of getter/setter share the same comment so that it will look conciser?

```
// xxx
StringRef getDefaultTargetFeatures();
void setDefaultTargetFeatures(StringRef Features);

// yyy
StringRef getDefaultTargetFeatures();
void setDefaultTargetFeatures(StringRef Features);
```

https://github.com/llvm/llvm-project/pull/96721


More information about the cfe-commits mailing list