Skip to content

Commit

Permalink
Fix unused field and override warnings (#2058)
Browse files Browse the repository at this point in the history
* Adds missing override on virtual methods in EnzymeAction

* Removes unused field dretAlloca in AdjointGenerator

* Removes unused field returnuses in AdjointGenerator

* Runs clang-format on changes
  • Loading branch information
MattBolitho authored Aug 28, 2024
1 parent f514f82 commit 19053fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
15 changes: 4 additions & 11 deletions enzyme/Enzyme/AdjointGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {
getIndex;
const std::map<llvm::CallInst *, const std::vector<bool>>
overwritten_args_map;
const llvm::SmallPtrSetImpl<llvm::Instruction *> *returnuses;
const AugmentedReturn *augmentedReturn;
const std::map<llvm::ReturnInst *, llvm::StoreInst *> *replacedReturns;

Expand All @@ -69,7 +68,6 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {
&unnecessaryInstructions;
const llvm::SmallPtrSetImpl<const llvm::Instruction *> &unnecessaryStores;
const llvm::SmallPtrSetImpl<llvm::BasicBlock *> &oldUnreachable;
llvm::AllocaInst *dretAlloca;

public:
AdjointGenerator(
Expand All @@ -80,23 +78,20 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {
getIndex,
const std::map<llvm::CallInst *, const std::vector<bool>>
overwritten_args_map,
const llvm::SmallPtrSetImpl<llvm::Instruction *> *returnuses,
const AugmentedReturn *augmentedReturn,
const std::map<llvm::ReturnInst *, llvm::StoreInst *> *replacedReturns,
const llvm::SmallPtrSetImpl<const llvm::Value *> &unnecessaryValues,
const llvm::SmallPtrSetImpl<const llvm::Instruction *>
&unnecessaryInstructions,
const llvm::SmallPtrSetImpl<const llvm::Instruction *> &unnecessaryStores,
const llvm::SmallPtrSetImpl<llvm::BasicBlock *> &oldUnreachable,
llvm::AllocaInst *dretAlloca)
const llvm::SmallPtrSetImpl<llvm::BasicBlock *> &oldUnreachable)
: Mode(Mode), gutils(gutils), constant_args(constant_args),
retType(retType), getIndex(getIndex),
overwritten_args_map(overwritten_args_map), returnuses(returnuses),
overwritten_args_map(overwritten_args_map),
augmentedReturn(augmentedReturn), replacedReturns(replacedReturns),
unnecessaryValues(unnecessaryValues),
unnecessaryInstructions(unnecessaryInstructions),
unnecessaryStores(unnecessaryStores), oldUnreachable(oldUnreachable),
dretAlloca(dretAlloca) {
unnecessaryStores(unnecessaryStores), oldUnreachable(oldUnreachable) {
using namespace llvm;

assert(TR.getFunction() == gutils->oldFunc);
Expand Down Expand Up @@ -5683,9 +5678,7 @@ class AdjointGenerator : public llvm::InstVisitor<AdjointGenerator> {
bool hasNonReturnUse = false;
for (auto use : call.users()) {
if (Mode == DerivativeMode::ReverseModePrimal ||
!isa<ReturnInst>(
use)) { // || returnuses.find(cast<Instruction>(use)) ==
// returnuses.end()) {
!isa<ReturnInst>(use)) {
hasNonReturnUse = true;
}
}
Expand Down
5 changes: 3 additions & 2 deletions enzyme/Enzyme/Clang/EnzymeClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ template <typename ConsumerType>
class EnzymeAction final : public clang::PluginASTAction {
protected:
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef InFile) {
CreateASTConsumer(clang::CompilerInstance &CI,
llvm::StringRef InFile) override {
return std::unique_ptr<clang::ASTConsumer>(new ConsumerType(CI));
}

bool ParseArgs(const clang::CompilerInstance &CI,
const std::vector<std::string> &args) {
const std::vector<std::string> &args) override {
return true;
}

Expand Down
31 changes: 13 additions & 18 deletions enzyme/Enzyme/EnzymeLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2481,10 +2481,9 @@ const AugmentedReturn &EnzymeLogic::CreateAugmentedPrimal(

AdjointGenerator maker(DerivativeMode::ReverseModePrimal, gutils,
constant_args, retType, getIndex, overwritten_args_map,
&returnuses,
&AugmentedCachedFunctions.find(tup)->second, nullptr,
unnecessaryValues, unnecessaryInstructions,
unnecessaryStores, guaranteedUnreachable, nullptr);
unnecessaryStores, guaranteedUnreachable);

for (BasicBlock &oBB : *gutils->oldFunc) {
auto term = oBB.getTerminator();
Expand Down Expand Up @@ -4325,12 +4324,10 @@ Function *EnzymeLogic::CreatePrimalAndGradient(
}
}

AdjointGenerator maker(key.mode, gutils, key.constant_args, key.retType,
getIndex, overwritten_args_map,
/*returnuses*/ nullptr, augmenteddata,
&replacedReturns, unnecessaryValues,
unnecessaryInstructions, unnecessaryStores,
guaranteedUnreachable, dretAlloca);
AdjointGenerator maker(
key.mode, gutils, key.constant_args, key.retType, getIndex,
overwritten_args_map, augmenteddata, &replacedReturns, unnecessaryValues,
unnecessaryInstructions, unnecessaryStores, guaranteedUnreachable);

for (BasicBlock &oBB : *gutils->oldFunc) {
// Don't create derivatives for code that results in termination
Expand Down Expand Up @@ -4857,11 +4854,10 @@ Function *EnzymeLogic::CreateForwardDiff(
calculateUnusedStoresInFunction(*gutils->oldFunc, unnecessaryStores,
unnecessaryInstructions, gutils, TLI);

maker = new AdjointGenerator(
mode, gutils, constant_args, retType, getIndex, overwritten_args_map,
/*returnuses*/ nullptr, augmenteddata, nullptr, unnecessaryValues,
unnecessaryInstructions, unnecessaryStores, guaranteedUnreachable,
nullptr);
maker = new AdjointGenerator(mode, gutils, constant_args, retType, getIndex,
overwritten_args_map, augmenteddata, nullptr,
unnecessaryValues, unnecessaryInstructions,
unnecessaryStores, guaranteedUnreachable);

if (additionalArg) {
auto v = gutils->newFunc->arg_end();
Expand Down Expand Up @@ -4910,11 +4906,10 @@ Function *EnzymeLogic::CreateForwardDiff(

calculateUnusedStoresInFunction(*gutils->oldFunc, unnecessaryStores,
unnecessaryInstructions, gutils, TLI);
maker =
new AdjointGenerator(mode, gutils, constant_args, retType, nullptr, {},
/*returnuses*/ nullptr, nullptr, nullptr,
unnecessaryValues, unnecessaryInstructions,
unnecessaryStores, guaranteedUnreachable, nullptr);
maker = new AdjointGenerator(mode, gutils, constant_args, retType, nullptr,
{}, nullptr, nullptr, unnecessaryValues,
unnecessaryInstructions, unnecessaryStores,
guaranteedUnreachable);
}

for (BasicBlock &oBB : *gutils->oldFunc) {
Expand Down

0 comments on commit 19053fa

Please sign in to comment.