Skip to content
Merged

Llvm16 #1207

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
cffea47
compiles with llvm-16 (old PM is gone so I could not run opt) (#1)
stepasite Apr 11, 2023
19c8b16
Llvm 16 (#2)
stepasite Apr 11, 2023
a01eab2
disabling old pm tests where new pm tests exist (#3)
stepasite Apr 12, 2023
0503d38
Disable old pm tests fix (#4)
stepasite Apr 12, 2023
fc9159b
fix build with llvm-16 (#5)
stepasite Apr 12, 2023
8f3573b
fix build with llvm < 16 (#6)
stepasite Apr 13, 2023
8348594
Attribute::Memory fixes (#7)
stepasite Apr 13, 2023
21bf500
curly brace out of macro (#8)
stepasite Apr 13, 2023
524bcd0
fix typo (#9)
stepasite Apr 13, 2023
f71c8bc
fix for llvm-16 (#10)
stepasite Apr 13, 2023
2eedfe3
Llvm 16 gha (#11)
stepasite Apr 14, 2023
5adc5af
llvm-16: fixing tests, wip (#12)
stepasite Apr 16, 2023
02ff4b2
resolving latest test/ll commits (#13)
stepasite Apr 17, 2023
fc91aa7
Llvm 16 tests (#14)
stepasite Apr 20, 2023
872f47f
llvm 16 tests, wip
stepasite Apr 21, 2023
55d3853
llvm tests, WIP (#15)
stepasite Apr 25, 2023
7628921
continued test fixes
wsmoses May 17, 2023
0147c1d
fixup
wsmoses May 17, 2023
2bae0bd
fix build
wsmoses May 17, 2023
633e3a3
fix
wsmoses May 17, 2023
47a046c
cleanup
wsmoses May 17, 2023
ed5ed83
fixes
wsmoses May 18, 2023
22aa8be
fix
wsmoses May 18, 2023
2866d02
fix attr
wsmoses May 18, 2023
be3face
fix format
wsmoses May 18, 2023
09adb52
fixup
wsmoses May 19, 2023
ed26ddc
fix attrs
wsmoses May 19, 2023
c79b04d
fix
wsmoses May 19, 2023
d83a999
fix
wsmoses May 19, 2023
14d9800
fix
wsmoses May 19, 2023
1529781
fix sret
wsmoses May 19, 2023
15e5b8f
fix
wsmoses May 19, 2023
87c00c0
add type analysis
wsmoses May 20, 2023
fc5b956
activity analysis
wsmoses May 20, 2023
50e703c
fix ta
wsmoses May 20, 2023
854f895
fix
wsmoses May 20, 2023
4b25494
fix
wsmoses May 20, 2023
6422fdb
fixes
wsmoses May 20, 2023
2bb4f59
more tests
wsmoses May 20, 2023
f744bfa
more fixes
wsmoses May 20, 2023
2fe53ee
297
wsmoses May 20, 2023
ebb92c2
more tests
wsmoses May 20, 2023
af19142
fix
wsmoses May 20, 2023
2de1ba7
fix
wsmoses May 20, 2023
a493813
fix
wsmoses May 21, 2023
64ebc7a
fix
wsmoses May 21, 2023
939980f
fix
wsmoses May 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
llvm: ["7", "8", "9", "10", "11", "12", "13", "14", "15"]
llvm: ["7", "8", "9", "10", "11", "12", "13", "14", "15", "16"]
build: ["Release"] # "RelWithDebInfo"
os: [ubuntu-20.04]

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/enzyme-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
llvm: ["7", "8", "9", "10", "11", "12", "13", "14", "15"]
llvm: ["7", "8", "9", "10", "11", "12", "13", "14", "15", "16"]
build: ["Release", "Debug"] # "RelWithDebInfo"
os: [ubuntu-20.04] #self-hosted]

Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
strategy:
fail-fast: false
matrix:
llvm: ["8", "9", "11", "12", "13", "14", "15"]
llvm: ["8", "9", "11", "12", "13", "14", "15", "16"]
build: ["Release", "Debug"] # "RelWithDebInfo"

timeout-minutes: 30
Expand Down
208 changes: 111 additions & 97 deletions enzyme/Enzyme/ActivityAnalysisPrinter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//===- TypeAnalysisPrinter.cpp - Printer utility pass for Type Analysis
//----===//
// ActivityAnalysisPrinter.cpp - Printer utility pass for Activity Analysis =//
//
// Enzyme Project
//
Expand All @@ -19,7 +18,7 @@
//
//===----------------------------------------------------------------------===//
//
// This file contains a utility LLVM pass for printing derived Type Analysis
// This file contains a utility LLVM pass for printing derived Activity Analysis
// results of a given function.
//
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -50,6 +49,7 @@
#include "llvm/Support/CommandLine.h"

#include "ActivityAnalysis.h"
#include "ActivityAnalysisPrinter.h"
#include "FunctionUtils.h"
#include "TypeAnalysis/TypeAnalysis.h"
#include "Utils.h"
Expand All @@ -74,117 +74,122 @@ static llvm::cl::opt<bool>
cl::Hidden, cl::desc("Whether the return is duplicated"));
namespace {

class ActivityAnalysisPrinter final : public FunctionPass {
public:
static char ID;
ActivityAnalysisPrinter() : FunctionPass(ID) {}

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<TargetLibraryInfoWrapperPass>();
}

bool runOnFunction(Function &F) override {
if (F.getName() != FunctionToAnalyze)
return /*changed*/ false;

#if LLVM_VERSION_MAJOR >= 10
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
#else
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
#endif

FnTypeInfo type_args(&F);
for (auto &a : type_args.Function->args()) {
TypeTree dt;
if (a.getType()->isFPOrFPVectorTy()) {
dt = ConcreteType(a.getType()->getScalarType());
} else if (a.getType()->isPointerTy()) {
auto et = a.getType()->getPointerElementType();
if (et->isFPOrFPVectorTy()) {
dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr);
} else if (et->isPointerTy()) {
dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr);
}
} else if (a.getType()->isIntOrIntVectorTy()) {
dt = ConcreteType(BaseType::Integer);
}
type_args.Arguments.insert(
std::pair<Argument *, TypeTree>(&a, dt.Only(-1, nullptr)));
// TODO note that here we do NOT propagate constants in type info (and
// should consider whether we should)
type_args.KnownValues.insert(
std::pair<Argument *, std::set<int64_t>>(&a, {}));
}
bool printActivityAnalysis(llvm::Function &F, TargetLibraryInfo &TLI) {
if (F.getName() != FunctionToAnalyze)
return /*changed*/ false;

FnTypeInfo type_args(&F);
for (auto &a : type_args.Function->args()) {
TypeTree dt;
if (F.getReturnType()->isFPOrFPVectorTy()) {
dt = ConcreteType(F.getReturnType()->getScalarType());
} else if (F.getReturnType()->isPointerTy()) {
auto et = F.getReturnType()->getPointerElementType();
if (a.getType()->isFPOrFPVectorTy()) {
dt = ConcreteType(a.getType()->getScalarType());
} else if (a.getType()->isPointerTy()) {
auto et = a.getType()->getPointerElementType();
if (et->isFPOrFPVectorTy()) {
dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr);
} else if (et->isPointerTy()) {
dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr);
}
} else if (F.getReturnType()->isIntOrIntVectorTy()) {
} else if (a.getType()->isIntOrIntVectorTy()) {
dt = ConcreteType(BaseType::Integer);
}
type_args.Return = dt.Only(-1, nullptr);

PreProcessCache PPC;
TypeAnalysis TA(PPC.FAM);
TypeResults TR = TA.analyzeFunction(type_args);

llvm::SmallPtrSet<llvm::Value *, 4> ConstantValues;
llvm::SmallPtrSet<llvm::Value *, 4> ActiveValues;
for (auto &a : type_args.Function->args()) {
if (InactiveArgs) {
ConstantValues.insert(&a);
} else if (a.getType()->isIntOrIntVectorTy()) {
ConstantValues.insert(&a);
} else {
ActiveValues.insert(&a);
}
type_args.Arguments.insert(
std::pair<Argument *, TypeTree>(&a, dt.Only(-1, nullptr)));
// TODO note that here we do NOT propagate constants in type info (and
// should consider whether we should)
type_args.KnownValues.insert(
std::pair<Argument *, std::set<int64_t>>(&a, {}));
}

TypeTree dt;
if (F.getReturnType()->isFPOrFPVectorTy()) {
dt = ConcreteType(F.getReturnType()->getScalarType());
} else if (F.getReturnType()->isPointerTy()) {
auto et = F.getReturnType()->getPointerElementType();
if (et->isFPOrFPVectorTy()) {
dt = TypeTree(ConcreteType(et->getScalarType())).Only(-1, nullptr);
} else if (et->isPointerTy()) {
dt = TypeTree(ConcreteType(BaseType::Pointer)).Only(-1, nullptr);
}
} else if (F.getReturnType()->isIntOrIntVectorTy()) {
dt = ConcreteType(BaseType::Integer);
}
type_args.Return = dt.Only(-1, nullptr);

PreProcessCache PPC;
TypeAnalysis TA(PPC.FAM);
TypeResults TR = TA.analyzeFunction(type_args);

llvm::SmallPtrSet<llvm::Value *, 4> ConstantValues;
llvm::SmallPtrSet<llvm::Value *, 4> ActiveValues;
for (auto &a : type_args.Function->args()) {
if (InactiveArgs) {
ConstantValues.insert(&a);
} else if (a.getType()->isIntOrIntVectorTy()) {
ConstantValues.insert(&a);
} else {
ActiveValues.insert(&a);
}
}

DIFFE_TYPE ActiveReturns = F.getReturnType()->isFPOrFPVectorTy()
? DIFFE_TYPE::OUT_DIFF
: DIFFE_TYPE::CONSTANT;
if (DuplicatedRet)
ActiveReturns = DIFFE_TYPE::DUP_ARG;
SmallPtrSet<BasicBlock *, 4> notForAnalysis(getGuaranteedUnreachable(&F));
ActivityAnalyzer ATA(PPC, PPC.FAM.getResult<AAManager>(F), notForAnalysis,
TLI, ConstantValues, ActiveValues, ActiveReturns);

for (auto &a : F.args()) {
ATA.isConstantValue(TR, &a);
DIFFE_TYPE ActiveReturns = F.getReturnType()->isFPOrFPVectorTy()
? DIFFE_TYPE::OUT_DIFF
: DIFFE_TYPE::CONSTANT;
if (DuplicatedRet)
ActiveReturns = DIFFE_TYPE::DUP_ARG;
SmallPtrSet<BasicBlock *, 4> notForAnalysis(getGuaranteedUnreachable(&F));
ActivityAnalyzer ATA(PPC, PPC.FAM.getResult<AAManager>(F), notForAnalysis,
TLI, ConstantValues, ActiveValues, ActiveReturns);

for (auto &a : F.args()) {
ATA.isConstantValue(TR, &a);
llvm::errs().flush();
}
for (auto &BB : F) {
for (auto &I : BB) {
ATA.isConstantInstruction(TR, &I);
ATA.isConstantValue(TR, &I);
llvm::errs().flush();
}
for (auto &BB : F) {
for (auto &I : BB) {
ATA.isConstantInstruction(TR, &I);
ATA.isConstantValue(TR, &I);
llvm::errs().flush();
}
}
}

for (auto &a : F.args()) {
bool icv = ATA.isConstantValue(TR, &a);
for (auto &a : F.args()) {
bool icv = ATA.isConstantValue(TR, &a);
llvm::errs().flush();
llvm::outs() << a << ": icv:" << icv << "\n";
llvm::outs().flush();
}
for (auto &BB : F) {
llvm::outs() << BB.getName() << "\n";
for (auto &I : BB) {
bool ici = ATA.isConstantInstruction(TR, &I);
bool icv = ATA.isConstantValue(TR, &I);
llvm::errs().flush();
llvm::outs() << a << ": icv:" << icv << "\n";
llvm::outs() << I << ": icv:" << icv << " ici:" << ici << "\n";
llvm::outs().flush();
}
for (auto &BB : F) {
llvm::outs() << BB.getName() << "\n";
for (auto &I : BB) {
bool ici = ATA.isConstantInstruction(TR, &I);
bool icv = ATA.isConstantValue(TR, &I);
llvm::errs().flush();
llvm::outs() << I << ": icv:" << icv << " ici:" << ici << "\n";
llvm::outs().flush();
}
}
return /*changed*/ false;
}
return /*changed*/ false;
}

class ActivityAnalysisPrinter final : public FunctionPass {
public:
static char ID;
ActivityAnalysisPrinter() : FunctionPass(ID) {}

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<TargetLibraryInfoWrapperPass>();
}

bool runOnFunction(Function &F) override {

#if LLVM_VERSION_MAJOR >= 10
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
#else
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
#endif

return printActivityAnalysis(F, TLI);
}
};

Expand All @@ -194,3 +199,12 @@ char ActivityAnalysisPrinter::ID = 0;

static RegisterPass<ActivityAnalysisPrinter>
X("print-activity-analysis", "Print Activity Analysis Results");

ActivityAnalysisPrinterNewPM::Result
ActivityAnalysisPrinterNewPM::run(llvm::Function &F,
llvm::FunctionAnalysisManager &FAM) {
bool changed = false;
changed = printActivityAnalysis(F, FAM.getResult<TargetLibraryAnalysis>(F));
return changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
}
llvm::AnalysisKey ActivityAnalysisPrinterNewPM::Key;
48 changes: 48 additions & 0 deletions enzyme/Enzyme/ActivityAnalysisPrinter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//=- ActivityAnalysisPrinter.h - Printer utility pass for Activity Analysis =//
//
// Enzyme Project
//
// Part of the Enzyme 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
//
// If using this code in an academic setting, please cite the following:
// @incollection{enzymeNeurips,
// title = {Instead of Rewriting Foreign Code for Machine Learning,
// Automatically Synthesize Fast Gradients},
// author = {Moses, William S. and Churavy, Valentin},
// booktitle = {Advances in Neural Information Processing Systems 33},
// year = {2020},
// note = {To appear in},
// }
//
//===----------------------------------------------------------------------===//
//
// This file contains a utility LLVM pass for printing derived Activity Analysis
// results of a given function.
//
//===----------------------------------------------------------------------===//
#include <llvm/Config/llvm-config.h>

#include "llvm/IR/PassManager.h"
#include "llvm/Passes/PassPlugin.h"

namespace llvm {
class FunctionPass;
}

class ActivityAnalysisPrinterNewPM final
: public llvm::AnalysisInfoMixin<ActivityAnalysisPrinterNewPM> {
friend struct llvm::AnalysisInfoMixin<ActivityAnalysisPrinterNewPM>;

private:
static llvm::AnalysisKey Key;

public:
using Result = llvm::PreservedAnalyses;
ActivityAnalysisPrinterNewPM() {}

Result run(llvm::Function &M, llvm::FunctionAnalysisManager &MAM);

static bool isRequired() { return true; }
};
Loading