projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use DataLayout from the module when easily available.
[oota-llvm.git]
/
examples
/
Kaleidoscope
/
Chapter6
/
toy.cpp
diff --git
a/examples/Kaleidoscope/Chapter6/toy.cpp
b/examples/Kaleidoscope/Chapter6/toy.cpp
index 5316b80be548b3604aa636616ac413d3b61b14ef..5a3bd2e314749a2ee8686a1c6354b61bcc5d4cee 100644
(file)
--- a/
examples/Kaleidoscope/Chapter6/toy.cpp
+++ b/
examples/Kaleidoscope/Chapter6/toy.cpp
@@
-1,18
+1,19
@@
-#include "llvm/
DerivedTyp
es.h"
+#include "llvm/
Analysis/Pass
es.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Module.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"
#include "llvm/PassManager.h"
#include "llvm/PassManager.h"
-#include "llvm/Analysis/Verifier.h"
-#include "llvm/Analysis/Passes.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetSelect.h"
+#include "llvm/Support/TargetSelect.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar.h"
-#include
"llvm/Support/IRBuilder.h"
+#include
<cctype>
#include <cstdio>
#include <cstdio>
-#include <string>
#include <map>
#include <map>
+#include <string>
#include <vector>
using namespace llvm;
#include <vector>
using namespace llvm;
@@
-100,7
+101,7
@@
static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
-
+namespace {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
@@
-210,6
+211,7
@@
public:
Function *Codegen();
};
Function *Codegen();
};
+} // end anonymous namespace
//===----------------------------------------------------------------------===//
// Parser
//===----------------------------------------------------------------------===//
// Parser
@@
-589,7
+591,7
@@
Value *BinaryExprAST::Codegen() {
assert(F && "binary operator not found!");
Value *Ops[] = { L, R };
assert(F && "binary operator not found!");
Value *Ops[] = { L, R };
- return Builder.CreateCall(F, Ops,
Ops+2,
"binop");
+ return Builder.CreateCall(F, Ops, "binop");
}
Value *CallExprAST::Codegen() {
}
Value *CallExprAST::Codegen() {
@@
-608,7
+610,7
@@
Value *CallExprAST::Codegen() {
if (ArgsV.back() == 0) return 0;
}
if (ArgsV.back() == 0) return 0;
}
- return Builder.CreateCall(CalleeF, ArgsV
.begin(), ArgsV.end()
, "calltmp");
+ return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
}
Value *IfExprAST::Codegen() {
}
Value *IfExprAST::Codegen() {
@@
-654,9
+656,8
@@
Value *IfExprAST::Codegen() {
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
// Emit merge block.
TheFunction->getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
- PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
+ PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
2,
"iftmp");
"iftmp");
- PN->reserveOperandSpace(2);
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
PN->addIncoming(ThenV, ThenBB);
PN->addIncoming(ElseV, ElseBB);
@@
-697,8
+698,7
@@
Value *ForExprAST::Codegen() {
Builder.SetInsertPoint(LoopBB);
// Start the PHI node with an entry for Start.
Builder.SetInsertPoint(LoopBB);
// Start the PHI node with an entry for Start.
- PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
- Variable->reserveOperandSpace(2);
+ PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());
Variable->addIncoming(StartVal, PreheaderBB);
// Within the loop, the variable is defined equal to the PHI node. If it
Variable->addIncoming(StartVal, PreheaderBB);
// Within the loop, the variable is defined equal to the PHI node. If it
@@
-759,8
+759,8
@@
Value *ForExprAST::Codegen() {
Function *PrototypeAST::Codegen() {
// Make the function type: double(double,double) etc.
Function *PrototypeAST::Codegen() {
// Make the function type: double(double,double) etc.
- std::vector<
const
Type*> Doubles(Args.size(),
-
Type::getDoubleTy(getGlobalContext()));
+ std::vector<Type*> Doubles(Args.size(),
+ Type::getDoubleTy(getGlobalContext()));
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
Doubles, false);
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
Doubles, false);
@@
-949,7
+949,8
@@
int main() {
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
- OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
+ TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+ OurFPM.add(new DataLayoutPass(TheModule));
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.