aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/IR/GlobalObject.h
blob: 3bc8b8531dd6730d3f0c0c236302fec4f2109b0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//===-- llvm/GlobalObject.h - Class to represent a global object *- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This represents an independent object. That is, a function or a global
// variable, but not an alias.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_IR_GLOBALOBJECT_H
#define LLVM_IR_GLOBALOBJECT_H

#include "llvm/IR/Constant.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GlobalValue.h"

namespace llvm {

class Module;

class GlobalObject : public GlobalValue {
  GlobalObject(const GlobalObject &) LLVM_DELETED_FUNCTION;

protected:
  GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
               LinkageTypes Linkage, const Twine &Name)
      : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name) {
    setGlobalValueSubClassData(0);
  }

  std::string Section;     // Section to emit this into, empty means default
public:
  unsigned getAlignment() const {
    return (1u << getGlobalValueSubClassData()) >> 1;
  }
  void setAlignment(unsigned Align);

  bool hasSection() const { return !getSection().empty(); }
  const std::string &getSection() const { return Section; }
  void setSection(StringRef S);

  void copyAttributesFrom(const GlobalValue *Src) override;

  // Methods for support type inquiry through isa, cast, and dyn_cast:
  static inline bool classof(const Value *V) {
    return V->getValueID() == Value::FunctionVal ||
           V->getValueID() == Value::GlobalVariableVal;
  }
};

} // End llvm namespace

#endif