Files
Reid Kleckner afe76c5beb [Options] Add IR-unit helpers for per-context library options (#234761)
Add free functions alongside the private option structures so callers
can use getScalarOptions(L) instead of spelling out the loop-header and
context access chain.

This should make option checks much more readable:
```
if (getCodeGenOptions(MF).CGOpt)
if (getScalarOptions(Fn).ScalarSetting)
```

Before we'd do:

```
if (MF.getFunction().getContext().getLibraryOptions().get<CodeGenOptions>().CGOpt)
```

The MachineFunction CGOpt lookup is prevalent in our downstream with
loads of tunables, but I found many opportunities to improve readability
in the upstream Transform libraries.

LLM-aided
2026-10-23 15:23:39 -07:00

32 lines
923 B
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_CODEGEN_CODEGENOPTIONS_H
#define LLVM_LIB_CODEGEN_CODEGENOPTIONS_H
#include "llvm/Target/TargetOptions.h"
#include <cstdint>
#include <optional>
#define OPTIONS_STRUCT_DECL
#include "CodeGenOptions.inc"
namespace llvm {
class LLVMContext;
class MachineFunction;
class Module;
const CodeGenOptions &getCodeGenOptions(const LLVMContext &C);
const CodeGenOptions &getCodeGenOptions(const Module &M);
const CodeGenOptions &getCodeGenOptions(const MachineFunction &MF);
} // namespace llvm
#endif // LLVM_LIB_CODEGEN_CODEGENOPTIONS_H