Skip to content

[Passes] Report error when pass requires target machine #142550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/AtomicExpand.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AtomicExpandPass : public PassInfoMixin<AtomicExpandPass> {
const TargetMachine *TM;

public:
AtomicExpandPass(const TargetMachine *TM) : TM(TM) {}
AtomicExpandPass(const TargetMachine &TM) : TM(&TM) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class BasicBlockSectionsProfileReaderAnalysis
public:
static AnalysisKey Key;
typedef BasicBlockSectionsProfileReader Result;
BasicBlockSectionsProfileReaderAnalysis(const TargetMachine *TM) : TM(TM) {}
BasicBlockSectionsProfileReaderAnalysis(const TargetMachine &TM) : TM(&TM) {}

Result run(Function &F, FunctionAnalysisManager &AM);

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/CodeGenPrepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CodeGenPreparePass : public PassInfoMixin<CodeGenPreparePass> {
const TargetMachine *TM;

public:
CodeGenPreparePass(const TargetMachine *TM) : TM(TM) {}
CodeGenPreparePass(const TargetMachine &TM) : TM(&TM) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/ComplexDeinterleavingPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class TargetMachine;
struct ComplexDeinterleavingPass
: public PassInfoMixin<ComplexDeinterleavingPass> {
private:
TargetMachine *TM;
const TargetMachine *TM;

public:
ComplexDeinterleavingPass(TargetMachine *TM) : TM(TM) {}
ComplexDeinterleavingPass(const TargetMachine &TM) : TM(&TM) {}

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/DwarfEHPrepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DwarfEHPreparePass : public PassInfoMixin<DwarfEHPreparePass> {
const TargetMachine *TM;

public:
explicit DwarfEHPreparePass(const TargetMachine *TM_) : TM(TM_) {}
explicit DwarfEHPreparePass(const TargetMachine &TM_) : TM(&TM_) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/ExpandFp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ExpandFpPass : public PassInfoMixin<ExpandFpPass> {
const TargetMachine *TM;

public:
explicit ExpandFpPass(const TargetMachine *TM_) : TM(TM_) {}
explicit ExpandFpPass(const TargetMachine &TM_) : TM(&TM_) {}

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/ExpandLargeDivRem.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ExpandLargeDivRemPass : public PassInfoMixin<ExpandLargeDivRemPass> {
const TargetMachine *TM;

public:
explicit ExpandLargeDivRemPass(const TargetMachine *TM_) : TM(TM_) {}
explicit ExpandLargeDivRemPass(const TargetMachine &TM_) : TM(&TM_) {}

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/ExpandMemCmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExpandMemCmpPass : public PassInfoMixin<ExpandMemCmpPass> {
const TargetMachine *TM;

public:
explicit ExpandMemCmpPass(const TargetMachine *TM_) : TM(TM_) {}
explicit ExpandMemCmpPass(const TargetMachine &TM_) : TM(&TM_) {}

PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/IndirectBrExpand.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IndirectBrExpandPass : public PassInfoMixin<IndirectBrExpandPass> {
const TargetMachine *TM;

public:
IndirectBrExpandPass(const TargetMachine *TM) : TM(TM) {}
IndirectBrExpandPass(const TargetMachine &TM) : TM(&TM) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/InterleavedAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class InterleavedAccessPass : public PassInfoMixin<InterleavedAccessPass> {
const TargetMachine *TM;

public:
explicit InterleavedAccessPass(const TargetMachine *TM) : TM(TM) {}
explicit InterleavedAccessPass(const TargetMachine &TM) : TM(&TM) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/InterleavedLoadCombine.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InterleavedLoadCombinePass
const TargetMachine *TM;

public:
explicit InterleavedLoadCombinePass(const TargetMachine *TM) : TM(TM) {}
explicit InterleavedLoadCombinePass(const TargetMachine &TM) : TM(&TM) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/MachineFunctionAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MachineFunctionAnalysis
FunctionAnalysisManager::Invalidator &);
};

MachineFunctionAnalysis(const TargetMachine *TM) : TM(TM) {};
MachineFunctionAnalysis(const TargetMachine &TM) : TM(&TM) {};
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &FAM);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/SafeStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SafeStackPass : public PassInfoMixin<SafeStackPass> {
const TargetMachine *TM;

public:
explicit SafeStackPass(const TargetMachine *TM_) : TM(TM_) {}
explicit SafeStackPass(const TargetMachine &TM_) : TM(&TM_) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/SelectOptimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SelectOptimizePass : public PassInfoMixin<SelectOptimizePass> {
const TargetMachine *TM;

public:
explicit SelectOptimizePass(const TargetMachine *TM) : TM(TM) {}
explicit SelectOptimizePass(const TargetMachine &TM) : TM(&TM) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/StackProtector.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class StackProtectorPass : public PassInfoMixin<StackProtectorPass> {
const TargetMachine *TM;

public:
explicit StackProtectorPass(const TargetMachine *TM) : TM(TM) {}
explicit StackProtectorPass(const TargetMachine &TM) : TM(&TM) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/TypePromotion.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TypePromotionPass : public PassInfoMixin<TypePromotionPass> {
const TargetMachine *TM;

public:
TypePromotionPass(const TargetMachine *TM): TM(TM) { }
TypePromotionPass(const TargetMachine &TM) : TM(&TM) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

Expand Down
18 changes: 9 additions & 9 deletions llvm/include/llvm/Passes/CodeGenPassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPasses(
addPass(LowerEmuTLSPass());

addPass(PreISelIntrinsicLoweringPass(&TM));
addPass(ExpandLargeDivRemPass(&TM));
addPass(ExpandFpPass(&TM));
addPass(ExpandLargeDivRemPass(TM));
addPass(ExpandFpPass(TM));

derived().addIRPasses(addPass);
derived().addCodeGenPrepare(addPass);
Expand Down Expand Up @@ -704,7 +704,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses(
// target lowering hook.
if (!Opt.DisableMergeICmps)
addPass(MergeICmpsPass());
addPass(ExpandMemCmpPass(&TM));
addPass(ExpandMemCmpPass(TM));
}

// Run GC lowering passes for builtin collectors
Expand Down Expand Up @@ -742,7 +742,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses(

// Convert conditional moves to conditional jumps when profitable.
if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableSelectOptimize)
addPass(SelectOptimizePass(&TM));
addPass(SelectOptimizePass(TM));

if (Opt.EnableGlobalMergeFunc)
addPass(GlobalMergeFuncPass());
Expand All @@ -769,14 +769,14 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addPassesToHandleExceptions(
case ExceptionHandling::ARM:
case ExceptionHandling::AIX:
case ExceptionHandling::ZOS:
addPass(DwarfEHPreparePass(&TM));
addPass(DwarfEHPreparePass(TM));
break;
case ExceptionHandling::WinEH:
// We support using both GCC-style and MSVC-style exceptions on Windows, so
// add both preparation passes. Each pass will only actually run if it
// recognizes the personality function.
addPass(WinEHPreparePass());
addPass(DwarfEHPreparePass(&TM));
addPass(DwarfEHPreparePass(TM));
break;
case ExceptionHandling::Wasm:
// Wasm EH uses Windows EH instructions, but it does not need to demote PHIs
Expand All @@ -801,7 +801,7 @@ template <typename Derived, typename TargetMachineT>
void CodeGenPassBuilder<Derived, TargetMachineT>::addCodeGenPrepare(
AddIRPass &addPass) const {
if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableCGP)
addPass(CodeGenPreparePass(&TM));
addPass(CodeGenPreparePass(TM));
// TODO: Default ctor'd RewriteSymbolPass is no-op.
// addPass(RewriteSymbolPass());
}
Expand All @@ -816,8 +816,8 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPrepare(
addPass(CallBrPreparePass());
// Add both the safe stack and the stack protection passes: each of them will
// only protect functions that have corresponding attributes.
addPass(SafeStackPass(&TM));
addPass(StackProtectorPass(&TM));
addPass(SafeStackPass(TM));
addPass(StackProtectorPass(TM));

if (Opt.PrintISelInput)
addPass(PrintFunctionPass(dbgs(),
Expand Down
36 changes: 34 additions & 2 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,14 @@ Error PassBuilder::parseModulePass(ModulePassManager &MPM,
}
#define FUNCTION_PASS(NAME, CREATE_PASS) \
if (Name == NAME) { \
if constexpr (std::is_constructible_v< \
std::remove_reference_t<decltype(CREATE_PASS)>, \
const TargetMachine &>) { \
if (!TM) \
return make_error<StringError>( \
formatv("Pass '{0}' requires TargetMachine", Name).str(), \
inconvertibleErrorCode()); \
} \
MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \
return Error::success(); \
}
Expand Down Expand Up @@ -1997,6 +2005,14 @@ Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
}
#define FUNCTION_PASS(NAME, CREATE_PASS) \
if (Name == NAME) { \
if constexpr (std::is_constructible_v< \
std::remove_reference_t<decltype(CREATE_PASS)>, \
const TargetMachine &>) { \
if (!TM) \
return make_error<StringError>( \
formatv("Pass '{0}' requires TargetMachine", Name).str(), \
inconvertibleErrorCode()); \
} \
CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS)); \
return Error::success(); \
}
Expand Down Expand Up @@ -2091,6 +2107,14 @@ Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
// Now expand the basic registered passes from the .inc file.
#define FUNCTION_PASS(NAME, CREATE_PASS) \
if (Name == NAME) { \
if constexpr (std::is_constructible_v< \
std::remove_reference_t<decltype(CREATE_PASS)>, \
const TargetMachine &>) { \
if (!TM) \
return make_error<StringError>( \
formatv("Pass '{0}' requires TargetMachine", Name).str(), \
inconvertibleErrorCode()); \
} \
FPM.addPass(CREATE_PASS); \
return Error::success(); \
}
Expand All @@ -2104,9 +2128,17 @@ Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
}
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
if (Name == "require<" NAME ">") { \
if constexpr (std::is_constructible_v< \
std::remove_reference_t<decltype(CREATE_PASS)>, \
const TargetMachine &>) { \
if (!TM) \
return make_error<StringError>( \
formatv("Pass '{0}' requires TargetMachine", Name).str(), \
inconvertibleErrorCode()); \
} \
FPM.addPass( \
RequireAnalysisPass< \
std::remove_reference_t<decltype(CREATE_PASS)>, Function>()); \
RequireAnalysisPass<std::remove_reference_t<decltype(CREATE_PASS)>, \
Function>()); \
return Error::success(); \
} \
if (Name == "invalidate<" NAME ">") { \
Expand Down
32 changes: 16 additions & 16 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ CGSCC_PASS_WITH_PARAMS(
FUNCTION_ANALYSIS("aa", AAManager())
FUNCTION_ANALYSIS("access-info", LoopAccessAnalysis())
FUNCTION_ANALYSIS("assumptions", AssumptionAnalysis())
FUNCTION_ANALYSIS("bb-sections-profile-reader", BasicBlockSectionsProfileReaderAnalysis(TM))
FUNCTION_ANALYSIS("bb-sections-profile-reader", BasicBlockSectionsProfileReaderAnalysis(*TM))
FUNCTION_ANALYSIS("block-freq", BlockFrequencyAnalysis())
FUNCTION_ANALYSIS("branch-prob", BranchProbabilityAnalysis())
FUNCTION_ANALYSIS("cycles", CycleAnalysis())
Expand All @@ -297,7 +297,7 @@ FUNCTION_ANALYSIS("domfrontier", DominanceFrontierAnalysis())
FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis())
FUNCTION_ANALYSIS("ephemerals", EphemeralValuesAnalysis())
FUNCTION_ANALYSIS("func-properties", FunctionPropertiesAnalysis())
FUNCTION_ANALYSIS("machine-function-info", MachineFunctionAnalysis(TM))
FUNCTION_ANALYSIS("machine-function-info", MachineFunctionAnalysis(*TM))
FUNCTION_ANALYSIS("gc-function", GCFunctionAnalysis())
FUNCTION_ANALYSIS("inliner-size-estimator", InlineSizeEstimatorAnalysis())
FUNCTION_ANALYSIS("last-run-tracking", LastRunTrackingAnalysis())
Expand Down Expand Up @@ -347,14 +347,14 @@ FUNCTION_PASS("alignment-from-assumptions", AlignmentFromAssumptionsPass())
FUNCTION_PASS("annotation-remarks", AnnotationRemarksPass())
FUNCTION_PASS("assume-builder", AssumeBuilderPass())
FUNCTION_PASS("assume-simplify", AssumeSimplifyPass())
FUNCTION_PASS("atomic-expand", AtomicExpandPass(TM))
FUNCTION_PASS("atomic-expand", AtomicExpandPass(*TM))
FUNCTION_PASS("bdce", BDCEPass())
FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass())
FUNCTION_PASS("callbr-prepare", CallBrPreparePass())
FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass())
FUNCTION_PASS("chr", ControlHeightReductionPass())
FUNCTION_PASS("codegenprepare", CodeGenPreparePass(TM))
FUNCTION_PASS("complex-deinterleaving", ComplexDeinterleavingPass(TM))
FUNCTION_PASS("codegenprepare", CodeGenPreparePass(*TM))
FUNCTION_PASS("complex-deinterleaving", ComplexDeinterleavingPass(*TM))
FUNCTION_PASS("consthoist", ConstantHoistingPass())
FUNCTION_PASS("constraint-elimination", ConstraintEliminationPass())
FUNCTION_PASS("coro-elide", CoroElidePass())
Expand All @@ -371,10 +371,10 @@ FUNCTION_PASS("dot-dom-only", DomOnlyPrinter())
FUNCTION_PASS("dot-post-dom", PostDomPrinter())
FUNCTION_PASS("dot-post-dom-only", PostDomOnlyPrinter())
FUNCTION_PASS("dse", DSEPass())
FUNCTION_PASS("dwarf-eh-prepare", DwarfEHPreparePass(TM))
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass(TM))
FUNCTION_PASS("expand-fp", ExpandFpPass(TM))
FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass(TM))
FUNCTION_PASS("dwarf-eh-prepare", DwarfEHPreparePass(*TM))
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass(*TM))
FUNCTION_PASS("expand-fp", ExpandFpPass(*TM))
FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass(*TM))
FUNCTION_PASS("extra-vector-passes",
ExtraFunctionPassManager<ShouldRunExtraVectorPasses>())
FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
Expand All @@ -385,15 +385,15 @@ FUNCTION_PASS("guard-widening", GuardWideningPass())
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
FUNCTION_PASS("gvn-sink", GVNSinkPass())
FUNCTION_PASS("helloworld", HelloWorldPass())
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass(TM))
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass(*TM))
FUNCTION_PASS("infer-address-spaces", InferAddressSpacesPass())
FUNCTION_PASS("infer-alignment", InferAlignmentPass())
FUNCTION_PASS("inject-tli-mappings", InjectTLIMappings())
FUNCTION_PASS("instcount", InstCountPass())
FUNCTION_PASS("instnamer", InstructionNamerPass())
FUNCTION_PASS("instsimplify", InstSimplifyPass())
FUNCTION_PASS("interleaved-access", InterleavedAccessPass(TM))
FUNCTION_PASS("interleaved-load-combine", InterleavedLoadCombinePass(TM))
FUNCTION_PASS("interleaved-access", InterleavedAccessPass(*TM))
FUNCTION_PASS("interleaved-load-combine", InterleavedLoadCombinePass(*TM))
FUNCTION_PASS("invalidate<all>", InvalidateAllAnalysesPass())
FUNCTION_PASS("irce", IRCEPass())
FUNCTION_PASS("jump-threading", JumpThreadingPass())
Expand Down Expand Up @@ -469,25 +469,25 @@ FUNCTION_PASS("print<uniformity>", UniformityInfoPrinterPass(errs()))
FUNCTION_PASS("reassociate", ReassociatePass())
FUNCTION_PASS("redundant-dbg-inst-elim", RedundantDbgInstEliminationPass())
FUNCTION_PASS("reg2mem", RegToMemPass())
FUNCTION_PASS("safe-stack", SafeStackPass(TM))
FUNCTION_PASS("safe-stack", SafeStackPass(*TM))
FUNCTION_PASS("sandbox-vectorizer", SandboxVectorizerPass())
FUNCTION_PASS("scalarize-masked-mem-intrin", ScalarizeMaskedMemIntrinPass())
FUNCTION_PASS("sccp", SCCPPass())
FUNCTION_PASS("select-optimize", SelectOptimizePass(TM))
FUNCTION_PASS("select-optimize", SelectOptimizePass(*TM))
FUNCTION_PASS("separate-const-offset-from-gep",
SeparateConstOffsetFromGEPPass())
FUNCTION_PASS("sink", SinkingPass())
FUNCTION_PASS("sjlj-eh-prepare", SjLjEHPreparePass(TM))
FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
FUNCTION_PASS("slsr", StraightLineStrengthReducePass())
FUNCTION_PASS("stack-protector", StackProtectorPass(TM))
FUNCTION_PASS("stack-protector", StackProtectorPass(*TM))
FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
FUNCTION_PASS("tailcallelim", TailCallElimPass())
FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
FUNCTION_PASS("trigger-crash-function", TriggerCrashFunctionPass())
FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
FUNCTION_PASS("tsan", ThreadSanitizerPass())
FUNCTION_PASS("typepromotion", TypePromotionPass(TM))
FUNCTION_PASS("typepromotion", TypePromotionPass(*TM))
FUNCTION_PASS("unify-loop-exits", UnifyLoopExitsPass())
FUNCTION_PASS("vector-combine", VectorCombinePass())
FUNCTION_PASS("verify", VerifierPass())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ void AMDGPUCodeGenPassBuilder::addIRPasses(AddIRPass &addPass) const {
(AMDGPUAtomicOptimizerStrategy != ScanOptions::None))
addPass(AMDGPUAtomicOptimizerPass(TM, AMDGPUAtomicOptimizerStrategy));

addPass(AtomicExpandPass(&TM));
addPass(AtomicExpandPass(TM));

if (TM.getOptLevel() > CodeGenOptLevel::None) {
addPass(AMDGPUPromoteAllocaPass(TM));
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/tools/opt/no-target-machine.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; Report error when pass requires TargetMachine.
; RUN: not opt -passes=codegenprepare -disable-output %s 2>&1 | FileCheck %s
define void @foo() { ret void }
; CHECK: Pass 'codegenprepare' requires TargetMachine