Skip to content
Merged
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/docs/WritingAnLLVMPass.rst
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ default optimization pipelines, e.g. (the output has been trimmed):
ModulePass Manager
Pre-ISel Intrinsic Lowering
FunctionPass Manager
Expand fp
Expand IR instructions
Expand Atomic instructions
SVE intrinsics optimizations
FunctionPass Manager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===- ExpandFp.h -----------------------------------*- C++ -*-===//
//===- ExpandIRInsts.h -----------------------------------*- 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_CODEGEN_EXPANDFP_H
#define LLVM_CODEGEN_EXPANDFP_H
#ifndef LLVM_CODEGEN_EXPANDIRINSTS_H
#define LLVM_CODEGEN_EXPANDIRINSTS_H

#include "llvm/IR/PassManager.h"
#include "llvm/Support/CodeGen.h"
Expand All @@ -16,13 +16,13 @@ namespace llvm {

class TargetMachine;

class ExpandFpPass : public PassInfoMixin<ExpandFpPass> {
class ExpandIRInstsPass : public PassInfoMixin<ExpandIRInstsPass> {
private:
const TargetMachine *TM;
CodeGenOptLevel OptLevel;

public:
explicit ExpandFpPass(const TargetMachine &TM, CodeGenOptLevel OptLevel);
explicit ExpandIRInstsPass(const TargetMachine &TM, CodeGenOptLevel OptLevel);

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
static bool isRequired() { return true; }
Expand All @@ -32,4 +32,4 @@ class ExpandFpPass : public PassInfoMixin<ExpandFpPass> {

} // end namespace llvm

#endif // LLVM_CODEGEN_EXPANDFP_H
#endif // LLVM_CODEGEN_EXPANDIRINSTS_H
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ LLVM_ABI FunctionPass *createExpandReductionsPass();
LLVM_ABI FunctionPass *createReplaceWithVeclibLegacyPass();

// Expands large div/rem instructions.
LLVM_ABI FunctionPass *createExpandFpPass();
LLVM_ABI FunctionPass *createExpandIRInstsPass();

// This pass expands memcmp() to load/stores.
LLVM_ABI FunctionPass *createExpandMemCmpLegacyPass();
Expand All @@ -565,7 +565,7 @@ LLVM_ABI FunctionPass *createCFIFixup();
LLVM_ABI FunctionPass *createCFIInstrInserter();

// Expands floating point instructions.
FunctionPass *createExpandFpPass(CodeGenOptLevel);
FunctionPass *createExpandIRInstsPass(CodeGenOptLevel);

/// Creates CFGuard longjmp target identification pass.
/// \see CFGuardLongjmp.cpp
Expand Down
12 changes: 6 additions & 6 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -2219,13 +2219,13 @@ class LLVM_ABI TargetLoweringBase {
}

/// Returns the size in bits of the maximum div/rem the backend supports.
/// Larger operations will be expanded by ExpandFp.
/// Larger operations will be expanded by ExpandIRInsts.
unsigned getMaxDivRemBitWidthSupported() const {
return MaxDivRemBitWidthSupported;
}

/// Returns the size in bits of the maximum fp to/from int conversion the
/// backend supports. Larger operations will be expanded by ExpandFp.
/// backend supports. Larger operations will be expanded by ExpandIRInsts.
unsigned getMaxLargeFPConvertBitWidthSupported() const {
return MaxLargeFPConvertBitWidthSupported;
}
Expand Down Expand Up @@ -2885,13 +2885,13 @@ class LLVM_ABI TargetLoweringBase {
}

/// Set the size in bits of the maximum div/rem the backend supports.
/// Larger operations will be expanded by ExpandFp.
/// Larger operations will be expanded by ExpandIRInsts.
void setMaxDivRemBitWidthSupported(unsigned SizeInBits) {
MaxDivRemBitWidthSupported = SizeInBits;
}

/// Set the size in bits of the maximum fp to/from int conversion the backend
/// supports. Larger operations will be expanded by ExpandFp.
/// supports. Larger operations will be expanded by ExpandIRInsts.
void setMaxLargeFPConvertBitWidthSupported(unsigned SizeInBits) {
MaxLargeFPConvertBitWidthSupported = SizeInBits;
}
Expand Down Expand Up @@ -3742,12 +3742,12 @@ class LLVM_ABI TargetLoweringBase {
unsigned MaxAtomicSizeInBitsSupported;

/// Size in bits of the maximum div/rem size the backend supports.
/// Larger operations will be expanded by ExpandFp.
/// Larger operations will be expanded by ExpandIRInsts.
unsigned MaxDivRemBitWidthSupported;

/// Size in bits of the maximum fp to/from int conversion size the
/// backend supports. Larger operations will be expanded by
/// ExpandFp.
/// ExpandIRInsts.
unsigned MaxLargeFPConvertBitWidthSupported;

/// Size in bits of the minimum cmpxchg or ll/sc operation the
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ LLVM_ABI void initializeEarlyMachineLICMPass(PassRegistry &);
LLVM_ABI void initializeEarlyTailDuplicateLegacyPass(PassRegistry &);
LLVM_ABI void initializeEdgeBundlesWrapperLegacyPass(PassRegistry &);
LLVM_ABI void initializeEHContGuardTargetsPass(PassRegistry &);
LLVM_ABI void initializeExpandFpLegacyPassPass(PassRegistry &);
LLVM_ABI void initializeExpandIRInstsLegacyPassPass(PassRegistry &);
LLVM_ABI void initializeExpandMemCmpLegacyPassPass(PassRegistry &);
LLVM_ABI void initializeExpandPostRALegacyPass(PassRegistry &);
LLVM_ABI void initializeExpandReductionsPass(PassRegistry &);
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Passes/CodeGenPassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "llvm/CodeGen/DetectDeadLanes.h"
#include "llvm/CodeGen/DwarfEHPrepare.h"
#include "llvm/CodeGen/EarlyIfConversion.h"
#include "llvm/CodeGen/ExpandFp.h"
#include "llvm/CodeGen/ExpandIRInsts.h"
#include "llvm/CodeGen/ExpandMemCmp.h"
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
#include "llvm/CodeGen/ExpandReductions.h"
Expand Down Expand Up @@ -677,7 +677,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPasses(
addModulePass(LowerEmuTLSPass(), PMW);

addModulePass(PreISelIntrinsicLoweringPass(&TM), PMW);
addFunctionPass(ExpandFpPass(TM, getOptLevel()), PMW);
addFunctionPass(ExpandIRInstsPass(TM, getOptLevel()), PMW);

derived().addIRPasses(PMW);
derived().addCodeGenPrepare(PMW);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ add_llvm_component_library(LLVMCodeGen
EdgeBundles.cpp
EHContGuardTargets.cpp
ExecutionDomainFix.cpp
ExpandFp.cpp
ExpandIRInsts.cpp
ExpandMemCmp.cpp
ExpandPostRAPseudos.cpp
ExpandReductions.cpp
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeEarlyIfPredicatorPass(Registry);
initializeEarlyMachineLICMPass(Registry);
initializeEarlyTailDuplicateLegacyPass(Registry);
initializeExpandFpLegacyPassPass(Registry);
initializeExpandIRInstsLegacyPassPass(Registry);
initializeExpandMemCmpLegacyPassPass(Registry);
initializeExpandPostRALegacyPass(Registry);
initializeFEntryInserterLegacyPass(Registry);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
//===--- ExpandFp.cpp - Expand fp instructions ----------------------------===//
//===--- ExpandIRInsts.cpp - Expand IR instructions -----------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// This pass expands certain floating point instructions at the IR level.
// This pass expands certain instructions at the IR level.
//
// It expands ‘fptoui .. to’, ‘fptosi .. to’, ‘uitofp .. to’, ‘sitofp
// The following expansions are implemented:
// - Expansion of ‘fptoui .. to’, ‘fptosi .. to’, ‘uitofp .. to’, ‘sitofp
// .. to’ instructions with a bitwidth above a threshold. This is
// useful for targets like x86_64 that cannot lower fp convertions
// with more than 128 bits.
//
// This pass also expands div/rem instructions with a bitwidth above a
// threshold into a call to auto-generated functions. This is useful
// for targets like x86_64 that cannot lower divisions with more than
// 128 bits or targets like x86_32 that cannot lower divisions with
// more than 64 bits.
// - Expansion of ‘frem‘ for types MVT::f16, MVT::f32, and MVT::f64 for
// targets which use "Expand" as the legalization action for the
// corresponding type.
//
// - Expansion of ‘udiv‘, ‘sdiv‘, ‘urem‘, and ‘srem‘ instructions with
// a bitwidth above a threshold into a call to auto-generated
// functions. This is useful for targets like x86_64 that cannot
// lower divisions with more than 128 bits or targets like x86_32 that
// cannot lower divisions with more than 64 bits.
//
// Instructions with vector types are scalarized first if their scalar
// types can be expanded. Scalable vector types are not supported.
//===----------------------------------------------------------------------===//

#include "llvm/CodeGen/ExpandFp.h"
#include "llvm/CodeGen/ExpandIRInsts.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/GlobalsModRef.h"
Expand All @@ -45,7 +52,7 @@
#include <llvm/Support/Casting.h>
#include <optional>

#define DEBUG_TYPE "expand-fp"
#define DEBUG_TYPE "expand-ir-insts"

using namespace llvm;

Expand Down Expand Up @@ -1125,18 +1132,18 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
}

namespace {
class ExpandFpLegacyPass : public FunctionPass {
class ExpandIRInstsLegacyPass : public FunctionPass {
CodeGenOptLevel OptLevel;

public:
static char ID;

ExpandFpLegacyPass(CodeGenOptLevel OptLevel)
ExpandIRInstsLegacyPass(CodeGenOptLevel OptLevel)
: FunctionPass(ID), OptLevel(OptLevel) {
initializeExpandFpLegacyPassPass(*PassRegistry::getPassRegistry());
initializeExpandIRInstsLegacyPassPass(*PassRegistry::getPassRegistry());
}

ExpandFpLegacyPass() : ExpandFpLegacyPass(CodeGenOptLevel::None) {};
ExpandIRInstsLegacyPass() : ExpandIRInstsLegacyPass(CodeGenOptLevel::None) {};

bool runOnFunction(Function &F) override {
auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
Expand Down Expand Up @@ -1165,19 +1172,21 @@ class ExpandFpLegacyPass : public FunctionPass {
};
} // namespace

ExpandFpPass::ExpandFpPass(const TargetMachine &TM, CodeGenOptLevel OptLevel)
ExpandIRInstsPass::ExpandIRInstsPass(const TargetMachine &TM,
CodeGenOptLevel OptLevel)
: TM(&TM), OptLevel(OptLevel) {}

void ExpandFpPass::printPipeline(
void ExpandIRInstsPass::printPipeline(
raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
static_cast<PassInfoMixin<ExpandFpPass> *>(this)->printPipeline(
static_cast<PassInfoMixin<ExpandIRInstsPass> *>(this)->printPipeline(
OS, MapClassName2PassName);
OS << '<';
OS << "O" << (int)OptLevel;
OS << '>';
}

PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) {
PreservedAnalyses ExpandIRInstsPass::run(Function &F,
FunctionAnalysisManager &FAM) {
const TargetSubtargetInfo *STI = TM->getSubtargetImpl(F);
auto &TLI = *STI->getTargetLowering();
AssumptionCache *AC = nullptr;
Expand All @@ -1202,12 +1211,13 @@ PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) {
: PreservedAnalyses::all();
}

char ExpandFpLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(ExpandFpLegacyPass, "expand-fp",
char ExpandIRInstsLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(ExpandIRInstsLegacyPass, "expand-ir-insts",
"Expand certain fp instructions", false, false)
INITIALIZE_PASS_DEPENDENCY(LibcallLoweringInfoWrapper)
INITIALIZE_PASS_END(ExpandFpLegacyPass, "expand-fp", "Expand fp", false, false)
INITIALIZE_PASS_END(ExpandIRInstsLegacyPass, "expand-ir-insts",
"Expand IR instructions", false, false)

FunctionPass *llvm::createExpandFpPass(CodeGenOptLevel OptLevel) {
return new ExpandFpLegacyPass(OptLevel);
FunctionPass *llvm::createExpandIRInstsPass(CodeGenOptLevel OptLevel) {
return new ExpandIRInstsLegacyPass(OptLevel);
}
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/TargetPassConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ bool TargetPassConfig::addISelPasses() {

PM->add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
addPass(createPreISelIntrinsicLoweringPass());
addPass(createExpandFpPass(getOptLevel()));
addPass(createExpandIRInstsPass(getOptLevel()));
addIRPasses();
addCodeGenPrepare();
addPassesToHandleExceptions();
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
#include "llvm/CodeGen/DwarfEHPrepare.h"
#include "llvm/CodeGen/EarlyIfConversion.h"
#include "llvm/CodeGen/EdgeBundles.h"
#include "llvm/CodeGen/ExpandFp.h"
#include "llvm/CodeGen/ExpandIRInsts.h"
#include "llvm/CodeGen/ExpandMemCmp.h"
#include "llvm/CodeGen/ExpandPostRAPseudos.h"
#include "llvm/CodeGen/ExpandReductions.h"
Expand Down Expand Up @@ -1632,7 +1632,7 @@ parseBoundsCheckingOptions(StringRef Params) {
return Options;
}

Expected<CodeGenOptLevel> parseExpandFpOptions(StringRef Param) {
Expected<CodeGenOptLevel> parseExpandIRInstsOptions(StringRef Param) {
if (Param.empty())
return CodeGenOptLevel::None;

Expand All @@ -1641,13 +1641,13 @@ Expected<CodeGenOptLevel> parseExpandFpOptions(StringRef Param) {

uint8_t N;
if (!Prefix.empty() || Digit.getAsInteger(10, N))
return createStringError("invalid expand-fp pass parameter '%s'",
return createStringError("invalid expand-ir-insts pass parameter '%s'",
Param.str().c_str());

std::optional<CodeGenOptLevel> Level = CodeGenOpt::getLevel(N);
if (!Level.has_value())
return createStringError(
"invalid optimization level for expand-fp pass: %s",
"invalid optimization level for expand-ir-insts pass: %s",
Digit.str().c_str());

return *Level;
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,11 @@ FUNCTION_PASS_WITH_PARAMS(
parseBoundsCheckingOptions,
"trap;rt;rt-abort;min-rt;min-rt-abort;merge;guard=N")
FUNCTION_PASS_WITH_PARAMS(
"expand-fp", "ExpandFpPass",
"expand-ir-insts", "ExpandIRInstsPass",
[TM = TM](CodeGenOptLevel OL) {
return ExpandFpPass(*TM, OL);
return ExpandIRInstsPass(*TM, OL);
},
parseExpandFpOptions, "O0;O1;O2;O3")
parseExpandIRInstsOptions, "O0;O1;O2;O3")

#undef FUNCTION_PASS_WITH_PARAMS

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AArch64/O0-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
; CHECK-NEXT: ModulePass Manager
; CHECK-NEXT: Pre-ISel Intrinsic Lowering
; CHECK-NEXT: FunctionPass Manager
; CHECK-NEXT: Expand fp
; CHECK-NEXT: Expand IR instructions
; CHECK-NEXT: Expand Atomic instructions
; CHECK-NEXT: Module Verifier
; CHECK-NEXT: Lower Garbage Collection Instructions
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AArch64/O3-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
; CHECK-NEXT: ModulePass Manager
; CHECK-NEXT: Pre-ISel Intrinsic Lowering
; CHECK-NEXT: FunctionPass Manager
; CHECK-NEXT: Expand fp
; CHECK-NEXT: Expand IR instructions
; CHECK-NEXT: Expand Atomic instructions
; CHECK-NEXT: SVE intrinsics optimizations
; CHECK-NEXT: FunctionPass Manager
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/AMDGPU/dagcombine-select.ll
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ define amdgpu_kernel void @fdiv_constant_sel_constants(ptr addrspace(1) %p, i1 %
ret void
}

; ExpandFp now expands frem before it reaches dagcombine.
; TODO Implement this optimization in/before ExpandFP
; ExpandIRInsts now expands frem before it reaches dagcombine.
; TODO Implement this optimization in/before ExpandIRInsts?
define amdgpu_kernel void @frem_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
; GFX9-LABEL: frem_constant_sel_constants:
; GFX9: ; %bb.0:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AMDGPU/itofp.i128.bf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; RUN: llc -global-isel=0 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,SDAG %s
; RUN: not --crash llc -global-isel=1 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 < %s 2>&1 | FileCheck -check-prefix=GISEL %s

; FIXME: GISEL can't handle the "fptrunc float to bfloat" that expand-fp emits.
; FIXME: GISEL can't handle the "fptrunc float to bfloat" that expand-ir-insts emits.

; GISEL: unable to translate instruction: fptrunc

Expand Down
Loading
Loading