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

Fix calling convention and other small bugs #16

Merged
merged 12 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix julia
  • Loading branch information
wsmoses committed Oct 12, 2019
commit 3412e9cf3400faea5b57e530012704494b8e7316
2 changes: 2 additions & 0 deletions .github/workflows/julia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
run: |
mkdir build
cd build
cmake --version
ls /home/runner/work/Enzyme/Enzyme/enzyme/Enzyme/
cmake -DLLVM_DIR=../contrib/usr/lib/cmake/llvm -DLLVM_EXTERNAL_LIT=../contrib/usr/tools/lit/lit.py ../enzyme
make -j
- name: "Julia tests"
Expand Down
1 change: 1 addition & 0 deletions enzyme/Enzyme/ActiveVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"

#include "llvm/Support/raw_ostream.h"

#include "ActiveVariable.h"
#include "Utils.h"
Expand Down
4 changes: 3 additions & 1 deletion enzyme/Enzyme/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# set(LLVM_LINK_COMPONENTS Core Support)
#endif()

file(GLOB ENZYME_SRC
file(GLOB ENZYME_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"*.cpp"
)

list(APPEND ENZYME_SRC SCEV/ScalarEvolutionExpander.cpp)

message("found enzyme sources " ${ENZYME_SRC})

if (${LLVM_VERSION_MAJOR} LESS 8)
add_llvm_loadable_module( LLVMEnzyme-${LLVM_VERSION_MAJOR}
${ENZYME_SRC}
Expand Down
2 changes: 0 additions & 2 deletions enzyme/Enzyme/Enzyme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils.h"

#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/ScalarEvolution.h"
Expand Down Expand Up @@ -222,7 +221,6 @@ class Enzyme : public FunctionPass {
AU.addRequired<TargetLibraryInfoWrapperPass>();
AU.addRequired<AAResultsWrapperPass>();
AU.addRequired<GlobalsAAWrapperPass>();
AU.addRequiredID(LoopSimplifyID);
//AU.addRequiredID(LCSSAID);

AU.addRequired<LoopInfoWrapperPass>();
Expand Down
130 changes: 21 additions & 109 deletions enzyme/Enzyme/LibraryFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,114 +20,6 @@

#include "llvm/Analysis/TargetLibraryInfo.h"

/*
//For updating below one should read MemoryBuiltins.cpp, TargetLibraryInfo.cpp
static inline
bool mapAllocationToDeallocation(const llvm::LibFunc libfunc, const llvm::TargetLibraryInfo &TLI) {



// void operator delete[](void*);
case LibFunc_msvc_delete_array_ptr32:
// void operator delete[](void*);
case LibFunc_msvc_delete_array_ptr64:
// void operator delete(void*);
case LibFunc_msvc_delete_ptr32:
// void operator delete(void*);
case LibFunc_msvc_delete_ptr64:
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());

// void operator delete[](void*, unsigned long);
case LibFunc_ZdaPvm:
// void operator delete(void*, nothrow);
case LibFunc_ZdlPvRKSt9nothrow_t:
// void operator delete(void*, unsigned int);
case LibFunc_ZdlPvj:
// void operator delete(void*, unsigned long);
case LibFunc_ZdlPvm:
// void operator delete(void*, align_val_t)
case LibFunc_ZdlPvSt11align_val_t:
// void operator delete[](void*, align_val_t)
case LibFunc_ZdaPvSt11align_val_t:
// void operator delete[](void*, unsigned int);
case LibFunc_msvc_delete_array_ptr32_int:
// void operator delete[](void*, nothrow);
case LibFunc_msvc_delete_array_ptr32_nothrow:
// void operator delete[](void*, unsigned long long);
case LibFunc_msvc_delete_array_ptr64_longlong:
// void operator delete[](void*, nothrow);
case LibFunc_msvc_delete_array_ptr64_nothrow:
// void operator delete(void*, unsigned int);
case LibFunc_msvc_delete_ptr32_int:
// void operator delete(void*, nothrow);
case LibFunc_msvc_delete_ptr32_nothrow:
// void operator delete(void*, unsigned long long);
case LibFunc_msvc_delete_ptr64_longlong:
// void operator delete(void*, nothrow);
case LibFunc_msvc_delete_ptr64_nothrow:
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());

// void operator delete(void*, align_val_t, nothrow)
case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
// void operator delete[](void*, align_val_t, nothrow)
case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:

switch (libfunc) {
case LibFunc_malloc: // malloc(unsigned int);
case LibFunc_valloc: // valloc(unsigned int);
return LibFunc_free;

case LibFunc_Znwj: // new(unsigned int);
return LibFunc_ZdlPv; // void operator delete(void*);

case LibFunc_ZnwjRKSt9nothrow_t: // new(unsigned int, nothrow);
case LibFunc_ZnwjSt11align_val_t: // new(unsigned int, align_val_t)
case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: // new(unsigned int, align_val_t, nothrow)

case LibFunc_Znwm: // new(unsigned long);
case LibFunc_ZnwmRKSt9nothrow_t: // new(unsigned long, nothrow);
case LibFunc_ZnwmSt11align_val_t: // new(unsigned long, align_val_t)
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: // new(unsigned long, align_val_t, nothrow)

case LibFunc_Znaj: // new[](unsigned int);
return LibFunc_ZdaPv; // void operator delete[](void*);

case LibFunc_ZnajRKSt9nothrow_t: // new[](unsigned int, nothrow);
return LibFunc_ZdaPvRKSt9nothrow_t; // void operator delete[](void*, nothrow);

case LibFunc_ZnajSt11align_val_t: // new[](unsigned int, align_val_t)

return LibFunc_ZdaPvj; // void operator delete[](void*, unsigned int);

case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: // new[](unsigned int, align_val_t, nothrow)


case LibFunc_Znam: // new[](unsigned long);
case LibFunc_ZnamRKSt9nothrow_t: // new[](unsigned long, nothrow);
case LibFunc_ZnamSt11align_val_t: // new[](unsigned long, align_val_t)
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: // new[](unsigned long, align_val_t, nothrow)

case LibFunc_msvc_new_int: // new(unsigned int);
case LibFunc_msvc_new_int_nothrow: // new(unsigned int, nothrow);
case LibFunc_msvc_new_longlong: // new(unsigned long long);
case LibFunc_msvc_new_longlong_nothrow: // new(unsigned long long, nothrow);
case LibFunc_msvc_new_array_int: // new[](unsigned int);
case LibFunc_msvc_new_array_int_nothrow: // new[](unsigned int, nothrow);
case LibFunc_msvc_new_array_longlong: // new[](unsigned long long);
case LibFunc_msvc_new_array_longlong_nothrow: // new[](unsigned long long, nothrow);

//TODO strdup, strndup

//TODO call, realloc, reallocf

//TODO (perhaps) posix_memalign
TLI.get
return true;
default:
llvm_unreachable("unknown allocation function to find deallocation function for");
return false;
}
*/

//For updating below one should read MemoryBuiltins.cpp, TargetLibraryInfo.cpp
static inline
Expand All @@ -141,24 +33,32 @@ bool isAllocationFunction(const llvm::Function &F, const llvm::TargetLibraryInfo

case LibFunc_Znwj: // new(unsigned int);
case LibFunc_ZnwjRKSt9nothrow_t: // new(unsigned int, nothrow);
#if LLVM_VERSION_MAJOR > 6
case LibFunc_ZnwjSt11align_val_t: // new(unsigned int, align_val_t)
case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: // new(unsigned int, align_val_t, nothrow)
#endif

case LibFunc_Znwm: // new(unsigned long);
case LibFunc_ZnwmRKSt9nothrow_t: // new(unsigned long, nothrow);
#if LLVM_VERSION_MAJOR > 6
case LibFunc_ZnwmSt11align_val_t: // new(unsigned long, align_val_t)
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: // new(unsigned long, align_val_t, nothrow)
#endif

case LibFunc_Znaj: // new[](unsigned int);
case LibFunc_ZnajRKSt9nothrow_t: // new[](unsigned int, nothrow);
#if LLVM_VERSION_MAJOR > 6
case LibFunc_ZnajSt11align_val_t: // new[](unsigned int, align_val_t)
case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: // new[](unsigned int, align_val_t, nothrow)
#endif


case LibFunc_Znam: // new[](unsigned long);
case LibFunc_ZnamRKSt9nothrow_t: // new[](unsigned long, nothrow);
#if LLVM_VERSION_MAJOR > 6
case LibFunc_ZnamSt11align_val_t: // new[](unsigned long, align_val_t)
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: // new[](unsigned long, align_val_t, nothrow)
#endif

case LibFunc_msvc_new_int: // new(unsigned int);
case LibFunc_msvc_new_int_nothrow: // new(unsigned int, nothrow);
Expand Down Expand Up @@ -218,10 +118,12 @@ bool isDeallocationFunction(const llvm::Function &F, const llvm::TargetLibraryIn
case LibFunc_ZdlPvj:
// void operator delete(void*, unsigned long);
case LibFunc_ZdlPvm:
#if LLVM_VERSION_MAJOR > 6
// void operator delete(void*, align_val_t)
case LibFunc_ZdlPvSt11align_val_t:
// void operator delete[](void*, align_val_t)
case LibFunc_ZdaPvSt11align_val_t:
#endif
// void operator delete[](void*, unsigned int);
case LibFunc_msvc_delete_array_ptr32_int:
// void operator delete[](void*, nothrow);
Expand All @@ -239,10 +141,12 @@ bool isDeallocationFunction(const llvm::Function &F, const llvm::TargetLibraryIn
// void operator delete(void*, nothrow);
case LibFunc_msvc_delete_ptr64_nothrow:

#if LLVM_VERSION_MAJOR > 6
// void operator delete(void*, align_val_t, nothrow)
case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
// void operator delete[](void*, align_val_t, nothrow)
case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
#endif
return true;
default:
return false;
Expand All @@ -268,25 +172,33 @@ CallInst* freeKnownAllocation(llvm::IRBuilder <>& builder, llvm::Value* tofree,

case LibFunc_Znwj: // new(unsigned int);
case LibFunc_ZnwjRKSt9nothrow_t: // new(unsigned int, nothrow);
#if LLVM_VERSION_MAJOR > 6
case LibFunc_ZnwjSt11align_val_t: // new(unsigned int, align_val_t)
case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: // new(unsigned int, align_val_t, nothrow)
#endif

case LibFunc_Znwm: // new(unsigned long);
case LibFunc_ZnwmRKSt9nothrow_t: // new(unsigned long, nothrow);
#if LLVM_VERSION_MAJOR > 6
case LibFunc_ZnwmSt11align_val_t: // new(unsigned long, align_val_t)
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: // new(unsigned long, align_val_t, nothrow)
#endif
freefunc = LibFunc_ZdlPv;
break;

case LibFunc_Znaj: // new[](unsigned int);
case LibFunc_ZnajRKSt9nothrow_t: // new[](unsigned int, nothrow);
#if LLVM_VERSION_MAJOR > 6
case LibFunc_ZnajSt11align_val_t: // new[](unsigned int, align_val_t)
case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: // new[](unsigned int, align_val_t, nothrow)
#endif

case LibFunc_Znam: // new[](unsigned long);
case LibFunc_ZnamRKSt9nothrow_t: // new[](unsigned long, nothrow);
#if LLVM_VERSION_MAJOR > 6
case LibFunc_ZnamSt11align_val_t: // new[](unsigned long, align_val_t)
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: // new[](unsigned long, align_val_t, nothrow)
#endif
freefunc = LibFunc_ZdaPv;
break;

Expand Down Expand Up @@ -320,4 +232,4 @@ CallInst* freeKnownAllocation(llvm::IRBuilder <>& builder, llvm::Value* tofree,
return freecall;
}

#endif
#endif
8 changes: 5 additions & 3 deletions enzyme/Enzyme/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
#ifndef ENZYME_UTILS_H
#define ENZYME_UTILS_H

#include "llvm/ADT/SmallPtrSet.h"

#include "llvm/IR/Function.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Type.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/IR/IntrinsicInst.h"

#include "llvm/IR/Function.h"
#include "llvm/IR/IntrinsicInst.h"

#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"

static inline llvm::FastMathFlags getFast() {
llvm::FastMathFlags f;
Expand Down
2 changes: 1 addition & 1 deletion enzyme/test/Enzyme/memcpy-flt.ll
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ attributes #3 = { nounwind }
; CHECK-NEXT: br i1 %0, label %for.end, label %for.body

; CHECK: for.body:
; CHECK-NEXT: %idx = phi i64 [ %idx.next, %for.body ], [ 0, %entry ]
; CHECK-NEXT: %idx = phi i64 [ 0, %entry ], [ %idx.next, %for.body ]
; CHECK-NEXT: %dst.i = getelementptr double, double* %dst, i64 %idx
; CHECK-NEXT: %dst.i.l = load double, double* %dst.i, align 8
; CHECK-NEXT: store double 0.000000e+00, double* %dst.i, align 8
Expand Down
24 changes: 8 additions & 16 deletions enzyme/test/Enzyme/sumwithbreak.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: opt < %s %loadEnzyme -enzyme -enzyme_preopt=false -mem2reg -instcombine -correlated-propagation -adce -instcombine -simplifycfg -early-cse -simplifycfg -loop-unroll -instcombine -simplifycfg -gvn -S | FileCheck %s
; RUN: opt < %s %loadEnzyme -enzyme -enzyme_preopt=false -mem2reg -instcombine -correlated-propagation -adce -instcombine -simplifycfg -early-cse -simplifycfg -loop-unroll -instcombine -simplifycfg -gvn -jump-threading -instcombine -S | FileCheck %s

; Function Attrs: noinline nounwind uwtable
define dso_local double @f(double* nocapture readonly %x, i64 %n) #0 {
Expand Down Expand Up @@ -50,51 +50,43 @@ attributes #0 = { noinline nounwind uwtable }
; CHECK-NEXT: %iv = phi i64 [ %iv.next, %if.end ], [ 0, %entry ]
; CHECK-NEXT: %data.016 = phi double [ %add5, %if.end ], [ 0.000000e+00, %entry ]
; CHECK-NEXT: %cmp2 = fcmp fast ogt double %data.016, 1.000000e+01
; CHECK-NEXT: br i1 %cmp2, label %invertif.then, label %if.end
; CHECK-NEXT: br i1 %cmp2, label %[[invertifthen:.+]], label %if.end

; CHECK: if.end: ; preds = %for.body
; CHECK-NEXT: %iv.next = add nuw i64 %iv, 1
; CHECK-NEXT: %arrayidx4 = getelementptr inbounds double, double* %x, i64 %iv
; CHECK-NEXT: %0 = load double, double* %arrayidx4, align 8
; CHECK-NEXT: %add5 = fadd fast double %0, %data.016
; CHECK-NEXT: %cmp = icmp eq i64 %iv, %n
; CHECK-NEXT: br i1 %cmp, label %loopMerge.peel, label %for.body
; CHECK-NEXT: br i1 %cmp, label %invertif.end.peel, label %for.body

; CHECK: invertentry:
; CHECK-NEXT: ret {} undef

; CHECK: invertif.then:
; CHECK: [[invertifthen]]:
; CHECK-NEXT: %"arrayidx'ipg" = getelementptr double, double* %"x'", i64 %n
; CHECK-NEXT: %[[loadit:.+]] = load double, double* %"arrayidx'ipg", align 8
; CHECK-NEXT: %[[tostoreit:.+]] = fadd fast double %[[loadit]], %differeturn
; CHECK-NEXT: store double %[[tostoreit]], double* %"arrayidx'ipg", align 8
; CHECK-NEXT: br label %loopMerge.peel

; CHECK: loopMerge.peel:
; CHECK-NEXT: %"add5'de.1" = phi double [ 0.000000e+00, %invertif.then ], [ %differeturn, %if.end ]
; CHECK-NEXT: %"data.016'de.1" = phi double [ %differeturn, %invertif.then ], [ 0.000000e+00, %if.end ]
; CHECK-NEXT: br i1 %cmp2, label %invertfor.body.peel, label %invertif.end.peel
; CHECK-NEXT: br label %invertfor.body.peel

; CHECK: invertif.end.peel:
; CHECK-NEXT: %[[diffehere:.+]] = fadd fast double %"data.016'de.1", %"add5'de.1"
; CHECK-NEXT: %"arrayidx4'ipg.peel" = getelementptr double, double* %"x'", i64 %iv
; CHECK-NEXT: %[[loaditp:.+]] = load double, double* %"arrayidx4'ipg.peel", align 8
; CHECK-NEXT: %[[tostoreitp:.+]] = fadd fast double %[[loaditp]], %"add5'de.1"
; CHECK-NEXT: %[[tostoreitp:.+]] = fadd fast double %[[loaditp]], %differeturn
; CHECK-NEXT: store double %[[tostoreitp]], double* %"arrayidx4'ipg.peel", align 8
; CHECK-NEXT: br label %invertfor.body.peel

; CHECK: invertfor.body.peel:
; CHECK-NEXT: %"add5'de.0.peel" = phi double [ %"add5'de.1", %loopMerge.peel ], [ 0.000000e+00, %invertif.end.peel ]
; CHECK-NEXT: %"data.016'de.0.peel" = phi double [ %"data.016'de.1", %loopMerge.peel ], [ %[[diffehere]], %invertif.end.peel ]
; CHECK-NEXT: %[[donecmp:.+]] = icmp eq i64 %iv, 0
; CHECK-NEXT: %[[dthere:.+]] = fadd fast double %"add5'de.0.peel", %"data.016'de.0.peel"
; CHECK-NEXT: br i1 %[[donecmp]], label %invertentry, label %loopMerge

; CHECK: loopMerge:
; CHECK-NEXT: %"iv'phi.in" = phi i64 [ %"iv'phi", %loopMerge ], [ %iv, %invertfor.body.peel ]
; CHECK-NEXT: %"iv'phi" = add i64 %"iv'phi.in", -1
; CHECK-NEXT: %"arrayidx4'ipg" = getelementptr double, double* %"x'", i64 %"iv'phi"
; CHECK-NEXT: %[[ldhere:.+]] = load double, double* %"arrayidx4'ipg", align 8
; CHECK-NEXT: %[[tshere:.+]] = fadd fast double %[[ldhere]], %[[dthere]]
; CHECK-NEXT: %[[tshere:.+]] = fadd fast double %[[ldhere]], %differeturn
; CHECK-NEXT: store double %[[tshere]], double* %"arrayidx4'ipg", align 8
; CHECK-NEXT: %[[icmp:.+]] = icmp eq i64 %"iv'phi", 0
; CHECK-NEXT: br i1 %[[icmp]], label %invertentry, label %loopMerge
Expand Down