Changeset View
Changeset View
Standalone View
Standalone View
lib/Support/GICHelper.cpp
//===- GmpConv.cpp - Recreate LLVM IR from the Scop. ---------------------===// | //===- GmpConv.cpp - Recreate LLVM IR from the Scop. ---------------------===// | ||||
// | // | ||||
// The LLVM Compiler Infrastructure | // The LLVM Compiler Infrastructure | ||||
// | // | ||||
// This file is distributed under the University of Illinois Open Source | // This file is distributed under the University of Illinois Open Source | ||||
// License. See LICENSE.TXT for details. | // License. See LICENSE.TXT for details. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// Functions for converting between gmp objects and apint. | // Functions for converting between gmp objects and apint. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "polly/Support/GICHelper.h" | #include "polly/Support/GICHelper.h" | ||||
#include "llvm/IR/Value.h" | #include "llvm/IR/Value.h" | ||||
#include "isl/aff.h" | #include "isl/aff.h" | ||||
#include "isl/map.h" | #include "isl/map.h" | ||||
#include "isl/schedule.h" | #include "isl/schedule.h" | ||||
#include "isl/set.h" | #include "isl/set.h" | ||||
#include "isl/union_map.h" | #include "isl/union_map.h" | ||||
#include "isl/union_set.h" | #include "isl/union_set.h" | ||||
#include "isl/val.h" | #include "isl/val.h" | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | std::string polly::getIslCompatibleName(std::string Prefix, const Value *Val, | ||||
Val->printAsOperand(OS, false); | Val->printAsOperand(OS, false); | ||||
ValStr = OS.str(); | ValStr = OS.str(); | ||||
// Remove the leading % | // Remove the leading % | ||||
ValStr.erase(0, 1); | ValStr.erase(0, 1); | ||||
ValStr = Prefix + ValStr + Suffix; | ValStr = Prefix + ValStr + Suffix; | ||||
makeIslCompatible(ValStr); | makeIslCompatible(ValStr); | ||||
return ValStr; | return ValStr; | ||||
} | } | ||||
isl_pw_aff *polly::incrementPwAff(isl_pw_aff *Aff, int i) { | |||||
isl_aff *Zero = isl_aff_zero_on_domain( | |||||
isl_local_space_from_space(isl_pw_aff_get_domain_space(Aff))); | |||||
isl_aff *Inc = isl_aff_add_constant_si(Zero, i); | |||||
return isl_pw_aff_add(Aff, isl_pw_aff_from_aff(Inc)); | |||||
} | |||||
isl_pw_multi_aff *polly::getNumElementsUB(isl_set *S, int Dim, | |||||
isl_map **LexMinPtr, | |||||
isl_map **LexMaxPtr) { | |||||
S = isl_set_reset_tuple_id(S); | |||||
isl_map *Map = isl_map_from_domain_and_range(isl_set_copy(S), S); | |||||
for (int i = 0; i < Dim; i++) | |||||
Map = isl_map_equate(Map, isl_dim_in, i, isl_dim_out, i); | |||||
isl_map *LexMax = isl_map_lexmax(isl_map_copy(Map)); | |||||
if (LexMaxPtr) | |||||
*LexMaxPtr = isl_map_copy(LexMax); | |||||
isl_map *LexMin = isl_map_lexmin(Map); | |||||
if (LexMinPtr) | |||||
*LexMinPtr = isl_map_copy(LexMin); | |||||
isl_map *Sub = isl_map_sum(LexMax, isl_map_neg(LexMin)); | |||||
isl_pw_multi_aff *Elements = isl_pw_multi_aff_from_map(Sub); | |||||
// Elements is now off-by-one (to low) in each dimension. | |||||
for (unsigned u = 0, e = isl_pw_multi_aff_dim(Elements, isl_dim_out); u < e; | |||||
u++) { | |||||
isl_pw_aff *ElementsDim = isl_pw_multi_aff_get_pw_aff(Elements, u); | |||||
ElementsDim = incrementPwAff(ElementsDim, 1); | |||||
Elements = isl_pw_multi_aff_set_pw_aff(Elements, u, ElementsDim); | |||||
} | |||||
return isl_pw_multi_aff_coalesce(Elements); | |||||
} | |||||
static int extractAffineFromPiecewiseAffine(__isl_keep isl_set *Dom, | |||||
jdoerfert: This will probably be easier from within isl. | |||||
__isl_keep isl_aff *Aff, | |||||
void *User) { | |||||
isl_set_free(Dom); | |||||
*(isl_aff **)User = Aff; | |||||
return 0; | |||||
} | |||||
isl_aff *polly::isl_aff_from_pw_aff(isl_pw_aff *PA) { | |||||
assert(PA && isl_pw_aff_n_piece(PA) == 1 && | |||||
"PA is null or has not exactly one piece"); | |||||
isl_aff *A = nullptr; | |||||
isl_pw_aff_foreach_piece(PA, extractAffineFromPiecewiseAffine, &A); | |||||
isl_pw_aff_free(PA); | |||||
assert(A && "Could not extract affine piece"); | |||||
return A; | |||||
} | |||||
isl_pw_aff *polly::getNumberOfIterationsForSchedule(isl_union_map *Schedule) { | |||||
isl_union_set *Range = isl_union_map_range(Schedule); | |||||
isl_set *LoopDomain = isl_set_from_union_set(Range); | |||||
int InDim = isl_set_n_dim(LoopDomain) - 1; | |||||
isl_pw_multi_aff *NumElements = getNumElementsUB(LoopDomain, InDim); | |||||
unsigned Dim = isl_pw_multi_aff_dim(NumElements, isl_dim_set) - 1; | |||||
isl_pw_aff *NumIterations = isl_pw_multi_aff_get_pw_aff(NumElements, Dim); | |||||
isl_pw_multi_aff_free(NumElements); | |||||
return NumIterations; | |||||
} |
This will probably be easier from within isl.