Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 1 | //===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jim Laskey | 864e444 | 2006-03-24 10:00:56 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements methods that make it really easy to deal with intrinsic |
| 11 | // functions with the isa/dyncast family of functions. In particular, this |
| 12 | // allows you to do things like: |
| 13 | // |
| 14 | // if (DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(Inst)) |
| 15 | // ... SPI->getFileName() ... SPI->getDirectory() ... |
| 16 | // |
| 17 | // All intrinsic function calls are instances of the call instruction, so these |
| 18 | // are all subclasses of the CallInst class. Note that none of these classes |
| 19 | // has state or virtual methods, which is an important part of this gross/neat |
| 20 | // hack working. |
| 21 | // |
| 22 | // In some cases, arguments to intrinsics need to be generic and are defined as |
| 23 | // type pointer to empty struct { }*. To access the real item of interest the |
| 24 | // cast instruction needs to be stripped away. |
| 25 | // |
| 26 | //===----------------------------------------------------------------------===// |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 27 | |
| 28 | #include "llvm/IntrinsicInst.h" |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 29 | #include "llvm/Constants.h" |
| 30 | #include "llvm/GlobalVariable.h" |
Evan Cheng | da3db11 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 31 | #include "llvm/Analysis/ValueTracking.h" |
Jim Laskey | c56315c | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics |
| 37 | /// |
| 38 | |
| 39 | static Value *CastOperand(Value *C) { |
| 40 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 41 | if (CE->isCast()) |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 42 | return CE->getOperand(0); |
| 43 | return NULL; |
| 44 | } |
| 45 | |
| 46 | Value *DbgInfoIntrinsic::StripCast(Value *C) { |
| 47 | if (Value *CO = CastOperand(C)) { |
Jim Laskey | 7092888 | 2006-03-26 22:46:27 +0000 | [diff] [blame] | 48 | C = StripCast(CO); |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 49 | } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) { |
| 50 | if (GV->hasInitializer()) |
| 51 | if (Value *CO = CastOperand(GV->getInitializer())) |
Jim Laskey | 7092888 | 2006-03-26 22:46:27 +0000 | [diff] [blame] | 52 | C = StripCast(CO); |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 53 | } |
Jim Laskey | 7092888 | 2006-03-26 22:46:27 +0000 | [diff] [blame] | 54 | return dyn_cast<GlobalVariable>(C); |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | //===----------------------------------------------------------------------===// |
| 58 | /// DbgStopPointInst - This represents the llvm.dbg.stoppoint instruction. |
| 59 | /// |
| 60 | |
Evan Cheng | da3db11 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 61 | Value *DbgStopPointInst::getFileName() const { |
Jim Laskey | 90cd68a | 2006-06-19 12:54:15 +0000 | [diff] [blame] | 62 | // Once the operand indices are verified, update this assert |
John Criswell | 8dd90a7 | 2008-12-19 19:56:36 +0000 | [diff] [blame] | 63 | assert(LLVMDebugVersion == (7 << 16) && "Verify operand indices"); |
Torok Edwin | 18e03dd | 2009-09-02 11:13:56 +0000 | [diff] [blame] | 64 | return getContext()->getElement(3); |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Evan Cheng | da3db11 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 67 | Value *DbgStopPointInst::getDirectory() const { |
Jim Laskey | 90cd68a | 2006-06-19 12:54:15 +0000 | [diff] [blame] | 68 | // Once the operand indices are verified, update this assert |
John Criswell | 8dd90a7 | 2008-12-19 19:56:36 +0000 | [diff] [blame] | 69 | assert(LLVMDebugVersion == (7 << 16) && "Verify operand indices"); |
Torok Edwin | 18e03dd | 2009-09-02 11:13:56 +0000 | [diff] [blame] | 70 | return getContext()->getElement(4); |
Jim Laskey | 0cf8ed6 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 71 | } |