llvm.org GIT mirror llvm / 25ceb5f
add an x86 implementation of MCTargetExpr for representing @GOT and friends. Use it for personality references as a first use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95588 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
5 changed file(s) with 90 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
2525 X86JITInfo.cpp
2626 X86MCAsmInfo.cpp
2727 X86MCCodeEmitter.cpp
28 X86MCTargetExpr.cpp
2829 X86RegisterInfo.cpp
2930 X86Subtarget.cpp
3031 X86TargetMachine.cpp
0 //===- X86MCTargetExpr.cpp - X86 Target Specific MCExpr Implementation ----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "X86MCTargetExpr.h"
10 #include "llvm/MC/MCContext.h"
11 #include "llvm/MC/MCSymbol.h"
12 #include "llvm/MC/MCValue.h"
13 #include "llvm/Support/raw_ostream.h"
14 using namespace llvm;
15
16 X86MCTargetExpr *X86MCTargetExpr::Create(const MCSymbol *Sym, VariantKind K,
17 MCContext &Ctx) {
18 return new (Ctx) X86MCTargetExpr(Sym, K);
19 }
20
21 void X86MCTargetExpr::PrintImpl(raw_ostream &OS) const {
22 OS << *Sym;
23
24 switch (Kind) {
25 case GOT: OS << "@GOT"; break;
26 case PLT: OS << "@PLT"; break;
27 case GOTPCREL: OS << "@GOTPCREL"; break;
28 }
29 }
30
31 bool X86MCTargetExpr::EvaluateAsRelocatableImpl(MCValue &Res) const {
32 // FIXME: I don't know if this is right, it followed MCSymbolRefExpr.
33
34 // Evaluate recursively if this is a variable.
35 if (Sym->isVariable())
36 return Sym->getValue()->EvaluateAsRelocatable(Res);
37
38 Res = MCValue::get(Sym, 0, 0);
39 return true;
40 }
41
42 X86MCTargetExpr *foo(MCExpr *A) { return (X86MCTargetExpr*)A; }
0 //===- X86MCTargetExpr.h - X86 Target Specific MCExpr -----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef X86_MCTARGETEXPR_H
10 #define X86_MCTARGETEXPR_H
11
12 #include "llvm/MC/MCExpr.h"
13
14 namespace llvm {
15
16 /// X86MCTargetExpr - This class represents symbol variants, like foo@GOT.
17 class X86MCTargetExpr : public MCTargetExpr {
18 public:
19 enum VariantKind {
20 GOT,
21 PLT,
22 GOTPCREL
23 };
24 private:
25 /// Sym - The symbol being referenced.
26 const MCSymbol * const Sym;
27 /// Kind - The modifier.
28 const VariantKind Kind;
29
30 X86MCTargetExpr(const MCSymbol *S, VariantKind K) : Sym(S), Kind(K) {}
31 public:
32 static X86MCTargetExpr *Create(const MCSymbol *Sym, VariantKind K,
33 MCContext &Ctx);
34
35 void PrintImpl(raw_ostream &OS) const;
36 bool EvaluateAsRelocatableImpl(MCValue &Res) const;
37 };
38
39 } // end namespace llvm
40
41 #endif
77 //===----------------------------------------------------------------------===//
88
99 #include "X86TargetObjectFile.h"
10 #include "X86MCTargetExpr.h"
1011 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
1112 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCExpr.h"
1313 #include "llvm/Target/Mangler.h"
1414 #include "llvm/ADT/SmallString.h"
1515 using namespace llvm;
5656
5757 SmallString<128> Name;
5858 Mang->getNameWithPrefix(Name, GV, false);
59 Name += "@GOTPCREL";
59 const MCSymbol *Sym = getContext().CreateSymbol(Name);
6060 const MCExpr *Res =
61 MCSymbolRefExpr::Create(Name.str(), getContext());
61 X86MCTargetExpr::Create(Sym, X86MCTargetExpr::GOTPCREL, getContext());
6262 const MCExpr *Four = MCConstantExpr::Create(4, getContext());
6363 return MCBinaryExpr::CreateAdd(Res, Four, getContext());
6464 }
3838 declare void @__cxa_end_catch()
3939
4040 ; X64: Leh_frame_common_begin:
41 ; X64: .long ___gxx_personality_v0@GOTPCREL+4
41 ; X64: .long (___gxx_personality_v0@GOTPCREL)+4
4242
4343 ; X32: Leh_frame_common_begin:
4444 ; X32: .long L___gxx_personality_v0$non_lazy_ptr-