Skip to content

Commit

Permalink
Mangling
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanradanov committed Feb 21, 2024
1 parent caa6777 commit f90201a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions enzyme/Enzyme/EnzymeLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5142,7 +5142,7 @@ class TruncateGenerator : public llvm::InstVisitor<TruncateGenerator> {
void visitExtractValueInst(llvm::ExtractValueInst &EEI) { return; }
void visitInsertValueInst(llvm::InsertValueInst &EEI) { return; }
CallInst *createMPFRCall(llvm::IRBuilder<> &B, llvm::Instruction &I,
llvm::Type *RetTy, SmallVectorImpl<Value *> &Args) {
llvm::Type *RetTy, SmallVectorImpl<Value *> &ArgsIn) {
std::string Name;
if (auto BO = dyn_cast<BinaryOperator>(&I)) {
Name = "binop_" + std::string(BO->getOpcodeName());
Expand All @@ -5164,8 +5164,11 @@ class TruncateGenerator : public llvm::InstVisitor<TruncateGenerator> {
}

std::string MangledName =
std::string("__enzyme_mpfr_") + truncation.mangleString() + "_" + Name;
std::string("__enzyme_mpfr_") + truncation.mangleFrom() + "_" + Name;
auto F = newFunc->getParent()->getFunction(MangledName);
SmallVector<Value *> Args(ArgsIn.begin(), ArgsIn.end());
Args.push_back(B.getInt64(truncation.getTo().exponentWidth));
Args.push_back(B.getInt64(truncation.getTo().significandWidth));
if (!F) {
SmallVector<Type *> ArgTypes;
for (auto Arg : Args)
Expand Down Expand Up @@ -5467,7 +5470,7 @@ llvm::Function *EnzymeLogic::CreateTruncateFunc(RequestContext context,
FunctionType *FTy = FunctionType::get(NewTy, params, totrunc->isVarArg());
std::string truncName =
std::string("__enzyme_done_truncate_") + truncateModeStr(mode) +
"_func_" + truncation.mangleString() + "_" + totrunc->getName().str();
"_func_" + truncation.mangleTruncation() + "_" + totrunc->getName().str();
Function *NewF = Function::Create(FTy, totrunc->getLinkage(), truncName,
totrunc->getParent());

Expand Down
7 changes: 6 additions & 1 deletion enzyme/Enzyme/EnzymeLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ enum TruncateMode { TruncMemMode, TruncOpMode, TruncOpFullModuleMode };
case TruncOpFullModuleMode:
return "op_full_module";
}
llvm_unreachable("Invalid truncation mode");
}

struct FloatRepresentation {
Expand Down Expand Up @@ -366,6 +367,7 @@ struct FloatTruncation {
llvm::report_fatal_error(
"Float truncation `from` and `to` type must not be the same.");
}
FloatRepresentation getTo() { return to;}
unsigned getFromTypeWidth() { return from.getTypeWidth(); }
unsigned getToTypeWidth() { return to.getTypeWidth(); }
llvm::Type *getFromType(llvm::LLVMContext &ctx) {
Expand All @@ -388,9 +390,12 @@ struct FloatTruncation {
bool operator<(const FloatTruncation &other) const {
return std::tuple(from, to) < std::tuple(other.from, other.to);
}
std::string mangleString() const {
std::string mangleTruncation() const {
return from.to_string() + "to" + to.to_string();
}
std::string mangleFrom() const {
return from.to_string();
}
};

class EnzymeLogic {
Expand Down

0 comments on commit f90201a

Please sign in to comment.