blob: cb9252efdf5881bab570f120c1f9573ca849d159 [file] [log] [blame]
Jim Laskey0cf8ed62006-03-23 18:05:12 +00001//===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey0cf8ed62006-03-23 18:05:12 +00007//
8//===----------------------------------------------------------------------===//
Jim Laskey864e4442006-03-24 10:00:56 +00009//
10// This file implements methods that make it really easy to deal with intrinsic
Devang Patelbe94f232010-01-05 01:10:40 +000011// functions.
Jim Laskey864e4442006-03-24 10:00:56 +000012//
13// All intrinsic function calls are instances of the call instruction, so these
14// are all subclasses of the CallInst class. Note that none of these classes
15// has state or virtual methods, which is an important part of this gross/neat
16// hack working.
17//
18// In some cases, arguments to intrinsics need to be generic and are defined as
19// type pointer to empty struct { }*. To access the real item of interest the
20// cast instruction needs to be stripped away.
21//
22//===----------------------------------------------------------------------===//
Jim Laskey0cf8ed62006-03-23 18:05:12 +000023
24#include "llvm/IntrinsicInst.h"
Jim Laskey0cf8ed62006-03-23 18:05:12 +000025#include "llvm/Constants.h"
26#include "llvm/GlobalVariable.h"
Evan Chengda3db112008-06-30 07:31:25 +000027#include "llvm/Analysis/ValueTracking.h"
Jim Laskeyc56315c2007-01-26 21:22:28 +000028#include "llvm/CodeGen/MachineModuleInfo.h"
Jim Laskey0cf8ed62006-03-23 18:05:12 +000029using namespace llvm;
30
31//===----------------------------------------------------------------------===//
32/// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
33///
34
35static Value *CastOperand(Value *C) {
36 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
Reid Spencer6c38f0b2006-11-27 01:05:10 +000037 if (CE->isCast())
Jim Laskey0cf8ed62006-03-23 18:05:12 +000038 return CE->getOperand(0);
39 return NULL;
40}
41
42Value *DbgInfoIntrinsic::StripCast(Value *C) {
43 if (Value *CO = CastOperand(C)) {
Jim Laskey70928882006-03-26 22:46:27 +000044 C = StripCast(CO);
Jim Laskey0cf8ed62006-03-23 18:05:12 +000045 } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
46 if (GV->hasInitializer())
47 if (Value *CO = CastOperand(GV->getInitializer()))
Jim Laskey70928882006-03-26 22:46:27 +000048 C = StripCast(CO);
Jim Laskey0cf8ed62006-03-23 18:05:12 +000049 }
Jim Laskey70928882006-03-26 22:46:27 +000050 return dyn_cast<GlobalVariable>(C);
Jim Laskey0cf8ed62006-03-23 18:05:12 +000051}
52
53//===----------------------------------------------------------------------===//
Chris Lattnercc8c8142009-12-31 01:32:41 +000054/// DbgValueInst - This represents the llvm.dbg.value instruction.
55///
56
Victor Hernandez9ce5b512010-01-11 07:45:19 +000057const Value *DbgValueInst::getValue() const {
58 return cast<MDNode>(getOperand(1))->getOperand(0);
59}
60
61Value *DbgValueInst::getValue() {
Chris Lattnercc8c8142009-12-31 01:32:41 +000062 return cast<MDNode>(getOperand(1))->getOperand(0);
63}