Skip to content
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

Remove the rest if the #if LLVM_VERSION_MAJOR checks #171

Merged
merged 2 commits into from
Jul 19, 2023
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
15 changes: 0 additions & 15 deletions lib/Target/CBackend/CTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,18 @@
#include "CTargetMachine.h"
#include "CBackend.h"
#include "llvm/CodeGen/TargetPassConfig.h"

#if LLVM_VERSION_MAJOR >= 7
#include "llvm/Transforms/Utils.h"
#endif

namespace llvm {

bool CTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
raw_pwrite_stream &Out,
#if LLVM_VERSION_MAJOR >= 7
raw_pwrite_stream *DwoOut,
#endif
CodeGenFileType FileType,
bool DisableVerify,
#if LLVM_VERSION_MAJOR >= 10
MachineModuleInfoWrapperPass *MMI) {
#else
MachineModuleInfo *MMI) {
#endif

#if LLVM_VERSION_MAJOR >= 10
if (FileType != CodeGenFileType::CGFT_AssemblyFile)
#else
if (FileType != TargetMachine::CGFT_AssemblyFile)
#endif
return true;

PM.add(new TargetPassConfig(*this, PM));
Expand All @@ -53,10 +40,8 @@ bool CTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
// Lower atomic operations to libcalls
PM.add(createAtomicExpandPass());

#if LLVM_VERSION_MAJOR >= 16
// Lower vector operations into shuffle sequences
PM.add(createExpandReductionsPass());
#endif

PM.add(new llvm_cbe::CWriter(Out));
return false;
Expand Down
65 changes: 11 additions & 54 deletions lib/Target/CBackend/CTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,13 @@ class CTargetLowering : public TargetLowering {

class CTargetSubtargetInfo : public TargetSubtargetInfo {
public:
#if LLVM_VERSION_MAJOR >= 12
CTargetSubtargetInfo(const TargetMachine &TM, const Triple &TT, StringRef CPU,
StringRef TuneCPU, StringRef FS)
#else
CTargetSubtargetInfo(const TargetMachine &TM, const Triple &TT, StringRef CPU,
StringRef FS)
#endif
#if LLVM_VERSION_MAJOR >= 9
#if LLVM_VERSION_MAJOR >= 12
: TargetSubtargetInfo(TT, CPU, TuneCPU, FS,
ArrayRef<SubtargetFeatureKV>(),
ArrayRef<SubtargetSubTypeKV>(), nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr),
#else
: TargetSubtargetInfo(TT, CPU, FS, ArrayRef<SubtargetFeatureKV>(),
ArrayRef<SubtargetSubTypeKV>(), nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr),
#endif
#else
: TargetSubtargetInfo(TT, CPU, FS, ArrayRef<SubtargetFeatureKV>(),
ArrayRef<SubtargetFeatureKV>(), nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr),
#endif
Lowering(TM) {
}
Lowering(TM) {}
bool enableAtomicExpand() const override;
const TargetLowering *getTargetLowering() const override;
const CTargetLowering Lowering;
Expand All @@ -63,46 +45,21 @@ class CTargetSubtargetInfo : public TargetSubtargetInfo {
class CTargetMachine : public LLVMTargetMachine {
public:
CTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
const TargetOptions &Options,
#if LLVM_VERSION_MAJOR >= 16
std::optional<Reloc::Model> RM,
std::optional<CodeModel::Model> CM,
#else
llvm
: Optional<Reloc::Model> RM, llvm
: Optional<CodeModel::Model> CM,
#endif
CodeGenOpt::Level OL, bool /*JIT*/)
const TargetOptions &Options, std::optional<Reloc::Model> RM,
std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
bool /*JIT*/)
: LLVMTargetMachine(T, "", TT, CPU, FS, Options,
#if LLVM_VERSION_MAJOR >= 16
RM.value_or(Reloc::Static),
CM.value_or(CodeModel::Small),
#else
RM.hasValue() ? RM.getValue() : Reloc::Static,
CM.hasValue() ? CM.getValue() : CodeModel::Small,
#endif
OL),
#if LLVM_VERSION_MAJOR >= 12
SubtargetInfo(*this, TT, CPU, "", FS) {
}
#else
SubtargetInfo(*this, TT, CPU, FS) {
}
#endif
CM.value_or(CodeModel::Small), OL),
SubtargetInfo(*this, TT, CPU, "", FS) {}

/// Add passes to the specified pass manager to get the specified file
/// emitted. Typically this will involve several steps of code generation.
bool addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
#if LLVM_VERSION_MAJOR >= 7
raw_pwrite_stream *DwoOut,
#endif
CodeGenFileType FileType, bool DisableVerify = true,
#if LLVM_VERSION_MAJOR >= 10
MachineModuleInfoWrapperPass *MMI = nullptr
#else
MachineModuleInfo *MMI = nullptr
#endif
) override;
bool
addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
bool DisableVerify = true,
MachineModuleInfoWrapperPass *MMI = nullptr) override;

// TargetMachine interface
const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override;
Expand Down
5 changes: 1 addition & 4 deletions lib/Target/CBackend/TargetInfo/CBackendTargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

#include "../CTargetMachine.h"
#include "llvm/IR/Module.h"
#if LLVM_VERSION_MAJOR >= 16
#include "llvm/MC/TargetRegistry.h"
#else
#include "llvm/Support/TargetRegistry.h"
#endif

using namespace llvm;

Target llvm::TheCBackendTarget;
Expand Down
11 changes: 1 addition & 10 deletions lib/Target/CBackend/TopologicalSorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@ TopologicalSorter::TopologicalSorter(int Size) {
Result.reserve(Size);
}

#if LLVM_VERSION_MAJOR >= 16
std::optional<std::vector<int>>
#else
llvm::Optional<std::vector<int>>
#endif
TopologicalSorter::sort() {
std::optional<std::vector<int>> TopologicalSorter::sort() {
for (int I = 0; I < Size; ++I) {
if (visit(I)) {
#if LLVM_VERSION_MAJOR >= 16
return std::nullopt;
#else
return llvm::None;
#endif
}
}
return Result;
Expand Down
8 changes: 0 additions & 8 deletions lib/Target/CBackend/TopologicalSorter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#define TOPOLOGICALSORTER_H

#include <llvm/Config/llvm-config.h>
#if LLVM_VERSION_MAJOR >= 16
#include <optional>
#else
#include <llvm/ADT/Optional.h>
#endif
#include <vector>

namespace llvm_cbe {
Expand All @@ -40,11 +36,7 @@ class TopologicalSorter {
explicit TopologicalSorter(int Size);

void addEdge(int Start, int End);
#if LLVM_VERSION_MAJOR >= 16
std::optional<std::vector<int>> sort(); // Returns None if there are cycles
#else
llvm::Optional<std::vector<int>> sort(); // Returns None if there are cycles
#endif
};

} // namespace llvm_cbe
Expand Down
Loading