From 00b946960e07be04c12a87cb0aaeb940de07022c Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 6 Mar 2024 18:04:14 -0800 Subject: [PATCH] Fix bazel build for macos --- enzyme/Enzyme/InstructionDerivatives.td | 70 +++++++++---------- .../Analysis/DataFlowActivityAnalysis.cpp | 2 +- ...Analysis.cpp => DataFlowAliasAnalysis.cpp} | 4 +- ...liasAnalysis.h => DataFlowAliasAnalysis.h} | 4 +- .../MLIR/Interfaces/EnzymeLogicReverse.cpp | 8 +-- .../Enzyme/MLIR/Passes/PrintAliasAnalysis.cpp | 2 +- enzyme/tools/enzyme-tblgen/enzyme-tblgen.cpp | 5 +- 7 files changed, 49 insertions(+), 46 deletions(-) rename enzyme/Enzyme/MLIR/Analysis/{AliasAnalysis.cpp => DataFlowAliasAnalysis.cpp} (99%) rename enzyme/Enzyme/MLIR/Analysis/{AliasAnalysis.h => DataFlowAliasAnalysis.h} (99%) diff --git a/enzyme/Enzyme/InstructionDerivatives.td b/enzyme/Enzyme/InstructionDerivatives.td index e309055c34d2..70b3ef991095 100644 --- a/enzyme/Enzyme/InstructionDerivatives.td +++ b/enzyme/Enzyme/InstructionDerivatives.td @@ -220,41 +220,41 @@ class GlobalExpr : OperationisHalfTy()) {\n" -" tsize = 16;\n" -" high = tsize - 1;\n" -" low = high - 5;\n" -" } else if (ty->isFloatTy()) {\n" -" tsize = 32;\n" -" high = tsize - 1;\n" -" low = high - 8;\n" -" } else if (ty->isDoubleTy()) {\n" -" tsize = 64;\n" -" high = tsize - 1;\n" -" low = high - 11;\n" -" } else if (ty->isX86_FP80Ty()) {\n" -" tsize = 80;\n" -" high = tsize - 1;\n" -" low = high - 16;\n" - // x86_fp80 has only 15 exponent bits, but we must also - // retain the most-significant bit of the mantissa as - // there is no implicit leading 1. -" } else if (ty->isFP128Ty()) {\n" -" tsize = 128;\n" -" high = tsize - 1;\n" -" low = high - 15;\n" -" } else {\n" -" llvm_unreachable(\"Unknown type within frexp\");\n" -" }\n" -" APInt eval = APInt::getBitsSet(tsize, low, high);\n" -" auto ity = IntegerType::get(ty->getContext(), tsize);\n" -" ConstantInt::get(ity, eval);\n" -" })">; +def MantissaMaskOfReturnForFrexp : GlobalExprisHalfTy()) { + tsize = 16; + high = tsize - 1; + low = high - 5; + } else if (ty->isFloatTy()) { + tsize = 32; + high = tsize - 1; + low = high - 8; + } else if (ty->isDoubleTy()) { + tsize = 64; + high = tsize - 1; + low = high - 11; + } else if (ty->isX86_FP80Ty()) { + tsize = 80; + high = tsize - 1; + low = high - 16; + // x86_fp80 has only 15 exponent bits, but we must also + // retain the most-significant bit of the mantissa as + // there is no implicit leading + } else if (ty->isFP128Ty()) { + tsize = 128; + high = tsize - 1; + low = high - 15; + } else { + llvm_unreachable("Unknown type within frexp"); + } + APInt eval = APInt::getBitsSet(tsize, low, high); + auto ity = IntegerType::get(ty->getContext(), tsize); + ConstantInt::get(ity, eval); +}]>; class ConstantFP : Operation { string value = val; diff --git a/enzyme/Enzyme/MLIR/Analysis/DataFlowActivityAnalysis.cpp b/enzyme/Enzyme/MLIR/Analysis/DataFlowActivityAnalysis.cpp index 9c540064a49a..1121962d5453 100644 --- a/enzyme/Enzyme/MLIR/Analysis/DataFlowActivityAnalysis.cpp +++ b/enzyme/Enzyme/MLIR/Analysis/DataFlowActivityAnalysis.cpp @@ -25,7 +25,7 @@ // //===----------------------------------------------------------------------===// #include "DataFlowActivityAnalysis.h" -#include "AliasAnalysis.h" +#include "DataFlowAliasAnalysis.h" #include "Dialect/Ops.h" #include "Interfaces/AutoDiffTypeInterface.h" diff --git a/enzyme/Enzyme/MLIR/Analysis/AliasAnalysis.cpp b/enzyme/Enzyme/MLIR/Analysis/DataFlowAliasAnalysis.cpp similarity index 99% rename from enzyme/Enzyme/MLIR/Analysis/AliasAnalysis.cpp rename to enzyme/Enzyme/MLIR/Analysis/DataFlowAliasAnalysis.cpp index 9af864e592d6..c2c38cbe09f0 100644 --- a/enzyme/Enzyme/MLIR/Analysis/AliasAnalysis.cpp +++ b/enzyme/Enzyme/MLIR/Analysis/DataFlowAliasAnalysis.cpp @@ -1,4 +1,4 @@ -//===- AliasAnalysis.cpp - Implementation of Alias Analysis ---------------===// +//===- DataFlowAliasAnalysis.cpp - Implementation of Alias Analysis ------===// // // Enzyme Project // @@ -23,7 +23,7 @@ // that the pointers in a program may point to. // //===----------------------------------------------------------------------===// -#include "AliasAnalysis.h" +#include "DataFlowAliasAnalysis.h" #include "mlir/Analysis/AliasAnalysis.h" #include "mlir/Analysis/DataFlow/DenseAnalysis.h" diff --git a/enzyme/Enzyme/MLIR/Analysis/AliasAnalysis.h b/enzyme/Enzyme/MLIR/Analysis/DataFlowAliasAnalysis.h similarity index 99% rename from enzyme/Enzyme/MLIR/Analysis/AliasAnalysis.h rename to enzyme/Enzyme/MLIR/Analysis/DataFlowAliasAnalysis.h index 57297f1242a7..e8fae0e147eb 100644 --- a/enzyme/Enzyme/MLIR/Analysis/AliasAnalysis.h +++ b/enzyme/Enzyme/MLIR/Analysis/DataFlowAliasAnalysis.h @@ -1,4 +1,4 @@ -//===- AliasAnalysis.h - Declaration of Alias Analysis --------------------===// +//===- DataflowAliasAnalysis.h - Declaration of Alias Analysis ------------===// // // Enzyme Project // @@ -307,7 +307,7 @@ class AliasClassLattice : public dataflow::AbstractSparseLattice { void print(raw_ostream &os) const override; - AliasResult alias(const AbstractSparseLattice &other) const; + ::mlir::AliasResult alias(const AbstractSparseLattice &other) const; ChangeResult join(const AbstractSparseLattice &other) override; diff --git a/enzyme/Enzyme/MLIR/Interfaces/EnzymeLogicReverse.cpp b/enzyme/Enzyme/MLIR/Interfaces/EnzymeLogicReverse.cpp index 96d5a65a884b..e3bb0af8e338 100644 --- a/enzyme/Enzyme/MLIR/Interfaces/EnzymeLogicReverse.cpp +++ b/enzyme/Enzyme/MLIR/Interfaces/EnzymeLogicReverse.cpp @@ -214,14 +214,14 @@ FunctionOpInterface MEnzymeLogic::CreateReverseDiff( auto nf = gutils->newFunc; - // llvm::errs() << "nf\n"; - // nf.dump(); - // llvm::errs() << "nf end\n"; - delete gutils; if (!res.succeeded()) return nullptr; + // llvm::errs() << "nf\n"; + nf.dump(); + // llvm::errs() << "nf end\n"; + return nf; } diff --git a/enzyme/Enzyme/MLIR/Passes/PrintAliasAnalysis.cpp b/enzyme/Enzyme/MLIR/Passes/PrintAliasAnalysis.cpp index c2680ae6db72..2b466a30ed0e 100644 --- a/enzyme/Enzyme/MLIR/Passes/PrintAliasAnalysis.cpp +++ b/enzyme/Enzyme/MLIR/Passes/PrintAliasAnalysis.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "Analysis/AliasAnalysis.h" +#include "Analysis/DataFlowAliasAnalysis.h" #include "Dialect/Ops.h" #include "Passes/PassDetails.h" #include "Passes/Passes.h" diff --git a/enzyme/tools/enzyme-tblgen/enzyme-tblgen.cpp b/enzyme/tools/enzyme-tblgen/enzyme-tblgen.cpp index a5f7fa768f55..485af7868a70 100644 --- a/enzyme/tools/enzyme-tblgen/enzyme-tblgen.cpp +++ b/enzyme/tools/enzyme-tblgen/enzyme-tblgen.cpp @@ -609,8 +609,11 @@ bool handle(const Twine &curIndent, const Twine &argPattern, raw_ostream &os, PrintFatalError(pattern->getLoc(), Twine("string 'value' not defined in ") + resultTree->getAsString()); - + if (value->getValue().contains(';')) + os << "({ "; os << value->getValue(); + if (value->getValue().contains(';')) + os << " })"; return false; } else if (opName == "Undef" || Def->isSubClassOf("Undef")) { if (resultRoot->getNumArgs() != 1)