Remove attribution from file headers, per discussion on llvmdev.
[oota-llvm.git] / lib / VMCore / IntrinsicInst.cpp
1 //===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
27
28 #include "llvm/IntrinsicInst.h"
29 #include "llvm/Constants.h"
30 #include "llvm/GlobalVariable.h"
31 #include "llvm/CodeGen/MachineModuleInfo.h"
32 using namespace llvm;
33
34 //===----------------------------------------------------------------------===//
35 /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
36 ///
37
38 static Value *CastOperand(Value *C) {
39   if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
40     if (CE->isCast())
41       return CE->getOperand(0);
42   return NULL;
43 }
44
45 Value *DbgInfoIntrinsic::StripCast(Value *C) {
46   if (Value *CO = CastOperand(C)) {
47     C = StripCast(CO);
48   } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
49     if (GV->hasInitializer())
50       if (Value *CO = CastOperand(GV->getInitializer()))
51         C = StripCast(CO);
52   }
53   return dyn_cast<GlobalVariable>(C);
54 }
55
56 //===----------------------------------------------------------------------===//
57 /// DbgStopPointInst - This represents the llvm.dbg.stoppoint instruction.
58 ///
59
60 std::string DbgStopPointInst::getFileName() const {
61   // Once the operand indices are verified, update this assert
62   assert(LLVMDebugVersion == (6 << 16) && "Verify operand indices");
63   GlobalVariable *GV = cast<GlobalVariable>(getContext());
64   if (!GV->hasInitializer()) return "";
65   ConstantStruct *CS = cast<ConstantStruct>(GV->getInitializer());
66   return CS->getOperand(3)->getStringValue();
67 }
68
69 std::string DbgStopPointInst::getDirectory() const {
70   // Once the operand indices are verified, update this assert
71   assert(LLVMDebugVersion == (6 << 16) && "Verify operand indices");
72   GlobalVariable *GV = cast<GlobalVariable>(getContext());
73   if (!GV->hasInitializer()) return "";
74   ConstantStruct *CS = cast<ConstantStruct>(GV->getInitializer());
75   return CS->getOperand(4)->getStringValue();
76 }
77
78 //===----------------------------------------------------------------------===//
79 /// Ensure that users of IntrinsicInst.h will link with this module.
80 DEFINING_FILE_FOR(IntrinsicInst)