Skip to content

Commit

Permalink
[Examples] Fix some Clang-tidy modernize-use-default and Include What…
Browse files Browse the repository at this point in the history
… You Use warnings; other minor fixes.

Differential revision: https://reviews.llvm.org/D26433

llvm-svn: 287384
  • Loading branch information
EugeneZelenko committed Nov 18, 2016
1 parent 09c311b commit ae7ac95
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 56 deletions.
Expand Up @@ -93,7 +93,6 @@ class KaleidoscopeJIT {
void removeModule(ModuleHandle H) {
CompileLayer.removeModuleSet(H);
}

};

} // end namespace orc
Expand Down
22 changes: 17 additions & 5 deletions llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
Expand Up @@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
Expand Down Expand Up @@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//

namespace {

/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
virtual ~ExprAST() {}
virtual ~ExprAST() = default;

virtual Value *codegen() = 0;
};

Expand All @@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {

public:
NumberExprAST(double Val) : Val(Val) {}

Value *codegen() override;
};

Expand All @@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {

public:
VariableExprAST(const std::string &Name) : Name(Name) {}
const std::string &getName() const { return Name; }

Value *codegen() override;
const std::string &getName() const { return Name; }
};

/// UnaryExprAST - Expression class for a unary operator.
Expand All @@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}

Value *codegen() override;
};

Expand All @@ -182,6 +186,7 @@ class BinaryExprAST : public ExprAST {
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}

Value *codegen() override;
};

Expand All @@ -194,6 +199,7 @@ class CallExprAST : public ExprAST {
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}

Value *codegen() override;
};

Expand All @@ -205,6 +211,7 @@ class IfExprAST : public ExprAST {
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}

Value *codegen() override;
};

Expand All @@ -219,6 +226,7 @@ class ForExprAST : public ExprAST {
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}

Value *codegen() override;
};

Expand All @@ -232,6 +240,7 @@ class VarExprAST : public ExprAST {
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}

Value *codegen() override;
};

Expand All @@ -249,6 +258,7 @@ class PrototypeAST {
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}

Function *codegen();
const std::string &getName() const { return Name; }

Expand All @@ -272,8 +282,10 @@ class FunctionAST {
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}

Function *codegen();
};

} // end anonymous namespace

//===----------------------------------------------------------------------===//
Expand Down
Expand Up @@ -25,10 +25,13 @@
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
#include <memory>
#include <string>
Expand Down Expand Up @@ -105,7 +108,6 @@ class KaleidoscopeJIT {
}

private:

std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
// Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
Expand All @@ -124,7 +126,6 @@ class KaleidoscopeJIT {

return M;
}

};

} // end namespace orc
Expand Down
22 changes: 17 additions & 5 deletions llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
Expand Up @@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
Expand Down Expand Up @@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//

namespace {

/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
virtual ~ExprAST() {}
virtual ~ExprAST() = default;

virtual Value *codegen() = 0;
};

Expand All @@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {

public:
NumberExprAST(double Val) : Val(Val) {}

Value *codegen() override;
};

Expand All @@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {

public:
VariableExprAST(const std::string &Name) : Name(Name) {}
const std::string &getName() const { return Name; }

Value *codegen() override;
const std::string &getName() const { return Name; }
};

/// UnaryExprAST - Expression class for a unary operator.
Expand All @@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}

Value *codegen() override;
};

Expand All @@ -182,6 +186,7 @@ class BinaryExprAST : public ExprAST {
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}

Value *codegen() override;
};

Expand All @@ -194,6 +199,7 @@ class CallExprAST : public ExprAST {
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}

Value *codegen() override;
};

Expand All @@ -205,6 +211,7 @@ class IfExprAST : public ExprAST {
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}

Value *codegen() override;
};

Expand All @@ -219,6 +226,7 @@ class ForExprAST : public ExprAST {
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}

Value *codegen() override;
};

Expand All @@ -232,6 +240,7 @@ class VarExprAST : public ExprAST {
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}

Value *codegen() override;
};

Expand All @@ -249,6 +258,7 @@ class PrototypeAST {
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}

Function *codegen();
const std::string &getName() const { return Name; }

Expand All @@ -272,8 +282,10 @@ class FunctionAST {
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}

Function *codegen();
};

} // end anonymous namespace

//===----------------------------------------------------------------------===//
Expand Down
Expand Up @@ -26,12 +26,16 @@
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
#include <memory>
#include <set>
#include <string>
#include <vector>

Expand Down Expand Up @@ -116,7 +120,6 @@ class KaleidoscopeJIT {
}

private:

std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
// Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
Expand All @@ -135,7 +138,6 @@ class KaleidoscopeJIT {

return M;
}

};

} // end namespace orc
Expand Down

0 comments on commit ae7ac95

Please sign in to comment.