LLVM 19.0.0git
Go to the documentation of this file.
1//===- ValueList.cpp - Internal BitcodeReader implementation --------------===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9#include "ValueList.h"
10#include "llvm/IR/Argument.h"
11#include "llvm/IR/Constant.h"
12#include "llvm/IR/Constants.h"
13#include "llvm/IR/GlobalValue.h"
14#include "llvm/IR/Instruction.h"
15#include "llvm/IR/Type.h"
16#include "llvm/IR/User.h"
17#include "llvm/IR/Value.h"
19#include "llvm/Support/Error.h"
21#include <cstddef>
23using namespace llvm;
26 unsigned TypeID) {
27 if (Idx == size()) {
28 push_back(V, TypeID);
29 return Error::success();
30 }
32 if (Idx >= size())
33 resize(Idx + 1);
35 auto &Old = ValuePtrs[Idx];
36 if (!Old.first) {
37 Old.first = V;
38 Old.second = TypeID;
39 return Error::success();
40 }
42 assert(!isa<Constant>(&*Old.first) && "Shouldn't update constant");
43 // If there was a forward reference to this value, replace it.
44 Value *PrevVal = Old.first;
45 if (PrevVal->getType() != V->getType())
46 return createStringError(
47 std::errc::illegal_byte_sequence,
48 "Assigned value does not match type of forward declaration");
49 Old.first->replaceAllUsesWith(V);
50 PrevVal->deleteValue();
51 return Error::success();
55 unsigned TyID,
56 BasicBlock *ConstExprInsertBB) {
57 // Bail out for a clearly invalid value.
58 if (Idx >= RefsUpperBound)
59 return nullptr;
61 if (Idx >= size())
62 resize(Idx + 1);
64 if (Value *V = ValuePtrs[Idx].first) {
65 // If the types don't match, it's invalid.
66 if (Ty && Ty != V->getType())
67 return nullptr;
69 Expected<Value *> MaybeV = MaterializeValueFn(Idx, ConstExprInsertBB);
70 if (!MaybeV) {
71 // TODO: We might want to propagate the precise error message here.
72 consumeError(MaybeV.takeError());
73 return nullptr;
74 }
75 return MaybeV.get();
76 }
78 // No type specified, must be invalid reference.
79 if (!Ty)
80 return nullptr;
82 // Create and return a placeholder, which will later be RAUW'd.
83 Value *V = new Argument(Ty);
84 ValuePtrs[Idx] = {V, TyID};
85 return V;
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
Definition: ValueList.cpp:54
void resize(unsigned N)
Definition: ValueList.h:49
void push_back(Value *V, unsigned TypeID)
Definition: ValueList.h:52
Error assignValue(unsigned Idx, Value *V, unsigned TypeID)
Definition: ValueList.cpp:25
unsigned size() const
Definition: ValueList.h:48
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
Error takeError()
Take ownership of the stored error.
Definition: Error.h:601
reference get()
Returns a reference to the stored T value.
Definition: Error.h:571
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Definitions of all of the base types for the Type system.
Definition: Type.h:54
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void deleteValue()
Delete a pointer to a generic Value.
Definition: Value.cpp:110
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1258
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1041