Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: lib/Transforms/NaCl/ReplacePtrsWithInts.cpp

Issue 1151093004: Changes from 3.7 merge to files not in upstream (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- ReplacePtrsWithInts.cpp - Convert pointer values to integer values--===// 1 //===- ReplacePtrsWithInts.cpp - Convert pointer values to integer values--===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This pass strips out aggregate pointer types and replaces them with 10 // This pass strips out aggregate pointer types and replaces them with
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 I != E; ++I) { 276 I != E; ++I) {
277 (*I)->dropAllReferences(); 277 (*I)->dropAllReferences();
278 } 278 }
279 for (SmallVectorImpl<Instruction *>::iterator I = ToErase.begin(), 279 for (SmallVectorImpl<Instruction *>::iterator I = ToErase.begin(),
280 E = ToErase.end(); 280 E = ToErase.end();
281 I != E; ++I) { 281 I != E; ++I) {
282 (*I)->eraseFromParent(); 282 (*I)->eraseFromParent();
283 } 283 }
284 } 284 }
285 285
286 static void ConvertMetadataOperand(FunctionConverter *FC,
287 IntrinsicInst *Call, int Index) {
288 MDNode *MD = cast<MDNode>(Call->getArgOperand(Index));
289 if (MD->getNumOperands() != 1)
290 return;
291 Value *MDArg = MD->getOperand(0);
292 if (MDArg && (isa<Argument>(MDArg) || isa<Instruction>(MDArg))) {
293 MDArg = FC->convert(MDArg, /* BypassPlaceholder= */ true);
294 if (PtrToIntInst *Cast = dyn_cast<PtrToIntInst>(MDArg)) {
295 // Unwrapping this is necessary for llvm.dbg.declare to work.
296 MDArg = Cast->getPointerOperand();
297 }
298 SmallVector<Value *, 1> Args;
299 Args.push_back(MDArg);
300 Call->setArgOperand(Index, MDNode::get(Call->getContext(), Args));
301 }
302 }
303
304 // Remove attributes that only apply to pointer arguments. Returns 286 // Remove attributes that only apply to pointer arguments. Returns
305 // the updated AttributeSet. 287 // the updated AttributeSet.
306 static AttributeSet RemovePointerAttrs(LLVMContext &Context, 288 static AttributeSet RemovePointerAttrs(LLVMContext &Context,
307 AttributeSet Attrs) { 289 AttributeSet Attrs) {
308 SmallVector<AttributeSet, 8> AttrList; 290 SmallVector<AttributeSet, 8> AttrList;
309 for (unsigned Slot = 0; Slot < Attrs.getNumSlots(); ++Slot) { 291 for (unsigned Slot = 0; Slot < Attrs.getNumSlots(); ++Slot) {
310 unsigned Index = Attrs.getSlotIndex(Slot); 292 unsigned Index = Attrs.getSlotIndex(Slot);
311 AttrBuilder AB; 293 AttrBuilder AB;
312 for (AttributeSet::iterator Attr = Attrs.begin(Slot), E = Attrs.end(Slot); 294 for (AttributeSet::iterator Attr = Attrs.begin(Slot), E = Attrs.end(Slot);
313 Attr != E; ++Attr) { 295 Attr != E; ++Attr) {
(...skipping 12 matching lines...) Expand all
326 break; 308 break;
327 // Strip these attributes because they apply only to pointers. This pass 309 // Strip these attributes because they apply only to pointers. This pass
328 // rewrites pointer arguments, thus these parameter attributes are 310 // rewrites pointer arguments, thus these parameter attributes are
329 // meaningless. Also, they are rejected by the PNaCl module verifier. 311 // meaningless. Also, they are rejected by the PNaCl module verifier.
330 case Attribute::NoCapture: 312 case Attribute::NoCapture:
331 case Attribute::NoAlias: 313 case Attribute::NoAlias:
332 case Attribute::ReadNone: 314 case Attribute::ReadNone:
333 case Attribute::ReadOnly: 315 case Attribute::ReadOnly:
334 case Attribute::NonNull: 316 case Attribute::NonNull:
335 case Attribute::Dereferenceable: 317 case Attribute::Dereferenceable:
318 case Attribute::DereferenceableOrNull:
336 break; 319 break;
337 default: 320 default:
338 AB.addAttribute(*Attr); 321 AB.addAttribute(*Attr);
339 } 322 }
340 } 323 }
341 AttrList.push_back(AttributeSet::get(Context, Index, AB)); 324 AttrList.push_back(AttributeSet::get(Context, Index, AB));
342 } 325 }
343 return AttributeSet::get(Context, AttrList); 326 return AttributeSet::get(Context, AttrList);
344 } 327 }
345 328
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 } 567 }
585 568
586 // Convert the function body. 569 // Convert the function body.
587 for (Function::iterator BB = NewFunc->begin(), E = NewFunc->end(); 570 for (Function::iterator BB = NewFunc->begin(), E = NewFunc->end();
588 BB != E; ++BB) { 571 BB != E; ++BB) {
589 for (BasicBlock::iterator Iter = BB->begin(), E = BB->end(); 572 for (BasicBlock::iterator Iter = BB->begin(), E = BB->end();
590 Iter != E; ) { 573 Iter != E; ) {
591 ConvertInstruction(&DL, IntPtrType, &FC, Iter++); 574 ConvertInstruction(&DL, IntPtrType, &FC, Iter++);
592 } 575 }
593 } 576 }
594 // Now that all the replacement instructions have been created, we
jvoung (off chromium) 2015/05/26 20:39:45 this is automatic now?
Derek Schuff 2015/05/26 22:01:32 RAUW seems to work on MetadataAsValue. We could ma
595 // can update the debug intrinsic calls.
596 for (Function::iterator BB = NewFunc->begin(), E = NewFunc->end();
597 BB != E; ++BB) {
598 for (BasicBlock::iterator Inst = BB->begin(), E = BB->end();
599 Inst != E; ++Inst) {
600 if (IntrinsicInst *Call = dyn_cast<IntrinsicInst>(Inst)) {
601 if (Call->getIntrinsicID() == Intrinsic::dbg_declare) {
602 ConvertMetadataOperand(&FC, Call, 0);
603 }
604 }
605 }
606 }
607 FC.eraseReplacedInstructions(); 577 FC.eraseReplacedInstructions();
608 578
609 // Patch the pointer to LLVM function in debug info descriptor. 579 // Patch the pointer to LLVM function in debug info descriptor.
610 auto DI = FunctionDIs.find(OldFunc); 580 auto DI = FunctionDIs.find(OldFunc);
611 if (DI != FunctionDIs.end()) 581 if (DI != FunctionDIs.end())
612 DI->second.replaceFunction(NewFunc); 582 DI->second->replaceFunction(NewFunc);
613 583
614 OldFunc->eraseFromParent(); 584 OldFunc->eraseFromParent();
615 } 585 }
616 // Now that all functions have their normalized types, we can remove 586 // Now that all functions have their normalized types, we can remove
617 // various casts. 587 // various casts.
618 for (Module::iterator Func = M.begin(), E = M.end(); Func != E; ++Func) { 588 for (Module::iterator Func = M.begin(), E = M.end(); Func != E; ++Func) {
619 CleanUpFunction(Func, IntPtrType); 589 CleanUpFunction(Func, IntPtrType);
620 // Delete the now-unused bitcast ConstantExprs that we created so 590 // Delete the now-unused bitcast ConstantExprs that we created so
621 // that they don't interfere with StripDeadPrototypes. 591 // that they don't interfere with StripDeadPrototypes.
622 Func->removeDeadConstantUsers(); 592 Func->removeDeadConstantUsers();
623 } 593 }
624 return true; 594 return true;
625 } 595 }
626 596
627 ModulePass *llvm::createReplacePtrsWithIntsPass() { 597 ModulePass *llvm::createReplacePtrsWithIntsPass() {
628 return new ReplacePtrsWithInts(); 598 return new ReplacePtrsWithInts();
629 } 599 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698