llvm.org GIT mirror llvm / 66981fe
Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for requiring the macro. NFC; LLVM edition. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229340 91177308-0d34-0410-b5e6-96231b3b80d8 Aaron Ballman 4 years ago
161 changed file(s) with 831 addition(s) and 859 deletion(s). Raw diff Collapse all Expand all
446446 };
447447
448448 class HelpingMemoryManager : public SectionMemoryManager {
449 HelpingMemoryManager(const HelpingMemoryManager &) LLVM_DELETED_FUNCTION;
450 void operator=(const HelpingMemoryManager &) LLVM_DELETED_FUNCTION;
449 HelpingMemoryManager(const HelpingMemoryManager &) = delete;
450 void operator=(const HelpingMemoryManager &) = delete;
451451
452452 public:
453453 HelpingMemoryManager(MCJITHelper *Helper) : MasterHelper(Helper) {}
3535 cl::desc("Specify the name of an IR file to load for function definitions"),
3636 cl::value_desc("input IR file name"));
3737
38 cl::opt
39 UseObjectCache("use-object-cache",
38 cl::opt
39 UseObjectCache("use-object-cache",
4040 cl::desc("Enable use of the MCJIT object caching"),
4141 cl::init(false));
4242
5454
5555 // primary
5656 tok_identifier = -4, tok_number = -5,
57
57
5858 // control
5959 tok_if = -6, tok_then = -7, tok_else = -8,
6060 tok_for = -9, tok_in = -10,
61
61
6262 // operators
6363 tok_binary = -11, tok_unary = -12,
64
64
6565 // var definition
6666 tok_var = -13
6767 };
110110 // Comment until end of line.
111111 do LastChar = getchar();
112112 while (LastChar != EOF && LastChar != '\n' && LastChar != '\r');
113
113
114114 if (LastChar != EOF)
115115 return gettok();
116116 }
117
117
118118 // Check for end of file. Don't eat the EOF.
119119 if (LastChar == EOF)
120120 return tok_eof;
158158 char Opcode;
159159 ExprAST *Operand;
160160 public:
161 UnaryExprAST(char opcode, ExprAST *operand)
161 UnaryExprAST(char opcode, ExprAST *operand)
162162 : Opcode(opcode), Operand(operand) {}
163163 virtual Value *Codegen();
164164 };
168168 char Op;
169169 ExprAST *LHS, *RHS;
170170 public:
171 BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs)
171 BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs)
172172 : Op(op), LHS(lhs), RHS(rhs) {}
173173 virtual Value *Codegen();
174174 };
211211 VarExprAST(const std::vector > &varnames,
212212 ExprAST *body)
213213 : VarNames(varnames), Body(body) {}
214
214
215215 virtual Value *Codegen();
216216 };
217217
226226 PrototypeAST(const std::string &name, const std::vector &args,
227227 bool isoperator = false, unsigned prec = 0)
228228 : Name(name), Args(args), isOperator(isoperator), Precedence(prec) {}
229
229
230230 bool isUnaryOp() const { return isOperator && Args.size() == 1; }
231231 bool isBinaryOp() const { return isOperator && Args.size() == 2; }
232
232
233233 char getOperatorName() const {
234234 assert(isUnaryOp() || isBinaryOp());
235235 return Name[Name.size()-1];
236236 }
237
237
238238 unsigned getBinaryPrecedence() const { return Precedence; }
239
239
240240 Function *Codegen();
241
241
242242 void CreateArgumentAllocas(Function *F);
243243 };
244244
249249 public:
250250 FunctionAST(PrototypeAST *proto, ExprAST *body)
251251 : Proto(proto), Body(body) {}
252
252
253253 Function *Codegen();
254254 };
255255
273273 static int GetTokPrecedence() {
274274 if (!isascii(CurTok))
275275 return -1;
276
276
277277 // Make sure it's a declared binop.
278278 int TokPrec = BinopPrecedence[CurTok];
279279 if (TokPrec <= 0) return -1;
292292 /// ::= identifier '(' expression* ')'
293293 static ExprAST *ParseIdentifierExpr() {
294294 std::string IdName = IdentifierStr;
295
295
296296 getNextToken(); // eat identifier.
297
297
298298 if (CurTok != '(') // Simple variable ref.
299299 return new VariableExprAST(IdName);
300
300
301301 // Call.
302302 getNextToken(); // eat (
303303 std::vector Args;
317317
318318 // Eat the ')'.
319319 getNextToken();
320
320
321321 return new CallExprAST(IdName, Args);
322322 }
323323
333333 getNextToken(); // eat (.
334334 ExprAST *V = ParseExpression();
335335 if (!V) return 0;
336
336
337337 if (CurTok != ')')
338338 return Error("expected ')'");
339339 getNextToken(); // eat ).
343343 /// ifexpr ::= 'if' expression 'then' expression 'else' expression
344344 static ExprAST *ParseIfExpr() {
345345 getNextToken(); // eat the if.
346
346
347347 // condition.
348348 ExprAST *Cond = ParseExpression();
349349 if (!Cond) return 0;
350
350
351351 if (CurTok != tok_then)
352352 return Error("expected then");
353353 getNextToken(); // eat the then
354
354
355355 ExprAST *Then = ParseExpression();
356356 if (Then == 0) return 0;
357
357
358358 if (CurTok != tok_else)
359359 return Error("expected else");
360
360
361361 getNextToken();
362
362
363363 ExprAST *Else = ParseExpression();
364364 if (!Else) return 0;
365
365
366366 return new IfExprAST(Cond, Then, Else);
367367 }
368368
372372
373373 if (CurTok != tok_identifier)
374374 return Error("expected identifier after for");
375
375
376376 std::string IdName = IdentifierStr;
377377 getNextToken(); // eat identifier.
378
378
379379 if (CurTok != '=')
380380 return Error("expected '=' after for");
381381 getNextToken(); // eat '='.
382
383
382
383
384384 ExprAST *Start = ParseExpression();
385385 if (Start == 0) return 0;
386386 if (CurTok != ',')
387387 return Error("expected ',' after for start value");
388388 getNextToken();
389
389
390390 ExprAST *End = ParseExpression();
391391 if (End == 0) return 0;
392
392
393393 // The step value is optional.
394394 ExprAST *Step = 0;
395395 if (CurTok == ',') {
397397 Step = ParseExpression();
398398 if (Step == 0) return 0;
399399 }
400
400
401401 if (CurTok != tok_in)
402402 return Error("expected 'in' after for");
403403 getNextToken(); // eat 'in'.
404
404
405405 ExprAST *Body = ParseExpression();
406406 if (Body == 0) return 0;
407407
408408 return new ForExprAST(IdName, Start, End, Step, Body);
409409 }
410410
411 /// varexpr ::= 'var' identifier ('=' expression)?
411 /// varexpr ::= 'var' identifier ('=' expression)?
412412 // (',' identifier ('=' expression)?)* 'in' expression
413413 static ExprAST *ParseVarExpr() {
414414 getNextToken(); // eat the var.
418418 // At least one variable name is required.
419419 if (CurTok != tok_identifier)
420420 return Error("expected identifier after var");
421
421
422422 while (1) {
423423 std::string Name = IdentifierStr;
424424 getNextToken(); // eat identifier.
427427 ExprAST *Init = 0;
428428 if (CurTok == '=') {
429429 getNextToken(); // eat the '='.
430
430
431431 Init = ParseExpression();
432432 if (Init == 0) return 0;
433433 }
434
434
435435 VarNames.push_back(std::make_pair(Name, Init));
436
436
437437 // End of var list, exit loop.
438438 if (CurTok != ',') break;
439439 getNextToken(); // eat the ','.
440
440
441441 if (CurTok != tok_identifier)
442442 return Error("expected identifier list after var");
443443 }
444
444
445445 // At this point, we have to have 'in'.
446446 if (CurTok != tok_in)
447447 return Error("expected 'in' keyword after 'var'");
448448 getNextToken(); // eat 'in'.
449
449
450450 ExprAST *Body = ParseExpression();
451451 if (Body == 0) return 0;
452
452
453453 return new VarExprAST(VarNames, Body);
454454 }
455455
479479 // If the current token is not an operator, it must be a primary expr.
480480 if (!isascii(CurTok) || CurTok == '(' || CurTok == ',')
481481 return ParsePrimary();
482
482
483483 // If this is a unary operator, read it.
484484 int Opc = CurTok;
485485 getNextToken();
494494 // If this is a binop, find its precedence.
495495 while (1) {
496496 int TokPrec = GetTokPrecedence();
497
497
498498 // If this is a binop that binds at least as tightly as the current binop,
499499 // consume it, otherwise we are done.
500500 if (TokPrec < ExprPrec)
501501 return LHS;
502
502
503503 // Okay, we know this is a binop.
504504 int BinOp = CurTok;
505505 getNextToken(); // eat binop
506
506
507507 // Parse the unary expression after the binary operator.
508508 ExprAST *RHS = ParseUnary();
509509 if (!RHS) return 0;
510
510
511511 // If BinOp binds less tightly with RHS than the operator after RHS, let
512512 // the pending operator take RHS as its LHS.
513513 int NextPrec = GetTokPrecedence();
515515 RHS = ParseBinOpRHS(TokPrec+1, RHS);
516516 if (RHS == 0) return 0;
517517 }
518
518
519519 // Merge LHS/RHS.
520520 LHS = new BinaryExprAST(BinOp, LHS, RHS);
521521 }
527527 static ExprAST *ParseExpression() {
528528 ExprAST *LHS = ParseUnary();
529529 if (!LHS) return 0;
530
530
531531 return ParseBinOpRHS(0, LHS);
532532 }
533533
537537 /// ::= unary LETTER (id)
538538 static PrototypeAST *ParsePrototype() {
539539 std::string FnName;
540
540
541541 unsigned Kind = 0; // 0 = identifier, 1 = unary, 2 = binary.
542542 unsigned BinaryPrecedence = 30;
543
543
544544 switch (CurTok) {
545545 default:
546546 return ErrorP("Expected function name in prototype");
566566 FnName += (char)CurTok;
567567 Kind = 2;
568568 getNextToken();
569
569
570570 // Read the precedence if present.
571571 if (CurTok == tok_number) {
572572 if (NumVal < 1 || NumVal > 100)
576576 }
577577 break;
578578 }
579
579
580580 if (CurTok != '(')
581581 return ErrorP("Expected '(' in prototype");
582
582
583583 std::vector ArgNames;
584584 while (getNextToken() == tok_identifier)
585585 ArgNames.push_back(IdentifierStr);
586586 if (CurTok != ')')
587587 return ErrorP("Expected ')' in prototype");
588
588
589589 // success.
590590 getNextToken(); // eat ')'.
591
591
592592 // Verify right number of names for operator.
593593 if (Kind && ArgNames.size() != Kind)
594594 return ErrorP("Invalid number of operands for operator");
595
595
596596 return new PrototypeAST(FnName, ArgNames, Kind != 0, BinaryPrecedence);
597597 }
598598
761761
762762 class HelpingMemoryManager : public SectionMemoryManager
763763 {
764 HelpingMemoryManager(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;
765 void operator=(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;
764 HelpingMemoryManager(const HelpingMemoryManager&) = delete;
765 void operator=(const HelpingMemoryManager&) = delete;
766766
767767 public:
768768 HelpingMemoryManager(MCJITHelper *Helper) : MasterHelper(Helper) {}
769769 virtual ~HelpingMemoryManager() {}
770770
771 /// This method returns the address of the specified function.
771 /// This method returns the address of the specified function.
772772 /// Our implementation will attempt to find functions in other
773773 /// modules associated with the MCJITHelper to cross link functions
774774 /// from one generated module to another.
837837
838838 // If we don't have a prototype yet, create one.
839839 if (!PF)
840 PF = Function::Create(F->getFunctionType(),
841 Function::ExternalLinkage,
842 FnName,
840 PF = Function::Create(F->getFunctionType(),
841 Function::ExternalLinkage,
842 FnName,
843843 OpenModule);
844844 return PF;
845845 }
10261026 Value *UnaryExprAST::Codegen() {
10271027 Value *OperandV = Operand->Codegen();
10281028 if (OperandV == 0) return 0;
1029
1029
10301030 Function *F = TheHelper->getFunction(MakeLegalFunctionName(std::string("unary")+Opcode));
10311031 if (F == 0)
10321032 return ErrorV("Unknown unary operator");
1033
1033
10341034 return Builder.CreateCall(F, OperandV, "unop");
10351035 }
10361036
10521052 Builder.CreateStore(Val, Variable);
10531053 return Val;
10541054 }
1055
1055
10561056 Value *L = LHS->Codegen();
10571057 Value *R = RHS->Codegen();
10581058 if (L == 0 || R == 0) return 0;
1059
1059
10601060 switch (Op) {
10611061 case '+': return Builder.CreateFAdd(L, R, "addtmp");
10621062 case '-': return Builder.CreateFSub(L, R, "subtmp");
10691069 "booltmp");
10701070 default: break;
10711071 }
1072
1072
10731073 // If it wasn't a builtin binary operator, it must be a user defined one. Emit
10741074 // a call to it.
10751075 Function *F = TheHelper->getFunction(MakeLegalFunctionName(std::string("binary")+Op));
10761076 assert(F && "binary operator not found!");
1077
1077
10781078 Value *Ops[] = { L, R };
10791079 return Builder.CreateCall(F, Ops, "binop");
10801080 }
10841084 Function *CalleeF = TheHelper->getFunction(Callee);
10851085 if (CalleeF == 0)
10861086 return ErrorV("Unknown function referenced");
1087
1087
10881088 // If argument mismatch error.
10891089 if (CalleeF->arg_size() != Args.size())
10901090 return ErrorV("Incorrect # arguments passed");
10941094 ArgsV.push_back(Args[i]->Codegen());
10951095 if (ArgsV.back() == 0) return 0;
10961096 }
1097
1097
10981098 return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
10991099 }
11001100
11011101 Value *IfExprAST::Codegen() {
11021102 Value *CondV = Cond->Codegen();
11031103 if (CondV == 0) return 0;
1104
1104
11051105 // Convert condition to a bool by comparing equal to 0.0.
1106 CondV = Builder.CreateFCmpONE(CondV,
1106 CondV = Builder.CreateFCmpONE(CondV,
11071107 ConstantFP::get(getGlobalContext(), APFloat(0.0)),
11081108 "ifcond");
1109
1109
11101110 Function *TheFunction = Builder.GetInsertBlock()->getParent();
1111
1111
11121112 // Create blocks for the then and else cases. Insert the 'then' block at the
11131113 // end of the function.
11141114 BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
11151115 BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
11161116 BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
1117
1117
11181118 Builder.CreateCondBr(CondV, ThenBB, ElseBB);
1119
1119
11201120 // Emit then value.
11211121 Builder.SetInsertPoint(ThenBB);
1122
1122
11231123 Value *ThenV = Then->Codegen();
11241124 if (ThenV == 0) return 0;
1125
1125
11261126 Builder.CreateBr(MergeBB);
11271127 // Codegen of 'Then' can change the current block, update ThenBB for the PHI.
11281128 ThenBB = Builder.GetInsertBlock();
1129
1129
11301130 // Emit else block.
11311131 TheFunction->getBasicBlockList().push_back(ElseBB);
11321132 Builder.SetInsertPoint(ElseBB);
1133
1133
11341134 Value *ElseV = Else->Codegen();
11351135 if (ElseV == 0) return 0;
1136
1136
11371137 Builder.CreateBr(MergeBB);
11381138 // Codegen of 'Else' can change the current block, update ElseBB for the PHI.
11391139 ElseBB = Builder.GetInsertBlock();
1140
1140
11411141 // Emit merge block.
11421142 TheFunction->getBasicBlockList().push_back(MergeBB);
11431143 Builder.SetInsertPoint(MergeBB);
11441144 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
11451145 "iftmp");
1146
1146
11471147 PN->addIncoming(ThenV, ThenBB);
11481148 PN->addIncoming(ElseV, ElseBB);
11491149 return PN;
11561156 // start = startexpr
11571157 // store start -> var
11581158 // goto loop
1159 // loop:
1159 // loop:
11601160 // ...
11611161 // bodyexpr
11621162 // ...
11691169 // store nextvar -> var
11701170 // br endcond, loop, endloop
11711171 // outloop:
1172
1172
11731173 Function *TheFunction = Builder.GetInsertBlock()->getParent();
11741174
11751175 // Create an alloca for the variable in the entry block.
11761176 AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
1177
1177
11781178 // Emit the start code first, without 'variable' in scope.
11791179 Value *StartVal = Start->Codegen();
11801180 if (StartVal == 0) return 0;
1181
1181
11821182 // Store the value into the alloca.
11831183 Builder.CreateStore(StartVal, Alloca);
1184
1184
11851185 // Make the new basic block for the loop header, inserting after current
11861186 // block.
11871187 BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
1188
1188
11891189 // Insert an explicit fall through from the current block to the LoopBB.
11901190 Builder.CreateBr(LoopBB);
11911191
11921192 // Start insertion in LoopBB.
11931193 Builder.SetInsertPoint(LoopBB);
1194
1194
11951195 // Within the loop, the variable is defined equal to the PHI node. If it
11961196 // shadows an existing variable, we have to restore it, so save it now.
11971197 AllocaInst *OldVal = NamedValues[VarName];
11981198 NamedValues[VarName] = Alloca;
1199
1199
12001200 // Emit the body of the loop. This, like any other expr, can change the
12011201 // current BB. Note that we ignore the value computed by the body, but don't
12021202 // allow an error.
12031203 if (Body->Codegen() == 0)
12041204 return 0;
1205
1205
12061206 // Emit the step value.
12071207 Value *StepVal;
12081208 if (Step) {
12121212 // If not specified, use 1.0.
12131213 StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
12141214 }
1215
1215
12161216 // Compute the end condition.
12171217 Value *EndCond = End->Codegen();
12181218 if (EndCond == 0) return EndCond;
1219
1219
12201220 // Reload, increment, and restore the alloca. This handles the case where
12211221 // the body of the loop mutates the variable.
12221222 Value *CurVar = Builder.CreateLoad(Alloca, VarName.c_str());
12231223 Value *NextVar = Builder.CreateFAdd(CurVar, StepVal, "nextvar");
12241224 Builder.CreateStore(NextVar, Alloca);
1225
1225
12261226 // Convert condition to a bool by comparing equal to 0.0.
1227 EndCond = Builder.CreateFCmpONE(EndCond,
1227 EndCond = Builder.CreateFCmpONE(EndCond,
12281228 ConstantFP::get(getGlobalContext(), APFloat(0.0)),
12291229 "loopcond");
1230
1230
12311231 // Create the "after loop" block and insert it.
12321232 BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
1233
1233
12341234 // Insert the conditional branch into the end of LoopEndBB.
12351235 Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
1236
1236
12371237 // Any new code will be inserted in AfterBB.
12381238 Builder.SetInsertPoint(AfterBB);
1239
1239
12401240 // Restore the unshadowed variable.
12411241 if (OldVal)
12421242 NamedValues[VarName] = OldVal;
12431243 else
12441244 NamedValues.erase(VarName);
12451245
1246
1246
12471247 // for expr always returns 0.0.
12481248 return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
12491249 }
12501250
12511251 Value *VarExprAST::Codegen() {
12521252 std::vector OldBindings;
1253
1253
12541254 Function *TheFunction = Builder.GetInsertBlock()->getParent();
12551255
12561256 // Register all variables and emit their initializer.
12571257 for (unsigned i = 0, e = VarNames.size(); i != e; ++i) {
12581258 const std::string &VarName = VarNames[i].first;
12591259 ExprAST *Init = VarNames[i].second;
1260
1260
12611261 // Emit the initializer before adding the variable to scope, this prevents
12621262 // the initializer from referencing the variable itself, and permits stuff
12631263 // like this:
12701270 } else { // If not specified, use 0.0.
12711271 InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
12721272 }
1273
1273
12741274 AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
12751275 Builder.CreateStore(InitVal, Alloca);
12761276
12771277 // Remember the old variable binding so that we can restore the binding when
12781278 // we unrecurse.
12791279 OldBindings.push_back(NamedValues[VarName]);
1280
1280
12811281 // Remember this binding.
12821282 NamedValues[VarName] = Alloca;
12831283 }
1284
1284
12851285 // Codegen the body, now that all vars are in scope.
12861286 Value *BodyVal = Body->Codegen();
12871287 if (BodyVal == 0) return 0;
1288
1288
12891289 // Pop all our variables from scope.
12901290 for (unsigned i = 0, e = VarNames.size(); i != e; ++i)
12911291 NamedValues[VarNames[i].first] = OldBindings[i];
12961296
12971297 Function *PrototypeAST::Codegen() {
12981298 // Make the function type: double(double,double) etc.
1299 std::vector Doubles(Args.size(),
1299 std::vector Doubles(Args.size(),
13001300 Type::getDoubleTy(getGlobalContext()));
13011301 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
13021302 Doubles, false);
13131313 // Delete the one we just made and get the existing one.
13141314 F->eraseFromParent();
13151315 F = M->getFunction(Name);
1316
1316
13171317 // If F already has a body, reject this.
13181318 if (!F->empty()) {
13191319 ErrorF("redefinition of function");
13201320 return 0;
13211321 }
1322
1322
13231323 // If F took a different number of args, reject.
13241324 if (F->arg_size() != Args.size()) {
13251325 ErrorF("redefinition of function with different # args");
13261326 return 0;
13271327 }
13281328 }
1329
1329
13301330 // Set names for all arguments.
13311331 unsigned Idx = 0;
13321332 for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();
13331333 ++AI, ++Idx)
13341334 AI->setName(Args[Idx]);
1335
1335
13361336 return F;
13371337 }
13381338
13541354
13551355 Function *FunctionAST::Codegen() {
13561356 NamedValues.clear();
1357
1357
13581358 Function *TheFunction = Proto->Codegen();
13591359 if (TheFunction == 0)
13601360 return 0;
1361
1361
13621362 // If this is an operator, install it.
13631363 if (Proto->isBinaryOp())
13641364 BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
1365
1365
13661366 // Create a new basic block to start insertion into.
13671367 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
13681368 Builder.SetInsertPoint(BB);
1369
1369
13701370 // Add all arguments to the symbol table and create their allocas.
13711371 Proto->CreateArgumentAllocas(TheFunction);
13721372
14271427 if (Function *LF = F->Codegen()) {
14281428 // JIT the function, returning a function pointer.
14291429 void *FPtr = TheHelper->getPointerToFunction(LF);
1430
1430
14311431 // Cast it to the right type (takes no arguments, returns a double) so we
14321432 // can call it as a native function.
14331433 double (*FP)() = (double (*)())(intptr_t)FPtr;
14641464 //===----------------------------------------------------------------------===//
14651465
14661466 /// putchard - putchar that takes a double and returns 0.
1467 extern "C"
1467 extern "C"
14681468 double putchard(double X) {
14691469 putchar((char)X);
14701470 return 0;
14711471 }
14721472
14731473 /// printd - printf that takes a double prints it as "%f\n", returning 0.
1474 extern "C"
1474 extern "C"
14751475 double printd(double X) {
14761476 printf("%f", X);
14771477 return 0;
14781478 }
14791479
1480 extern "C"
1480 extern "C"
14811481 double printlf() {
14821482 printf("\n");
14831483 return 0;
3636 cl::value_desc("input IR file name"));
3737
3838 cl::opt
39 VerboseOutput("verbose",
39 VerboseOutput("verbose",
4040 cl::desc("Enable verbose output (results, IR, etc.) to stderr"),
4141 cl::init(false));
4242
829829
830830 class HelpingMemoryManager : public SectionMemoryManager
831831 {
832 HelpingMemoryManager(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;
833 void operator=(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;
832 HelpingMemoryManager(const HelpingMemoryManager&) = delete;
833 void operator=(const HelpingMemoryManager&) = delete;
834834
835835 public:
836836 HelpingMemoryManager(MCJITHelper *Helper) : MasterHelper(Helper) {}
3131
3232 // primary
3333 tok_identifier = -4, tok_number = -5,
34
34
3535 // control
3636 tok_if = -6, tok_then = -7, tok_else = -8,
3737 tok_for = -9, tok_in = -10,
38
38
3939 // operators
4040 tok_binary = -11, tok_unary = -12,
41
41
4242 // var definition
4343 tok_var = -13
4444 };
8787 // Comment until end of line.
8888 do LastChar = getchar();
8989 while (LastChar != EOF && LastChar != '\n' && LastChar != '\r');
90
90
9191 if (LastChar != EOF)
9292 return gettok();
9393 }
94
94
9595 // Check for end of file. Don't eat the EOF.
9696 if (LastChar == EOF)
9797 return tok_eof;
135135 char Opcode;
136136 ExprAST *Operand;
137137 public:
138 UnaryExprAST(char opcode, ExprAST *operand)
138 UnaryExprAST(char opcode, ExprAST *operand)
139139 : Opcode(opcode), Operand(operand) {}
140140 virtual Value *Codegen();
141141 };
145145 char Op;
146146 ExprAST *LHS, *RHS;
147147 public:
148 BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs)
148 BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs)
149149 : Op(op), LHS(lhs), RHS(rhs) {}
150150 virtual Value *Codegen();
151151 };
188188 VarExprAST(const std::vector > &varnames,
189189 ExprAST *body)
190190 : VarNames(varnames), Body(body) {}
191
191
192192 virtual Value *Codegen();
193193 };
194194
203203 PrototypeAST(const std::string &name, const std::vector &args,
204204 bool isoperator = false, unsigned prec = 0)
205205 : Name(name), Args(args), isOperator(isoperator), Precedence(prec) {}
206
206
207207 bool isUnaryOp() const { return isOperator && Args.size() == 1; }
208208 bool isBinaryOp() const { return isOperator && Args.size() == 2; }
209
209
210210 char getOperatorName() const {
211211 assert(isUnaryOp() || isBinaryOp());
212212 return Name[Name.size()-1];
213213 }
214
214
215215 unsigned getBinaryPrecedence() const { return Precedence; }
216
216
217217 Function *Codegen();
218
218
219219 void CreateArgumentAllocas(Function *F);
220220 };
221221
226226 public:
227227 FunctionAST(PrototypeAST *proto, ExprAST *body)
228228 : Proto(proto), Body(body) {}
229
229
230230 Function *Codegen();
231231 };
232232
250250 static int GetTokPrecedence() {
251251 if (!isascii(CurTok))
252252 return -1;
253
253
254254 // Make sure it's a declared binop.
255255 int TokPrec = BinopPrecedence[CurTok];
256256 if (TokPrec <= 0) return -1;
269269 /// ::= identifier '(' expression* ')'
270270 static ExprAST *ParseIdentifierExpr() {
271271 std::string IdName = IdentifierStr;
272
272
273273 getNextToken(); // eat identifier.
274
274
275275 if (CurTok != '(') // Simple variable ref.
276276 return new VariableExprAST(IdName);
277
277
278278 // Call.
279279 getNextToken(); // eat (
280280 std::vector Args;
294294
295295 // Eat the ')'.
296296 getNextToken();
297
297
298298 return new CallExprAST(IdName, Args);
299299 }
300300
310310 getNextToken(); // eat (.
311311 ExprAST *V = ParseExpression();
312312 if (!V) return 0;
313
313
314314 if (CurTok != ')')
315315 return Error("expected ')'");
316316 getNextToken(); // eat ).
320320 /// ifexpr ::= 'if' expression 'then' expression 'else' expression
321321 static ExprAST *ParseIfExpr() {
322322 getNextToken(); // eat the if.
323
323
324324 // condition.
325325 ExprAST *Cond = ParseExpression();
326326 if (!Cond) return 0;
327
327
328328 if (CurTok != tok_then)
329329 return Error("expected then");
330330 getNextToken(); // eat the then
331
331
332332 ExprAST *Then = ParseExpression();
333333 if (Then == 0) return 0;
334
334
335335 if (CurTok != tok_else)
336336 return Error("expected else");
337
337
338338 getNextToken();
339
339
340340 ExprAST *Else = ParseExpression();
341341 if (!Else) return 0;
342
342
343343 return new IfExprAST(Cond, Then, Else);
344344 }
345345
349349
350350 if (CurTok != tok_identifier)
351351 return Error("expected identifier after for");
352
352
353353 std::string IdName = IdentifierStr;
354354 getNextToken(); // eat identifier.
355
355
356356 if (CurTok != '=')
357357 return Error("expected '=' after for");
358358 getNextToken(); // eat '='.
359
360
359
360
361361 ExprAST *Start = ParseExpression();
362362 if (Start == 0) return 0;
363363 if (CurTok != ',')
364364 return Error("expected ',' after for start value");
365365 getNextToken();
366
366
367367 ExprAST *End = ParseExpression();
368368 if (End == 0) return 0;
369
369
370370 // The step value is optional.
371371 ExprAST *Step = 0;
372372 if (CurTok == ',') {
374374 Step = ParseExpression();
375375 if (Step == 0) return 0;
376376 }
377
377
378378 if (CurTok != tok_in)
379379 return Error("expected 'in' after for");
380380 getNextToken(); // eat 'in'.
381
381
382382 ExprAST *Body = ParseExpression();
383383 if (Body == 0) return 0;
384384
385385 return new ForExprAST(IdName, Start, End, Step, Body);
386386 }
387387
388 /// varexpr ::= 'var' identifier ('=' expression)?
388 /// varexpr ::= 'var' identifier ('=' expression)?
389389 // (',' identifier ('=' expression)?)* 'in' expression
390390 static ExprAST *ParseVarExpr() {
391391 getNextToken(); // eat the var.
395395 // At least one variable name is required.
396396 if (CurTok != tok_identifier)
397397 return Error("expected identifier after var");
398
398
399399 while (1) {
400400 std::string Name = IdentifierStr;
401401 getNextToken(); // eat identifier.
404404 ExprAST *Init = 0;
405405 if (CurTok == '=') {
406406 getNextToken(); // eat the '='.
407
407
408408 Init = ParseExpression();
409409 if (Init == 0) return 0;
410410 }
411
411
412412 VarNames.push_back(std::make_pair(Name, Init));
413
413
414414 // End of var list, exit loop.
415415 if (CurTok != ',') break;
416416 getNextToken(); // eat the ','.
417
417
418418 if (CurTok != tok_identifier)
419419 return Error("expected identifier list after var");
420420 }
421
421
422422 // At this point, we have to have 'in'.
423423 if (CurTok != tok_in)
424424 return Error("expected 'in' keyword after 'var'");
425425 getNextToken(); // eat 'in'.
426
426
427427 ExprAST *Body = ParseExpression();
428428 if (Body == 0) return 0;
429
429
430430 return new VarExprAST(VarNames, Body);
431431 }
432432
456456 // If the current token is not an operator, it must be a primary expr.
457457 if (!isascii(CurTok) || CurTok == '(' || CurTok == ',')
458458 return ParsePrimary();
459
459
460460 // If this is a unary operator, read it.
461461 int Opc = CurTok;
462462 getNextToken();
471471 // If this is a binop, find its precedence.
472472 while (1) {
473473 int TokPrec = GetTokPrecedence();
474
474
475475 // If this is a binop that binds at least as tightly as the current binop,
476476 // consume it, otherwise we are done.
477477 if (TokPrec < ExprPrec)
478478 return LHS;
479
479
480480 // Okay, we know this is a binop.
481481 int BinOp = CurTok;
482482 getNextToken(); // eat binop
483
483
484484 // Parse the unary expression after the binary operator.
485485 ExprAST *RHS = ParseUnary();
486486 if (!RHS) return 0;
487
487
488488 // If BinOp binds less tightly with RHS than the operator after RHS, let
489489 // the pending operator take RHS as its LHS.
490490 int NextPrec = GetTokPrecedence();
492492 RHS = ParseBinOpRHS(TokPrec+1, RHS);
493493 if (RHS == 0) return 0;
494494 }
495
495
496496 // Merge LHS/RHS.
497497 LHS = new BinaryExprAST(BinOp, LHS, RHS);
498498 }
504504 static ExprAST *ParseExpression() {
505505 ExprAST *LHS = ParseUnary();
506506 if (!LHS) return 0;
507
507
508508 return ParseBinOpRHS(0, LHS);
509509 }
510510
514514 /// ::= unary LETTER (id)
515515 static PrototypeAST *ParsePrototype() {
516516 std::string FnName;
517
517
518518 unsigned Kind = 0; // 0 = identifier, 1 = unary, 2 = binary.
519519 unsigned BinaryPrecedence = 30;
520
520
521521 switch (CurTok) {
522522 default:
523523 return ErrorP("Expected function name in prototype");
543543 FnName += (char)CurTok;
544544 Kind = 2;
545545 getNextToken();
546
546
547547 // Read the precedence if present.
548548 if (CurTok == tok_number) {
549549 if (NumVal < 1 || NumVal > 100)
553553 }
554554 break;
555555 }
556
556
557557 if (CurTok != '(')
558558 return ErrorP("Expected '(' in prototype");
559
559
560560 std::vector ArgNames;
561561 while (getNextToken() == tok_identifier)
562562 ArgNames.push_back(IdentifierStr);
563563 if (CurTok != ')')
564564 return ErrorP("Expected ')' in prototype");
565
565
566566 // success.
567567 getNextToken(); // eat ')'.
568
568
569569 // Verify right number of names for operator.
570570 if (Kind && ArgNames.size() != Kind)
571571 return ErrorP("Invalid number of operands for operator");
572
572
573573 return new PrototypeAST(FnName, ArgNames, Kind != 0, BinaryPrecedence);
574574 }
575575
669669
670670 class HelpingMemoryManager : public SectionMemoryManager
671671 {
672 HelpingMemoryManager(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;
673 void operator=(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;
672 HelpingMemoryManager(const HelpingMemoryManager&) = delete;
673 void operator=(const HelpingMemoryManager&) = delete;
674674
675675 public:
676676 HelpingMemoryManager(MCJITHelper *Helper) : MasterHelper(Helper) {}
677677 virtual ~HelpingMemoryManager() {}
678678
679 /// This method returns the address of the specified function.
679 /// This method returns the address of the specified function.
680680 /// Our implementation will attempt to find functions in other
681681 /// modules associated with the MCJITHelper to cross link functions
682682 /// from one generated module to another.
738738
739739 // If we don't have a prototype yet, create one.
740740 if (!PF)
741 PF = Function::Create(F->getFunctionType(),
742 Function::ExternalLinkage,
743 FnName,
741 PF = Function::Create(F->getFunctionType(),
742 Function::ExternalLinkage,
743 FnName,
744744 OpenModule);
745745 return PF;
746746 }
884884 Value *UnaryExprAST::Codegen() {
885885 Value *OperandV = Operand->Codegen();
886886 if (OperandV == 0) return 0;
887
887
888888 Function *F = TheHelper->getFunction(MakeLegalFunctionName(std::string("unary")+Opcode));
889889 if (F == 0)
890890 return ErrorV("Unknown unary operator");
891
891
892892 return Builder.CreateCall(F, OperandV, "unop");
893893 }
894894
910910 Builder.CreateStore(Val, Variable);
911911 return Val;
912912 }
913
913
914914 Value *L = LHS->Codegen();
915915 Value *R = RHS->Codegen();
916916 if (L == 0 || R == 0) return 0;
917
917
918918 switch (Op) {
919919 case '+': return Builder.CreateFAdd(L, R, "addtmp");
920920 case '-': return Builder.CreateFSub(L, R, "subtmp");
927927 "booltmp");
928928 default: break;
929929 }
930
930
931931 // If it wasn't a builtin binary operator, it must be a user defined one. Emit
932932 // a call to it.
933933 Function *F = TheHelper->getFunction(MakeLegalFunctionName(std::string("binary")+Op));
934934 assert(F && "binary operator not found!");
935
935
936936 Value *Ops[] = { L, R };
937937 return Builder.CreateCall(F, Ops, "binop");
938938 }
942942 Function *CalleeF = TheHelper->getFunction(Callee);
943943 if (CalleeF == 0)
944944 return ErrorV("Unknown function referenced");
945
945
946946 // If argument mismatch error.
947947 if (CalleeF->arg_size() != Args.size())
948948 return ErrorV("Incorrect # arguments passed");
952952 ArgsV.push_back(Args[i]->Codegen());
953953 if (ArgsV.back() == 0) return 0;
954954 }
955
955
956956 return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
957957 }
958958
959959 Value *IfExprAST::Codegen() {
960960 Value *CondV = Cond->Codegen();
961961 if (CondV == 0) return 0;
962
962
963963 // Convert condition to a bool by comparing equal to 0.0.
964 CondV = Builder.CreateFCmpONE(CondV,
964 CondV = Builder.CreateFCmpONE(CondV,
965965 ConstantFP::get(getGlobalContext(), APFloat(0.0)),
966966 "ifcond");
967
967
968968 Function *TheFunction = Builder.GetInsertBlock()->getParent();
969
969
970970 // Create blocks for the then and else cases. Insert the 'then' block at the
971971 // end of the function.
972972 BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
973973 BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
974974 BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
975
975
976976 Builder.CreateCondBr(CondV, ThenBB, ElseBB);
977
977
978978 // Emit then value.
979979 Builder.SetInsertPoint(ThenBB);
980
980
981981 Value *ThenV = Then->Codegen();
982982 if (ThenV == 0) return 0;
983
983
984984 Builder.CreateBr(MergeBB);
985985 // Codegen of 'Then' can change the current block, update ThenBB for the PHI.
986986 ThenBB = Builder.GetInsertBlock();
987
987
988988 // Emit else block.
989989 TheFunction->getBasicBlockList().push_back(ElseBB);
990990 Builder.SetInsertPoint(ElseBB);
991
991
992992 Value *ElseV = Else->Codegen();
993993 if (ElseV == 0) return 0;
994
994
995995 Builder.CreateBr(MergeBB);
996996 // Codegen of 'Else' can change the current block, update ElseBB for the PHI.
997997 ElseBB = Builder.GetInsertBlock();
998
998
999999 // Emit merge block.
10001000 TheFunction->getBasicBlockList().push_back(MergeBB);
10011001 Builder.SetInsertPoint(MergeBB);
10021002 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
10031003 "iftmp");
1004
1004
10051005 PN->addIncoming(ThenV, ThenBB);
10061006 PN->addIncoming(ElseV, ElseBB);
10071007 return PN;
10141014 // start = startexpr
10151015 // store start -> var
10161016 // goto loop
1017 // loop:
1017 // loop:
10181018 // ...
10191019 // bodyexpr
10201020 // ...
10271027 // store nextvar -> var
10281028 // br endcond, loop, endloop
10291029 // outloop:
1030
1030
10311031 Function *TheFunction = Builder.GetInsertBlock()->getParent();
10321032
10331033 // Create an alloca for the variable in the entry block.
10341034 AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
1035
1035
10361036 // Emit the start code first, without 'variable' in scope.
10371037 Value *StartVal = Start->Codegen();
10381038 if (StartVal == 0) return 0;
1039
1039
10401040 // Store the value into the alloca.
10411041 Builder.CreateStore(StartVal, Alloca);
1042
1042
10431043 // Make the new basic block for the loop header, inserting after current
10441044 // block.
10451045 BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
1046
1046
10471047 // Insert an explicit fall through from the current block to the LoopBB.
10481048 Builder.CreateBr(LoopBB);
10491049
10501050 // Start insertion in LoopBB.
10511051 Builder.SetInsertPoint(LoopBB);
1052
1052
10531053 // Within the loop, the variable is defined equal to the PHI node. If it
10541054 // shadows an existing variable, we have to restore it, so save it now.
10551055 AllocaInst *OldVal = NamedValues[VarName];
10561056 NamedValues[VarName] = Alloca;
1057
1057
10581058 // Emit the body of the loop. This, like any other expr, can change the
10591059 // current BB. Note that we ignore the value computed by the body, but don't
10601060 // allow an error.
10611061 if (Body->Codegen() == 0)
10621062 return 0;
1063
1063
10641064 // Emit the step value.
10651065 Value *StepVal;
10661066 if (Step) {
10701070 // If not specified, use 1.0.
10711071 StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
10721072 }
1073
1073
10741074 // Compute the end condition.
10751075 Value *EndCond = End->Codegen();
10761076 if (EndCond == 0) return EndCond;
1077
1077
10781078 // Reload, increment, and restore the alloca. This handles the case where
10791079 // the body of the loop mutates the variable.
10801080 Value *CurVar = Builder.CreateLoad(Alloca, VarName.c_str());
10811081 Value *NextVar = Builder.CreateFAdd(CurVar, StepVal, "nextvar");
10821082 Builder.CreateStore(NextVar, Alloca);
1083
1083
10841084 // Convert condition to a bool by comparing equal to 0.0.
1085 EndCond = Builder.CreateFCmpONE(EndCond,
1085 EndCond = Builder.CreateFCmpONE(EndCond,
10861086 ConstantFP::get(getGlobalContext(), APFloat(0.0)),
10871087 "loopcond");
1088
1088
10891089 // Create the "after loop" block and insert it.
10901090 BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
1091
1091
10921092 // Insert the conditional branch into the end of LoopEndBB.
10931093 Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
1094
1094
10951095 // Any new code will be inserted in AfterBB.
10961096 Builder.SetInsertPoint(AfterBB);
1097
1097
10981098 // Restore the unshadowed variable.
10991099 if (OldVal)
11001100 NamedValues[VarName] = OldVal;
11011101 else
11021102 NamedValues.erase(VarName);
11031103
1104
1104
11051105 // for expr always returns 0.0.
11061106 return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
11071107 }
11081108
11091109 Value *VarExprAST::Codegen() {
11101110 std::vector OldBindings;
1111
1111
11121112 Function *TheFunction = Builder.GetInsertBlock()->getParent();
11131113
11141114 // Register all variables and emit their initializer.
11151115 for (unsigned i = 0, e = VarNames.size(); i != e; ++i) {
11161116 const std::string &VarName = VarNames[i].first;
11171117 ExprAST *Init = VarNames[i].second;
1118
1118
11191119 // Emit the initializer before adding the variable to scope, this prevents
11201120 // the initializer from referencing the variable itself, and permits stuff
11211121 // like this:
11281128 } else { // If not specified, use 0.0.
11291129 InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
11301130 }
1131
1131
11321132 AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
11331133 Builder.CreateStore(InitVal, Alloca);
11341134
11351135 // Remember the old variable binding so that we can restore the binding when
11361136 // we unrecurse.
11371137 OldBindings.push_back(NamedValues[VarName]);
1138
1138
11391139 // Remember this binding.
11401140 NamedValues[VarName] = Alloca;
11411141 }
1142
1142
11431143 // Codegen the body, now that all vars are in scope.
11441144 Value *BodyVal = Body->Codegen();
11451145 if (BodyVal == 0) return 0;
1146
1146
11471147 // Pop all our variables from scope.
11481148 for (unsigned i = 0, e = VarNames.size(); i != e; ++i)
11491149 NamedValues[VarNames[i].first] = OldBindings[i];
11541154
11551155 Function *PrototypeAST::Codegen() {
11561156 // Make the function type: double(double,double) etc.
1157 std::vector Doubles(Args.size(),
1157 std::vector Doubles(Args.size(),
11581158 Type::getDoubleTy(getGlobalContext()));
11591159 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
11601160 Doubles, false);
11711171 // Delete the one we just made and get the existing one.
11721172 F->eraseFromParent();
11731173 F = M->getFunction(Name);
1174
1174
11751175 // If F already has a body, reject this.
11761176 if (!F->empty()) {
11771177 ErrorF("redefinition of function");
11781178 return 0;
11791179 }
1180
1180
11811181 // If F took a different number of args, reject.
11821182 if (F->arg_size() != Args.size()) {
11831183 ErrorF("redefinition of function with different # args");
11841184 return 0;
11851185 }
11861186 }
1187
1187
11881188 // Set names for all arguments.
11891189 unsigned Idx = 0;
11901190 for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();
11911191 ++AI, ++Idx)
11921192 AI->setName(Args[Idx]);
1193
1193
11941194 return F;
11951195 }
11961196
12121212
12131213 Function *FunctionAST::Codegen() {
12141214 NamedValues.clear();
1215
1215
12161216 Function *TheFunction = Proto->Codegen();
12171217 if (TheFunction == 0)
12181218 return 0;
1219
1219
12201220 // If this is an operator, install it.
12211221 if (Proto->isBinaryOp())
12221222 BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
1223
1223
12241224 // Create a new basic block to start insertion into.
12251225 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
12261226 Builder.SetInsertPoint(BB);
1227
1227
12281228 // Add all arguments to the symbol table and create their allocas.
12291229 Proto->CreateArgumentAllocas(TheFunction);
12301230
12371237
12381238 return TheFunction;
12391239 }
1240
1240
12411241 // Error reading body, remove function.
12421242 TheFunction->eraseFromParent();
12431243
12841284 if (Function *LF = F->Codegen()) {
12851285 // JIT the function, returning a function pointer.
12861286 void *FPtr = TheHelper->getPointerToFunction(LF);
1287
1287
12881288 // Cast it to the right type (takes no arguments, returns a double) so we
12891289 // can call it as a native function.
12901290 double (*FP)() = (double (*)())(intptr_t)FPtr;
13211321 //===----------------------------------------------------------------------===//
13221322
13231323 /// putchard - putchar that takes a double and returns 0.
1324 extern "C"
1324 extern "C"
13251325 double putchard(double X) {
13261326 putchar((char)X);
13271327 return 0;
13281328 }
13291329
13301330 /// printd - printf that takes a double prints it as "%f\n", returning 0.
1331 extern "C"
1331 extern "C"
13321332 double printd(double X) {
13331333 printf("%f", X);
13341334 return 0;
13351335 }
13361336
1337 extern "C"
1337 extern "C"
13381338 double printlf() {
13391339 printf("\n");
13401340 return 0;
3333
3434 // primary
3535 tok_identifier = -4, tok_number = -5,
36
36
3737 // control
3838 tok_if = -6, tok_then = -7, tok_else = -8,
3939 tok_for = -9, tok_in = -10,
40
40
4141 // operators
4242 tok_binary = -11, tok_unary = -12,
43
43
4444 // var definition
4545 tok_var = -13
4646 };
8989 // Comment until end of line.
9090 do LastChar = getchar();
9191 while (LastChar != EOF && LastChar != '\n' && LastChar != '\r');
92
92
9393 if (LastChar != EOF)
9494 return gettok();
9595 }
96
96
9797 // Check for end of file. Don't eat the EOF.
9898 if (LastChar == EOF)
9999 return tok_eof;
137137 char Opcode;
138138 ExprAST *Operand;
139139 public:
140 UnaryExprAST(char opcode, ExprAST *operand)
140 UnaryExprAST(char opcode, ExprAST *operand)
141141 : Opcode(opcode), Operand(operand) {}
142142 virtual Value *Codegen();
143143 };
147147 char Op;
148148 ExprAST *LHS, *RHS;
149149 public:
150 BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs)
150 BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs)
151151 : Op(op), LHS(lhs), RHS(rhs) {}
152152 virtual Value *Codegen();
153153 };
190190 VarExprAST(const std::vector > &varnames,
191191 ExprAST *body)
192192 : VarNames(varnames), Body(body) {}
193
193
194194 virtual Value *Codegen();
195195 };
196196
205205 PrototypeAST(const std::string &name, const std::vector &args,
206206 bool isoperator = false, unsigned prec = 0)
207207 : Name(name), Args(args), isOperator(isoperator), Precedence(prec) {}
208
208
209209 bool isUnaryOp() const { return isOperator && Args.size() == 1; }
210210 bool isBinaryOp() const { return isOperator && Args.size() == 2; }
211
211
212212 char getOperatorName() const {
213213 assert(isUnaryOp() || isBinaryOp());
214214 return Name[Name.size()-1];
215215 }
216
216
217217 unsigned getBinaryPrecedence() const { return Precedence; }
218
218
219219 Function *Codegen();
220
220
221221 void CreateArgumentAllocas(Function *F);
222222 };
223223
228228 public:
229229 FunctionAST(PrototypeAST *proto, ExprAST *body)
230230 : Proto(proto), Body(body) {}
231
231
232232 Function *Codegen();
233233 };
234234
252252 static int GetTokPrecedence() {
253253 if (!isascii(CurTok))
254254 return -1;
255
255
256256 // Make sure it's a declared binop.
257257 int TokPrec = BinopPrecedence[CurTok];
258258 if (TokPrec <= 0) return -1;
271271 /// ::= identifier '(' expression* ')'
272272 static ExprAST *ParseIdentifierExpr() {
273273 std::string IdName = IdentifierStr;
274
274
275275 getNextToken(); // eat identifier.
276
276
277277 if (CurTok != '(') // Simple variable ref.
278278 return new VariableExprAST(IdName);
279
279
280280 // Call.
281281 getNextToken(); // eat (
282282 std::vector Args;
296296
297297 // Eat the ')'.
298298 getNextToken();
299
299
300300 return new CallExprAST(IdName, Args);
301301 }
302302
312312 getNextToken(); // eat (.
313313 ExprAST *V = ParseExpression();
314314 if (!V) return 0;
315
315
316316 if (CurTok != ')')
317317 return Error("expected ')'");
318318 getNextToken(); // eat ).
322322 /// ifexpr ::= 'if' expression 'then' expression 'else' expression
323323 static ExprAST *ParseIfExpr() {
324324 getNextToken(); // eat the if.
325
325
326326 // condition.
327327 ExprAST *Cond = ParseExpression();
328328 if (!Cond) return 0;
329
329
330330 if (CurTok != tok_then)
331331 return Error("expected then");
332332 getNextToken(); // eat the then
333
333
334334 ExprAST *Then = ParseExpression();
335335 if (Then == 0) return 0;
336
336
337337 if (CurTok != tok_else)
338338 return Error("expected else");
339
339
340340 getNextToken();
341
341
342342 ExprAST *Else = ParseExpression();
343343 if (!Else) return 0;
344
344
345345 return new IfExprAST(Cond, Then, Else);
346346 }
347347
351351
352352 if (CurTok != tok_identifier)
353353 return Error("expected identifier after for");
354
354
355355 std::string IdName = IdentifierStr;
356356 getNextToken(); // eat identifier.
357
357
358358 if (CurTok != '=')
359359 return Error("expected '=' after for");
360360 getNextToken(); // eat '='.
361
362
361
362
363363 ExprAST *Start = ParseExpression();
364364 if (Start == 0) return 0;
365365 if (CurTok != ',')
366366 return Error("expected ',' after for start value");
367367 getNextToken();
368
368
369369 ExprAST *End = ParseExpression();
370370 if (End == 0) return 0;
371
371
372372 // The step value is optional.
373373 ExprAST *Step = 0;
374374 if (CurTok == ',') {
376376 Step = ParseExpression();
377377 if (Step == 0) return 0;
378378 }
379
379
380380 if (CurTok != tok_in)
381381 return Error("expected 'in' after for");
382382 getNextToken(); // eat 'in'.
383
383
384384 ExprAST *Body = ParseExpression();
385385 if (Body == 0) return 0;
386386
387387 return new ForExprAST(IdName, Start, End, Step, Body);
388388 }
389389
390 /// varexpr ::= 'var' identifier ('=' expression)?
390 /// varexpr ::= 'var' identifier ('=' expression)?
391391 // (',' identifier ('=' expression)?)* 'in' expression
392392 static ExprAST *ParseVarExpr() {
393393 getNextToken(); // eat the var.
397397 // At least one variable name is required.
398398 if (CurTok != tok_identifier)
399399 return Error("expected identifier after var");
400
400
401401 while (1) {
402402 std::string Name = IdentifierStr;
403403 getNextToken(); // eat identifier.
406406 ExprAST *Init = 0;
407407 if (CurTok == '=') {
408408 getNextToken(); // eat the '='.
409
409
410410 Init = ParseExpression();
411411 if (Init == 0) return 0;
412412 }
413
413
414414 VarNames.push_back(std::make_pair(Name, Init));
415
415
416416 // End of var list, exit loop.
417417 if (CurTok != ',') break;
418418 getNextToken(); // eat the ','.
419
419
420420 if (CurTok != tok_identifier)
421421 return Error("expected identifier list after var");
422422 }
423
423
424424 // At this point, we have to have 'in'.
425425 if (CurTok != tok_in)
426426 return Error("expected 'in' keyword after 'var'");
427427 getNextToken(); // eat 'in'.
428
428
429429 ExprAST *Body = ParseExpression();
430430 if (Body == 0) return 0;
431
431
432432 return new VarExprAST(VarNames, Body);
433433 }
434434
458458 // If the current token is not an operator, it must be a primary expr.
459459 if (!isascii(CurTok) || CurTok == '(' || CurTok == ',')
460460 return ParsePrimary();
461
461
462462 // If this is a unary operator, read it.
463463 int Opc = CurTok;
464464 getNextToken();
473473 // If this is a binop, find its precedence.
474474 while (1) {
475475 int TokPrec = GetTokPrecedence();
476
476
477477 // If this is a binop that binds at least as tightly as the current binop,
478478 // consume it, otherwise we are done.
479479 if (TokPrec < ExprPrec)
480480 return LHS;
481
481
482482 // Okay, we know this is a binop.
483483 int BinOp = CurTok;
484484 getNextToken(); // eat binop
485
485
486486 // Parse the unary expression after the binary operator.
487487 ExprAST *RHS = ParseUnary();
488488 if (!RHS) return 0;
489
489
490490 // If BinOp binds less tightly with RHS than the operator after RHS, let
491491 // the pending operator take RHS as its LHS.
492492 int NextPrec = GetTokPrecedence();
494494 RHS = ParseBinOpRHS(TokPrec+1, RHS);
495495 if (RHS == 0) return 0;
496496 }
497
497
498498 // Merge LHS/RHS.
499499 LHS = new BinaryExprAST(BinOp, LHS, RHS);
500500 }
506506 static ExprAST *ParseExpression() {
507507 ExprAST *LHS = ParseUnary();
508508 if (!LHS) return 0;
509
509
510510 return ParseBinOpRHS(0, LHS);
511511 }
512512
516516 /// ::= unary LETTER (id)
517517 static PrototypeAST *ParsePrototype() {
518518 std::string FnName;
519
519
520520 unsigned Kind = 0; // 0 = identifier, 1 = unary, 2 = binary.
521521 unsigned BinaryPrecedence = 30;
522
522
523523 switch (CurTok) {
524524 default:
525525 return ErrorP("Expected function name in prototype");
545545 FnName += (char)CurTok;
546546 Kind = 2;
547547 getNextToken();
548
548
549549 // Read the precedence if present.
550550 if (CurTok == tok_number) {
551551 if (NumVal < 1 || NumVal > 100)
555555 }
556556 break;
557557 }
558
558
559559 if (CurTok != '(')
560560 return ErrorP("Expected '(' in prototype");
561
561
562562 std::vector ArgNames;
563563 while (getNextToken() == tok_identifier)
564564 ArgNames.push_back(IdentifierStr);
565565 if (CurTok != ')')
566566 return ErrorP("Expected ')' in prototype");
567
567
568568 // success.
569569 getNextToken(); // eat ')'.
570
570
571571 // Verify right number of names for operator.
572572 if (Kind && ArgNames.size() != Kind)
573573 return ErrorP("Invalid number of operands for operator");
574
574
575575 return new PrototypeAST(FnName, ArgNames, Kind != 0, BinaryPrecedence);
576576 }
577577
672672
673673 class HelpingMemoryManager : public SectionMemoryManager
674674 {
675 HelpingMemoryManager(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;
676 void operator=(const HelpingMemoryManager&) LLVM_DELETED_FUNCTION;
675 HelpingMemoryManager(const HelpingMemoryManager&) = delete;
676 void operator=(const HelpingMemoryManager&) = delete;
677677
678678 public:
679679 HelpingMemoryManager(MCJITHelper *Helper) : MasterHelper(Helper) {}
680680 virtual ~HelpingMemoryManager() {}
681681
682 /// This method returns the address of the specified function.
682 /// This method returns the address of the specified function.
683683 /// Our implementation will attempt to find functions in other
684684 /// modules associated with the MCJITHelper to cross link functions
685685 /// from one generated module to another.
748748
749749 // If we don't have a prototype yet, create one.
750750 if (!PF)
751 PF = Function::Create(F->getFunctionType(),
752 Function::ExternalLinkage,
753 FnName,
751 PF = Function::Create(F->getFunctionType(),
752 Function::ExternalLinkage,
753 FnName,
754754 OpenModule);
755755 return PF;
756756 }
924924 Value *UnaryExprAST::Codegen() {
925925 Value *OperandV = Operand->Codegen();
926926 if (OperandV == 0) return 0;
927
927
928928 Function *F = TheHelper->getFunction(MakeLegalFunctionName(std::string("unary")+Opcode));
929929 if (F == 0)
930930 return ErrorV("Unknown unary operator");
931
931
932932 return Builder.CreateCall(F, OperandV, "unop");
933933 }
934934
950950 Builder.CreateStore(Val, Variable);
951951 return Val;
952952 }
953
953
954954 Value *L = LHS->Codegen();
955955 Value *R = RHS->Codegen();
956956 if (L == 0 || R == 0) return 0;
957
957
958958 switch (Op) {
959959 case '+': return Builder.CreateFAdd(L, R, "addtmp");
960960 case '-': return Builder.CreateFSub(L, R, "subtmp");
967967 "booltmp");
968968 default: break;
969969 }
970
970
971971 // If it wasn't a builtin binary operator, it must be a user defined one. Emit
972972 // a call to it.
973973 Function *F = TheHelper->getFunction(MakeLegalFunctionName(std::string("binary")+Op));
974974 assert(F && "binary operator not found!");
975
975
976976 Value *Ops[] = { L, R };
977977 return Builder.CreateCall(F, Ops, "binop");
978978 }
982982 Function *CalleeF = TheHelper->getFunction(Callee);
983983 if (CalleeF == 0)
984984 return ErrorV("Unknown function referenced");
985
985
986986 // If argument mismatch error.
987987 if (CalleeF->arg_size() != Args.size())
988988 return ErrorV("Incorrect # arguments passed");
992992 ArgsV.push_back(Args[i]->Codegen());
993993 if (ArgsV.back() == 0) return 0;
994994 }
995
995
996996 return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
997997 }
998998
999999 Value *IfExprAST::Codegen() {
10001000 Value *CondV = Cond->Codegen();
10011001 if (CondV == 0) return 0;
1002
1002
10031003 // Convert condition to a bool by comparing equal to 0.0.
1004 CondV = Builder.CreateFCmpONE(CondV,
1004 CondV = Builder.CreateFCmpONE(CondV,
10051005 ConstantFP::get(getGlobalContext(), APFloat(0.0)),
10061006 "ifcond");
1007
1007
10081008 Function *TheFunction = Builder.GetInsertBlock()->getParent();
1009
1009
10101010 // Create blocks for the then and else cases. Insert the 'then' block at the
10111011 // end of the function.
10121012 BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
10131013 BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
10141014 BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
1015
1015
10161016 Builder.CreateCondBr(CondV, ThenBB, ElseBB);
1017
1017
10181018 // Emit then value.
10191019 Builder.SetInsertPoint(ThenBB);
1020
1020
10211021 Value *ThenV = Then->Codegen();
10221022 if (ThenV == 0) return 0;
1023
1023
10241024 Builder.CreateBr(MergeBB);
10251025 // Codegen of 'Then' can change the current block, update ThenBB for the PHI.
10261026 ThenBB = Builder.GetInsertBlock();
1027
1027
10281028 // Emit else block.
10291029 TheFunction->getBasicBlockList().push_back(ElseBB);
10301030 Builder.SetInsertPoint(ElseBB);
1031
1031
10321032 Value *ElseV = Else->Codegen();
10331033 if (ElseV == 0) return 0;
1034
1034
10351035 Builder.CreateBr(MergeBB);
10361036 // Codegen of 'Else' can change the current block, update ElseBB for the PHI.
10371037 ElseBB = Builder.GetInsertBlock();
1038
1038
10391039 // Emit merge block.
10401040 TheFunction->getBasicBlockList().push_back(MergeBB);
10411041 Builder.SetInsertPoint(MergeBB);
10421042 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
10431043 "iftmp");
1044
1044
10451045 PN->addIncoming(ThenV, ThenBB);
10461046 PN->addIncoming(ElseV, ElseBB);
10471047 return PN;
10541054 // start = startexpr
10551055 // store start -> var
10561056 // goto loop
1057 // loop:
1057 // loop:
10581058 // ...
10591059 // bodyexpr
10601060 // ...
10671067 // store nextvar -> var
10681068 // br endcond, loop, endloop
10691069 // outloop:
1070
1070
10711071 Function *TheFunction = Builder.GetInsertBlock()->getParent();
10721072
10731073 // Create an alloca for the variable in the entry block.
10741074 AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
1075
1075
10761076 // Emit the start code first, without 'variable' in scope.
10771077 Value *StartVal = Start->Codegen();
10781078 if (StartVal == 0) return 0;
1079
1079
10801080 // Store the value into the alloca.
10811081 Builder.CreateStore(StartVal, Alloca);
1082
1082
10831083 // Make the new basic block for the loop header, inserting after current
10841084 // block.
10851085 BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
1086
1086
10871087 // Insert an explicit fall through from the current block to the LoopBB.
10881088 Builder.CreateBr(LoopBB);
10891089
10901090 // Start insertion in LoopBB.
10911091 Builder.SetInsertPoint(LoopBB);
1092
1092
10931093 // Within the loop, the variable is defined equal to the PHI node. If it
10941094 // shadows an existing variable, we have to restore it, so save it now.
10951095 AllocaInst *OldVal = NamedValues[VarName];
10961096 NamedValues[VarName] = Alloca;
1097
1097
10981098 // Emit the body of the loop. This, like any other expr, can change the
10991099 // current BB. Note that we ignore the value computed by the body, but don't
11001100 // allow an error.
11011101 if (Body->Codegen() == 0)
11021102 return 0;
1103
1103
11041104 // Emit the step value.
11051105 Value *StepVal;
11061106 if (Step) {
11101110 // If not specified, use 1.0.
11111111 StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
11121112 }
1113
1113
11141114 // Compute the end condition.
11151115 Value *EndCond = End->Codegen();
11161116 if (EndCond == 0) return EndCond;
1117
1117
11181118 // Reload, increment, and restore the alloca. This handles the case where
11191119 // the body of the loop mutates the variable.
11201120 Value *CurVar = Builder.CreateLoad(Alloca, VarName.c_str());
11211121 Value *NextVar = Builder.CreateFAdd(CurVar, StepVal, "nextvar");
11221122 Builder.CreateStore(NextVar, Alloca);
1123
1123
11241124 // Convert condition to a bool by comparing equal to 0.0.
1125 EndCond = Builder.CreateFCmpONE(EndCond,
1125 EndCond = Builder.CreateFCmpONE(EndCond,
11261126 ConstantFP::get(getGlobalContext(), APFloat(0.0)),
11271127 "loopcond");
1128
1128
11291129 // Create the "after loop" block and insert it.
11301130 BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
1131
1131
11321132 // Insert the conditional branch into the end of LoopEndBB.
11331133 Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
1134
1134
11351135 // Any new code will be inserted in AfterBB.
11361136 Builder.SetInsertPoint(AfterBB);
1137
1137
11381138 // Restore the unshadowed variable.
11391139 if (OldVal)
11401140 NamedValues[VarName] = OldVal;
11411141 else
11421142 NamedValues.erase(VarName);
11431143
1144
1144
11451145 // for expr always returns 0.0.
11461146 return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
11471147 }
11481148
11491149 Value *VarExprAST::Codegen() {
11501150 std::vector OldBindings;
1151
1151
11521152 Function *TheFunction = Builder.GetInsertBlock()->getParent();
11531153
11541154 // Register all variables and emit their initializer.
11551155 for (unsigned i = 0, e = VarNames.size(); i != e; ++i) {
11561156 const std::string &VarName = VarNames[i].first;
11571157 ExprAST *Init = VarNames[i].second;
1158
1158
11591159 // Emit the initializer before adding the variable to scope, this prevents
11601160 // the initializer from referencing the variable itself, and permits stuff
11611161 // like this:
11681168 } else { // If not specified, use 0.0.
11691169 InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
11701170 }
1171
1171
11721172 AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
11731173 Builder.CreateStore(InitVal, Alloca);
11741174
11751175 // Remember the old variable binding so that we can restore the binding when
11761176 // we unrecurse.
11771177 OldBindings.push_back(NamedValues[VarName]);
1178
1178
11791179 // Remember this binding.
11801180 NamedValues[VarName] = Alloca;
11811181 }
1182
1182
11831183 // Codegen the body, now that all vars are in scope.
11841184 Value *BodyVal = Body->Codegen();
11851185 if (BodyVal == 0) return 0;
1186
1186
11871187 // Pop all our variables from scope.
11881188 for (unsigned i = 0, e = VarNames.size(); i != e; ++i)
11891189 NamedValues[VarNames[i].first] = OldBindings[i];
11941194
11951195 Function *PrototypeAST::Codegen() {
11961196 // Make the function type: double(double,double) etc.
1197 std::vector Doubles(Args.size(),
1197 std::vector Doubles(Args.size(),
11981198 Type::getDoubleTy(getGlobalContext()));
11991199 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
12001200 Doubles, false);
12111211 // Delete the one we just made and get the existing one.
12121212 F->eraseFromParent();
12131213 F = M->getFunction(Name);
1214
1214
12151215 // If F already has a body, reject this.
12161216 if (!F->empty()) {
12171217 ErrorF("redefinition of function");
12181218 return 0;
12191219 }
1220
1220
12211221 // If F took a different number of args, reject.
12221222 if (F->arg_size() != Args.size()) {
12231223 ErrorF("redefinition of function with different # args");
12241224 return 0;
12251225 }
12261226 }
1227
1227
12281228 // Set names for all arguments.
12291229 unsigned Idx = 0;
12301230 for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();
12311231 ++AI, ++Idx)
12321232 AI->setName(Args[Idx]);
1233
1233
12341234 return F;
12351235 }
12361236
12521252
12531253 Function *FunctionAST::Codegen() {
12541254 NamedValues.clear();
1255
1255
12561256 Function *TheFunction = Proto->Codegen();
12571257 if (TheFunction == 0)
12581258 return 0;
1259
1259
12601260 // If this is an operator, install it.
12611261 if (Proto->isBinaryOp())
12621262 BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
1263
1263
12641264 // Create a new basic block to start insertion into.
12651265 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
12661266 Builder.SetInsertPoint(BB);
1267
1267
12681268 // Add all arguments to the symbol table and create their allocas.
12691269 Proto->CreateArgumentAllocas(TheFunction);
12701270
13251325 if (Function *LF = F->Codegen()) {
13261326 // JIT the function, returning a function pointer.
13271327 void *FPtr = TheHelper->getPointerToFunction(LF);
1328
1328
13291329 // Cast it to the right type (takes no arguments, returns a double) so we
13301330 // can call it as a native function.
13311331 double (*FP)() = (double (*)())(intptr_t)FPtr;
13621362 //===----------------------------------------------------------------------===//
13631363
13641364 /// putchard - putchar that takes a double and returns 0.
1365 extern "C"
1365 extern "C"
13661366 double putchard(double X) {
13671367 putchar((char)X);
13681368 return 0;
13691369 }
13701370
13711371 /// printd - printf that takes a double prints it as "%f\n", returning 0.
1372 extern "C"
1372 extern "C"
13731373 double printd(double X) {
13741374 printf("%f", X);
13751375 return 0;
13761376 }
13771377
1378 extern "C"
1378 extern "C"
13791379 double printlf() {
13801380 printf("\n");
13811381 return 0;
375375 /// The definition of equality is not straightforward for floating point, so
376376 /// we won't use operator==. Use one of the following, or write whatever it
377377 /// is you really mean.
378 bool operator==(const APFloat &) const LLVM_DELETED_FUNCTION;
378 bool operator==(const APFloat &) const = delete;
379379
380380 /// IEEE comparison with another floating point number (NaNs compare
381381 /// unordered, 0==-0).
3232
3333 friend class ImmutableListFactory;
3434
35 void operator=(const ImmutableListImpl&) LLVM_DELETED_FUNCTION;
36 ImmutableListImpl(const ImmutableListImpl&) LLVM_DELETED_FUNCTION;
35 void operator=(const ImmutableListImpl&) = delete;
36 ImmutableListImpl(const ImmutableListImpl&) = delete;
3737
3838 public:
3939 const T& getHead() const { return Head; }
121121 }
122122
123123 private:
124 Factory(const Factory& RHS) LLVM_DELETED_FUNCTION;
125 void operator=(const Factory& RHS) LLVM_DELETED_FUNCTION;
124 Factory(const Factory& RHS) = delete;
125 void operator=(const Factory& RHS) = delete;
126126 };
127127
128128 bool contains(key_type_ref K) const {
10131013 }
10141014
10151015 private:
1016 Factory(const Factory& RHS) LLVM_DELETED_FUNCTION;
1017 void operator=(const Factory& RHS) LLVM_DELETED_FUNCTION;
1016 Factory(const Factory& RHS) = delete;
1017 void operator=(const Factory& RHS) = delete;
10181018 };
10191019
10201020 friend class Factory;
339339 /// This function isn't used and is only here to provide better compile errors.
340340 template
341341 typename std::enable_if::value != 0>::type
342 make_unique(Args &&...) LLVM_DELETED_FUNCTION;
342 make_unique(Args &&...) = delete;
343343
344344 struct FreeDeleter {
345345 void operator()(void* v) {
8989 /// LastValInScope - This is the last value that was inserted for this scope
9090 /// or null if none have been inserted yet.
9191 ScopedHashTableVal *LastValInScope;
92 void operator=(ScopedHashTableScope&) LLVM_DELETED_FUNCTION;
93 ScopedHashTableScope(ScopedHashTableScope&) LLVM_DELETED_FUNCTION;
92 void operator=(ScopedHashTableScope&) = delete;
93 ScopedHashTableScope(ScopedHashTableScope&) = delete;
9494 public:
9595 ScopedHashTableScope(ScopedHashTable &HT);
9696 ~ScopedHashTableScope();
131131 /// Grow - Allocate a larger backing store for the buckets and move it over.
132132 void Grow(unsigned NewSize);
133133
134 void operator=(const SmallPtrSetImplBase &RHS) LLVM_DELETED_FUNCTION;
134 void operator=(const SmallPtrSetImplBase &RHS) = delete;
135135 protected:
136136 /// swap - Swaps the elements of two sets.
137137 /// Note: This method assumes that both sets have the same small size.
241241 class SmallPtrSetImpl : public SmallPtrSetImplBase {
242242 typedef PointerLikeTypeTraits PtrTraits;
243243
244 SmallPtrSetImpl(const SmallPtrSetImpl&) LLVM_DELETED_FUNCTION;
244 SmallPtrSetImpl(const SmallPtrSetImpl&) = delete;
245245 protected:
246246 // Constructors that forward to the base.
247247 SmallPtrSetImpl(const void **SmallStorage, const SmallPtrSetImpl &that)
342342 class SmallVectorImpl : public SmallVectorTemplateBase::value> {
343343 typedef SmallVectorTemplateBase::value > SuperClass;
344344
345 SmallVectorImpl(const SmallVectorImpl&) LLVM_DELETED_FUNCTION;
345 SmallVectorImpl(const SmallVectorImpl&) = delete;
346346 public:
347347 typedef typename SuperClass::iterator iterator;
348348 typedef typename SuperClass::size_type size_type;
132132
133133 // Disable copy construction and assignment.
134134 // This data structure is not meant to be used that way.
135 SparseMultiSet(const SparseMultiSet&) LLVM_DELETED_FUNCTION;
136 SparseMultiSet &operator=(const SparseMultiSet&) LLVM_DELETED_FUNCTION;
135 SparseMultiSet(const SparseMultiSet&) = delete;
136 SparseMultiSet &operator=(const SparseMultiSet&) = delete;
137137
138138 /// Whether the given entry is the head of the list. List heads's previous
139139 /// pointers are to the tail of the list, allowing for efficient access to the
132132
133133 // Disable copy construction and assignment.
134134 // This data structure is not meant to be used that way.
135 SparseSet(const SparseSet&) LLVM_DELETED_FUNCTION;
136 SparseSet &operator=(const SparseSet&) LLVM_DELETED_FUNCTION;
135 SparseSet(const SparseSet&) = delete;
136 SparseSet &operator=(const SparseSet&) = delete;
137137
138138 public:
139139 typedef ValueT value_type;
110110 /// and data.
111111 template
112112 class StringMapEntry : public StringMapEntryBase {
113 StringMapEntry(StringMapEntry &E) LLVM_DELETED_FUNCTION;
113 StringMapEntry(StringMapEntry &E) = delete;
114114 public:
115115 ValueTy second;
116116
181181
182182 /// Since the intended use of twines is as temporary objects, assignments
183183 /// when concatenating might cause undefined behavior or stack corruptions
184 Twine &operator=(const Twine &Other) LLVM_DELETED_FUNCTION;
184 Twine &operator=(const Twine &Other) = delete;
185185
186186 /// isNull - Check for the null twine.
187187 bool isNull() const {
236236 // These are to catch errors when people try to use them as random access
237237 // iterators.
238238 template
239 void operator-(int, ilist_iterator) LLVM_DELETED_FUNCTION;
240 template
241 void operator-(ilist_iterator,int) LLVM_DELETED_FUNCTION;
242
243 template
244 void operator+(int, ilist_iterator) LLVM_DELETED_FUNCTION;
245 template
246 void operator+(ilist_iterator,int) LLVM_DELETED_FUNCTION;
239 void operator-(int, ilist_iterator) = delete;
240 template
241 void operator-(ilist_iterator,int) = delete;
242
243 template
244 void operator+(int, ilist_iterator) = delete;
245 template
246 void operator+(ilist_iterator,int) = delete;
247247
248248 // operator!=/operator== - Allow mixed comparisons without dereferencing
249249 // the iterator, which could very likely be pointing to end().
331331
332332 // No fundamental reason why iplist can't be copyable, but the default
333333 // copy/copy-assign won't do.
334 iplist(const iplist &) LLVM_DELETED_FUNCTION;
335 void operator=(const iplist &) LLVM_DELETED_FUNCTION;
334 iplist(const iplist &) = delete;
335 void operator=(const iplist &) = delete;
336336
337337 public:
338338 typedef NodeTy *pointer;
225225 AccessTy(NoModRef), AliasTy(MustAlias), Volatile(false) {
226226 }
227227
228 AliasSet(const AliasSet &AS) LLVM_DELETED_FUNCTION;
229 void operator=(const AliasSet &AS) LLVM_DELETED_FUNCTION;
228 AliasSet(const AliasSet &AS) = delete;
229 void operator=(const AliasSet &AS) = delete;
230230
231231 PointerRec *getSomePointer() const {
232232 return PtrList;
272272 /// CalledFunctions array of this or other CallGraphNodes.
273273 unsigned NumReferences;
274274
275 CallGraphNode(const CallGraphNode &) LLVM_DELETED_FUNCTION;
276 void operator=(const CallGraphNode &) LLVM_DELETED_FUNCTION;
275 CallGraphNode(const CallGraphNode &) = delete;
276 void operator=(const CallGraphNode &) = delete;
277277
278278 void DropRef() { --NumReferences; }
279279 void AddRef() { ++NumReferences; }
277277 /// DependenceAnalysis - This class is the main dependence-analysis driver.
278278 ///
279279 class DependenceAnalysis : public FunctionPass {
280 void operator=(const DependenceAnalysis &) LLVM_DELETED_FUNCTION;
281 DependenceAnalysis(const DependenceAnalysis &) LLVM_DELETED_FUNCTION;
280 void operator=(const DependenceAnalysis &) = delete;
281 DependenceAnalysis(const DependenceAnalysis &) = delete;
282282 public:
283283 /// depends - Tests for a dependence between the Src and Dst instructions.
284284 /// Returns NULL if no dependence; otherwise, returns a Dependence (or a
3232 class TargetLibraryInfo *TLI;
3333 DominatorTree *DT;
3434 void *PImpl;
35 LazyValueInfo(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
36 void operator=(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
35 LazyValueInfo(const LazyValueInfo&) = delete;
36 void operator=(const LazyValueInfo&) = delete;
3737 public:
3838 static char ID;
3939 LazyValueInfo() : FunctionPass(ID), PImpl(nullptr) {
7878
7979 SmallPtrSet DenseBlockSet;
8080
81 LoopBase(const LoopBase &) LLVM_DELETED_FUNCTION;
81 LoopBase(const LoopBase &) = delete;
8282 const LoopBase&
83 operator=(const LoopBase &) LLVM_DELETED_FUNCTION;
83 operator=(const LoopBase &) = delete;
8484 public:
8585 /// Loop ctor - This creates an empty loop.
8686 LoopBase() : ParentLoop(nullptr) {}
500500 friend class LoopBase;
501501 friend class LoopInfo;
502502
503 void operator=(const LoopInfoBase &) LLVM_DELETED_FUNCTION;
504 LoopInfoBase(const LoopInfoBase &) LLVM_DELETED_FUNCTION;
503 void operator=(const LoopInfoBase &) = delete;
504 LoopInfoBase(const LoopInfoBase &) = delete;
505505 public:
506506 LoopInfoBase() { }
507507 ~LoopInfoBase() { releaseMemory(); }
650650
651651 friend class LoopBase;
652652
653 void operator=(const LoopInfo &) LLVM_DELETED_FUNCTION;
654 LoopInfo(const LoopInfo &) LLVM_DELETED_FUNCTION;
653 void operator=(const LoopInfo &) = delete;
654 LoopInfo(const LoopInfo &) = delete;
655655 public:
656656 LoopInfo() {}
657657
;
114114 typedef typename Tr::RegionT RegionT;
115115
116116 private:
117 RegionNodeBase(const RegionNodeBase &) LLVM_DELETED_FUNCTION;
118 const RegionNodeBase &operator=(const RegionNodeBase &) LLVM_DELETED_FUNCTION;
117 RegionNodeBase(const RegionNodeBase &) = delete;
118 const RegionNodeBase &operator=(const RegionNodeBase &) = delete;
119119
120120 /// This is the entry basic block that starts this region node. If this is a
121121 /// BasicBlock RegionNode, then entry is just the basic block, that this
260260 typedef typename InvBlockTraits::ChildIteratorType PredIterTy;
261261
262262 friend class RegionInfoBase
263 RegionBase(const RegionBase &) LLVM_DELETED_FUNCTION;
264 const RegionBase &operator=(const RegionBase &) LLVM_DELETED_FUNCTION;
263 RegionBase(const RegionBase &) = delete;
264 const RegionBase &operator=(const RegionBase &) = delete;
265265
266266 // Information necessary to manage this Region.
267267 RegionInfoT *RI;
673673 RegionInfoBase();
674674 virtual ~RegionInfoBase();
675675
676 RegionInfoBase(const RegionInfoBase &) LLVM_DELETED_FUNCTION;
677 const RegionInfoBase &operator=(const RegionInfoBase &) LLVM_DELETED_FUNCTION;
676 RegionInfoBase(const RegionInfoBase &) = delete;
677 const RegionInfoBase &operator=(const RegionInfoBase &) = delete;
678678
679679 DomTreeT *DT;
680680 PostDomTreeT *PDT;
7070 unsigned short SubclassData;
7171
7272 private:
73 SCEV(const SCEV &) LLVM_DELETED_FUNCTION;
74 void operator=(const SCEV &) LLVM_DELETED_FUNCTION;
73 SCEV(const SCEV &) = delete;
74 void operator=(const SCEV &) = delete;
7575
7676 public:
7777 /// NoWrapFlags are bitfield indices into SubclassData.
130130 typedef std::pair Edge;
131131 std::set KnownFeasibleEdges;
132132
133 SparseSolver(const SparseSolver&) LLVM_DELETED_FUNCTION;
134 void operator=(const SparseSolver&) LLVM_DELETED_FUNCTION;
133 SparseSolver(const SparseSolver&) = delete;
134 void operator=(const SparseSolver&) = delete;
135135 public:
136136 explicit SparseSolver(AbstractLatticeFunction *Lattice)
137137 : LatticeFunc(Lattice) {}
4949 /// information in the BlockInfo block. Only llvm-bcanalyzer uses this.
5050 bool IgnoreBlockInfoNames;
5151
52 BitstreamReader(const BitstreamReader&) LLVM_DELETED_FUNCTION;
53 void operator=(const BitstreamReader&) LLVM_DELETED_FUNCTION;
52 BitstreamReader(const BitstreamReader&) = delete;
53 void operator=(const BitstreamReader&) = delete;
5454 public:
5555 BitstreamReader() : IgnoreBlockInfoNames(true) {
5656 }
4343 GCMetadataPrinter();
4444
4545 private:
46 GCMetadataPrinter(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
47 GCMetadataPrinter &operator=(const GCMetadataPrinter &) LLVM_DELETED_FUNCTION;
46 GCMetadataPrinter(const GCMetadataPrinter &) = delete;
47 GCMetadataPrinter &operator=(const GCMetadataPrinter &) = delete;
4848
4949 public:
5050 GCStrategy &getStrategy() { return *S; }
744744 #endif
745745
746746 private:
747 LiveInterval& operator=(const LiveInterval& rhs) LLVM_DELETED_FUNCTION;
747 LiveInterval& operator=(const LiveInterval& rhs) = delete;
748748
749749 /// Appends @p Range to SubRanges list.
750750 void appendSubRange(SubRange *Range) {
178178 }
179179
180180 private:
181 Query(const Query&) LLVM_DELETED_FUNCTION;
182 void operator=(const Query&) LLVM_DELETED_FUNCTION;
181 Query(const Query&) = delete;
182 void operator=(const Query&) = delete;
183183 };
184184
185185 // Array of LiveIntervalUnions.
4343 const TargetRegisterInfo *TRI;
4444 SparseSet LiveRegs;
4545
46 LivePhysRegs(const LivePhysRegs&) LLVM_DELETED_FUNCTION;
47 LivePhysRegs &operator=(const LivePhysRegs&) LLVM_DELETED_FUNCTION;
46 LivePhysRegs(const LivePhysRegs&) = delete;
47 LivePhysRegs &operator=(const LivePhysRegs&) = delete;
4848 public:
4949 /// \brief Constructs a new empty LivePhysRegs set.
5050 LivePhysRegs() : TRI(nullptr), LiveRegs() {}
2525 typedef DominanceFrontierBase::iterator iterator;
2626 typedef DominanceFrontierBase::const_iterator const_iterator;
2727
28 void operator=(const MachineDominanceFrontier &) LLVM_DELETED_FUNCTION;
29 MachineDominanceFrontier(const MachineDominanceFrontier &) LLVM_DELETED_FUNCTION;
28 void operator=(const MachineDominanceFrontier &) = delete;
29 MachineDominanceFrontier(const MachineDominanceFrontier &) = delete;
3030
3131 static char ID;
3232
144144 /// True if the function includes any inline assembly.
145145 bool HasInlineAsm;
146146
147 MachineFunction(const MachineFunction &) LLVM_DELETED_FUNCTION;
148 void operator=(const MachineFunction&) LLVM_DELETED_FUNCTION;
147 MachineFunction(const MachineFunction &) = delete;
148 void operator=(const MachineFunction&) = delete;
149149 public:
150150 MachineFunction(const Function *Fn, const TargetMachine &TM,
151151 unsigned FunctionNum, MachineModuleInfo &MMI);
9292
9393 DebugLoc debugLoc; // Source line information.
9494
95 MachineInstr(const MachineInstr&) LLVM_DELETED_FUNCTION;
96 void operator=(const MachineInstr&) LLVM_DELETED_FUNCTION;
95 MachineInstr(const MachineInstr&) = delete;
96 void operator=(const MachineInstr&) = delete;
9797 // Use MachineFunction::DeleteMachineInstr() instead.
98 ~MachineInstr() LLVM_DELETED_FUNCTION;
98 ~MachineInstr() = delete;
9999
100100 // Intrusive list support
101101 friend struct ilist_traits;
7373 LoopInfoBase LI;
7474 friend class LoopBase;
7575
76 void operator=(const MachineLoopInfo &) LLVM_DELETED_FUNCTION;
77 MachineLoopInfo(const MachineLoopInfo &) LLVM_DELETED_FUNCTION;
76 void operator=(const MachineLoopInfo &) = delete;
77 MachineLoopInfo(const MachineLoopInfo &) = delete;
7878
7979 public:
8080 static char ID; // Pass identification, replacement for typeid
122122 /// second element.
123123 std::vector > LiveIns;
124124
125 MachineRegisterInfo(const MachineRegisterInfo&) LLVM_DELETED_FUNCTION;
126 void operator=(const MachineRegisterInfo&) LLVM_DELETED_FUNCTION;
125 MachineRegisterInfo(const MachineRegisterInfo&) = delete;
126 void operator=(const MachineRegisterInfo&) = delete;
127127 public:
128128 explicit MachineRegisterInfo(const MachineFunction *MF);
129129
106106 private:
107107 unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
108108
109 void operator=(const MachineSSAUpdater&) LLVM_DELETED_FUNCTION;
110 MachineSSAUpdater(const MachineSSAUpdater&) LLVM_DELETED_FUNCTION;
109 void operator=(const MachineSSAUpdater&) = delete;
110 MachineSSAUpdater(const MachineSSAUpdater&) = delete;
111111 };
112112
113113 } // End llvm namespace
114114 typedef DenseMap > DbgValMapType;
115115 DbgValMapType DbgValMap;
116116
117 void operator=(const SDDbgInfo&) LLVM_DELETED_FUNCTION;
118 SDDbgInfo(const SDDbgInfo&) LLVM_DELETED_FUNCTION;
117 void operator=(const SDDbgInfo&) = delete;
118 SDDbgInfo(const SDDbgInfo&) = delete;
119119 public:
120120 SDDbgInfo() {}
121121
261261 DenseSet &visited,
262262 int level, bool &printed);
263263
264 void operator=(const SelectionDAG&) LLVM_DELETED_FUNCTION;
265 SelectionDAG(const SelectionDAG&) LLVM_DELETED_FUNCTION;
264 void operator=(const SelectionDAG&) = delete;
265 SelectionDAG(const SelectionDAG&) = delete;
266266
267267 public:
268268 explicit SelectionDAG(const TargetMachine &TM, llvm::CodeGenOpt::Level);
258258 /// this operand.
259259 SDUse **Prev, *Next;
260260
261 SDUse(const SDUse &U) LLVM_DELETED_FUNCTION;
262 void operator=(const SDUse &U) LLVM_DELETED_FUNCTION;
261 SDUse(const SDUse &U) = delete;
262 void operator=(const SDUse &U) = delete;
263263
264264 public:
265265 SDUse() : Val(), User(nullptr), Prev(nullptr), Next(nullptr) {}
16101610 /// BUILD_VECTORs.
16111611 class BuildVectorSDNode : public SDNode {
16121612 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1613 explicit BuildVectorSDNode() LLVM_DELETED_FUNCTION;
1613 explicit BuildVectorSDNode() = delete;
16141614 public:
16151615 /// isConstantSplat - Check if this is a constant splat, and if so, find the
16161616 /// smallest element size that splats the vector. If MinSplatBits is
6262 /// createSpillSlot - Allocate a spill slot for RC from MFI.
6363 unsigned createSpillSlot(const TargetRegisterClass *RC);
6464
65 VirtRegMap(const VirtRegMap&) LLVM_DELETED_FUNCTION;
66 void operator=(const VirtRegMap&) LLVM_DELETED_FUNCTION;
65 VirtRegMap(const VirtRegMap&) = delete;
66 void operator=(const VirtRegMap&) = delete;
6767
6868 public:
6969 static char ID;
4343 std::unique_ptr AbbrevDWO;
4444 std::unique_ptr LocDWO;
4545
46 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
47 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
46 DWARFContext(DWARFContext &) = delete;
47 DWARFContext &operator=(DWARFContext &) = delete;
4848
4949 /// Read compile units from the debug_info section (if necessary)
5050 /// and store them in CUs.
3333 /// had been provided by this instance. Higher level layers are responsible
3434 /// for taking any action required to handle the missing symbols.
3535 class LinkedObjectSet {
36 LinkedObjectSet(const LinkedObjectSet&) LLVM_DELETED_FUNCTION;
37 void operator=(const LinkedObjectSet&) LLVM_DELETED_FUNCTION;
36 LinkedObjectSet(const LinkedObjectSet&) = delete;
37 void operator=(const LinkedObjectSet&) = delete;
3838 public:
3939 LinkedObjectSet(std::unique_ptr MM)
4040 : MM(std::move(MM)), RTDyld(llvm::make_unique(&*this->MM)),
3333 // FIXME: As the RuntimeDyld fills out, additional routines will be needed
3434 // for the varying types of objects to be allocated.
3535 class RTDyldMemoryManager {
36 RTDyldMemoryManager(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
37 void operator=(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
36 RTDyldMemoryManager(const RTDyldMemoryManager&) = delete;
37 void operator=(const RTDyldMemoryManager&) = delete;
3838 public:
3939 RTDyldMemoryManager() {}
4040 virtual ~RTDyldMemoryManager();
3131 class RuntimeDyld {
3232 friend class RuntimeDyldCheckerImpl;
3333
34 RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
35 void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
34 RuntimeDyld(const RuntimeDyld &) = delete;
35 void operator=(const RuntimeDyld &) = delete;
3636
3737 // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
3838 // interface.
3434 /// MCJIT::finalizeObject or by calling SectionMemoryManager::finalizeMemory
3535 /// directly. Clients of MCJIT should call MCJIT::finalizeObject.
3636 class SectionMemoryManager : public RTDyldMemoryManager {
37 SectionMemoryManager(const SectionMemoryManager&) LLVM_DELETED_FUNCTION;
38 void operator=(const SectionMemoryManager&) LLVM_DELETED_FUNCTION;
37 SectionMemoryManager(const SectionMemoryManager&) = delete;
38 void operator=(const SectionMemoryManager&) = delete;
3939
4040 public:
4141 SectionMemoryManager() { }
8181 void setParent(Function *parent);
8282 friend class SymbolTableListTraits;
8383
84 BasicBlock(const BasicBlock &) LLVM_DELETED_FUNCTION;
85 void operator=(const BasicBlock &) LLVM_DELETED_FUNCTION;
84 BasicBlock(const BasicBlock &) = delete;
85 void operator=(const BasicBlock &) = delete;
8686
8787 /// \brief Constructor.
8888 ///
4848 friend class Module;
4949 Comdat();
5050 Comdat(SelectionKind SK, StringMapEntry *Name);
51 Comdat(const Comdat &) LLVM_DELETED_FUNCTION;
51 Comdat(const Comdat &) = delete;
5252
5353 // Points to the map in Module.
5454 StringMapEntry *Name;
3838 /// don't have to worry about the lifetime of the objects.
3939 /// @brief LLVM Constant Representation
4040 class Constant : public User {
41 void operator=(const Constant &) LLVM_DELETED_FUNCTION;
42 Constant(const Constant &) LLVM_DELETED_FUNCTION;
41 void operator=(const Constant &) = delete;
42 Constant(const Constant &) = delete;
4343 void anchor() override;
4444
4545 protected:
4545 /// @brief Class for constant integers.
4646 class ConstantInt : public Constant {
4747 void anchor() override;
48 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
49 ConstantInt(const ConstantInt &) LLVM_DELETED_FUNCTION;
48 void *operator new(size_t, unsigned) = delete;
49 ConstantInt(const ConstantInt &) = delete;
5050 ConstantInt(IntegerType *Ty, const APInt& V);
5151 APInt Val;
5252 protected:
227227 class ConstantFP : public Constant {
228228 APFloat Val;
229229 void anchor() override;
230 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
231 ConstantFP(const ConstantFP &) LLVM_DELETED_FUNCTION;
230 void *operator new(size_t, unsigned) = delete;
231 ConstantFP(const ConstantFP &) = delete;
232232 friend class LLVMContextImpl;
233233 protected:
234234 ConstantFP(Type *Ty, const APFloat& V);
293293 /// ConstantAggregateZero - All zero aggregate value
294294 ///
295295 class ConstantAggregateZero : public Constant {
296 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
297 ConstantAggregateZero(const ConstantAggregateZero &) LLVM_DELETED_FUNCTION;
296 void *operator new(size_t, unsigned) = delete;
297 ConstantAggregateZero(const ConstantAggregateZero &) = delete;
298298 protected:
299299 explicit ConstantAggregateZero(Type *ty)
300300 : Constant(ty, ConstantAggregateZeroVal, nullptr, 0) {}
337337 ///
338338 class ConstantArray : public Constant {
339339 friend struct ConstantAggrKeyType;
340 ConstantArray(const ConstantArray &) LLVM_DELETED_FUNCTION;
340 ConstantArray(const ConstantArray &) = delete;
341341 protected:
342342 ConstantArray(ArrayType *T, ArrayRef Val);
343343 public:
379379 //
380380 class ConstantStruct : public Constant {
381381 friend struct ConstantAggrKeyType;
382 ConstantStruct(const ConstantStruct &) LLVM_DELETED_FUNCTION;
382 ConstantStruct(const ConstantStruct &) = delete;
383383 protected:
384384 ConstantStruct(StructType *T, ArrayRef Val);
385385 public:
438438 ///
439439 class ConstantVector : public Constant {
440440 friend struct ConstantAggrKeyType;
441 ConstantVector(const ConstantVector &) LLVM_DELETED_FUNCTION;
441 ConstantVector(const ConstantVector &) = delete;
442442 protected:
443443 ConstantVector(VectorType *T, ArrayRef Val);
444444 public:
487487 /// ConstantPointerNull - a constant pointer value that points to null
488488 ///
489489 class ConstantPointerNull : public Constant {
490 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
491 ConstantPointerNull(const ConstantPointerNull &) LLVM_DELETED_FUNCTION;
490 void *operator new(size_t, unsigned) = delete;
491 ConstantPointerNull(const ConstantPointerNull &) = delete;
492492 protected:
493493 explicit ConstantPointerNull(PointerType *T)
494494 : Constant(T,
538538 /// element array of i8, or a 1-element array of i32. They'll both end up in
539539 /// the same StringMap bucket, linked up.
540540 ConstantDataSequential *Next;
541 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
542 ConstantDataSequential(const ConstantDataSequential &) LLVM_DELETED_FUNCTION;
541 void *operator new(size_t, unsigned) = delete;
542 ConstantDataSequential(const ConstantDataSequential &) = delete;
543543 protected:
544544 explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
545545 : Constant(ty, VT, nullptr, 0), DataElements(Data), Next(nullptr) {}
649649 /// operands because it stores all of the elements of the constant as densely
650650 /// packed data, instead of as Value*'s.
651651 class ConstantDataArray : public ConstantDataSequential {
652 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
653 ConstantDataArray(const ConstantDataArray &) LLVM_DELETED_FUNCTION;
652 void *operator new(size_t, unsigned) = delete;
653 ConstantDataArray(const ConstantDataArray &) = delete;
654654 void anchor() override;
655655 friend class ConstantDataSequential;
656656 explicit ConstantDataArray(Type *ty, const char *Data)
701701 /// operands because it stores all of the elements of the constant as densely
702702 /// packed data, instead of as Value*'s.
703703 class ConstantDataVector : public ConstantDataSequential {
704 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
705 ConstantDataVector(const ConstantDataVector &) LLVM_DELETED_FUNCTION;
704 void *operator new(size_t, unsigned) = delete;
705 ConstantDataVector(const ConstantDataVector &) = delete;
706706 void anchor() override;
707707 friend class ConstantDataSequential;
708708 explicit ConstantDataVector(Type *ty, const char *Data)
752752 /// BlockAddress - The address of a basic block.
753753 ///
754754 class BlockAddress : public Constant {
755 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
755 void *operator new(size_t, unsigned) = delete;
756756 void *operator new(size_t s) { return User::operator new(s, 2); }
757757 BlockAddress(Function *F, BasicBlock *BB);
758758 public:
11641164 /// LangRef.html#undefvalues for details.
11651165 ///
11661166 class UndefValue : public Constant {
1167 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1168 UndefValue(const UndefValue &) LLVM_DELETED_FUNCTION;
1167 void *operator new(size_t, unsigned) = delete;
1168 UndefValue(const UndefValue &) = delete;
11691169 protected:
11701170 explicit UndefValue(Type *T) : Constant(T, UndefValueVal, nullptr, 0) {}
11711171 protected:
7979 /// Each subprogram's preserved local variables.
8080 DenseMap> PreservedVariables;
8181
82 DIBuilder(const DIBuilder &) LLVM_DELETED_FUNCTION;
83 void operator=(const DIBuilder &) LLVM_DELETED_FUNCTION;
82 DIBuilder(const DIBuilder &) = delete;
83 void operator=(const DIBuilder &) = delete;
8484
8585 /// \brief Create a temporary.
8686 ///
6262 }
6363
6464 // Disallow replacing operands.
65 void replaceOperandWith(unsigned I, Metadata *New) LLVM_DELETED_FUNCTION;
65 void replaceOperandWith(unsigned I, Metadata *New) = delete;
6666
6767 public:
6868 DEFINE_MDNODE_GET(MDLocation,
9393 /// FunctionType - Class to represent function types
9494 ///
9595 class FunctionType : public Type {
96 FunctionType(const FunctionType &) LLVM_DELETED_FUNCTION;
97 const FunctionType &operator=(const FunctionType &) LLVM_DELETED_FUNCTION;
96 FunctionType(const FunctionType &) = delete;
97 const FunctionType &operator=(const FunctionType &) = delete;
9898 FunctionType(Type *Result, ArrayRef Params, bool IsVarArgs);
9999
100100 public:
187187 /// generator for a target expects).
188188 ///
189189 class StructType : public CompositeType {
190 StructType(const StructType &) LLVM_DELETED_FUNCTION;
191 const StructType &operator=(const StructType &) LLVM_DELETED_FUNCTION;
190 StructType(const StructType &) = delete;
191 const StructType &operator=(const StructType &) = delete;
192192 StructType(LLVMContext &C)
193193 : CompositeType(C, StructTyID), SymbolTableEntry(nullptr) {}
194194 enum {
307307 ///
308308 class SequentialType : public CompositeType {
309309 Type *ContainedType; ///< Storage for the single contained type.
310 SequentialType(const SequentialType &) LLVM_DELETED_FUNCTION;
311 const SequentialType &operator=(const SequentialType &) LLVM_DELETED_FUNCTION;
310 SequentialType(const SequentialType &) = delete;
311 const SequentialType &operator=(const SequentialType &) = delete;
312312
313313 protected:
314314 SequentialType(TypeID TID, Type *ElType)
334334 class ArrayType : public SequentialType {
335335 uint64_t NumElements;
336336
337 ArrayType(const ArrayType &) LLVM_DELETED_FUNCTION;
338 const ArrayType &operator=(const ArrayType &) LLVM_DELETED_FUNCTION;
337 ArrayType(const ArrayType &) = delete;
338 const ArrayType &operator=(const ArrayType &) = delete;
339339 ArrayType(Type *ElType, uint64_t NumEl);
340340 public:
341341 /// ArrayType::get - This static method is the primary way to construct an
360360 class VectorType : public SequentialType {
361361 unsigned NumElements;
362362
363 VectorType(const VectorType &) LLVM_DELETED_FUNCTION;
364 const VectorType &operator=(const VectorType &) LLVM_DELETED_FUNCTION;
363 VectorType(const VectorType &) = delete;
364 const VectorType &operator=(const VectorType &) = delete;
365365 VectorType(Type *ElType, unsigned NumEl);
366366 public:
367367 /// VectorType::get - This static method is the primary way to construct an
445445 /// PointerType - Class to represent pointers.
446446 ///
447447 class PointerType : public SequentialType {
448 PointerType(const PointerType &) LLVM_DELETED_FUNCTION;
449 const PointerType &operator=(const PointerType &) LLVM_DELETED_FUNCTION;
448 PointerType(const PointerType &) = delete;
449 const PointerType &operator=(const PointerType &) = delete;
450450 explicit PointerType(Type *ElType, unsigned AddrSpace);
451451 public:
452452 /// PointerType::get - This constructs a pointer to an object of the specified
112112 }
113113 void BuildLazyArguments() const;
114114
115 Function(const Function&) LLVM_DELETED_FUNCTION;
116 void operator=(const Function&) LLVM_DELETED_FUNCTION;
115 Function(const Function&) = delete;
116 void operator=(const Function&) = delete;
117117
118118 /// Do the actual lookup of an intrinsic ID when the query could not be
119119 /// answered from the cache.
2727
2828 class GlobalAlias : public GlobalValue, public ilist_node {
2929 friend class SymbolTableListTraits;
30 void operator=(const GlobalAlias &) LLVM_DELETED_FUNCTION;
31 GlobalAlias(const GlobalAlias &) LLVM_DELETED_FUNCTION;
30 void operator=(const GlobalAlias &) = delete;
31 GlobalAlias(const GlobalAlias &) = delete;
3232
3333 void setParent(Module *parent);
3434
2323 class Module;
2424
2525 class GlobalObject : public GlobalValue {
26 GlobalObject(const GlobalObject &) LLVM_DELETED_FUNCTION;
26 GlobalObject(const GlobalObject &) = delete;
2727
2828 protected:
2929 GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
2828 class Module;
2929
3030 class GlobalValue : public Constant {
31 GlobalValue(const GlobalValue &) LLVM_DELETED_FUNCTION;
31 GlobalValue(const GlobalValue &) = delete;
3232 public:
3333 /// @brief An enumeration for the kinds of linkage for global values.
3434 enum LinkageTypes {
3333
3434 class GlobalVariable : public GlobalObject, public ilist_node {
3535 friend class SymbolTableListTraits;
36 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
37 void operator=(const GlobalVariable &) LLVM_DELETED_FUNCTION;
38 GlobalVariable(const GlobalVariable &) LLVM_DELETED_FUNCTION;
36 void *operator new(size_t, unsigned) = delete;
37 void operator=(const GlobalVariable &) = delete;
38 GlobalVariable(const GlobalVariable &) = delete;
3939
4040 void setParent(Module *parent);
4141
197197 BasicBlock::iterator Point;
198198 DebugLoc DbgLoc;
199199
200 InsertPointGuard(const InsertPointGuard &) LLVM_DELETED_FUNCTION;
201 InsertPointGuard &operator=(const InsertPointGuard &) LLVM_DELETED_FUNCTION;
200 InsertPointGuard(const InsertPointGuard &) = delete;
201 InsertPointGuard &operator=(const InsertPointGuard &) = delete;
202202
203203 public:
204204 InsertPointGuard(IRBuilderBase &B)
218218 FastMathFlags FMF;
219219 MDNode *FPMathTag;
220220
221 FastMathFlagGuard(const FastMathFlagGuard &) LLVM_DELETED_FUNCTION;
221 FastMathFlagGuard(const FastMathFlagGuard &) = delete;
222222 FastMathFlagGuard &operator=(
223 const FastMathFlagGuard &) LLVM_DELETED_FUNCTION;
223 const FastMathFlagGuard &) = delete;
224224
225225 public:
226226 FastMathFlagGuard(IRBuilderBase &B)
12941294 // \brief Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
12951295 // compile time error, instead of converting the string to bool for the
12961296 // isSigned parameter.
1297 Value *CreateIntCast(Value *, Type *, const char *) LLVM_DELETED_FUNCTION;
1297 Value *CreateIntCast(Value *, Type *, const char *) = delete;
12981298 public:
12991299 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
13001300 if (V->getType() == DestTy)